• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- PTXParamManager.h - Manager for .param variables ----------*- 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 defines the PTXParamManager class, which manages all defined .param
11 // variables for a particular function.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef PTX_PARAM_MANAGER_H
16 #define PTX_PARAM_MANAGER_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20 
21 namespace llvm {
22 
23 /// PTXParamManager - This class manages all .param variables defined for a
24 /// particular function.
25 class PTXParamManager {
26 private:
27 
28   /// PTXParamType - Type of a .param variable
29   enum PTXParamType {
30     PTX_PARAM_TYPE_ARGUMENT,
31     PTX_PARAM_TYPE_RETURN,
32     PTX_PARAM_TYPE_LOCAL
33   };
34 
35   /// PTXParam - Definition of a PTX .param variable
36   struct PTXParam {
37     PTXParamType  Type;
38     unsigned      Size;
39     std::string   Name;
40   };
41 
42   DenseMap<unsigned, PTXParam> AllParams;
43   SmallVector<unsigned, 4> ArgumentParams;
44   SmallVector<unsigned, 4> ReturnParams;
45   SmallVector<unsigned, 4> LocalParams;
46 
47 public:
48 
49   typedef SmallVector<unsigned, 4>::const_iterator param_iterator;
50 
51   PTXParamManager();
52 
arg_begin()53   param_iterator arg_begin() const { return ArgumentParams.begin(); }
arg_end()54   param_iterator arg_end() const { return ArgumentParams.end(); }
ret_begin()55   param_iterator ret_begin() const { return ReturnParams.begin(); }
ret_end()56   param_iterator ret_end() const { return ReturnParams.end(); }
local_begin()57   param_iterator local_begin() const { return LocalParams.begin(); }
local_end()58   param_iterator local_end() const { return LocalParams.end(); }
59 
60   /// addArgumentParam - Returns a new .param used as an argument.
61   unsigned addArgumentParam(unsigned Size);
62 
63   /// addReturnParam - Returns a new .param used as a return argument.
64   unsigned addReturnParam(unsigned Size);
65 
66   /// addLocalParam - Returns a new .param used as a local .param variable.
67   unsigned addLocalParam(unsigned Size);
68 
69   /// getParamName - Returns the name of the parameter as a string.
getParamName(unsigned Param)70   const std::string &getParamName(unsigned Param) const {
71     assert(AllParams.count(Param) == 1 && "Param has not been defined!");
72     return AllParams.find(Param)->second.Name;
73   }
74 
75   /// getParamSize - Returns the size of the parameter in bits.
getParamSize(unsigned Param)76   unsigned getParamSize(unsigned Param) const {
77     assert(AllParams.count(Param) == 1 && "Param has not been defined!");
78     return AllParams.find(Param)->second.Size;
79   }
80 
81 };
82 
83 }
84 
85 #endif
86 
87