blob: 92e7728b4f8b55153bff9b1c077642b1820933b3 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- PTXParamManager.h - Manager for .param variables --------*- C++ -*-===//
Justin Holewinski27f08fc2011-09-23 14:18:22 +00002//
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 Holewinskia5745562011-09-23 17:59:11 +000019#include "llvm/ADT/SmallVector.h"
Chris Lattnere59b0e72012-03-19 23:31:01 +000020#include <string>
Justin Holewinski27f08fc2011-09-23 14:18:22 +000021
22namespace llvm {
23
24/// PTXParamManager - This class manages all .param variables defined for a
25/// particular function.
26class PTXParamManager {
27private:
28
29 /// PTXParamType - Type of a .param variable
30 enum PTXParamType {
31 PTX_PARAM_TYPE_ARGUMENT,
32 PTX_PARAM_TYPE_RETURN,
33 PTX_PARAM_TYPE_LOCAL
34 };
35
36 /// PTXParam - Definition of a PTX .param variable
37 struct PTXParam {
38 PTXParamType Type;
39 unsigned Size;
40 std::string Name;
41 };
42
43 DenseMap<unsigned, PTXParam> AllParams;
Justin Holewinskia5745562011-09-23 17:59:11 +000044 SmallVector<unsigned, 4> ArgumentParams;
45 SmallVector<unsigned, 4> ReturnParams;
46 SmallVector<unsigned, 4> LocalParams;
Justin Holewinski27f08fc2011-09-23 14:18:22 +000047
48public:
49
Justin Holewinskia5745562011-09-23 17:59:11 +000050 typedef SmallVector<unsigned, 4>::const_iterator param_iterator;
Justin Holewinski27f08fc2011-09-23 14:18:22 +000051
52 PTXParamManager();
53
54 param_iterator arg_begin() const { return ArgumentParams.begin(); }
55 param_iterator arg_end() const { return ArgumentParams.end(); }
56 param_iterator ret_begin() const { return ReturnParams.begin(); }
57 param_iterator ret_end() const { return ReturnParams.end(); }
58 param_iterator local_begin() const { return LocalParams.begin(); }
59 param_iterator local_end() const { return LocalParams.end(); }
60
61 /// addArgumentParam - Returns a new .param used as an argument.
62 unsigned addArgumentParam(unsigned Size);
63
64 /// addReturnParam - Returns a new .param used as a return argument.
65 unsigned addReturnParam(unsigned Size);
66
67 /// addLocalParam - Returns a new .param used as a local .param variable.
68 unsigned addLocalParam(unsigned Size);
69
70 /// getParamName - Returns the name of the parameter as a string.
Benjamin Kramer8adae0c2011-09-28 04:08:02 +000071 const std::string &getParamName(unsigned Param) const {
Justin Holewinski27f08fc2011-09-23 14:18:22 +000072 assert(AllParams.count(Param) == 1 && "Param has not been defined!");
Benjamin Kramer8adae0c2011-09-28 04:08:02 +000073 return AllParams.find(Param)->second.Name;
Justin Holewinski27f08fc2011-09-23 14:18:22 +000074 }
75
76 /// getParamSize - Returns the size of the parameter in bits.
77 unsigned getParamSize(unsigned Param) const {
78 assert(AllParams.count(Param) == 1 && "Param has not been defined!");
Benjamin Kramer8adae0c2011-09-28 04:08:02 +000079 return AllParams.find(Param)->second.Size;
Justin Holewinski27f08fc2011-09-23 14:18:22 +000080 }
81
82};
83
84}
85
86#endif
87