[llvm] r263524 - Move global ID computation from Function to GlobalValue (NFC)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 14 19:13:19 PDT 2016


Author: tejohnson
Date: Mon Mar 14 21:13:19 2016
New Revision: 263524

URL: http://llvm.org/viewvc/llvm-project?rev=263524&view=rev
Log:
Move global ID computation from Function to GlobalValue (NFC)

Since the static getGlobalIdentifier and getGUID methods are now called
for global values other than functions, reflect that by moving these
methods to the GlobalValue class.

Modified:
    llvm/trunk/include/llvm/IR/Function.h
    llvm/trunk/include/llvm/IR/GlobalValue.h
    llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/IR/Function.cpp
    llvm/trunk/lib/IR/Globals.cpp
    llvm/trunk/lib/ProfileData/InstrProf.cpp
    llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp

Modified: llvm/trunk/include/llvm/IR/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Function.h?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Function.h (original)
+++ llvm/trunk/include/llvm/IR/Function.h Mon Mar 14 21:13:19 2016
@@ -27,7 +27,6 @@
 #include "llvm/IR/GlobalObject.h"
 #include "llvm/IR/OperandTraits.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/MD5.h"
 
 namespace llvm {
 
@@ -646,20 +645,6 @@ public:
   /// to \a DISubprogram.
   DISubprogram *getSubprogram() const;
 
-  /// Return the modified name for a function suitable to be
-  /// used as the key for a global lookup (e.g. profile or ThinLTO).
-  /// The function's original name is \c FuncName and has linkage of type
-  /// \c Linkage. The function is defined in module \c FileName.
-  static std::string getGlobalIdentifier(StringRef FuncName,
-                                         GlobalValue::LinkageTypes Linkage,
-                                         StringRef FileName);
-
-  /// Return a 64-bit global unique ID constructed from global function name
-  /// (i.e. returned by getGlobalIdentifier).
-  static uint64_t getGUID(StringRef GlobalFuncName) {
-    return MD5Hash(GlobalFuncName);
-  }
-
 private:
   void allocHungoffUselist();
   template<int Idx> void setHungoffOperand(Constant *C);

Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Mon Mar 14 21:13:19 2016
@@ -20,6 +20,7 @@
 
 #include "llvm/IR/Constant.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/Support/MD5.h"
 #include <system_error>
 
 namespace llvm {
@@ -307,11 +308,24 @@ public:
     return Name;
   }
 
-/// @name Materialization
-/// Materialization is used to construct functions only as they're needed. This
-/// is useful to reduce memory usage in LLVM or parsing work done by the
-/// BitcodeReader to load the Module.
-/// @{
+  /// Return the modified name for a global value suitable to be
+  /// used as the key for a global lookup (e.g. profile or ThinLTO).
+  /// The value's original name is \c Name and has linkage of type
+  /// \c Linkage. The value is defined in module \c FileName.
+  static std::string getGlobalIdentifier(StringRef Name,
+                                         GlobalValue::LinkageTypes Linkage,
+                                         StringRef FileName);
+
+  /// Return a 64-bit global unique ID constructed from global value name
+  /// (i.e. returned by getGlobalIdentifier).
+  static uint64_t getGUID(StringRef GlobalName) { return MD5Hash(GlobalName); }
+
+  /// @name Materialization
+  /// Materialization is used to construct functions only as they're needed.
+  /// This
+  /// is useful to reduce memory usage in LLVM or parsing work done by the
+  /// BitcodeReader to load the Module.
+  /// @{
 
   /// If this function's Module is being lazily streamed in functions from disk
   /// or some other source, this method can be used to check to see if the

Modified: llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h (original)
+++ llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h Mon Mar 14 21:13:19 2016
@@ -277,13 +277,13 @@ public:
 
   /// Get the list of global value info objects for a given value name.
   const GlobalValueInfoList &getGlobalValueInfoList(StringRef ValueName) {
-    return GlobalValueMap[Function::getGUID(ValueName)];
+    return GlobalValueMap[GlobalValue::getGUID(ValueName)];
   }
 
   /// Get the list of global value info objects for a given value name.
   const const_globalvalueinfo_iterator
   findGlobalValueInfoList(StringRef ValueName) const {
-    return GlobalValueMap.find(Function::getGUID(ValueName));
+    return GlobalValueMap.find(GlobalValue::getGUID(ValueName));
   }
 
   /// Get the list of global value info objects for a given value GUID.
@@ -295,7 +295,7 @@ public:
   /// Add a global value info for a value of the given name.
   void addGlobalValueInfo(StringRef ValueName,
                           std::unique_ptr<GlobalValueInfo> Info) {
-    GlobalValueMap[Function::getGUID(ValueName)].push_back(std::move(Info));
+    GlobalValueMap[GlobalValue::getGUID(ValueName)].push_back(std::move(Info));
   }
 
   /// Add a global value info for a value of the given GUID.

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Mar 14 21:13:19 2016
@@ -5506,10 +5506,10 @@ std::error_code ModuleSummaryIndexBitcod
       auto VLI = ValueIdToLinkageMap.find(ValueID);
       assert(VLI != ValueIdToLinkageMap.end() &&
              "No linkage found for VST entry?");
-      std::string GlobalId =
-          Function::getGlobalIdentifier(ValueName, VLI->second, SourceFileName);
+      std::string GlobalId = GlobalValue::getGlobalIdentifier(
+          ValueName, VLI->second, SourceFileName);
       TheIndex->addGlobalValueInfo(GlobalId, std::move(GlobalValInfo));
-      ValueIdToCallGraphGUIDMap[ValueID] = Function::getGUID(GlobalId);
+      ValueIdToCallGraphGUIDMap[ValueID] = GlobalValue::getGUID(GlobalId);
       ValueName.clear();
       break;
     }
@@ -5526,10 +5526,11 @@ std::error_code ModuleSummaryIndexBitcod
       auto VLI = ValueIdToLinkageMap.find(ValueID);
       assert(VLI != ValueIdToLinkageMap.end() &&
              "No linkage found for VST entry?");
-      std::string FunctionGlobalId =
-          Function::getGlobalIdentifier(ValueName, VLI->second, SourceFileName);
+      std::string FunctionGlobalId = GlobalValue::getGlobalIdentifier(
+          ValueName, VLI->second, SourceFileName);
       TheIndex->addGlobalValueInfo(FunctionGlobalId, std::move(FuncInfo));
-      ValueIdToCallGraphGUIDMap[ValueID] = Function::getGUID(FunctionGlobalId);
+      ValueIdToCallGraphGUIDMap[ValueID] =
+          GlobalValue::getGUID(FunctionGlobalId);
 
       ValueName.clear();
       break;

Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Mon Mar 14 21:13:19 2016
@@ -1005,27 +1005,3 @@ Optional<uint64_t> Function::getEntryCou
       }
   return None;
 }
-
-std::string Function::getGlobalIdentifier(StringRef FuncName,
-                                          GlobalValue::LinkageTypes Linkage,
-                                          StringRef FileName) {
-
-  // Function names may be prefixed with a binary '1' to indicate
-  // that the backend should not modify the symbols due to any platform
-  // naming convention. Do not include that '1' in the PGO profile name.
-  if (FuncName[0] == '\1')
-    FuncName = FuncName.substr(1);
-
-  std::string NewFuncName = FuncName;
-  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
-    // For local symbols, prepend the main file name to distinguish them.
-    // Do not include the full path in the file name since there's no guarantee
-    // that it will stay the same, e.g., if the files are checked out from
-    // version control in different locations.
-    if (FileName.empty())
-      NewFuncName = NewFuncName.insert(0, "<unknown>:");
-    else
-      NewFuncName = NewFuncName.insert(0, FileName.str() + ":");
-  }
-  return NewFuncName;
-}

Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Mon Mar 14 21:13:19 2016
@@ -99,6 +99,30 @@ void GlobalObject::copyAttributesFrom(co
   }
 }
 
+std::string GlobalValue::getGlobalIdentifier(StringRef Name,
+                                             GlobalValue::LinkageTypes Linkage,
+                                             StringRef FileName) {
+
+  // Value names may be prefixed with a binary '1' to indicate
+  // that the backend should not modify the symbols due to any platform
+  // naming convention. Do not include that '1' in the PGO profile name.
+  if (Name[0] == '\1')
+    Name = Name.substr(1);
+
+  std::string NewName = Name;
+  if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
+    // For local symbols, prepend the main file name to distinguish them.
+    // Do not include the full path in the file name since there's no guarantee
+    // that it will stay the same, e.g., if the files are checked out from
+    // version control in different locations.
+    if (FileName.empty())
+      NewName = NewName.insert(0, "<unknown>:");
+    else
+      NewName = NewName.insert(0, FileName.str() + ":");
+  }
+  return NewName;
+}
+
 const char *GlobalValue::getSection() const {
   if (auto *GA = dyn_cast<GlobalAlias>(this)) {
     // In general we cannot compute this at the IR level, but we try.

Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Mon Mar 14 21:13:19 2016
@@ -80,7 +80,7 @@ std::string getPGOFuncName(StringRef Raw
                            GlobalValue::LinkageTypes Linkage,
                            StringRef FileName,
                            uint64_t Version LLVM_ATTRIBUTE_UNUSED) {
-  return Function::getGlobalIdentifier(RawFuncName, Linkage, FileName);
+  return GlobalValue::getGlobalIdentifier(RawFuncName, Linkage, FileName);
 }
 
 std::string getPGOFuncName(const Function &F, uint64_t Version) {

Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=263524&r1=263523&r2=263524&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Mon Mar 14 21:13:19 2016
@@ -142,7 +142,7 @@ static void findExternalCalls(
           ImportedName = Renamed;
         }
         // Compute the global identifier used in the summary index.
-        auto CalledFunctionGlobalID = Function::getGlobalIdentifier(
+        auto CalledFunctionGlobalID = GlobalValue::getGlobalIdentifier(
             CalledFunction->getName(), CalledFunction->getLinkage(),
             CalledFunction->getParent()->getSourceFileName());
 




More information about the llvm-commits mailing list