klee
OptNone.cpp
Go to the documentation of this file.
1//===-- OptNone.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
12#include "klee/Config/Version.h"
13
14#include "llvm/ADT/SmallPtrSet.h"
15#include "llvm/IR/Function.h"
16#include "llvm/IR/Instruction.h"
17#include "llvm/IR/Module.h"
18
19namespace klee {
20
22
23bool OptNonePass::runOnModule(llvm::Module &M) {
24 // Find list of functions that start with `klee_`
25 // and mark all functions that contain such call or invoke as optnone
26 llvm::SmallPtrSet<llvm::Function *,16> CallingFunctions;
27 for (auto &F : M) {
28 if (!F.hasName() || !F.getName().startswith("klee_"))
29 continue;
30 for (auto *U : F.users()) {
31 // skip non-calls and non-invokes
32 if (!llvm::isa<llvm::CallInst>(U) && !llvm::isa<llvm::InvokeInst>(U))
33 continue;
34 auto *Inst = llvm::cast<llvm::Instruction>(U);
35 CallingFunctions.insert(Inst->getParent()->getParent());
36 }
37 }
38
39 bool changed = false;
40 for (auto F : CallingFunctions) {
41 // Skip if already annotated
42 if (F->hasFnAttribute(llvm::Attribute::OptimizeNone))
43 continue;
44 F->addFnAttr(llvm::Attribute::OptimizeNone);
45 F->addFnAttr(llvm::Attribute::NoInline);
46 changed = true;
47 }
48
49 return changed;
50}
51} // namespace klee
bool runOnModule(llvm::Module &M) override
Definition: OptNone.cpp:23
static char ID
Definition: Passes.h:203
Definition: main.cpp:291