aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/CodeGen/LowerEmuTLS.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/LowerEmuTLS.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/CodeGen/LowerEmuTLS.cpp53
1 files changed, 38 insertions, 15 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/LowerEmuTLS.cpp b/contrib/llvm-project/llvm/lib/CodeGen/LowerEmuTLS.cpp
index f3b5069d351b..af0b0a20c856 100644
--- a/contrib/llvm-project/llvm/lib/CodeGen/LowerEmuTLS.cpp
+++ b/contrib/llvm-project/llvm/lib/CodeGen/LowerEmuTLS.cpp
@@ -13,7 +13,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/LowerEmuTLS.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/GlobalsModRef.h"
+#include "llvm/Analysis/ModuleSummaryAnalysis.h"
+#include "llvm/Analysis/StackSafetyAnalysis.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/Constants.h"
@@ -24,7 +28,7 @@
using namespace llvm;
-#define DEBUG_TYPE "loweremutls"
+#define DEBUG_TYPE "lower-emutls"
namespace {
@@ -36,22 +40,41 @@ public:
}
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>();
+ return PA;
+}
+
char LowerEmuTLS::ID = 0;
INITIALIZE_PASS(LowerEmuTLS, DEBUG_TYPE,
@@ -83,7 +106,7 @@ bool LowerEmuTLS::runOnModule(Module &M) {
return Changed;
}
-bool LowerEmuTLS::addEmuTlsVar(Module &M, const GlobalVariable *GV) {
+bool addEmuTlsVar(Module &M, const GlobalVariable *GV) {
LLVMContext &C = M.getContext();
PointerType *VoidPtrType = PointerType::getUnqual(C);