@@ -62,10 +62,6 @@ inline MetadataAsValue *buildMD(Value *Arg) {
62
62
Ctx, MDNode::get (Ctx, ValueAsMetadata::getConstant (Arg)));
63
63
}
64
64
65
- inline bool mayUpdateOpType (Value *Op) {
66
- return !(isa<CallInst>(Op) || isa<GetElementPtrInst>(Op));
67
- }
68
-
69
65
class SPIRVEmitIntrinsics
70
66
: public ModulePass,
71
67
public InstVisitor<SPIRVEmitIntrinsics, Instruction *> {
@@ -101,11 +97,6 @@ class SPIRVEmitIntrinsics
101
97
auto It = TodoType.find (Op);
102
98
return It != TodoType.end () && It->second ;
103
99
}
104
- // bool mayUpdateOpType(Value *Op) {
105
- // if (isa<CallInst>(Op) || isa<GetElementPtrInst>(Op))
106
- // return false;
107
- // return isTodoType(Op);
108
- // }
109
100
110
101
// well known result types of builtins
111
102
enum WellKnownTypes { Event };
@@ -408,7 +399,6 @@ void SPIRVEmitIntrinsics::buildAssignPtr(IRBuilder<> &B, Type *ElemTy,
408
399
GR->addDeducedElementType (Arg, ElemTy);
409
400
GR->addAssignPtrTypeInstr (Arg, AssignPtrTyCI);
410
401
} else {
411
- assert (mayUpdateOpType (Arg) || " Forbidden to update assigned type" );
412
402
updateAssignType (AssignPtrTyCI, Arg, OfType);
413
403
}
414
404
}
@@ -695,12 +685,6 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
695
685
Visited, UnknownElemTypeI8);
696
686
else if (Type *KnownRetTy = GR->findDeducedElementType (CalledF))
697
687
Ty = KnownRetTy;
698
- /*
699
- else {
700
- Ty = IntegerType::getInt8Ty(I->getContext());
701
- insertTodoType(I);
702
- }
703
- */
704
688
}
705
689
}
706
690
@@ -950,8 +934,7 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
950
934
Uncomplete = isTodoType (I);
951
935
Ops.push_back (std::make_pair (Ref->getPointerOperand (), 0 ));
952
936
} else if (auto *Ref = dyn_cast<GetElementPtrInst>(I)) {
953
- // TODO: ensure that Ref->getPointerOperand() has
954
- // Ref->getSourceElementType()
937
+ // TODO: ensure that getPointerOperand() and GEP result type are consistent
955
938
if (GR->findDeducedElementType (Ref->getPointerOperand ()))
956
939
return ;
957
940
KnownElemTy = Ref->getSourceElementType ();
@@ -967,11 +950,8 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
967
950
Ops.push_back (std::make_pair (Ref->getPointerOperand (),
968
951
LoadInst::getPointerOperandIndex ()));
969
952
} else if (auto *Ref = dyn_cast<StoreInst>(I)) {
970
- // if (IsKernelArgInt8(Ref->getParent()->getParent(), Ref))
971
- // return;
972
953
if (!(KnownElemTy =
973
- reconstructType (Ref->getValueOperand (),
974
- false /* UnknownElemTypeI8*/ , IsPostprocessing)))
954
+ reconstructType (Ref->getValueOperand (), false , IsPostprocessing)))
975
955
return ;
976
956
Type *PointeeTy = GR->findDeducedElementType (Ref->getPointerOperand ());
977
957
if (PointeeTy && !isUntypedPointerTy (PointeeTy))
@@ -1076,8 +1056,7 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
1076
1056
continue ;
1077
1057
Value *OpTyVal = PoisonValue::get (KnownElemTy);
1078
1058
Type *OpTy = Op->getType ();
1079
- if ( // mayUpdateOpType(Op) &&
1080
- (!Ty || AskTy || isUntypedPointerTy (Ty) || isTodoType (Op))) {
1059
+ if (!Ty || AskTy || isUntypedPointerTy (Ty) || isTodoType (Op)) {
1081
1060
GR->addDeducedElementType (Op, KnownElemTy);
1082
1061
// check if KnownElemTy is complete
1083
1062
if (!Uncomplete)
@@ -1344,7 +1323,6 @@ void SPIRVEmitIntrinsics::insertAssignPtrTypeTargetExt(
1344
1323
1345
1324
// Our previous guess about the type seems to be wrong, let's update
1346
1325
// inferred type according to a new, more precise type information.
1347
- assert (mayUpdateOpType (V) || " Forbidden to update assigned type" );
1348
1326
updateAssignType (AssignCI, V, PoisonValue::get (AssignedType));
1349
1327
}
1350
1328
@@ -1409,7 +1387,7 @@ void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast(
1409
1387
return ;
1410
1388
} else if (isTodoType (Pointer)) {
1411
1389
eraseTodoType (Pointer);
1412
- if (mayUpdateOpType (Pointer)) {
1390
+ if (!isa<CallInst>(Pointer) && !isa<GetElementPtrInst> (Pointer)) {
1413
1391
// If this wouldn't be the first spv_ptrcast but existing type info is
1414
1392
// uncomplete, update spv_assign_ptr_type arguments.
1415
1393
if (CallInst *AssignCI = GR->findAssignPtrTypeInstr (Pointer)) {
@@ -1431,7 +1409,6 @@ void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast(
1431
1409
I->setOperand (OperandToReplace, PtrCastI);
1432
1410
// We need to set up a pointee type for the newly created spv_ptrcast.
1433
1411
buildAssignPtr (B, ExpectedElementType, PtrCastI);
1434
- // propagateElemType(Pointer, ExpectedElementType);
1435
1412
}
1436
1413
1437
1414
void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr (Instruction *I,
@@ -1455,8 +1432,8 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
1455
1432
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
1456
1433
Value *Pointer = LI->getPointerOperand ();
1457
1434
Type *OpTy = LI->getType ();
1458
- if (auto *PtrTy = dyn_cast<PointerType>(
1459
- OpTy)) { // TODO: isNestedPointer or rather getNestedPointerAS()
1435
+ if (auto *PtrTy = dyn_cast<PointerType>(OpTy)) {
1436
+ // TODO: isNestedPointer() instead of dyn_cast<PointerType>
1460
1437
if (Type *ElemTy = GR->findDeducedElementType (LI)) {
1461
1438
OpTy = getTypedPointerWrapper (ElemTy, PtrTy->getAddressSpace ());
1462
1439
} else {
@@ -1468,24 +1445,6 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
1468
1445
}
1469
1446
return replacePointerOperandWithPtrCast (I, Pointer, OpTy, 0 , B);
1470
1447
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
1471
- /*
1472
- Value *Pointer = GEPI->getPointerOperand();
1473
- Type *OpTy = GEPI->getSourceElementType();
1474
- if (auto *PtrTy = dyn_cast<PointerType>(
1475
- OpTy)) { // TODO: isNestedPointer or rather getNestedPointerAS()
1476
- if (Type *ElemTy = GR->findDeducedElementType(Pointer)) {
1477
- return;
1478
- } else {
1479
- if (Type *ElemTy = deduceElementTypeHelper(Pointer, false))
1480
- OpTy = ElemTy;
1481
- else
1482
- insertTodoType(Pointer);
1483
- }
1484
- }
1485
- //::getPointeeType(OpTy)
1486
- // isNestedPointer
1487
- return replacePointerOperandWithPtrCast(I, Pointer, OpTy, 0, B);
1488
- */
1489
1448
Value *Pointer = GEPI->getPointerOperand ();
1490
1449
Type *OpTy = GEPI->getSourceElementType ();
1491
1450
replacePointerOperandWithPtrCast (I, Pointer, OpTy, 0 , B);
@@ -1494,7 +1453,7 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
1494
1453
return ;
1495
1454
}
1496
1455
1497
- // TODO: review and maybe merge with existing logics the following ... :
1456
+ // TODO: review and merge with existing logics:
1498
1457
// Handle calls to builtins (non-intrinsics):
1499
1458
CallInst *CI = dyn_cast<CallInst>(I);
1500
1459
if (!CI || CI->isIndirectCall () || CI->isInlineAsm () ||
@@ -1796,53 +1755,7 @@ void SPIRVEmitIntrinsics::insertAssignTypeIntrs(Instruction *I,
1796
1755
}
1797
1756
}
1798
1757
}
1799
- } /* else if (auto *Ref = dyn_cast<StoreInst>(I)) {
1800
- if (!IsKernelArgInt8(CurrF, Ref)) {
1801
- Type *ElemTy = reconstructType(Ref->getValueOperand(), false, false);
1802
- if (ElemTy) {
1803
- setInsertPointAfterDef(B, I);
1804
- buildAssignPtr(B, ElemTy, Ref->getPointerOperand());
1805
- }
1806
- }
1807
- } */ /* else if (auto *Ref = dyn_cast<StoreInst>(I)) {
1808
- if (!IsKernelArgInt8(CurrF, Ref)) {
1809
- Type *ElemTy =
1810
- reconstructType(Ref->getValueOperand(), true,
1811
- false);
1812
- assert(ElemTy);
1813
- setInsertPointAfterDef(B, I);
1814
- buildAssignPtr(B, ElemTy, Ref->getPointerOperand());
1815
- }
1816
- } else if (auto *Ref = dyn_cast<StoreInst>(I)) {
1817
- if (IsKernelArgInt8(CurrF, Ref)) {
1818
- // TODO: rework this outdated call
1819
- replacePointerOperandWithPtrCast(
1820
- I, Ref->getPointerOperand(),
1821
- IntegerType::getInt8Ty(CurrF->getContext()), 0, B);
1822
- } else {
1823
- Type *ElemTy = reconstructType(GR, Ref->getValueOperand(), true);
1824
- assert(ElemTy);
1825
- setInsertPointAfterDef(B, I);
1826
- buildAssignPtr(B, ElemTy, Ref->getPointerOperand());
1827
- }
1828
- } else if (auto *Ref = dyn_cast<GetElementPtrInst>(I)) {
1829
- Value *Op = Ref->getPointerOperand();
1830
- Type *ElemTy = Ref->getSourceElementType();
1831
- if (isUntypedPointerTy(ElemTy))
1832
- insertTodoType(Op);
1833
- setInsertPointAfterDef(B, I);
1834
- buildAssignPtr(B, ElemTy, Op);
1835
- // TODO: rework this outdated call
1836
- // replacePointerOperandWithPtrCast(I, Op,
1837
- // ElemTy, 0, B);
1838
- // Ty = Ref->getResultElementType();
1839
- // TODO: GR->findDeduceElementType()
1840
- // if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
1841
- // return replacePointerOperandWithPtrCast(I, GEPI->getPointerOperand(),
1842
- // GEPI->getSourceElementType(),
1843
- // 0, B);
1844
- // }
1845
- }*/
1758
+ }
1846
1759
1847
1760
Type *Ty = I->getType ();
1848
1761
if (!IsKnown && !Ty->isVoidTy () && !isPointerTy (Ty) && requireAssignType (I)) {
@@ -2037,11 +1950,6 @@ void SPIRVEmitIntrinsics::processParamTypesByFunHeader(Function *F,
2037
1950
buildAssignPtr (B, ElemTy, Arg);
2038
1951
continue ;
2039
1952
}
2040
- // ElemTy = deduceFunParamElementType(F, OpIdx);
2041
- // if (ElemTy) {
2042
- // buildAssignPtr(B, ElemTy, Arg);
2043
- // continue;
2044
- // }
2045
1953
if (HaveFunPtrs) {
2046
1954
for (User *U : Arg->users ()) {
2047
1955
CallInst *CI = dyn_cast<CallInst>(U);
@@ -2057,33 +1965,6 @@ void SPIRVEmitIntrinsics::processParamTypesByFunHeader(Function *F,
2057
1965
}
2058
1966
}
2059
1967
}
2060
- /*
2061
- for (User *U : Arg->users()) {
2062
- if (CallInst *CI = dyn_cast<CallInst>(U)) {
2063
- if (!CI->isIndirectCall())
2064
- deduceOperandElementTypeCalledFunction(CI, Ops, ElemTy);
2065
- else if (HaveFunPtrs)
2066
- deduceOperandElementTypeFunctionPointer(CI, Ops, ElemTy, false);
2067
- }
2068
- }
2069
- */
2070
- /*
2071
- if (HaveFunPtrs) {
2072
- for (User *U : Arg->users()) {
2073
- CallInst *CI = dyn_cast<CallInst>(U);
2074
- if (CI && !isa<IntrinsicInst>(CI) && CI->isIndirectCall() &&
2075
- CI->getCalledOperand() == Arg &&
2076
- CI->getParent()->getParent() == CurrF) {
2077
- SmallVector<std::pair<Value *, unsigned>> Ops;
2078
- deduceOperandElementTypeFunctionPointer(CI, Ops, ElemTy, false);
2079
- if (ElemTy) {
2080
- buildAssignPtr(B, ElemTy, Arg);
2081
- break;
2082
- }
2083
- }
2084
- }
2085
- }
2086
- */
2087
1968
}
2088
1969
}
2089
1970
@@ -2295,14 +2176,6 @@ bool SPIRVEmitIntrinsics::postprocessTypes(Module &M) {
2295
2176
}
2296
2177
eraseTodoType (Op);
2297
2178
continue ;
2298
- /*
2299
- if (mayUpdateOpType(CI)) {
2300
- updateAssignType(AssignCI, CI, PoisonValue::get(ElemTy));
2301
- propagateElemType(CI, KnownTy);
2302
- } else {
2303
- propagateElemType(CI, ElemTy);
2304
- }
2305
- */
2306
2179
}
2307
2180
}
2308
2181
}
@@ -2355,16 +2228,7 @@ bool SPIRVEmitIntrinsics::runOnModule(Module &M) {
2355
2228
2356
2229
if (HaveFunPtrs)
2357
2230
Changed |= processFunctionPointers (M);
2358
- /*
2359
- TodoType.clear();
2360
- TodoTypeSz = 0;
2361
- std::unordered_set<Value *> Visited;
2362
- for (auto &F : M) {
2363
- CurrF = &F;
2364
- for (auto &I : instructions(F))
2365
- deduceOperandElementType(&I, nullptr, true);
2366
- }
2367
- */
2231
+
2368
2232
return Changed;
2369
2233
}
2370
2234
0 commit comments