Set optimization level from -O argument when creating TargetMachine.

This commit is contained in:
Yves Le Maout 2015-12-04 18:56:17 +01:00 committed by sftnight
parent 890e4b2e2a
commit 62d51e5f8a
3 changed files with 28 additions and 6 deletions

View File

@ -43,7 +43,7 @@ using namespace llvm;
namespace cling {
IncrementalExecutor::IncrementalExecutor(clang::DiagnosticsEngine& diags):
IncrementalExecutor::IncrementalExecutor(clang::DiagnosticsEngine& diags, const int& argc, const char* const *argv):
m_CurrentAtExitModule(0)
#if 0
: m_Diags(diags)
@ -57,14 +57,14 @@ IncrementalExecutor::IncrementalExecutor(clang::DiagnosticsEngine& diags):
// can use this object yet.
m_AtExitFuncs.reserve(256);
m_JIT.reset(new IncrementalJIT(*this, std::move(CreateHostTargetMachine())));
m_JIT.reset(new IncrementalJIT(*this, std::move(CreateHostTargetMachine(argc, argv))));
}
// Keep in source: ~unique_ptr<ClingJIT> needs ClingJIT
IncrementalExecutor::~IncrementalExecutor() {}
std::unique_ptr<TargetMachine>
IncrementalExecutor::CreateHostTargetMachine() const {
IncrementalExecutor::CreateHostTargetMachine(const int& argc, const char* const *argv) const {
// TODO: make this configurable.
Triple TheTriple(sys::getProcessTriple());
#ifdef _WIN32
@ -91,6 +91,28 @@ std::unique_ptr<TargetMachine>
CodeModel::Model CMModel = CodeModel::JITDefault;
CodeGenOpt::Level OptLevel = CodeGenOpt::Less;
for (int i = 0; i < argc; ++i) {
const std::string arg(argv[i]);
if (arg.length() != 3 || arg.rfind("-O", 0) != 0) {
continue;
}
switch (argv[i][2]) {
case '0':
OptLevel = CodeGenOpt::None;
break;
case '1':
OptLevel = CodeGenOpt::Less;
break;
case '2':
OptLevel = CodeGenOpt::Default;
break;
case '3':
OptLevel = CodeGenOpt::Aggressive;
break;
}
}
std::unique_ptr<TargetMachine> TM;
TM.reset(TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr,

View File

@ -127,7 +127,7 @@ namespace cling {
clang::DiagnosticsEngine& m_Diags;
#endif
std::unique_ptr<llvm::TargetMachine> CreateHostTargetMachine() const;
std::unique_ptr<llvm::TargetMachine> CreateHostTargetMachine(const int& argc, const char* const *argv) const;
public:
enum ExecutionResult {
@ -137,7 +137,7 @@ namespace cling {
kNumExeResults
};
IncrementalExecutor(clang::DiagnosticsEngine& diags);
IncrementalExecutor(clang::DiagnosticsEngine& diags, const int& argc, const char* const *argv);
~IncrementalExecutor();

View File

@ -193,7 +193,7 @@ namespace cling {
/*isTemp*/true), this));
if (!isInSyntaxOnlyMode())
m_Executor.reset(new IncrementalExecutor(SemaRef.Diags));
m_Executor.reset(new IncrementalExecutor(SemaRef.Diags, argc, argv));
// Tell the diagnostic client that we are entering file parsing mode.
DiagnosticConsumer& DClient = getCI()->getDiagnosticClient();