summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenAction.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2017-03-13 18:08:11 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2017-03-13 18:08:11 +0000
commit5eb9c81d828090dd597fb1ae8789b32d4ac66bb3 (patch)
treef650f8d540844fe7ccc6e9ef2e5652edbdb71ac6 /clang/lib/CodeGen/CodeGenAction.cpp
parent13a3af19318cd010aa1cfc276298e2772240594a (diff)
downloadbcm5719-llvm-5eb9c81d828090dd597fb1ae8789b32d4ac66bb3.tar.gz
bcm5719-llvm-5eb9c81d828090dd597fb1ae8789b32d4ac66bb3.zip
[Linker] Provide callback for internalization
Differential Revision: https://reviews.llvm.org/D30738 llvm-svn: 297649
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index c7604145619..20a61f33f94 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -28,6 +28,7 @@
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
@@ -38,6 +39,8 @@
#include "llvm/Support/Timer.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Transforms/IPO/Internalize.h"
+
#include <memory>
using namespace clang;
using namespace llvm;
@@ -168,8 +171,22 @@ namespace clang {
Gen->CGM().AddDefaultFnAttrs(F);
CurLinkModule = LM.Module.get();
- if (Linker::linkModules(*getModule(), std::move(LM.Module),
- LM.LinkFlags))
+
+ bool Err;
+ if (LM.Internalize) {
+ Err = Linker::linkModules(
+ *getModule(), std::move(LM.Module), LM.LinkFlags,
+ [](llvm::Module &M, const llvm::StringSet<> &GVS) {
+ internalizeModule(M, [&M, &GVS](const llvm::GlobalValue &GV) {
+ return !GV.hasName() || (GVS.count(GV.getName()) == 0);
+ });
+ });
+ } else {
+ Err = Linker::linkModules(*getModule(), std::move(LM.Module),
+ LM.LinkFlags);
+ }
+
+ if (Err)
return true;
}
return false; // success
@@ -319,7 +336,7 @@ namespace clang {
void OptimizationFailureHandler(
const llvm::DiagnosticInfoOptimizationFailure &D);
};
-
+
void BackendConsumer::anchor() {}
}
@@ -388,7 +405,7 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
// code.
if (LocCookie.isValid()) {
Diags.Report(LocCookie, DiagID).AddString(Message);
-
+
if (D.getLoc().isValid()) {
DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here);
// Convert the SMDiagnostic ranges into SourceRange and attach them
@@ -401,7 +418,7 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
}
return;
}
-
+
// Otherwise, report the backend issue as occurring in the generated .s file.
// If Loc is invalid, we still need to report the issue, it just gets no
// location info.
@@ -815,8 +832,8 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
LinkModules.clear();
return nullptr;
}
- LinkModules.push_back(
- {std::move(ModuleOrErr.get()), F.PropagateAttrs, F.LinkFlags});
+ LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
+ F.Internalize, F.LinkFlags});
}
CoverageSourceInfo *CoverageInfo = nullptr;
OpenPOWER on IntegriCloud