Skip to content

Commit aba0401

Browse files
authored
[IR] Replace uses of IRBuilder::getInt8PtrTy with getPtrTy. NFC (#73154)
1 parent 6772c4f commit aba0401

File tree

9 files changed

+36
-51
lines changed

9 files changed

+36
-51
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,15 +1767,14 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
17671767
SharedsSize);
17681768
}
17691769

1770-
Value *DepArrayPtr = nullptr;
1770+
Value *DepArray = nullptr;
17711771
if (Dependencies.size()) {
17721772
InsertPointTy OldIP = Builder.saveIP();
17731773
Builder.SetInsertPoint(
17741774
&OldIP.getBlock()->getParent()->getEntryBlock().back());
17751775

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

17801779
unsigned P = 0;
17811780
for (const DependData &Dep : Dependencies) {
@@ -1806,7 +1805,6 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
18061805
++P;
18071806
}
18081807

1809-
DepArrayPtr = Builder.CreateBitCast(DepArray, Builder.getInt8PtrTy());
18101808
Builder.restoreIP(OldIP);
18111809
}
18121810

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

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

@@ -2093,18 +2091,13 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
20932091
const ReductionInfo &RI = En.value();
20942092
Value *RedArrayElemPtr = Builder.CreateConstInBoundsGEP2_64(
20952093
RedArrayTy, RedArray, 0, Index, "red.array.elem." + Twine(Index));
2096-
Value *Casted =
2097-
Builder.CreateBitCast(RI.PrivateVariable, Builder.getInt8PtrTy(),
2098-
"private.red.var." + Twine(Index) + ".casted");
2099-
Builder.CreateStore(Casted, RedArrayElemPtr);
2094+
Builder.CreateStore(RI.PrivateVariable, RedArrayElemPtr);
21002095
}
21012096

21022097
// Emit a call to the runtime function that orchestrates the reduction.
21032098
// Declare the reduction function in the process.
21042099
Function *Func = Builder.GetInsertBlock()->getParent();
21052100
Module *Module = Func->getParent();
2106-
Value *RedArrayPtr =
2107-
Builder.CreateBitCast(RedArray, Builder.getInt8PtrTy(), "red.array.ptr");
21082101
uint32_t SrcLocStrSize;
21092102
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
21102103
bool CanGenerateAtomic =
@@ -2127,8 +2120,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
21272120
: RuntimeFunction::OMPRTL___kmpc_reduce);
21282121
CallInst *ReduceCall =
21292122
Builder.CreateCall(ReduceFunc,
2130-
{Ident, ThreadId, NumVariables, RedArraySize,
2131-
RedArrayPtr, ReductionFunc, Lock},
2123+
{Ident, ThreadId, NumVariables, RedArraySize, RedArray,
2124+
ReductionFunc, Lock},
21322125
"reduce");
21332126

21342127
// Create final reduction entry blocks for the atomic and non-atomic case.
@@ -2197,12 +2190,12 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions(
21972190
const ReductionInfo &RI = En.value();
21982191
Value *LHSI8PtrPtr = Builder.CreateConstInBoundsGEP2_64(
21992192
RedArrayTy, LHSArrayPtr, 0, En.index());
2200-
Value *LHSI8Ptr = Builder.CreateLoad(Builder.getInt8PtrTy(), LHSI8PtrPtr);
2193+
Value *LHSI8Ptr = Builder.CreateLoad(Builder.getPtrTy(), LHSI8PtrPtr);
22012194
Value *LHSPtr = Builder.CreateBitCast(LHSI8Ptr, RI.Variable->getType());
22022195
Value *LHS = Builder.CreateLoad(RI.ElementType, LHSPtr);
22032196
Value *RHSI8PtrPtr = Builder.CreateConstInBoundsGEP2_64(
22042197
RedArrayTy, RHSArrayPtr, 0, En.index());
2205-
Value *RHSI8Ptr = Builder.CreateLoad(Builder.getInt8PtrTy(), RHSI8PtrPtr);
2198+
Value *RHSI8Ptr = Builder.CreateLoad(Builder.getPtrTy(), RHSI8PtrPtr);
22062199
Value *RHSPtr =
22072200
Builder.CreateBitCast(RHSI8Ptr, RI.PrivateVariable->getType());
22082201
Value *RHS = Builder.CreateLoad(RI.ElementType, RHSPtr);
@@ -5198,12 +5191,12 @@ void OpenMPIRBuilder::emitNonContiguousDescriptor(InsertPointTy AllocaIP,
51985191
// args[I] = &dims
51995192
Builder.restoreIP(CodeGenIP);
52005193
Value *DAddr = Builder.CreatePointerBitCastOrAddrSpaceCast(
5201-
DimsAddr, Builder.getInt8PtrTy());
5194+
DimsAddr, Builder.getPtrTy());
52025195
Value *P = Builder.CreateConstInBoundsGEP2_32(
5203-
ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs),
5196+
ArrayType::get(Builder.getPtrTy(), Info.NumberOfPtrs),
52045197
Info.RTArgs.PointersArray, 0, I);
52055198
Builder.CreateAlignedStore(
5206-
DAddr, P, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
5199+
DAddr, P, M.getDataLayout().getPrefTypeAlign(Builder.getPtrTy()));
52075200
++L;
52085201
}
52095202
}
@@ -5225,7 +5218,7 @@ void OpenMPIRBuilder::emitOffloadingArrays(
52255218
// Detect if we have any capture size requiring runtime evaluation of the
52265219
// size so that a constant array could be eventually used.
52275220
ArrayType *PointerArrayType =
5228-
ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs);
5221+
ArrayType::get(Builder.getPtrTy(), Info.NumberOfPtrs);
52295222

52305223
Info.RTArgs.BasePointersArray = Builder.CreateAlloca(
52315224
PointerArrayType, /* ArraySize = */ nullptr, ".offload_baseptrs");

llvm/lib/Transforms/Coroutines/CoroCleanup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
3232
Value *FrameRaw = SubFn->getFrame();
3333
int Index = SubFn->getIndex();
3434

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

3939
Builder.SetInsertPoint(SubFn);

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,10 +1481,9 @@ static void handleNoSuspendCoroutine(coro::Shape &Shape) {
14811481
IRBuilder<> Builder(AllocInst);
14821482
auto *Frame = Builder.CreateAlloca(Shape.FrameTy);
14831483
Frame->setAlignment(Shape.FrameAlign);
1484-
auto *VFrame = Builder.CreateBitCast(Frame, Builder.getInt8PtrTy());
14851484
AllocInst->replaceAllUsesWith(Builder.getFalse());
14861485
AllocInst->eraseFromParent();
1487-
CoroBegin->replaceAllUsesWith(VFrame);
1486+
CoroBegin->replaceAllUsesWith(Frame);
14881487
} else {
14891488
CoroBegin->replaceAllUsesWith(CoroBegin->getMem());
14901489
}

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ bool LoopIdiomRecognize::processLoopStridedStore(
10211021
SCEVExpander Expander(*SE, *DL, "loop-idiom");
10221022
SCEVExpanderCleaner ExpCleaner(Expander);
10231023

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

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

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

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

13401340
// If the store is a memcpy instruction, we must check if it will write to
13411341
// the load memory locations. So remove it from the ignored stores.

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3502,7 +3502,7 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
35023502
NewEndOffset - NewBeginOffset);
35033503
// Lifetime intrinsics always expect an i8* so directly get such a pointer
35043504
// for the new alloca slice.
3505-
Type *PointerTy = IRB.getInt8PtrTy(OldPtr->getType()->getPointerAddressSpace());
3505+
Type *PointerTy = IRB.getPtrTy(OldPtr->getType()->getPointerAddressSpace());
35063506
Value *Ptr = getNewAllocaSlicePtr(IRB, PointerTy);
35073507
Value *New;
35083508
if (II.getIntrinsicID() == Intrinsic::lifetime_start)

llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,17 @@ static Value *getStrlenWithNull(IRBuilder<> &Builder, Value *Str) {
153153
static Value *callAppendStringN(IRBuilder<> &Builder, Value *Desc, Value *Str,
154154
Value *Length, bool isLast) {
155155
auto Int64Ty = Builder.getInt64Ty();
156-
auto CharPtrTy = Builder.getInt8PtrTy();
156+
auto PtrTy = Builder.getPtrTy();
157157
auto Int32Ty = Builder.getInt32Ty();
158158
auto M = Builder.GetInsertBlock()->getModule();
159159
auto Fn = M->getOrInsertFunction("__ockl_printf_append_string_n", Int64Ty,
160-
Int64Ty, CharPtrTy, Int64Ty, Int32Ty);
160+
Int64Ty, PtrTy, Int64Ty, Int32Ty);
161161
auto IsLastInt32 = Builder.getInt32(isLast);
162162
return Builder.CreateCall(Fn, {Desc, Str, Length, IsLastInt32});
163163
}
164164

165165
static Value *appendString(IRBuilder<> &Builder, Value *Desc, Value *Arg,
166166
bool IsLast) {
167-
Arg = Builder.CreateBitCast(
168-
Arg, Builder.getInt8PtrTy(Arg->getType()->getPointerAddressSpace()));
169167
auto Length = getStrlenWithNull(Builder, Arg);
170168
return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
171169
}
@@ -299,9 +297,9 @@ static Value *callBufferedPrintfStart(
299297
Builder.getContext(), AttributeList::FunctionIndex, Attribute::NoUnwind);
300298

301299
Type *Tys_alloc[1] = {Builder.getInt32Ty()};
302-
Type *I8Ptr =
303-
Builder.getInt8PtrTy(M->getDataLayout().getDefaultGlobalsAddressSpace());
304-
FunctionType *FTy_alloc = FunctionType::get(I8Ptr, Tys_alloc, false);
300+
Type *PtrTy =
301+
Builder.getPtrTy(M->getDataLayout().getDefaultGlobalsAddressSpace());
302+
FunctionType *FTy_alloc = FunctionType::get(PtrTy, Tys_alloc, false);
305303
auto PrintfAllocFn =
306304
M->getOrInsertFunction(StringRef("__printf_alloc"), FTy_alloc, Attr);
307305

llvm/lib/Transforms/Utils/ModuleUtils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F,
4444
}
4545
GVCtor->eraseFromParent();
4646
} else {
47-
EltTy = StructType::get(
48-
IRB.getInt32Ty(), PointerType::get(FnTy, F->getAddressSpace()),
49-
IRB.getInt8PtrTy());
47+
EltTy = StructType::get(IRB.getInt32Ty(),
48+
PointerType::get(FnTy, F->getAddressSpace()),
49+
IRB.getPtrTy());
5050
}
5151

5252
// Build a 3 field global_ctor entry. We don't take a comdat key.
5353
Constant *CSVals[3];
5454
CSVals[0] = IRB.getInt32(Priority);
5555
CSVals[1] = F;
56-
CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getInt8PtrTy())
57-
: Constant::getNullValue(IRB.getInt8PtrTy());
56+
CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getPtrTy())
57+
: Constant::getNullValue(IRB.getPtrTy());
5858
Constant *RuntimeCtorInit =
5959
ConstantStruct::get(EltTy, ArrayRef(CSVals, EltTy->getNumElements()));
6060

llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ static void convertToRelLookupTable(GlobalVariable &LookupTable) {
159159
Value *Result = Builder.CreateCall(LoadRelIntrinsic, {RelLookupTable, Offset},
160160
"reltable.intrinsic");
161161

162-
// Create a bitcast instruction if necessary.
163-
if (Load->getType() != Builder.getInt8PtrTy())
164-
Result = Builder.CreateBitCast(Result, Load->getType(), "reltable.bitcast");
165-
166162
// Replace load instruction with the new generated instruction sequence.
167163
Load->replaceAllUsesWith(Result);
168164
// Remove Load and GEP instructions.

llvm/lib/Transforms/Utils/SanitizerStats.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,19 @@ StructType *SanitizerStatReport::makeModuleStatsTy() {
4242
void SanitizerStatReport::create(IRBuilder<> &B, SanitizerStatKind SK) {
4343
Function *F = B.GetInsertBlock()->getParent();
4444
Module *M = F->getParent();
45-
PointerType *Int8PtrTy = B.getInt8PtrTy();
45+
PointerType *PtrTy = B.getPtrTy();
4646
IntegerType *IntPtrTy = B.getIntPtrTy(M->getDataLayout());
47-
ArrayType *StatTy = ArrayType::get(Int8PtrTy, 2);
47+
ArrayType *StatTy = ArrayType::get(PtrTy, 2);
4848

4949
Inits.push_back(ConstantArray::get(
5050
StatTy,
51-
{Constant::getNullValue(Int8PtrTy),
51+
{Constant::getNullValue(PtrTy),
5252
ConstantExpr::getIntToPtr(
5353
ConstantInt::get(IntPtrTy, uint64_t(SK) << (IntPtrTy->getBitWidth() -
5454
kSanitizerStatKindBits)),
55-
Int8PtrTy)}));
55+
PtrTy)}));
5656

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

0 commit comments

Comments
 (0)