LLVM: lib/Target/NVPTX/NVPTXLowerAlloca.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
33
34using namespace llvm;
35
36namespace {
39
40public:
41 static char ID;
42 NVPTXLowerAlloca() : FunctionPass(ID) {}
43 StringRef getPassName() const override {
44 return "convert address space of alloca'ed memory to local";
45 }
46};
47}
48
49char NVPTXLowerAlloca::ID = 1;
50
51INITIALIZE_PASS(NVPTXLowerAlloca, "nvptx-lower-alloca", "Lower Alloca", false,
52 false)
53
54
55
56
58 if (skipFunction(F))
59 return false;
60
62 for (auto &BB : F)
63 for (auto &I : BB) {
66
69 unsigned AllocAddrSpace = AllocInstPtrTy->getAddressSpace();
72 "AllocaInst can only be in Generic or Local address space for "
73 "NVPTX.");
74
75 Instruction *AllocaInLocalAS = allocaInst;
76 auto ETy = allocaInst->getAllocatedType();
77
78
79
80
81
82
83
84
85
86
89 allocaInst,
91 ASCastToLocalAS->insertAfter(allocaInst->getIterator());
92 AllocaInLocalAS = ASCastToLocalAS;
93 }
94
96 AllocaInLocalAS,
98 AllocaInGenericAS->insertAfter(AllocaInLocalAS->getIterator());
99
101
102
103
104
105
107 if (LI && LI->getPointerOperand() == allocaInst &&
108 !LI->isVolatile()) {
109 LI->setOperand(LI->getPointerOperandIndex(), AllocaInGenericAS);
110 continue;
111 }
113 if (SI && SI->getPointerOperand() == allocaInst &&
114 ->isVolatile()) {
115 SI->setOperand(SI->getPointerOperandIndex(), AllocaInGenericAS);
116 continue;
117 }
119 if (GI && GI->getPointerOperand() == allocaInst) {
120 GI->setOperand(GI->getPointerOperandIndex(), AllocaInGenericAS);
121 continue;
122 }
124 if (BI && BI->getOperand(0) == allocaInst) {
125 BI->setOperand(0, AllocaInGenericAS);
126 continue;
127 }
128 }
129 }
130 }
132}
133
135 return new NVPTXLowerAlloca();
136}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool runOnFunction(Function &F, bool PostInlining)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This class represents a conversion between pointers from one address space to another.
FunctionPass class - This class is used to implement most global optimizations.
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
A Use represents the edge between a Value definition and its users.
self_iterator getIterator()
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
FunctionPass * createNVPTXLowerAllocaPass()
Definition NVPTXLowerAlloca.cpp:134
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.