llvm.org GIT mirror llvm / 4ed9d9e
[opaque pointer types] Update LoadInst creation APIs to consistently accept a return-type argument. Note: this also adds a new C API and soft-deprecates the old C API. Differential Revision: https://reviews.llvm.org/D56558 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351123 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 8 months ago
5 changed file(s) with 118 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
13511351 return Insert(new AllocaInst(Ty, DL.getAllocaAddrSpace(), ArraySize), Name);
13521352 }
13531353
1354 /// Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
1354 /// Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of
13551355 /// converting the string to 'bool' for the isVolatile parameter.
1356 LoadInst *CreateLoad(Value *Ptr, const char *Name) {
1357 return Insert(new LoadInst(Ptr), Name);
1358 }
1359
1360 LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
1361 return Insert(new LoadInst(Ptr), Name);
1356 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const char *Name) {
1357 return Insert(new LoadInst(Ty, Ptr), Name);
13621358 }
13631359
13641360 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
13651361 return Insert(new LoadInst(Ty, Ptr), Name);
13661362 }
13671363
1364 LoadInst *CreateLoad(Type *Ty, Value *Ptr, bool isVolatile,
1365 const Twine &Name = "") {
1366 return Insert(new LoadInst(Ty, Ptr, Twine(), isVolatile), Name);
1367 }
1368
1369 // Deprecated [opaque pointer types]
1370 LoadInst *CreateLoad(Value *Ptr, const char *Name) {
1371 return CreateLoad(Ptr->getType()->getPointerElementType(), Ptr, Name);
1372 }
1373
1374 // Deprecated [opaque pointer types]
1375 LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
1376 return CreateLoad(Ptr->getType()->getPointerElementType(), Ptr, Name);
1377 }
1378
1379 // Deprecated [opaque pointer types]
13681380 LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
1369 return Insert(new LoadInst(Ptr, nullptr, isVolatile), Name);
1381 return CreateLoad(Ptr->getType()->getPointerElementType(), Ptr, isVolatile,
1382 Name);
13701383 }
13711384
13721385 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
13761389 /// Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
13771390 /// correctly, instead of converting the string to 'bool' for the isVolatile
13781391 /// parameter.
1379 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
1380 LoadInst *LI = CreateLoad(Ptr, Name);
1392 LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
1393 const char *Name) {
1394 LoadInst *LI = CreateLoad(Ty, Ptr, Name);
13811395 LI->setAlignment(Align);
13821396 return LI;
13831397 }
1398 LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
1399 const Twine &Name = "") {
1400 LoadInst *LI = CreateLoad(Ty, Ptr, Name);
1401 LI->setAlignment(Align);
1402 return LI;
1403 }
1404 LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
1405 bool isVolatile, const Twine &Name = "") {
1406 LoadInst *LI = CreateLoad(Ty, Ptr, isVolatile, Name);
1407 LI->setAlignment(Align);
1408 return LI;
1409 }
1410
1411 // Deprecated [opaque pointer types]
1412 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
1413 return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
1414 Align, Name);
1415 }
1416 // Deprecated [opaque pointer types]
13841417 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align,
13851418 const Twine &Name = "") {
1386 LoadInst *LI = CreateLoad(Ptr, Name);
1387 LI->setAlignment(Align);
1388 return LI;
1389 }
1419 return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
1420 Align, Name);
1421 }
1422 // Deprecated [opaque pointer types]
13901423 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile,
13911424 const Twine &Name = "") {
1392 LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
1393 LI->setAlignment(Align);
1394 return LI;
1425 return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
1426 Align, isVolatile, Name);
13951427 }
13961428
13971429 StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align,
174174 LoadInst *cloneImpl() const;
175175
176176 public:
177 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
178 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
179 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
177 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr = "",
180178 Instruction *InsertBefore = nullptr);
181 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
182 Instruction *InsertBefore = nullptr)
183 : LoadInst(cast(Ptr->getType())->getElementType(), Ptr,
184 NameStr, isVolatile, InsertBefore) {}
185 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
179 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
180 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
181 Instruction *InsertBefore = nullptr);
182 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
186183 BasicBlock *InsertAtEnd);
187 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
188 Instruction *InsertBefore = nullptr)
189 : LoadInst(cast(Ptr->getType())->getElementType(), Ptr,
190 NameStr, isVolatile, Align, InsertBefore) {}
191184 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
192185 unsigned Align, Instruction *InsertBefore = nullptr);
193 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
186 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
194187 unsigned Align, BasicBlock *InsertAtEnd);
195 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
196 AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
197 Instruction *InsertBefore = nullptr)
198 : LoadInst(cast(Ptr->getType())->getElementType(), Ptr,
199 NameStr, isVolatile, Align, Order, SSID, InsertBefore) {}
200188 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
201189 unsigned Align, AtomicOrdering Order,
202190 SyncScope::ID SSID = SyncScope::System,
203191 Instruction *InsertBefore = nullptr);
204 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
192 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
205193 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
206194 BasicBlock *InsertAtEnd);
207 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
208 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
209 LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
210 bool isVolatile = false, Instruction *InsertBefore = nullptr);
211 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
212 bool isVolatile = false,
195
196 // Deprecated [opaque pointer types]
197 explicit LoadInst(Value *Ptr, const Twine &NameStr = "",
213198 Instruction *InsertBefore = nullptr)
214 : LoadInst(cast(Ptr->getType())->getElementType(), Ptr,
215 NameStr, isVolatile, InsertBefore) {}
216 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
217 BasicBlock *InsertAtEnd);
199 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
200 InsertBefore) {}
201 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd)
202 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
203 InsertAtEnd) {}
204 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
205 Instruction *InsertBefore = nullptr)
206 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
207 isVolatile, InsertBefore) {}
208 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
209 BasicBlock *InsertAtEnd)
210 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
211 isVolatile, InsertAtEnd) {}
212 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
213 Instruction *InsertBefore = nullptr)
214 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
215 isVolatile, Align, InsertBefore) {}
216 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
217 BasicBlock *InsertAtEnd)
218 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
219 isVolatile, Align, InsertAtEnd) {}
220 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
221 AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
222 Instruction *InsertBefore = nullptr)
223 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
224 isVolatile, Align, Order, SSID, InsertBefore) {}
225 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
226 AtomicOrdering Order, SyncScope::ID SSID, BasicBlock *InsertAtEnd)
227 : LoadInst(Ptr->getType()->getPointerElementType(), Ptr, NameStr,
228 isVolatile, Align, Order, SSID, InsertAtEnd) {}
218229
219230 /// Return true if this is a load from a volatile memory location.
220231 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
35963596 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
35973597 LLVMValueRef Val, const char *Name);
35983598 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
3599 // LLVMBuildLoad is deprecated in favor of LLVMBuildLoad2, in preparation for
3600 // opaque pointer types.
35993601 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
36003602 const char *Name);
3603 LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
3604 LLVMValueRef PointerVal, const char *Name);
36013605 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
36023606 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
36033607 LLVMValueRef *Indices, unsigned NumIndices,
33453345
33463346 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
33473347 const char *Name) {
3348 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
3348 Value *V = unwrap(PointerVal);
3349 PointerType *Ty = cast(V->getType());
3350
3351 return wrap(unwrap(B)->CreateLoad(Ty->getElementType(), V, Name));
3352 }
3353
3354 LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef B, LLVMTypeRef Ty,
3355 LLVMValueRef PointerVal, const char *Name) {
3356 return wrap(unwrap(B)->CreateLoad(unwrap(Ty), unwrap(PointerVal), Name));
33493357 }
33503358
33513359 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
11371137 "Alignment required for atomic load");
11381138 }
11391139
1140 LoadInst::LoadInst(Value *Ptr, const Twine &Name, Instruction *InsertBef)
1141 : LoadInst(Ptr, Name, /*isVolatile=*/false, InsertBef) {}
1142
1143 LoadInst::LoadInst(Value *Ptr, const Twine &Name, BasicBlock *InsertAE)
1144 : LoadInst(Ptr, Name, /*isVolatile=*/false, InsertAE) {}
1140 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
1141 Instruction *InsertBef)
1142 : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertBef) {}
1143
1144 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
1145 BasicBlock *InsertAE)
1146 : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertAE) {}
11451147
11461148 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
11471149 Instruction *InsertBef)
11481150 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertBef) {}
11491151
1150 LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile,
1152 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
11511153 BasicBlock *InsertAE)
1152 : LoadInst(Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {}
1154 : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {}
11531155
11541156 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
11551157 unsigned Align, Instruction *InsertBef)
11561158 : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
11571159 SyncScope::System, InsertBef) {}
11581160
1159 LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile,
1161 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
11601162 unsigned Align, BasicBlock *InsertAE)
1161 : LoadInst(Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
1163 : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
11621164 SyncScope::System, InsertAE) {}
11631165
11641166 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
11731175 setName(Name);
11741176 }
11751177
1176 LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile,
1177 unsigned Align, AtomicOrdering Order,
1178 SyncScope::ID SSID,
1178 LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
1179 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
11791180 BasicBlock *InsertAE)
1180 : UnaryInstruction(cast(Ptr->getType())->getElementType(),
1181 Load, Ptr, InsertAE) {
1181 : UnaryInstruction(Ty, Load, Ptr, InsertAE) {
1182 assert(Ty == cast(Ptr->getType())->getElementType());
11821183 setVolatile(isVolatile);
11831184 setAlignment(Align);
11841185 setAtomic(Order, SSID);
11851186 AssertOK();
11861187 setName(Name);
1187 }
1188
1189 LoadInst::LoadInst(Value *Ptr, const char *Name, Instruction *InsertBef)
1190 : UnaryInstruction(cast(Ptr->getType())->getElementType(),
1191 Load, Ptr, InsertBef) {
1192 setVolatile(false);
1193 setAlignment(0);
1194 setAtomic(AtomicOrdering::NotAtomic);
1195 AssertOK();
1196 if (Name && Name[0]) setName(Name);
1197 }
1198
1199 LoadInst::LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAE)
1200 : UnaryInstruction(cast(Ptr->getType())->getElementType(),
1201 Load, Ptr, InsertAE) {
1202 setVolatile(false);
1203 setAlignment(0);
1204 setAtomic(AtomicOrdering::NotAtomic);
1205 AssertOK();
1206 if (Name && Name[0]) setName(Name);
1207 }
1208
1209 LoadInst::LoadInst(Type *Ty, Value *Ptr, const char *Name, bool isVolatile,
1210 Instruction *InsertBef)
1211 : UnaryInstruction(Ty, Load, Ptr, InsertBef) {
1212 assert(Ty == cast(Ptr->getType())->getElementType());
1213 setVolatile(isVolatile);
1214 setAlignment(0);
1215 setAtomic(AtomicOrdering::NotAtomic);
1216 AssertOK();
1217 if (Name && Name[0]) setName(Name);
1218 }
1219
1220 LoadInst::LoadInst(Value *Ptr, const char *Name, bool isVolatile,
1221 BasicBlock *InsertAE)
1222 : UnaryInstruction(cast(Ptr->getType())->getElementType(),
1223 Load, Ptr, InsertAE) {
1224 setVolatile(isVolatile);
1225 setAlignment(0);
1226 setAtomic(AtomicOrdering::NotAtomic);
1227 AssertOK();
1228 if (Name && Name[0]) setName(Name);
12291188 }
12301189
12311190 void LoadInst::setAlignment(unsigned Align) {
38783837 }
38793838
38803839 LoadInst *LoadInst::cloneImpl() const {
3881 return new LoadInst(getOperand(0), Twine(), isVolatile(),
3840 return new LoadInst(getType(), getOperand(0), Twine(), isVolatile(),
38823841 getAlignment(), getOrdering(), getSyncScopeID());
38833842 }
38843843