Skip to content

Commit abcc78b

Browse files
ViacheslavRbigcbot
authored andcommitted
Reduce usage of pointer element types (31).
This change replaces calls to getNonOpaquePtrEltTy 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 3354c80 commit abcc78b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ bool GASPropagator::visitBitCastInst(BitCastInst& I) {
120120
PointerType* SrcPtrTy = cast<PointerType>(TheVal->getType());
121121
PointerType* DstPtrTy = cast<PointerType>(I.getType());
122122

123+
BuilderType::InsertPointGuard Guard(IRB);
124+
IRB.SetInsertPoint(I.getNextNode());
125+
Value* Src = TheVal;
123126
if (!IGCLLVM::isOpaquePointerTy(SrcPtrTy)) {
124-
BuilderType::InsertPointGuard Guard(IRB);
125-
IRB.SetInsertPoint(I.getNextNode());
126127
// Push `addrspacecast` forward by replacing this `bitcast` on GAS with the
127128
// one on non-GAS followed by a new `addrspacecast` to GAS.
128129
Type* DstTy = IGCLLVM::getNonOpaquePtrEltTy(DstPtrTy); // Legacy code: getNonOpaquePtrEltTy
129130
PointerType* TransPtrTy =
130131
PointerType::get(DstTy, SrcPtrTy->getAddressSpace());
131-
Value* Src = TheVal;
132132
if (IGCLLVM::getNonOpaquePtrEltTy(SrcPtrTy) != DstTy) // Legacy code: getNonOpaquePtrEltTy
133133
Src = IRB.CreateBitCast(Src, TransPtrTy);
134-
Value* NewPtr = IRB.CreateAddrSpaceCast(Src, DstPtrTy);
135-
I.replaceAllUsesWith(NewPtr);
136-
I.eraseFromParent();
137134
}
135+
Value* NewPtr = IRB.CreateAddrSpaceCast(Src, DstPtrTy);
136+
I.replaceAllUsesWith(NewPtr);
137+
I.eraseFromParent();
138138
return true;
139139
}
140140

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SPDX-License-Identifier: MIT
1111
#include "Compiler/CISACodeGen/ShaderCodeGen.hpp"
1212
#include "Compiler/InitializePasses.h"
1313
#include "llvmWrapper/IR/DerivedTypes.h"
14+
#include "llvmWrapper/IR/Argument.h"
1415

1516
// Generic address space (GAS) pointer resolving is done in two steps:
1617
// 1) Find cast from non-GAS pointer to GAS pointer
@@ -266,7 +267,12 @@ bool GASResolving::checkGenericArguments(Function& F) const {
266267
if (auto Ty = dyn_cast<PointerType>(FT->getParamType(p))) {
267268
if (Ty->getAddressSpace() != ADDRESS_SPACE_GLOBAL)
268269
continue;
269-
auto PteeTy = IGCLLVM::getNonOpaquePtrEltTy(Ty);
270+
auto PteeTy = IGCLLVM::getArgAttrEltTy(F.getArg(p));
271+
if (PteeTy == nullptr && !IGCLLVM::isOpaquePointerTy(Ty))
272+
PteeTy = IGCLLVM::getNonOpaquePtrEltTy(Ty); // Legacy code: getNonOpaquePtrEltTy
273+
if (PteeTy == nullptr)
274+
// go to slow path
275+
return true;
270276
if (auto PTy = dyn_cast<PointerType>(PteeTy)) {
271277
if (PTy->getAddressSpace() == ADDRESS_SPACE_GENERIC)
272278
return true;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ inline void setParamByRefType([[maybe_unused]] llvm::Argument *arg, [[maybe_unus
3737
#endif
3838
}
3939

40+
inline llvm::Type* getArgAttrEltTy(const llvm::Argument* Arg) {
41+
llvm::AttributeSet ParamAttrs =
42+
Arg->getParent()->getAttributes().getParamAttrs(Arg->getArgNo());
43+
if (llvm::Type* ByValTy = ParamAttrs.getByValType())
44+
return ByValTy;
45+
if (llvm::Type* ByRefTy = ParamAttrs.getByRefType())
46+
return ByRefTy;
47+
if (llvm::Type* PreAllocTy = ParamAttrs.getPreallocatedType())
48+
return PreAllocTy;
49+
if (llvm::Type* InAllocaTy = ParamAttrs.getInAllocaType())
50+
return InAllocaTy;
51+
if (llvm::Type* SRetTy = ParamAttrs.getStructRetType())
52+
return SRetTy;
53+
return nullptr;
54+
}
55+
4056
} // namespace IGCLLVM
4157

4258
#endif // IGCLLVM_IR_ARGUMENT_H

0 commit comments

Comments
 (0)