Skip to content

Fix some deprecated uses of IRBuilder API #39686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,9 @@ std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
} else if (auto *function = functionPointer.getRawAsyncFunction()) {
fn = function;
} else {
llvm::Value *addrPtr = IGF.Builder.CreateStructGEP(getAFPPtr(), 0);
llvm::Value *addrPtr = IGF.Builder.CreateStructGEP(
getAFPPtr()->getType()->getScalarType()->getPointerElementType(),
getAFPPtr(), 0);
fn = IGF.emitLoadOfRelativePointer(
Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false,
/*expectedType*/ functionPointer.getFunctionType()->getPointerTo());
Expand All @@ -2037,7 +2039,9 @@ std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
initialContextSize.getValue());
} else {
assert(!functionPointer.useStaticContextSize());
auto *sizePtr = IGF.Builder.CreateStructGEP(getAFPPtr(), 1);
auto *sizePtr = IGF.Builder.CreateStructGEP(
getAFPPtr()->getType()->getScalarType()->getPointerElementType(),
getAFPPtr(), 1);
size = IGF.Builder.CreateLoad(sizePtr, IGF.IGM.getPointerAlignment());
}
}
Expand Down Expand Up @@ -4830,7 +4834,9 @@ llvm::Value *FunctionPointer::getPointer(IRGenFunction &IGF) const {
}
auto *descriptorPtr =
IGF.Builder.CreateBitCast(fnPtr, IGF.IGM.AsyncFunctionPointerPtrTy);
auto *addrPtr = IGF.Builder.CreateStructGEP(descriptorPtr, 0);
auto *addrPtr = IGF.Builder.CreateStructGEP(
descriptorPtr->getType()->getScalarType()->getPointerElementType(),
descriptorPtr, 0);
auto *result = IGF.emitLoadOfRelativePointer(
Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false,
/*expectedType*/ getFunctionType()->getPointerTo());
Expand Down
3 changes: 2 additions & 1 deletion lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ llvm::Value *IRGenFunction::emitByteOffsetGEP(llvm::Value *base,
const llvm::Twine &name) {
assert(offset->getType() == IGM.SizeTy || offset->getType() == IGM.Int32Ty);
auto addr = Builder.CreateBitCast(base, IGM.Int8PtrTy);
addr = Builder.CreateInBoundsGEP(addr, offset);
addr = Builder.CreateInBoundsGEP(
addr->getType()->getScalarType()->getPointerElementType(), addr, offset);
return Builder.CreateBitCast(addr, objectType->getPointerTo(), name);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/IRGen/GenHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,9 @@ static llvm::Value *emitLoadOfHeapMetadataRef(IRGenFunction &IGF,
structTy = dyn_cast<llvm::StructType>(eltTy);
} while (structTy != nullptr);

slot = IGF.Builder.CreateInBoundsGEP(object, indexes);
slot = IGF.Builder.CreateInBoundsGEP(
object->getType()->getScalarType()->getPointerElementType(), object,
indexes);

if (!suppressCast) {
slot = IGF.Builder.CreateBitCast(slot,
Expand Down
45 changes: 32 additions & 13 deletions lib/IRGen/GenKeyPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ bindPolymorphicArgumentsFromComponentIndices(IRGenFunction &IGF,
requirements.size() * IGF.IGM.getPointerSize().getValue());

auto genericArgsOffset = IGF.Builder.CreateSub(size, genericArgsSize);
args = IGF.Builder.CreateInBoundsGEP(args, genericArgsOffset);
args = IGF.Builder.CreateInBoundsGEP(
args->getType()->getScalarType()->getPointerElementType(), args,
genericArgsOffset);
}
bindFromGenericRequirementsBuffer(IGF, requirements,
Address(args, IGF.IGM.getPointerAlignment()),
Expand Down Expand Up @@ -414,7 +416,10 @@ getWitnessTableForComputedComponent(IRGenModule &IGM,
} else {
offset = llvm::ConstantInt::get(IGM.SizeTy, 0);
}
auto elt = IGF.Builder.CreateInBoundsGEP(componentArgsBuf, offset);
auto elt = IGF.Builder.CreateInBoundsGEP(componentArgsBuf->getType()
->getScalarType()
->getPointerElementType(),
componentArgsBuf, offset);
auto eltAddr = ti.getAddressForPointer(
IGF.Builder.CreateBitCast(elt, ti.getStorageType()->getPointerTo()));
ti.destroy(IGF, eltAddr, ty,
Expand Down Expand Up @@ -466,8 +471,12 @@ getWitnessTableForComputedComponent(IRGenModule &IGM,
} else {
offset = llvm::ConstantInt::get(IGM.SizeTy, 0);
}
auto sourceElt = IGF.Builder.CreateInBoundsGEP(sourceArgsBuf, offset);
auto destElt = IGF.Builder.CreateInBoundsGEP(destArgsBuf, offset);
auto sourceElt = IGF.Builder.CreateInBoundsGEP(
sourceArgsBuf->getType()->getScalarType()->getPointerElementType(),
sourceArgsBuf, offset);
auto destElt = IGF.Builder.CreateInBoundsGEP(
destArgsBuf->getType()->getScalarType()->getPointerElementType(),
destArgsBuf, offset);
auto sourceEltAddr = ti.getAddressForPointer(
IGF.Builder.CreateBitCast(sourceElt,
ti.getStorageType()->getPointerTo()));
Expand All @@ -487,10 +496,14 @@ getWitnessTableForComputedComponent(IRGenModule &IGM,
auto notAlignMask = IGF.Builder.CreateNot(envAlignMask);
offset = IGF.Builder.CreateAdd(offset, envAlignMask);
offset = IGF.Builder.CreateAnd(offset, notAlignMask);

auto sourceEnv = IGF.Builder.CreateInBoundsGEP(sourceArgsBuf, offset);
auto destEnv = IGF.Builder.CreateInBoundsGEP(destArgsBuf, offset);


auto sourceEnv = IGF.Builder.CreateInBoundsGEP(
sourceArgsBuf->getType()->getScalarType()->getPointerElementType(),
sourceArgsBuf, offset);
auto destEnv = IGF.Builder.CreateInBoundsGEP(
destArgsBuf->getType()->getScalarType()->getPointerElementType(),
destArgsBuf, offset);

auto align = IGM.getPointerAlignment().getValue();
IGF.Builder.CreateMemCpy(destEnv, llvm::MaybeAlign(align), sourceEnv,
llvm::MaybeAlign(align),
Expand Down Expand Up @@ -601,8 +614,10 @@ getInitializerForComputedComponent(IRGenModule &IGM,
offset = IGF.Builder.CreateAdd(offset, alignMask);
offset = IGF.Builder.CreateAnd(offset, notAlignMask);
}

auto ptr = IGF.Builder.CreateInBoundsGEP(src, offset);

auto ptr = IGF.Builder.CreateInBoundsGEP(
src->getType()->getScalarType()->getPointerElementType(), src,
offset);
auto addr = ti.getAddressForPointer(IGF.Builder.CreateBitCast(
ptr, ti.getStorageType()->getPointerTo()));
srcAddresses.push_back(addr);
Expand Down Expand Up @@ -630,8 +645,10 @@ getInitializerForComputedComponent(IRGenModule &IGM,
offset = IGF.Builder.CreateAdd(offset, alignMask);
offset = IGF.Builder.CreateAnd(offset, notAlignMask);
}

auto ptr = IGF.Builder.CreateInBoundsGEP(dest, offset);

auto ptr = IGF.Builder.CreateInBoundsGEP(
dest->getType()->getScalarType()->getPointerElementType(), dest,
offset);
auto destAddr = ti.getAddressForPointer(IGF.Builder.CreateBitCast(
ptr, ti.getStorageType()->getPointerTo()));

Expand Down Expand Up @@ -660,7 +677,9 @@ getInitializerForComputedComponent(IRGenModule &IGM,
auto notGenericEnvAlignMask = IGF.Builder.CreateNot(genericEnvAlignMask);
offset = IGF.Builder.CreateAdd(offset, genericEnvAlignMask);
offset = IGF.Builder.CreateAnd(offset, notGenericEnvAlignMask);
destGenericEnv = IGF.Builder.CreateInBoundsGEP(dest, offset);
destGenericEnv = IGF.Builder.CreateInBoundsGEP(
dest->getType()->getScalarType()->getPointerElementType(), dest,
offset);
}

auto align = IGM.getPointerAlignment().getValue();
Expand Down
3 changes: 2 additions & 1 deletion lib/IRGen/GenOpaque.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ llvm::Value *irgen::emitInvariantLoadOfOpaqueWitness(IRGenFunction &IGF,
assert(table->getType() == IGF.IGM.WitnessTablePtrTy);

// GEP to the appropriate index.
llvm::Value *slot = IGF.Builder.CreateInBoundsGEP(table, index);
llvm::Value *slot = IGF.Builder.CreateInBoundsGEP(
table->getType()->getScalarType()->getPointerElementType(), table, index);

if (slotPtr) *slotPtr = slot;

Expand Down
9 changes: 6 additions & 3 deletions lib/IRGen/GenStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,12 @@ namespace {
// the compiler's idea of the offset.
auto metadataBytes =
IGF.Builder.CreateBitCast(metadata, IGF.IGM.Int8PtrTy);
auto fieldOffsetPtr =
IGF.Builder.CreateInBoundsGEP(metadataBytes,
IGF.IGM.getSize(scanner.FieldOffset - scanner.AddressPoint));
auto fieldOffsetPtr = IGF.Builder.CreateInBoundsGEP(
metadataBytes->getType()
->getScalarType()
->getPointerElementType(),
metadataBytes,
IGF.IGM.getSize(scanner.FieldOffset - scanner.AddressPoint));
fieldOffsetPtr =
IGF.Builder.CreateBitCast(fieldOffsetPtr,
IGF.IGM.Int32Ty->getPointerTo());
Expand Down
4 changes: 3 additions & 1 deletion lib/IRGen/GenTuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ namespace {
IGF.IGM.getSize(Size(index)), // [index]
llvm::ConstantInt::get(IGF.IGM.Int32Ty, 1) // .Offset
};
auto slot = IGF.Builder.CreateInBoundsGEP(asTuple, indices);
auto slot = IGF.Builder.CreateInBoundsGEP(
asTuple->getType()->getScalarType()->getPointerElementType(), asTuple,
indices);

return IGF.Builder.CreateLoad(slot, IGF.IGM.getPointerAlignment(),
metadata->getName()
Expand Down
8 changes: 6 additions & 2 deletions lib/IRGen/GenValueWitness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,15 @@ Address TypeInfo::indexArray(IRGenFunction &IGF, Address base,
if (size->getType() != index->getType())
size = IGF.Builder.CreateZExtOrTrunc(size, index->getType());
llvm::Value *distance = IGF.Builder.CreateNSWMul(index, size);
destValue = IGF.Builder.CreateInBoundsGEP(byteAddr, distance);
destValue = IGF.Builder.CreateInBoundsGEP(
byteAddr->getType()->getScalarType()->getPointerElementType(), byteAddr,
distance);
destValue = IGF.Builder.CreateBitCast(destValue, base.getType());
} else {
// We don't expose a non-inbounds GEP operation.
destValue = IGF.Builder.CreateInBoundsGEP(base.getAddress(), index);
destValue = IGF.Builder.CreateInBoundsGEP(
base.getAddress()->getType()->getScalarType()->getPointerElementType(),
base.getAddress(), index);
stride = fixedTI->getFixedStride();
}
if (auto *IndexConst = dyn_cast<llvm::ConstantInt>(index)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/IRGen/IRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class IRBuilder : public IRBuilderBase {

llvm::LoadInst *CreateLoad(llvm::Value *addr, Alignment align,
const llvm::Twine &name = "") {
llvm::LoadInst *load = IRBuilderBase::CreateLoad(addr, name);
llvm::LoadInst *load = IRBuilderBase::CreateLoad(
addr->getType()->getPointerElementType(), addr, name);
load->setAlignment(llvm::MaybeAlign(align.getValue()).valueOrOne());
return load;
}
Expand Down
28 changes: 20 additions & 8 deletions lib/IRGen/IRGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ Address IRGenFunction::emitAddressAtOffset(llvm::Value *base, Offset offset,
auto scaledIndex =
int64_t(byteOffset.getValue()) / int64_t(objectSize.getValue());
auto indexValue = IGM.getSize(Size(scaledIndex));
auto slotPtr = Builder.CreateInBoundsGEP(base, indexValue);
auto slotPtr = Builder.CreateInBoundsGEP(
base->getType()->getScalarType()->getPointerElementType(), base,
indexValue);

return Address(slotPtr, objectAlignment);
}
Expand Down Expand Up @@ -684,8 +686,11 @@ void IRGenFunction::emitAwaitAsyncContinuation(
// swift_continuation_await, emit the old inline sequence. This can
// be removed as soon as we're sure that such SDKs don't exist.
if (!useContinuationAwait) {
auto contAwaitSyncAddr =
Builder.CreateStructGEP(AsyncCoroutineCurrentContinuationContext, 1);
auto contAwaitSyncAddr = Builder.CreateStructGEP(
AsyncCoroutineCurrentContinuationContext->getType()
->getScalarType()
->getPointerElementType(),
AsyncCoroutineCurrentContinuationContext, 1);

auto pendingV = llvm::ConstantInt::get(
contAwaitSyncAddr->getType()->getPointerElementType(),
Expand Down Expand Up @@ -754,9 +759,13 @@ void IRGenFunction::emitAwaitAsyncContinuation(
// to the error destination.
if (optionalErrorBB) {
auto normalContBB = createBasicBlock("await.async.normal");
auto contErrResultAddr = Address(
Builder.CreateStructGEP(AsyncCoroutineCurrentContinuationContext, 2),
pointerAlignment);
auto contErrResultAddr =
Address(Builder.CreateStructGEP(
AsyncCoroutineCurrentContinuationContext->getType()
->getScalarType()
->getPointerElementType(),
AsyncCoroutineCurrentContinuationContext, 2),
pointerAlignment);
auto errorRes = Builder.CreateLoad(contErrResultAddr);
auto nullError = llvm::Constant::getNullValue(errorRes->getType());
auto hasError = Builder.CreateICmpNE(errorRes, nullError);
Expand All @@ -769,8 +778,11 @@ void IRGenFunction::emitAwaitAsyncContinuation(
// result slot, load from the temporary we created during
// get_async_continuation.
if (!isIndirectResult) {
auto contResultAddrAddr =
Builder.CreateStructGEP(AsyncCoroutineCurrentContinuationContext, 3);
auto contResultAddrAddr = Builder.CreateStructGEP(
AsyncCoroutineCurrentContinuationContext->getType()
->getScalarType()
->getPointerElementType(),
AsyncCoroutineCurrentContinuationContext, 3);
auto resultAddrVal =
Builder.CreateLoad(Address(contResultAddrAddr, pointerAlignment));
// Take the result.
Expand Down
23 changes: 16 additions & 7 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,8 @@ class IRGenSILFunction :
auto shadow = Alloca.getAddress();
auto inst = cast<llvm::Instruction>(shadow);
llvm::IRBuilder<> builder(inst->getNextNode());
shadow = builder.CreateLoad(shadow);
shadow = builder.CreateLoad(shadow->getType()->getPointerElementType(),
shadow);
copy.push_back(shadow);
return;
}
Expand Down Expand Up @@ -2482,7 +2483,9 @@ void IRGenSILFunction::visitDifferentiabilityWitnessFunctionInst(
llvm_unreachable("Not yet implemented");
}

diffWitness = Builder.CreateStructGEP(diffWitness, offset);
diffWitness = Builder.CreateStructGEP(
diffWitness->getType()->getScalarType()->getPointerElementType(),
diffWitness, offset);
diffWitness = Builder.CreateLoad(diffWitness, IGM.getPointerAlignment());

auto fnType = cast<SILFunctionType>(i->getType().getASTType());
Expand Down Expand Up @@ -5148,7 +5151,8 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
ValueDomPoints.push_back({shadow, getActiveDominancePoint()});
auto inst = cast<llvm::Instruction>(shadow);
llvm::IRBuilder<> builder(inst->getNextNode());
addr = builder.CreateLoad(shadow);
addr =
builder.CreateLoad(shadow->getType()->getPointerElementType(), shadow);
}

bindArchetypes(DbgTy.getType());
Expand Down Expand Up @@ -6243,8 +6247,12 @@ void IRGenSILFunction::visitKeyPathInst(swift::KeyPathInst *I) {
for (unsigned i : indices(I->getAllOperands())) {
auto operand = I->getAllOperands()[i].get();
auto &ti = getTypeInfo(operand->getType());
auto ptr = Builder.CreateInBoundsGEP(argsBuf.getAddress(),
operandOffsets[i]);
auto ptr =
Builder.CreateInBoundsGEP(argsBuf.getAddress()
->getType()
->getScalarType()
->getPointerElementType(),
argsBuf.getAddress(), operandOffsets[i]);
auto addr = ti.getAddressForPointer(
Builder.CreateBitCast(ptr, ti.getStorageType()->getPointerTo()));
if (operand->getType().isAddress()) {
Expand Down Expand Up @@ -6334,8 +6342,9 @@ void IRGenSILFunction::visitIndexRawPointerInst(swift::IndexRawPointerInst *i) {
llvm::Value *index = indexValues.claimNext();

// We don't expose a non-inbounds GEP operation.
llvm::Value *destValue = Builder.CreateInBoundsGEP(base, index);

llvm::Value *destValue = Builder.CreateInBoundsGEP(
base->getType()->getScalarType()->getPointerElementType(), base, index);

Explosion result;
result.add(destValue);
setLoweredExplosion(i, result);
Expand Down
18 changes: 13 additions & 5 deletions lib/IRGen/TypeLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ llvm::Value *TypeLayoutEntry::getEnumTagSinglePayloadGeneric(
// Read the value stored in the extra tag bytes.
auto *valueAddr =
Builder.CreateBitOrPointerCast(addr.getAddress(), IGM.Int8PtrTy);
auto *extraTagBitsAddr = Builder.CreateInBoundsGEP(valueAddr, size);
auto *extraTagBitsAddr = Builder.CreateInBoundsGEP(
valueAddr->getType()->getScalarType()->getPointerElementType(), valueAddr,
size);
auto *extraTagBits = emitGetTag(IGF, Address(extraTagBitsAddr, Alignment(1)),
numExtraTagBytes);

Expand Down Expand Up @@ -505,8 +507,11 @@ void TypeLayoutEntry::storeEnumTagSinglePayloadGeneric(

auto *valueAddr =
Builder.CreateBitOrPointerCast(addr.getAddress(), IGM.Int8PtrTy);
auto extraTagBitsAddr =
Address(Builder.CreateInBoundsGEP(valueAddr, size), Alignment(1));
auto extraTagBitsAddr = Address(
Builder.CreateInBoundsGEP(
valueAddr->getType()->getScalarType()->getPointerElementType(),
valueAddr, size),
Alignment(1));

// Do we need extra tag bytes.
auto *entryBB = Builder.GetInsertBlock();
Expand Down Expand Up @@ -2226,8 +2231,11 @@ EnumTypeLayoutEntry::getMultiPalyloadEnumTagByteAddrAndNumBytes(
auto payloadSize = maxPayloadSize(IGF);
auto *valueAddr =
Builder.CreateBitOrPointerCast(addr.getAddress(), IGM.Int8PtrTy);
auto extraTagBytesAddr =
Address(Builder.CreateInBoundsGEP(valueAddr, payloadSize), Alignment(1));
auto extraTagBytesAddr = Address(
Builder.CreateInBoundsGEP(
valueAddr->getType()->getScalarType()->getPointerElementType(),
valueAddr, payloadSize),
Alignment(1));
auto numPayloads = IGM.getInt32(cases.size());
auto emptyCaseCount = IGM.getInt32(numEmptyCases);

Expand Down