blob: 0a860b5c1af7d0e0976ded6ca842bdb68eba3747 [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) {
34 reg_arg.reserve(32);
35 reg_local_var.reserve(64);
36 }
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
56 typedef std::vector<unsigned>::const_iterator reg_iterator;
57
58 bool argRegEmpty() const { return reg_arg.empty(); }
59 reg_iterator argRegBegin() const { return reg_arg.begin(); }
60 reg_iterator argRegEnd() const { return reg_arg.end(); }
61
62 bool localVarRegEmpty() const { return reg_local_var.empty(); }
63 reg_iterator localVarRegBegin() const { return reg_local_var.begin(); }
64 reg_iterator localVarRegEnd() const { return reg_local_var.end(); }
65
66 unsigned retReg() const { return reg_ret; }
67
68 bool isArgReg(unsigned reg) const {
69 return std::binary_search(reg_arg.begin(), reg_arg.end(), reg);
70 }
71
72 bool isLocalVarReg(unsigned reg) const {
73 return std::binary_search(reg_local_var.begin(), reg_local_var.end(), reg);
74 }
75}; // class PTXMachineFunctionInfo
76} // namespace llvm
77
78#endif // PTX_MACHINE_FUNCTION_INFO_H