diff options
author | Martin Nowack <m.nowack@imperial.ac.uk> | 2019-03-16 23:27:20 +0000 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2019-03-18 20:29:35 +0000 |
commit | 842966d5f2921e807ddc348505ee710eba3ad86d (patch) | |
tree | 847f010a578f011e787def078dc33a6f42e48aad /lib/Module/KModule.cpp | |
parent | 33394de6b4f14a7677e7c470be80929c1192b98e (diff) | |
download | klee-842966d5f2921e807ddc348505ee710eba3ad86d.tar.gz |
Disable optimisation for functions that contain KLEE calls
Compilers are allowed to hoist function calls and do GVE. This is currently done even without `--optimization` enabled. This is unfortunate in the context of KLEE function calls that might depend on specific code position without direct control flow dependencies. In such cases, function calls can be hoisted. To circumvent this, disallow to optimise functions that contain such calls by default. This might reduce optimisation for some functions containing such function calls but still allows it for all others. This patch adds an additional pass, that detects all functions starting with a prefix `klee_` and disable optimisations for functions containing such calls. This is enabled by default but can be disabled by `--klee-call-optimisation=false`.
Diffstat (limited to 'lib/Module/KModule.cpp')
-rw-r--r-- | lib/Module/KModule.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp index 3ce95a9e..2a15b02f 100644 --- a/lib/Module/KModule.cpp +++ b/lib/Module/KModule.cpp @@ -112,6 +112,12 @@ namespace { DontVerify("disable-verify", cl::desc("Do not verify the module integrity (default=false)"), cl::init(false), cl::cat(klee::ModuleCat)); + + cl::opt<bool> + OptimiseKLEECall("klee-call-optimisation", + cl::desc("Allow optimization of functions that " + "contain KLEE calls (default=true)"), + cl::init(true), cl::cat(ModuleCat)); } /***/ @@ -262,6 +268,14 @@ void KModule::instrument(const Interpreter::ModuleOptions &opts) { void KModule::optimiseAndPrepare( const Interpreter::ModuleOptions &opts, llvm::ArrayRef<const char *> preservedFunctions) { + // Preserve all functions containing klee-related function calls from being + // optimised around + if (!OptimiseKLEECall) { + LegacyLLVMPassManagerTy pm; + pm.add(new OptNonePass()); + pm.run(*module); + } + if (opts.Optimize) Optimize(module.get(), preservedFunctions); |