[llvm] a35b728 - [IR] Change maybeSetDSOLocal to isImplicitDSOLocal

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 16 13:14:42 PST 2020


Author: Fangrui Song
Date: 2020-02-16T13:14:15-08:00
New Revision: a35b7288b13855c49c625830fe0e2a13d4e9a9e5

URL: https://github.com/llvm/llvm-project/commit/a35b7288b13855c49c625830fe0e2a13d4e9a9e5
DIFF: https://github.com/llvm/llvm-project/commit/a35b7288b13855c49c625830fe0e2a13d4e9a9e5.diff

LOG: [IR] Change maybeSetDSOLocal to isImplicitDSOLocal

This allows some simplification.

Added: 
    

Modified: 
    llvm/include/llvm/IR/GlobalValue.h
    llvm/lib/IR/AsmWriter.cpp
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index 89adf5e5cee4..398eca2d9b2e 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -146,12 +146,6 @@ class GlobalValue : public Constant {
     llvm_unreachable("Fully covered switch above!");
   }
 
-  void maybeSetDsoLocal() {
-    if (hasLocalLinkage() ||
-        (!hasDefaultVisibility() && !hasExternalWeakLinkage()))
-      setDSOLocal(true);
-  }
-
 protected:
   /// The intrinsic ID for this subclass (which must be a Function).
   ///
@@ -243,7 +237,8 @@ class GlobalValue : public Constant {
     assert((!hasLocalLinkage() || V == DefaultVisibility) &&
            "local linkage requires default visibility");
     Visibility = V;
-    maybeSetDsoLocal();
+    if (isImplicitDSOLocal())
+      setDSOLocal(true);
   }
 
   /// If the value is "Thread Local", its value isn't shared by the threads.
@@ -278,6 +273,11 @@ class GlobalValue : public Constant {
 
   Type *getValueType() const { return ValueType; }
 
+  bool isImplicitDSOLocal() const {
+    return hasLocalLinkage() ||
+           (!hasDefaultVisibility() && !hasExternalWeakLinkage());
+  }
+
   void setDSOLocal(bool Local) { IsDSOLocal = Local; }
 
   bool isDSOLocal() const {
@@ -455,7 +455,8 @@ class GlobalValue : public Constant {
     if (isLocalLinkage(LT))
       Visibility = DefaultVisibility;
     Linkage = LT;
-    maybeSetDsoLocal();
+    if (isImplicitDSOLocal())
+      setDSOLocal(true);
   }
   LinkageTypes getLinkage() const { return LinkageTypes(Linkage); }
 

diff  --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 1a3043b9da08..ac30dd10e45f 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -3210,11 +3210,7 @@ static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
 
 static void PrintDSOLocation(const GlobalValue &GV,
                              formatted_raw_ostream &Out) {
-  // GVs with local linkage or non default visibility are implicitly dso_local,
-  // so we don't print it.
-  bool Implicit = GV.hasLocalLinkage() ||
-                  (!GV.hasExternalWeakLinkage() && !GV.hasDefaultVisibility());
-  if (GV.isDSOLocal() && !Implicit)
+  if (GV.isDSOLocal() && !GV.isImplicitDSOLocal())
     Out << "dso_local ";
 }
 

diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 6062baa70dee..cf8e73f30225 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -590,15 +590,12 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
            "Global is marked as dllimport, but not external", &GV);
   }
 
-  if (GV.hasLocalLinkage())
+  if (GV.isImplicitDSOLocal())
     Assert(GV.isDSOLocal(),
-           "GlobalValue with private or internal linkage must be dso_local!",
+           "GlobalValue with local linkage or non-default "
+           "visibility must be dso_local!",
            &GV);
 
-  if (!GV.hasDefaultVisibility() && !GV.hasExternalWeakLinkage())
-    Assert(GV.isDSOLocal(),
-           "GlobalValue with non default visibility must be dso_local!", &GV);
-
   forEachUser(&GV, GlobalValueVisited, [&](const Value *V) -> bool {
     if (const Instruction *I = dyn_cast<Instruction>(V)) {
       if (!I->getParent() || !I->getParent()->getParent())


        


More information about the llvm-commits mailing list