Justin Holewinski | 27f08fc | 2011-09-23 14:18:22 +0000 | [diff] [blame] | 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" |
Justin Holewinski | a574556 | 2011-09-23 17:59:11 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallVector.h" |
Justin Holewinski | 27f08fc | 2011-09-23 14:18:22 +0000 | [diff] [blame] | 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; |
Justin Holewinski | a574556 | 2011-09-23 17:59:11 +0000 | [diff] [blame] | 43 | SmallVector<unsigned, 4> ArgumentParams; |
| 44 | SmallVector<unsigned, 4> ReturnParams; |
| 45 | SmallVector<unsigned, 4> LocalParams; |
Justin Holewinski | 27f08fc | 2011-09-23 14:18:22 +0000 | [diff] [blame] | 46 | |
| 47 | public: |
| 48 | |
Justin Holewinski | a574556 | 2011-09-23 17:59:11 +0000 | [diff] [blame] | 49 | typedef SmallVector<unsigned, 4>::const_iterator param_iterator; |
Justin Holewinski | 27f08fc | 2011-09-23 14:18:22 +0000 | [diff] [blame] | 50 | |
| 51 | PTXParamManager(); |
| 52 | |
| 53 | param_iterator arg_begin() const { return ArgumentParams.begin(); } |
| 54 | param_iterator arg_end() const { return ArgumentParams.end(); } |
| 55 | param_iterator ret_begin() const { return ReturnParams.begin(); } |
| 56 | param_iterator ret_end() const { return ReturnParams.end(); } |
| 57 | param_iterator local_begin() const { return LocalParams.begin(); } |
| 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. |
Benjamin Kramer | 8adae0c | 2011-09-28 04:08:02 +0000 | [diff] [blame] | 70 | const std::string &getParamName(unsigned Param) const { |
Justin Holewinski | 27f08fc | 2011-09-23 14:18:22 +0000 | [diff] [blame] | 71 | assert(AllParams.count(Param) == 1 && "Param has not been defined!"); |
Benjamin Kramer | 8adae0c | 2011-09-28 04:08:02 +0000 | [diff] [blame] | 72 | return AllParams.find(Param)->second.Name; |
Justin Holewinski | 27f08fc | 2011-09-23 14:18:22 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /// getParamSize - Returns the size of the parameter in bits. |
| 76 | unsigned getParamSize(unsigned Param) const { |
| 77 | assert(AllParams.count(Param) == 1 && "Param has not been defined!"); |
Benjamin Kramer | 8adae0c | 2011-09-28 04:08:02 +0000 | [diff] [blame] | 78 | return AllParams.find(Param)->second.Size; |
Justin Holewinski | 27f08fc | 2011-09-23 14:18:22 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | }; |
| 82 | |
| 83 | } |
| 84 | |
| 85 | #endif |
| 86 | |