[llvm] ModuleUtils: Use proper address space defaults in a few places. (PR #119136)
Owen Anderson via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 8 09:43:07 PST 2024
https://github.com/resistor created https://github.com/llvm/llvm-project/pull/119136
None
>From ddeb6e81d647a557dfb905caa5e39fee204c7f9b Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Mon, 9 Dec 2024 06:41:44 +1300
Subject: [PATCH] ModuleUtils: Use proper address space defaults in a few
places.
---
llvm/lib/Transforms/Utils/ModuleUtils.cpp | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index 7249571f344938..0bf68eca5299f4 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -31,6 +31,11 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F,
IRBuilder<> IRB(M.getContext());
FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false);
+ unsigned CtorPtrAS = M.getDataLayout().getProgramAddressSpace();
+ unsigned GlobalsAS = M.getDataLayout().getDefaultGlobalsAddressSpace();
+ llvm::Type *CtorPFTy = llvm::PointerType::get(FnTy, CtorPtrAS);
+ llvm::Type *ArgTy = IRB.getPtrTy(GlobalsAS);
+
// Get the current set of static global constructors and add the new ctor
// to the list.
SmallVector<Constant *, 16> CurrentCtors;
@@ -45,17 +50,16 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F,
}
GVCtor->eraseFromParent();
} else {
- EltTy = StructType::get(IRB.getInt32Ty(),
- PointerType::get(FnTy, F->getAddressSpace()),
- IRB.getPtrTy());
+ EltTy = StructType::get(
+ IRB.getInt32Ty(), PointerType::get(FnTy, F->getAddressSpace()), ArgTy);
}
// Build a 3 field global_ctor entry. We don't take a comdat key.
Constant *CSVals[3];
CSVals[0] = IRB.getInt32(Priority);
CSVals[1] = F;
- CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getPtrTy())
- : Constant::getNullValue(IRB.getPtrTy());
+ CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, ArgTy)
+ : Constant::getNullValue(ArgTy);
Constant *RuntimeCtorInit =
ConstantStruct::get(EltTy, ArrayRef(CSVals, EltTy->getNumElements()));
@@ -483,7 +487,8 @@ bool llvm::lowerGlobalIFuncUsersAsGlobalCtor(
InitBuilder.CreateRetVoid();
- PointerType *ConstantDataTy = PointerType::get(Ctx, 0);
+ PointerType *ConstantDataTy =
+ PointerType::get(Ctx, DL.getDefaultGlobalsAddressSpace());
// TODO: Is this the right priority? Probably should be before any other
// constructors?
More information about the llvm-commits
mailing list