mirror of
https://github.com/RPCS3/llvm.git
synced 2025-03-01 23:25:56 +00:00
Keep only the splitCodegen version that takes a factory.
This makes it much easier to see that all created TargetMachines are equivalent. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266564 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3a804b2a6d
commit
ec86ae2bb5
include/llvm
lib
tools/gold
@ -26,31 +26,17 @@ 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.
|
||||
///
|
||||
/// \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,
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user