forked from OSchip/llvm-project
Revert "[LTO] Add a new splitCodeGen() API which takes a TargetMachineFactory."
This reverts commits r266390 and r266396 as they broke some bots. llvm-svn: 266408
This commit is contained in:
parent
4cd7c3b7d5
commit
2abf2e7c8c
|
@ -18,8 +18,6 @@
|
||||||
#include "llvm/Support/CodeGen.h"
|
#include "llvm/Support/CodeGen.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class Module;
|
class Module;
|
||||||
|
@ -45,19 +43,6 @@ splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
|
||||||
TargetMachine::CodeGenFileType FT = TargetMachine::CGFT_ObjectFile,
|
TargetMachine::CodeGenFileType FT = TargetMachine::CGFT_ObjectFile,
|
||||||
bool PreserveLocals = false);
|
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. TMFactory needs to be thread safe on the client side.
|
|
||||||
/// 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,
|
|
||||||
bool PreserveLocals = false);
|
|
||||||
|
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,47 +25,39 @@
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static void
|
static void codegen(Module *M, llvm::raw_pwrite_stream &OS,
|
||||||
codegen(Module *M, llvm::raw_pwrite_stream &OS,
|
const Target *TheTarget, StringRef CPU, StringRef Features,
|
||||||
const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
|
const TargetOptions &Options, Reloc::Model RM,
|
||||||
TargetMachine::CodeGenFileType FileType) {
|
CodeModel::Model CM, CodeGenOpt::Level OL,
|
||||||
std::unique_ptr<TargetMachine> TM = TMFactory();
|
TargetMachine::CodeGenFileType FileType) {
|
||||||
|
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
|
||||||
|
M->getTargetTriple(), CPU, Features, Options, RM, CM, OL));
|
||||||
|
|
||||||
legacy::PassManager CodeGenPasses;
|
legacy::PassManager CodeGenPasses;
|
||||||
if (TM->addPassesToEmitFile(CodeGenPasses, OS, FileType))
|
if (TM->addPassesToEmitFile(CodeGenPasses, OS, FileType))
|
||||||
report_fatal_error("Failed to setup codegen");
|
report_fatal_error("Failed to setup codegen");
|
||||||
CodeGenPasses.run(*M);
|
CodeGenPasses.run(*M);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Module>
|
std::unique_ptr<Module> llvm::splitCodeGen(
|
||||||
llvm::splitCodeGen(std::unique_ptr<Module> M, ArrayRef<raw_pwrite_stream *> OSs,
|
std::unique_ptr<Module> M, ArrayRef<llvm::raw_pwrite_stream *> OSs,
|
||||||
ArrayRef<llvm::raw_pwrite_stream *> BCOSs, StringRef CPU,
|
ArrayRef<llvm::raw_pwrite_stream *> BCOSs, StringRef CPU,
|
||||||
StringRef Features, const TargetOptions &Options,
|
StringRef Features, const TargetOptions &Options, Reloc::Model RM,
|
||||||
Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL,
|
CodeModel::Model CM, CodeGenOpt::Level OL,
|
||||||
TargetMachine::CodeGenFileType FileType,
|
TargetMachine::CodeGenFileType FileType, bool PreserveLocals) {
|
||||||
bool PreserveLocals) {
|
|
||||||
StringRef TripleStr = M->getTargetTriple();
|
StringRef TripleStr = M->getTargetTriple();
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
|
|
||||||
const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
|
const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
|
||||||
if (!TheTarget)
|
if (!TheTarget)
|
||||||
report_fatal_error(Twine("Target not found: ") + ErrMsg);
|
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,
|
|
||||||
const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
|
|
||||||
TargetMachine::CodeGenFileType FileType, bool PreserveLocals) {
|
|
||||||
assert(BCOSs.empty() || BCOSs.size() == OSs.size());
|
assert(BCOSs.empty() || BCOSs.size() == OSs.size());
|
||||||
|
|
||||||
if (OSs.size() == 1) {
|
if (OSs.size() == 1) {
|
||||||
if (!BCOSs.empty())
|
if (!BCOSs.empty())
|
||||||
WriteBitcodeToFile(M.get(), *BCOSs[0]);
|
WriteBitcodeToFile(M.get(), *BCOSs[0]);
|
||||||
codegen(M.get(), *OSs[0], TMFactory, FileType);
|
codegen(M.get(), *OSs[0], TheTarget, CPU, Features, Options, RM, CM, OL,
|
||||||
|
FileType);
|
||||||
return M;
|
return M;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +88,8 @@ std::unique_ptr<Module> llvm::splitCodeGen(
|
||||||
llvm::raw_pwrite_stream *ThreadOS = OSs[ThreadCount++];
|
llvm::raw_pwrite_stream *ThreadOS = OSs[ThreadCount++];
|
||||||
// Enqueue the task
|
// Enqueue the task
|
||||||
CodegenThreadPool.async(
|
CodegenThreadPool.async(
|
||||||
[&TMFactory, FileType, ThreadOS](const SmallVector<char, 0> &BC) {
|
[TheTarget, CPU, Features, Options, RM, CM, OL, FileType,
|
||||||
|
ThreadOS](const SmallVector<char, 0> &BC) {
|
||||||
LLVMContext Ctx;
|
LLVMContext Ctx;
|
||||||
ErrorOr<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
|
ErrorOr<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
|
||||||
MemoryBufferRef(StringRef(BC.data(), BC.size()),
|
MemoryBufferRef(StringRef(BC.data(), BC.size()),
|
||||||
|
@ -106,7 +99,8 @@ std::unique_ptr<Module> llvm::splitCodeGen(
|
||||||
report_fatal_error("Failed to read bitcode");
|
report_fatal_error("Failed to read bitcode");
|
||||||
std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
|
std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
|
||||||
|
|
||||||
codegen(MPartInCtx.get(), *ThreadOS, TMFactory, FileType);
|
codegen(MPartInCtx.get(), *ThreadOS, TheTarget, CPU, Features,
|
||||||
|
Options, RM, CM, OL, FileType);
|
||||||
},
|
},
|
||||||
// Pass BC using std::move to ensure that it get moved rather than
|
// Pass BC using std::move to ensure that it get moved rather than
|
||||||
// copied into the thread's context.
|
// copied into the thread's context.
|
||||||
|
|
Loading…
Reference in New Issue