13#ifndef LLVM_TRANSFORMS_IPO_INSTRUMENTOR_H
14#define LLVM_TRANSFORMS_IPO_INSTRUMENTOR_H
112 bool ForceIndirection);
191 return "module_post";
195 return "global_post";
197 return "function_pre";
199 return "function_post";
201 return "basic_block_pre";
203 return "basic_block_post";
205 return "instruction_pre";
207 return "instruction_post";
254 "Expected instruction!");
263 const unsigned Opcode = -1;
341 *
this,
"runtime_prefix",
"The runtime API prefix.",
"__instrumentor_");
343 *
this,
"target_regex",
344 "Regular expression to be matched against the module target. "
345 "Only targets that match this regex will be instrumented",
348 *
this,
"host_enabled",
"Instrument non-GPU targets",
true);
350 *
this,
"gpu_enabled",
"Instrument GPU targets",
true);
362 return (
getRTName() + Prefix + Name + Suffix1 + Suffix2).str();
375 template <
typename Ty,
typename... ArgsTy>
379 new (Obj) Ty(std::forward<ArgsTy>(Args)...);
482 "A unique ID associated with the given instrumentor call",
502 static int32_t GlobalId = 0;
503 int32_t &EpochId = EpochIdMap[CurrentEpoch];
505 EpochId = ++GlobalId;
513template <
unsigned Opcode>
596 for (
auto IsPRE : {
true,
false}) {
598 AIC->init(IConf, IIRB);
671 for (
auto IsPRE : {
true,
false}) {
673 AIC->init(IConf, IIRB);
686 InstrumentationConfig *UserIConf;
687 InstrumentorIRBuilderTy *UserIIRB;
690 InstrumentorIRBuilderTy &IIRB,
bool ReadConfig);
699 InstrumentorIRBuilderTy *IIRB =
nullptr)
700 : UserIConf(IC), UserIIRB(IIRB) {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines an array type that can be indexed using scoped enum values.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
ModuleAnalysisManager MAM
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
This class represents a function call, abstracting a target machine's calling convention.
A parsed version of the target data layout string in and methods for querying it.
Class to represent function types.
const char * getOpcodeName() const
InstrumentorPass(InstrumentationConfig *IC=nullptr, InstrumentorIRBuilderTy *IIRB=nullptr)
Construct an instrumentor pass that will use the instrumentation configuration IC and the IR builder ...
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Represent a constant reference to a string, i.e.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::function< Value *( Value &, Value &, InstrumentationConfig &, InstrumentorIRBuilderTy &)> SetterCallbackTy
std::function< Value *( Value &, Type &, InstrumentationConfig &, InstrumentorIRBuilderTy &)> GetterCallbackTy
Callback type for getting/setting a value for a instrumented opportunity.
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
A CRTP mix-in to automatically provide informational APIs needed for passes.
Boolean option bitset with a compile-time number of bits to store as many options as the enumeration ...
An option for the base configuration.
void setBool(bool B)
Set and get of the boolean value.
static BaseConfigurationOption * createStringOption(InstrumentationConfig &IC, StringRef Name, StringRef Description, StringRef DefaultValue)
Create a string option with Name name, Description description and DefaultValue as string default val...
static BaseConfigurationOption * createBoolOption(InstrumentationConfig &IC, StringRef Name, StringRef Description, bool DefaultValue)
Create a boolean option with Name name, Description description and DefaultValue as boolean default v...
BaseConfigurationOption(StringRef Name, StringRef Desc, KindTy Kind)
}
KindTy
The possible types of options.
StringRef getString() const
void setString(StringRef S)
}
GetterCallbackTy GetterCB
The callback for getting the value of the argument.
StringRef Description
A string with the description of the argument.
unsigned Flags
The flags that describe the properties of the argument.
Type * Ty
The type of the argument.
IRTArg(Type *Ty, StringRef Name, StringRef Description, unsigned Flags, GetterCallbackTy GetterCB, SetterCallbackTy SetterCB=nullptr, bool Enabled=true, bool NoCache=false)
Construct an argument.
bool Enabled
Whether the argument is enabled and should be passed to the function call.
SetterCallbackTy SetterCB
The callback for consuming the output value of the argument.
StringRef Name
A string with the name of the argument.
bool NoCache
Whether the argument value can be cached between the PRE and POST calls.
IRArgFlagTy
Flags describing the possible properties of an argument.
Helper to represent an instrumentation runtime function that is related to an instrumentation opportu...
bool isReplacable(IRTArg &IRTA) const
Return whether the IRTA argument can be replaced.
IRTCallDescription(InstrumentationOpportunity &IO, Type *RetTy=nullptr)
Construct an instrumentation function description linked to the IO instrumentation opportunity and Re...
bool MightRequireIndirection
Whether any argument may require indirection.
CallInst * createLLVMCall(Value *&V, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, const DataLayout &DL, InstrumentationCaches &ICaches)
Create a call instruction that calls to the instrumentation function and passes the corresponding arg...
Type * RetTy
The return type of the instrumentation function.
InstrumentationOpportunity & IO
The instrumentation opportunity which it is linked to.
FunctionType * createLLVMSignature(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, const DataLayout &DL, bool ForceIndirection)
Create the type of the instrumentation function.
unsigned NumReplaceableArgs
The number of arguments that can be replaced.
bool RequiresIndirection
Whether the function requires indirection in some argument.
bool isPotentiallyIndirect(IRTArg &IRTA) const
Return whether the function may have any indirect argument.
InstructionIO(bool IsPRE)
Construct an instruction opportunity.
StringRef getName() const override
Get the name of the instruction.
Helper that represent the caches for instrumentation call arguments.
The class that contains the configuration for the instrumentor.
virtual void populate(InstrumentorIRBuilderTy &IIRB)
Populate the instrumentation opportunities.
virtual ~InstrumentationConfig()
BaseConfigurationOption * GPUEnabled
void addChoice(InstrumentationOpportunity &IO, LLVMContext &Ctx)
Register instrumentation opportunity IO.
BaseConfigurationOption * TargetRegex
BaseConfigurationOption * HostEnabled
BumpPtrAllocator StringAllocator
Utilities for allocating and building strings.
std::string getRTName(StringRef Prefix, StringRef Name, StringRef Suffix1="", StringRef Suffix2="") const
Get the instrumentation function name.
StringRef getRTName() const
Get the runtime prefix for the instrumentation runtime functions.
void addBaseChoice(BaseConfigurationOption *BCO)
Add the base configuration option BCO into the list of base options.
static Ty * allocate(ArgsTy &&...Args)
Allocate an object of type Ty using a bump allocator and construct it with the Args arguments.
SmallVector< BaseConfigurationOption * > BaseConfigurationOptions
The list of enabled base configuration options.
InstrumentationConfig()
Construct an instrumentation configuration with the base options.
BaseConfigurationOption * RuntimePrefix
The base configuration options.
EnumeratedArray< StringMap< InstrumentationOpportunity * >, InstrumentationLocation::KindTy > IChoices
The map registered instrumentation opportunities.
Helper to represent an instrumentation location, which is composed of an instrumentation opportunity ...
unsigned getOpcode() const
Get the opcode of the instruction instrumentation location.
KindTy getKind() const
Return the type and position.
InstrumentationLocation(KindTy Kind)
Construct an instrumentation location that is not instrumenting an instruction.
static KindTy getKindFromStr(StringRef S)
Return the location kind described by a string.
static StringRef getKindStr(KindTy Kind)
Return the string representation given a location kind.
KindTy
The supported location kinds, which are composed of a opportunity type and position.
static bool isPRE(KindTy Kind)
Return whether a location kind is positioned before the event occurs.
bool isPRE() const
Return whether the instrumentation location is before the event occurs.
InstrumentationLocation(unsigned Opcode, bool IsPRE)
Construct an instrumentation location belonging to the instrumentation of an instruction.
Base class for instrumentation opportunities.
InstrumentationLocation::KindTy getLocationKind() const
Get the location kind of the instrumentation opportunity.
bool Enabled
Whether the opportunity is enabled.
static Value * getIdPre(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
Get the opportunity identifier for the pre and post positions.
static Value * forceCast(Value &V, Type &Ty, InstrumentorIRBuilderTy &IIRB)
Helpers to cast values, pass them to the runtime, and replace them.
static int32_t getIdFromEpoch(uint32_t CurrentEpoch)
}
std::function< bool(Value &)> CallbackTy
An optional callback that takes the value that is about to be instrumented and can return false if it...
static Value * getIdPost(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getValue(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
virtual Value * instrument(Value *&V, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, InstrumentationCaches &ICaches)
}
static Value * replaceValue(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
unsigned getOpcode() const
Get the opcode of the instruction instrumentation opportunity.
virtual StringRef getName() const =0
Get the name of the instrumentation opportunity.
InstrumentationLocation IP
The instrumentation location of the opportunity.
InstrumentationOpportunity(const InstrumentationLocation IP)
Construct an opportunity with location IP.
virtual ~InstrumentationOpportunity()
SmallVector< IRTArg > IRTArgs
The list of possible arguments for the instrumentation runtime function.
void addCommonArgs(InstrumentationConfig &IConf, LLVMContext &Ctx, bool PassId)
}
virtual Type * getRetTy(LLVMContext &Ctx) const
Get the return type for the instrumentation runtime function.
An IR builder augmented with extra information for the instrumentor pass.
IRBuilder< ConstantFolder, IRBuilderCallbackInserter > IRB
The underlying IR builder with insertion callback.
LoadIO(bool IsPRE)
Construct a load opportunity.
static Value * getValueSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getSyncScopeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getAtomicityOrdering(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
virtual Type * getValueType(InstrumentorIRBuilderTy &IIRB) const
}
static Value * getValue(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
ConfigKind
The selector of arguments for load opportunities.
static Value * getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getPointer(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
Getters and setters for the arguments of the instrumentation function for the load opportunity.
static Value * isVolatile(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * setPointer(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseConfigTy< ConfigKind > ConfigTy
static Value * getPointerAS(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
}
static Value * getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
Initialize the load opportunity using the instrumentation config IConf and the user config UserConfig...
static Value * getPointer(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
Getters and setters for the arguments of the instrumentation function for the store opportunity.
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
}
static Value * getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
virtual Type * getValueType(InstrumentorIRBuilderTy &IIRB) const
}
static Value * getSyncScopeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getPointerAS(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
ConfigKind
The selector of arguments for store opportunities.
static Value * getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getValue(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * setPointer(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * isVolatile(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getValueSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseConfigTy< ConfigKind > ConfigTy
void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
Initialize the store opportunity using the instrumentation config IConf and the user config UserConfi...
static Value * getAtomicityOrdering(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
StoreIO(bool IsPRE)
Construct a store instruction opportunity.
Helper union that holds any possible option type.