• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- PTXParamManager.cpp - 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 implements the PTXParamManager class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "PTX.h"
15 #include "PTXParamManager.h"
16 #include "llvm/ADT/StringExtras.h"
17 
18 using namespace llvm;
19 
PTXParamManager()20 PTXParamManager::PTXParamManager() {
21 }
22 
addArgumentParam(unsigned Size)23 unsigned PTXParamManager::addArgumentParam(unsigned Size) {
24   PTXParam Param;
25   Param.Type = PTX_PARAM_TYPE_ARGUMENT;
26   Param.Size = Size;
27 
28   std::string Name;
29   Name = "__param_";
30   Name += utostr(ArgumentParams.size()+1);
31   Param.Name = Name;
32 
33   unsigned Index = AllParams.size();
34   AllParams[Index] = Param;
35   ArgumentParams.push_back(Index);
36 
37   return Index;
38 }
39 
addReturnParam(unsigned Size)40 unsigned PTXParamManager::addReturnParam(unsigned Size) {
41   PTXParam Param;
42   Param.Type = PTX_PARAM_TYPE_RETURN;
43   Param.Size = Size;
44 
45   std::string Name;
46   Name = "__ret_";
47   Name += utostr(ReturnParams.size()+1);
48   Param.Name = Name;
49 
50   unsigned Index = AllParams.size();
51   AllParams[Index] = Param;
52   ReturnParams.push_back(Index);
53 
54   return Index;
55 }
56 
addLocalParam(unsigned Size)57 unsigned PTXParamManager::addLocalParam(unsigned Size) {
58   PTXParam Param;
59   Param.Type = PTX_PARAM_TYPE_LOCAL;
60   Param.Size = Size;
61 
62   std::string Name;
63   Name = "__localparam_";
64   Name += utostr(LocalParams.size()+1);
65   Param.Name = Name;
66 
67   unsigned Index = AllParams.size();
68   AllParams[Index] = Param;
69   LocalParams.push_back(Index);
70 
71   return Index;
72 }
73 
74