Skip to content

Commit e4737aa

Browse files
committed
Iterate over uses of GlobalVariable instead of all instructions
1 parent cfe1cf9 commit e4737aa

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,19 @@ class CoalesceFeaturesAndStripAtomics final : public ModulePass {
289289

290290
bool stripThreadLocals(Module &M) {
291291
bool Stripped = false;
292-
for (auto &F : M) {
293-
for (auto &B : F) {
294-
for (auto &I : make_early_inc_range(B)) {
295-
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I)) {
296-
if (II->getIntrinsicID() == Intrinsic::threadlocal_address) {
297-
II->replaceAllUsesWith(II->getArgOperand(0));
292+
for (auto &GV : M.globals()) {
293+
if (GV.isThreadLocal()) {
294+
// replace `@llvm.threadlocal.address.pX(GV)` with `GV`.
295+
for (Use &U : make_early_inc_range(GV.uses())) {
296+
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U.getUser())) {
297+
if (II->getIntrinsicID() == Intrinsic::threadlocal_address &&
298+
II->getArgOperand(0) == &GV) {
299+
II->replaceAllUsesWith(&GV);
298300
II->eraseFromParent();
299-
Stripped = true;
300301
}
301302
}
302303
}
303-
}
304-
}
305-
for (auto &GV : M.globals()) {
306-
if (GV.isThreadLocal()) {
304+
307305
Stripped = true;
308306
GV.setThreadLocal(false);
309307
}

0 commit comments

Comments
 (0)