[clang] 68e0133 - [CGBuilder] Remove type-less CreateAlignedLoad() APIs (NFC)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 11 01:41:34 PST 2021
Author: Nikita Popov
Date: 2021-03-11T10:41:23+01:00
New Revision: 68e01339cc5bc3d8a885bc9413611fbc6ca151e4
URL: https://github.com/llvm/llvm-project/commit/68e01339cc5bc3d8a885bc9413611fbc6ca151e4
DIFF: https://github.com/llvm/llvm-project/commit/68e01339cc5bc3d8a885bc9413611fbc6ca151e4.diff
LOG: [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.
Added:
Modified:
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGException.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 91c726f4cf641..7e5d96fb8633e 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1190,8 +1190,10 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
// First argument of a block call is a generic block literal casted to
// generic void pointer, i.e. i8 addrspace(4)*
+ llvm::Type *GenericVoidPtrTy =
+ CGM.getOpenCLRuntime().getGenericVoidPointerType();
llvm::Value *BlockDescriptor = Builder.CreatePointerCast(
- BlockPtr, CGM.getOpenCLRuntime().getGenericVoidPointerType());
+ BlockPtr, GenericVoidPtrTy);
QualType VoidPtrQualTy = Ctx.getPointerType(
Ctx.getAddrSpaceQualType(Ctx.VoidTy, LangAS::opencl_generic));
Args.add(RValue::get(BlockDescriptor), VoidPtrQualTy);
@@ -1203,7 +1205,8 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
Func = CGM.getOpenCLRuntime().getInvokeFunction(E->getCallee());
else {
llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 2);
- Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign());
+ Func = Builder.CreateAlignedLoad(GenericVoidPtrTy, FuncPtr,
+ getPointerAlign());
}
} else {
// Bitcast the block literal to a generic block literal.
@@ -1219,7 +1222,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E,
EmitCallArgs(Args, FnType->getAs<FunctionProtoType>(), E->arguments());
// Load the function.
- Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign());
+ Func = Builder.CreateAlignedLoad(VoidPtrTy, FuncPtr, getPointerAlign());
}
const FunctionType *FuncTy = FnType->castAs<FunctionType>();
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 4cdf9fce7a3eb..320278eac1241 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -82,19 +82,11 @@ class CGBuilderTy : public CGBuilderBaseTy {
}
using CGBuilderBaseTy::CreateAlignedLoad;
- llvm::LoadInst *CreateAlignedLoad(llvm::Value *Addr, CharUnits Align,
- const llvm::Twine &Name = "") {
- return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
- }
- llvm::LoadInst *CreateAlignedLoad(llvm::Value *Addr, CharUnits Align,
- const char *Name) {
- return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
- }
llvm::LoadInst *CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr,
CharUnits Align,
const llvm::Twine &Name = "") {
assert(Addr->getType()->getPointerElementType() == Ty);
- return CreateAlignedLoad(Addr, Align.getAsAlign(), Name);
+ return CreateAlignedLoad(Ty, Addr, Align.getAsAlign(), Name);
}
// Note that we intentionally hide the CreateStore APIs that don't
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ac10fabaea390..44bd151093cce 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -414,7 +414,7 @@ static Value *EmitISOVolatileLoad(CodeGenFunction &CGF, const CallExpr *E) {
llvm::Type *ITy =
llvm::IntegerType::get(CGF.getLLVMContext(), LoadSize.getQuantity() * 8);
Ptr = CGF.Builder.CreateBitCast(Ptr, ITy->getPointerTo());
- llvm::LoadInst *Load = CGF.Builder.CreateAlignedLoad(Ptr, LoadSize);
+ llvm::LoadInst *Load = CGF.Builder.CreateAlignedLoad(ITy, Ptr, LoadSize);
Load->setVolatile(true);
return Load;
}
@@ -12160,7 +12160,8 @@ Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) {
llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0),
ConstantInt::get(Int32Ty, Index)};
llvm::Value *CpuValue = Builder.CreateGEP(STy, CpuModel, Idxs);
- CpuValue = Builder.CreateAlignedLoad(CpuValue, CharUnits::fromQuantity(4));
+ CpuValue = Builder.CreateAlignedLoad(Int32Ty, CpuValue,
+ CharUnits::fromQuantity(4));
// Check the value of the field against the requested value.
return Builder.CreateICmpEQ(CpuValue,
@@ -12217,8 +12218,8 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
Value *Idxs[] = {Builder.getInt32(0), Builder.getInt32(3),
Builder.getInt32(0)};
Value *CpuFeatures = Builder.CreateGEP(STy, CpuModel, Idxs);
- Value *Features =
- Builder.CreateAlignedLoad(CpuFeatures, CharUnits::fromQuantity(4));
+ Value *Features = Builder.CreateAlignedLoad(Int32Ty, CpuFeatures,
+ CharUnits::fromQuantity(4));
// Check the value of the bit corresponding to the feature requested.
Value *Mask = Builder.getInt32(Features1);
@@ -12232,8 +12233,8 @@ llvm::Value *CodeGenFunction::EmitX86CpuSupports(uint64_t FeaturesMask) {
"__cpu_features2");
cast<llvm::GlobalValue>(CpuFeatures2)->setDSOLocal(true);
- Value *Features =
- Builder.CreateAlignedLoad(CpuFeatures2, CharUnits::fromQuantity(4));
+ Value *Features = Builder.CreateAlignedLoad(Int32Ty, CpuFeatures2,
+ CharUnits::fromQuantity(4));
// Check the value of the bit corresponding to the feature requested.
Value *Mask = Builder.getInt32(Features2);
@@ -16665,7 +16666,9 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
SmallVector<Value *, 10> Values = {Dst};
for (unsigned i = 0; i < II.NumResults; ++i) {
Value *V = Builder.CreateAlignedLoad(
- Builder.CreateGEP(Src.getPointer(), llvm::ConstantInt::get(IntTy, i)),
+ Src.getElementType(),
+ Builder.CreateGEP(Src.getElementType(), Src.getPointer(),
+ llvm::ConstantInt::get(IntTy, i)),
CharUnits::fromQuantity(4));
Values.push_back(Builder.CreateBitCast(V, ParamType));
}
@@ -16728,7 +16731,8 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
// Load A
for (unsigned i = 0; i < MI.NumEltsA; ++i) {
Value *V = Builder.CreateAlignedLoad(
- Builder.CreateGEP(SrcA.getPointer(),
+ SrcA.getElementType(),
+ Builder.CreateGEP(SrcA.getElementType(), SrcA.getPointer(),
llvm::ConstantInt::get(IntTy, i)),
CharUnits::fromQuantity(4));
Values.push_back(Builder.CreateBitCast(V, AType));
@@ -16737,7 +16741,8 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
llvm::Type *BType = Intrinsic->getFunctionType()->getParamType(MI.NumEltsA);
for (unsigned i = 0; i < MI.NumEltsB; ++i) {
Value *V = Builder.CreateAlignedLoad(
- Builder.CreateGEP(SrcB.getPointer(),
+ SrcB.getElementType(),
+ Builder.CreateGEP(SrcB.getElementType(), SrcB.getPointer(),
llvm::ConstantInt::get(IntTy, i)),
CharUnits::fromQuantity(4));
Values.push_back(Builder.CreateBitCast(V, BType));
@@ -16747,7 +16752,8 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
Intrinsic->getFunctionType()->getParamType(MI.NumEltsA + MI.NumEltsB);
for (unsigned i = 0; i < MI.NumEltsC; ++i) {
Value *V = Builder.CreateAlignedLoad(
- Builder.CreateGEP(SrcC.getPointer(),
+ SrcC.getElementType(),
+ Builder.CreateGEP(SrcC.getElementType(), SrcC.getPointer(),
llvm::ConstantInt::get(IntTy, i)),
CharUnits::fromQuantity(4));
Values.push_back(Builder.CreateBitCast(V, CType));
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 34ad782d810cc..dc73e3260891c 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3400,7 +3400,9 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
llvm::Value *ArgStruct = &*EI;
llvm::Value *SRet = Builder.CreateStructGEP(
nullptr, ArgStruct, RetAI.getInAllocaFieldIndex());
- RV = Builder.CreateAlignedLoad(SRet, getPointerAlign(), "sret");
+ llvm::Type *Ty =
+ cast<llvm::GetElementPtrInst>(SRet)->getResultElementType();
+ RV = Builder.CreateAlignedLoad(Ty, SRet, getPointerAlign(), "sret");
}
break;
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 5ac037cd9db94..078c60c6c4cf4 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1343,7 +1343,8 @@ namespace {
CGF.EmitBlock(RethrowBB);
if (SavedExnVar) {
CGF.EmitRuntimeCallOrInvoke(RethrowFn,
- CGF.Builder.CreateAlignedLoad(SavedExnVar, CGF.getPointerAlign()));
+ CGF.Builder.CreateAlignedLoad(CGF.Int8PtrTy, SavedExnVar,
+ CGF.getPointerAlign()));
} else {
CGF.EmitRuntimeCallOrInvoke(RethrowFn);
}
@@ -2038,8 +2039,8 @@ void CodeGenFunction::EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF,
llvm::Type *PtrsTy = llvm::StructType::get(RecordTy, CGM.VoidPtrTy);
llvm::Value *Ptrs = Builder.CreateBitCast(SEHInfo, PtrsTy->getPointerTo());
llvm::Value *Rec = Builder.CreateStructGEP(PtrsTy, Ptrs, 0);
- Rec = Builder.CreateAlignedLoad(Rec, getPointerAlign());
- llvm::Value *Code = Builder.CreateAlignedLoad(Rec, getIntAlign());
+ Rec = Builder.CreateAlignedLoad(RecordTy, Rec, getPointerAlign());
+ llvm::Value *Code = Builder.CreateAlignedLoad(Int32Ty, Rec, getIntAlign());
assert(!SEHCodeSlotStack.empty() && "emitting EH code outside of __except");
Builder.CreateStore(Code, SEHCodeSlotStack.back());
}
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 55e19313850c2..b5bfae914ba4c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -852,8 +852,9 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
CacheSize-1));
llvm::Value *Indices[] = { Builder.getInt32(0), Slot };
llvm::Value *CacheVal =
- Builder.CreateAlignedLoad(Builder.CreateInBoundsGEP(Cache, Indices),
- getPointerAlign());
+ Builder.CreateAlignedLoad(IntPtrTy,
+ Builder.CreateInBoundsGEP(Cache, Indices),
+ getPointerAlign());
// If the hash isn't in the cache, call a runtime handler to perform the
// 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
getContext().getFunctionTypeWithExceptionSpec(PointeeType, EST_None);
llvm::Constant *FTRTTIConst =
CGM.GetAddrOfRTTIDescriptor(ProtoTy, /*ForEH=*/true);
- llvm::Type *PrefixStructTyElems[] = {PrefixSig->getType(), Int32Ty};
+ llvm::Type *PrefixSigType = PrefixSig->getType();
llvm::StructType *PrefixStructTy = llvm::StructType::get(
- CGM.getLLVMContext(), PrefixStructTyElems, /*isPacked=*/true);
+ CGM.getLLVMContext(), {PrefixSigType, Int32Ty}, /*isPacked=*/true);
llvm::Value *CalleePtr = Callee.getFunctionPointer();
@@ -5139,7 +5140,7 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee
llvm::Value *CalleeSigPtr =
Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 0);
llvm::Value *CalleeSig =
- Builder.CreateAlignedLoad(CalleeSigPtr, getIntAlign());
+ Builder.CreateAlignedLoad(PrefixSigType, CalleeSigPtr, getIntAlign());
llvm::Value *CalleeSigMatch = Builder.CreateICmpEQ(CalleeSig, PrefixSig);
llvm::BasicBlock *Cont = createBasicBlock("cont");
@@ -5150,7 +5151,7 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee
llvm::Value *CalleeRTTIPtr =
Builder.CreateConstGEP2_32(PrefixStructTy, CalleePrefixStruct, 0, 1);
llvm::Value *CalleeRTTIEncoded =
- Builder.CreateAlignedLoad(CalleeRTTIPtr, getPointerAlign());
+ Builder.CreateAlignedLoad(Int32Ty, CalleeRTTIPtr, getPointerAlign());
llvm::Value *CalleeRTTI =
DecodeAddrUsedInPrologue(CalleePtr, CalleeRTTIEncoded);
llvm::Value *CalleeRTTIMatch =
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 663666b6bf8b8..2005eb9856aec 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -1819,9 +1819,10 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
llvm::Value *StateMutationsPtr
= Builder.CreateLoad(StateMutationsPtrPtr, "mutationsptr");
+ llvm::Type *UnsignedLongTy = ConvertType(getContext().UnsignedLongTy);
llvm::Value *initialMutations =
- Builder.CreateAlignedLoad(StateMutationsPtr, getPointerAlign(),
- "forcoll.initial-mutations");
+ Builder.CreateAlignedLoad(UnsignedLongTy, StateMutationsPtr,
+ getPointerAlign(), "forcoll.initial-mutations");
// Start looping. This is the point we return to whenever we have a
// fresh, non-empty batch of objects.
@@ -1843,8 +1844,8 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
// refreshes.
StateMutationsPtr = Builder.CreateLoad(StateMutationsPtrPtr, "mutationsptr");
llvm::Value *currentMutations
- = Builder.CreateAlignedLoad(StateMutationsPtr, getPointerAlign(),
- "statemutations");
+ = Builder.CreateAlignedLoad(UnsignedLongTy, StateMutationsPtr,
+ getPointerAlign(), "statemutations");
llvm::BasicBlock *WasMutatedBB = createBasicBlock("forcoll.mutated");
llvm::BasicBlock *WasNotMutatedBB = createBasicBlock("forcoll.notmutated");
@@ -1854,9 +1855,9 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
// If so, call the enumeration-mutation function.
EmitBlock(WasMutatedBB);
+ llvm::Type *ObjCIdType = ConvertType(getContext().getObjCIdType());
llvm::Value *V =
- Builder.CreateBitCast(Collection,
- ConvertType(getContext().getObjCIdType()));
+ Builder.CreateBitCast(Collection, ObjCIdType);
CallArgList Args2;
Args2.add(RValue::get(V), getContext().getObjCIdType());
// FIXME: We shouldn't need to get the function info here, the runtime already
@@ -1905,7 +1906,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
llvm::Value *CurrentItemPtr =
Builder.CreateGEP(EnumStateItems, index, "currentitem.ptr");
llvm::Value *CurrentItem =
- Builder.CreateAlignedLoad(CurrentItemPtr, getPointerAlign());
+ Builder.CreateAlignedLoad(ObjCIdType, CurrentItemPtr, getPointerAlign());
if (SanOpts.has(SanitizerKind::ObjCCast)) {
// Before using an item from the collection, check that the implicit cast
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9825d7bca18c0..6e6b73f550e35 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -780,7 +780,8 @@ class CGObjCGNUstep : public CGObjCGNU {
// Load the imp from the slot
llvm::Value *imp = Builder.CreateAlignedLoad(
- Builder.CreateStructGEP(nullptr, slot, 4), CGF.getPointerAlign());
+ IMPTy, Builder.CreateStructGEP(nullptr, slot, 4),
+ CGF.getPointerAlign());
// The lookup function may have changed the receiver, so make sure we use
// the new one.
@@ -798,8 +799,9 @@ class CGObjCGNUstep : public CGObjCGNU {
CGF.EmitNounwindRuntimeCall(SlotLookupSuperFn, lookupArgs);
slot->setOnlyReadsMemory();
- return Builder.CreateAlignedLoad(Builder.CreateStructGEP(nullptr, slot, 4),
- CGF.getPointerAlign());
+ return Builder.CreateAlignedLoad(
+ IMPTy, Builder.CreateStructGEP(nullptr, slot, 4),
+ CGF.getPointerAlign());
}
public:
@@ -1328,7 +1330,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
Ref = GV;
}
EmittedProtocolRef = true;
- return CGF.Builder.CreateAlignedLoad(Ref, CGM.getPointerAlign());
+ return CGF.Builder.CreateAlignedLoad(ProtocolPtrTy, Ref,
+ CGM.getPointerAlign());
}
llvm::Constant *GenerateProtocolList(ArrayRef<llvm::Constant*> Protocols) {
@@ -1689,7 +1692,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
IvarOffsetPointer = new llvm::GlobalVariable(TheModule, IntTy, false,
llvm::GlobalValue::ExternalLinkage, nullptr, Name);
CharUnits Align = CGM.getIntAlign();
- llvm::Value *Offset = CGF.Builder.CreateAlignedLoad(IvarOffsetPointer, Align);
+ llvm::Value *Offset =
+ CGF.Builder.CreateAlignedLoad(IntTy, IvarOffsetPointer, Align);
if (Offset->getType() != PtrDiffTy)
Offset = CGF.Builder.CreateZExtOrBitCast(Offset, PtrDiffTy);
return Offset;
@@ -2543,7 +2547,7 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF,
ReceiverClass = Builder.CreateBitCast(ReceiverClass,
llvm::PointerType::getUnqual(IdTy));
ReceiverClass =
- Builder.CreateAlignedLoad(ReceiverClass, CGF.getPointerAlign());
+ Builder.CreateAlignedLoad(IdTy, ReceiverClass, CGF.getPointerAlign());
}
ReceiverClass = EnforceType(Builder, ReceiverClass, IdTy);
} else {
@@ -2588,7 +2592,7 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF,
ReceiverClass = Builder.CreateStructGEP(CastTy, ReceiverClass, 1);
// Load the superclass pointer
ReceiverClass =
- Builder.CreateAlignedLoad(ReceiverClass, CGF.getPointerAlign());
+ Builder.CreateAlignedLoad(IdTy, ReceiverClass, CGF.getPointerAlign());
}
// Construct the structure used to look up the IMP
llvm::StructType *ObjCSuperTy =
@@ -4086,6 +4090,7 @@ llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGenFunction &CGF,
return CGF.Builder.CreateZExtOrBitCast(
CGF.Builder.CreateAlignedLoad(
Int32Ty, CGF.Builder.CreateAlignedLoad(
+ llvm::Type::getInt32PtrTy(VMContext),
ObjCIvarOffsetVariable(Interface, Ivar),
CGF.getPointerAlign(), "ivar"),
CharUnits::fromQuantity(4)),
@@ -4101,7 +4106,7 @@ llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGenFunction &CGF,
GV->setAlignment(Align.getAsAlign());
Offset = GV;
}
- Offset = CGF.Builder.CreateAlignedLoad(Offset, Align);
+ Offset = CGF.Builder.CreateAlignedLoad(IntTy, Offset, Align);
if (Offset->getType() != PtrDiffTy)
Offset = CGF.Builder.CreateZExtOrBitCast(Offset, PtrDiffTy);
return Offset;
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 4c4a316308cea..76ea28c933134 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2096,6 +2096,7 @@ CGObjCMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
CGF.Builder.CreateStructGEP(ObjCSuper, 0));
// If this is a class message the metaclass is passed as the target.
+ llvm::Type *ClassTyPtr = llvm::PointerType::getUnqual(ObjCTypes.ClassTy);
llvm::Value *Target;
if (IsClassMessage) {
if (isCategoryImpl) {
@@ -2107,13 +2108,14 @@ CGObjCMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
// isa" is the first ivar in a class (which it must be).
Target = EmitClassRef(CGF, Class->getSuperClass());
Target = CGF.Builder.CreateStructGEP(ObjCTypes.ClassTy, Target, 0);
- Target = CGF.Builder.CreateAlignedLoad(Target, CGF.getPointerAlign());
+ Target = CGF.Builder.CreateAlignedLoad(ClassTyPtr, Target,
+ CGF.getPointerAlign());
} else {
llvm::Constant *MetaClassPtr = EmitMetaClassRef(Class);
llvm::Value *SuperPtr =
CGF.Builder.CreateStructGEP(ObjCTypes.ClassTy, MetaClassPtr, 1);
- llvm::Value *Super =
- CGF.Builder.CreateAlignedLoad(SuperPtr, CGF.getPointerAlign());
+ llvm::Value *Super = CGF.Builder.CreateAlignedLoad(ClassTyPtr, SuperPtr,
+ CGF.getPointerAlign());
Target = Super;
}
} else if (isCategoryImpl)
@@ -2121,7 +2123,8 @@ CGObjCMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
else {
llvm::Value *ClassPtr = EmitSuperClassRef(Class);
ClassPtr = CGF.Builder.CreateStructGEP(ObjCTypes.ClassTy, ClassPtr, 1);
- Target = CGF.Builder.CreateAlignedLoad(ClassPtr, CGF.getPointerAlign());
+ Target = CGF.Builder.CreateAlignedLoad(ClassTyPtr, ClassPtr,
+ CGF.getPointerAlign());
}
// FIXME: We shouldn't need to do this cast, rectify the ASTContext and
// ObjCTypes types.
@@ -5285,7 +5288,8 @@ llvm::Value *CGObjCMac::EmitClassRefFromId(CodeGenFunction &CGF,
CGM.getPointerAlign(), true);
}
- return CGF.Builder.CreateAlignedLoad(Entry, CGF.getPointerAlign());
+ return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry,
+ CGF.getPointerAlign());
}
llvm::Value *CGObjCMac::EmitClassRef(CodeGenFunction &CGF,
@@ -6682,7 +6686,7 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF,
llvm::GlobalVariable *PTGV = CGM.getModule().getGlobalVariable(ProtocolName);
if (PTGV)
- return CGF.Builder.CreateAlignedLoad(PTGV, Align);
+ return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align);
PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
llvm::GlobalValue::WeakAnyLinkage, Init,
ProtocolName);
@@ -6693,7 +6697,7 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF,
if (!CGM.getTriple().isOSBinFormatMachO())
PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName));
CGM.addUsedGlobal(PTGV);
- return CGF.Builder.CreateAlignedLoad(PTGV, Align);
+ return CGF.Builder.CreateAlignedLoad(PTGV->getValueType(), PTGV, Align);
}
/// GenerateCategory - Build metadata for a category implementation.
@@ -7246,7 +7250,8 @@ CGObjCNonFragileABIMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
} else {
llvm::GlobalVariable *GV = ObjCIvarOffsetVariable(Interface, Ivar);
IvarOffsetValue =
- CGF.Builder.CreateAlignedLoad(GV, CGF.getSizeAlign(), "ivar");
+ CGF.Builder.CreateAlignedLoad(GV->getValueType(), GV,
+ CGF.getSizeAlign(), "ivar");
if (IsIvarOffsetKnownIdempotent(CGF, Ivar))
cast<llvm::LoadInst>(IvarOffsetValue)
->setMetadata(CGM.getModule().getMDKindID("invariant.load"),
@@ -7486,7 +7491,7 @@ CGObjCNonFragileABIMac::EmitLoadOfClassRef(CodeGenFunction &CGF,
}
CharUnits Align = CGF.getPointerAlign();
- return CGF.Builder.CreateAlignedLoad(Entry, Align);
+ return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry, Align);
}
llvm::Value *
@@ -7578,7 +7583,7 @@ llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CodeGenFunction &CGF,
CGM.addCompilerUsedGlobal(Entry);
}
- return CGF.Builder.CreateAlignedLoad(Entry, Align);
+ return CGF.Builder.CreateAlignedLoad(ObjCTypes.ClassnfABIPtrTy, Entry, Align);
}
/// GetClass - Return a reference to the class for the given interface
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index f03208fa62ebe..3a7d1ab03e683 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1062,8 +1062,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
llvm::Function::arg_iterator EI = CurFn->arg_end();
--EI;
llvm::Value *Addr = Builder.CreateStructGEP(nullptr, &*EI, Idx);
+ llvm::Type *Ty =
+ cast<llvm::GetElementPtrInst>(Addr)->getResultElementType();
ReturnValuePointer = Address(Addr, getPointerAlign());
- Addr = Builder.CreateAlignedLoad(Addr, getPointerAlign(), "agg.result");
+ Addr = Builder.CreateAlignedLoad(Ty, Addr, getPointerAlign(), "agg.result");
ReturnValue = Address(Addr, CGM.getNaturalTypeAlignment(RetTy));
} else {
ReturnValue = CreateIRTemp(RetTy, "retval");
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 6ece8566ac081..2a6a07e91ce12 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -755,7 +755,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
VFPAddr = CGF.Builder.CreateBitCast(
VFPAddr, FTy->getPointerTo()->getPointerTo());
VirtualFn = CGF.Builder.CreateAlignedLoad(
- VFPAddr, CGF.getPointerAlign(), "memptr.virtualfn");
+ FTy->getPointerTo(), VFPAddr, CGF.getPointerAlign(),
+ "memptr.virtualfn");
}
}
assert(VirtualFn && "Virtual fuction pointer not created!");
@@ -1254,8 +1255,7 @@ void ItaniumCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
// Track back to entry -2 and pull out the offset there.
llvm::Value *OffsetPtr = CGF.Builder.CreateConstInBoundsGEP1_64(
VTable, -2, "complete-offset.ptr");
- llvm::Value *Offset =
- CGF.Builder.CreateAlignedLoad(OffsetPtr, CGF.getPointerAlign());
+ llvm::Value *Offset = CGF.Builder.CreateAlignedLoad(CGF.IntPtrTy, OffsetPtr, CGF.getPointerAlign());
// Apply the offset.
llvm::Value *CompletePtr =
@@ -1467,7 +1467,8 @@ llvm::Value *ItaniumCXXABI::EmitTypeid(CodeGenFunction &CGF,
// Load the type info.
Value = CGF.Builder.CreateConstInBoundsGEP1_64(Value, -1ULL);
}
- return CGF.Builder.CreateAlignedLoad(Value, CGF.getPointerAlign());
+ return CGF.Builder.CreateAlignedLoad(StdTypeInfoPtrTy, Value,
+ CGF.getPointerAlign());
}
bool ItaniumCXXABI::shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
@@ -1535,7 +1536,7 @@ llvm::Value *ItaniumCXXABI::EmitDynamicCastToVoid(CodeGenFunction &CGF,
OffsetToTop =
CGF.Builder.CreateConstInBoundsGEP1_32(/*Type=*/nullptr, VTable, -2U);
OffsetToTop = CGF.Builder.CreateAlignedLoad(
- OffsetToTop, CharUnits::fromQuantity(4), "offset.to.top");
+ CGM.Int32Ty, OffsetToTop, CharUnits::fromQuantity(4), "offset.to.top");
} else {
llvm::Type *PtrDiffLTy =
CGF.ConvertType(CGF.getContext().getPointerDiffType());
@@ -1547,7 +1548,7 @@ llvm::Value *ItaniumCXXABI::EmitDynamicCastToVoid(CodeGenFunction &CGF,
// Get the offset-to-top from the vtable.
OffsetToTop = CGF.Builder.CreateConstInBoundsGEP1_64(VTable, -2ULL);
OffsetToTop = CGF.Builder.CreateAlignedLoad(
- OffsetToTop, CGF.getPointerAlign(), "offset.to.top");
+ PtrDiffLTy, OffsetToTop, CGF.getPointerAlign(), "offset.to.top");
}
// Finally, add the offset to the pointer.
llvm::Value *Value = ThisAddr.getPointer();
@@ -1582,12 +1583,13 @@ ItaniumCXXABI::GetVirtualBaseClassOffset(CodeGenFunction &CGF,
VBaseOffsetPtr =
CGF.Builder.CreateBitCast(VBaseOffsetPtr, CGF.Int32Ty->getPointerTo());
VBaseOffset = CGF.Builder.CreateAlignedLoad(
- VBaseOffsetPtr, CharUnits::fromQuantity(4), "vbase.offset");
+ CGF.Int32Ty, VBaseOffsetPtr, CharUnits::fromQuantity(4),
+ "vbase.offset");
} else {
VBaseOffsetPtr = CGF.Builder.CreateBitCast(VBaseOffsetPtr,
CGM.PtrDiffTy->getPointerTo());
VBaseOffset = CGF.Builder.CreateAlignedLoad(
- VBaseOffsetPtr, CGF.getPointerAlign(), "vbase.offset");
+ CGM.PtrDiffTy, VBaseOffsetPtr, CGF.getPointerAlign(), "vbase.offset");
}
return VBaseOffset;
}
@@ -1848,7 +1850,8 @@ llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
VTT = CGF.Builder.CreateConstInBoundsGEP1_64(VTT, VirtualPointerIndex);
// And load the address point from the VTT.
- return CGF.Builder.CreateAlignedLoad(VTT, CGF.getPointerAlign());
+ return CGF.Builder.CreateAlignedLoad(CGF.VoidPtrTy, VTT,
+ CGF.getPointerAlign());
}
llvm::Constant *ItaniumCXXABI::getVTableAddressPointForConstExpr(
@@ -1923,7 +1926,8 @@ CGCallee ItaniumCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
llvm::Value *VTableSlotPtr =
CGF.Builder.CreateConstInBoundsGEP1_64(VTable, VTableIndex, "vfn");
VFuncLoad =
- CGF.Builder.CreateAlignedLoad(VTableSlotPtr, CGF.getPointerAlign());
+ CGF.Builder.CreateAlignedLoad(Ty->getPointerTo(), VTableSlotPtr,
+ CGF.getPointerAlign());
}
// Add !invariant.load md to virtual function load to indicate that
@@ -2068,7 +2072,8 @@ static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
OffsetPtr =
CGF.Builder.CreateBitCast(OffsetPtr, CGF.Int32Ty->getPointerTo());
Offset =
- CGF.Builder.CreateAlignedLoad(OffsetPtr, CharUnits::fromQuantity(4));
+ CGF.Builder.CreateAlignedLoad(CGF.Int32Ty, OffsetPtr,
+ CharUnits::fromQuantity(4));
} else {
llvm::Type *PtrDiffTy =
CGF.ConvertType(CGF.getContext().getPointerDiffType());
@@ -2077,7 +2082,8 @@ static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
CGF.Builder.CreateBitCast(OffsetPtr, PtrDiffTy->getPointerTo());
// Load the adjustment offset from the vtable.
- Offset = CGF.Builder.CreateAlignedLoad(OffsetPtr, CGF.getPointerAlign());
+ Offset = CGF.Builder.CreateAlignedLoad(PtrDiffTy, OffsetPtr,
+ CGF.getPointerAlign());
}
// Adjust our pointer.
ResultPtr = CGF.Builder.CreateInBoundsGEP(V.getPointer(), Offset);
@@ -2940,7 +2946,7 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
llvm::Value *Val = Var;
if (VD->getType()->isReferenceType()) {
CharUnits Align = CGM.getContext().getDeclAlign(VD);
- Val = Builder.CreateAlignedLoad(Val, Align);
+ Val = Builder.CreateAlignedLoad(Var->getValueType(), Var, Align);
}
if (Val->getType() != Wrapper->getReturnType())
Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index cb0dc1d5d7173..2c7dfee5ead4b 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1911,12 +1911,13 @@ CGCallee MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
SourceLocation Loc) {
CGBuilderTy &Builder = CGF.Builder;
- Ty = Ty->getPointerTo()->getPointerTo();
+ Ty = Ty->getPointerTo();
Address VPtr =
adjustThisArgumentForVirtualFunctionCall(CGF, GD, This, true);
auto *MethodDecl = cast<CXXMethodDecl>(GD.getDecl());
- llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty, MethodDecl->getParent());
+ llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty->getPointerTo(),
+ MethodDecl->getParent());
MicrosoftVTableContext &VFTContext = CGM.getMicrosoftVTableContext();
MethodVFTableLocation ML = VFTContext.getMethodVFTableLocation(GD);
@@ -1944,7 +1945,7 @@ CGCallee MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
llvm::Value *VFuncPtr =
Builder.CreateConstInBoundsGEP1_64(VTable, ML.Index, "vfn");
- VFunc = Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+ VFunc = Builder.CreateAlignedLoad(Ty, VFuncPtr, CGF.getPointerAlign());
}
CGCallee Callee(GD, VFunc);
@@ -2078,7 +2079,8 @@ MicrosoftCXXABI::EmitVirtualMemPtrThunk(const CXXMethodDecl *MD,
llvm::Value *VFuncPtr =
CGF.Builder.CreateConstInBoundsGEP1_64(VTable, ML.Index, "vfn");
llvm::Value *Callee =
- CGF.Builder.CreateAlignedLoad(VFuncPtr, CGF.getPointerAlign());
+ CGF.Builder.CreateAlignedLoad(ThunkTy->getPointerTo(), VFuncPtr,
+ CGF.getPointerAlign());
CGF.EmitMustTailThunk(MD, getThisValue(CGF), {ThunkTy, Callee});
@@ -3022,7 +3024,8 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
VBPtrAlign = CGF.getPointerAlign();
}
- llvm::Value *VBTable = Builder.CreateAlignedLoad(VBPtr, VBPtrAlign, "vbtable");
+ llvm::Value *VBTable = Builder.CreateAlignedLoad(
+ CGM.Int32Ty->getPointerTo(0), VBPtr, VBPtrAlign, "vbtable");
// Translate from byte offset to table index. It improves analyzability.
llvm::Value *VBTableIndex = Builder.CreateAShr(
@@ -3032,8 +3035,8 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
// Load an i32 offset from the vb-table.
llvm::Value *VBaseOffs = Builder.CreateInBoundsGEP(VBTable, VBTableIndex);
VBaseOffs = Builder.CreateBitCast(VBaseOffs, CGM.Int32Ty->getPointerTo(0));
- return Builder.CreateAlignedLoad(VBaseOffs, CharUnits::fromQuantity(4),
- "vbase_offs");
+ return Builder.CreateAlignedLoad(CGM.Int32Ty, VBaseOffs,
+ CharUnits::fromQuantity(4), "vbase_offs");
}
// Returns an adjusted base cast to i8*, since we do more address arithmetic on
@@ -3295,7 +3298,8 @@ llvm::Value *MicrosoftCXXABI::EmitNonNullMemberPointerConversion(
} else {
llvm::Value *Idxs[] = {getZeroInt(), VBIndex};
VirtualBaseAdjustmentOffset =
- Builder.CreateAlignedLoad(Builder.CreateInBoundsGEP(VDispMap, Idxs),
+ Builder.CreateAlignedLoad(CGM.IntTy,
+ Builder.CreateInBoundsGEP(VDispMap, Idxs),
CharUnits::fromQuantity(4));
}
More information about the cfe-commits
mailing list