Skip to content

Commit 3c03e79

Browse files
ViacheslavRbigcbot
authored andcommitted
Reduce usage of pointer element types.
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 c3f247b commit 3c03e79

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

IGC/Compiler/CISACodeGen/GenCodeGenModule.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
@@ -31,6 +31,7 @@ SPDX-License-Identifier: MIT
3131
#include "llvm/IR/InstVisitor.h"
3232
#include "llvm/Transforms/IPO.h"
3333
#include "llvm/Transforms/IPO/Inliner.h"
34+
#include "llvmWrapper/IR/DerivedTypes.h"
3435
#include "llvmWrapper/Transforms/Utils/Cloning.h"
3536
#include "llvm/IR/DebugInfo.h"
3637
#include "llvm/IR/DIBuilder.h"
@@ -1371,14 +1372,14 @@ void SubroutineInliner::visitMemCpyInst(MemCpyInst& I)
13711372
if (origSrc->getType()->getPointerAddressSpace() != Src->getType()->getPointerAddressSpace())
13721373
{
13731374
Value* SrcCast = BitCastInst::Create(Instruction::BitCast, origSrc,
1374-
PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(Src->getType()), origSrc->getType()->getPointerAddressSpace()),
1375+
IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(Src->getType()), origSrc->getType()->getPointerAddressSpace()),
13751376
"", &I);
13761377
I.replaceUsesOfWith(Src, SrcCast);
13771378
}
13781379
if (origDst->getType()->getPointerAddressSpace() != Dst->getType()->getPointerAddressSpace())
13791380
{
13801381
Value* DstCast = BitCastInst::Create(Instruction::BitCast, origDst,
1381-
PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(Dst->getType()), origDst->getType()->getPointerAddressSpace()),
1382+
IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(Dst->getType()), origDst->getType()->getPointerAddressSpace()),
13821383
"", &I);
13831384
I.replaceUsesOfWith(Dst, DstCast);
13841385
}

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/LowerGPCallArg.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
@@ -16,6 +16,7 @@ SPDX-License-Identifier: MIT
1616
#include "llvm/ADT/PostOrderIterator.h"
1717
#include <llvm/IR/DIBuilder.h>
1818
#include "common/LLVMWarningsPop.hpp"
19+
#include "llvmWrapper/IR/DerivedTypes.h"
1920

2021
// (1)
2122
// Optimization pass to lower generic pointers in function arguments.
@@ -157,7 +158,7 @@ Function* LowerGPCallArg::createFuncWithLoweredArgs(Function* F, GenericPointerA
157158
std::vector<Type*> newParamTypes(pFuncType->param_begin(), pFuncType->param_end());
158159
for (auto& argInfo : argsInfo)
159160
{
160-
PointerType* ptrType = PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(newParamTypes[argInfo.argNo]),
161+
PointerType* ptrType = IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(newParamTypes[argInfo.argNo]),
161162
argInfo.addrSpace);
162163
newParamTypes[argInfo.argNo] = ptrType;
163164
}

IGC/Compiler/Optimizer/OpenCLPasses/StatelessToStateful/StatelessToStateful.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
@@ -13,6 +13,7 @@ SPDX-License-Identifier: MIT
1313
#include "common/Stats.hpp"
1414
#include "common/secure_string.h"
1515
#include "common/LLVMWarningsPush.hpp"
16+
#include "llvmWrapper/IR/DerivedTypes.h"
1617
#include "llvmWrapper/IR/Instructions.h"
1718
#include "llvmWrapper/Support/Alignment.h"
1819
#include <llvm/IR/Function.h>
@@ -557,7 +558,7 @@ void StatelessToStateful::promoteIntrinsic(InstructionInfo& II)
557558
Module* M = m_F->getParent();
558559
const DebugLoc& DL = I->getDebugLoc();
559560
GenISAIntrinsic::ID const intrinID = I->getIntrinsicID();
560-
PointerType* pTy = PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(II.ptr->getType()), II.getStatefulAddrSpace());
561+
PointerType* pTy = IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(II.ptr->getType()), II.getStatefulAddrSpace());
561562

562563
if (m_targetAddressing == TargetAddressing::BINDLESS)
563564
{
@@ -663,7 +664,7 @@ void StatelessToStateful::promoteLoad(InstructionInfo& II)
663664
{
664665
auto newBasePtr = IntToPtrInst::Create(Instruction::IntToPtr, II.offset, pTy, "", I);
665666
auto bindfulLoad = new LoadInst(
666-
IGCLLVM::getNonOpaquePtrEltTy(newBasePtr->getType()),
667+
I->getType(),
667668
newBasePtr,
668669
"",
669670
I->isVolatile(),

IGC/Compiler/PromoteResourceToDirectAS.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-2021 Intel Corporation
3+
Copyright (C) 2017-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -12,6 +12,7 @@ SPDX-License-Identifier: MIT
1212
#include <llvm/IR/Constants.h>
1313
#include <llvm/IR/Module.h>
1414
#include <llvm/IR/Function.h>
15+
#include "llvmWrapper/IR/DerivedTypes.h"
1516
#include <llvmWrapper/IR/Type.h>
1617
#include <llvmWrapper/Support/Alignment.h>
1718
#include "common/LLVMWarningsPop.hpp"
@@ -280,7 +281,7 @@ void PromoteResourceToDirectAS::PromoteSamplerTextureToDirectAS(GenIntrinsicInst
280281
}
281282

282283
addrSpace = IGC::EncodeAS4GFXResource(*bufferId, bufTy);
283-
PointerType* newptrType = PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(resourcePtr->getType()), addrSpace);
284+
PointerType* newptrType = IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(resourcePtr->getType()), addrSpace);
284285

285286
Value* mutePtr = nullptr;
286287
if (llvm::isa<llvm::ConstantInt>(bufferId))
@@ -364,7 +365,7 @@ bool PatchGetElementPtr(const std::vector<Value*>& instList, Type* dstTy, unsign
364365
}
365366
else if (BitCastInst * cast = dyn_cast<BitCastInst>(inst))
366367
{
367-
PointerType* newptrType = PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(cast->getType()), directAS);
368+
PointerType* newptrType = IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(cast->getType()), directAS);
368369
patchedInst = BitCastInst::Create(Instruction::BitCast, patchedInst, newptrType, "", cast);
369370
if (BitCastInst* castPathedInst = dyn_cast<BitCastInst>(patchedInst))
370371
{
@@ -447,7 +448,7 @@ bool PatchInstructionAddressSpace(const std::vector<Value*>& instList, Type* dst
447448
}
448449
else if (phiNode)
449450
{
450-
PointerType* newPhiTy = PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(phiNode->getType()), directAS);
451+
PointerType* newPhiTy = IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(phiNode->getType()), directAS);
451452
PHINode* pNewPhi = PHINode::Create(newPhiTy, phiNode->getNumIncomingValues(), "", phiNode);
452453
for (unsigned int i = 0; i < phiNode->getNumIncomingValues(); ++i)
453454
{

IGC/Compiler/PromoteStatelessToBindless.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) 2019-2021 Intel Corporation
3+
Copyright (C) 2019-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -10,6 +10,7 @@ SPDX-License-Identifier: MIT
1010
#include "AdaptorCommon/ImplicitArgs.hpp"
1111
#include "Compiler/IGCPassSupport.h"
1212
#include "common/LLVMWarningsPush.hpp"
13+
#include "llvmWrapper/IR/DerivedTypes.h"
1314
#include <llvm/IR/Constants.h>
1415
#include <llvm/IR/Function.h>
1516
#include "common/LLVMWarningsPop.hpp"
@@ -225,7 +226,7 @@ void PromoteStatelessToBindless::PromoteStatelessToBindlessBuffers(Function& F)
225226
Value* resourcePtr = IGC::GetBufferOperand(accessInst);
226227
IGC_ASSERT(resourcePtr);
227228
unsigned bindlessAS = IGC::EncodeAS4GFXResource(*UndefValue::get(builder.getInt32Ty()), IGC::BINDLESS);
228-
PointerType* basePointerType = PointerType::get(IGCLLVM::getNonOpaquePtrEltTy(resourcePtr->getType()), bindlessAS);
229+
PointerType* basePointerType = IGCLLVM::getWithSamePointeeType(dyn_cast<PointerType>(resourcePtr->getType()), bindlessAS);
229230
Value* bufferOffset = builder.CreatePtrToInt(resourcePtr, builder.getInt32Ty());
230231

231232
Value* basePointer = nullptr;

0 commit comments

Comments
 (0)