Skip to content

Commit 9ea4103

Browse files
ViacheslavRbigcbot
authored andcommitted
Reduce usage of pointer element types (3).
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 cf0dd6b commit 9ea4103

File tree

11 files changed

+38
-34
lines changed

11 files changed

+38
-34
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/GASResolving.cpp

Lines changed: 3 additions & 2 deletions
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
@@ -10,6 +10,7 @@ SPDX-License-Identifier: MIT
1010

1111
#include "Compiler/CISACodeGen/ShaderCodeGen.hpp"
1212
#include "Compiler/InitializePasses.h"
13+
#include "llvmWrapper/IR/DerivedTypes.h"
1314

1415
// Generic address space (GAS) pointer resolving is done in two steps:
1516
// 1) Find cast from non-GAS pointer to GAS pointer
@@ -259,7 +260,7 @@ void GASResolving::convertLoadToGlobal(LoadInst* LI) const {
259260

260261
PointerType* PtrTy = cast<PointerType>(LI->getType());
261262
IRB->SetInsertPoint(LI->getNextNode());
262-
PointerType* GlobalPtrTy = PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(PtrTy), ADDRESS_SPACE_GLOBAL);
263+
PointerType* GlobalPtrTy = IGCLLVM::getWithSamePointeeType(PtrTy, ADDRESS_SPACE_GLOBAL);
263264
Value* GlobalAddr = IRB->CreateAddrSpaceCast(LI, GlobalPtrTy);
264265
Value* GenericCopyAddr = IRB->CreateAddrSpaceCast(GlobalAddr, PtrTy);
265266

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/GASRetValuePropagator.cpp

Lines changed: 5 additions & 2 deletions
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
@@ -17,6 +17,7 @@ SPDX-License-Identifier: MIT
1717
#include "llvm/ADT/PostOrderIterator.h"
1818
#include "llvm/BinaryFormat/Dwarf.h"
1919
#include "common/LLVMWarningsPop.hpp"
20+
#include "llvmWrapper/IR/DerivedTypes.h"
2021
#include "DebugInfo/DwarfDebug.hpp"
2122

2223
#define PASS_FLAG "igc-gas-ret-value-propagator"
@@ -152,8 +153,10 @@ PointerType* GASRetValuePropagator::getRetValueNonGASType(Function* F)
152153
originAddrSpace.emplace(AS);
153154
}
154155

156+
PointerType* retTy = cast<PointerType>(F->getReturnType());
157+
155158
return originAddrSpace ?
156-
PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(F->getReturnType()), originAddrSpace.value()) :
159+
IGCLLVM::getWithSamePointeeType(retTy, originAddrSpace.value()) :
157160
nullptr;
158161
}
159162

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/GenericAddressDynamicResolution.cpp

Lines changed: 5 additions & 4 deletions
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
@@ -16,6 +16,7 @@ SPDX-License-Identifier: MIT
1616
#include "Compiler/MetaDataUtilsWrapper.h"
1717
#include "common/LLVMWarningsPush.hpp"
1818
#include "llvmWrapper/Support/Alignment.h"
19+
#include "llvmWrapper/IR/DerivedTypes.h"
1920
#include <llvm/IR/Module.h>
2021
#include <llvm/IR/Instructions.h>
2122
#include <llvm/IR/DataLayout.h>
@@ -272,7 +273,7 @@ void GenericAddressDynamicResolution::resolveGAS(Instruction& I, Value* pointerO
272273
{
273274
BasicBlock* BB = BasicBlock::Create(I.getContext(), BlockName, convergeBlock->getParent(), convergeBlock);
274275
builder.SetInsertPoint(BB);
275-
PointerType* ptrType = IGCLLVM::getNonOpaquePtrEltTy(pointerType)->getPointerTo(addressSpace);
276+
PointerType* ptrType = IGCLLVM::getWithSamePointeeType(pointerType, addressSpace);
276277
Value* ptr = builder.CreateAddrSpaceCast(pointerOperand, ptrType);
277278

278279
if (LoadInst* LI = dyn_cast<LoadInst>(&I))
@@ -349,7 +350,7 @@ void GenericAddressDynamicResolution::resolveGASWithoutBranches(Instruction& I,
349350

350351
Value* nonLocalLoad = nullptr;
351352

352-
PointerType* ptrType = IGCLLVM::getNonOpaquePtrEltTy(pointerType)->getPointerTo(ADDRESS_SPACE_GLOBAL);
353+
PointerType* ptrType = IGCLLVM::getWithSamePointeeType(pointerType, ADDRESS_SPACE_GLOBAL);
353354
Value* globalPtr = builder.CreateAddrSpaceCast(pointerOperand, ptrType);
354355

355356
if (LoadInst* LI = dyn_cast<LoadInst>(&I))
@@ -438,7 +439,7 @@ bool GenericAddressDynamicResolution::visitIntrinsicCall(CallInst& I)
438439
// If Block
439440
{
440441
IRBuilder<> ifBuilder(ifBlock);
441-
PointerType* ptrType = IGCLLVM::getNonOpaquePtrEltTy(pointerType)->getPointerTo(targetAS);
442+
PointerType* ptrType = IGCLLVM::getWithSamePointeeType(pointerType, targetAS);
442443
newPtr = ifBuilder.CreateAddrSpaceCast(arg, ptrType);
443444
ifBuilder.CreateBr(convergeBlock);
444445
}

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/StaticGASResolution.cpp

Lines changed: 3 additions & 3 deletions
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
@@ -10,6 +10,7 @@ SPDX-License-Identifier: MIT
1010

1111
#include "Compiler/CISACodeGen/ShaderCodeGen.hpp"
1212
#include "Compiler/InitializePasses.h"
13+
#include "llvmWrapper/IR/DerivedTypes.h"
1314

1415
FunctionPass* IGC::createStaticGASResolution() { return new StaticGASResolution(); }
1516

@@ -59,8 +60,7 @@ bool StaticGASResolution::runOnFunction(llvm::Function& F)
5960
if (!toSkip(Ptr))
6061
{
6162
PointerType* PtrTy = cast<PointerType>(Ptr->getType());
62-
Type* eltTy = IGCLLVM::getNonOpaquePtrEltTy(PtrTy);
63-
PointerType* glbPtrTy = PointerType::get(eltTy, ADDRESS_SPACE_GLOBAL);
63+
PointerType* glbPtrTy = IGCLLVM::getWithSamePointeeType(PtrTy, ADDRESS_SPACE_GLOBAL);
6464

6565
IRB.SetInsertPoint(I);
6666
Value* NewPtr = IRB.CreateAddrSpaceCast(Ptr, glbPtrTy);

IGC/Compiler/Optimizer/OpenCLPasses/LocalBuffers/InlineLocalsResolution.cpp

Lines changed: 2 additions & 3 deletions
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
@@ -519,8 +519,7 @@ void InlineLocalsResolution::computeOffsetList(Module& M, llvm::MapVector<Functi
519519
offsetMap[F][G] = (offset & 0xFFFF);
520520

521521
// And the total size after this local is added
522-
PointerType* ptrType = dyn_cast<PointerType>(G->getType());
523-
Type* varType = IGCLLVM::getNonOpaquePtrEltTy(ptrType);
522+
Type* varType = G->getValueType();
524523
if (G == m_pGV)
525524
{
526525
// it is GetMemPoolPtr usage

IGC/Compiler/Optimizer/OpenCLPasses/NamedBarriers/NamedBarriersResolution.cpp

Lines changed: 2 additions & 2 deletions
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
@@ -332,7 +332,7 @@ void NamedBarriersResolution::HandleNamedBarrierInitSW(CallInst& NBarrierInitCal
332332
m_NamedBarrierType->getPointerTo(SPIRAS_Local),
333333
Type::getInt32PtrTy(context, SPIRAS_Local)
334334
};
335-
Type *BaseTy = IGCLLVM::getNonOpaquePtrEltTy(m_NamedBarrierArray->getType());
335+
Type* BaseTy = m_NamedBarrierArray->getValueType();
336336
auto pointerNBarrier = GetElementPtrInst::Create(BaseTy, m_NamedBarrierArray, { getInt64(module, 0), getInt32(module, 0) }, "", &(NBarrierInitCall));
337337
auto bitcastPointerNBarrier = BitCastInst::CreatePointerBitCastOrAddrSpaceCast(pointerNBarrier, m_NamedBarrierType->getPointerTo(SPIRAS_Local), "", &(NBarrierInitCall));
338338
SmallVector<Value*, 3> ArgsVal

IGC/Compiler/Optimizer/OpenCLPasses/PoisonFP64KernelsPass/PoisonFP64KernelsPass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2022 Intel Corporation
3+
Copyright (C) 2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -90,7 +90,7 @@ bool PoisonFP64Kernels::runOnSCC(CallGraphSCC &SCC) {
9090
return modified;
9191
}
9292

93-
static Constant *createPoisonMessage(Module *M, Function *Kernel) {
93+
static GlobalVariable *createPoisonMessage(Module *M, Function *Kernel) {
9494
std::string message = "[CRITICAL ERROR] Kernel '" + Kernel->getName().str()
9595
+ "' removed due to usage of FP64 instructions unsupported by the targeted hardware. "
9696
+ "Running this kernel may result in unexpected results.\n";
@@ -162,8 +162,8 @@ static void poisonKernel(Function *Kernel) {
162162

163163
Function *Printf = getOrDeclareFunction(M, "printf", FunctionType::get(Int32Ty, { Type::getInt8PtrTy(Ctx, 2) }, true));
164164

165-
Constant *PoisonMessage = createPoisonMessage(M, Kernel);
166-
Type *MessageType = IGCLLVM::getNonOpaquePtrEltTy(PoisonMessage->getType());
165+
GlobalVariable* PoisonMessage = createPoisonMessage(M, Kernel);
166+
Type* MessageType = PoisonMessage->getValueType();
167167

168168
std::vector<Value *> Indices = {
169169
ConstantInt::getSigned(Type::getInt32Ty(Ctx), 0),

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp

Lines changed: 5 additions & 5 deletions
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
@@ -571,7 +571,7 @@ class TransposeHelperPrivateMem : public TransposeHelper
571571
IRB.SetInsertPoint(pLoad);
572572
if (!vectorIO && pLoad->getType()->isVectorTy())
573573
{
574-
Type* scalarType = IGCLLVM::getNonOpaquePtrEltTy(pLoad->getPointerOperand()->getType())->getScalarType();
574+
Type* scalarType = pLoad->getType()->getScalarType();
575575
IGC_ASSERT(nullptr != scalarType);
576576
Type* scalarptrTy = PointerType::get(scalarType, pLoad->getPointerAddressSpace());
577577
IGC_ASSERT(scalarType->getPrimitiveSizeInBits() / 8 == elementSize);
@@ -609,7 +609,7 @@ class TransposeHelperPrivateMem : public TransposeHelper
609609
IRB.SetInsertPoint(pStore);
610610
if (!vectorIO && pStore->getValueOperand()->getType()->isVectorTy())
611611
{
612-
Type* scalarType = IGCLLVM::getNonOpaquePtrEltTy(pStore->getPointerOperand()->getType())->getScalarType();
612+
Type* scalarType = pStore->getValueOperand()->getType()->getScalarType();
613613
IGC_ASSERT(nullptr != scalarType);
614614
Type* scalarptrTy = PointerType::get(scalarType, pStore->getPointerAddressSpace());
615615
IGC_ASSERT(scalarType->getPrimitiveSizeInBits() / 8 == elementSize);
@@ -998,7 +998,7 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack)
998998
// possibility to use large loads/stores, so cancel the transformation.
999999
// Currently it is only enabled by option
10001000
bool isSOABeneficial = pTypeOfAccessedObject->isVectorTy() || !allUsesAreVector;
1001-
Type* allocaType = GetBaseType(IGCLLVM::getNonOpaquePtrEltTy(pAI->getType()));
1001+
Type* allocaType = pAI->getAllocatedType();
10021002
if (VectorType* vectorType = dyn_cast<VectorType>(allocaType))
10031003
{
10041004
bool baseTypeIsSmall = (unsigned)(vectorType->getElementType()->getScalarSizeInBits()) < 32;
@@ -1012,7 +1012,7 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack)
10121012
{
10131013
auto DL = &m_currFunction->getParent()->getDataLayout();
10141014
bufferSize = (unsigned)DL->getTypeAllocSize(pTypeOfAccessedObject);
1015-
IGC_ASSERT(testTransposedMemory(IGCLLVM::getNonOpaquePtrEltTy(pAI->getType()), pTypeOfAccessedObject, bufferSize, (m_ModAllocaInfo->getConstBufferSize(pAI))));
1015+
IGC_ASSERT(testTransposedMemory(pAI->getAllocatedType(), pTypeOfAccessedObject, bufferSize, (m_ModAllocaInfo->getConstBufferSize(pAI))));
10161016
}
10171017
else
10181018
{

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryToSLM.cpp

Lines changed: 3 additions & 4 deletions
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
@@ -192,8 +192,7 @@ namespace IGC
192192
unsigned int offset = 0;
193193
for (const auto &offsets : ModuleMD->FuncMD[F].localOffsets)
194194
{
195-
PointerType* ptrType = dyn_cast<PointerType>(offsets.m_Var->getType());
196-
Type* varType = IGCLLVM::getNonOpaquePtrEltTy(ptrType);
195+
Type* varType = offsets.m_Var->getValueType();
197196
offset = iSTD::Align(offset, IGCLLVM::getPreferredAlignValue(&DL, offsets.m_Var));
198197
offset += (unsigned int) DL.getTypeAllocSize(varType);
199198
}
@@ -229,7 +228,7 @@ namespace IGC
229228

230229
if (m_ForceAll || isForcedBuffer)
231230
{
232-
Type* origType = IGCLLVM::getNonOpaquePtrEltTy(pAI->getType());
231+
Type* origType = pAI->getAllocatedType();
233232
bool isArray = origType->isArrayTy();
234233
Type* eltType = isArray ? origType->getArrayElementType() : origType;
235234
uint64_t numEltsPerThread = isArray ? origType->getArrayNumElements() : 1;

IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantAnalysis.cpp

Lines changed: 2 additions & 2 deletions
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
@@ -196,7 +196,7 @@ bool ProgramScopeConstantAnalysis::runOnModule(Module& M)
196196
offset = iSTD::Align(offset, (unsigned)m_DL->getPreferredAlign(globalVar).value());
197197
#endif
198198
inlineProgramScopeOffsets[globalVar] = offset;
199-
offset += (unsigned)(m_DL->getTypeAllocSize(IGCLLVM::getNonOpaquePtrEltTy(globalVar->getType())));
199+
offset += (unsigned)(m_DL->getTypeAllocSize(globalVar->getValueType()));
200200
}
201201

202202
// Patch the offsets for usages of zero initialized globals after those offsets have been calculated in the previous step.

IGC/Compiler/Optimizer/PreCompiledFuncImport.cpp

Lines changed: 4 additions & 3 deletions
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
@@ -549,8 +549,9 @@ bool PreCompiledFuncImport::preProcessDouble()
549549
else if (Inst->getOpcode() == Instruction::FNeg)
550550
{
551551
// check if Inst is double instruction or vector of double instructions
552-
if (Inst->getType()->isDoubleTy() ||
553-
(Inst->getType()->isVectorTy() && IGCLLVM::getNonOpaquePtrEltTy(Inst->getType())->isDoubleTy()))
552+
Type* instType = Inst->getType();
553+
IGCLLVM::FixedVectorType* instVecType = dyn_cast<IGCLLVM::FixedVectorType>(instType);
554+
if (instType->isDoubleTy() || (instVecType && instVecType->getElementType()->isDoubleTy()))
554555
{
555556
IGCLLVM::IRBuilder<> builder(Inst);
556557
Value* fsub = nullptr;

0 commit comments

Comments
 (0)