Skip to content

Commit 12a354e

Browse files
fix applying of deduced types
1 parent 5fb5a7f commit 12a354e

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ class SPIRVEmitIntrinsics
7777
SPIRV::InstructionSet::InstructionSet InstrSet;
7878

7979
// map of function declarations to <pointer arg index => element type>
80-
DenseMap<const Function *, SmallVector<std::pair<unsigned, Type *>>>
81-
FDeclPtrTys;
80+
DenseMap<Function *, SmallVector<std::pair<unsigned, Type *>>> FDeclPtrTys;
8281

8382
// a register of Instructions that don't have a complete type definition
8483
bool CanTodoType = true;
@@ -2176,8 +2175,6 @@ bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
21762175
AggrConstTypes.clear();
21772176
AggrStores.clear();
21782177

2179-
DenseMap<Function *, DenseMap<unsigned, Type *>> FDeclPtrTys;
2180-
21812178
processParamTypesByFunHeader(CurrF, B);
21822179

21832180
// StoreInst's operand type can be changed during the next transformations,
@@ -2202,28 +2199,31 @@ bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
22022199
Worklist.push_back(&I);
22032200

22042201
// Apply types parsed from demangled function declarations.
2205-
for (auto &I : Worklist) {
2206-
CallInst *CI = dyn_cast<CallInst>(I);
2207-
if (!CI || !CI->getCalledFunction())
2208-
continue;
2209-
auto It = FDeclPtrTys.find(CI->getCalledFunction());
2210-
if (It == FDeclPtrTys.end())
2211-
continue;
2212-
unsigned Sz = CI->arg_size();
2213-
for (auto [Idx, ElemTy] : It->second)
2214-
if (Idx < Sz) {
2202+
for (auto It : FDeclPtrTys) {
2203+
Function *F = It.first;
2204+
for (auto *U : F->users()) {
2205+
CallInst *CI = dyn_cast<CallInst>(U);
2206+
if (!CI || CI->getCalledFunction() != F)
2207+
continue;
2208+
unsigned Sz = CI->arg_size();
2209+
for (auto [Idx, ElemTy] : It.second) {
2210+
if (Idx >= Sz)
2211+
continue;
22152212
Value *Arg = CI->getArgOperand(Idx);
22162213
GR->addDeducedElementType(Arg, ElemTy);
2217-
if (CallInst *Ref = dyn_cast<CallInst>(Arg))
2218-
if (Function *RefF = Ref->getCalledFunction();
2219-
RefF && isPointerTy(RefF->getReturnType()) &&
2220-
!GR->findDeducedElementType(RefF)) {
2221-
GR->addDeducedElementType(RefF, ElemTy);
2222-
GR->addReturnType(RefF, TypedPointerType::get(
2223-
ElemTy, getPointerAddressSpace(
2224-
RefF->getReturnType())));
2225-
}
2214+
CallInst *Ref = dyn_cast<CallInst>(Arg);
2215+
if (!Ref)
2216+
continue;
2217+
Function *RefF = Ref->getCalledFunction();
2218+
if (!RefF || !isPointerTy(RefF->getReturnType()) ||
2219+
GR->findDeducedElementType(RefF))
2220+
continue;
2221+
GR->addDeducedElementType(RefF, ElemTy);
2222+
GR->addReturnType(
2223+
RefF, TypedPointerType::get(
2224+
ElemTy, getPointerAddressSpace(RefF->getReturnType())));
22262225
}
2226+
}
22272227
}
22282228

22292229
// Pass forward: use operand to deduce instructions result.

0 commit comments

Comments
 (0)