Skip to content

Commit 5d47cd1

Browse files
[SYCL][NFC] Optimize SpecConstantPass (intel#2610)
Instead of checking each `CallInst` in a module it is better to find declarations of desired intrinsics and work with their users.
1 parent 551d706 commit 5d47cd1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

llvm/tools/sycl-post-link/SpecConstants.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,27 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
183183
int NextID = 0;
184184
StringMap<unsigned> IDMap;
185185

186-
// Iterate through all calls to
186+
// Iterate through all declarations of instances of function template
187187
// template <typename T> T __sycl_getSpecConstantValue(const char *ID)
188-
// intrinsic and lower them depending on the SetValAtRT setting (see below).
188+
// intrinsic to find its calls and lower them depending on the SetValAtRT
189+
// setting (see below).
189190
bool IRModified = false;
190191

191192
for (Function &F : M) {
192-
if (F.isDeclaration())
193+
if (!F.isDeclaration())
193194
continue;
194-
SmallVector<CallInst *, 32> SCIntrCalls;
195195

196-
for (Instruction &I : instructions(F)) {
197-
auto *CI = dyn_cast<CallInst>(&I);
198-
Function *Callee = nullptr;
199-
if (!CI || CI->isIndirectCall() || !(Callee = CI->getCalledFunction()))
200-
continue;
201-
StringRef Name = Callee->getName();
196+
if (!F.getName().startswith(SYCL_GET_SPEC_CONST_VAL))
197+
continue;
202198

203-
if (!Name.startswith(SYCL_GET_SPEC_CONST_VAL))
199+
SmallVector<CallInst *, 32> SCIntrCalls;
200+
for (auto *U : F.users()) {
201+
auto *CI = dyn_cast<CallInst>(U);
202+
if (!CI)
204203
continue;
205204
SCIntrCalls.push_back(CI);
206205
}
206+
207207
IRModified = IRModified || (SCIntrCalls.size() > 0);
208208

209209
for (auto *CI : SCIntrCalls) {

0 commit comments

Comments
 (0)