Mercurial > hg > CbC > CbC_llvm
comparison lib/Target/NVPTX/NVPTXLowerKernelArgs.cpp @ 100:7d135dc70f03 LLVM 3.9
LLVM 3.9
author | Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Jan 2016 22:53:40 +0900 |
parents | afa8332a0e37 |
children |
comparison
equal
deleted
inserted
replaced
96:6418606d0ead | 100:7d135dc70f03 |
---|---|
126 | 126 |
127 INITIALIZE_PASS(NVPTXLowerKernelArgs, "nvptx-lower-kernel-args", | 127 INITIALIZE_PASS(NVPTXLowerKernelArgs, "nvptx-lower-kernel-args", |
128 "Lower kernel arguments (NVPTX)", false, false) | 128 "Lower kernel arguments (NVPTX)", false, false) |
129 | 129 |
130 // ============================================================================= | 130 // ============================================================================= |
131 // If the function had a byval struct ptr arg, say foo(%struct.x *byval %d), | 131 // If the function had a byval struct ptr arg, say foo(%struct.x* byval %d), |
132 // then add the following instructions to the first basic block: | 132 // then add the following instructions to the first basic block: |
133 // | 133 // |
134 // %temp = alloca %struct.x, align 8 | 134 // %temp = alloca %struct.x, align 8 |
135 // %tempd = addrspacecast %struct.x* %d to %struct.x addrspace(101)* | 135 // %tempd = addrspacecast %struct.x* %d to %struct.x addrspace(101)* |
136 // %tv = load %struct.x addrspace(101)* %tempd | 136 // %tv = load %struct.x addrspace(101)* %tempd |
171 if (Argument *Arg = dyn_cast<Argument>(Ptr)) { | 171 if (Argument *Arg = dyn_cast<Argument>(Ptr)) { |
172 // Insert at the functon entry if Ptr is an argument. | 172 // Insert at the functon entry if Ptr is an argument. |
173 InsertPt = Arg->getParent()->getEntryBlock().begin(); | 173 InsertPt = Arg->getParent()->getEntryBlock().begin(); |
174 } else { | 174 } else { |
175 // Insert right after Ptr if Ptr is an instruction. | 175 // Insert right after Ptr if Ptr is an instruction. |
176 InsertPt = cast<Instruction>(Ptr); | 176 InsertPt = ++cast<Instruction>(Ptr)->getIterator(); |
177 ++InsertPt; | |
178 assert(InsertPt != InsertPt->getParent()->end() && | 177 assert(InsertPt != InsertPt->getParent()->end() && |
179 "We don't call this function with Ptr being a terminator."); | 178 "We don't call this function with Ptr being a terminator."); |
180 } | 179 } |
181 | 180 |
182 Instruction *PtrInGlobal = new AddrSpaceCastInst( | 181 Instruction *PtrInGlobal = new AddrSpaceCastInst( |
183 Ptr, PointerType::get(Ptr->getType()->getPointerElementType(), | 182 Ptr, PointerType::get(Ptr->getType()->getPointerElementType(), |
184 ADDRESS_SPACE_GLOBAL), | 183 ADDRESS_SPACE_GLOBAL), |
185 Ptr->getName(), InsertPt); | 184 Ptr->getName(), &*InsertPt); |
186 Value *PtrInGeneric = new AddrSpaceCastInst(PtrInGlobal, Ptr->getType(), | 185 Value *PtrInGeneric = new AddrSpaceCastInst(PtrInGlobal, Ptr->getType(), |
187 Ptr->getName(), InsertPt); | 186 Ptr->getName(), &*InsertPt); |
188 // Replace with PtrInGeneric all uses of Ptr except PtrInGlobal. | 187 // Replace with PtrInGeneric all uses of Ptr except PtrInGlobal. |
189 Ptr->replaceAllUsesWith(PtrInGeneric); | 188 Ptr->replaceAllUsesWith(PtrInGeneric); |
190 PtrInGlobal->setOperand(0, Ptr); | 189 PtrInGlobal->setOperand(0, Ptr); |
191 } | 190 } |
192 | 191 |