aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/tools/llc/llc.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-10 19:17:14 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-10 19:17:14 +0000
commitdb17bf38c59bc172953ed66cfe1b10c03c6bc383 (patch)
tree2712281fec99b99c2fcafd5b46439dfdd93261aa /contrib/llvm/tools/llc/llc.cpp
parent686fb94a00297bf9ff49d93b948925552a2ce8e0 (diff)
parent7ab83427af0f77b59941ceba41d509d7d097b065 (diff)
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r305145, and update
build glue.
Notes
Notes: svn path=/projects/clang500-import/; revision=319799
Diffstat (limited to 'contrib/llvm/tools/llc/llc.cpp')
-rw-r--r--contrib/llvm/tools/llc/llc.cpp97
1 files changed, 60 insertions, 37 deletions
diff --git a/contrib/llvm/tools/llc/llc.cpp b/contrib/llvm/tools/llc/llc.cpp
index e10d112dcf90..e71c3c5bb705 100644
--- a/contrib/llvm/tools/llc/llc.cpp
+++ b/contrib/llvm/tools/llc/llc.cpp
@@ -62,6 +62,9 @@ static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
static cl::opt<std::string>
+InputLanguage("x", cl::desc("Input language ('ir' or 'mir')"));
+
+static cl::opt<std::string>
OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));
static cl::opt<unsigned>
@@ -335,6 +338,12 @@ int main(int argc, char **argv) {
llvm::make_unique<yaml::Output>(YamlFile->os()));
}
+ if (InputLanguage != "" && InputLanguage != "ir" &&
+ InputLanguage != "mir") {
+ errs() << argv[0] << "Input language must be '', 'IR' or 'MIR'\n";
+ return 1;
+ }
+
// Compile the module TimeCompilations times to give better compile time
// metrics.
for (unsigned I = TimeCompilations; I; --I)
@@ -398,10 +407,11 @@ static int compileModule(char **argv, LLVMContext &Context) {
// If user just wants to list available options, skip module loading
if (!SkipModule) {
- if (StringRef(InputFilename).endswith_lower(".mir")) {
+ if (InputLanguage == "mir" ||
+ (InputLanguage == "" && StringRef(InputFilename).endswith(".mir"))) {
MIR = createMIRParserFromFile(InputFilename, Err, Context);
if (MIR)
- M = MIR->parseLLVMModule();
+ M = MIR->parseIRModule();
} else
M = parseIRFile(InputFilename, Err, Context);
if (!M) {
@@ -518,54 +528,67 @@ static int compileModule(char **argv, LLVMContext &Context) {
OS = BOS.get();
}
- if (!RunPassNames->empty()) {
- if (!StartAfter.empty() || !StopAfter.empty() || !StartBefore.empty() ||
- !StopBefore.empty()) {
- errs() << argv[0] << ": start-after and/or stop-after passes are "
- "redundant when run-pass is specified.\n";
- return 1;
- }
- if (!MIR) {
- errs() << argv[0] << ": run-pass needs a .mir input.\n";
- return 1;
- }
+ const char *argv0 = argv[0];
+ AnalysisID StartBeforeID = getPassID(argv0, "start-before", StartBefore);
+ AnalysisID StartAfterID = getPassID(argv0, "start-after", StartAfter);
+ AnalysisID StopAfterID = getPassID(argv0, "stop-after", StopAfter);
+ AnalysisID StopBeforeID = getPassID(argv0, "stop-before", StopBefore);
+ if (StartBeforeID && StartAfterID) {
+ errs() << argv0 << ": -start-before and -start-after specified!\n";
+ return 1;
+ }
+ if (StopBeforeID && StopAfterID) {
+ errs() << argv0 << ": -stop-before and -stop-after specified!\n";
+ return 1;
+ }
+
+ if (MIR) {
+ // Construct a custom pass pipeline that starts after instruction
+ // selection.
LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine&>(*Target);
TargetPassConfig &TPC = *LLVMTM.createPassConfig(PM);
+ TPC.setDisableVerify(NoVerify);
PM.add(&TPC);
MachineModuleInfo *MMI = new MachineModuleInfo(&LLVMTM);
- MMI->setMachineFunctionInitializer(MIR.get());
+ if (MIR->parseMachineFunctions(*M, *MMI))
+ return 1;
PM.add(MMI);
TPC.printAndVerify("");
- for (const std::string &RunPassName : *RunPassNames) {
- if (addPass(PM, argv[0], RunPassName, TPC))
+ if (!RunPassNames->empty()) {
+ if (!StartAfter.empty() || !StopAfter.empty() || !StartBefore.empty() ||
+ !StopBefore.empty()) {
+ errs() << argv0 << ": start-after and/or stop-after passes are "
+ "redundant when run-pass is specified.\n";
return 1;
+ }
+
+ for (const std::string &RunPassName : *RunPassNames) {
+ if (addPass(PM, argv0, RunPassName, TPC))
+ return 1;
+ }
+ } else {
+ TPC.setStartStopPasses(StartBeforeID, StartAfterID, StopBeforeID,
+ StopAfterID);
+ TPC.addISelPasses();
+ TPC.addMachinePasses();
}
- PM.add(createPrintMIRPass(*OS));
- } else {
- const char *argv0 = argv[0];
- AnalysisID StartBeforeID = getPassID(argv0, "start-before", StartBefore);
- AnalysisID StartAfterID = getPassID(argv0, "start-after", StartAfter);
- AnalysisID StopAfterID = getPassID(argv0, "stop-after", StopAfter);
- AnalysisID StopBeforeID = getPassID(argv0, "stop-before", StopBefore);
-
- if (StartBeforeID && StartAfterID) {
- errs() << argv[0] << ": -start-before and -start-after specified!\n";
- return 1;
- }
- if (StopBeforeID && StopAfterID) {
- errs() << argv[0] << ": -stop-before and -stop-after specified!\n";
- return 1;
- }
+ TPC.setInitialized();
- // Ask the target to add backend passes as necessary.
- if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify,
- StartBeforeID, StartAfterID, StopBeforeID,
- StopAfterID, MIR.get())) {
- errs() << argv[0] << ": target does not support generation of this"
+ if (!StopBefore.empty() || !StopAfter.empty() || !RunPassNames->empty()) {
+ PM.add(createPrintMIRPass(*OS));
+ } else if (LLVMTM.addAsmPrinter(PM, *OS, FileType, MMI->getContext())) {
+ errs() << argv0 << ": target does not support generation of this"
<< " file type!\n";
return 1;
}
+ PM.add(createFreeMachineFunctionPass());
+ } else if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify,
+ StartBeforeID, StartAfterID,
+ StopBeforeID, StopAfterID)) {
+ errs() << argv0 << ": target does not support generation of this"
+ << " file type!\n";
+ return 1;
}
// Before executing passes, print the final values of the LLVM options.