mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-29 22:50:53 +03:00
Several changes to optimizer related code.
- New functions codeGenOptLevel() and verifyModule() to remove code duplication - Hidden option no-verify renamed to disable-verify and moved to optimizer (like opt tool) - Removed global.params.noVerify
This commit is contained in:
parent
34d595de26
commit
e6a07ffdfe
8 changed files with 59 additions and 48 deletions
|
@ -310,7 +310,6 @@ struct Param
|
|||
// Codegen cl options
|
||||
bool singleObj;
|
||||
bool disableRedZone;
|
||||
bool noVerify;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -276,7 +276,6 @@ struct Param
|
|||
// Codegen cl options
|
||||
bool singleObj;
|
||||
bool disableRedZone;
|
||||
bool noVerify;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -375,10 +375,6 @@ static cl::opt<MultiSetter, true, cl::parser<bool> > release("release",
|
|||
cl::location(ReleaseSetter),
|
||||
cl::ValueDisallowed);
|
||||
|
||||
cl::opt<bool, true> noVerify("noverify",
|
||||
llvm::cl::desc("Do not run the validation pass before writing bitcode"),
|
||||
cl::location(global.params.noVerify));
|
||||
|
||||
cl::opt<bool, true> singleObj("singleobj",
|
||||
cl::desc("Create only a single output object file"),
|
||||
cl::location(global.params.singleObj));
|
||||
|
|
|
@ -325,8 +325,6 @@ int main(int argc, char** argv)
|
|||
|
||||
#if LDC_LLVM_VER >= 301
|
||||
llvm::TargetOptions targetOptions;
|
||||
// FIXME: Options here are { None, Less, Default, Aggressive } as defined http://llvm.org/docs/doxygen/html/namespacellvm_1_1CodeGenOpt.html
|
||||
llvm::CodeGenOpt::Level codeGenOptLevel = llvm::CodeGenOpt::None; // I am setting this to None for the moment as I dont know how this changes generation
|
||||
#endif
|
||||
|
||||
Array* libs;
|
||||
|
@ -554,7 +552,7 @@ int main(int argc, char** argv)
|
|||
targetOptions,
|
||||
mRelocModel,
|
||||
mCodeModel,
|
||||
codeGenOptLevel
|
||||
codeGenOptLevel()
|
||||
);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -33,22 +33,7 @@ void emit_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostrea
|
|||
void writeModule(llvm::Module* m, std::string filename)
|
||||
{
|
||||
// run optimizer
|
||||
bool reverify = ldc_optimize_module(m);
|
||||
|
||||
// verify the llvm
|
||||
if (!global.params.noVerify && reverify) {
|
||||
std::string verifyErr;
|
||||
Logger::println("Verifying module... again...");
|
||||
LOG_SCOPE;
|
||||
if (llvm::verifyModule(*m,llvm::ReturnStatusAction,&verifyErr))
|
||||
{
|
||||
error("%s", verifyErr.c_str());
|
||||
fatal();
|
||||
}
|
||||
else {
|
||||
Logger::println("Verification passed!");
|
||||
}
|
||||
}
|
||||
ldc_optimize_module(m);
|
||||
|
||||
// eventually do our own path stuff, dmd's is a bit strange.
|
||||
typedef llvm::sys::Path LLPath;
|
||||
|
@ -141,16 +126,8 @@ void emit_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostrea
|
|||
else
|
||||
Passes.add(new TargetData(&m));
|
||||
|
||||
// Last argument is enum CodeGenOpt::Level OptLevel
|
||||
// debug info doesn't work properly with OptLevel != None!
|
||||
CodeGenOpt::Level LastArg = CodeGenOpt::Default;
|
||||
if (global.params.symdebug || !optimize())
|
||||
LastArg = CodeGenOpt::None;
|
||||
else if (optLevel() >= 3)
|
||||
LastArg = CodeGenOpt::Aggressive;
|
||||
|
||||
llvm::formatted_raw_ostream fout(out);
|
||||
if (Target.addPassesToEmitFile(Passes, fout, fileType, LastArg))
|
||||
if (Target.addPassesToEmitFile(Passes, fout, fileType, codeGenOptLevel()))
|
||||
assert(0 && "no support for asm output");
|
||||
|
||||
Passes.doInitialization();
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "gen/structs.h"
|
||||
#include "gen/todebug.h"
|
||||
#include "gen/tollvm.h"
|
||||
#include "gen/optimizer.h"
|
||||
|
||||
#include "ir/irvar.h"
|
||||
#include "ir/irmodule.h"
|
||||
|
@ -289,19 +290,7 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir)
|
|||
genmoduleinfo();
|
||||
|
||||
// verify the llvm
|
||||
if (!global.params.noVerify) {
|
||||
std::string verifyErr;
|
||||
Logger::println("Verifying module...");
|
||||
LOG_SCOPE;
|
||||
if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
|
||||
{
|
||||
error("%s", verifyErr.c_str());
|
||||
fatal();
|
||||
}
|
||||
else {
|
||||
Logger::println("Verification passed!");
|
||||
}
|
||||
}
|
||||
verifyModule(*ir.module);
|
||||
|
||||
gIR = NULL;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "gen/optimizer.h"
|
||||
#include "gen/cl_helpers.h"
|
||||
#include "gen/logger.h"
|
||||
|
||||
#include "gen/passes/Passes.h"
|
||||
|
||||
|
@ -39,6 +40,11 @@ static cl::opt<unsigned char> optimizeLevel(
|
|||
clEnumValEnd),
|
||||
cl::init(0));
|
||||
|
||||
static cl::opt<bool>
|
||||
noVerify("disable-verify",
|
||||
cl::desc("Do not verify result module"),
|
||||
cl::Hidden);
|
||||
|
||||
static cl::opt<bool>
|
||||
verifyEach("verify-each",
|
||||
cl::desc("Run verifier after each optimization pass"),
|
||||
|
@ -95,6 +101,22 @@ bool optimize() {
|
|||
return optimizeLevel || doInline() || !passList.empty();
|
||||
}
|
||||
|
||||
llvm::CodeGenOpt::Level codeGenOptLevel() {
|
||||
#if LDC_LLVM_VER < 302
|
||||
const int opt = optLevel();
|
||||
// Use same appoach as clang (see lib/CodeGen/BackendUtil.cpp)
|
||||
llvm::CodeGenOpt::Level codeGenOptLevel = llvm::CodeGenOpt::Default;
|
||||
// Debug info doesn't work properly with CodeGenOpt <> None
|
||||
if (global.params.symdebug || !opt) codeGenOptLevel = llvm::CodeGenOpt::None;
|
||||
else if (opt >= 3) codeGenOptLevel = llvm::CodeGenOpt::Aggressive;
|
||||
#else
|
||||
// There's a bug in llvm:LiveInterval::createDeadDef()
|
||||
// which prevents use of other values.
|
||||
// Happens only with 3.2 trunk.
|
||||
return llvm::CodeGenOpt::None;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void addPass(PassManager& pm, Pass* pass) {
|
||||
pm.add(pass);
|
||||
|
||||
|
@ -260,5 +282,25 @@ bool ldc_optimize_module(llvm::Module* m)
|
|||
addPassesForOptLevel(pm);
|
||||
|
||||
pm.run(*m);
|
||||
|
||||
verifyModule(m);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Verifies the module.
|
||||
void verifyModule(llvm::Module* m) {
|
||||
if (!noVerify) {
|
||||
std::string verifyErr;
|
||||
Logger::println("Verifying module...");
|
||||
LOG_SCOPE;
|
||||
if (llvm::verifyModule(*m, llvm::ReturnStatusAction, &verifyErr))
|
||||
{
|
||||
error("%s", verifyErr.c_str());
|
||||
fatal();
|
||||
}
|
||||
else {
|
||||
Logger::println("Verification passed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
#ifndef LDC_GEN_OPTIMIZER_H
|
||||
#define LDC_GEN_OPTIMIZER_H
|
||||
|
||||
// For llvm::CodeGenOpt::Level
|
||||
#if LDC_LLVM_VER == 300
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#else
|
||||
#include "llvm/Support/CodeGen.h"
|
||||
#endif
|
||||
|
||||
namespace llvm { class Module; }
|
||||
|
||||
bool ldc_optimize_module(llvm::Module* m);
|
||||
|
@ -14,5 +21,9 @@ int optLevel();
|
|||
|
||||
bool optimize();
|
||||
|
||||
llvm::CodeGenOpt::Level codeGenOptLevel();
|
||||
|
||||
void verifyModule(llvm::Module* m);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue