summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2016-04-17 18:42:27 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2016-04-17 18:42:27 +0000
commit3c1c9875b9749e4e644b7fd783993a1c74a006f9 (patch)
treeb8f44deca31fc0651ba6ea4f1f7f7a9f91c22d09
parentd7c560e16675ccbd115df501b982f1d317b79861 (diff)
downloadbcm5719-llvm-3c1c9875b9749e4e644b7fd783993a1c74a006f9.tar.gz
bcm5719-llvm-3c1c9875b9749e4e644b7fd783993a1c74a006f9.zip
Keep only the splitCodegen version that takes a factory.
This makes it much easier to see that all created TargetMachines are equivalent. llvm-svn: 266564
-rw-r--r--llvm/include/llvm/CodeGen/ParallelCG.h24
-rw-r--r--llvm/include/llvm/LTO/LTOCodeGenerator.h3
-rw-r--r--llvm/lib/CodeGen/ParallelCG.cpp19
-rw-r--r--llvm/lib/LTO/LTOCodeGenerator.cpp22
-rw-r--r--llvm/tools/gold/gold-plugin.cpp33
5 files changed, 40 insertions, 61 deletions
diff --git a/llvm/include/llvm/CodeGen/ParallelCG.h b/llvm/include/llvm/CodeGen/ParallelCG.h
index 9f913d0e86d..47e4614bd68 100644
--- a/llvm/include/llvm/CodeGen/ParallelCG.h
+++ b/llvm/include/llvm/CodeGen/ParallelCG.h
@@ -26,10 +26,11 @@ class Module;
class TargetOptions;
class raw_pwrite_stream;
-/// Split M into OSs.size() partitions, and generate code for each. Writes
-/// OSs.size() output files to the output streams in OSs. The resulting output
-/// files if linked together are intended to be equivalent to the single output
-/// file that would have been code generated from M.
+/// Split M into OSs.size() partitions, and generate code for each. Takes a
+/// factory function for the TargetMachine TMFactory. Writes OSs.size() output
+/// files to the output streams in OSs. The resulting output files if linked
+/// together are intended to be equivalent to the single output file that would
+/// have been code generated from M.
///
/// Writes bitcode for individual partitions into output streams in BCOSs, if
/// BCOSs is not empty.
@@ -37,21 +38,6 @@ class raw_pwrite_stream;
/// \returns M if OSs.size() == 1, otherwise returns std::unique_ptr<Module>().
std::unique_ptr<Module>
splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
- ArrayRef<llvm::raw_pwrite_stream *> BCOSs, StringRef CPU,
- StringRef Features, const TargetOptions &Options,
- Reloc::Model RM = Reloc::Default,
- CodeModel::Model CM = CodeModel::Default,
- CodeGenOpt::Level OL = CodeGenOpt::Default,
- TargetMachine::CodeGenFileType FT = TargetMachine::CGFT_ObjectFile,
- bool PreserveLocals = false);
-
-/// Split M into OSs.size() partitions, and generate code for each.
-/// It is a variant that takes a factory function for the TargetMachine
-/// TMFactory. See the other splitCodeGen() for a more detailed description.
-///
-/// \returns M if OSs.size() == 1, otherwise returns std::unique_ptr<Module>().
-std::unique_ptr<Module>
-splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
TargetMachine::CodeGenFileType FT = TargetMachine::CGFT_ObjectFile,
diff --git a/llvm/include/llvm/LTO/LTOCodeGenerator.h b/llvm/include/llvm/LTO/LTOCodeGenerator.h
index a3b3fd7fa0d..0791e39e745 100644
--- a/llvm/include/llvm/LTO/LTOCodeGenerator.h
+++ b/llvm/include/llvm/LTO/LTOCodeGenerator.h
@@ -175,6 +175,7 @@ private:
void restoreLinkageForExternals();
void applyScopeRestrictions();
bool determineTarget();
+ std::unique_ptr<TargetMachine> createTargetMachine();
static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context);
@@ -199,6 +200,8 @@ private:
std::string NativeObjectPath;
TargetOptions Options;
CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
+ const Target *MArch = nullptr;
+ std::string TripleStr;
unsigned OptLevel = 2;
lto_diagnostic_handler_t DiagHandler = nullptr;
void *DiagContext = nullptr;
diff --git a/llvm/lib/CodeGen/ParallelCG.cpp b/llvm/lib/CodeGen/ParallelCG.cpp
index e431acd6400..42096f06fe2 100644
--- a/llvm/lib/CodeGen/ParallelCG.cpp
+++ b/llvm/lib/CodeGen/ParallelCG.cpp
@@ -36,25 +36,6 @@ codegen(Module *M, llvm::raw_pwrite_stream &OS,
CodeGenPasses.run(*M);
}
-std::unique_ptr<Module>
-llvm::splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
- ArrayRef<llvm::raw_pwrite_stream *> BCOSs, StringRef CPU,
- StringRef Features, const TargetOptions &Options,
- Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL,
- TargetMachine::CodeGenFileType FileType,
- bool PreserveLocals) {
- std::string TripleStr = M->getTargetTriple();
- std::string ErrMsg;
-
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
- if (!TheTarget)
- report_fatal_error(Twine("Target not found: ") + ErrMsg);
- return splitCodeGen(std::move(M), OSs, BCOSs, [&]() {
- return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
- TripleStr, CPU, Features, Options, RM, CM, OL));
- }, FileType, PreserveLocals);
-}
-
std::unique_ptr<Module> llvm::splitCodeGen(
std::unique_ptr<Module> M, ArrayRef<llvm::raw_pwrite_stream *> OSs,
ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 4f779d4390b..a1d4d7bd101 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -299,7 +299,7 @@ bool LTOCodeGenerator::determineTarget() {
if (TargetMach)
return true;
- std::string TripleStr = MergedModule->getTargetTriple();
+ TripleStr = MergedModule->getTargetTriple();
if (TripleStr.empty()) {
TripleStr = sys::getDefaultTargetTriple();
MergedModule->setTargetTriple(TripleStr);
@@ -308,8 +308,8 @@ bool LTOCodeGenerator::determineTarget() {
// create target machine from info for merged modules
std::string ErrMsg;
- const Target *march = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
- if (!march) {
+ MArch = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
+ if (!MArch) {
emitError(ErrMsg);
return false;
}
@@ -329,12 +329,16 @@ bool LTOCodeGenerator::determineTarget() {
MCpu = "cyclone";
}
- TargetMach.reset(march->createTargetMachine(TripleStr, MCpu, FeatureStr,
- Options, RelocModel,
- CodeModel::Default, CGOptLevel));
+ TargetMach = createTargetMachine();
return true;
}
+std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() {
+ return std::unique_ptr<TargetMachine>(
+ MArch->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
+ RelocModel, CodeModel::Default, CGOptLevel));
+}
+
void LTOCodeGenerator::applyScopeRestrictions() {
if (ScopeRestrictionsDone || !ShouldInternalize)
return;
@@ -473,9 +477,9 @@ bool LTOCodeGenerator::compileOptimized(ArrayRef<raw_pwrite_stream *> Out) {
// parallelism level 1. This is achieved by having splitCodeGen return the
// original module at parallelism level 1 which we then assign back to
// MergedModule.
- MergedModule = splitCodeGen(
- std::move(MergedModule), Out, {}, MCpu, FeatureStr, Options, RelocModel,
- CodeModel::Default, CGOptLevel, FileType, ShouldRestoreGlobalsLinkage);
+ MergedModule = splitCodeGen(std::move(MergedModule), Out, {},
+ [&]() { return createTargetMachine(); }, FileType,
+ ShouldRestoreGlobalsLinkage);
// If statistics were requested, print them out after codegen.
if (llvm::AreStatisticsEnabled())
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 15a70a22dc6..a93fc930d58 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -879,10 +879,16 @@ public:
void runCodegenPasses();
private:
+ const Target *TheTarget;
+ std::string FeaturesString;
+ TargetOptions Options;
+
/// Create a target machine for the module. Must be unique for each
/// module/task.
void initTargetMachine();
+ std::unique_ptr<TargetMachine> createTargetMachine();
+
/// Run all LTO passes on the module.
void runLTOPasses();
@@ -921,16 +927,23 @@ void CodeGen::initTargetMachine() {
Triple TheTriple(TripleStr);
std::string ErrMsg;
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
+ TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
if (!TheTarget)
message(LDPL_FATAL, "Target not found: %s", ErrMsg.c_str());
SubtargetFeatures Features = getFeatures(TheTriple);
- TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
+ FeaturesString = Features.getString();
+ Options = InitTargetOptionsFromCodeGenFlags();
+
+ TM = createTargetMachine();
+}
+
+std::unique_ptr<TargetMachine> CodeGen::createTargetMachine() {
+ const std::string &TripleStr = M->getTargetTriple();
CodeGenOpt::Level CGOptLevel = getCGOptLevel();
- TM.reset(TheTarget->createTargetMachine(
- TripleStr, options::mcpu, Features.getString(), Options, RelocationModel,
+ return std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
+ TripleStr, options::mcpu, FeaturesString, Options, RelocationModel,
CodeModel::Default, CGOptLevel));
}
@@ -990,14 +1003,6 @@ void CodeGen::runCodegenPasses() {
}
void CodeGen::runSplitCodeGen(const SmallString<128> &BCFilename) {
- const std::string &TripleStr = M->getTargetTriple();
- Triple TheTriple(TripleStr);
-
- SubtargetFeatures Features = getFeatures(TheTriple);
-
- TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
- CodeGenOpt::Level CGOptLevel = getCGOptLevel();
-
SmallString<128> Filename;
// Note that openOutputFile will append a unique ID for each task
if (!options::obj_path.empty())
@@ -1038,8 +1043,8 @@ void CodeGen::runSplitCodeGen(const SmallString<128> &BCFilename) {
}
// Run backend tasks.
- splitCodeGen(std::move(M), OSPtrs, BCOSPtrs, options::mcpu, Features.getString(),
- Options, RelocationModel, CodeModel::Default, CGOptLevel);
+ splitCodeGen(std::move(M), OSPtrs, BCOSPtrs,
+ [&]() { return createTargetMachine(); });
}
for (auto &Filename : Filenames)
OpenPOWER on IntegriCloud