UserSearcher.cpp

Go to the documentation of this file.
00001 //===-- UserSearcher.cpp --------------------------------------------------===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "Common.h"
00011 
00012 #include "UserSearcher.h"
00013 
00014 #include "Searcher.h"
00015 #include "Executor.h"
00016 
00017 #include "llvm/Support/CommandLine.h"
00018 
00019 using namespace llvm;
00020 using namespace klee;
00021 
00022 namespace {
00023   cl::opt<bool>
00024   UseRandomSearch("use-random-search");
00025 
00026   cl::opt<bool>
00027   UseInterleavedRS("use-interleaved-RS");
00028 
00029   cl::opt<bool>
00030   UseInterleavedNURS("use-interleaved-NURS");
00031 
00032   cl::opt<bool>
00033   UseInterleavedMD2UNURS("use-interleaved-MD2U-NURS");
00034 
00035   cl::opt<bool>
00036   UseInterleavedInstCountNURS("use-interleaved-icnt-NURS");
00037 
00038   cl::opt<bool>
00039   UseInterleavedCPInstCountNURS("use-interleaved-cpicnt-NURS");
00040 
00041   cl::opt<bool>
00042   UseInterleavedQueryCostNURS("use-interleaved-query-cost-NURS");
00043 
00044   cl::opt<bool>
00045   UseInterleavedCovNewNURS("use-interleaved-covnew-NURS");
00046 
00047   cl::opt<bool>
00048   UseNonUniformRandomSearch("use-non-uniform-random-search");
00049 
00050   cl::opt<bool>
00051   UseRandomPathSearch("use-random-path");
00052 
00053   cl::opt<WeightedRandomSearcher::WeightType>
00054   WeightType("weight-type", cl::desc("Set the weight type for --use-non-uniform-random-search"),
00055              cl::values(clEnumValN(WeightedRandomSearcher::Depth, "none", "use (2^depth)"),
00056                         clEnumValN(WeightedRandomSearcher::InstCount, "icnt", "use current pc exec count"),
00057                         clEnumValN(WeightedRandomSearcher::CPInstCount, "cpicnt", "use current pc exec count"),
00058                         clEnumValN(WeightedRandomSearcher::QueryCost, "query-cost", "use query cost"),
00059                         clEnumValN(WeightedRandomSearcher::MinDistToUncovered, "md2u", "use min dist to uncovered"),
00060                         clEnumValN(WeightedRandomSearcher::CoveringNew, "covnew", "use min dist to uncovered + coveringNew flag"),
00061                         clEnumValEnd));
00062   
00063   cl::opt<bool>
00064   UseMerge("use-merge", 
00065            cl::desc("Enable support for klee_merge() (experimental)"));
00066  
00067   cl::opt<bool>
00068   UseBumpMerge("use-bump-merge", 
00069            cl::desc("Enable support for klee_merge() (extra experimental)"));
00070  
00071   cl::opt<bool>
00072   UseIterativeDeepeningTimeSearch("use-iterative-deepening-time-search", 
00073                                     cl::desc("(experimental)"));
00074 
00075   cl::opt<bool>
00076   UseBatchingSearch("use-batching-search", 
00077            cl::desc("Use batching searcher (keep running selected state for N instructions/time, see --batch-instructions and --batch-time"));
00078 
00079   cl::opt<unsigned>
00080   BatchInstructions("batch-instructions",
00081                     cl::desc("Number of instructions to batch when using --use-batching-search"),
00082                     cl::init(10000));
00083   
00084   cl::opt<double>
00085   BatchTime("batch-time",
00086             cl::desc("Amount of time to batch when using --use-batching-search"),
00087             cl::init(5.0));
00088 }
00089 
00090 bool klee::userSearcherRequiresMD2U() {
00091   return (WeightType==WeightedRandomSearcher::MinDistToUncovered ||
00092           WeightType==WeightedRandomSearcher::CoveringNew ||
00093           UseInterleavedMD2UNURS ||
00094           UseInterleavedCovNewNURS || 
00095           UseInterleavedInstCountNURS || 
00096           UseInterleavedCPInstCountNURS || 
00097           UseInterleavedQueryCostNURS);
00098 }
00099 
00100 // FIXME: Remove.
00101 bool klee::userSearcherRequiresBranchSequences() {
00102   return false;
00103 }
00104 
00105 Searcher *klee::constructUserSearcher(Executor &executor) {
00106   Searcher *searcher = 0;
00107 
00108   if (UseRandomPathSearch) {
00109     searcher = new RandomPathSearcher(executor);
00110   } else if (UseNonUniformRandomSearch) {
00111     searcher = new WeightedRandomSearcher(executor, WeightType);
00112   } else if (UseRandomSearch) {
00113     searcher = new RandomSearcher();
00114   } else {
00115     searcher = new DFSSearcher();
00116   }
00117 
00118   if (UseInterleavedNURS || UseInterleavedMD2UNURS || UseInterleavedRS ||
00119       UseInterleavedCovNewNURS || UseInterleavedInstCountNURS ||
00120       UseInterleavedCPInstCountNURS || UseInterleavedQueryCostNURS) {
00121     std::vector<Searcher *> s;
00122     s.push_back(searcher);
00123     
00124     if (UseInterleavedNURS)
00125       s.push_back(new WeightedRandomSearcher(executor, 
00126                                              WeightedRandomSearcher::Depth));
00127     if (UseInterleavedMD2UNURS)
00128       s.push_back(new WeightedRandomSearcher(executor, 
00129                                              WeightedRandomSearcher::MinDistToUncovered));
00130 
00131     if (UseInterleavedCovNewNURS)
00132       s.push_back(new WeightedRandomSearcher(executor, 
00133                                              WeightedRandomSearcher::CoveringNew));
00134    
00135     if (UseInterleavedInstCountNURS)
00136       s.push_back(new WeightedRandomSearcher(executor, 
00137                                              WeightedRandomSearcher::InstCount));
00138     
00139     if (UseInterleavedCPInstCountNURS)
00140       s.push_back(new WeightedRandomSearcher(executor, 
00141                                              WeightedRandomSearcher::CPInstCount));
00142     
00143     if (UseInterleavedQueryCostNURS)
00144       s.push_back(new WeightedRandomSearcher(executor, 
00145                                              WeightedRandomSearcher::QueryCost));
00146 
00147     if (UseInterleavedRS) 
00148       s.push_back(new RandomSearcher());
00149 
00150     searcher = new InterleavedSearcher(s);
00151   }
00152 
00153   if (UseBatchingSearch) {
00154     searcher = new BatchingSearcher(searcher, BatchTime, BatchInstructions);
00155   }
00156 
00157   if (UseMerge) {
00158     assert(!UseBumpMerge);
00159     searcher = new MergingSearcher(executor, searcher);
00160   } else if (UseBumpMerge) {    
00161     searcher = new BumpMergingSearcher(executor, searcher);
00162   }
00163   
00164   if (UseIterativeDeepeningTimeSearch) {
00165     searcher = new IterativeDeepeningTimeSearcher(searcher);
00166   }
00167 
00168   std::ostream &os = executor.getHandler().getInfoStream();
00169 
00170   os << "BEGIN searcher description\n";
00171   searcher->printName(os);
00172   os << "END searcher description\n";
00173 
00174   return searcher;
00175 }

Generated on Fri Jun 5 03:31:32 2009 for klee by  doxygen 1.5.8