File tree Expand file tree Collapse file tree 6 files changed +56
-11
lines changed Expand file tree Collapse file tree 6 files changed +56
-11
lines changed Original file line number Diff line number Diff line change 88#===------------------------------------------------------------------------===#
99set (KLEE_MODULE_COMPONENT_SRCS
1010 CallSplitter.cpp
11+ CallRemover.cpp
1112 Checks.cpp
1213 CodeGraphInfo.cpp
1314 FunctionAlias.cpp
Original file line number Diff line number Diff line change 1+ // ===-- CallRemover.cpp----------------------------------------------------===//
2+ //
3+ // The KLEE Symbolic Virtual Machine
4+ //
5+ // This file is distributed under the University of Illinois Open Source
6+ // License. See LICENSE.TXT for details.
7+ //
8+ // ===----------------------------------------------------------------------===//
9+
10+ #include " Passes.h"
11+ #include < unordered_set>
12+
13+ namespace klee {
14+
15+ using namespace llvm ;
16+
17+ char CallRemover::ID;
18+
19+ bool CallRemover::runOnModule (llvm::Module &M) {
20+ std::vector<std::string> badFuncs = {" llvm.dbg.declare" , " llvm.dbg.label" };
21+
22+ for (const auto &f : badFuncs) {
23+ auto Declare = M.getFunction (f);
24+ if (!Declare)
25+ continue ;
26+ while (!Declare->use_empty ()) {
27+ auto CI = cast<CallInst>(Declare->user_back ());
28+ assert (CI->use_empty () && " deleted function must have void result" );
29+ CI->eraseFromParent ();
30+ }
31+ Declare->eraseFromParent ();
32+ }
33+
34+ return true ;
35+ }
36+ } // namespace klee
Original file line number Diff line number Diff line change 1- // ===-- CallSplitter.cpp
2- // -------------------------------------------------------===//
1+ // ===-- CallSplitter.cpp --------------------------------------------------===//
32//
43// The KLEE Symbolic Virtual Machine
54//
@@ -46,8 +45,9 @@ bool CallSplitter::runOnFunction(Function &F) {
4645 if (callInst != firstInst) {
4746 fbb = fbb->splitBasicBlock (callInst);
4847 }
49- if (isa<BranchInst>(afterCallInst) &&
50- cast<BranchInst>(afterCallInst)->isUnconditional ()) {
48+ if ((isa<BranchInst>(afterCallInst) &&
49+ cast<BranchInst>(afterCallInst)->isUnconditional ()) ||
50+ isa<UnreachableInst>(afterCallInst)) {
5151 break ;
5252 }
5353 fbb = fbb->splitBasicBlock (afterCallInst);
Original file line number Diff line number Diff line change @@ -117,6 +117,11 @@ cl::opt<bool>
117117 cl::desc (" Split each call in own basic block (default=true)" ),
118118 cl::init(true ), cl::cat(klee::ModuleCat));
119119
120+ static cl::opt<bool >
121+ StripUnwantedCalls (" strip-unwanted-calls" ,
122+ cl::desc (" Strip all unwanted calls (llvm.dbg.* stuff)" ),
123+ cl::init(false ), cl::cat(klee::ModuleCat));
124+
120125cl::opt<bool > SplitReturns (
121126 " split-returns" ,
122127 cl::desc (" Split each return in own basic block (default=true)" ),
@@ -332,6 +337,8 @@ void KModule::optimiseAndPrepare(
332337 pm3.add (createScalarizerPass ());
333338 pm3.add (new PhiCleanerPass ());
334339 pm3.add (new FunctionAliasPass ());
340+ if (StripUnwantedCalls)
341+ pm3.add (new CallRemover ());
335342 if (SplitCalls) {
336343 pm3.add (new CallSplitter ());
337344 }
Original file line number Diff line number Diff line change @@ -72,11 +72,6 @@ static cl::opt<bool>
7272 cl::desc (" Strip debugger symbol info from executable" ),
7373 cl::init(false ), cl::cat(klee::ModuleCat));
7474
75- static cl::opt<bool >
76- StripDebugDeclare (" strip-debug-declare" ,
77- cl::desc (" Strip all llvm.dbg.declare intrinsics" ),
78- cl::init(true ), cl::cat(klee::ModuleCat));
79-
8075static cl::alias A1 (" S" , cl::desc(" Alias for --strip-debug" ),
8176 cl::aliasopt(StripDebug));
8277
@@ -103,8 +98,6 @@ static void AddStandardCompilePasses(legacy::PassManager &PM) {
10398 // If the -strip-debug command line option was specified, do it.
10499 if (StripDebug)
105100 addPass (PM, createStripSymbolsPass (true ));
106- if (StripDebugDeclare)
107- addPass (PM, createStripDebugDeclarePass ());
108101
109102 addPass (PM, createCFGSimplificationPass ()); // Clean up disgusting code
110103 addPass (PM, createPromoteMemoryToRegisterPass ()); // Kill useless allocas
Original file line number Diff line number Diff line change @@ -206,6 +206,14 @@ class CallSplitter : public llvm::FunctionPass {
206206 bool runOnFunction (llvm::Function &F) override ;
207207};
208208
209+ // / Remove unwanted calls
210+ class CallRemover : public llvm ::ModulePass {
211+ public:
212+ static char ID;
213+ CallRemover () : llvm::ModulePass(ID) {}
214+ bool runOnModule (llvm::Module &M) override ;
215+ };
216+
209217class ReturnSplitter : public llvm ::FunctionPass {
210218public:
211219 static char ID;
You can’t perform that action at this time.
0 commit comments