[llvm] [CodeGen] Port `LowerEmuTLS` to new pass manager (PR #75171)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 00:01:35 PST 2023


================
@@ -36,22 +37,34 @@ class LowerEmuTLS : public ModulePass {
   }
 
   bool runOnModule(Module &M) override;
-private:
-  bool addEmuTlsVar(Module &M, const GlobalVariable *GV);
-  static void copyLinkageVisibility(Module &M,
-                                    const GlobalVariable *from,
-                                    GlobalVariable *to) {
-    to->setLinkage(from->getLinkage());
-    to->setVisibility(from->getVisibility());
-    to->setDSOLocal(from->isDSOLocal());
-    if (from->hasComdat()) {
-      to->setComdat(M.getOrInsertComdat(to->getName()));
-      to->getComdat()->setSelectionKind(from->getComdat()->getSelectionKind());
-    }
-  }
 };
 }
 
+static bool addEmuTlsVar(Module &M, const GlobalVariable *GV);
+
+static void copyLinkageVisibility(Module &M, const GlobalVariable *from,
+                                  GlobalVariable *to) {
+  to->setLinkage(from->getLinkage());
+  to->setVisibility(from->getVisibility());
+  to->setDSOLocal(from->isDSOLocal());
+  if (from->hasComdat()) {
+    to->setComdat(M.getOrInsertComdat(to->getName()));
+    to->getComdat()->setSelectionKind(from->getComdat()->getSelectionKind());
+  }
+}
+
+PreservedAnalyses LowerEmuTLSPass::run(Module &M, ModuleAnalysisManager &MAM) {
+  bool Changed = false;
+  SmallVector<const GlobalVariable *, 8> TlsVars;
+  for (const auto &G : M.globals()) {
+    if (G.isThreadLocal())
+      TlsVars.push_back(&G);
+  }
+  for (const auto *G : TlsVars)
+    Changed |= addEmuTlsVar(M, G);
+  return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
----------------
arsenm wrote:

Should be able to preserve most analyses, in particular control flow 

https://github.com/llvm/llvm-project/pull/75171


More information about the llvm-commits mailing list