1 //===- PTXMachineFuctionInfo.h - PTX machine function info -------*- C++ -*-==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file declares PTX-specific per-machine-function information. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef PTX_MACHINE_FUNCTION_INFO_H 15 #define PTX_MACHINE_FUNCTION_INFO_H 16 17 #include "PTX.h" 18 #include "llvm/ADT/DenseSet.h" 19 #include "llvm/CodeGen/MachineFunction.h" 20 21 namespace llvm { 22 /// PTXMachineFunctionInfo - This class is derived from MachineFunction and 23 /// contains private PTX target-specific information for each MachineFunction. 24 /// 25 class PTXMachineFunctionInfo : public MachineFunctionInfo { 26 private: 27 bool is_kernel; 28 std::vector<unsigned> reg_arg, reg_local_var; 29 std::vector<unsigned> reg_ret; 30 bool _isDoneAddArg; 31 32 public: PTXMachineFunctionInfo(MachineFunction & MF)33 PTXMachineFunctionInfo(MachineFunction &MF) 34 : is_kernel(false), reg_ret(PTX::NoRegister), _isDoneAddArg(false) { 35 reg_arg.reserve(8); 36 reg_local_var.reserve(32); 37 } 38 39 void setKernel(bool _is_kernel=true) { is_kernel = _is_kernel; } 40 addArgReg(unsigned reg)41 void addArgReg(unsigned reg) { reg_arg.push_back(reg); } addLocalVarReg(unsigned reg)42 void addLocalVarReg(unsigned reg) { reg_local_var.push_back(reg); } addRetReg(unsigned reg)43 void addRetReg(unsigned reg) { 44 if (!isRetReg(reg)) { 45 reg_ret.push_back(reg); 46 } 47 } 48 doneAddArg(void)49 void doneAddArg(void) { 50 _isDoneAddArg = true; 51 } doneAddLocalVar(void)52 void doneAddLocalVar(void) {} 53 isKernel()54 bool isKernel() const { return is_kernel; } 55 56 typedef std::vector<unsigned>::const_iterator reg_iterator; 57 typedef std::vector<unsigned>::const_reverse_iterator reg_reverse_iterator; 58 typedef std::vector<unsigned>::const_iterator ret_iterator; 59 argRegEmpty()60 bool argRegEmpty() const { return reg_arg.empty(); } getNumArg()61 int getNumArg() const { return reg_arg.size(); } argRegBegin()62 reg_iterator argRegBegin() const { return reg_arg.begin(); } argRegEnd()63 reg_iterator argRegEnd() const { return reg_arg.end(); } argRegReverseBegin()64 reg_reverse_iterator argRegReverseBegin() const { return reg_arg.rbegin(); } argRegReverseEnd()65 reg_reverse_iterator argRegReverseEnd() const { return reg_arg.rend(); } 66 localVarRegEmpty()67 bool localVarRegEmpty() const { return reg_local_var.empty(); } localVarRegBegin()68 reg_iterator localVarRegBegin() const { return reg_local_var.begin(); } localVarRegEnd()69 reg_iterator localVarRegEnd() const { return reg_local_var.end(); } 70 retRegEmpty()71 bool retRegEmpty() const { return reg_ret.empty(); } getNumRet()72 int getNumRet() const { return reg_ret.size(); } retRegBegin()73 ret_iterator retRegBegin() const { return reg_ret.begin(); } retRegEnd()74 ret_iterator retRegEnd() const { return reg_ret.end(); } 75 isArgReg(unsigned reg)76 bool isArgReg(unsigned reg) const { 77 return std::find(reg_arg.begin(), reg_arg.end(), reg) != reg_arg.end(); 78 } 79 isRetReg(unsigned reg)80 bool isRetReg(unsigned reg) const { 81 return std::find(reg_ret.begin(), reg_ret.end(), reg) != reg_ret.end(); 82 } 83 isLocalVarReg(unsigned reg)84 bool isLocalVarReg(unsigned reg) const { 85 return std::find(reg_local_var.begin(), reg_local_var.end(), reg) 86 != reg_local_var.end(); 87 } 88 }; // class PTXMachineFunctionInfo 89 } // namespace llvm 90 91 #endif // PTX_MACHINE_FUNCTION_INFO_H 92