Skip to content

Commit 124cd80

Browse files
authored
Merge pull request #785 from hvdijk/pointertype-deprecation
Update to address PointerType deprecation.
2 parents 18fed0a + cb3efd2 commit 124cd80

19 files changed

Lines changed: 70 additions & 372 deletions

examples/refsi/refsi_m1/compiler/refsi_m1/source/refsi_mux_builtin_info.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ static IntegerType *getTransferIDTy(Module &M) {
6161
// Materialize the address of a DMA memory-mapped register in a basic block.
6262
static Value *getDmaRegAddress(IRBuilder<> &B, unsigned RegIdx) {
6363
Type *const DmaRegTy = getDmaRegTy(B.getContext());
64-
Type *const DmaRegPtrTy = PointerType::get(DmaRegTy, 0);
64+
Type *const PtrTy = B.getPtrTy(/*AddressSpace=*/0);
6565
Value *const DmaRegAddr = ConstantInt::get(
6666
DmaRegTy, REFSI_DMA_REG_ADDR(REFSI_DMA_IO_ADDRESS, RegIdx));
67-
return B.CreateIntToPtr(DmaRegAddr, DmaRegPtrTy);
67+
return B.CreateIntToPtr(DmaRegAddr, PtrTy);
6868
}
6969

7070
// Convert the value to a format that can be directly written to a DMA register.

modules/compiler/compiler_pipeline/source/add_kernel_wrapper_pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void compiler::utils::AddKernelWrapperPass::createNewFunctionArgTypes(
4343
StructType *structTy, SmallVectorImpl<KernelArgMapping> &argMappings,
4444
SmallVectorImpl<Type *> &argTypes) {
4545
// the first element is our new packed argument struct
46-
argTypes.push_back(PointerType::get(structTy, /*AddressSpace=*/0));
46+
argTypes.push_back(PointerType::get(M.getContext(), /*AddressSpace=*/0));
4747

4848
uint32_t index = 0;
4949
// Track which arguments are *not* packed, and which index each corresponds

modules/compiler/compiler_pipeline/source/barrier_regions.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,6 @@ Value *compiler::utils::Barrier::LiveValuesHelper::getGEP(const Value *live,
312312
}
313313

314314
Value *gep;
315-
Type *data_ty = live->getType();
316-
if (auto *AI = dyn_cast<AllocaInst>(live)) {
317-
data_ty = AI->getAllocatedType();
318-
}
319315

320316
if (auto field_it = barrier.live_variable_index_map_.find(key);
321317
field_it != barrier.live_variable_index_map_.end()) {
@@ -356,13 +352,6 @@ Value *compiler::utils::Barrier::LiveValuesHelper::getGEP(const Value *live,
356352
gep = gepBuilder.CreateInBoundsGEP(
357353
barrier.live_var_mem_ty_, barrier_struct, live_variable_info_idxs,
358354
Twine("live_gep_scalable_") + live->getName());
359-
360-
// Cast the pointer to the scalable vector type
361-
gep = gepBuilder.CreatePointerCast(
362-
gep,
363-
PointerType::get(
364-
data_ty,
365-
cast<PointerType>(barrier_struct->getType())->getAddressSpace()));
366355
} else {
367356
// Fall back and see if this live variable is actually a decomposed
368357
// structure type.
@@ -1071,7 +1060,7 @@ Function *compiler::utils::Barrier::GenerateNewKernel(BarrierRegion &region) {
10711060
const bool hasBarrierStruct = !whole_live_variables_set_.empty() &&
10721061
region.schedule != BarrierSchedule::Once;
10731062
if (hasBarrierStruct) {
1074-
PointerType *pty = PointerType::get(live_var_mem_ty_, 0);
1063+
PointerType *pty = PointerType::get(context, /*AddressSpace=*/0);
10751064
new_func_params.push_back(pty);
10761065
}
10771066

modules/compiler/compiler_pipeline/source/cl_builtin_info.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,8 +1295,7 @@ Function *CLBuiltinInfo::getVectorEquivalent(const Builtin &B, unsigned Width,
12951295
if (!FixedVectorType::isValidElementType(PtrRetPointeeTy)) {
12961296
return nullptr;
12971297
}
1298-
Type *NewEleTy = FixedVectorType::get(PtrRetPointeeTy, Width);
1299-
Type *NewType = PointerType::get(NewEleTy, OldPtrTy->getAddressSpace());
1298+
Type *NewType = OldPtrTy;
13001299
TypeQualifiers NewQuals;
13011300
TypeQualifiers EleQuals = OldQuals;
13021301
NewQuals.push_back(EleQuals.pop_front()); // Pointer qualifier
@@ -1413,9 +1412,7 @@ Function *CLBuiltinInfo::getScalarEquivalent(const Builtin &B, Module *M) {
14131412
[[maybe_unused]] auto *OldPointeeTy = BuiltinPointeeTypes[i];
14141413
assert(OldPointeeTy && OldPointeeTy == PtrRetPointeeTy &&
14151414
"Demangling inconsistency");
1416-
auto *OldVecTy = cast<FixedVectorType>(PtrRetPointeeTy);
1417-
Type *NewTy = PointerType::get(OldVecTy->getElementType(),
1418-
OldPtrTy->getAddressSpace());
1415+
Type *NewTy = OldPtrTy;
14191416
TypeQualifiers NewQuals = OldQuals;
14201417
const TypeQualifier PtrQual = NewQuals.pop_front();
14211418
const TypeQualifier VecQual = NewQuals.pop_front();
@@ -2190,8 +2187,7 @@ Value *CLBuiltinInfo::emitBuiltinInlineVLoad(Function *F, unsigned Width,
21902187
Data = B.CreateInsertElement(Data, Lane, Index, "vload_insert");
21912188
}
21922189
} else {
2193-
Value *VecBase = B.CreateBitCast(GEPBase, PtrTy, "vload_ptr");
2194-
auto *Load = B.CreateLoad(DataTy, VecBase, false, "vload");
2190+
auto *Load = B.CreateLoad(DataTy, GEPBase, false, "vload");
21952191

21962192
const unsigned Align = DataTy->getScalarSizeInBits() / 8;
21972193
Load->setAlignment(MaybeAlign(Align).valueOrOne());
@@ -2250,8 +2246,7 @@ Value *CLBuiltinInfo::emitBuiltinInlineVStore(Function *F, unsigned Width,
22502246
Store = B.CreateStore(Lane, GEP, false);
22512247
}
22522248
} else {
2253-
Value *VecBase = B.CreateBitCast(GEPBase, PtrTy, "vstore_ptr");
2254-
Store = B.CreateStore(Data, VecBase, false);
2249+
Store = B.CreateStore(Data, GEPBase, false);
22552250

22562251
const unsigned Align = VecDataTy->getScalarSizeInBits() / 8;
22572252
Store->setAlignment(MaybeAlign(Align).valueOrOne());
@@ -2279,12 +2274,10 @@ Value *CLBuiltinInfo::emitBuiltinInlineVLoadHalf(Function *F, IRBuilder<> &B,
22792274
return nullptr;
22802275
}
22812276
Type *U16Ty = B.getInt16Ty();
2282-
Type *U16PtrTy = PointerType::get(U16Ty, PtrTy->getAddressSpace());
2283-
Value *DataPtr = B.CreateBitCast(Ptr, U16PtrTy);
22842277

22852278
// Emit the base pointer.
22862279
Value *Offset = Args[0];
2287-
DataPtr = B.CreateGEP(U16Ty, DataPtr, Offset, "vload_base");
2280+
Value *DataPtr = B.CreateGEP(U16Ty, Ptr, Offset, "vload_base");
22882281

22892282
// Load a ushort.
22902283
Value *Data = B.CreateLoad(B.getInt16Ty(), DataPtr, "vload_half");
@@ -2368,12 +2361,10 @@ Value *CLBuiltinInfo::emitBuiltinInlineVStoreHalf(Function *F, StringRef Mode,
23682361
return nullptr;
23692362
}
23702363
auto U16Ty = B.getInt16Ty();
2371-
Type *U16PtrTy = PointerType::get(U16Ty, PtrTy->getAddressSpace());
2372-
Value *DataPtr = B.CreateBitCast(Ptr, U16PtrTy);
23732364

23742365
// Emit the base pointer.
23752366
Value *Offset = Args[1];
2376-
DataPtr = B.CreateGEP(U16Ty, DataPtr, Offset, "vstore_base");
2367+
Value *DataPtr = B.CreateGEP(U16Ty, Ptr, Offset, "vstore_base");
23772368

23782369
// Store the ushort.
23792370
return B.CreateStore(Data, DataPtr);
@@ -2644,7 +2635,7 @@ Value *CLBuiltinInfo::emitBuiltinInlinePrintf(BuiltinID, IRBuilder<> &B,
26442635
// Declare printf if needed.
26452636
Function *Printf = M.getFunction("printf");
26462637
if (!Printf) {
2647-
PointerType *PtrTy = PointerType::getUnqual(B.getInt8Ty());
2638+
PointerType *PtrTy = B.getPtrTy(/*AddressSpace=*/0);
26482639
FunctionType *PrintfTy = FunctionType::get(B.getInt32Ty(), {PtrTy}, true);
26492640
Printf =
26502641
Function::Create(PrintfTy, GlobalValue::ExternalLinkage, "printf", &M);

modules/compiler/compiler_pipeline/source/mangling.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ bool NameMangler::demangleType(Lexer &L, Type *&Ty, Type **PointerEltTy,
573573
return false;
574574
}
575575
Quals.push_back(QualsAS->Qual);
576-
return PointerType::get(nullptr, QualsAS->AS);
576+
return llvm::PointerType::get(*Context, QualsAS->AS);
577577
}
578578

579579
// Match scalable vector types.
@@ -620,11 +620,7 @@ bool NameMangler::demangleType(Lexer &L, Type *&Ty, Type **PointerEltTy,
620620
if (PointerEltTy) {
621621
*PointerEltTy = ElementType;
622622
}
623-
if (ElementType->isVoidTy()) {
624-
Ty = llvm::PointerType::get(Type::getInt8Ty(*Context), QualsAS->AS);
625-
} else {
626-
Ty = llvm::PointerType::get(ElementType, QualsAS->AS);
627-
}
623+
Ty = llvm::PointerType::get(*Context, QualsAS->AS);
628624
return true;
629625
}
630626

modules/compiler/compiler_pipeline/source/mux_builtin_info.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -897,13 +897,7 @@ Type *BIMuxInfoConcept::getRemappedTargetExtTy(Type *Ty, Module &M) {
897897
// space to the same structure type (i.e., regardless of image dimensions,
898898
// etc.)
899899
if (TgtExtTy->getName() == "spirv.Image") {
900-
return PointerType::getUnqual([&Ctx]() {
901-
const char *MuxImageTyName = "MuxImage";
902-
if (auto *STy = StructType::getTypeByName(Ctx, MuxImageTyName)) {
903-
return STy;
904-
}
905-
return StructType::create(Ctx, MuxImageTyName);
906-
}());
900+
return PointerType::getUnqual(Ctx);
907901
}
908902

909903
return nullptr;
@@ -1210,7 +1204,7 @@ BIMuxInfoConcept::getMuxSchedulingParameters(Module &M) {
12101204
auto *const WIInfoS = getWorkItemInfoStructTy(M);
12111205
WIInfo.ID = SchedParamIndices::WI;
12121206
WIInfo.ParamPointeeTy = WIInfoS;
1213-
WIInfo.ParamTy = PointerType::get(WIInfoS, /*AddressSpace=*/0);
1207+
WIInfo.ParamTy = PointerType::get(Ctx, /*AddressSpace=*/0);
12141208
WIInfo.ParamName = "wi-info";
12151209
WIInfo.ParamDebugName = WIInfoS->getStructName().str();
12161210
WIInfo.PassedExternally = false;
@@ -1226,7 +1220,7 @@ BIMuxInfoConcept::getMuxSchedulingParameters(Module &M) {
12261220
auto *const WGInfoS = getWorkGroupInfoStructTy(M);
12271221
WGInfo.ID = SchedParamIndices::WG;
12281222
WGInfo.ParamPointeeTy = WGInfoS;
1229-
WGInfo.ParamTy = PointerType::get(WGInfoS, /*AddressSpace=*/0);
1223+
WGInfo.ParamTy = PointerType::get(Ctx, /*AddressSpace=*/0);
12301224
WGInfo.ParamName = "wg-info";
12311225
WGInfo.ParamDebugName = WGInfoS->getStructName().str();
12321226
WGInfo.PassedExternally = true;

modules/compiler/compiler_pipeline/source/replace_local_module_scope_variables_pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ PreservedAnalyses compiler::utils::ReplaceLocalModuleScopeVariablesPass::run(
355355
// change all our functions to take a pointer to the new structTy we created
356356
const AttributeSet defaultAttrs;
357357
addParamToAllRequiredFunctions(
358-
M, PointerType::get(structTy, /*AddressSpace=*/0), defaultAttrs);
358+
M, PointerType::get(M.getContext(), /*AddressSpace=*/0), defaultAttrs);
359359

360360
// Check if we have debug info, if so we need to fix it up to turn global
361361
// variable entries into local variable ones.

modules/compiler/compiler_pipeline/source/work_item_loops_pass.cpp

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
using namespace llvm;
3838

39-
#define NDEBUG_WI_LOOPS
4039
#define DEBUG_TYPE "work-item-loops"
4140

4241
namespace compiler {
@@ -99,65 +98,6 @@ class BarrierWithLiveVars : public Barrier {
9998
} // namespace compiler
10099

101100
namespace {
102-
#ifndef NDEBUG_WI_LOOPS
103-
/// @brief Generate IR level printf function call Debug function only.
104-
///
105-
/// @param[in] format Format string string.
106-
/// @param[in] module Current module.
107-
/// @param[in] v Value for printing.
108-
/// @param[in] bb Basic block insertion point for @p v.
109-
///
110-
/// @return Return instruction to be checked.
111-
Instruction *IRPrintf(const std::string format, Module &module, Value *v,
112-
BasicBlock *bb) {
113-
LLVMContext &context = module.getContext();
114-
PointerType *ptr_type = PointerType::getUnqual(IntegerType::get(context, 8));
115-
116-
SmallVector<Type *, 16> args;
117-
args.push_back(ptr_type);
118-
FunctionType *printf_type =
119-
FunctionType::get(IntegerType::get(context, 32), args, true);
120-
121-
bool isDeclared = true;
122-
Function *func_printf = module.getFunction("printf");
123-
if (!func_printf) {
124-
func_printf = Function::Create(printf_type, GlobalValue::ExternalLinkage,
125-
"printf", &module);
126-
isDeclared = false;
127-
}
128-
129-
ArrayType *array_type =
130-
ArrayType::get(IntegerType::get(context, 8), format.size() + 1);
131-
GlobalVariable *str;
132-
if (isDeclared) {
133-
str = new GlobalVariable(
134-
module, array_type, true, GlobalValue::PrivateLinkage, 0, ".str",
135-
nullptr, GlobalValue::ThreadLocalMode::NotThreadLocal, 2, false);
136-
} else {
137-
str = new GlobalVariable(
138-
module, array_type, true, GlobalValue::PrivateLinkage, 0, ".str",
139-
nullptr, GlobalValue::ThreadLocalMode::NotThreadLocal, 0, false);
140-
}
141-
str->setAlignment(MaybeAlign(1));
142-
143-
Constant *const_array = ConstantDataArray::getString(context, format, true);
144-
SmallVector<Constant *, 16> indices;
145-
ConstantInt *cst_8 = ConstantInt::get(context, APInt(64, StringRef("0"), 10));
146-
indices.push_back(cst_8);
147-
indices.push_back(cst_8);
148-
Constant *cst_ptr = ConstantExpr::getGetElementPtr(nullptr, str, indices);
149-
150-
str->setInitializer(const_array);
151-
152-
SmallVector<Value *, 8> call_params;
153-
call_params.push_back(cst_ptr);
154-
call_params.push_back(v);
155-
156-
CallInst *call = CallInst::Create(func_printf, call_params, "", bb);
157-
158-
return call;
159-
}
160-
#endif // NDEBUG_WI_LOOPS
161101

162102
Value *materializeVF(IRBuilder<> &builder,
163103
compiler::utils::VectorizationFactor vf) {
@@ -235,13 +175,6 @@ struct ScheduleGenerator {
235175
Value *const live_var_mem_idxs[] = {byteOffset};
236176
live_var_ptr =
237177
ir.CreateInBoundsGEP(ir.getInt8Ty(), mem_space, live_var_mem_idxs);
238-
239-
// cast to the live mem type
240-
live_var_ptr = ir.CreatePointerCast(
241-
live_var_ptr,
242-
PointerType::get(
243-
barrier.getLiveVarsType(),
244-
cast<PointerType>(live_var_ptr->getType())->getAddressSpace()));
245178
}
246179

247180
return live_var_ptr;
@@ -380,10 +313,6 @@ struct ScheduleGenerator {
380313
ci->setCallingConv(subkernel.getCallingConv());
381314
ci->setAttributes(compiler::utils::getCopiedFunctionAttrs(subkernel));
382315

383-
#ifndef NDEBUG_WI_LOOPS
384-
IRPrintf(std::string("return.kernel.body=%d\x0A"), module, ci, block);
385-
#endif // NDEBUG_WI_LOOPS
386-
387316
// And update the location of where we need to go to next (if we need to)
388317
const auto &successors = barrier.getSuccessorIds(i);
389318
if (successors.size() > 1) {

modules/compiler/source/base/source/printf_replacement_pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ PreservedAnalyses compiler::PrintfReplacementPass::run(
839839
// Clone functions and add extra argument for printf(). Only functions
840840
// directly or indirectly calling printf are given the extra parameter.
841841
auto new_param_type =
842-
PointerType::get(getBufferEltTy(module.getContext()), 1);
842+
PointerType::get(module.getContext(), /*AddressSpace=*/1);
843843
auto param_type_func = [new_param_type](Module &) {
844844
return compiler::utils::ParamTypeAttrsPair{new_param_type, AttributeSet{}};
845845
};

modules/compiler/spirv-ll/source/builder_core.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,9 +1781,9 @@ llvm::Error Builder::create<OpFunction>(const OpFunction *op) {
17811781

17821782
// turn the list of descriptor binding IDs into a sorted list of the
17831783
// interface block types
1784-
for (auto id : binding_list) {
1784+
for ([[maybe_unused]] auto _ : binding_list) {
17851785
// Blocks are always passed by pointer
1786-
llvm::Type *type = llvm::PointerType::get(module.getBlockType(id), 1);
1786+
llvm::Type *type = IRBuilder.getPtrTy(/*AddressSpace=*/1);
17871787
SPIRV_LL_ASSERT_PTR(type);
17881788

17891789
arg_types.push_back(type);
@@ -1798,8 +1798,7 @@ llvm::Error Builder::create<OpFunction>(const OpFunction *op) {
17981798
// if this module has used any descriptor bindings add the buffer sizes
17991799
// buffer to the argument list (1 == global address space)
18001800
if (module.hasDescriptorBindings()) {
1801-
arg_types.push_back(llvm::PointerType::get(
1802-
getBufferSizeTy(IRBuilder.getContext()), 1));
1801+
arg_types.push_back(IRBuilder.getPtrTy(/*AddressSpace=*/1));
18031802
}
18041803

18051804
// create a new function type with the same return type as the original

0 commit comments

Comments
 (0)