Skip to content

Commit

Permalink
[IR] Replace uses of IRBuilder::getInt8PtrTy with getPtrTy. NFC (#73154)
Browse files Browse the repository at this point in the history
  • Loading branch information
topperc committed Nov 22, 2023
1 parent 6772c4f commit aba0401
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 51 deletions.
33 changes: 13 additions & 20 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,15 +1767,14 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
SharedsSize);
}

Value *DepArrayPtr = nullptr;
Value *DepArray = nullptr;
if (Dependencies.size()) {
InsertPointTy OldIP = Builder.saveIP();
Builder.SetInsertPoint(
&OldIP.getBlock()->getParent()->getEntryBlock().back());

Type *DepArrayTy = ArrayType::get(DependInfo, Dependencies.size());
Value *DepArray =
Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr");
DepArray = Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr");

unsigned P = 0;
for (const DependData &Dep : Dependencies) {
Expand Down Expand Up @@ -1806,7 +1805,6 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
++P;
}

DepArrayPtr = Builder.CreateBitCast(DepArray, Builder.getInt8PtrTy());
Builder.restoreIP(OldIP);
}

Expand Down Expand Up @@ -1856,7 +1854,7 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
Builder.CreateCall(
TaskFn,
{Ident, ThreadID, TaskData, Builder.getInt32(Dependencies.size()),
DepArrayPtr, ConstantInt::get(Builder.getInt32Ty(), 0),
DepArray, ConstantInt::get(Builder.getInt32Ty(), 0),
ConstantPointerNull::get(PointerType::getUnqual(M.getContext()))});

} else {
Expand Down Expand Up @@ -2082,7 +2080,7 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
// Create and populate array of type-erased pointers to private reduction
// values.
unsigned NumReductions = ReductionInfos.size();
Type *RedArrayTy = ArrayType::get(Builder.getInt8PtrTy(), NumReductions);
Type *RedArrayTy = ArrayType::get(Builder.getPtrTy(), NumReductions);
Builder.restoreIP(AllocaIP);
Value *RedArray = Builder.CreateAlloca(RedArrayTy, nullptr, "red.array");

Expand All @@ -2093,18 +2091,13 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
const ReductionInfo &RI = En.value();
Value *RedArrayElemPtr = Builder.CreateConstInBoundsGEP2_64(
RedArrayTy, RedArray, 0, Index, "red.array.elem." + Twine(Index));
Value *Casted =
Builder.CreateBitCast(RI.PrivateVariable, Builder.getInt8PtrTy(),
"private.red.var." + Twine(Index) + ".casted");
Builder.CreateStore(Casted, RedArrayElemPtr);
Builder.CreateStore(RI.PrivateVariable, RedArrayElemPtr);
}

// Emit a call to the runtime function that orchestrates the reduction.
// Declare the reduction function in the process.
Function *Func = Builder.GetInsertBlock()->getParent();
Module *Module = Func->getParent();
Value *RedArrayPtr =
Builder.CreateBitCast(RedArray, Builder.getInt8PtrTy(), "red.array.ptr");
uint32_t SrcLocStrSize;
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
bool CanGenerateAtomic =
Expand All @@ -2127,8 +2120,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
: RuntimeFunction::OMPRTL___kmpc_reduce);
CallInst *ReduceCall =
Builder.CreateCall(ReduceFunc,
{Ident, ThreadId, NumVariables, RedArraySize,
RedArrayPtr, ReductionFunc, Lock},
{Ident, ThreadId, NumVariables, RedArraySize, RedArray,
ReductionFunc, Lock},
"reduce");

// Create final reduction entry blocks for the atomic and non-atomic case.
Expand Down Expand Up @@ -2197,12 +2190,12 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
const ReductionInfo &RI = En.value();
Value *LHSI8PtrPtr = Builder.CreateConstInBoundsGEP2_64(
RedArrayTy, LHSArrayPtr, 0, En.index());
Value *LHSI8Ptr = Builder.CreateLoad(Builder.getInt8PtrTy(), LHSI8PtrPtr);
Value *LHSI8Ptr = Builder.CreateLoad(Builder.getPtrTy(), LHSI8PtrPtr);
Value *LHSPtr = Builder.CreateBitCast(LHSI8Ptr, RI.Variable->getType());
Value *LHS = Builder.CreateLoad(RI.ElementType, LHSPtr);
Value *RHSI8PtrPtr = Builder.CreateConstInBoundsGEP2_64(
RedArrayTy, RHSArrayPtr, 0, En.index());
Value *RHSI8Ptr = Builder.CreateLoad(Builder.getInt8PtrTy(), RHSI8PtrPtr);
Value *RHSI8Ptr = Builder.CreateLoad(Builder.getPtrTy(), RHSI8PtrPtr);
Value *RHSPtr =
Builder.CreateBitCast(RHSI8Ptr, RI.PrivateVariable->getType());
Value *RHS = Builder.CreateLoad(RI.ElementType, RHSPtr);
Expand Down Expand Up @@ -5198,12 +5191,12 @@ void OpenMPIRBuilder::emitNonContiguousDescriptor(InsertPointTy AllocaIP,
// args[I] = &dims
Builder.restoreIP(CodeGenIP);
Value *DAddr = Builder.CreatePointerBitCastOrAddrSpaceCast(
DimsAddr, Builder.getInt8PtrTy());
DimsAddr, Builder.getPtrTy());
Value *P = Builder.CreateConstInBoundsGEP2_32(
ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs),
ArrayType::get(Builder.getPtrTy(), Info.NumberOfPtrs),
Info.RTArgs.PointersArray, 0, I);
Builder.CreateAlignedStore(
DAddr, P, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
DAddr, P, M.getDataLayout().getPrefTypeAlign(Builder.getPtrTy()));
++L;
}
}
Expand All @@ -5225,7 +5218,7 @@ void OpenMPIRBuilder::emitOffloadingArrays(
// Detect if we have any capture size requiring runtime evaluation of the
// size so that a constant array could be eventually used.
ArrayType *PointerArrayType =
ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs);
ArrayType::get(Builder.getPtrTy(), Info.NumberOfPtrs);

Info.RTArgs.BasePointersArray = Builder.CreateAlloca(
PointerArrayType, /* ArraySize = */ nullptr, ".offload_baseptrs");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
Value *FrameRaw = SubFn->getFrame();
int Index = SubFn->getIndex();

auto *FrameTy = StructType::get(
SubFn->getContext(), {Builder.getInt8PtrTy(), Builder.getInt8PtrTy()});
auto *FrameTy = StructType::get(SubFn->getContext(),
{Builder.getPtrTy(), Builder.getPtrTy()});
PointerType *FramePtrTy = FrameTy->getPointerTo();

Builder.SetInsertPoint(SubFn);
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,9 @@ static void handleNoSuspendCoroutine(coro::Shape &Shape) {
IRBuilder<> Builder(AllocInst);
auto *Frame = Builder.CreateAlloca(Shape.FrameTy);
Frame->setAlignment(Shape.FrameAlign);
auto *VFrame = Builder.CreateBitCast(Frame, Builder.getInt8PtrTy());
AllocInst->replaceAllUsesWith(Builder.getFalse());
AllocInst->eraseFromParent();
CoroBegin->replaceAllUsesWith(VFrame);
CoroBegin->replaceAllUsesWith(Frame);
} else {
CoroBegin->replaceAllUsesWith(CoroBegin->getMem());
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ bool LoopIdiomRecognize::processLoopStridedStore(
SCEVExpander Expander(*SE, *DL, "loop-idiom");
SCEVExpanderCleaner ExpCleaner(Expander);

Type *DestInt8PtrTy = Builder.getInt8PtrTy(DestAS);
Type *DestInt8PtrTy = Builder.getPtrTy(DestAS);
Type *IntIdxTy = DL->getIndexType(DestPtr->getType());

bool Changed = false;
Expand Down Expand Up @@ -1282,7 +1282,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(
// feeds the stores. Check for an alias by generating the base address and
// checking everything.
Value *StoreBasePtr = Expander.expandCodeFor(
StrStart, Builder.getInt8PtrTy(StrAS), Preheader->getTerminator());
StrStart, Builder.getPtrTy(StrAS), Preheader->getTerminator());

// From here on out, conservatively report to the pass manager that we've
// changed the IR, even if we later clean up these added instructions. There
Expand Down Expand Up @@ -1334,8 +1334,8 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(

// For a memcpy, we have to make sure that the input array is not being
// mutated by the loop.
Value *LoadBasePtr = Expander.expandCodeFor(
LdStart, Builder.getInt8PtrTy(LdAS), Preheader->getTerminator());
Value *LoadBasePtr = Expander.expandCodeFor(LdStart, Builder.getPtrTy(LdAS),
Preheader->getTerminator());

// If the store is a memcpy instruction, we must check if it will write to
// the load memory locations. So remove it from the ignored stores.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3502,7 +3502,7 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
NewEndOffset - NewBeginOffset);
// Lifetime intrinsics always expect an i8* so directly get such a pointer
// for the new alloca slice.
Type *PointerTy = IRB.getInt8PtrTy(OldPtr->getType()->getPointerAddressSpace());
Type *PointerTy = IRB.getPtrTy(OldPtr->getType()->getPointerAddressSpace());
Value *Ptr = getNewAllocaSlicePtr(IRB, PointerTy);
Value *New;
if (II.getIntrinsicID() == Intrinsic::lifetime_start)
Expand Down
12 changes: 5 additions & 7 deletions llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,17 @@ static Value *getStrlenWithNull(IRBuilder<> &Builder, Value *Str) {
static Value *callAppendStringN(IRBuilder<> &Builder, Value *Desc, Value *Str,
Value *Length, bool isLast) {
auto Int64Ty = Builder.getInt64Ty();
auto CharPtrTy = Builder.getInt8PtrTy();
auto PtrTy = Builder.getPtrTy();
auto Int32Ty = Builder.getInt32Ty();
auto M = Builder.GetInsertBlock()->getModule();
auto Fn = M->getOrInsertFunction("__ockl_printf_append_string_n", Int64Ty,
Int64Ty, CharPtrTy, Int64Ty, Int32Ty);
Int64Ty, PtrTy, Int64Ty, Int32Ty);
auto IsLastInt32 = Builder.getInt32(isLast);
return Builder.CreateCall(Fn, {Desc, Str, Length, IsLastInt32});
}

static Value *appendString(IRBuilder<> &Builder, Value *Desc, Value *Arg,
bool IsLast) {
Arg = Builder.CreateBitCast(
Arg, Builder.getInt8PtrTy(Arg->getType()->getPointerAddressSpace()));
auto Length = getStrlenWithNull(Builder, Arg);
return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
}
Expand Down Expand Up @@ -299,9 +297,9 @@ static Value *callBufferedPrintfStart(
Builder.getContext(), AttributeList::FunctionIndex, Attribute::NoUnwind);

Type *Tys_alloc[1] = {Builder.getInt32Ty()};
Type *I8Ptr =
Builder.getInt8PtrTy(M->getDataLayout().getDefaultGlobalsAddressSpace());
FunctionType *FTy_alloc = FunctionType::get(I8Ptr, Tys_alloc, false);
Type *PtrTy =
Builder.getPtrTy(M->getDataLayout().getDefaultGlobalsAddressSpace());
FunctionType *FTy_alloc = FunctionType::get(PtrTy, Tys_alloc, false);
auto PrintfAllocFn =
M->getOrInsertFunction(StringRef("__printf_alloc"), FTy_alloc, Attr);

Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/Utils/ModuleUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F,
}
GVCtor->eraseFromParent();
} else {
EltTy = StructType::get(
IRB.getInt32Ty(), PointerType::get(FnTy, F->getAddressSpace()),
IRB.getInt8PtrTy());
EltTy = StructType::get(IRB.getInt32Ty(),
PointerType::get(FnTy, F->getAddressSpace()),
IRB.getPtrTy());
}

// 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.getInt8PtrTy())
: Constant::getNullValue(IRB.getInt8PtrTy());
CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getPtrTy())
: Constant::getNullValue(IRB.getPtrTy());
Constant *RuntimeCtorInit =
ConstantStruct::get(EltTy, ArrayRef(CSVals, EltTy->getNumElements()));

Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ static void convertToRelLookupTable(GlobalVariable &LookupTable) {
Value *Result = Builder.CreateCall(LoadRelIntrinsic, {RelLookupTable, Offset},
"reltable.intrinsic");

// Create a bitcast instruction if necessary.
if (Load->getType() != Builder.getInt8PtrTy())
Result = Builder.CreateBitCast(Result, Load->getType(), "reltable.bitcast");

// Replace load instruction with the new generated instruction sequence.
Load->replaceAllUsesWith(Result);
// Remove Load and GEP instructions.
Expand Down
11 changes: 5 additions & 6 deletions llvm/lib/Transforms/Utils/SanitizerStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,19 @@ StructType *SanitizerStatReport::makeModuleStatsTy() {
void SanitizerStatReport::create(IRBuilder<> &B, SanitizerStatKind SK) {
Function *F = B.GetInsertBlock()->getParent();
Module *M = F->getParent();
PointerType *Int8PtrTy = B.getInt8PtrTy();
PointerType *PtrTy = B.getPtrTy();
IntegerType *IntPtrTy = B.getIntPtrTy(M->getDataLayout());
ArrayType *StatTy = ArrayType::get(Int8PtrTy, 2);
ArrayType *StatTy = ArrayType::get(PtrTy, 2);

Inits.push_back(ConstantArray::get(
StatTy,
{Constant::getNullValue(Int8PtrTy),
{Constant::getNullValue(PtrTy),
ConstantExpr::getIntToPtr(
ConstantInt::get(IntPtrTy, uint64_t(SK) << (IntPtrTy->getBitWidth() -
kSanitizerStatKindBits)),
Int8PtrTy)}));
PtrTy)}));

FunctionType *StatReportTy =
FunctionType::get(B.getVoidTy(), Int8PtrTy, false);
FunctionType *StatReportTy = FunctionType::get(B.getVoidTy(), PtrTy, false);
FunctionCallee StatReport =
M->getOrInsertFunction("__sanitizer_stat_report", StatReportTy);

Expand Down

0 comments on commit aba0401

Please sign in to comment.