LLVM 24.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/ArrayRef.h"
17#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/MapVector.h"
22#include "llvm/ADT/StringMap.h"
23#include "llvm/ADT/StringRef.h"
25#include "llvm/IR/Constants.h"
26#include "llvm/IR/DataLayout.h"
27#include "llvm/IR/IRBuilder.h"
28#include "llvm/IR/Instruction.h"
30#include "llvm/IR/LLVMContext.h"
31#include "llvm/IR/Module.h"
32#include "llvm/IR/PassManager.h"
38
39#include <cstdint>
40#include <functional>
41#include <memory>
42#include <string>
43#include <tuple>
44
45namespace llvm {
46namespace instrumentor {
47
50
51/// Callback type for getting/setting a value for a instrumented opportunity.
52///{
53using GetterCallbackTy = std::function<Value *(
55using SetterCallbackTy = std::function<Value *(
57///}
58
59/// Helper to represent an argument to an instrumentation runtime function.
60struct IRTArg {
61 /// Flags describing the possible properties of an argument.
63 NONE = 0,
64 STRING = 1 << 0,
65 REPLACABLE = 1 << 1,
69 VALUE_PACK = 1 << 5,
70 TYPEID = 1 << 6,
72 };
73
74 /// Construct an argument.
81
82 /// Whether the argument is enabled and should be passed to the function call.
83 bool Enabled;
84
85 /// The type of the argument.
87
88 /// A string with the name of the argument.
90
91 /// A string with the description of the argument.
93
94 /// The flags that describe the properties of the argument. Multiple flags may
95 /// be specified.
96 unsigned Flags;
97
98 /// The callback for getting the value of the argument.
100
101 /// The callback for consuming the output value of the argument.
103
104 /// Whether the argument value can be cached between the PRE and POST calls.
106};
107
108/// Helper to represent an instrumentation runtime function that is related to
109/// an instrumentation opportunity.
111 /// Construct an instrumentation function description linked to the \p IO
112 /// instrumentation opportunity and \p RetTy return type.
114 Type *RetTy = nullptr);
115
116 /// Create the type of the instrumentation function.
119 const DataLayout &DL,
120 bool ForceIndirection);
121
122 /// Create a call instruction that calls to the instrumentation function and
123 /// passes the corresponding arguments.
126 const DataLayout &DL,
127 InstrumentationCaches &ICaches);
128
129 /// Create a string representation of the function declaration in C. Two
130 /// strings are returned: the function definition with direct arguments and
131 /// the function with any indirect argument.
132 LLVM_ABI std::pair<std::string, std::string>
133 createCSignature(const InstrumentationConfig &IConf) const;
134
135 /// Create a string representation of the function definition in C. The
136 /// function body implements a stub and only prints the passed arguments. Two
137 /// strings are returned: the function definition with direct arguments and
138 /// the function with any indirect argument.
139 LLVM_ABI std::pair<std::string, std::string> createCBodies() const;
140
141 /// Return whether the \p IRTA argument can be replaced.
142 bool isReplacable(IRTArg &IRTA) const {
144 }
145
146 /// Return whether the function may have any indirect argument.
147 bool isPotentiallyIndirect(IRTArg &IRTA) const {
148 return ((IRTA.Flags & IRTArg::POTENTIALLY_INDIRECT) ||
150 }
151
152 /// Whether the function requires indirection in some argument.
154
155 /// Whether any argument may require indirection.
157
158 /// The number of arguments that can be replaced.
159 unsigned NumReplaceableArgs = 0;
160
161 /// The instrumentation opportunity which it is linked to.
163
164 /// The return type of the instrumentation function.
165 Type *RetTy = nullptr;
166};
167
168/// Helper to represent an instrumentation location, which is composed of an
169/// instrumentation opportunity type and a position.
171 /// The supported location kinds, which are composed of a opportunity type and
172 /// position. The PRE position indicates the instrumentation function call is
173 /// inserted before the instrumented event occurs. The POST position indicates
174 /// the instrumentation call is inserted after the event occurs. Some
175 /// opportunity types may only support one position.
190
191 /// Construct an instrumentation location with the given kind.
192 InstrumentationLocation(KindTy Kind) : Kind(Kind) {}
193
194 /// Return the type and position.
195 KindTy getKind() const { return Kind; }
196
197 /// Return the string representation given a location kind. This is the string
198 /// used in the configuration file.
200 switch (Kind) {
201 case MODULE_PRE:
202 return "module_pre";
203 case MODULE_POST:
204 return "module_post";
205 case GLOBAL_PRE:
206 return "global_pre";
207 case GLOBAL_POST:
208 return "global_post";
209 case FUNCTION_PRE:
210 return "function_pre";
211 case FUNCTION_POST:
212 return "function_post";
213 case BASIC_BLOCK_PRE:
214 return "basic_block_pre";
215 case BASIC_BLOCK_POST:
216 return "basic_block_post";
217 case INSTRUCTION_PRE:
218 return "instruction_pre";
219 case INSTRUCTION_POST:
220 return "instruction_post";
221 case SPECIAL_VALUE:
222 return "special_value";
223 }
224 llvm_unreachable("Invalid kind!");
225 }
226
227 /// Return the location kind described by a string.
229 return StringSwitch<KindTy>(S)
230 .Case("module_pre", MODULE_PRE)
231 .Case("module_post", MODULE_POST)
232 .Case("global_pre", GLOBAL_PRE)
233 .Case("global_post", GLOBAL_POST)
234 .Case("function_pre", FUNCTION_PRE)
235 .Case("function_post", FUNCTION_POST)
236 .Case("basic_block_pre", BASIC_BLOCK_PRE)
237 .Case("basic_block_post", BASIC_BLOCK_POST)
238 .Case("instruction_pre", INSTRUCTION_PRE)
239 .Case("instruction_post", INSTRUCTION_POST)
240 .Case("special_value", SPECIAL_VALUE)
241 .Default(Last);
242 }
243
244 /// Return whether a location kind is positioned before the event occurs.
245 static bool isPRE(KindTy Kind) {
246 switch (Kind) {
247 case MODULE_PRE:
248 case GLOBAL_PRE:
249 case FUNCTION_PRE:
250 case BASIC_BLOCK_PRE:
251 case INSTRUCTION_PRE:
252 return true;
253 case MODULE_POST:
254 case GLOBAL_POST:
255 case FUNCTION_POST:
256 case BASIC_BLOCK_POST:
257 case INSTRUCTION_POST:
258 case SPECIAL_VALUE:
259 return false;
260 }
261 llvm_unreachable("Invalid kind!");
262 }
263
264 /// Return whether the instrumentation location is before the event occurs.
265 bool isPRE() const { return isPRE(Kind); }
266
267private:
268 /// The kind (type and position) of the instrumentation location.
269 const KindTy Kind;
270};
271
272/// An option for the base configuration.
274 /// The possible types of options.
280
281 /// Create a boolean option with \p Name name, \p Description description and
282 /// \p DefaultValue as boolean default value.
283 LLVM_ABI static std::unique_ptr<BaseConfigurationOption>
285 StringRef Description, bool DefaultValue);
286
287 /// Create a string option with \p Name name, \p Description description and
288 /// \p DefaultValue as string default value.
289 LLVM_ABI static std::unique_ptr<BaseConfigurationOption>
291 StringRef Description, StringRef DefaultValue);
292
293 /// Create a string-list option with \p Name name, \p Description
294 /// description and \p DefaultValue as string-list default value.
295 LLVM_ABI static std::unique_ptr<BaseConfigurationOption>
298 ArrayRef<StringRef> DefaultValue);
299
300 /// Helper union that holds any possible option type.
301 union ValueTy {
302 bool Bool;
304 };
305
306 /// Set and get of the boolean value. Only valid if it is a boolean option.
307 ///{
308 void setBool(bool B) {
309 assert(Kind == BOOLEAN && "Not a boolean!");
310 Value.Bool = B;
311 }
312 bool getBool() const {
313 assert(Kind == BOOLEAN && "Not a boolean!");
314 return Value.Bool;
315 }
316 ///}
317
318 /// Set and get the string value. Only valid if it is a boolean option.
319 ///{
321 assert(Kind == STRING && "Not a string!");
322 Value.String = S;
323 }
325 assert(Kind == STRING && "Not a string!");
326 return Value.String;
327 }
328 ///}
329
330 /// Set and get of the string-list value. Only valid if it is a string-list
331 /// option.
332 ///{
334 assert(Kind == STRING_LIST && "Not a string list!");
335 StringList.assign(Values.begin(), Values.end());
336 }
338 assert(Kind == STRING_LIST && "Not a string list!");
339 return StringList;
340 }
341 ///}
342
343 /// The information of the option.
344 ///{
350 ///}
351
352 /// Construct a base configuration option.
355};
356
357/// The class that contains the configuration for the instrumentor. It holds the
358/// information for each instrumented opportunity, including the base
359/// configuration options. Another class may inherit from this one to modify the
360/// default behavior.
363
364 /// Construct an instrumentation configuration with the base options.
366
367 /// Initialize the config to a clean base state without loosing cached values
368 /// that can be reused across configurations.
370 // Clear previous configurations but not the caches.
372 for (auto &Map : IChoices)
373 Map.clear();
374
376 *this, "runtime_prefix", "The runtime API prefix.", "__instrumentor_");
378 *this, "runtime_stubs_file",
379 "The file into which runtime stubs should be written.", "");
381 *this, "target_regex",
382 "Regular expression to be matched against the module target. "
383 "Only targets that match this regex will be instrumented.",
384 "");
386 *this, "function_regex",
387 "Regular expression to be matched against a function name. "
388 "Only functions that match this regex will be instrumented.",
389 "");
391 *this, "demangle_function_names",
392 "Demangle functions names passed to the runtime.", true);
394 *this, "host_enabled", "Instrument non-GPU targets", true);
396 *this, "gpu_enabled", "Instrument GPU targets", true);
398 *this, "runtime_bitcodes", "Link runtime bitcode files", {});
400 *this, "inline_runtime", "Inline runtime function calls eagerly", true);
401 populate(IIRB);
402 }
403
404 /// Populate the instrumentation opportunities.
405 virtual void populate(InstrumentorIRBuilderTy &IIRB);
406
407 /// Get the runtime prefix for the instrumentation runtime functions.
408 StringRef getRTName() const { return RuntimePrefix->getString(); }
409
410 /// Get the instrumentation function name.
411 std::string getRTName(StringRef Prefix, StringRef Name,
412 StringRef Suffix1 = "", StringRef Suffix2 = "") const {
413 return (getRTName() + Prefix + Name + Suffix1 + Suffix2).str();
414 }
415
416 /// Add the base configuration option \p BCO into the list of base options.
418 BaseConfigurationOptions.push_back(BCO);
419 }
420
421 /// Register instrumentation opportunity \p IO.
422 void addChoice(InstrumentationOpportunity &IO, LLVMContext &Ctx);
423
424 /// Allocate an object of type \p Ty using a bump allocator and construct it
425 /// with the \p Args arguments. The object may not be freed manually.
426 template <typename Ty, typename... ArgsTy>
427 static Ty *allocate(ArgsTy &&...Args) {
429 Ty *Obj = Allocator.Allocate();
430 new (Obj) Ty(std::forward<ArgsTy>(Args)...);
431 return Obj;
432 }
433
434 /// Map to remember underlying objects for pointers.
436
437 /// Map to remember base pointer info for values in a specific function.
439
440 /// Return the base pointer info for \p V.
442
443 /// Mapping to remember global strings passed to the runtime.
445
446 /// Mapping from constants to globals with the constant as initializer.
448
450 Constant *&V = GlobalStringsMap[SS.save(S)];
451 if (!V) {
452 auto &M = *IIRB.IRB.getModule();
453 V = IIRB.IRB.CreateGlobalString(
454 S, getRTName() + ".str",
455 M.getDataLayout().getDefaultGlobalsAddressSpace(), &M);
456 if (V->getType() != IIRB.IRB.getPtrTy())
457 V = ConstantExpr::getAddrSpaceCast(V, IIRB.IRB.getPtrTy());
458 }
459 return V;
460 }
461 /// The list of enabled base configuration options.
463
464 /// The base configuration options.
465 std::unique_ptr<BaseConfigurationOption> RuntimePrefix;
466 std::unique_ptr<BaseConfigurationOption> RuntimeStubsFile;
467 std::unique_ptr<BaseConfigurationOption> DemangleFunctionNames;
468 std::unique_ptr<BaseConfigurationOption> TargetRegex;
469 std::unique_ptr<BaseConfigurationOption> FunctionRegex;
470 std::unique_ptr<BaseConfigurationOption> HostEnabled;
471 std::unique_ptr<BaseConfigurationOption> GPUEnabled;
472 std::unique_ptr<BaseConfigurationOption> RuntimeBitcodes;
473 std::unique_ptr<BaseConfigurationOption> InlineRuntimeEagerly;
474
475 /// The map registered instrumentation opportunities. The map is indexed by
476 /// the instrumentation location kind and then by the opportunity name. Notice
477 /// that an instrumentation location may have more than one instrumentation
478 /// opportunity registered.
482
483 /// Utilities for allocating and building strings.
484 ///{
487 ///}
488};
489
490/// Base class for instrumentation opportunities. All opportunities should
491/// inherit from this class and implement the virtual class members.
494
495 /// Construct an opportunity with location \p IP.
497
498 /// The instrumentation location of the opportunity.
500
501 /// The list of possible arguments for the instrumentation runtime function.
502 /// The order within the array determines the order of arguments. Arguments
503 /// may be disabled and will not be passed to the function call.
505
506 /// Flag names and their integer bitmask values.
508
509 /// Whether the opportunity is enabled.
510 bool Enabled = true;
511
512 /// A filter expression to be matched against runtime property values. If the
513 /// filter is non-empty, only instrumentations matching the filter will be
514 /// executed. The filter syntax supports:
515 /// - Integer comparisons: ==, !=, <, >, <=, >=
516 /// - String comparisons: ==, != (with quoted strings)
517 /// - String prefix check: startswith("prefix")
518 /// - Logical operators: &&, ||
519 /// Examples:
520 /// "sync_scope_id==3 && atomicity_ordering>0"
521 /// "name==\"foo\" || name.startswith(\"test_\")"
522 /// If a property value is dynamic (not a constant), the filter is assumed to
523 /// pass (true).
525
526 /// Helpers to cast values, pass them to the runtime, and replace them. To be
527 /// used as part of the getter/setter of a InstrumentationOpportunity.
528 ///{
529 LLVM_ABI static Value *forceCast(Value &V, Type &Ty,
533 return forceCast(V, Ty, IIRB);
534 }
535 LLVM_ABI static Value *replaceValue(Value &V, Value &NewV,
538 ///}
539
540 /// Instrument the value \p V using the configuration \p IConf, and
541 /// potentially, the caches \p ICaches.
542 virtual Value *instrument(Value *&V, bool &Changed,
545 InstrumentationCaches &ICaches) {
546 if (CB && !CB(*V))
547 return nullptr;
548
549 // Check if the filter matches before instrumenting
550 if (!evaluateFilter(*V, Changed, *this, IConf, IIRB))
551 return nullptr;
552
553 Changed = true;
554 const DataLayout &DL = IIRB.IRB.getDataLayout();
555 IRTCallDescription IRTCallDesc(*this, getRetTy(V->getContext()));
556 auto *CI = IRTCallDesc.createLLVMCall(V, IConf, IIRB, DL, ICaches);
557 return CI;
558 }
559
560 /// Get the return type for the instrumentation runtime function.
561 virtual Type *getRetTy(LLVMContext &Ctx) const { return nullptr; }
562
563 /// Get the name of the instrumentation opportunity.
564 virtual StringRef getName() const = 0;
565
566 /// Get all opcodes for this instrumentation opportunity. For non-instruction
567 /// opportunities, returns an empty array. For instruction opportunities,
568 /// returns an array of all opcodes this IO handles.
569 virtual ArrayRef<unsigned> getAllOpcodes() const { return {}; }
570
571 /// Get the location kind of the instrumentation opportunity.
573 return IP.getKind();
574 }
575
576 /// An optional callback that takes the value that is about to be
577 /// instrumented and can return false if it should be skipped.
578 ///{
579 using CallbackTy = std::function<bool(Value &)>;
580 CallbackTy CB = nullptr;
581 ///}
582
583 /// Add arguments available in all instrumentation opportunities.
585 bool PassId) {
586 const auto CB = IP.isPRE() ? getIdPre : getIdPost;
587 if (PassId) {
588 IRTArgs.push_back(
590 "A unique ID associated with the given instrumentor call",
591 IRTArg::NONE, CB, nullptr, true, true));
592 }
593 }
594
595 /// Get the opportunity identifier for the pre and post positions.
596 ///{
597 LLVM_ABI static Value *getIdPre(Value &V, Type &Ty,
600 LLVM_ABI static Value *getIdPost(Value &V, Type &Ty,
603 ///}
604
605 /// Compute the opportunity identifier for the current instrumentation epoch
606 /// \p CurrentEpoch. The identifiers are assigned consecutively as the epoch
607 /// advances. Epochs may have no identifier assigned (e.g., because no id was
608 /// requested). This function always returns the same identifier when called
609 /// multiple times with the same epoch.
610 static int32_t getIdFromEpoch(uint32_t CurrentEpoch) {
611 static DenseMap<uint32_t, int32_t> EpochIdMap;
612 static int32_t GlobalId = 0;
613 int32_t &EpochId = EpochIdMap[CurrentEpoch];
614 if (EpochId == 0)
615 EpochId = ++GlobalId;
616 return EpochId;
617 }
618};
619
620/// The base class that implements basic logic for any instruction
621/// instrumentation opportunity that inherits from InstructionIO.
647
648/// The common instrumentation opportunity class for instruction opportunities.
649/// Each instruction opportunity should inherit from this class and implement
650/// the virtual class members. If multiple opcodes are provided, all of them
651/// are instrumented using the same logic, and a name must be explicitly
652/// provided by overriding getName().
653template <unsigned... Opcodes> struct InstructionIO : public BaseInstructionIO {
654 virtual ~InstructionIO() {}
655
656 /// Construct an instruction opportunity.
658 : BaseInstructionIO(Kind) {
659 static_assert(sizeof...(Opcodes) >= 1,
660 "InstructionIO must have at least one opcode");
661 }
662
663 static constexpr std::array<unsigned, sizeof...(Opcodes)> OpcodesArray = {
664 Opcodes...};
665
666 /// Get all opcodes for this instrumentation opportunity (override).
667 ArrayRef<unsigned> getAllOpcodes() const override { return OpcodesArray; }
668
669 /// Get the number of opcodes.
670 static constexpr size_t getNumOpcodes() { return OpcodesArray.size(); }
671
672 /// Get the name of the instruction. For single-opcode IOs, this defaults to
673 /// the opcode name. For multi-opcode IOs, getName() MUST be overridden to
674 /// provide an explicit name identifying the whole group of opcodes.
675 virtual StringRef getName() const override {
676 // This method should not be called for multi-opcode IOs.
677 // Multi-opcode IOs must override getName().
678 assert(sizeof...(Opcodes) == 1 &&
679 "Multi-opcode InstructionIO must override getName() to provide an "
680 "explicit name instead of using the first opcode");
681 // Get the first opcode from the opcodes array.
683 }
684};
685
686/// The instrumentation opportunity for functions.
690
701
702 struct ConfigTy final : public BaseConfigTy<ConfigKind> {
703 std::function<bool(Argument &)> ArgFilter;
704
707
708 StringRef getName() const override { return "function"; }
709
712 ConfigTy *UserConfig = nullptr);
713
717 LLVM_ABI static Value *getFunctionName(Value &V, Type &Ty,
728 LLVM_ABI static Value *isMainFunction(Value &V, Type &Ty,
731
732 static void populate(InstrumentationConfig &IConf,
734 auto *PreIO =
736 PreIO->init(IConf, IIRB);
737 auto *PostIO =
739 PostIO->init(IConf, IIRB);
740 }
741};
742
743/// The instrumentation opportunity for alloca instructions.
744struct AllocaIO final : public InstructionIO<Instruction::Alloca> {
746
756
759
762 ConfigTy *UserConfig = nullptr);
763
764 LLVM_ABI static Value *getSize(Value &V, Type &Ty,
767 LLVM_ABI static Value *setSize(Value &V, Value &NewV,
770 LLVM_ABI static Value *getAlignment(Value &V, Type &Ty,
773
774 static void populate(InstrumentationConfig &IConf,
776 auto *PreIO =
778 PreIO->init(IConf, IIRB);
779 auto *PostIO =
781 PostIO->init(IConf, IIRB);
782 }
783};
784
785struct UnreachableIO final : public InstructionIO<Instruction::Unreachable> {
787 : InstructionIO<Instruction::Unreachable>(
788 InstrumentationLocation::INSTRUCTION_PRE) {}
789
794
797
800 ConfigTy *UserConfig = nullptr);
801
802 static void populate(InstrumentationConfig &IConf,
804 auto *PreIO = IConf.allocate<UnreachableIO>();
805 PreIO->init(IConf, IIRB);
806 }
807};
808
809// Special instrumentation opportunity for base pointers of memory operations.
814 virtual ~BasePointerIO() {};
815
822
825
826 StringRef getName() const override { return "base_pointer_info"; }
827
830 ConfigTy *UserConfig = nullptr);
831
832 LLVM_ABI static Value *getPointerKind(Value &V, Type &Ty,
835
836 /// This is necessary to produce a return value that can be used by other IOs.
837 /// No replacement is actually happening.
838 static Value *setValueNoop(Value &V, Value &NewV,
841 return &NewV;
842 }
843
844 static void populate(InstrumentationConfig &IConf,
846 auto *BPIO = IConf.allocate<BasePointerIO>();
847 BPIO->init(IConf, IIRB);
848 }
849};
850
851// Module instrumentation opportunity.
855
862
865
866 StringRef getName() const override { return "module"; }
867
870 ConfigTy *UserConfig = nullptr);
871
872 LLVM_ABI static Value *getModuleName(Value &V, Type &Ty,
875 LLVM_ABI static Value *getTargetTriple(Value &V, Type &Ty,
878
879 static void populate(InstrumentationConfig &IConf,
882 PreIO->init(IConf, IIRB);
883 auto *PostIO =
885 PostIO->init(IConf, IIRB);
886 }
887};
888
889// Global variable instrumentation opportunity.
893
907
910
911 StringRef getName() const override { return "global"; }
912
915 ConfigTy *UserConfig = nullptr);
916
917 LLVM_ABI static Value *getAddress(Value &V, Type &Ty,
920 LLVM_ABI static Value *setAddress(Value &V, Value &NewV,
923 LLVM_ABI static Value *getAS(Value &V, Type &Ty, InstrumentationConfig &IConf,
925 LLVM_ABI static Value *getDeclaredSize(Value &V, Type &Ty,
928 LLVM_ABI static Value *getAlignment(Value &V, Type &Ty,
931 LLVM_ABI static Value *getSymbolName(Value &V, Type &Ty,
934 LLVM_ABI static Value *getInitialValue(Value &V, Type &Ty,
937 LLVM_ABI static Value *isConstant(Value &V, Type &Ty,
940 LLVM_ABI static Value *isDefinition(Value &V, Type &Ty,
943
944 static void populate(InstrumentationConfig &IConf,
946 auto *PreIO =
948 PreIO->init(IConf, IIRB);
949 auto *PostIO =
951 PostIO->init(IConf, IIRB);
952 }
953};
954
955/// The instrumentation opportunity for store instructions.
956struct StoreIO : public InstructionIO<Instruction::Store> {
957 virtual ~StoreIO() {};
958
959 /// Construct a store instruction opportunity.
961
962 /// The selector of arguments for store opportunities.
963 ///{
980
983 ///}
984
985 /// Get the type of the stored value.
987 return IIRB.Int64Ty;
988 }
989
990 /// Initialize the store opportunity using the instrumentation config \p IConf
991 /// and the user config \p UserConfig.
994 ConfigTy *UserConfig = nullptr);
995
996 /// Getters and setters for the arguments of the instrumentation function for
997 /// the store opportunity.
998 ///{
999 LLVM_ABI static Value *getPointer(Value &V, Type &Ty,
1000 InstrumentationConfig &IConf,
1002 LLVM_ABI static Value *setPointer(Value &V, Value &NewV,
1003 InstrumentationConfig &IConf,
1005 LLVM_ABI static Value *getPointerAS(Value &V, Type &Ty,
1006 InstrumentationConfig &IConf,
1008 LLVM_ABI static Value *getBasePointerInfo(Value &V, Type &Ty,
1009 InstrumentationConfig &IConf,
1011 LLVM_ABI static Value *getValue(Value &V, Type &Ty,
1012 InstrumentationConfig &IConf,
1014 LLVM_ABI static Value *getValueSize(Value &V, Type &Ty,
1015 InstrumentationConfig &IConf,
1017 LLVM_ABI static Value *getAlignment(Value &V, Type &Ty,
1018 InstrumentationConfig &IConf,
1020 LLVM_ABI static Value *getValueTypeId(Value &V, Type &Ty,
1021 InstrumentationConfig &IConf,
1023 LLVM_ABI static Value *getValueSubTypeId(Value &V, Type &Ty,
1024 InstrumentationConfig &IConf,
1027 InstrumentationConfig &IConf,
1029 LLVM_ABI static Value *getSyncScopeId(Value &V, Type &Ty,
1030 InstrumentationConfig &IConf,
1032 LLVM_ABI static Value *isVolatile(Value &V, Type &Ty,
1033 InstrumentationConfig &IConf,
1035 ///}
1036
1037 /// Create the store opportunities for pre and post positions. The
1038 /// opportunities are also initialized with the arguments for their
1039 /// instrumentation calls.
1042 auto *PreIO =
1044 PreIO->init(IConf, IIRB);
1045 auto *PostIO =
1047 PostIO->init(IConf, IIRB);
1048 }
1049};
1050
1051/// The instrumentation opportunity for load instructions.
1052struct LoadIO : public InstructionIO<Instruction::Load> {
1053 virtual ~LoadIO() {};
1054
1055 /// Construct a load opportunity.
1057
1058 /// The selector of arguments for load opportunities.
1059 ///{
1077
1080 ///}
1081
1082 /// Get the type of the loaded value.
1084 return IIRB.Int64Ty;
1085 }
1086
1087 /// Initialize the load opportunity using the instrumentation config \p IConf
1088 /// and the user config \p UserConfig.
1091 ConfigTy *UserConfig = nullptr);
1092
1093 /// Getters and setters for the arguments of the instrumentation function for
1094 /// the load opportunity.
1095 ///{
1096 LLVM_ABI static Value *getPointer(Value &V, Type &Ty,
1097 InstrumentationConfig &IConf,
1099 LLVM_ABI static Value *setPointer(Value &V, Value &NewV,
1100 InstrumentationConfig &IConf,
1102 LLVM_ABI static Value *getPointerAS(Value &V, Type &Ty,
1103 InstrumentationConfig &IConf,
1105 LLVM_ABI static Value *getBasePointerInfo(Value &V, Type &Ty,
1106 InstrumentationConfig &IConf,
1108 LLVM_ABI static Value *getValue(Value &V, Type &Ty,
1109 InstrumentationConfig &IConf,
1111 LLVM_ABI static Value *getValueSize(Value &V, Type &Ty,
1112 InstrumentationConfig &IConf,
1114 LLVM_ABI static Value *getAlignment(Value &V, Type &Ty,
1115 InstrumentationConfig &IConf,
1117 LLVM_ABI static Value *getValueTypeId(Value &V, Type &Ty,
1118 InstrumentationConfig &IConf,
1120 LLVM_ABI static Value *getValueSubTypeId(Value &V, Type &Ty,
1121 InstrumentationConfig &IConf,
1124 InstrumentationConfig &IConf,
1126 LLVM_ABI static Value *getSyncScopeId(Value &V, Type &Ty,
1127 InstrumentationConfig &IConf,
1129 LLVM_ABI static Value *isVolatile(Value &V, Type &Ty,
1130 InstrumentationConfig &IConf,
1132 ///}
1133
1134 /// Create the load opportunities for PRE and POST positions.
1137 auto *PreIO =
1139 PreIO->init(IConf, IIRB);
1140 auto *PostIO =
1142 PostIO->init(IConf, IIRB);
1143 }
1144};
1145
1146/// The instrumentation opportunity for type cast instructions.
1147/// This includes PtrToInt, IntToPtr, Trunc, ZExt, SExt, FPToUI, FPToSI,
1148/// UIToFP, SIToFP, FPTrunc, FPExt, AddrSpaceCast, and BitCast.
1149struct CastIO final
1150 : public InstructionIO<
1151 Instruction::PtrToInt, Instruction::IntToPtr, Instruction::Trunc,
1152 Instruction::ZExt, Instruction::SExt, Instruction::FPToUI,
1153 Instruction::FPToSI, Instruction::UIToFP, Instruction::SIToFP,
1154 Instruction::FPTrunc, Instruction::FPExt, Instruction::AddrSpaceCast,
1155 Instruction::BitCast> {
1157
1172
1175
1176 StringRef getName() const override { return "cast"; }
1177
1180 ConfigTy *UserConfig = nullptr);
1181
1182 LLVM_ABI static Value *getInput(Value &V, Type &Ty,
1183 InstrumentationConfig &IConf,
1185 LLVM_ABI static Value *getInputTypeId(Value &V, Type &Ty,
1186 InstrumentationConfig &IConf,
1188 LLVM_ABI static Value *getInputSubTypeId(Value &V, Type &Ty,
1189 InstrumentationConfig &IConf,
1191 LLVM_ABI static Value *getInputSize(Value &V, Type &Ty,
1192 InstrumentationConfig &IConf,
1194 LLVM_ABI static Value *getResultTypeId(Value &V, Type &Ty,
1195 InstrumentationConfig &IConf,
1197 LLVM_ABI static Value *getResultSubTypeId(Value &V, Type &Ty,
1198 InstrumentationConfig &IConf,
1200 LLVM_ABI static Value *getResultSize(Value &V, Type &Ty,
1201 InstrumentationConfig &IConf,
1203
1206 auto *PreIO =
1208 PreIO->init(IConf, IIRB);
1209 auto *PostIO =
1211 PostIO->init(IConf, IIRB);
1212 }
1213};
1214
1215/// Instrumentation opportunity for numeric operations. This includes Add, FAdd,
1216/// Sub, FSub, Mul, FMul, UDiv, FDiv, SDiv, URem, SRem, FRem, Shl, LShr, AShr,
1217/// And, Or, Xor, and FNeg.
1218struct NumericIO final
1219 : public InstructionIO<
1220 Instruction::Add, Instruction::FAdd, Instruction::Sub,
1221 Instruction::FSub, Instruction::Mul, Instruction::FMul,
1222 Instruction::UDiv, Instruction::FDiv, Instruction::SDiv,
1223 Instruction::URem, Instruction::SRem, Instruction::FRem,
1224 Instruction::Shl, Instruction::LShr, Instruction::AShr,
1225 Instruction::And, Instruction::Or, Instruction::Xor,
1226 Instruction::FNeg> {
1228
1242
1245
1246 StringRef getName() const override { return "numeric"; }
1247
1250 ConfigTy *UserConfig = nullptr);
1251 LLVM_ABI void addFlagNames();
1252
1253 LLVM_ABI static Value *getFlags(Value &V, Type &Ty,
1254 InstrumentationConfig &IConf,
1256
1259 auto *PreIO =
1261 PreIO->init(IConf, IIRB);
1262 auto *PostIO =
1264 PostIO->init(IConf, IIRB);
1265 }
1266};
1267
1268struct CompareIO final
1269 : public InstructionIO<Instruction::ICmp, Instruction::FCmp> {
1271
1287
1290
1291 StringRef getName() const override { return "compare"; }
1292
1295 ConfigTy *UserConfig = nullptr);
1296 LLVM_ABI void addFlagNames();
1297
1298 LLVM_ABI static Value *getOperandTypeId(Value &V, Type &Ty,
1299 InstrumentationConfig &IConf,
1301 LLVM_ABI static Value *getOperandSize(Value &V, Type &Ty,
1302 InstrumentationConfig &IConf,
1304 LLVM_ABI static Value *getPredicate(Value &V, Type &Ty,
1305 InstrumentationConfig &IConf,
1307 LLVM_ABI static Value *getFlags(Value &V, Type &Ty,
1308 InstrumentationConfig &IConf,
1310
1313 auto *PreIO =
1315 PreIO->init(IConf, IIRB);
1316 auto *PostIO =
1318 PostIO->init(IConf, IIRB);
1319 }
1320};
1321
1322} // namespace instrumentor
1323
1324/// The Instrumentor pass.
1325class InstrumentorPass : public RequiredPassInfoMixin<InstrumentorPass> {
1326 using InstrumentationConfig = instrumentor::InstrumentationConfig;
1327 using InstrumentorIRBuilderTy = instrumentor::InstrumentorIRBuilderTy;
1328
1329 /// File system to be used for read operations.
1331
1332 /// The configuration and IR builder provided by the user.
1333 InstrumentationConfig *UserIConf;
1334 InstrumentorIRBuilderTy *UserIIRB;
1335
1336 PreservedAnalyses run(Module &M, InstrumentationConfig &IConf,
1337 InstrumentorIRBuilderTy &IIRB, bool ReadConfig);
1338
1339public:
1340 /// Construct an instrumentor pass that will use the instrumentation
1341 /// configuration \p IC and the IR builder \p IIRB. If an IR builder is not
1342 /// provided, a default builder is used. When the configuration is not
1343 /// provided, it is read from the config file if available and otherwise a
1344 /// default configuration is used.
1346 InstrumentationConfig *IC = nullptr,
1347 InstrumentorIRBuilderTy *IIRB = nullptr);
1348
1350};
1351
1352} // end namespace llvm
1353
1354#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")
#define LLVM_ABI
Definition Compiler.h:215
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.
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
This file implements a map that provides insertion order iteration.
ModuleAnalysisManager MAM
Basic Register Allocator
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is an important base class in LLVM.
Definition Constant.h:43
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
LLVM_ABI InstrumentorPass(IntrusiveRefCntPtr< vfs::FileSystem > FS=nullptr, InstrumentationConfig *IC=nullptr, InstrumentorIRBuilderTy *IIRB=nullptr)
Construct an instrumentor pass that will use the instrumentation configuration IC and the IR builder ...
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:71
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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:398
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:299
LLVM Value Representation.
Definition Value.h:75
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::function< Value *( Value &, Value &, InstrumentationConfig &, InstrumentorIRBuilderTy &)> SetterCallbackTy
LLVM_ABI bool evaluateFilter(Value &V, bool &Changed, InstrumentationOpportunity &IO, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
Evaluate the filter expression against the current instrumentation opportunity.
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.
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
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:1933
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
@ Enable
Enable colors.
Definition WithColor.h:47
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
A CRTP mix-in for passes that should not be skipped.
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
}
AllocaIO(InstrumentationLocation::KindTy Kind)
BaseConfigTy< ConfigKind > ConfigTy
static LLVM_ABI Value * getSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * setSize(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
Boolean option bitset with a compile-time number of bits to store as many options as the enumeration ...
An option for the base configuration.
ArrayRef< StringRef > getStringList() const
void setBool(bool B)
Set and get of the boolean value.
static LLVM_ABI std::unique_ptr< BaseConfigurationOption > createStringListOption(InstrumentationConfig &IC, StringRef Name, StringRef Description, ArrayRef< StringRef > DefaultValue)
Create a string-list option with Name name, Description description and DefaultValue as string-list d...
static LLVM_ABI std::unique_ptr< 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...
BaseConfigurationOption(StringRef Name, StringRef Desc, KindTy Kind)
}
KindTy
The possible types of options.
static LLVM_ABI std::unique_ptr< 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...
void setStringList(ArrayRef< StringRef > Values)
}
static LLVM_ABI Value * getOpcode(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getRightOperand(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getSubTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getTypeSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseInstructionIO(InstrumentationLocation::KindTy Kind)
static LLVM_ABI Value * getLeftOperand(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getPointerKind(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * setValueNoop(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
This is necessary to produce a return value that can be used by other IOs.
StringRef getName() const override
Get the name of the instrumentation opportunity.
BaseConfigTy< ConfigKind > ConfigTy
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
CastIO {.
static LLVM_ABI Value * getResultTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getInputSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getResultSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getResultSubTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getInput(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getInputSubTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseConfigTy< ConfigKind > ConfigTy
CastIO(InstrumentationLocation::KindTy Kind)
static LLVM_ABI Value * getInputTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
StringRef getName() const override
Get the name of the instruction.
static LLVM_ABI Value * getFlags(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getOperandSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getOperandTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseConfigTy< ConfigKind > ConfigTy
StringRef getName() const override
Get the name of the instruction.
static LLVM_ABI Value * getPredicate(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
CompareIO(InstrumentationLocation::KindTy Kind)
std::function< bool(Argument &)> ArgFilter
llvm::instrumentor::FunctionIO::ConfigTy Config
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
StringRef getName() const override
Get the name of the instrumentation opportunity.
LLVM_ABI Value * setArguments(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getFunctionAddress(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * isMainFunction(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
FunctionIO(InstrumentationLocation::KindTy Kind)
LLVM_ABI Value * getArguments(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI Value * getNumArguments(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getFunctionName(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
FunctionIO {.
static LLVM_ABI Value * setAddress(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
static LLVM_ABI Value * getAS(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getInitialValue(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * isDefinition(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getDeclaredSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
StringRef getName() const override
Get the name of the instrumentation opportunity.
static LLVM_ABI Value * getSymbolName(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getAddress(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
GlobalVarIO(InstrumentationLocation::KindTy Kind)
BaseConfigTy< ConfigKind > ConfigTy
static LLVM_ABI Value * isConstant(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
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.
LLVM_ABI 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.
LLVM_ABI std::pair< std::string, std::string > createCBodies() const
Create a string representation of the function definition in C.
LLVM_ABI 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.
LLVM_ABI FunctionType * createLLVMSignature(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, const DataLayout &DL, bool ForceIndirection)
Create the type of the instrumentation function.
LLVM_ABI std::pair< std::string, std::string > createCSignature(const InstrumentationConfig &IConf) const
Create a string representation of the function declaration in C.
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.
ArrayRef< unsigned > getAllOpcodes() const override
Get all opcodes for this instrumentation opportunity (override).
InstructionIO(InstrumentationLocation::KindTy Kind)
Construct an instruction opportunity.
static constexpr std::array< unsigned, sizeof...(Opcodes)> OpcodesArray
static constexpr size_t getNumOpcodes()
Get the number of opcodes.
virtual 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.
std::unique_ptr< BaseConfigurationOption > InlineRuntimeEagerly
Constant * getGlobalString(StringRef S, InstrumentorIRBuilderTy &IIRB)
DenseMap< Value *, Value * > UnderlyingObjsMap
Map to remember underlying objects for pointers.
std::unique_ptr< BaseConfigurationOption > HostEnabled
std::unique_ptr< BaseConfigurationOption > DemangleFunctionNames
void init(InstrumentorIRBuilderTy &IIRB)
Initialize the config to a clean base state without loosing cached values that can be reused across c...
DenseMap< std::pair< Value *, Function * >, Value * > BasePointerInfoMap
Map to remember base pointer info for values in a specific function.
EnumeratedArray< MapVector< StringRef, InstrumentationOpportunity * >, InstrumentationLocation::KindTy > IChoices
The map registered instrumentation opportunities.
std::unique_ptr< BaseConfigurationOption > GPUEnabled
std::unique_ptr< BaseConfigurationOption > RuntimeBitcodes
DenseMap< Constant *, GlobalVariable * > ConstantGlobalsCache
Mapping from constants to globals with the constant as initializer.
Value * getBasePointerInfo(Value &V, InstrumentorIRBuilderTy &IIRB)
Return the base pointer info for V.
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.
std::unique_ptr< BaseConfigurationOption > RuntimeStubsFile
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.
std::unique_ptr< BaseConfigurationOption > FunctionRegex
std::unique_ptr< BaseConfigurationOption > TargetRegex
std::unique_ptr< BaseConfigurationOption > RuntimePrefix
The base configuration options.
DenseMap< StringRef, Constant * > GlobalStringsMap
Mapping to remember global strings passed to the runtime.
Helper to represent an instrumentation location, which is composed of an instrumentation opportunity ...
KindTy getKind() const
Return the type and position.
InstrumentationLocation(KindTy Kind)
Construct an instrumentation location with the given kind.
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.
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 LLVM_ABI Value * getIdPre(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
Get the opportunity identifier for the pre and post positions.
virtual ArrayRef< unsigned > getAllOpcodes() const
Get all opcodes for this instrumentation opportunity.
virtual Value * instrument(Value *&V, bool &Changed, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, InstrumentationCaches &ICaches)
}
static LLVM_ABI 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 LLVM_ABI Value * getIdPost(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Value * getValue(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * replaceValue(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
StringMap< int32_t > FlagNames
Flag names and their integer bitmask values.
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.
StringRef Filter
A filter expression to be matched against runtime property values.
An IR builder augmented with extra information for the instrumentor pass.
IRBuilder< ConstantFolder, IRBuilderCallbackInserter > IRB
The underlying IR builder with insertion callback.
static LLVM_ABI Value * getValueSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getSyncScopeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getAtomicityOrdering(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
virtual Type * getValueType(InstrumentorIRBuilderTy &IIRB) const
}
static LLVM_ABI Value * getValueSubTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getValue(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
ConfigKind
The selector of arguments for load opportunities.
LoadIO(InstrumentationLocation::KindTy Kind)
Construct a load opportunity.
static LLVM_ABI Value * getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI 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 LLVM_ABI Value * isVolatile(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getBasePointerInfo(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * setPointer(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseConfigTy< ConfigKind > ConfigTy
static LLVM_ABI Value * getPointerAS(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
}
static LLVM_ABI Value * getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
Initialize the load opportunity using the instrumentation config IConf and the user config UserConfig...
static LLVM_ABI Value * getModuleName(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
ModuleIO(InstrumentationLocation::KindTy Kind)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getTargetTriple(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
BaseConfigTy< ConfigKind > ConfigTy
StringRef getName() const override
Get the name of the instrumentation opportunity.
StringRef getName() const override
Get the name of the instruction.
static LLVM_ABI Value * getFlags(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
}
NumericIO(InstrumentationLocation::KindTy Kind)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseConfigTy< ConfigKind > ConfigTy
static LLVM_ABI 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 LLVM_ABI Value * getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
virtual Type * getValueType(InstrumentorIRBuilderTy &IIRB) const
}
static LLVM_ABI Value * getSyncScopeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getPointerAS(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
ConfigKind
The selector of arguments for store opportunities.
static LLVM_ABI Value * getAlignment(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getValue(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * setPointer(Value &V, Value &NewV, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
StoreIO(InstrumentationLocation::KindTy Kind)
Construct a store instruction opportunity.
static LLVM_ABI Value * isVolatile(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getValueSize(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getValueSubTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
BaseConfigTy< ConfigKind > ConfigTy
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
Initialize the store opportunity using the instrumentation config IConf and the user config UserConfi...
static LLVM_ABI Value * getBasePointerInfo(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static LLVM_ABI Value * getAtomicityOrdering(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
UnreachableIO {.
BaseConfigTy< ConfigKind > ConfigTy
Helper union that holds any possible option type.