Computer Laboratory

tesla::CalleeInstr Class Reference

Detailed Description

Function instrumentation (callee context).

Definition at line 80 of file Callee.h.

#include "Callee.h"

+ Inheritance diagram for tesla::CalleeInstr:
+ Collaboration diagram for tesla::CalleeInstr:

Static Public Member Functions

static CalleeInstrBuild (llvm::Module &, llvm::Function *Target, FunctionEvent::Direction, bool SuppressDebugInstr)
 Construct an object that can instrument a given function. More...
 

Additional Inherited Members

- Public Member Functions inherited from tesla::FnInstrumentation
void AppendInstrumentation (const Automaton &, const FunctionEvent &, TEquivalenceClass &)
 
- Protected Member Functions inherited from tesla::FnInstrumentation
 FnInstrumentation (llvm::Module &M, const llvm::Function *TargetFn, llvm::Function *InstrFn, FunctionEvent::Direction Dir)
 
- Protected Attributes inherited from tesla::FnInstrumentation
llvm::Module & M
 The current module. More...
 
const llvm::Function * TargetFn
 The function being instrumented. More...
 
llvm::Function * InstrFn
 The instrumentation function. More...
 
FunctionEvent::Direction Dir
 Which way we instrument (in or out). More...
 

Member Function Documentation

CalleeInstr * tesla::CalleeInstr::Build ( llvm::Module &  ,
llvm::Function *  Target,
FunctionEvent::Direction  ,
bool  SuppressDebugInstr 
)
static

Construct an object that can instrument a given function.

Definition at line 111 of file Callee.cpp.

References tesla::FunctionInstrumentation().

113  {
114 
115  // Find (or create) the instrumentation function.
116  // Note: it doesn't yet contain the code to translate events and
117  // dispatch them to tesla_update_state().
118  Function *InstrFn = FunctionInstrumentation(M, *Target, Dir,
120  SuppressDebugInstr);
121 
122  // Record the arguments passed to the instrumented function.
123  //
124  // LLVM's SSA magic will keep these around for us until we need them, even if
125  // C code overwrites its parameters.
126  ArgVector Args;
127  for (auto &Arg : Target->getArgumentList())
128  Args.push_back(&Arg);
129 
130  // Instrument either the entry or return points of the target function.
131  switch (Dir) {
132  case FunctionEvent::Entry: {
133  // Instrumenting function entry is easy: just add a new call to
134  // instrumentation at the beginning of the function's entry block.
135  BasicBlock& Entry = Target->getEntryBlock();
136  CallInst::Create(InstrFn, Args)->insertBefore(Entry.getFirstNonPHI());
137  break;
138  }
139 
140  case FunctionEvent::Exit: {
141  SmallPtrSet<ReturnInst*, 16> Returns;
142  for (auto i = inst_begin(Target), End = inst_end(Target); i != End; i++)
143  if (auto *Return = dyn_cast<ReturnInst>(&*i))
144  Returns.insert(Return);
145 
146  for (ReturnInst *Return : Returns) {
147  ArgVector InstrArgs(Args);
148 
149  if (Dir == FunctionEvent::Exit && !Target->getReturnType()->isVoidTy())
150  InstrArgs.push_back(Return->getReturnValue());
151 
152  CallInst::Create(InstrFn, InstrArgs)->insertBefore(Return);
153  }
154  break;
155  }
156  }
157 
158  return new CalleeInstr(M, Target, InstrFn, Dir);
159 }

+ Here is the call graph for this function:


The documentation for this class was generated from the following files: