Remove redundant calls to isMaterializable.
authorRafael Espindola <rafael.espindola@gmail.com>
Sat, 1 Nov 2014 16:46:18 +0000 (16:46 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sat, 1 Nov 2014 16:46:18 +0000 (16:46 +0000)
This removes calls to isMaterializable in the following cases:

* It was redundant with a call to isDeclaration now that isDeclaration returns
  the correct answer for materializable functions.
* It was followed by a call to Materialize. Just call Materialize and check EC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221050 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
lib/IR/LegacyPassManager.cpp
lib/IR/Verifier.cpp
lib/Linker/LinkModules.cpp
lib/Target/AArch64/AArch64Subtarget.cpp
lib/Target/ARM/ARMSubtarget.cpp
lib/Target/PowerPC/PPCSubtarget.cpp
lib/Target/X86/X86Subtarget.cpp
tools/gold/gold-plugin.cpp
tools/llvm-extract/llvm-extract.cpp

index 164f49633940dc1658b6191bf89a9b027160980d..9e20ba628d3f7376668a72911e4959b402cc01eb 100644 (file)
@@ -3357,10 +3357,8 @@ std::error_code BitcodeReader::MaterializeModule(Module *M) {
   // disk.
   for (Module::iterator F = TheModule->begin(), E = TheModule->end();
        F != E; ++F) {
-    if (F->isMaterializable()) {
-      if (std::error_code EC = materialize(F))
-        return EC;
-    }
+    if (std::error_code EC = materialize(F))
+      return EC;
   }
   // At this point, if there are any function bodies, the current bit is
   // pointing to the END_BLOCK record after them. Now make sure the rest
index 1081f2a1b8c27c6555a57995504aa85e4ee91cab..28fa74cbfda93973d242217ffcccc4baf25c9fac 100644 (file)
@@ -1403,10 +1403,8 @@ void FunctionPassManager::add(Pass *P) {
 /// so, return true.
 ///
 bool FunctionPassManager::run(Function &F) {
-  if (F.isMaterializable()) {
-    if (std::error_code EC = F.materialize())
-      report_fatal_error("Error reading bitcode file: " + EC.message());
-  }
+  if (std::error_code EC = F.materialize())
+    report_fatal_error("Error reading bitcode file: " + EC.message());
   return FPM->run(F);
 }
 
index e2fb62fdeef76e9f4f066a2dd4656ededc887505..1c54e9b062e466ac1df5baa010b4d49678387a9d 100644 (file)
@@ -377,8 +377,8 @@ void Verifier::visit(Instruction &I) {
 
 
 void Verifier::visitGlobalValue(const GlobalValue &GV) {
-  Assert1(!GV.isDeclaration() || GV.isMaterializable() ||
-              GV.hasExternalLinkage() || GV.hasExternalWeakLinkage(),
+  Assert1(!GV.isDeclaration() || GV.hasExternalLinkage() ||
+              GV.hasExternalWeakLinkage(),
           "Global is external, but doesn't have external or weak linkage!",
           &GV);
 
index 94d93ca4a46c774ad507b50b644313ab91332b8a..3e8eb25999f966080491c90bdb36df267df83569 100644 (file)
@@ -1517,10 +1517,8 @@ bool ModuleLinker::run() {
     }
 
     // Materialize if needed.
-    if (SF->isMaterializable()) {
-      if (std::error_code EC = SF->materialize())
-        return emitError(EC.message());
-    }
+    if (std::error_code EC = SF->materialize())
+      return emitError(EC.message());
 
     // Skip if no body (function is external).
     if (SF->isDeclaration())
@@ -1568,10 +1566,8 @@ bool ModuleLinker::run() {
       }
 
       // Materialize if needed.
-      if (SF->isMaterializable()) {
-        if (std::error_code EC = SF->materialize())
-          return emitError(EC.message());
-      }
+      if (std::error_code EC = SF->materialize())
+        return emitError(EC.message());
 
       // Skip if no body (function is external).
       if (SF->isDeclaration())
index 4ccd57661cbe1bbd240ca3781fd77a5efb7c07ef..47b5d546955f80d4847f4ce4aaf60b2ac4030845 100644 (file)
@@ -65,13 +65,7 @@ AArch64Subtarget::AArch64Subtarget(const std::string &TT,
 unsigned char
 AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
                                         const TargetMachine &TM) const {
-
-  // Determine whether this is a reference to a definition or a declaration.
-  // Materializable GVs (in JIT lazy compilation mode) do not require an extra
-  // load from stub.
-  bool isDecl = GV->hasAvailableExternallyLinkage();
-  if (GV->isDeclaration() && !GV->isMaterializable())
-    isDecl = true;
+  bool isDecl = GV->isDeclarationForLinker();
 
   // MachO large model always goes via a GOT, simply to get a single 8-byte
   // absolute relocation on all global addresses.
index df17e7590d9ea2d6e761b67ef3ad30b93dad978f..e53cef17140fc0e0b8465b630358a4e477f30e8c 100644 (file)
@@ -337,11 +337,7 @@ ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
   if (RelocM == Reloc::Static)
     return false;
 
-  // Materializable GVs (in JIT lazy compilation mode) do not require an extra
-  // load from stub.
-  bool isDecl = GV->hasAvailableExternallyLinkage();
-  if (GV->isDeclaration() && !GV->isMaterializable())
-    isDecl = true;
+  bool isDecl = GV->isDeclarationForLinker();
 
   if (!isTargetMachO()) {
     // Extra load is needed for all externally visible.
index d6b964d372c84f9f36d2f5d6e785cc960c4e0bb7..04e7ec66e5bda694cc78fcc6914bf20be040a3b6 100644 (file)
@@ -180,9 +180,7 @@ bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV,
   // We never have stubs if HasLazyResolverStubs=false or if in static mode.
   if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static)
     return false;
-  // If symbol visibility is hidden, the extra load is not needed if
-  // the symbol is definitely defined in the current translation unit.
-  bool isDecl = GV->isDeclaration() && !GV->isMaterializable();
+  bool isDecl = GV->isDeclaration();
   if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage())
     return false;
   return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
index 82d62b4a365e5aeaf57093a49aa40f6ef435302f..6d55b84e738c3380974f7630ef9eddf756ceeab1 100644 (file)
@@ -68,12 +68,7 @@ ClassifyGlobalReference(const GlobalValue *GV, const TargetMachine &TM) const {
   if (GV->hasDLLImportStorageClass())
     return X86II::MO_DLLIMPORT;
 
-  // Determine whether this is a reference to a definition or a declaration.
-  // Materializable GVs (in JIT lazy compilation mode) do not require an extra
-  // load from stub.
-  bool isDecl = GV->hasAvailableExternallyLinkage();
-  if (GV->isDeclaration() && !GV->isMaterializable())
-    isDecl = true;
+  bool isDecl = GV->isDeclarationForLinker();
 
   // X86-64 in PIC mode.
   if (isPICStyleRIPRel()) {
index 25089ba418813a6272db5a1c8f5a27213a21c547..87d7a4fa0ad5d9d3bc85144a34a10444c0df802a 100644 (file)
@@ -471,10 +471,8 @@ static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
   Module *M = GO->getParent();
   GlobalObject *Ret;
   if (auto *F = dyn_cast<Function>(GO)) {
-    if (F->isMaterializable()) {
-      if (F->materialize())
-        message(LDPL_FATAL, "LLVM gold plugin has failed to read a function");
-
+    if (F->materialize())
+      message(LDPL_FATAL, "LLVM gold plugin has failed to read a function");
     }
 
     auto *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
index fe97a03c0346f9b2573e759f61e6c587031e75c5..53b2f0d00f41221c46a926330aef9349ff569bbc 100644 (file)
@@ -216,19 +216,16 @@ int main(int argc, char **argv) {
   if (!DeleteFn)
     for (size_t i = 0, e = GVs.size(); i != e; ++i) {
       GlobalValue *GV = GVs[i];
-      if (GV->isMaterializable()) {
-        if (std::error_code EC = GV->materialize()) {
-          errs() << argv[0] << ": error reading input: " << EC.message()
-                 << "\n";
-          return 1;
-        }
+      if (std::error_code EC = GV->materialize()) {
+        errs() << argv[0] << ": error reading input: " << EC.message() << "\n";
+        return 1;
       }
     }
   else {
     // Deleting. Materialize every GV that's *not* in GVs.
     SmallPtrSet<GlobalValue *, 8> GVSet(GVs.begin(), GVs.end());
     for (auto &G : M->globals()) {
-      if (!GVSet.count(&G) && G.isMaterializable()) {
+      if (!GVSet.count(&G)) {
         if (std::error_code EC = G.materialize()) {
           errs() << argv[0] << ": error reading input: " << EC.message()
                  << "\n";
@@ -237,7 +234,7 @@ int main(int argc, char **argv) {
       }
     }
     for (auto &F : *M) {
-      if (!GVSet.count(&F) && F.isMaterializable()) {
+      if (!GVSet.count(&F)) {
         if (std::error_code EC = F.materialize()) {
           errs() << argv[0] << ": error reading input: " << EC.message()
                  << "\n";