LLVM 23.0.0git
Instrumentor.h
Go to the documentation of this file.
1//===-- Instrumentor.h - Highly configurable instrumentation pass ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// The Instrumentor, a highly configurable instrumentation pass.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TRANSFORMS_IPO_INSTRUMENTOR_H
14#define LLVM_TRANSFORMS_IPO_INSTRUMENTOR_H
15
16#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/StringMap.h"
19#include "llvm/ADT/StringRef.h"
21#include "llvm/IR/Constants.h"
22#include "llvm/IR/DataLayout.h"
23#include "llvm/IR/IRBuilder.h"
24#include "llvm/IR/Instruction.h"
26#include "llvm/IR/LLVMContext.h"
27#include "llvm/IR/Module.h"
28#include "llvm/IR/PassManager.h"
34
35#include <cstdint>
36#include <functional>
37#include <string>
38#include <tuple>
39
40namespace llvm {
41namespace instrumentor {
42
45
46/// Callback type for getting/setting a value for a instrumented opportunity.
47///{
48using GetterCallbackTy = std::function<Value *(
50using SetterCallbackTy = std::function<Value *(
52///}
53
54/// Helper to represent an argument to an instrumentation runtime function.
55struct IRTArg {
56 /// Flags describing the possible properties of an argument.
58 NONE = 0,
59 STRING = 1 << 0,
60 REPLACABLE = 1 << 1,
65 };
66
67 /// Construct an argument.
74
75 /// Whether the argument is enabled and should be passed to the function call.
76 bool Enabled;
77
78 /// The type of the argument.
80
81 /// A string with the name of the argument.
83
84 /// A string with the description of the argument.
86
87 /// The flags that describe the properties of the argument. Multiple flags may
88 /// be specified.
89 unsigned Flags;
90
91 /// The callback for getting the value of the argument.
93
94 /// The callback for consuming the output value of the argument.
96
97 /// Whether the argument value can be cached between the PRE and POST calls.
98 bool NoCache;
99};
100
101/// Helper to represent an instrumentation runtime function that is related to
102/// an instrumentation opportunity.
104 /// Construct an instrumentation function description linked to the \p IO
105 /// instrumentation opportunity and \p RetTy return type.
107
108 /// Create the type of the instrumentation function.
111 const DataLayout &DL,
112 bool ForceIndirection);
113
114 /// Create a call instruction that calls to the instrumentation function and
115 /// passes the corresponding arguments.
118 InstrumentationCaches &ICaches);
119
120 /// Return whether the \p IRTA argument can be replaced.
121 bool isReplacable(IRTArg &IRTA) const {
123 }
124
125 /// Return whether the function may have any indirect argument.
126 bool isPotentiallyIndirect(IRTArg &IRTA) const {
127 return ((IRTA.Flags & IRTArg::POTENTIALLY_INDIRECT) ||
129 }
130
131 /// Whether the function requires indirection in some argument.
133
134 /// Whether any argument may require indirection.
136
137 /// The number of arguments that can be replaced.
138 unsigned NumReplaceableArgs = 0;
139
140 /// The instrumentation opportunity which it is linked to.
142
143 /// The return type of the instrumentation function.
144 Type *RetTy = nullptr;
145};
146
147/// Helper to represent an instrumentation location, which is composed of an
148/// instrumentation opportunity type and a position.
150 /// The supported location kinds, which are composed of a opportunity type and
151 /// position. The PRE position indicates the instrumentation function call is
152 /// inserted before the instrumented event occurs. The POST position indicates
153 /// the instrumentation call is inserted after the event occurs. Some
154 /// opportunity types may only support one position.
168
169 /// Construct an instrumentation location that is not instrumenting an
170 /// instruction.
171 InstrumentationLocation(KindTy Kind) : Kind(Kind) {
172 assert(Kind != INSTRUCTION_PRE && Kind != INSTRUCTION_POST &&
173 "Opcode required!");
174 }
175
176 /// Construct an instrumentation location belonging to the instrumentation of
177 /// an instruction.
178 InstrumentationLocation(unsigned Opcode, bool IsPRE)
179 : Kind(IsPRE ? INSTRUCTION_PRE : INSTRUCTION_POST), Opcode(Opcode) {}
180
181 /// Return the type and position.
182 KindTy getKind() const { return Kind; }
183
184 /// Return the string representation given a location kind. This is the string
185 /// used in the configuration file.
187 switch (Kind) {
188 case MODULE_PRE:
189 return "module_pre";
190 case MODULE_POST:
191 return "module_post";
192 case GLOBAL_PRE:
193 return "global_pre";
194 case GLOBAL_POST:
195 return "global_post";
196 case FUNCTION_PRE:
197 return "function_pre";
198 case FUNCTION_POST:
199 return "function_post";
200 case BASIC_BLOCK_PRE:
201 return "basic_block_pre";
202 case BASIC_BLOCK_POST:
203 return "basic_block_post";
204 case INSTRUCTION_PRE:
205 return "instruction_pre";
206 case INSTRUCTION_POST:
207 return "instruction_post";
208 }
209 llvm_unreachable("Invalid kind!");
210 }
211
212 /// Return the location kind described by a string.
214 return StringSwitch<KindTy>(S)
215 .Case("module_pre", MODULE_PRE)
216 .Case("module_post", MODULE_POST)
217 .Case("global_pre", GLOBAL_PRE)
218 .Case("global_post", GLOBAL_POST)
219 .Case("function_pre", FUNCTION_PRE)
220 .Case("function_post", FUNCTION_POST)
221 .Case("basic_block_pre", BASIC_BLOCK_PRE)
222 .Case("basic_block_post", BASIC_BLOCK_POST)
223 .Case("instruction_pre", INSTRUCTION_PRE)
224 .Case("instruction_post", INSTRUCTION_POST)
225 .Default(Last);
226 }
227
228 /// Return whether a location kind is positioned before the event occurs.
229 static bool isPRE(KindTy Kind) {
230 switch (Kind) {
231 case MODULE_PRE:
232 case GLOBAL_PRE:
233 case FUNCTION_PRE:
234 case BASIC_BLOCK_PRE:
235 case INSTRUCTION_PRE:
236 return true;
237 case MODULE_POST:
238 case GLOBAL_POST:
239 case FUNCTION_POST:
240 case BASIC_BLOCK_POST:
241 case INSTRUCTION_POST:
242 return false;
243 }
244 llvm_unreachable("Invalid kind!");
245 }
246
247 /// Return whether the instrumentation location is before the event occurs.
248 bool isPRE() const { return isPRE(Kind); }
249
250 /// Get the opcode of the instruction instrumentation location. This function
251 /// may not be called by a non-instruction instrumentation location.
252 unsigned getOpcode() const {
253 assert((Kind == INSTRUCTION_PRE || Kind == INSTRUCTION_POST) &&
254 "Expected instruction!");
255 return Opcode;
256 }
257
258private:
259 /// The kind (type and position) of the instrumentation location.
260 const KindTy Kind;
261
262 /// The opcode for instruction instrumentation locations.
263 const unsigned Opcode = -1;
264};
265
266/// An option for the base configuration.
268 /// The possible types of options.
273
274 /// Create a boolean option with \p Name name, \p Description description and
275 /// \p DefaultValue as boolean default value.
279 bool DefaultValue);
280
281 /// Create a string option with \p Name name, \p Description description and
282 /// \p DefaultValue as string default value.
286 StringRef DefaultValue);
287
288 /// Helper union that holds any possible option type.
289 union ValueTy {
290 bool Bool;
292 };
293
294 /// Set and get of the boolean value. Only valid if it is a boolean option.
295 ///{
296 void setBool(bool B) {
297 assert(Kind == BOOLEAN && "Not a boolean!");
298 Value.Bool = B;
299 }
300 bool getBool() const {
301 assert(Kind == BOOLEAN && "Not a boolean!");
302 return Value.Bool;
303 }
304 ///}
305
306 /// Set and get the string value. Only valid if it is a boolean option.
307 ///{
309 assert(Kind == STRING && "Not a string!");
310 Value.String = S;
311 }
313 assert(Kind == STRING && "Not a string!");
314 return Value.String;
315 }
316 ///}
317
318 /// The information of the option.
319 ///{
324 ///}
325
326 /// Construct a base configuration option.
329};
330
331/// The class that contains the configuration for the instrumentor. It holds the
332/// information for each instrumented opportunity, including the base
333/// configuration options. Another class may inherit from this one to modify the
334/// default behavior.
337
338 /// Construct an instrumentation configuration with the base options.
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",
346 "");
348 *this, "host_enabled", "Instrument non-GPU targets", true);
350 *this, "gpu_enabled", "Instrument GPU targets", true);
351 }
352
353 /// Populate the instrumentation opportunities.
354 virtual void populate(InstrumentorIRBuilderTy &IIRB);
355
356 /// Get the runtime prefix for the instrumentation runtime functions.
357 StringRef getRTName() const { return RuntimePrefix->getString(); }
358
359 /// Get the instrumentation function name.
360 std::string getRTName(StringRef Prefix, StringRef Name,
361 StringRef Suffix1 = "", StringRef Suffix2 = "") const {
362 return (getRTName() + Prefix + Name + Suffix1 + Suffix2).str();
363 }
364
365 /// Add the base configuration option \p BCO into the list of base options.
367 BaseConfigurationOptions.push_back(BCO);
368 }
369
370 /// Register instrumentation opportunity \p IO.
372
373 /// Allocate an object of type \p Ty using a bump allocator and construct it
374 /// with the \p Args arguments. The object may not be freed manually.
375 template <typename Ty, typename... ArgsTy>
376 static Ty *allocate(ArgsTy &&...Args) {
378 Ty *Obj = Allocator.Allocate();
379 new (Obj) Ty(std::forward<ArgsTy>(Args)...);
380 return Obj;
381 }
382
383 /// The list of enabled base configuration options.
385
386 /// The base configuration options.
391
392 /// The map registered instrumentation opportunities. The map is indexed by
393 /// the instrumentation location kind and then by the opportunity name. Notice
394 /// that an instrumentation location may have more than one instrumentation
395 /// opportunity registered.
399
400 /// Utilities for allocating and building strings.
401 ///{
404 ///}
405};
406
407/// Base class for instrumentation opportunities. All opportunities should
408/// inherit from this class and implement the virtual class members.
411
412 /// Construct an opportunity with location \p IP.
414
415 /// The instrumentation location of the opportunity.
417
418 /// The list of possible arguments for the instrumentation runtime function.
419 /// The order within the array determines the order of arguments. Arguments
420 /// may be disabled and will not be passed to the function call.
422
423 /// Whether the opportunity is enabled.
424 bool Enabled = true;
425
426 /// Helpers to cast values, pass them to the runtime, and replace them. To be
427 /// used as part of the getter/setter of a InstrumentationOpportunity.
428 ///{
429 static Value *forceCast(Value &V, Type &Ty, InstrumentorIRBuilderTy &IIRB);
432 return forceCast(V, Ty, IIRB);
433 }
434 static Value *replaceValue(Value &V, Value &NewV,
437 ///}
438
439 /// Instrument the value \p V using the configuration \p IConf, and
440 /// potentially, the caches \p ICaches.
443 InstrumentationCaches &ICaches) {
444 if (CB && !CB(*V))
445 return nullptr;
446
447 const DataLayout &DL = IIRB.IRB.GetInsertBlock()->getDataLayout();
448 IRTCallDescription IRTCallDesc(*this, getRetTy(V->getContext()));
449 auto *CI = IRTCallDesc.createLLVMCall(V, IConf, IIRB, DL, ICaches);
450 return CI;
451 }
452
453 /// Get the return type for the instrumentation runtime function.
454 virtual Type *getRetTy(LLVMContext &Ctx) const { return nullptr; }
455
456 /// Get the name of the instrumentation opportunity.
457 virtual StringRef getName() const = 0;
458
459 /// Get the opcode of the instruction instrumentation opportunity. Only valid
460 /// if it is instruction instrumentation.
461 unsigned getOpcode() const { return IP.getOpcode(); }
462
463 /// Get the location kind of the instrumentation opportunity.
465 return IP.getKind();
466 }
467
468 /// An optional callback that takes the value that is about to be
469 /// instrumented and can return false if it should be skipped.
470 ///{
471 using CallbackTy = std::function<bool(Value &)>;
472 CallbackTy CB = nullptr;
473 ///}
474
475 /// Add arguments available in all instrumentation opportunities.
477 bool PassId) {
478 const auto CB = IP.isPRE() ? getIdPre : getIdPost;
479 if (PassId) {
480 IRTArgs.push_back(
482 "A unique ID associated with the given instrumentor call",
483 IRTArg::NONE, CB, nullptr, true, true));
484 }
485 }
486
487 /// Get the opportunity identifier for the pre and post positions.
488 ///{
489 static Value *getIdPre(Value &V, Type &Ty, InstrumentationConfig &IConf,
491 static Value *getIdPost(Value &V, Type &Ty, InstrumentationConfig &IConf,
493 ///}
494
495 /// Compute the opportunity identifier for the current instrumentation epoch
496 /// \p CurrentEpoch. The identifiers are assigned consecutively as the epoch
497 /// advances. Epochs may have no identifier assigned (e.g., because no id was
498 /// requested). This function always returns the same identifier when called
499 /// multiple times with the same epoch.
500 static int32_t getIdFromEpoch(uint32_t CurrentEpoch) {
501 static DenseMap<uint32_t, int32_t> EpochIdMap;
502 static int32_t GlobalId = 0;
503 int32_t &EpochId = EpochIdMap[CurrentEpoch];
504 if (EpochId == 0)
505 EpochId = ++GlobalId;
506 return EpochId;
507 }
508};
509
510/// The base instrumentation opportunity class for instruction opportunities.
511/// Each instruction opportunity should inherit from this class and implement
512/// the virtual class members.
513template <unsigned Opcode>
515 virtual ~InstructionIO() {}
516
517 /// Construct an instruction opportunity.
520
521 /// Get the name of the instruction.
522 StringRef getName() const override {
523 return Instruction::getOpcodeName(Opcode);
524 }
525};
526
527/// The instrumentation opportunity for store instructions.
528struct StoreIO : public InstructionIO<Instruction::Store> {
529 virtual ~StoreIO() {};
530
531 /// Construct a store instruction opportunity.
532 StoreIO(bool IsPRE) : InstructionIO(IsPRE) {}
533
534 /// The selector of arguments for store opportunities.
535 ///{
550
553 ///}
554
555 /// Get the type of the stored value.
557 return IIRB.Int64Ty;
558 }
559
560 /// Initialize the store opportunity using the instrumentation config \p IConf
561 /// and the user config \p UserConfig.
563 ConfigTy *UserConfig = nullptr);
564
565 /// Getters and setters for the arguments of the instrumentation function for
566 /// the store opportunity.
567 ///{
568 static Value *getPointer(Value &V, Type &Ty, InstrumentationConfig &IConf,
570 static Value *setPointer(Value &V, Value &NewV, InstrumentationConfig &IConf,
572 static Value *getPointerAS(Value &V, Type &Ty, InstrumentationConfig &IConf,
574 static Value *getValue(Value &V, Type &Ty, InstrumentationConfig &IConf,
576 static Value *getValueSize(Value &V, Type &Ty, InstrumentationConfig &IConf,
578 static Value *getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf,
580 static Value *getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
582 static Value *getAtomicityOrdering(Value &V, Type &Ty,
585 static Value *getSyncScopeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
587 static Value *isVolatile(Value &V, Type &Ty, InstrumentationConfig &IConf,
589 ///}
590
591 /// Create the store opportunities for pre and post positions. The
592 /// opportunities are also initialized with the arguments for their
593 /// instrumentation calls.
594 static void populate(InstrumentationConfig &IConf,
596 for (auto IsPRE : {true, false}) {
597 auto *AIC = IConf.allocate<StoreIO>(IsPRE);
598 AIC->init(IConf, IIRB);
599 }
600 }
601};
602
603/// The instrumentation opportunity for load instructions.
604struct LoadIO : public InstructionIO<Instruction::Load> {
605 virtual ~LoadIO() {};
606
607 /// Construct a load opportunity.
608 LoadIO(bool IsPRE) : InstructionIO(IsPRE) {}
609
610 /// The selector of arguments for load opportunities.
611 ///{
627
630 ///}
631
632 /// Get the type of the loaded value.
634 return IIRB.Int64Ty;
635 }
636
637 /// Initialize the load opportunity using the instrumentation config \p IConf
638 /// and the user config \p UserConfig.
640 ConfigTy *UserConfig = nullptr);
641
642 /// Getters and setters for the arguments of the instrumentation function for
643 /// the load opportunity.
644 ///{
645 static Value *getPointer(Value &V, Type &Ty, InstrumentationConfig &IConf,
647 static Value *setPointer(Value &V, Value &NewV, InstrumentationConfig &IConf,
649 static Value *getPointerAS(Value &V, Type &Ty, InstrumentationConfig &IConf,
651 static Value *getValue(Value &V, Type &Ty, InstrumentationConfig &IConf,
653 static Value *getValueSize(Value &V, Type &Ty, InstrumentationConfig &IConf,
655 static Value *getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf,
657 static Value *getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
659 static Value *getAtomicityOrdering(Value &V, Type &Ty,
662 static Value *getSyncScopeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
664 static Value *isVolatile(Value &V, Type &Ty, InstrumentationConfig &IConf,
666 ///}
667
668 /// Create the store opportunities for PRE and POST positions.
669 static void populate(InstrumentationConfig &IConf,
671 for (auto IsPRE : {true, false}) {
672 auto *AIC = IConf.allocate<LoadIO>(IsPRE);
673 AIC->init(IConf, IIRB);
674 }
675 }
676};
677
678} // namespace instrumentor
679
680/// The Instrumentor pass.
681class InstrumentorPass : public PassInfoMixin<InstrumentorPass> {
682 using InstrumentationConfig = instrumentor::InstrumentationConfig;
683 using InstrumentorIRBuilderTy = instrumentor::InstrumentorIRBuilderTy;
684
685 /// The configuration and IR builder provided by the user.
686 InstrumentationConfig *UserIConf;
687 InstrumentorIRBuilderTy *UserIIRB;
688
689 PreservedAnalyses run(Module &M, InstrumentationConfig &IConf,
690 InstrumentorIRBuilderTy &IIRB, bool ReadConfig);
691
692public:
693 /// Construct an instrumentor pass that will use the instrumentation
694 /// configuration \p IC and the IR builder \p IIRB. If an IR builder is not
695 /// provided, a default builder is used. When the configuration is not
696 /// provided, it is read from the config file if available and otherwise a
697 /// default configuration is used.
698 InstrumentorPass(InstrumentationConfig *IC = nullptr,
699 InstrumentorIRBuilderTy *IIRB = nullptr)
700 : UserIConf(IC), UserIIRB(IIRB) {}
701
703};
704
705} // end namespace llvm
706
707#endif // LLVM_TRANSFORMS_IPO_INSTRUMENTOR_H
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
Basic Register Allocator
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.
Definition DataLayout.h:64
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.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
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.
Definition Allocator.h:390
Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition StringSaver.h:22
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.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:313
LLVM Value Representation.
Definition Value.h:75
#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.
Op::Description Desc
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1916
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:874
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition PassManager.h:89
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.
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.
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.
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.