Skip to content

Commit 7b9d73c

Browse files
authored
[NFC] Remove Type::getInt8PtrTy (#71029)
Replace this with PointerType::getUnqual(). Followup to the opaque pointer transition. Fixes an in-code TODO item.
1 parent 75d6795 commit 7b9d73c

File tree

63 files changed

+229
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+229
-214
lines changed

clang/lib/CodeGen/CGGPUBuiltin.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ using namespace CodeGen;
2323

2424
namespace {
2525
llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
26-
llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
27-
llvm::Type::getInt8PtrTy(M.getContext())};
26+
llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
27+
llvm::PointerType::getUnqual(M.getContext())};
2828
llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
2929
llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
3030

@@ -45,8 +45,8 @@ llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
4545
llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule &CGM) {
4646
const char *Name = "__llvm_omp_vprintf";
4747
llvm::Module &M = CGM.getModule();
48-
llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
49-
llvm::Type::getInt8PtrTy(M.getContext()),
48+
llvm::Type *ArgTypes[] = {llvm::PointerType::getUnqual(M.getContext()),
49+
llvm::PointerType::getUnqual(M.getContext()),
5050
llvm::Type::getInt32Ty(M.getContext())};
5151
llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
5252
llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
@@ -99,7 +99,8 @@ packArgsIntoNVPTXFormatBuffer(CodeGenFunction *CGF, const CallArgList &Args) {
9999
// Construct and fill the args buffer that we'll pass to vprintf.
100100
if (Args.size() <= 1) {
101101
// If there are no args, pass a null pointer and size 0
102-
llvm::Value * BufferPtr = llvm::ConstantPointerNull::get(llvm::Type::getInt8PtrTy(Ctx));
102+
llvm::Value *BufferPtr =
103+
llvm::ConstantPointerNull::get(llvm::PointerType::getUnqual(Ctx));
103104
return {BufferPtr, llvm::TypeSize::Fixed(0)};
104105
} else {
105106
llvm::SmallVector<llvm::Type *, 8> ArgTypes;
@@ -120,7 +121,7 @@ packArgsIntoNVPTXFormatBuffer(CodeGenFunction *CGF, const CallArgList &Args) {
120121
Builder.CreateAlignedStore(Arg, P, DL.getPrefTypeAlign(Arg->getType()));
121122
}
122123
llvm::Value *BufferPtr =
123-
Builder.CreatePointerCast(Alloca, llvm::Type::getInt8PtrTy(Ctx));
124+
Builder.CreatePointerCast(Alloca, llvm::PointerType::getUnqual(Ctx));
124125
return {BufferPtr, DL.getTypeAllocSize(AllocaTy)};
125126
}
126127
}

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
422422

423423
case BuiltinType::NullPtr:
424424
// Model std::nullptr_t as i8*
425-
ResultType = llvm::Type::getInt8PtrTy(getLLVMContext());
425+
ResultType = llvm::PointerType::getUnqual(getLLVMContext());
426426
break;
427427

428428
case BuiltinType::UInt128:

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ void CoverageMappingModuleGen::emit() {
18201820
CGM.addUsedGlobal(CovData);
18211821
// Create the deferred function records array
18221822
if (!FunctionNames.empty()) {
1823-
auto NamesArrTy = llvm::ArrayType::get(llvm::Type::getInt8PtrTy(Ctx),
1823+
auto NamesArrTy = llvm::ArrayType::get(llvm::PointerType::getUnqual(Ctx),
18241824
FunctionNames.size());
18251825
auto NamesArrVal = llvm::ConstantArray::get(NamesArrTy, FunctionNames);
18261826
// This variable will *NOT* be emitted to the object file. It is used

clang/tools/clang-linker-wrapper/OffloadWrapper.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum OffloadEntryKindFlag : uint32_t {
4040

4141
IntegerType *getSizeTTy(Module &M) {
4242
LLVMContext &C = M.getContext();
43-
switch (M.getDataLayout().getPointerTypeSize(Type::getInt8PtrTy(C))) {
43+
switch (M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C))) {
4444
case 4u:
4545
return Type::getInt32Ty(C);
4646
case 8u:
@@ -60,9 +60,10 @@ StructType *getEntryTy(Module &M) {
6060
LLVMContext &C = M.getContext();
6161
StructType *EntryTy = StructType::getTypeByName(C, "__tgt_offload_entry");
6262
if (!EntryTy)
63-
EntryTy = StructType::create("__tgt_offload_entry", Type::getInt8PtrTy(C),
64-
Type::getInt8PtrTy(C), getSizeTTy(M),
65-
Type::getInt32Ty(C), Type::getInt32Ty(C));
63+
EntryTy =
64+
StructType::create("__tgt_offload_entry", PointerType::getUnqual(C),
65+
PointerType::getUnqual(C), getSizeTTy(M),
66+
Type::getInt32Ty(C), Type::getInt32Ty(C));
6667
return EntryTy;
6768
}
6869

@@ -80,9 +81,9 @@ StructType *getDeviceImageTy(Module &M) {
8081
LLVMContext &C = M.getContext();
8182
StructType *ImageTy = StructType::getTypeByName(C, "__tgt_device_image");
8283
if (!ImageTy)
83-
ImageTy = StructType::create("__tgt_device_image", Type::getInt8PtrTy(C),
84-
Type::getInt8PtrTy(C), getEntryPtrTy(M),
85-
getEntryPtrTy(M));
84+
ImageTy = StructType::create(
85+
"__tgt_device_image", PointerType::getUnqual(C),
86+
PointerType::getUnqual(C), getEntryPtrTy(M), getEntryPtrTy(M));
8687
return ImageTy;
8788
}
8889

@@ -284,17 +285,17 @@ StructType *getFatbinWrapperTy(Module &M) {
284285
LLVMContext &C = M.getContext();
285286
StructType *FatbinTy = StructType::getTypeByName(C, "fatbin_wrapper");
286287
if (!FatbinTy)
287-
FatbinTy = StructType::create("fatbin_wrapper", Type::getInt32Ty(C),
288-
Type::getInt32Ty(C), Type::getInt8PtrTy(C),
289-
Type::getInt8PtrTy(C));
288+
FatbinTy = StructType::create(
289+
"fatbin_wrapper", Type::getInt32Ty(C), Type::getInt32Ty(C),
290+
PointerType::getUnqual(C), PointerType::getUnqual(C));
290291
return FatbinTy;
291292
}
292293

293294
/// Embed the image \p Image into the module \p M so it can be found by the
294295
/// runtime.
295296
GlobalVariable *createFatbinDesc(Module &M, ArrayRef<char> Image, bool IsHIP) {
296297
LLVMContext &C = M.getContext();
297-
llvm::Type *Int8PtrTy = Type::getInt8PtrTy(C);
298+
llvm::Type *Int8PtrTy = PointerType::getUnqual(C);
298299
llvm::Triple Triple = llvm::Triple(M.getTargetTriple());
299300

300301
// Create the global string containing the fatbinary.
@@ -315,7 +316,7 @@ GlobalVariable *createFatbinDesc(Module &M, ArrayRef<char> Image, bool IsHIP) {
315316
ConstantInt::get(Type::getInt32Ty(C), IsHIP ? HIPFatMagic : CudaFatMagic),
316317
ConstantInt::get(Type::getInt32Ty(C), 1),
317318
ConstantExpr::getPointerBitCastOrAddrSpaceCast(Fatbin, Int8PtrTy),
318-
ConstantPointerNull::get(Type::getInt8PtrTy(C))};
319+
ConstantPointerNull::get(PointerType::getUnqual(C))};
319320

320321
Constant *FatbinInitializer =
321322
ConstantStruct::get(getFatbinWrapperTy(M), FatbinWrapper);
@@ -529,21 +530,21 @@ void createRegisterFatbinFunction(Module &M, GlobalVariable *FatbinDesc,
529530
DtorFunc->setSection(".text.startup");
530531

531532
// Get the __cudaRegisterFatBinary function declaration.
532-
auto *RegFatTy = FunctionType::get(Type::getInt8PtrTy(C)->getPointerTo(),
533-
Type::getInt8PtrTy(C),
533+
auto *RegFatTy = FunctionType::get(PointerType::getUnqual(C)->getPointerTo(),
534+
PointerType::getUnqual(C),
534535
/*isVarArg*/ false);
535536
FunctionCallee RegFatbin = M.getOrInsertFunction(
536537
IsHIP ? "__hipRegisterFatBinary" : "__cudaRegisterFatBinary", RegFatTy);
537538
// Get the __cudaRegisterFatBinaryEnd function declaration.
538-
auto *RegFatEndTy = FunctionType::get(Type::getVoidTy(C),
539-
Type::getInt8PtrTy(C)->getPointerTo(),
540-
/*isVarArg*/ false);
539+
auto *RegFatEndTy = FunctionType::get(
540+
Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
541+
/*isVarArg*/ false);
541542
FunctionCallee RegFatbinEnd =
542543
M.getOrInsertFunction("__cudaRegisterFatBinaryEnd", RegFatEndTy);
543544
// Get the __cudaUnregisterFatBinary function declaration.
544-
auto *UnregFatTy = FunctionType::get(Type::getVoidTy(C),
545-
Type::getInt8PtrTy(C)->getPointerTo(),
546-
/*isVarArg*/ false);
545+
auto *UnregFatTy = FunctionType::get(
546+
Type::getVoidTy(C), PointerType::getUnqual(C)->getPointerTo(),
547+
/*isVarArg*/ false);
547548
FunctionCallee UnregFatbin = M.getOrInsertFunction(
548549
IsHIP ? "__hipUnregisterFatBinary" : "__cudaUnregisterFatBinary",
549550
UnregFatTy);
@@ -554,19 +555,19 @@ void createRegisterFatbinFunction(Module &M, GlobalVariable *FatbinDesc,
554555
FunctionCallee AtExit = M.getOrInsertFunction("atexit", AtExitTy);
555556

556557
auto *BinaryHandleGlobal = new llvm::GlobalVariable(
557-
M, Type::getInt8PtrTy(C)->getPointerTo(), false,
558+
M, PointerType::getUnqual(C)->getPointerTo(), false,
558559
llvm::GlobalValue::InternalLinkage,
559-
llvm::ConstantPointerNull::get(Type::getInt8PtrTy(C)->getPointerTo()),
560+
llvm::ConstantPointerNull::get(PointerType::getUnqual(C)->getPointerTo()),
560561
IsHIP ? ".hip.binary_handle" : ".cuda.binary_handle");
561562

562563
// Create the constructor to register this image with the runtime.
563564
IRBuilder<> CtorBuilder(BasicBlock::Create(C, "entry", CtorFunc));
564565
CallInst *Handle = CtorBuilder.CreateCall(
565566
RegFatbin, ConstantExpr::getPointerBitCastOrAddrSpaceCast(
566-
FatbinDesc, Type::getInt8PtrTy(C)));
567+
FatbinDesc, PointerType::getUnqual(C)));
567568
CtorBuilder.CreateAlignedStore(
568569
Handle, BinaryHandleGlobal,
569-
Align(M.getDataLayout().getPointerTypeSize(Type::getInt8PtrTy(C))));
570+
Align(M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C))));
570571
CtorBuilder.CreateCall(createRegisterGlobalsFunction(M, IsHIP), Handle);
571572
if (!IsHIP)
572573
CtorBuilder.CreateCall(RegFatbinEnd, Handle);
@@ -578,8 +579,8 @@ void createRegisterFatbinFunction(Module &M, GlobalVariable *FatbinDesc,
578579
// `atexit()` intead.
579580
IRBuilder<> DtorBuilder(BasicBlock::Create(C, "entry", DtorFunc));
580581
LoadInst *BinaryHandle = DtorBuilder.CreateAlignedLoad(
581-
Type::getInt8PtrTy(C)->getPointerTo(), BinaryHandleGlobal,
582-
Align(M.getDataLayout().getPointerTypeSize(Type::getInt8PtrTy(C))));
582+
PointerType::getUnqual(C)->getPointerTo(), BinaryHandleGlobal,
583+
Align(M.getDataLayout().getPointerTypeSize(PointerType::getUnqual(C))));
583584
DtorBuilder.CreateCall(UnregFatbin, BinaryHandle);
584585
DtorBuilder.CreateRetVoid();
585586

llvm/examples/BrainF/BrainF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void BrainF::header(LLVMContext& C) {
6767
//Function prototypes
6868

6969
//declare void @llvm.memset.p0i8.i32(i8 *, i8, i32, i1)
70-
Type *Tys[] = { Type::getInt8PtrTy(C), Type::getInt32Ty(C) };
70+
Type *Tys[] = {PointerType::getUnqual(C), Type::getInt32Ty(C)};
7171
Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset,
7272
Tys);
7373

llvm/include/llvm/IR/Type.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,6 @@ class Type {
482482
//===--------------------------------------------------------------------===//
483483
// Convenience methods for getting pointer types.
484484
//
485-
486-
// TODO: After opaque pointer transition this can be replaced by simply
487-
// calling PointerType::get(C, AS).
488-
static PointerType *getInt8PtrTy(LLVMContext &C, unsigned AS = 0);
489-
490485
static Type *getWasm_ExternrefTy(LLVMContext &C);
491486
static Type *getWasm_FuncrefTy(LLVMContext &C);
492487

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ INSTR_PROF_DATA(const IntPtrT, IntPtrTy, BitmapPtr, RelativeBitmapPtr)
8181
* function name hashes during the conversion from raw to merged profile
8282
* data.
8383
*/
84-
INSTR_PROF_DATA(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), FunctionPointer, \
84+
INSTR_PROF_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx), FunctionPointer, \
8585
FunctionAddr)
86-
INSTR_PROF_DATA(IntPtrT, llvm::Type::getInt8PtrTy(Ctx), Values, \
86+
INSTR_PROF_DATA(IntPtrT, llvm::PointerType::getUnqual(Ctx), Values, \
8787
ValuesPtrExpr)
8888
INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumCounters, \
8989
ConstantInt::get(llvm::Type::getInt32Ty(Ctx), NumCounters))
@@ -116,7 +116,7 @@ INSTR_PROF_VALUE_NODE(uint64_t, llvm::Type::getInt64Ty(Ctx), Value, \
116116
ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
117117
INSTR_PROF_VALUE_NODE(uint64_t, llvm::Type::getInt64Ty(Ctx), Count, \
118118
ConstantInt::get(llvm::Type::GetInt64Ty(Ctx), 0))
119-
INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::Type::getInt8PtrTy(Ctx), Next, \
119+
INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::PointerType::getUnqual(Ctx), Next, \
120120
ConstantInt::get(llvm::Type::GetInt8PtrTy(Ctx), 0))
121121
#undef INSTR_PROF_VALUE_NODE
122122
/* INSTR_PROF_VALUE_NODE end. */
@@ -160,7 +160,7 @@ INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
160160
#endif
161161
VALUE_PROF_FUNC_PARAM(uint64_t, TargetValue, Type::getInt64Ty(Ctx)) \
162162
INSTR_PROF_COMMA
163-
VALUE_PROF_FUNC_PARAM(void *, Data, Type::getInt8PtrTy(Ctx)) INSTR_PROF_COMMA
163+
VALUE_PROF_FUNC_PARAM(void *, Data, PointerType::getUnqual(Ctx)) INSTR_PROF_COMMA
164164
VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
165165
#undef VALUE_PROF_FUNC_PARAM
166166
#undef INSTR_PROF_COMMA
@@ -213,9 +213,9 @@ VALUE_PROF_KIND(IPVK_Last, IPVK_MemOPSize, "last")
213213
#define INSTR_PROF_DATA_DEFINED
214214
#endif
215215
#ifdef COVMAP_V1
216-
COVMAP_FUNC_RECORD(const IntPtrT, llvm::Type::getInt8PtrTy(Ctx), \
216+
COVMAP_FUNC_RECORD(const IntPtrT, llvm::PointerType::getUnqual(Ctx), \
217217
NamePtr, llvm::ConstantExpr::getBitCast(NamePtr, \
218-
llvm::Type::getInt8PtrTy(Ctx)))
218+
llvm::PointerType::getUnqual(Ctx)))
219219
COVMAP_FUNC_RECORD(const uint32_t, llvm::Type::getInt32Ty(Ctx), NameSize, \
220220
llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
221221
NameValue.size()))

llvm/lib/Analysis/StackSafetyAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ ConstantRange StackSafetyLocalAnalysis::offsetFrom(Value *Addr, Value *Base) {
272272
if (!SE.isSCEVable(Addr->getType()) || !SE.isSCEVable(Base->getType()))
273273
return UnknownRange;
274274

275-
auto *PtrTy = IntegerType::getInt8PtrTy(SE.getContext());
275+
auto *PtrTy = PointerType::getUnqual(SE.getContext());
276276
const SCEV *AddrExp = SE.getTruncateOrZeroExtend(SE.getSCEV(Addr), PtrTy);
277277
const SCEV *BaseExp = SE.getTruncateOrZeroExtend(SE.getSCEV(Base), PtrTy);
278278
const SCEV *Diff = SE.getMinusSCEV(AddrExp, BaseExp);
@@ -363,7 +363,7 @@ bool StackSafetyLocalAnalysis::isSafeAccess(const Use &U, AllocaInst *AI,
363363
const auto *I = cast<Instruction>(U.getUser());
364364

365365
auto ToCharPtr = [&](const SCEV *V) {
366-
auto *PtrTy = IntegerType::getInt8PtrTy(SE.getContext());
366+
auto *PtrTy = PointerType::getUnqual(SE.getContext());
367367
return SE.getTruncateOrZeroExtend(V, PtrTy);
368368
};
369369

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5178,7 +5178,7 @@ void llvm::embedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
51785178
// Save llvm.compiler.used and remove it.
51795179
SmallVector<Constant *, 2> UsedArray;
51805180
SmallVector<GlobalValue *, 4> UsedGlobals;
5181-
Type *UsedElementType = Type::getInt8PtrTy(M.getContext());
5181+
Type *UsedElementType = PointerType::getUnqual(M.getContext());
51825182
GlobalVariable *Used = collectUsedGlobalVariables(M, UsedGlobals, true);
51835183
for (auto *GV : UsedGlobals) {
51845184
if (GV->getName() != "llvm.embedded.module" &&

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ bool AsmPrinter::doFinalization(Module &M) {
23222322
auto SymbolName = "swift_async_extendedFramePointerFlags";
23232323
auto Global = M.getGlobalVariable(SymbolName);
23242324
if (!Global) {
2325-
auto Int8PtrTy = Type::getInt8PtrTy(M.getContext());
2325+
auto Int8PtrTy = PointerType::getUnqual(M.getContext());
23262326
Global = new GlobalVariable(M, Int8PtrTy, false,
23272327
GlobalValue::ExternalWeakLinkage, nullptr,
23282328
SymbolName);

0 commit comments

Comments
 (0)