@@ -77,8 +77,7 @@ class SPIRVEmitIntrinsics
77
77
SPIRV::InstructionSet::InstructionSet InstrSet;
78
78
79
79
// 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;
82
81
83
82
// a register of Instructions that don't have a complete type definition
84
83
bool CanTodoType = true ;
@@ -2176,8 +2175,6 @@ bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
2176
2175
AggrConstTypes.clear ();
2177
2176
AggrStores.clear ();
2178
2177
2179
- DenseMap<Function *, DenseMap<unsigned , Type *>> FDeclPtrTys;
2180
-
2181
2178
processParamTypesByFunHeader (CurrF, B);
2182
2179
2183
2180
// StoreInst's operand type can be changed during the next transformations,
@@ -2202,28 +2199,31 @@ bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
2202
2199
Worklist.push_back (&I);
2203
2200
2204
2201
// 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 ;
2215
2212
Value *Arg = CI->getArgOperand (Idx);
2216
2213
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 ())));
2226
2225
}
2226
+ }
2227
2227
}
2228
2228
2229
2229
// Pass forward: use operand to deduce instructions result.
0 commit comments