[llvm] 2443549 - [IR] Remove some uses of StructType::setBody. NFC. (#113685)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 04:44:57 PDT 2024
Author: Jay Foad
Date: 2024-10-29T11:44:53Z
New Revision: 2443549b853908352a3b7b9bd6c07616492814a1
URL: https://github.com/llvm/llvm-project/commit/2443549b853908352a3b7b9bd6c07616492814a1
DIFF: https://github.com/llvm/llvm-project/commit/2443549b853908352a3b7b9bd6c07616492814a1.diff
LOG: [IR] Remove some uses of StructType::setBody. NFC. (#113685)
It is simple to create the struct body up front, now that we have
transitioned to opaque pointers.
Added:
Modified:
llvm/lib/CodeGen/ShadowStackGCLowering.cpp
llvm/lib/Target/X86/X86WinEHState.cpp
llvm/lib/Transforms/Coroutines/CoroEarly.cpp
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
index 232e5e2bb886df..f8ab44124b3ae8 100644
--- a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
+++ b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
@@ -242,13 +242,12 @@ bool ShadowStackGCLoweringImpl::doInitialization(Module &M) {
// void *Roots[]; // Stack roots (in-place array, so we pretend).
// };
- StackEntryTy = StructType::create(M.getContext(), "gc_stackentry");
+ PointerType *StackEntryPtrTy = PointerType::getUnqual(M.getContext());
EltTys.clear();
- EltTys.push_back(PointerType::getUnqual(StackEntryTy));
+ EltTys.push_back(StackEntryPtrTy);
EltTys.push_back(FrameMapPtrTy);
- StackEntryTy->setBody(EltTys);
- PointerType *StackEntryPtrTy = PointerType::getUnqual(StackEntryTy);
+ StackEntryTy = StructType::create(EltTys, "gc_stackentry");
// Get the root chain if it already exists.
Head = M.getGlobalVariable("llvm_gc_root_chain");
diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp
index bc9fd801f94b22..ef212736730114 100644
--- a/llvm/lib/Target/X86/X86WinEHState.cpp
+++ b/llvm/lib/Target/X86/X86WinEHState.cpp
@@ -210,13 +210,11 @@ Type *WinEHStatePass::getEHLinkRegistrationType() {
if (EHLinkRegistrationTy)
return EHLinkRegistrationTy;
LLVMContext &Context = TheModule->getContext();
- EHLinkRegistrationTy = StructType::create(Context, "EHRegistrationNode");
Type *FieldTys[] = {
- PointerType::getUnqual(
- EHLinkRegistrationTy->getContext()), // EHRegistrationNode *Next
- PointerType::getUnqual(Context) // EXCEPTION_DISPOSITION (*Handler)(...)
+ PointerType::getUnqual(Context), // EHRegistrationNode *Next
+ PointerType::getUnqual(Context) // EXCEPTION_DISPOSITION (*Handler)(...)
};
- EHLinkRegistrationTy->setBody(FieldTys, false);
+ EHLinkRegistrationTy = StructType::create(FieldTys, "EHRegistrationNode");
return EHLinkRegistrationTy;
}
diff --git a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp
index a3674306f3e10e..5375448d2d2e2b 100644
--- a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp
@@ -123,11 +123,11 @@ void Lowerer::lowerCoroNoop(IntrinsicInst *II) {
Module &M = *II->getModule();
// Create a noop.frame struct type.
- StructType *FrameTy = StructType::create(C, "NoopCoro.Frame");
auto *FnTy = FunctionType::get(Type::getVoidTy(C), Builder.getPtrTy(0),
/*isVarArg=*/false);
auto *FnPtrTy = Builder.getPtrTy(0);
- FrameTy->setBody({FnPtrTy, FnPtrTy});
+ StructType *FrameTy =
+ StructType::create({FnPtrTy, FnPtrTy}, "NoopCoro.Frame");
// Create a Noop function that does nothing.
Function *NoopFn =
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 021fcc20c1f18b..bb6126026d9058 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -290,8 +290,8 @@ class FrameTypeBuilder {
return Fields.size() - 1;
}
- /// Finish the layout and set the body on the given type.
- void finish(StructType *Ty);
+ /// Finish the layout and create the struct type with the given name.
+ StructType *finish(StringRef Name);
uint64_t getStructSize() const {
assert(IsFinished && "not yet finished!");
@@ -464,7 +464,7 @@ void FrameTypeBuilder::addFieldForAllocas(const Function &F,
});
}
-void FrameTypeBuilder::finish(StructType *Ty) {
+StructType *FrameTypeBuilder::finish(StringRef Name) {
assert(!IsFinished && "already finished!");
// Prepare the optimal-layout field array.
@@ -526,7 +526,7 @@ void FrameTypeBuilder::finish(StructType *Ty) {
LastOffset = Offset + F.Size;
}
- Ty->setBody(FieldTypes, Packed);
+ StructType *Ty = StructType::create(Context, FieldTypes, Name, Packed);
#ifndef NDEBUG
// Check that the IR layout matches the offsets we expect.
@@ -538,6 +538,8 @@ void FrameTypeBuilder::finish(StructType *Ty) {
#endif
IsFinished = true;
+
+ return Ty;
}
static void cacheDIVar(FrameDataInfo &FrameData,
@@ -866,11 +868,6 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
bool OptimizeFrame) {
LLVMContext &C = F.getContext();
const DataLayout &DL = F.getDataLayout();
- StructType *FrameTy = [&] {
- SmallString<32> Name(F.getName());
- Name.append(".Frame");
- return StructType::create(C, Name);
- }();
// We will use this value to cap the alignment of spilled values.
std::optional<Align> MaxFrameAlignment;
@@ -931,7 +928,12 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
FrameData.setFieldIndex(S.first, Id);
}
- B.finish(FrameTy);
+ StructType *FrameTy = [&] {
+ SmallString<32> Name(F.getName());
+ Name.append(".Frame");
+ return B.finish(Name);
+ }();
+
FrameData.updateLayoutIndex(B);
Shape.FrameAlign = B.getStructAlign();
Shape.FrameSize = B.getStructSize();
More information about the llvm-commits
mailing list