blob: b5b3c3be17b8a8eebf9126c82db49072959c8172 [file] [log] [blame]
Che-Liang Chiou3278c422010-11-08 03:00:52 +00001//===- 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/CodeGen/MachineFunction.h"
19
20namespace llvm {
21/// PTXMachineFunctionInfo - This class is derived from MachineFunction and
22/// contains private PTX target-specific information for each MachineFunction.
23///
24class PTXMachineFunctionInfo : public MachineFunctionInfo {
25private:
26 bool is_kernel;
27 std::vector<unsigned> reg_arg, reg_local_var;
28 unsigned reg_ret;
29 bool _isDoneAddArg;
30
31public:
32 PTXMachineFunctionInfo(MachineFunction &MF)
33 : is_kernel(false), reg_ret(PTX::NoRegister), _isDoneAddArg(false) {
Che-Liang Chiou8e5d01c2011-02-10 12:01:24 +000034 reg_arg.reserve(8);
35 reg_local_var.reserve(32);
Che-Liang Chiou3278c422010-11-08 03:00:52 +000036 }
37
38 void setKernel(bool _is_kernel=true) { is_kernel = _is_kernel; }
39
40 void addArgReg(unsigned reg) { reg_arg.push_back(reg); }
41 void addLocalVarReg(unsigned reg) { reg_local_var.push_back(reg); }
42 void setRetReg(unsigned reg) { reg_ret = reg; }
43
44 void doneAddArg(void) {
45 std::sort(reg_arg.begin(), reg_arg.end());
46 _isDoneAddArg = true;
47 }
48 void doneAddLocalVar(void) {
49 std::sort(reg_local_var.begin(), reg_local_var.end());
50 }
51
52 bool isDoneAddArg(void) { return _isDoneAddArg; }
53
54 bool isKernel() const { return is_kernel; }
55
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000056 typedef std::vector<unsigned>::const_iterator reg_iterator;
57 typedef std::vector<unsigned>::const_reverse_iterator reg_reverse_iterator;
Che-Liang Chiou3278c422010-11-08 03:00:52 +000058
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000059 bool argRegEmpty() const { return reg_arg.empty(); }
60 int getNumArg() const { return reg_arg.size(); }
Che-Liang Chiou3278c422010-11-08 03:00:52 +000061 reg_iterator argRegBegin() const { return reg_arg.begin(); }
62 reg_iterator argRegEnd() const { return reg_arg.end(); }
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000063 reg_reverse_iterator argRegReverseBegin() const { return reg_arg.rbegin(); }
64 reg_reverse_iterator argRegReverseEnd() const { return reg_arg.rend(); }
Che-Liang Chiou3278c422010-11-08 03:00:52 +000065
Che-Liang Chiouf48817c2011-03-02 07:36:48 +000066 bool localVarRegEmpty() const { return reg_local_var.empty(); }
Che-Liang Chiou3278c422010-11-08 03:00:52 +000067 reg_iterator localVarRegBegin() const { return reg_local_var.begin(); }
68 reg_iterator localVarRegEnd() const { return reg_local_var.end(); }
69
70 unsigned retReg() const { return reg_ret; }
71
72 bool isArgReg(unsigned reg) const {
73 return std::binary_search(reg_arg.begin(), reg_arg.end(), reg);
74 }
75
76 bool isLocalVarReg(unsigned reg) const {
77 return std::binary_search(reg_local_var.begin(), reg_local_var.end(), reg);
78 }
79}; // class PTXMachineFunctionInfo
80} // namespace llvm
81
82#endif // PTX_MACHINE_FUNCTION_INFO_H