2010-11-08 11:00:52 +08:00
|
|
|
//===- PTXMachineFuctionInfo.h - PTX machine function info -------*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares PTX-specific per-machine-function information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef PTX_MACHINE_FUNCTION_INFO_H
|
|
|
|
#define PTX_MACHINE_FUNCTION_INFO_H
|
|
|
|
|
|
|
|
#include "PTX.h"
|
2011-09-23 22:18:22 +08:00
|
|
|
#include "PTXParamManager.h"
|
2011-09-23 00:45:40 +08:00
|
|
|
#include "PTXRegisterInfo.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2011-06-17 01:50:00 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2011-09-23 00:45:40 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2010-11-08 11:00:52 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2011-09-23 00:45:46 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-11-08 11:00:52 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2011-09-23 00:45:46 +08:00
|
|
|
|
2010-11-08 11:00:52 +08:00
|
|
|
/// PTXMachineFunctionInfo - This class is derived from MachineFunction and
|
|
|
|
/// contains private PTX target-specific information for each MachineFunction.
|
|
|
|
///
|
|
|
|
class PTXMachineFunctionInfo : public MachineFunctionInfo {
|
|
|
|
private:
|
2011-09-24 01:15:53 +08:00
|
|
|
bool IsKernel;
|
|
|
|
DenseSet<unsigned> RegArgs;
|
|
|
|
DenseSet<unsigned> RegRets;
|
2010-11-08 11:00:52 +08:00
|
|
|
|
2011-09-23 00:45:40 +08:00
|
|
|
typedef std::vector<unsigned> RegisterList;
|
|
|
|
typedef DenseMap<const TargetRegisterClass*, RegisterList> RegisterMap;
|
|
|
|
typedef DenseMap<unsigned, std::string> RegisterNameMap;
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
RegisterMap UsedRegs;
|
|
|
|
RegisterNameMap RegNames;
|
2011-09-23 00:45:46 +08:00
|
|
|
|
2011-09-23 22:18:22 +08:00
|
|
|
PTXParamManager ParamManager;
|
|
|
|
|
2010-11-08 11:00:52 +08:00
|
|
|
public:
|
2011-09-24 01:15:53 +08:00
|
|
|
typedef DenseSet<unsigned>::const_iterator reg_iterator;
|
|
|
|
|
2010-11-08 11:00:52 +08:00
|
|
|
PTXMachineFunctionInfo(MachineFunction &MF)
|
2011-09-24 01:15:53 +08:00
|
|
|
: IsKernel(false) {
|
|
|
|
UsedRegs[PTX::RegPredRegisterClass] = RegisterList();
|
|
|
|
UsedRegs[PTX::RegI16RegisterClass] = RegisterList();
|
|
|
|
UsedRegs[PTX::RegI32RegisterClass] = RegisterList();
|
|
|
|
UsedRegs[PTX::RegI64RegisterClass] = RegisterList();
|
|
|
|
UsedRegs[PTX::RegF32RegisterClass] = RegisterList();
|
|
|
|
UsedRegs[PTX::RegF64RegisterClass] = RegisterList();
|
2010-11-08 11:00:52 +08:00
|
|
|
}
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// getParamManager - Returns the PTXParamManager instance for this function.
|
2011-09-23 22:18:22 +08:00
|
|
|
PTXParamManager& getParamManager() { return ParamManager; }
|
|
|
|
const PTXParamManager& getParamManager() const { return ParamManager; }
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// setKernel/isKernel - Gets/sets a flag that indicates if this function is
|
|
|
|
/// a PTX kernel function.
|
|
|
|
void setKernel(bool _IsKernel=true) { IsKernel = _IsKernel; }
|
|
|
|
bool isKernel() const { return IsKernel; }
|
2010-11-08 11:00:52 +08:00
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// argreg_begin/argreg_end - Returns iterators to the set of registers
|
|
|
|
/// containing function arguments.
|
|
|
|
reg_iterator argreg_begin() const { return RegArgs.begin(); }
|
|
|
|
reg_iterator argreg_end() const { return RegArgs.end(); }
|
2011-06-17 01:50:00 +08:00
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// retreg_begin/retreg_end - Returns iterators to the set of registers
|
|
|
|
/// containing the function return values.
|
|
|
|
reg_iterator retreg_begin() const { return RegRets.begin(); }
|
|
|
|
reg_iterator retreg_end() const { return RegRets.end(); }
|
2011-09-23 00:45:40 +08:00
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// addRetReg - Adds a register to the set of return-value registers.
|
2011-09-23 00:45:46 +08:00
|
|
|
void addRetReg(unsigned Reg) {
|
2011-09-24 01:15:53 +08:00
|
|
|
if (!RegRets.count(Reg)) {
|
|
|
|
RegRets.insert(Reg);
|
2011-09-23 00:45:46 +08:00
|
|
|
std::string name;
|
|
|
|
name = "%ret";
|
2011-09-24 01:15:53 +08:00
|
|
|
name += utostr(RegRets.size() - 1);
|
|
|
|
RegNames[Reg] = name;
|
2011-09-23 00:45:46 +08:00
|
|
|
}
|
|
|
|
}
|
2011-09-23 00:45:40 +08:00
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// addArgReg - Adds a register to the set of function argument registers.
|
2011-09-23 00:45:46 +08:00
|
|
|
void addArgReg(unsigned Reg) {
|
2011-09-24 01:15:53 +08:00
|
|
|
RegArgs.insert(Reg);
|
2011-09-23 00:45:46 +08:00
|
|
|
std::string name;
|
|
|
|
name = "%param";
|
2011-09-24 01:15:53 +08:00
|
|
|
name += utostr(RegArgs.size() - 1);
|
|
|
|
RegNames[Reg] = name;
|
2011-09-23 00:45:46 +08:00
|
|
|
}
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// addVirtualRegister - Adds a virtual register to the set of all used
|
|
|
|
/// registers in the function.
|
2011-09-23 00:45:46 +08:00
|
|
|
void addVirtualRegister(const TargetRegisterClass *TRC, unsigned Reg) {
|
|
|
|
std::string name;
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
// Do not count registers that are argument/return registers.
|
|
|
|
if (!RegRets.count(Reg) && !RegArgs.count(Reg)) {
|
|
|
|
UsedRegs[TRC].push_back(Reg);
|
2011-09-23 00:45:46 +08:00
|
|
|
if (TRC == PTX::RegPredRegisterClass)
|
|
|
|
name = "%p";
|
|
|
|
else if (TRC == PTX::RegI16RegisterClass)
|
|
|
|
name = "%rh";
|
|
|
|
else if (TRC == PTX::RegI32RegisterClass)
|
|
|
|
name = "%r";
|
|
|
|
else if (TRC == PTX::RegI64RegisterClass)
|
|
|
|
name = "%rd";
|
|
|
|
else if (TRC == PTX::RegF32RegisterClass)
|
|
|
|
name = "%f";
|
|
|
|
else if (TRC == PTX::RegF64RegisterClass)
|
|
|
|
name = "%fd";
|
|
|
|
else
|
|
|
|
llvm_unreachable("Invalid register class");
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
name += utostr(UsedRegs[TRC].size() - 1);
|
|
|
|
RegNames[Reg] = name;
|
2011-09-23 00:45:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// getRegisterName - Returns the name of the specified virtual register. This
|
|
|
|
/// name is used during PTX emission.
|
2011-09-23 00:45:40 +08:00
|
|
|
std::string getRegisterName(unsigned Reg) const {
|
2011-09-24 01:15:53 +08:00
|
|
|
if (RegNames.count(Reg))
|
|
|
|
return RegNames.lookup(Reg);
|
2011-09-23 00:45:46 +08:00
|
|
|
else if (Reg == PTX::NoRegister)
|
|
|
|
return "%noreg";
|
2011-09-23 00:45:40 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("Register not in register name map");
|
|
|
|
}
|
|
|
|
|
2011-09-24 01:15:53 +08:00
|
|
|
/// getNumRegistersForClass - Returns the number of virtual registers that are
|
|
|
|
/// used for the specified register class.
|
2011-09-23 00:45:40 +08:00
|
|
|
unsigned getNumRegistersForClass(const TargetRegisterClass *TRC) const {
|
2011-09-24 01:15:53 +08:00
|
|
|
return UsedRegs.lookup(TRC).size();
|
2011-09-23 00:45:40 +08:00
|
|
|
}
|
|
|
|
|
2010-11-08 11:00:52 +08:00
|
|
|
}; // class PTXMachineFunctionInfo
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif // PTX_MACHINE_FUNCTION_INFO_H
|