Computer Laboratory

Detailed Description

Instrumentation for a function event.

Definition at line 64 of file Instrumentation.h.

#include "Instrumentation.h"

+ Inheritance diagram for tesla::FnInstrumentation:
+ Collaboration diagram for tesla::FnInstrumentation:

Public Member Functions

void AppendInstrumentation (const Automaton &, const FunctionEvent &, TEquivalenceClass &)
 

Protected Member Functions

 FnInstrumentation (llvm::Module &M, const llvm::Function *TargetFn, llvm::Function *InstrFn, FunctionEvent::Direction Dir)
 

Protected Attributes

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...
 

Constructor & Destructor Documentation

tesla::FnInstrumentation::FnInstrumentation ( llvm::Module &  M,
const llvm::Function *  TargetFn,
llvm::Function *  InstrFn,
FunctionEvent::Direction  Dir 
)
inlineprotected

Definition at line 70 of file Instrumentation.h.

73  {
74  }

Member Function Documentation

void tesla::FnInstrumentation::AppendInstrumentation ( const Automaton A,
const FunctionEvent Ev,
TEquivalenceClass Trans 
)

Definition at line 74 of file Instrumentation.cpp.

References tesla::FunctionEvent::argument, tesla::ConstructKey(), tesla::ConstructTransitions(), tesla::AutomatonDescription::context, tesla::FunctionEvent::direction, tesla::FindBlock(), tesla::FindStateUpdateFn(), tesla::FunctionEvent::function, tesla::Automaton::getAssertion(), tesla::Automaton::ID(), tesla::MatchPattern(), tesla::Automaton::Name(), tesla::Automaton::String(), and tesla::TeslaContext().

75  {
76 
77  LLVMContext& Ctx = TargetFn->getContext();
78 
79  auto Fn = Ev.function();
80  assert(Fn.name() == TargetFn->getName());
81  assert(Ev.direction() == Dir);
82 
83  // An instrumentation function should be a linear chain of event pattern
84  // matchers and instrumentation blocks. Find the current end of this chain
85  // and insert the new instrumentation before it.
86  auto *Exit = FindBlock("exit", *InstrFn);
87  auto *Instr = BasicBlock::Create(Ctx, A.Name() + ":instr", InstrFn, Exit);
88  Exit->replaceAllUsesWith(Instr);
89 
90  // We may need to check constant values (e.g. return values).
91  size_t i = 0;
92  for (auto& InstrArg : InstrFn->getArgumentList()) {
93  const Argument& Arg = Ev.argument(i);
94  MatchPattern(Ctx, (A.Name() + ":match:arg" + Twine(i)).str(), InstrFn,
95  Instr, Exit, &InstrArg, Arg);
96 
97  // Ignore the return value, which passed as an argument to InstrFn.
98  if (++i == Ev.argument_size())
99  break;
100  }
101 
102  if (Dir == FunctionEvent::Exit && Ev.has_expectedreturnvalue()) {
103  const Argument &Arg = Ev.expectedreturnvalue();
104  Value *ReturnValue = --(InstrFn->arg_end());
105  MatchPattern(Ctx, A.Name() + ":match:retval", InstrFn,
106  Instr, Exit, ReturnValue, Arg);
107  }
108 
109  IRBuilder<> Builder(Instr);
110  Type* IntType = Type::getInt32Ty(Ctx);
111 
112  vector<Value*> Args;
113  Args.push_back(TeslaContext(A.getAssertion().context(), Ctx));
114  Args.push_back(ConstantInt::get(IntType, A.ID()));
115  Args.push_back(ConstructKey(Builder, M, InstrFn->getArgumentList(), Ev));
116  Args.push_back(Builder.CreateGlobalStringPtr(A.Name()));
117  Args.push_back(Builder.CreateGlobalStringPtr(A.String()));
118  Args.push_back(ConstructTransitions(Builder, M, Trans));
119 
120  Function *UpdateStateFn = FindStateUpdateFn(M, IntType);
121  assert(Args.size() == UpdateStateFn->arg_size());
122  Builder.CreateCall(UpdateStateFn, Args);
123  Builder.CreateBr(Exit);
124 }

+ Here is the call graph for this function:

Member Data Documentation

FunctionEvent::Direction tesla::FnInstrumentation::Dir
protected

Which way we instrument (in or out).

Definition at line 79 of file Instrumentation.h.

llvm::Function* tesla::FnInstrumentation::InstrFn
protected

The instrumentation function.

Definition at line 78 of file Instrumentation.h.

llvm::Module& tesla::FnInstrumentation::M
protected

The current module.

Definition at line 76 of file Instrumentation.h.

const llvm::Function* tesla::FnInstrumentation::TargetFn
protected

The function being instrumented.

Definition at line 77 of file Instrumentation.h.


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