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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 05:52:41 PST 2023


================
@@ -36,22 +40,41 @@ 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);
+
+  if (!Changed)
+    return PreservedAnalyses::all();
+  PreservedAnalyses PA = PreservedAnalyses::all();
+  PA.abandon<GlobalsAA>();
+  PA.abandon<ModuleSummaryIndexAnalysis>();
+  PA.abandon<StackSafetyGlobalAnalysis>();
----------------
arsenm wrote:

Doing it this direction is potentially hazardous as new module analyses are added

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


More information about the llvm-commits mailing list