Skip to content

Commit a2f92f5

Browse files
clean comments; add TODOs
1 parent 9052572 commit a2f92f5

File tree

1 file changed

+9
-145
lines changed

1 file changed

+9
-145
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 9 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ inline MetadataAsValue *buildMD(Value *Arg) {
6262
Ctx, MDNode::get(Ctx, ValueAsMetadata::getConstant(Arg)));
6363
}
6464

65-
inline bool mayUpdateOpType(Value *Op) {
66-
return !(isa<CallInst>(Op) || isa<GetElementPtrInst>(Op));
67-
}
68-
6965
class SPIRVEmitIntrinsics
7066
: public ModulePass,
7167
public InstVisitor<SPIRVEmitIntrinsics, Instruction *> {
@@ -101,11 +97,6 @@ class SPIRVEmitIntrinsics
10197
auto It = TodoType.find(Op);
10298
return It != TodoType.end() && It->second;
10399
}
104-
// bool mayUpdateOpType(Value *Op) {
105-
// if (isa<CallInst>(Op) || isa<GetElementPtrInst>(Op))
106-
// return false;
107-
// return isTodoType(Op);
108-
// }
109100

110101
// well known result types of builtins
111102
enum WellKnownTypes { Event };
@@ -408,7 +399,6 @@ void SPIRVEmitIntrinsics::buildAssignPtr(IRBuilder<> &B, Type *ElemTy,
408399
GR->addDeducedElementType(Arg, ElemTy);
409400
GR->addAssignPtrTypeInstr(Arg, AssignPtrTyCI);
410401
} else {
411-
assert(mayUpdateOpType(Arg) || "Forbidden to update assigned type");
412402
updateAssignType(AssignPtrTyCI, Arg, OfType);
413403
}
414404
}
@@ -695,12 +685,6 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
695685
Visited, UnknownElemTypeI8);
696686
else if (Type *KnownRetTy = GR->findDeducedElementType(CalledF))
697687
Ty = KnownRetTy;
698-
/*
699-
else {
700-
Ty = IntegerType::getInt8Ty(I->getContext());
701-
insertTodoType(I);
702-
}
703-
*/
704688
}
705689
}
706690

@@ -950,8 +934,7 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
950934
Uncomplete = isTodoType(I);
951935
Ops.push_back(std::make_pair(Ref->getPointerOperand(), 0));
952936
} 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
955938
if (GR->findDeducedElementType(Ref->getPointerOperand()))
956939
return;
957940
KnownElemTy = Ref->getSourceElementType();
@@ -967,11 +950,8 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
967950
Ops.push_back(std::make_pair(Ref->getPointerOperand(),
968951
LoadInst::getPointerOperandIndex()));
969952
} else if (auto *Ref = dyn_cast<StoreInst>(I)) {
970-
// if (IsKernelArgInt8(Ref->getParent()->getParent(), Ref))
971-
// return;
972953
if (!(KnownElemTy =
973-
reconstructType(Ref->getValueOperand(),
974-
false /*UnknownElemTypeI8*/, IsPostprocessing)))
954+
reconstructType(Ref->getValueOperand(), false, IsPostprocessing)))
975955
return;
976956
Type *PointeeTy = GR->findDeducedElementType(Ref->getPointerOperand());
977957
if (PointeeTy && !isUntypedPointerTy(PointeeTy))
@@ -1076,8 +1056,7 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
10761056
continue;
10771057
Value *OpTyVal = PoisonValue::get(KnownElemTy);
10781058
Type *OpTy = Op->getType();
1079-
if ( // mayUpdateOpType(Op) &&
1080-
(!Ty || AskTy || isUntypedPointerTy(Ty) || isTodoType(Op))) {
1059+
if (!Ty || AskTy || isUntypedPointerTy(Ty) || isTodoType(Op)) {
10811060
GR->addDeducedElementType(Op, KnownElemTy);
10821061
// check if KnownElemTy is complete
10831062
if (!Uncomplete)
@@ -1344,7 +1323,6 @@ void SPIRVEmitIntrinsics::insertAssignPtrTypeTargetExt(
13441323

13451324
// Our previous guess about the type seems to be wrong, let's update
13461325
// inferred type according to a new, more precise type information.
1347-
assert(mayUpdateOpType(V) || "Forbidden to update assigned type");
13481326
updateAssignType(AssignCI, V, PoisonValue::get(AssignedType));
13491327
}
13501328

@@ -1409,7 +1387,7 @@ void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast(
14091387
return;
14101388
} else if (isTodoType(Pointer)) {
14111389
eraseTodoType(Pointer);
1412-
if (mayUpdateOpType(Pointer)) {
1390+
if (!isa<CallInst>(Pointer) && !isa<GetElementPtrInst>(Pointer)) {
14131391
// If this wouldn't be the first spv_ptrcast but existing type info is
14141392
// uncomplete, update spv_assign_ptr_type arguments.
14151393
if (CallInst *AssignCI = GR->findAssignPtrTypeInstr(Pointer)) {
@@ -1431,7 +1409,6 @@ void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast(
14311409
I->setOperand(OperandToReplace, PtrCastI);
14321410
// We need to set up a pointee type for the newly created spv_ptrcast.
14331411
buildAssignPtr(B, ExpectedElementType, PtrCastI);
1434-
//propagateElemType(Pointer, ExpectedElementType);
14351412
}
14361413

14371414
void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
@@ -1455,8 +1432,8 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
14551432
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
14561433
Value *Pointer = LI->getPointerOperand();
14571434
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>
14601437
if (Type *ElemTy = GR->findDeducedElementType(LI)) {
14611438
OpTy = getTypedPointerWrapper(ElemTy, PtrTy->getAddressSpace());
14621439
} else {
@@ -1468,24 +1445,6 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
14681445
}
14691446
return replacePointerOperandWithPtrCast(I, Pointer, OpTy, 0, B);
14701447
} 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-
*/
14891448
Value *Pointer = GEPI->getPointerOperand();
14901449
Type *OpTy = GEPI->getSourceElementType();
14911450
replacePointerOperandWithPtrCast(I, Pointer, OpTy, 0, B);
@@ -1494,7 +1453,7 @@ void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,
14941453
return;
14951454
}
14961455

1497-
// TODO: review and maybe merge with existing logics the following ...:
1456+
// TODO: review and merge with existing logics:
14981457
// Handle calls to builtins (non-intrinsics):
14991458
CallInst *CI = dyn_cast<CallInst>(I);
15001459
if (!CI || CI->isIndirectCall() || CI->isInlineAsm() ||
@@ -1796,53 +1755,7 @@ void SPIRVEmitIntrinsics::insertAssignTypeIntrs(Instruction *I,
17961755
}
17971756
}
17981757
}
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+
}
18461759

18471760
Type *Ty = I->getType();
18481761
if (!IsKnown && !Ty->isVoidTy() && !isPointerTy(Ty) && requireAssignType(I)) {
@@ -2037,11 +1950,6 @@ void SPIRVEmitIntrinsics::processParamTypesByFunHeader(Function *F,
20371950
buildAssignPtr(B, ElemTy, Arg);
20381951
continue;
20391952
}
2040-
// ElemTy = deduceFunParamElementType(F, OpIdx);
2041-
// if (ElemTy) {
2042-
// buildAssignPtr(B, ElemTy, Arg);
2043-
// continue;
2044-
// }
20451953
if (HaveFunPtrs) {
20461954
for (User *U : Arg->users()) {
20471955
CallInst *CI = dyn_cast<CallInst>(U);
@@ -2057,33 +1965,6 @@ void SPIRVEmitIntrinsics::processParamTypesByFunHeader(Function *F,
20571965
}
20581966
}
20591967
}
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-
*/
20871968
}
20881969
}
20891970

@@ -2295,14 +2176,6 @@ bool SPIRVEmitIntrinsics::postprocessTypes(Module &M) {
22952176
}
22962177
eraseTodoType(Op);
22972178
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-
*/
23062179
}
23072180
}
23082181
}
@@ -2355,16 +2228,7 @@ bool SPIRVEmitIntrinsics::runOnModule(Module &M) {
23552228

23562229
if (HaveFunPtrs)
23572230
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+
23682232
return Changed;
23692233
}
23702234

0 commit comments

Comments
 (0)