Skip to content

Commit 2443549

Browse files
authored
[IR] Remove some uses of StructType::setBody. NFC. (llvm#113685)
It is simple to create the struct body up front, now that we have transitioned to opaque pointers.
1 parent 46944d1 commit 2443549

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

llvm/lib/CodeGen/ShadowStackGCLowering.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,12 @@ bool ShadowStackGCLoweringImpl::doInitialization(Module &M) {
242242
// void *Roots[]; // Stack roots (in-place array, so we pretend).
243243
// };
244244

245-
StackEntryTy = StructType::create(M.getContext(), "gc_stackentry");
245+
PointerType *StackEntryPtrTy = PointerType::getUnqual(M.getContext());
246246

247247
EltTys.clear();
248-
EltTys.push_back(PointerType::getUnqual(StackEntryTy));
248+
EltTys.push_back(StackEntryPtrTy);
249249
EltTys.push_back(FrameMapPtrTy);
250-
StackEntryTy->setBody(EltTys);
251-
PointerType *StackEntryPtrTy = PointerType::getUnqual(StackEntryTy);
250+
StackEntryTy = StructType::create(EltTys, "gc_stackentry");
252251

253252
// Get the root chain if it already exists.
254253
Head = M.getGlobalVariable("llvm_gc_root_chain");

llvm/lib/Target/X86/X86WinEHState.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,11 @@ Type *WinEHStatePass::getEHLinkRegistrationType() {
210210
if (EHLinkRegistrationTy)
211211
return EHLinkRegistrationTy;
212212
LLVMContext &Context = TheModule->getContext();
213-
EHLinkRegistrationTy = StructType::create(Context, "EHRegistrationNode");
214213
Type *FieldTys[] = {
215-
PointerType::getUnqual(
216-
EHLinkRegistrationTy->getContext()), // EHRegistrationNode *Next
217-
PointerType::getUnqual(Context) // EXCEPTION_DISPOSITION (*Handler)(...)
214+
PointerType::getUnqual(Context), // EHRegistrationNode *Next
215+
PointerType::getUnqual(Context) // EXCEPTION_DISPOSITION (*Handler)(...)
218216
};
219-
EHLinkRegistrationTy->setBody(FieldTys, false);
217+
EHLinkRegistrationTy = StructType::create(FieldTys, "EHRegistrationNode");
220218
return EHLinkRegistrationTy;
221219
}
222220

llvm/lib/Transforms/Coroutines/CoroEarly.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ void Lowerer::lowerCoroNoop(IntrinsicInst *II) {
123123
Module &M = *II->getModule();
124124

125125
// Create a noop.frame struct type.
126-
StructType *FrameTy = StructType::create(C, "NoopCoro.Frame");
127126
auto *FnTy = FunctionType::get(Type::getVoidTy(C), Builder.getPtrTy(0),
128127
/*isVarArg=*/false);
129128
auto *FnPtrTy = Builder.getPtrTy(0);
130-
FrameTy->setBody({FnPtrTy, FnPtrTy});
129+
StructType *FrameTy =
130+
StructType::create({FnPtrTy, FnPtrTy}, "NoopCoro.Frame");
131131

132132
// Create a Noop function that does nothing.
133133
Function *NoopFn =

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ class FrameTypeBuilder {
290290
return Fields.size() - 1;
291291
}
292292

293-
/// Finish the layout and set the body on the given type.
294-
void finish(StructType *Ty);
293+
/// Finish the layout and create the struct type with the given name.
294+
StructType *finish(StringRef Name);
295295

296296
uint64_t getStructSize() const {
297297
assert(IsFinished && "not yet finished!");
@@ -464,7 +464,7 @@ void FrameTypeBuilder::addFieldForAllocas(const Function &F,
464464
});
465465
}
466466

467-
void FrameTypeBuilder::finish(StructType *Ty) {
467+
StructType *FrameTypeBuilder::finish(StringRef Name) {
468468
assert(!IsFinished && "already finished!");
469469

470470
// Prepare the optimal-layout field array.
@@ -526,7 +526,7 @@ void FrameTypeBuilder::finish(StructType *Ty) {
526526
LastOffset = Offset + F.Size;
527527
}
528528

529-
Ty->setBody(FieldTypes, Packed);
529+
StructType *Ty = StructType::create(Context, FieldTypes, Name, Packed);
530530

531531
#ifndef NDEBUG
532532
// Check that the IR layout matches the offsets we expect.
@@ -538,6 +538,8 @@ void FrameTypeBuilder::finish(StructType *Ty) {
538538
#endif
539539

540540
IsFinished = true;
541+
542+
return Ty;
541543
}
542544

543545
static void cacheDIVar(FrameDataInfo &FrameData,
@@ -866,11 +868,6 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
866868
bool OptimizeFrame) {
867869
LLVMContext &C = F.getContext();
868870
const DataLayout &DL = F.getDataLayout();
869-
StructType *FrameTy = [&] {
870-
SmallString<32> Name(F.getName());
871-
Name.append(".Frame");
872-
return StructType::create(C, Name);
873-
}();
874871

875872
// We will use this value to cap the alignment of spilled values.
876873
std::optional<Align> MaxFrameAlignment;
@@ -931,7 +928,12 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
931928
FrameData.setFieldIndex(S.first, Id);
932929
}
933930

934-
B.finish(FrameTy);
931+
StructType *FrameTy = [&] {
932+
SmallString<32> Name(F.getName());
933+
Name.append(".Frame");
934+
return B.finish(Name);
935+
}();
936+
935937
FrameData.updateLayoutIndex(B);
936938
Shape.FrameAlign = B.getStructAlign();
937939
Shape.FrameSize = B.getStructSize();

0 commit comments

Comments
 (0)