Skip to content

Commit 9818284

Browse files
ViacheslavRbigcbot
authored andcommitted
Reduce usage of pointer element types (6).
This change replaces calls to getNonOpaquePtrEltTy in compute-related passes with element type information got through other means. This change is part of the effort to support opaque pointers in newer LLVM versions.
1 parent 046c2e8 commit 9818284

File tree

8 files changed

+28
-29
lines changed

8 files changed

+28
-29
lines changed

IGC/AdaptorCommon/LegalizeFunctionSignatures.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2020-2021 Intel Corporation
3+
Copyright (C) 2020-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -205,7 +205,6 @@ inline void StoreToStruct(IGCLLVM::IRBuilder<>& builder, Value* strVal, Value* s
205205
{
206206
IGC_ASSERT(strPtr->getType()->isPointerTy());
207207
IGC_ASSERT(strVal->getType()->isStructTy());
208-
IGC_ASSERT(IGCLLVM::getNonOpaquePtrEltTy(strPtr->getType()) == strVal->getType());
209208

210209
StructType* sTy = cast<StructType>(strVal->getType());
211210
for (unsigned i = 0; i < sTy->getNumElements(); i++)
@@ -617,6 +616,7 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
617616
{
618617
IGCLLVM::IRBuilder<> builder(callInst);
619618
Value* newCalledValue = nullptr;
619+
FunctionType* newFnTy = nullptr;
620620
if (!calledFunc)
621621
{
622622
// Indirect call, cast the pointer type
@@ -628,7 +628,7 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
628628
Type* retType = legalizeReturnType ? Type::getVoidTy(callInst->getContext()) :
629629
promoteSRetType ? PromotedStructValueType(M, callInst->getArgOperand(0)->getType()) :
630630
callInst->getType();
631-
FunctionType* newFnTy = FunctionType::get(retType, argTypes, false);
631+
newFnTy = FunctionType::get(retType, argTypes, false);
632632
Value* calledValue = IGCLLVM::getCalledValue(callInst);
633633
newCalledValue = builder.CreatePointerCast(calledValue, PointerType::get(newFnTy, 0));
634634
}
@@ -637,10 +637,11 @@ void LegalizeFunctionSignatures::FixCallInstruction(Module& M, CallInst* callIns
637637
// Directly call the new function pointer
638638
IGC_ASSERT(oldToNewFuncMap.find(calledFunc) != oldToNewFuncMap.end());
639639
newCalledValue = oldToNewFuncMap[calledFunc];
640+
newFnTy = cast<Function>(newCalledValue)->getFunctionType();
640641
}
641642

642643
// Create the new call instruction
643-
CallInst* newCallInst = builder.CreateCall(newCalledValue, callArgs);
644+
CallInst* newCallInst = builder.CreateCall(newFnTy, newCalledValue, callArgs);
644645
newCallInst->setCallingConv(callInst->getCallingConv());
645646
newCallInst->setAttributes(AttributeList::get(M.getContext(), IGCLLVM::getFnAttrs(PAL), IGCLLVM::getRetAttrs(PAL), ArgAttrVec));
646647
newCallInst->setDebugLoc(callInst->getDebugLoc());

IGC/AdaptorOCL/LowerInvokeSIMD.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2023 Intel Corporation
3+
Copyright (C) 2023-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -125,7 +125,7 @@ void LowerInvokeSIMD::visitCallInst(CallInst &CI) {
125125
FTy,
126126
cast<PointerType>(CI.getArgOperand(0)->getType())->getAddressSpace());
127127
auto CastedPointer = m_Builder->CreateBitCast(CI.getArgOperand(0), PTy);
128-
NewCall = m_Builder->CreateCall(CastedPointer, ArgVals);
128+
NewCall = m_Builder->CreateCall(FTy, CastedPointer, ArgVals);
129129
}
130130

131131
NewCall->setCallingConv(CI.getCallingConv());

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2021 Intel Corporation
3+
Copyright (C) 2017-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -1931,7 +1931,7 @@ bool SPIRVToLLVM::transOCLBuiltinFromVariable(GlobalVariable *GV,
19311931
decorateSPIRVBuiltin(FuncName);
19321932
Function *Func = M->getFunction(FuncName);
19331933
if (!Func) {
1934-
Type *ReturnTy = IGCLLVM::getNonOpaquePtrEltTy(GV->getType());
1934+
Type *ReturnTy = GV->getValueType();
19351935
FunctionType *FT = FunctionType::get(ReturnTy, false);
19361936
Func = Function::Create(FT, GlobalValue::ExternalLinkage, FuncName, M);
19371937
Func->setCallingConv(CallingConv::SPIR_FUNC);
@@ -1974,7 +1974,7 @@ bool SPIRVToLLVM::transOCLBuiltinFromVariable(GlobalVariable *GV,
19741974
Value* substitution = call;
19751975
// Check if an ExtractElement instruction is needed.
19761976
if (Func->getFunctionType()->getReturnType()->isVectorTy() &&
1977-
!IGCLLVM::getNonOpaquePtrEltTy(load->getPointerOperandType())->isVectorTy()) {
1977+
!load->getType()->isVectorTy()) {
19781978
auto gep = cast<GetElementPtrInst>(load->getOperand(0));
19791979
IGC_ASSERT_MESSAGE(gep, "Expected GetElementrPtr instruction");
19801980
IGC_ASSERT_MESSAGE(gep->getNumIndices() == 2, "Expected GetElementrPtr with exactly two indices");
@@ -3367,7 +3367,7 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
33673367
0, GlobalVariable::NotThreadLocal, 0);
33683368

33693369
auto LD = new LoadInst(
3370-
IGCLLVM::getNonOpaquePtrEltTy(GV->getType()),
3370+
GV->getValueType(),
33713371
GV, BV->getName(), BB);
33723372
PlaceholderMap[BV] = LD;
33733373
return mapValue(BV, LD);

IGC/AdaptorOCL/preprocess_spvir/PromoteBools.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2022-2023 Intel Corporation
3+
Copyright (C) 2022-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -658,7 +658,7 @@ GlobalVariable* PromoteBools::promoteGlobalVariable(GlobalVariable* globalVariab
658658

659659
auto newGlobalVariable = new GlobalVariable(
660660
*globalVariable->getParent(),
661-
getOrCreatePromotedType(IGCLLVM::getNonOpaquePtrEltTy(globalVariable->getType())),
661+
getOrCreatePromotedType(globalVariable->getValueType()),
662662
globalVariable->isConstant(),
663663
globalVariable->getLinkage(),
664664
promoteConstant(globalVariable->getInitializer()),

IGC/Compiler/CISACodeGen/CShader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2022 Intel Corporation
3+
Copyright (C) 2017-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -3076,7 +3076,7 @@ CVariable* CShader::GetSymbol(llvm::Value* value, bool fromConstantPool)
30763076
{
30773077
return isa<GlobalValue>(value) &&
30783078
value->getType()->isPointerTy() &&
3079-
IGCLLVM::getNonOpaquePtrEltTy(value->getType())->isFunctionTy();
3079+
cast<GlobalValue>(value)->getValueType()->isFunctionTy();
30803080
};
30813081
// Global Variable/Constant
30823082
auto isGlobalVarType = [this](Value* value)

IGC/Compiler/CISACodeGen/helper.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2023 Intel Corporation
3+
Copyright (C) 2017-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -2788,8 +2788,7 @@ namespace IGC
27882788

27892789
if (instType && instType->getAddressSpace() == oldAS)
27902790
{
2791-
Type* eltType = IGCLLVM::getNonOpaquePtrEltTy(instType);
2792-
PointerType* ptrType = PointerType::get(eltType, newAS);
2791+
PointerType* ptrType = IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(instType), newAS);
27932792
inst->mutateType(ptrType);
27942793
FixAddressSpaceInAllUses(inst, newAS, oldAS);
27952794
}

IGC/Compiler/Optimizer/BuiltInFuncImport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ bool BIImport::runOnModule(Module& M)
795795
FunctionType* funcTy = FunctionType::get(builder.getVoidTy(), { argBuffer->getType() }, false);
796796
Value* funcPtr = builder.CreatePointerCast(CI->getArgOperand(0), PointerType::get(funcTy, 0));
797797
// Replace builtin with the function call
798-
CallInst* callFunc = builder.CreateCall(funcPtr, argBuffer);
798+
CallInst* callFunc = builder.CreateCall(funcTy, funcPtr, argBuffer);
799799
callFunc->setCallingConv(llvm::CallingConv::SPIR_FUNC);
800800
CI->replaceAllUsesWith(callFunc);
801801
InstToRemove.push_back(CI);

IGC/WrapperLLVM/include/llvmWrapper/IR/IRBuilder.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2018-2021 Intel Corporation
3+
Copyright (C) 2018-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -166,31 +166,30 @@ namespace IGCLLVM
166166
#endif
167167

168168
#if LLVM_VERSION_MAJOR >= 11
169-
inline llvm::CallInst* CreateCall(llvm::Value* Callee, llvm::ArrayRef<llvm::Value*> Args = llvm::None,
170-
const llvm::Twine& Name = "", llvm::MDNode* FPMathTag = nullptr) {
169+
170+
inline llvm::CallInst* CreateCall(llvm::Value* Callee, llvm::ArrayRef<llvm::Value*> Args = llvm::None,
171+
const llvm::Twine& Name = "", llvm::MDNode* FPMathTag = nullptr) {
171172
return llvm::IRBuilder<T, InserterTyDef()>::CreateCall(
172-
llvm::cast<llvm::FunctionType>(IGCLLVM::getNonOpaquePtrEltTy(Callee->getType())), Callee,
173-
Args, Name, FPMathTag);
173+
llvm::cast<llvm::Function>(Callee)->getFunctionType(),
174+
Callee, Args, Name, FPMathTag);
174175
}
175176

176177
inline llvm::CallInst *
177178
CreateCall(llvm::Value *Callee, llvm::ArrayRef<llvm::Value *> Args,
178179
llvm::ArrayRef<llvm::OperandBundleDef> OpBundles,
179180
const llvm::Twine &Name = "",
180181
llvm::MDNode *FPMathTag = nullptr) {
181-
return llvm::IRBuilder<T, InserterTyDef()>::CreateCall(
182-
llvm::cast<llvm::FunctionType>(
183-
IGCLLVM::getNonOpaquePtrEltTy(Callee->getType())),
184-
Callee, Args, OpBundles, Name, FPMathTag);
182+
return llvm::IRBuilder<T, InserterTyDef()>::CreateCall(
183+
llvm::cast<llvm::Function>(Callee)->getFunctionType(),
184+
Callee, Args, OpBundles, Name, FPMathTag);
185185
}
186186

187187
inline llvm::CallInst *
188188
CreateCall(llvm::FunctionType *FTy, llvm::Value *Callee,
189189
llvm::ArrayRef<llvm::Value *> Args = llvm::None,
190190
const llvm::Twine &Name = "",
191191
llvm::MDNode *FPMathTag = nullptr) {
192-
return llvm::IRBuilder<T, InserterTyDef()>::CreateCall(FTy, Callee, Args,
193-
Name, FPMathTag);
192+
return llvm::IRBuilder<T, InserterTyDef()>::CreateCall(FTy, Callee, Args, Name, FPMathTag);
194193
}
195194
#endif
196195

0 commit comments

Comments
 (0)