Skip to content

Commit 68e0133

Browse files
committed
[CGBuilder] Remove type-less CreateAlignedLoad() APIs (NFC)
These are incompatible with opaque pointers. This is in preparation of dropping this API on the IRBuilder side as well. Instead explicitly pass the loaded type.
1 parent 0070c9e commit 68e0133

File tree

12 files changed

+107
-79
lines changed

12 files changed

+107
-79
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,10 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
11901190

11911191
// First argument of a block call is a generic block literal casted to
11921192
// generic void pointer, i.e. i8 addrspace(4)*
1193+
llvm::Type *GenericVoidPtrTy =
1194+
CGM.getOpenCLRuntime().getGenericVoidPointerType();
11931195
llvm::Value *BlockDescriptor = Builder.CreatePointerCast(
1194-
BlockPtr, CGM.getOpenCLRuntime().getGenericVoidPointerType());
1196+
BlockPtr, GenericVoidPtrTy);
11951197
QualType VoidPtrQualTy = Ctx.getPointerType(
11961198
Ctx.getAddrSpaceQualType(Ctx.VoidTy, LangAS::opencl_generic));
11971199
Args.add(RValue::get(BlockDescriptor), VoidPtrQualTy);
@@ -1203,7 +1205,8 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
12031205
Func = CGM.getOpenCLRuntime().getInvokeFunction(E->getCallee());
12041206
else {
12051207
llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 2);
1206-
Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign());
1208+
Func = Builder.CreateAlignedLoad(GenericVoidPtrTy, FuncPtr,
1209+
getPointerAlign());
12071210
}
12081211
} else {
12091212
// Bitcast the block literal to a generic block literal.
@@ -1219,7 +1222,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
12191222
EmitCallArgs(Args, FnType->getAs<FunctionProtoType>(), E->arguments());
12201223

12211224
// Load the function.
1222-
Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign());
1225+
Func = Builder.CreateAlignedLoad(VoidPtrTy, FuncPtr, getPointerAlign());
12231226
}
12241227

12251228
const FunctionType *FuncTy = FnType->castAs<FunctionType>();

clang/lib/CodeGen/CGBuilder.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,11 @@ class CGBuilderTy : public CGBuilderBaseTy {
8282
}
8383

8484
using CGBuilderBaseTy::CreateAlignedLoad;
85-
llvm::LoadInst *CreateAlignedLoad(llvm::Value *Addr, CharUnits Align,
86-
const llvm::Twine &Name = "") {
87-
return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
88-
}
89-
llvm::LoadInst *CreateAlignedLoad(llvm::Value *Addr, CharUnits Align,
90-
const char *Name) {
91-
return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
92-
}
9385
llvm::LoadInst *CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr,
9486
CharUnits Align,
9587
const llvm::Twine &Name = "") {
9688
assert(Addr->getType()->getPointerElementType() == Ty);
97-
return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
89+
return CreateAlignedLoad(Ty, Addr, Align.getAsAlign(), Name);
9890
}
9991

10092
// Note that we intentionally hide the CreateStore APIs that don't

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static Value *EmitISOVolatileLoad(CodeGenFunction &CGF, const CallExpr *E) {
414414
llvm::Type *ITy =
415415
llvm::IntegerType::get(CGF.getLLVMContext(), LoadSize.getQuantity() * 8);
416416
Ptr = CGF.Builder.CreateBitCast(Ptr, ITy->getPointerTo());
417-
llvm::LoadInst *Load = CGF.Builder.CreateAlignedLoad(Ptr, LoadSize);
417+
llvm::LoadInst *Load = CGF.Builder.CreateAlignedLoad(ITy, Ptr, LoadSize);
418418
Load->setVolatile(true);
419419
return Load;
420420
}
@@ -12160,7 +12160,8 @@ Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) {
1216012160
llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0),
1216112161
ConstantInt::get(Int32Ty, Index)};
1216212162
llvm::Value *CpuValue = Builder.CreateGEP(STy, CpuModel, Idxs);
12163-
CpuValue = Builder.CreateAlignedLoad(CpuValue, CharUnits::fromQuantity(4));
12163+
CpuValue = Builder.CreateAlignedLoad(Int32Ty, CpuValue,
12164+
CharUnits::fromQuantity(4));
1216412165

1216512166
// Check the value of the field against the requested value.
1216612167
return Builder.CreateICmpEQ(CpuValue,
@@ -12217,8 +12218,8 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
1221712218
Value *Idxs[] = {Builder.getInt32(0), Builder.getInt32(3),
1221812219
Builder.getInt32(0)};
1221912220
Value *CpuFeatures = Builder.CreateGEP(STy, CpuModel, Idxs);
12220-
Value *Features =
12221-
Builder.CreateAlignedLoad(CpuFeatures, CharUnits::fromQuantity(4));
12221+
Value *Features = Builder.CreateAlignedLoad(Int32Ty, CpuFeatures,
12222+
CharUnits::fromQuantity(4));
1222212223

1222312224
// Check the value of the bit corresponding to the feature requested.
1222412225
Value *Mask = Builder.getInt32(Features1);
@@ -12232,8 +12233,8 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
1223212233
"__cpu_features2");
1223312234
cast<llvm::GlobalValue>(CpuFeatures2)->setDSOLocal(true);
1223412235

12235-
Value *Features =
12236-
Builder.CreateAlignedLoad(CpuFeatures2, CharUnits::fromQuantity(4));
12236+
Value *Features = Builder.CreateAlignedLoad(Int32Ty, CpuFeatures2,
12237+
CharUnits::fromQuantity(4));
1223712238

1223812239
// Check the value of the bit corresponding to the feature requested.
1223912240
Value *Mask = Builder.getInt32(Features2);
@@ -16665,7 +16666,9 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1666516666
SmallVector<Value *, 10> Values = {Dst};
1666616667
for (unsigned i = 0; i < II.NumResults; ++i) {
1666716668
Value *V = Builder.CreateAlignedLoad(
16668-
Builder.CreateGEP(Src.getPointer(), llvm::ConstantInt::get(IntTy, i)),
16669+
Src.getElementType(),
16670+
Builder.CreateGEP(Src.getElementType(), Src.getPointer(),
16671+
llvm::ConstantInt::get(IntTy, i)),
1666916672
CharUnits::fromQuantity(4));
1667016673
Values.push_back(Builder.CreateBitCast(V, ParamType));
1667116674
}
@@ -16728,7 +16731,8 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1672816731
// Load A
1672916732
for (unsigned i = 0; i < MI.NumEltsA; ++i) {
1673016733
Value *V = Builder.CreateAlignedLoad(
16731-
Builder.CreateGEP(SrcA.getPointer(),
16734+
SrcA.getElementType(),
16735+
Builder.CreateGEP(SrcA.getElementType(), SrcA.getPointer(),
1673216736
llvm::ConstantInt::get(IntTy, i)),
1673316737
CharUnits::fromQuantity(4));
1673416738
Values.push_back(Builder.CreateBitCast(V, AType));
@@ -16737,7 +16741,8 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1673716741
llvm::Type *BType = Intrinsic->getFunctionType()->getParamType(MI.NumEltsA);
1673816742
for (unsigned i = 0; i < MI.NumEltsB; ++i) {
1673916743
Value *V = Builder.CreateAlignedLoad(
16740-
Builder.CreateGEP(SrcB.getPointer(),
16744+
SrcB.getElementType(),
16745+
Builder.CreateGEP(SrcB.getElementType(), SrcB.getPointer(),
1674116746
llvm::ConstantInt::get(IntTy, i)),
1674216747
CharUnits::fromQuantity(4));
1674316748
Values.push_back(Builder.CreateBitCast(V, BType));
@@ -16747,7 +16752,8 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
1674716752
Intrinsic->getFunctionType()->getParamType(MI.NumEltsA + MI.NumEltsB);
1674816753
for (unsigned i = 0; i < MI.NumEltsC; ++i) {
1674916754
Value *V = Builder.CreateAlignedLoad(
16750-
Builder.CreateGEP(SrcC.getPointer(),
16755+
SrcC.getElementType(),
16756+
Builder.CreateGEP(SrcC.getElementType(), SrcC.getPointer(),
1675116757
llvm::ConstantInt::get(IntTy, i)),
1675216758
CharUnits::fromQuantity(4));
1675316759
Values.push_back(Builder.CreateBitCast(V, CType));

clang/lib/CodeGen/CGCall.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,9 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
34003400
llvm::Value *ArgStruct = &*EI;
34013401
llvm::Value *SRet = Builder.CreateStructGEP(
34023402
nullptr, ArgStruct, RetAI.getInAllocaFieldIndex());
3403-
RV = Builder.CreateAlignedLoad(SRet, getPointerAlign(), "sret");
3403+
llvm::Type *Ty =
3404+
cast<llvm::GetElementPtrInst>(SRet)->getResultElementType();
3405+
RV = Builder.CreateAlignedLoad(Ty, SRet, getPointerAlign(), "sret");
34043406
}
34053407
break;
34063408

clang/lib/CodeGen/CGException.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,8 @@ namespace {
13431343
CGF.EmitBlock(RethrowBB);
13441344
if (SavedExnVar) {
13451345
CGF.EmitRuntimeCallOrInvoke(RethrowFn,
1346-
CGF.Builder.CreateAlignedLoad(SavedExnVar, CGF.getPointerAlign()));
1346+
CGF.Builder.CreateAlignedLoad(CGF.Int8PtrTy, SavedExnVar,
1347+
CGF.getPointerAlign()));
13471348
} else {
13481349
CGF.EmitRuntimeCallOrInvoke(RethrowFn);
13491350
}
@@ -2038,8 +2039,8 @@ void CodeGenFunction::EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF,
20382039
llvm::Type *PtrsTy = llvm::StructType::get(RecordTy, CGM.VoidPtrTy);
20392040
llvm::Value *Ptrs = Builder.CreateBitCast(SEHInfo, PtrsTy->getPointerTo());
20402041
llvm::Value *Rec = Builder.CreateStructGEP(PtrsTy, Ptrs, 0);
2041-
Rec = Builder.CreateAlignedLoad(Rec, getPointerAlign());
2042-
llvm::Value *Code = Builder.CreateAlignedLoad(Rec, getIntAlign());
2042+
Rec = Builder.CreateAlignedLoad(RecordTy, Rec, getPointerAlign());
2043+
llvm::Value *Code = Builder.CreateAlignedLoad(Int32Ty, Rec, getIntAlign());
20432044
assert(!SEHCodeSlotStack.empty() && "emitting EH code outside of __except");
20442045
Builder.CreateStore(Code, SEHCodeSlotStack.back());
20452046
}

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,9 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
852852
CacheSize-1));
853853
llvm::Value *Indices[] = { Builder.getInt32(0), Slot };
854854
llvm::Value *CacheVal =
855-
Builder.CreateAlignedLoad(Builder.CreateInBoundsGEP(Cache, Indices),
856-
getPointerAlign());
855+
Builder.CreateAlignedLoad(IntPtrTy,
856+
Builder.CreateInBoundsGEP(Cache, Indices),
857+
getPointerAlign());
857858

858859
// If the hash isn't in the cache, call a runtime handler to perform the
859860
// hard work of checking whether the vptr is for an object of the right
@@ -5128,9 +5129,9 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee
51285129
getContext().getFunctionTypeWithExceptionSpec(PointeeType, EST_None);
51295130
llvm::Constant *FTRTTIConst =
51305131
CGM.GetAddrOfRTTIDescriptor(ProtoTy, /*ForEH=*/true);
5131-
llvm::Type *PrefixStructTyElems[] = {PrefixSig->getType(), Int32Ty};
5132+
llvm::Type *PrefixSigType = PrefixSig->getType();
51325133
llvm::StructType *PrefixStructTy = llvm::StructType::get(
5133-
CGM.getLLVMContext(), PrefixStructTyElems, /*isPacked=*/true);
5134+
CGM.getLLVMContext(), {PrefixSigType, Int32Ty}, /*isPacked=*/true);
51345135

51355136
llvm::Value *CalleePtr = Callee.getFunctionPointer();
51365137

@@ -5139,7 +5140,7 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee
51395140
llvm::Value *CalleeSigPtr =
51405141
Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 0);
51415142
llvm::Value *CalleeSig =
5142-
Builder.CreateAlignedLoad(CalleeSigPtr, getIntAlign());
5143+
Builder.CreateAlignedLoad(PrefixSigType, CalleeSigPtr, getIntAlign());
51435144
llvm::Value *CalleeSigMatch = Builder.CreateICmpEQ(CalleeSig, PrefixSig);
51445145

51455146
llvm::BasicBlock *Cont = createBasicBlock("cont");
@@ -5150,7 +5151,7 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee
51505151
llvm::Value *CalleeRTTIPtr =
51515152
Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 1);
51525153
llvm::Value *CalleeRTTIEncoded =
5153-
Builder.CreateAlignedLoad(CalleeRTTIPtr, getPointerAlign());
5154+
Builder.CreateAlignedLoad(Int32Ty, CalleeRTTIPtr, getPointerAlign());
51545155
llvm::Value *CalleeRTTI =
51555156
DecodeAddrUsedInPrologue(CalleePtr, CalleeRTTIEncoded);
51565157
llvm::Value *CalleeRTTIMatch =

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,9 +1819,10 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
18191819
llvm::Value *StateMutationsPtr
18201820
= Builder.CreateLoad(StateMutationsPtrPtr, "mutationsptr");
18211821

1822+
llvm::Type *UnsignedLongTy = ConvertType(getContext().UnsignedLongTy);
18221823
llvm::Value *initialMutations =
1823-
Builder.CreateAlignedLoad(StateMutationsPtr, getPointerAlign(),
1824-
"forcoll.initial-mutations");
1824+
Builder.CreateAlignedLoad(UnsignedLongTy, StateMutationsPtr,
1825+
getPointerAlign(), "forcoll.initial-mutations");
18251826

18261827
// Start looping. This is the point we return to whenever we have a
18271828
// fresh, non-empty batch of objects.
@@ -1843,8 +1844,8 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
18431844
// refreshes.
18441845
StateMutationsPtr = Builder.CreateLoad(StateMutationsPtrPtr, "mutationsptr");
18451846
llvm::Value *currentMutations
1846-
= Builder.CreateAlignedLoad(StateMutationsPtr, getPointerAlign(),
1847-
"statemutations");
1847+
= Builder.CreateAlignedLoad(UnsignedLongTy, StateMutationsPtr,
1848+
getPointerAlign(), "statemutations");
18481849

18491850
llvm::BasicBlock *WasMutatedBB = createBasicBlock("forcoll.mutated");
18501851
llvm::BasicBlock *WasNotMutatedBB = createBasicBlock("forcoll.notmutated");
@@ -1854,9 +1855,9 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
18541855

18551856
// If so, call the enumeration-mutation function.
18561857
EmitBlock(WasMutatedBB);
1858+
llvm::Type *ObjCIdType = ConvertType(getContext().getObjCIdType());
18571859
llvm::Value *V =
1858-
Builder.CreateBitCast(Collection,
1859-
ConvertType(getContext().getObjCIdType()));
1860+
Builder.CreateBitCast(Collection, ObjCIdType);
18601861
CallArgList Args2;
18611862
Args2.add(RValue::get(V), getContext().getObjCIdType());
18621863
// FIXME: We shouldn't need to get the function info here, the runtime already
@@ -1905,7 +1906,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
19051906
llvm::Value *CurrentItemPtr =
19061907
Builder.CreateGEP(EnumStateItems, index, "currentitem.ptr");
19071908
llvm::Value *CurrentItem =
1908-
Builder.CreateAlignedLoad(CurrentItemPtr, getPointerAlign());
1909+
Builder.CreateAlignedLoad(ObjCIdType, CurrentItemPtr, getPointerAlign());
19091910

19101911
if (SanOpts.has(SanitizerKind::ObjCCast)) {
19111912
// Before using an item from the collection, check that the implicit cast

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ class CGObjCGNUstep : public CGObjCGNU {
780780

781781
// Load the imp from the slot
782782
llvm::Value *imp = Builder.CreateAlignedLoad(
783-
Builder.CreateStructGEP(nullptr, slot, 4), CGF.getPointerAlign());
783+
IMPTy, Builder.CreateStructGEP(nullptr, slot, 4),
784+
CGF.getPointerAlign());
784785

785786
// The lookup function may have changed the receiver, so make sure we use
786787
// the new one.
@@ -798,8 +799,9 @@ class CGObjCGNUstep : public CGObjCGNU {
798799
CGF.EmitNounwindRuntimeCall(SlotLookupSuperFn, lookupArgs);
799800
slot->setOnlyReadsMemory();
800801

801-
return Builder.CreateAlignedLoad(Builder.CreateStructGEP(nullptr, slot, 4),
802-
CGF.getPointerAlign());
802+
return Builder.CreateAlignedLoad(
803+
IMPTy, Builder.CreateStructGEP(nullptr, slot, 4),
804+
CGF.getPointerAlign());
803805
}
804806

805807
public:
@@ -1328,7 +1330,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
13281330
Ref = GV;
13291331
}
13301332
EmittedProtocolRef = true;
1331-
return CGF.Builder.CreateAlignedLoad(Ref, CGM.getPointerAlign());
1333+
return CGF.Builder.CreateAlignedLoad(ProtocolPtrTy, Ref,
1334+
CGM.getPointerAlign());
13321335
}
13331336

13341337
llvm::Constant *GenerateProtocolList(ArrayRef<llvm::Constant*> Protocols) {
@@ -1689,7 +1692,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
16891692
IvarOffsetPointer = new llvm::GlobalVariable(TheModule, IntTy, false,
16901693
llvm::GlobalValue::ExternalLinkage, nullptr, Name);
16911694
CharUnits Align = CGM.getIntAlign();
1692-
llvm::Value *Offset = CGF.Builder.CreateAlignedLoad(IvarOffsetPointer, Align);
1695+
llvm::Value *Offset =
1696+
CGF.Builder.CreateAlignedLoad(IntTy, IvarOffsetPointer, Align);
16931697
if (Offset->getType() != PtrDiffTy)
16941698
Offset = CGF.Builder.CreateZExtOrBitCast(Offset, PtrDiffTy);
16951699
return Offset;
@@ -2543,7 +2547,7 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF,
25432547
ReceiverClass = Builder.CreateBitCast(ReceiverClass,
25442548
llvm::PointerType::getUnqual(IdTy));
25452549
ReceiverClass =
2546-
Builder.CreateAlignedLoad(ReceiverClass, CGF.getPointerAlign());
2550+
Builder.CreateAlignedLoad(IdTy, ReceiverClass, CGF.getPointerAlign());
25472551
}
25482552
ReceiverClass = EnforceType(Builder, ReceiverClass, IdTy);
25492553
} else {
@@ -2588,7 +2592,7 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF,
25882592
ReceiverClass = Builder.CreateStructGEP(CastTy, ReceiverClass, 1);
25892593
// Load the superclass pointer
25902594
ReceiverClass =
2591-
Builder.CreateAlignedLoad(ReceiverClass, CGF.getPointerAlign());
2595+
Builder.CreateAlignedLoad(IdTy, ReceiverClass, CGF.getPointerAlign());
25922596
}
25932597
// Construct the structure used to look up the IMP
25942598
llvm::StructType *ObjCSuperTy =
@@ -4086,6 +4090,7 @@ llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGenFunction &CGF,
40864090
return CGF.Builder.CreateZExtOrBitCast(
40874091
CGF.Builder.CreateAlignedLoad(
40884092
Int32Ty, CGF.Builder.CreateAlignedLoad(
4093+
llvm::Type::getInt32PtrTy(VMContext),
40894094
ObjCIvarOffsetVariable(Interface, Ivar),
40904095
CGF.getPointerAlign(), "ivar"),
40914096
CharUnits::fromQuantity(4)),
@@ -4101,7 +4106,7 @@ llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGenFunction &CGF,
41014106
GV->setAlignment(Align.getAsAlign());
41024107
Offset = GV;
41034108
}
4104-
Offset = CGF.Builder.CreateAlignedLoad(Offset, Align);
4109+
Offset = CGF.Builder.CreateAlignedLoad(IntTy, Offset, Align);
41054110
if (Offset->getType() != PtrDiffTy)
41064111
Offset = CGF.Builder.CreateZExtOrBitCast(Offset, PtrDiffTy);
41074112
return Offset;

0 commit comments

Comments
 (0)