Skip to content

Commit 0991b2c

Browse files
committed
IRGen: Factor out IRBuilder helpers for CreateLifetimeStart/End.
1 parent a954ebe commit 0991b2c

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

lib/IRGen/GenInit.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ ContainedAddress FixedTypeInfo::allocateStack(IRGenFunction &IGF, SILType T,
6262

6363
Address alloca =
6464
IGF.createAlloca(getStorageType(), getFixedAlignment(), name);
65-
IGF.Builder.CreateLifetimeStart(alloca.getAddress(),
66-
llvm::ConstantInt::get(IGF.IGM.Int64Ty, getFixedSize().getValue()));
65+
IGF.Builder.CreateLifetimeStart(alloca, getFixedSize());
6766

6867
return { alloca, alloca };
6968
}
@@ -72,6 +71,5 @@ void FixedTypeInfo::deallocateStack(IRGenFunction &IGF, Address addr,
7271
SILType T) const {
7372
if (isKnownEmpty())
7473
return;
75-
IGF.Builder.CreateLifetimeEnd(addr.getAddress(),
76-
llvm::ConstantInt::get(IGF.IGM.Int64Ty, getFixedSize().getValue()));
74+
IGF.Builder.CreateLifetimeEnd(addr, getFixedSize());
7775
}

lib/IRGen/IRBuilder.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ class IRBuilder : public IRBuilderBase {
211211
std::min(dest.getAlignment(),
212212
src.getAlignment()).getValue());
213213
}
214+
215+
using IRBuilderBase::CreateLifetimeStart;
216+
llvm::CallInst *CreateLifetimeStart(Address buf, Size size) {
217+
return CreateLifetimeStart(buf.getAddress(),
218+
llvm::ConstantInt::get(Context, APInt(64, size.getValue())));
219+
}
220+
221+
using IRBuilderBase::CreateLifetimeEnd;
222+
llvm::CallInst *CreateLifetimeEnd(Address buf, Size size) {
223+
return CreateLifetimeEnd(buf.getAddress(),
224+
llvm::ConstantInt::get(Context, APInt(64, size.getValue())));
225+
}
214226
};
215227

216228
} // end namespace irgen

lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,9 +3271,8 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
32713271
// now, but don't allocate the value inside it.
32723272
if (!fixedSizeBuffer.getAddress()) {
32733273
fixedSizeBuffer = IGF.createFixedSizeBufferAlloca(name);
3274-
IGF.Builder.CreateLifetimeStart(fixedSizeBuffer.getAddress(),
3275-
llvm::ConstantInt::get(IGF.IGM.Int64Ty,
3276-
getFixedBufferSize(IGF.IGM).getValue()));
3274+
IGF.Builder.CreateLifetimeStart(fixedSizeBuffer,
3275+
getFixedBufferSize(IGF.IGM));
32773276
}
32783277
if (containerValue)
32793278
IGF.setLoweredAddress(containerValue, fixedSizeBuffer);

lib/IRGen/NonFixedTypeInfo.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ class WitnessSizedTypeInfo : public IndirectTypeInfo<Impl, TypeInfo> {
6262
const llvm::Twine &name) const override {
6363
// Make a fixed-size buffer.
6464
Address buffer = IGF.createFixedSizeBufferAlloca(name);
65-
IGF.Builder.CreateLifetimeStart(buffer.getAddress(),
66-
llvm::ConstantInt::get(IGF.IGM.Int64Ty,
67-
getFixedBufferSize(IGF.IGM).getValue()));
65+
IGF.Builder.CreateLifetimeStart(buffer, getFixedBufferSize(IGF.IGM));
6866

6967
// Allocate an object of the appropriate type within it.
7068
llvm::Value *address = emitAllocateBufferCall(IGF, T, buffer);
@@ -74,9 +72,7 @@ class WitnessSizedTypeInfo : public IndirectTypeInfo<Impl, TypeInfo> {
7472
void deallocateStack(IRGenFunction &IGF, Address buffer,
7573
SILType T) const override {
7674
emitDeallocateBufferCall(IGF, T, buffer);
77-
IGF.Builder.CreateLifetimeEnd(buffer.getAddress(),
78-
llvm::ConstantInt::get(IGF.IGM.Int64Ty,
79-
getFixedBufferSize(IGF.IGM).getValue()));
75+
IGF.Builder.CreateLifetimeEnd(buffer, getFixedBufferSize(IGF.IGM));
8076
}
8177

8278
llvm::Value *getValueWitnessTable(IRGenFunction &IGF, SILType T) const {

0 commit comments

Comments
 (0)