aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-reduce/llvm-reduce.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-reduce/llvm-reduce.cpp')
-rw-r--r--llvm/tools/llvm-reduce/llvm-reduce.cpp48
1 files changed, 15 insertions, 33 deletions
diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp
index abcd4c6..db7bfa9 100644
--- a/llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -28,9 +28,8 @@
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
-#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/WithColor.h"
-#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/raw_ostream.h"
#include <system_error>
#include <vector>
@@ -85,10 +84,6 @@ static cl::opt<InputLanguages>
clEnumValN(InputLanguages::MIR, "mir", "")),
cl::cat(LLVMReduceOptions));
-static cl::opt<std::string> TargetTriple("mtriple",
- cl::desc("Set the target triple"),
- cl::cat(LLVMReduceOptions));
-
static cl::opt<int>
MaxPassIterations("max-pass-iterations",
cl::desc("Maximum number of times to run the full set "
@@ -97,6 +92,13 @@ static cl::opt<int>
static codegen::RegisterCodeGenFlags CGF;
+static void initializeTargetInfo() {
+ InitializeAllTargets();
+ InitializeAllTargetMCs();
+ InitializeAllAsmPrinters();
+ InitializeAllAsmParsers();
+}
+
void writeOutput(ReducerWorkItem &M, StringRef Message) {
if (ReplaceInput) // In-place
OutputFilename = InputFilename.c_str();
@@ -112,26 +114,6 @@ void writeOutput(ReducerWorkItem &M, StringRef Message) {
errs() << Message << OutputFilename << "\n";
}
-static std::unique_ptr<LLVMTargetMachine> createTargetMachine() {
- InitializeAllTargets();
- InitializeAllTargetMCs();
- InitializeAllAsmPrinters();
- InitializeAllAsmParsers();
-
- if (TargetTriple == "")
- TargetTriple = sys::getDefaultTargetTriple();
- auto TT(Triple::normalize(TargetTriple));
- std::string CPU(codegen::getCPUStr());
- std::string FS(codegen::getFeaturesStr());
-
- std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
-
- return std::unique_ptr<LLVMTargetMachine>(
- static_cast<LLVMTargetMachine *>(TheTarget->createTargetMachine(
- TT, CPU, FS, TargetOptions(), None, None, CodeGenOpt::Default)));
-}
-
int main(int Argc, char **Argv) {
InitLLVM X(Argc, Argv);
@@ -151,15 +133,15 @@ int main(int Argc, char **Argv) {
return 0;
}
+ if (ReduceModeMIR)
+ initializeTargetInfo();
+
LLVMContext Context;
- std::unique_ptr<LLVMTargetMachine> TM;
+ std::unique_ptr<TargetMachine> TM;
std::unique_ptr<MachineModuleInfo> MMI;
- std::unique_ptr<ReducerWorkItem> OriginalProgram;
- if (ReduceModeMIR) {
- TM = createTargetMachine();
- MMI = std::make_unique<MachineModuleInfo>(TM.get());
- }
- OriginalProgram = parseReducerWorkItem(InputFilename, Context, MMI.get());
+
+ std::unique_ptr<ReducerWorkItem> OriginalProgram = parseReducerWorkItem(
+ Argv[0], InputFilename, Context, TM, MMI, ReduceModeMIR);
if (!OriginalProgram) {
return 1;
}