LLVM 24.0.0git
Instrumentor.cpp
Go to the documentation of this file.
1//===-- Instrumentor.cpp - 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 implementation of the Instrumentor, a highly configurable instrumentation
10// pass.
11//
12//===----------------------------------------------------------------------===//
13
15#include "IPOOptions.h"
19
21#include "llvm/ADT/STLExtras.h"
25#include "llvm/ADT/StringMap.h"
26#include "llvm/ADT/iterator.h"
29#include "llvm/IR/Constant.h"
30#include "llvm/IR/Constants.h"
31#include "llvm/IR/DataLayout.h"
34#include "llvm/IR/Dominators.h"
35#include "llvm/IR/Function.h"
36#include "llvm/IR/IRBuilder.h"
37#include "llvm/IR/InstrTypes.h"
38#include "llvm/IR/Instruction.h"
41#include "llvm/IR/Intrinsics.h"
42#include "llvm/IR/LLVMContext.h"
43#include "llvm/IR/Metadata.h"
44#include "llvm/IR/Module.h"
45#include "llvm/IR/PassManager.h"
46#include "llvm/IR/Verifier.h"
48#include "llvm/Linker/Linker.h"
50#include "llvm/Support/Regex.h"
56
57#include <cassert>
58#include <cstdint>
59#include <functional>
60#include <iterator>
61#include <memory>
62#include <string>
63#include <type_traits>
64
65using namespace llvm;
66using namespace llvm::instrumentor;
67
68#define DEBUG_TYPE "instrumentor"
69
70namespace {
71
72/// Set the debug location, if not set, after changing the insertion point of
73/// the IR builder \p IRB.
74template <typename IRBuilderTy> void ensureDbgLoc(IRBuilderTy &IRB) {
75 if (IRB.getCurrentDebugLocation())
76 return;
77 auto *BB = IRB.GetInsertBlock();
78 if (auto *SP = BB->getParent()->getSubprogram())
79 IRB.SetCurrentDebugLocation(DILocation::get(BB->getContext(), 0, 0, SP));
80}
81
82/// Attempt to cast \p V to type \p Ty using only bit-preserving casts.
83/// This ensures that floating-point values are converted via bitcast (not
84/// fptosi/fptoui) to preserve their exact bit representation.
85template <typename IRBTy>
86Value *tryToCast(IRBTy &IRB, Value *V, Type *Ty, const DataLayout &DL,
87 bool AllowTruncate = false) {
88 if (!V)
90 Type *VTy = V->getType();
91 if (VTy == Ty)
92 return V;
93 if (VTy->isAggregateType() || VTy->isVectorTy())
94 return V;
95 if (VTy->isPointerTy() && Ty->isPointerTy())
96 return IRB.CreatePointerBitCastOrAddrSpaceCast(V, Ty);
97 TypeSize RequestedSize = DL.getTypeSizeInBits(Ty);
98 TypeSize ValueSize = DL.getTypeSizeInBits(VTy);
99 bool ShouldTruncate = RequestedSize < ValueSize;
100 if (ShouldTruncate && !AllowTruncate)
101 return V;
102 if (ShouldTruncate && AllowTruncate) {
103 // First convert to integer of the same size if needed.
104 Value *IntV = V;
105 if (VTy->isFloatingPointTy())
106 IntV = IRB.CreateBitCast(V, IRB.getIntNTy(ValueSize));
107 return tryToCast(IRB,
108 IRB.CreateIntCast(IntV, IRB.getIntNTy(RequestedSize),
109 /*IsSigned=*/false),
110 Ty, DL, AllowTruncate);
111 }
112 if (VTy->isIntegerTy() && Ty->isIntegerTy())
113 return IRB.CreateIntCast(V, Ty, /*IsSigned=*/false);
114 // Use bit-preserving casts for floating-point values: convert float to int
115 // of the same size via bitcast, then extend/truncate the integer if needed.
116 if (VTy->isFloatingPointTy() && Ty->isIntOrPtrTy()) {
117 return tryToCast(IRB, IRB.CreateBitCast(V, IRB.getIntNTy(ValueSize)), Ty,
118 DL, AllowTruncate);
119 }
120 // When converting int to float, never use sitofp/uitofp as they perform value
121 // conversion, not bit-preserving cast.
122 if (VTy->isIntegerTy() && Ty->isFloatingPointTy()) {
123 if (ValueSize == RequestedSize)
124 return IRB.CreateBitCast(V, Ty);
125 return tryToCast(
126 IRB,
127 IRB.CreateIntCast(V, IRB.getIntNTy(RequestedSize), /*IsSigned=*/false),
128 Ty, DL, AllowTruncate);
129 }
130 return IRB.CreateBitOrPointerCast(V, Ty);
131}
132
133/// Get a constant integer/boolean of type \p IT and value \p Val.
134template <typename Ty>
135Constant *getCI(Type *IT, Ty Val, bool IsSigned = false) {
136 return ConstantInt::get(IT, Val, IsSigned);
137}
138
139Constant *getSubTypeID(Type &OpTy, Type &ReqTy) {
140 switch (OpTy.getTypeID()) {
141 case Type::TypeID::ArrayTyID:
142 case Type::TypeID::FixedVectorTyID:
143 case Type::TypeID::ScalableVectorTyID:
144 return getCI(&ReqTy, OpTy.getContainedType(0)->getTypeID());
145 default:
146 break;
147 }
148
149 return getCI(&ReqTy, -1, /*IsSigned=*/true);
150}
151
152/// The core of the instrumentor pass, which instruments the module as the
153/// instrumentation configuration mandates.
154class InstrumentorImpl final {
155public:
156 /// Construct an instrumentor implementation using the configuration \p IConf.
157 InstrumentorImpl(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB,
158 Module &M)
159 : IConf(IConf), M(M), IIRB(IIRB) {}
160
161 /// Instrument the module, public entry point.
162 bool instrument();
163
164 // Reset the state to allow reuse of the instrumentor with a different
165 // configuration.
166 void clear() {
167 InstChoicesPRE.clear();
168 InstChoicesPOST.clear();
169 ParsedFunctionRegex = Regex();
170 }
171
172private:
173 /// Link the runtime bitcodes into the module. Returns true if the module
174 /// was changed.
175 bool linkRuntime();
176
177 /// Indicate if the module should be instrumented based on the target.
178 bool shouldInstrumentTarget();
179
180 /// Indicate if the function \p Fn should be instrumented.
181 bool shouldInstrumentFunction(Function &Fn);
182 bool shouldInstrumentGlobalVariable(GlobalVariable &GV);
183
184 /// Instrument instruction \p I if needed, and use the argument caches in \p
185 /// ICaches.
186 bool instrumentInstruction(Instruction &I, InstrumentationCaches &ICaches);
187
188 /// Instrument function \p Fn.
189 bool instrumentFunction(Function &Fn);
190 bool instrumentModule();
191
192 /// The instrumentation opportunities for instructions indexed by
193 /// their opcode.
195 InstChoicesPOST;
196
197 /// The instrumentor configuration.
199
200 /// The function regex filter, if any.
201 Regex ParsedFunctionRegex;
202
203 /// The underlying module.
204 Module &M;
205
206protected:
207 /// A special IR builder that keeps track of the inserted instructions.
209};
210
211} // end anonymous namespace
212
214 if (!Str.empty()) {
215 Regex RX(Str);
216 std::string ErrMsg;
217 if (!RX.isValid(ErrMsg)) {
219 Twine("failed to parse ") + Name + " regex: " + ErrMsg, DS_Error));
220 return Regex();
221 }
222 return RX;
223 }
224 return Regex();
225}
226
227bool InstrumentorImpl::linkRuntime() {
228 ArrayRef<StringRef> RuntimeBitcodes = IConf.RuntimeBitcodes->getStringList();
229 if (RuntimeBitcodes.empty())
230 return false;
231
232 bool Changed = false;
233
234 for (StringRef RuntimeBitcode : RuntimeBitcodes) {
235 if (RuntimeBitcode.empty())
236 continue;
237
238 SMDiagnostic Err;
239 auto RTM = parseIRFile(RuntimeBitcode, Err, M.getContext());
240 if (!RTM) {
241 IIRB.Ctx.diagnose(DiagnosticInfoInstrumentation(
242 Twine("Failed to parse runtime bitcode file '") + RuntimeBitcode +
243 Twine("': ") + Err.getMessage(),
244 DS_Error));
245 return Changed;
246 }
247
248 if (Linker::linkModules(M, std::move(RTM))) {
249 IIRB.Ctx.diagnose(DiagnosticInfoInstrumentation(
250 Twine("Failed to link in runtime bitcode file '") + RuntimeBitcode +
251 "'",
252 DS_Error));
253 return Changed;
254 }
255 Changed = true;
256 }
257
258 if (!IConf.InlineRuntimeEagerly->getBool())
259 return Changed;
260
261 for (auto [I, _] : IIRB.NewInsts) {
262 auto *CI = dyn_cast<CallInst>(I);
263 if (!CI || isa<IntrinsicInst>(CI))
264 continue;
265
266 InlineFunctionInfo IFI;
267 auto InlineResult = InlineFunction(*CI, IFI);
268 if (!InlineResult.isSuccess()) {
269 std::string WarnMsg;
270 raw_string_ostream SS(WarnMsg);
271 SS << "Inlining of runtime call failed: "
272 << CI->getCalledFunction()->getName() << "\n";
273 SS << "Reason: " << InlineResult.getFailureReason() << "\n";
274 SS << "Signatures: " << *CI->getFunctionType() << " vs "
275 << *CI->getCalledFunction()->getFunctionType() << "\n";
276 IIRB.Ctx.diagnose(DiagnosticInfoInstrumentation(WarnMsg, DS_Warning));
277 }
278 }
279
280 // Promote any eligible instrumentor-associated allocas to registers.
281 for (auto It : IIRB.AllocaMap) {
282 auto *Fn = It.first.first;
283 DominatorTree DT(*Fn);
284 auto &Allocas = *It.second;
286 [](const AllocaInst *AI) { return !isAllocaPromotable(AI); });
288 delete It.second;
289 }
290 IIRB.AllocaMap.clear();
291 return Changed;
292}
293
294bool InstrumentorImpl::shouldInstrumentTarget() {
295 const Triple &T = M.getTargetTriple();
296 const bool IsGPU = T.isAMDGPU() || T.isNVPTX();
297
298 bool RegexMatches = true;
299 Regex RX = createRegex(IConf.TargetRegex->getString(), "target", IIRB.Ctx);
300 if (RX.isValid())
301 RegexMatches = RX.match(T.str());
302
303 // Only instrument the module if the target has to be instrumented.
304 return ((IsGPU && IConf.GPUEnabled->getBool()) ||
305 (!IsGPU && IConf.HostEnabled->getBool())) &&
306 RegexMatches;
307}
308
309bool InstrumentorImpl::shouldInstrumentFunction(Function &Fn) {
310 if (Fn.isDeclaration())
311 return false;
312 if (Fn.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
313 return false;
314 bool RegexMatches = true;
315 if (ParsedFunctionRegex.isValid())
316 RegexMatches = ParsedFunctionRegex.match(Fn.getName());
317 return (RegexMatches && !Fn.getName().starts_with(IConf.getRTName())) ||
318 Fn.hasFnAttribute("instrument");
319}
320
321bool InstrumentorImpl::shouldInstrumentGlobalVariable(GlobalVariable &GV) {
322 return !GV.getName().starts_with("llvm.") &&
323 !GV.getName().starts_with(IConf.getRTName());
324}
325
326bool InstrumentorImpl::instrumentInstruction(Instruction &I,
327 InstrumentationCaches &ICaches) {
328 bool Changed = false;
329
330 // Skip instrumentation instructions.
331 if (IIRB.NewInsts.contains(&I))
332 return Changed;
333
334 // Count epochs eagerly.
335 ++IIRB.Epoch;
336
337 Value *IPtr = &I;
338 if (auto *IO = InstChoicesPRE.lookup(I.getOpcode())) {
339 IIRB.IRB.SetInsertPoint(&I);
340 ensureDbgLoc(IIRB.IRB);
341 IO->instrument(IPtr, Changed, IConf, IIRB, ICaches);
342 }
343
344 if (auto *IO = InstChoicesPOST.lookup(I.getOpcode())) {
345 IIRB.IRB.SetInsertPoint(I.getNextNode());
346 ensureDbgLoc(IIRB.IRB);
347 IO->instrument(IPtr, Changed, IConf, IIRB, ICaches);
348 }
349 IIRB.returnAllocas();
350
351 return Changed;
352}
353
354bool InstrumentorImpl::instrumentFunction(Function &Fn) {
355 bool Changed = false;
356 if (!shouldInstrumentFunction(Fn))
357 return Changed;
358
359 InstrumentationCaches ICaches;
360 SmallVector<Instruction *> FinalTIs;
361 ReversePostOrderTraversal<Function *> RPOT(&Fn);
362 for (auto &It : RPOT) {
363 for (auto &I : *It)
364 Changed |= instrumentInstruction(I, ICaches);
365
366 auto *TI = It->getTerminator();
367 if (!TI->getNumSuccessors())
368 FinalTIs.push_back(TI);
369 }
370
371 Value *FPtr = &Fn;
372 for (auto &[Name, IO] :
374 if (!IO->Enabled)
375 continue;
376 // Count epochs eagerly.
377 ++IIRB.Epoch;
378
379 IIRB.IRB.SetInsertPoint(
380 cast<Function>(FPtr)->getEntryBlock().getFirstNonPHIOrAlloca());
381 ensureDbgLoc(IIRB.IRB);
382 IO->instrument(FPtr, Changed, IConf, IIRB, ICaches);
383 IIRB.returnAllocas();
384 }
385
386 for (auto &[Name, IO] :
388 if (!IO->Enabled)
389 continue;
390 // Count epochs eagerly.
391 ++IIRB.Epoch;
392
393 for (Instruction *FinalTI : FinalTIs) {
394 IIRB.IRB.SetInsertPoint(FinalTI);
395 ensureDbgLoc(IIRB.IRB);
396 IO->instrument(FPtr, Changed, IConf, IIRB, ICaches);
397 IIRB.returnAllocas();
398 }
399 }
400 return Changed;
401}
402
403bool InstrumentorImpl::instrumentModule() {
405 Globals.reserve(M.global_size());
406 for (GlobalVariable &GV : M.globals()) {
407 // llvm.metadata contains globals such as llvm.used.
408 if (GV.getSection() == "llvm.metadata" ||
409 GV.getName() == "llvm.global_dtors" ||
410 GV.getName() == "llvm.global_ctors")
411 continue;
412 Globals.push_back(&GV);
413 }
414
415 auto CreateYtor = [&](bool Ctor) {
416 Function *YtorFn = Function::Create(
417 FunctionType::get(IIRB.VoidTy, false), GlobalValue::PrivateLinkage,
418 IConf.getRTName(Ctor ? "ctor" : "dtor", ""), M);
419
420 auto *EntryBB = BasicBlock::Create(IIRB.Ctx, "entry", YtorFn);
421 IIRB.IRB.SetInsertPoint(EntryBB->begin());
422 ensureDbgLoc(IIRB.IRB);
423 IIRB.IRB.CreateRetVoid();
424
425 if (Ctor)
426 appendToGlobalCtors(M, YtorFn, 1000);
427 else
428 appendToGlobalDtors(M, YtorFn, 1000);
429 return YtorFn;
430 };
431
432 InstrumentationCaches ICaches;
433
434 Function *CtorFn = nullptr, *DtorFn = nullptr;
435 bool Changed = false;
438 bool IsPRE = InstrumentationLocation::isPRE(Loc);
439 Function *&YtorFn = IsPRE ? CtorFn : DtorFn;
440 for (auto &ChoiceIt : IConf.IChoices[Loc]) {
441 auto *IO = ChoiceIt.second;
442 if (!IO->Enabled)
443 continue;
444 if (!YtorFn) {
445 YtorFn = CreateYtor(IsPRE);
446 Changed = true;
447 }
448 IIRB.IRB.SetInsertPointPastAllocas(YtorFn);
449 ensureDbgLoc(IIRB.IRB);
450 Value *YtorPtr = YtorFn;
451
452 // Count epochs eagerly.
453 ++IIRB.Epoch;
454
455 IO->instrument(YtorPtr, Changed, IConf, IIRB, ICaches);
456 IIRB.returnAllocas();
457 }
458 }
459
462 bool IsPRE = InstrumentationLocation::isPRE(Loc);
463 Function *&YtorFn = IsPRE ? CtorFn : DtorFn;
464 for (auto &ChoiceIt : IConf.IChoices[Loc]) {
465 auto *IO = ChoiceIt.second;
466 if (!IO->Enabled)
467 continue;
468 if (!YtorFn) {
469 YtorFn = CreateYtor(IsPRE);
470 Changed = true;
471 }
472 for (GlobalVariable *GV : Globals) {
473 if (!shouldInstrumentGlobalVariable(*GV))
474 continue;
475 if (IsPRE)
476 IIRB.IRB.SetInsertPoint(YtorFn->getEntryBlock().getTerminator());
477 else
478 IIRB.IRB.SetInsertPointPastAllocas(YtorFn);
479 ensureDbgLoc(IIRB.IRB);
480 Value *GVPtr = GV;
481
482 // Count epochs eagerly.
483 ++IIRB.Epoch;
484
485 IO->instrument(GVPtr, Changed, IConf, IIRB, ICaches);
486 IIRB.returnAllocas();
487 }
488 }
489 }
490
491 return Changed;
492}
493
494bool InstrumentorImpl::instrument() {
495 bool Changed = false;
496 if (!shouldInstrumentTarget())
497 return Changed;
498
499 StringRef FunctionRegexStr = IConf.FunctionRegex->getString();
500 ParsedFunctionRegex = createRegex(FunctionRegexStr, "function", IIRB.Ctx);
501
502 // Helper to register an IO for all its opcodes.
503 auto RegisterForAllOpcodes = [](auto &InstChoices,
504 InstrumentationOpportunity *IO) {
505 ArrayRef<unsigned> Opcodes = IO->getAllOpcodes();
506 // Register for all opcodes.
507 for (unsigned Opcode : Opcodes)
508 InstChoices[Opcode] = IO;
509 };
510
511 for (auto &[Name, IO] :
513 if (IO->Enabled)
514 RegisterForAllOpcodes(InstChoicesPRE, IO);
515 for (auto &[Name, IO] :
517 if (IO->Enabled)
518 RegisterForAllOpcodes(InstChoicesPOST, IO);
519 Changed |= instrumentModule();
520
521 for (Function &Fn : M)
522 Changed |= instrumentFunction(Fn);
523
524 Changed |= linkRuntime();
525
526 return Changed;
527}
528
530 InstrumentationConfig *IC,
531 InstrumentorIRBuilderTy *IIRB)
532 : FS(FS), UserIConf(IC), UserIIRB(IIRB) {
533 if (!FS)
534 this->FS = vfs::getRealFileSystem();
535}
536
537PreservedAnalyses InstrumentorPass::run(Module &M, InstrumentationConfig &IConf,
539 bool ReadConfig) {
540 const IPOOptions &Opts = getIPOOptions(M);
541 bool Changed = false;
542 InstrumentorImpl Impl(IConf, IIRB, M);
543
544 // If this is a configuration driven run, iterate over all configurations
545 // provided by the user, if not, use the config as is and run the instrumentor
546 // once.
547 auto ConfigFiles =
548 to_vector_of<std::string>(Opts.instrumentor_read_config_files);
549 if (ReadConfig)
550 readConfigPathsFile(Opts.instrumentor_read_config_paths_file, ConfigFiles,
551 IIRB.Ctx, *FS);
552
553 bool MultipleConfigs = ConfigFiles.size() > 1;
554 unsigned Idx = 0;
555 do {
556 std::string ConfigFile =
557 ReadConfig && !ConfigFiles.empty() ? ConfigFiles[Idx] : "";
558
559 // Initialize the config to the base state but keep the caches around.
560 Impl.clear();
561 IConf.init(IIRB);
562
563 if (!readConfigFromJSON(IConf, ConfigFile, IIRB.Ctx, *FS))
564 continue;
565
567 IConf,
568 MultipleConfigs
569 ? (Opts.instrumentor_write_config_file + "." + std::to_string(Idx))
570 .str()
571 : Opts.instrumentor_write_config_file.str(),
572 IIRB.Ctx);
573
574 printRuntimeStub(IConf, IConf.RuntimeStubsFile->getString(), IIRB.Ctx);
575
576 Changed |= Impl.instrument();
577 } while (++Idx < ConfigFiles.size());
578
579 if (!Changed)
580 return PreservedAnalyses::all();
582}
583
585 // Only create them if the user did not provide them.
586 std::unique_ptr<InstrumentationConfig> IConfInt(
587 !UserIConf ? new InstrumentationConfig() : nullptr);
588 std::unique_ptr<InstrumentorIRBuilderTy> IIRBInt(
589 !UserIIRB ? new InstrumentorIRBuilderTy(M) : nullptr);
590
591 auto *IConf = IConfInt ? IConfInt.get() : UserIConf;
592 auto *IIRB = IIRBInt ? IIRBInt.get() : UserIIRB;
593
594 auto PA = run(M, *IConf, *IIRB, !UserIConf);
595
596 assert(!verifyModule(M, &errs()));
597 return PA;
598}
599
600std::unique_ptr<BaseConfigurationOption>
603 bool DefaultValue) {
604 auto BCO =
605 std::make_unique<BaseConfigurationOption>(Name, Description, BOOLEAN);
606 BCO->setBool(DefaultValue);
607 IConf.addBaseChoice(BCO.get());
608 return BCO;
609}
610
611std::unique_ptr<BaseConfigurationOption>
615 StringRef DefaultValue) {
616 auto BCO =
617 std::make_unique<BaseConfigurationOption>(Name, Description, STRING);
618 BCO->setString(DefaultValue);
619 IConf.addBaseChoice(BCO.get());
620 return BCO;
621}
622
623std::unique_ptr<BaseConfigurationOption>
626 ArrayRef<StringRef> DefaultValue) {
627 auto BCO =
628 std::make_unique<BaseConfigurationOption>(Name, Description, STRING_LIST);
629 BCO->setStringList(DefaultValue);
630 IConf.addBaseChoice(BCO.get());
631 return BCO;
632}
633
635 /// List of all instrumentation opportunities.
636 BasePointerIO::populate(*this, IIRB);
637 ModuleIO::populate(*this, IIRB);
638 GlobalVarIO::populate(*this, IIRB);
639 FunctionIO::populate(*this, IIRB);
640 AllocaIO::populate(*this, IIRB);
641 UnreachableIO::populate(*this, IIRB);
642 LoadIO::populate(*this, IIRB);
643 StoreIO::populate(*this, IIRB);
644 CastIO::populate(*this, IIRB);
645 NumericIO::populate(*this, IIRB);
646 CompareIO::populate(*this, IIRB);
647}
648
650 LLVMContext &Ctx) {
651 auto *&ICPtr = IChoices[IO.getLocationKind()][IO.getName()];
652 if (ICPtr) {
654 Twine("registered two instrumentation opportunities for the same "
655 "location (") +
656 ICPtr->getName() + Twine(" vs ") + IO.getName() + Twine(")"),
657 DS_Warning));
658 }
659 ICPtr = &IO;
660}
661
662Value *
665 Function *Fn = IIRB.IRB.GetInsertBlock()->getParent();
666
667 Value *Obj;
668 {
669 Value *&UnderlyingObj = UnderlyingObjsMap[&V];
670 if (!UnderlyingObj)
671 UnderlyingObj = const_cast<Value *>(getUnderlyingObjectAggressive(&V));
672 Obj = UnderlyingObj;
673 }
674
675 Value *&BPI = BasePointerInfoMap[{Obj, Fn}];
676 if (BPI)
677 return BPI;
678
679 auto *BPIO =
681 if (!BPIO || !BPIO->Enabled) {
683 "Base pointer info disabled but required, passing nullptr.",
684 DS_Warning));
685 return BPI = Constant::getNullValue(BPIO->getRetTy(IIRB.Ctx));
686 }
687
689 if (auto *BasePtrI = dyn_cast<Instruction>(Obj)) {
690 std::optional<BasicBlock::iterator> IP =
691 BasePtrI->getInsertionPointAfterDef();
692 if (IP) {
693 IIRB.IRB.SetInsertPoint(*IP);
694 } else {
696 "Base pointer info could not be placed, passing nullptr.",
697 DS_Warning));
698 return BPI = Constant::getNullValue(BPIO->getRetTy(IIRB.Ctx));
699 }
700 } else if (isa<Constant>(Obj) || isa<Argument>(Obj)) {
701 IIRB.IRB.SetInsertPointPastAllocas(IIRB.IRB.GetInsertBlock()->getParent());
702 } else {
703 LLVM_DEBUG(Obj->dump());
704 llvm_unreachable("Unexpected base pointer!");
705 }
706 ensureDbgLoc(IIRB.IRB);
707
708 // Use fresh caches for safety, as this function may be called from
709 // another instrumentation opportunity.
710 bool Changed;
711 InstrumentationCaches ICaches;
712 BPI = BPIO->instrument(Obj, Changed, *this, IIRB, ICaches);
713 IIRB.returnAllocas();
714 if (!BPI)
715 BPI = Constant::getNullValue(BPIO->getRetTy(IIRB.Ctx));
716 return BPI;
717}
718
722 return getCI(&Ty, getIdFromEpoch(IIRB.Epoch));
723}
724
728 return getCI(&Ty, -getIdFromEpoch(IIRB.Epoch), /*IsSigned=*/true);
729}
730
733 if (V.getType()->isVoidTy())
734 return Ty.isVoidTy() ? &V : Constant::getNullValue(&Ty);
735 return tryToCast(IIRB.IRB, &V, &Ty, IIRB.IRB.getDataLayout());
736}
737
741 if (V.getType()->isVoidTy())
742 return &V;
743
744 auto *NewVCasted = &NewV;
745 if (auto *I = dyn_cast<Instruction>(&NewV)) {
747 IIRB.IRB.SetInsertPoint(I->getNextNode());
748 ensureDbgLoc(IIRB.IRB);
749 NewVCasted = tryToCast(IIRB.IRB, &NewV, V.getType(), IIRB.DL,
750 /*AllowTruncate=*/true);
751 }
752 V.replaceUsesWithIf(NewVCasted, [&](Use &U) {
753 if (IIRB.NewInsts.lookup(cast<Instruction>(U.getUser())) == IIRB.Epoch)
754 return false;
755 return !isa<LifetimeIntrinsic>(U.getUser()) && !U.getUser()->isDroppable();
756 });
757
758 return &V;
759}
760
762 Type *RetTy)
763 : IO(IO), RetTy(RetTy) {
764 for (auto &It : IO.IRTArgs) {
765 if (!It.Enabled)
766 continue;
767 NumReplaceableArgs += bool(It.Flags & IRTArg::REPLACABLE);
768 MightRequireIndirection |= It.Flags & IRTArg::POTENTIALLY_INDIRECT;
769 }
772}
773
776 const DataLayout &DL, bool ForceIndirection) {
777 assert(((ForceIndirection && MightRequireIndirection) ||
778 (!ForceIndirection && !RequiresIndirection)) &&
779 "Wrong indirection setting!");
780
781 SmallVector<Type *> ParamTypes;
782 for (auto &It : IO.IRTArgs) {
783 if (!It.Enabled)
784 continue;
785 if (!ForceIndirection || !isPotentiallyIndirect(It)) {
786 ParamTypes.push_back(It.Ty);
787 if (!RetTy && NumReplaceableArgs == 1 && (It.Flags & IRTArg::REPLACABLE))
788 RetTy = It.Ty;
789 continue;
790 }
791
792 // The indirection pointer and the size of the value.
793 ParamTypes.push_back(IIRB.PtrTy);
794 if (!(It.Flags & IRTArg::INDIRECT_HAS_SIZE))
795 ParamTypes.push_back(IIRB.Int32Ty);
796 }
797 if (!RetTy)
798 RetTy = IIRB.VoidTy;
799
800 return FunctionType::get(RetTy, ParamTypes, /*isVarArg=*/false);
801}
802
806 const DataLayout &DL,
807 InstrumentationCaches &ICaches) {
808 SmallVector<Value *> CallParams;
809
811 auto IP = IIRB.IRB.GetInsertPoint();
812
813 bool ForceIndirection = RequiresIndirection;
814 for (auto &It : IO.IRTArgs) {
815 if (!It.Enabled)
816 continue;
817 auto *&Param = ICaches.DirectArgCache[{IIRB.Epoch, IO.getName(), It.Name}];
818 if (!Param || It.NoCache)
819 // Avoid passing the caches to the getter.
820 Param = It.GetterCB(*V, *It.Ty, IConf, IIRB);
821 assert(Param);
822
823 if (Param->getType()->isVoidTy()) {
824 Param = Constant::getNullValue(It.Ty);
825 } else if (Param->getType()->isAggregateType() ||
826 Param->getType()->isVectorTy() ||
827 DL.getTypeSizeInBits(Param->getType()) >
828 DL.getTypeSizeInBits(It.Ty)) {
829 if (!isPotentiallyIndirect(It)) {
831 Twine("indirection needed for ") + It.Name + Twine(" in ") +
832 IO.getName() +
833 Twine(", but not indicated. Instrumentation is skipped"),
834 DS_Warning));
835 return nullptr;
836 }
837 ForceIndirection = true;
838 } else {
839 Param = tryToCast(IIRB.IRB, Param, It.Ty, DL);
840 }
841 CallParams.push_back(Param);
842 }
843
844 if (ForceIndirection) {
845 Function *Fn = IIRB.IRB.GetInsertBlock()->getParent();
846
847 unsigned Offset = 0;
848 for (auto &It : IO.IRTArgs) {
849 if (!It.Enabled)
850 continue;
851
852 if (!isPotentiallyIndirect(It)) {
853 ++Offset;
854 continue;
855 }
856 auto *&CallParam = CallParams[Offset++];
857 if (!(It.Flags & IRTArg::INDIRECT_HAS_SIZE)) {
858 CallParams.insert(&CallParam + 1, IIRB.IRB.getInt32(DL.getTypeStoreSize(
859 CallParam->getType())));
860 Offset += 1;
861 }
862
863 auto *&CachedParam =
864 ICaches.IndirectArgCache[{IIRB.Epoch, IO.getName(), It.Name}];
865 if (CachedParam) {
866 CallParam = CachedParam;
867 continue;
868 }
869
870 auto *AI = IIRB.getAlloca(Fn, CallParam->getType());
871 IIRB.IRB.CreateStore(CallParam, AI);
872 CallParam = CachedParam = tryToCast(IIRB.IRB, AI, IIRB.PtrTy, DL);
873 }
874 }
875
876 if (!ForceIndirection)
877 IIRB.IRB.SetInsertPoint(IP);
878 ensureDbgLoc(IIRB.IRB);
879
880 auto *FnTy = createLLVMSignature(IConf, IIRB, DL, ForceIndirection);
881 auto CompleteName =
882 IConf.getRTName(IO.IP.isPRE() ? "pre_" : "post_", IO.getName(),
883 ForceIndirection ? "_ind" : "");
884 auto FC = IIRB.IRB.getModule()->getOrInsertFunction(CompleteName, FnTy);
885 auto *CI = IIRB.IRB.CreateCall(FC, CallParams);
886 CI->addFnAttr(Attribute::get(IIRB.Ctx, Attribute::WillReturn));
887
888 for (unsigned I = 0, E = IO.IRTArgs.size(); I < E; ++I) {
889 if (!IO.IRTArgs[I].Enabled)
890 continue;
891 if (!isReplacable(IO.IRTArgs[I]))
892 continue;
893 bool IsCustomReplaceable = IO.IRTArgs[I].Flags & IRTArg::REPLACABLE_CUSTOM;
894 Value *NewValue = FnTy->isVoidTy() || IsCustomReplaceable
895 ? ICaches.DirectArgCache[{IIRB.Epoch, IO.getName(),
896 IO.IRTArgs[I].Name}]
897 : CI;
898 assert(NewValue);
899 if (ForceIndirection && !IsCustomReplaceable &&
900 isPotentiallyIndirect(IO.IRTArgs[I])) {
901 auto *Q =
902 ICaches
903 .IndirectArgCache[{IIRB.Epoch, IO.getName(), IO.IRTArgs[I].Name}];
904 NewValue = IIRB.IRB.CreateLoad(V->getType(), Q);
905 }
906 V = IO.IRTArgs[I].SetterCB(*V, *NewValue, IConf, IIRB);
907 }
908 return CI;
909}
910
911template <typename Ty> constexpr static Value *getValue(Ty &ValueOrUse) {
912 if constexpr (std::is_same<Ty, Use>::value)
913 return ValueOrUse.get();
914 else
915 return static_cast<Value *>(&ValueOrUse);
916}
917
918template <typename Range>
921 auto *Fn = IIRB.IRB.GetInsertBlock()->getParent();
922 auto *I32Ty = IIRB.IRB.getInt32Ty();
923 SmallVector<Constant *> ConstantValues;
926 for (auto &RE : R) {
927 Value *V = getValue(RE);
928 if (!V->getType()->isSized())
929 continue;
930 auto VSize = IIRB.DL.getTypeAllocSize(V->getType());
931 ConstantValues.push_back(getCI(I32Ty, VSize));
932 Types.push_back(I32Ty);
933 ConstantValues.push_back(getCI(I32Ty, V->getType()->getTypeID()));
934 Types.push_back(I32Ty);
935 if (uint32_t MisAlign = VSize % 8) {
936 Types.push_back(ArrayType::get(IIRB.Int8Ty, 8 - MisAlign));
937 ConstantValues.push_back(ConstantArray::getNullValue(Types.back()));
938 }
939 Types.push_back(V->getType());
940 if (auto *C = dyn_cast<Constant>(V)) {
941 ConstantValues.push_back(C);
942 continue;
943 }
944 Values.push_back({V, ConstantValues.size()});
945 ConstantValues.push_back(Constant::getNullValue(V->getType()));
946 }
947 if (Types.empty())
948 return ConstantPointerNull::get(IIRB.PtrTy);
949
950 StructType *STy = StructType::get(Fn->getContext(), Types, /*isPacked=*/true);
951 Constant *Initializer = ConstantStruct::get(STy, ConstantValues);
952
953 GlobalVariable *&GV = IConf.ConstantGlobalsCache[Initializer];
954 if (!GV)
955 GV = new GlobalVariable(*Fn->getParent(), STy, false,
956 GlobalValue::InternalLinkage, Initializer,
957 IConf.getRTName("", "value_pack"));
958
959 auto *AI = IIRB.getAlloca(Fn, STy);
960 IIRB.IRB.CreateMemCpy(AI, AI->getAlign(), GV, GV->getAlign(),
961 IIRB.DL.getTypeAllocSize(STy));
962 for (auto [Param, Idx] : Values) {
963 auto *Ptr = IIRB.IRB.CreateStructGEP(STy, AI, Idx);
964 IIRB.IRB.CreateStore(Param, Ptr);
965 }
966 return AI;
967}
968
969template <typename Range>
970static void readValuePack(const Range &R, Value &Pack,
972 function_ref<void(int, Value *)> SetterCB) {
973 auto *Fn = IIRB.IRB.GetInsertBlock()->getParent();
974 auto &DL = Fn->getDataLayout();
975 unsigned Offset = 0;
976 for (const auto &[Idx, RE] : enumerate(R)) {
977 Value *V = getValue(RE);
978 if (!V->getType()->isSized())
979 continue;
980 Offset += 8;
981 auto VSize = DL.getTypeAllocSize(V->getType());
982 auto Padding = alignTo(VSize, 8) - VSize;
983 Offset += Padding;
984 auto *Ptr = IIRB.IRB.CreateConstInBoundsGEP1_32(IIRB.Int8Ty, &Pack, Offset);
985 auto *NewV = IIRB.IRB.CreateLoad(V->getType(), Ptr);
986 SetterCB(Idx, NewV);
987 Offset += VSize;
988 }
989}
990
994 auto &I = cast<Instruction>(V);
995 return getCI(&Ty, I.getOpcode());
996}
997
1001 auto &I = cast<Instruction>(V);
1002 auto &DL = I.getDataLayout();
1003 return getCI(&Ty, DL.getTypeStoreSize(V.getType()));
1004}
1005
1007 InstrumentationConfig &IConf,
1009 auto &I = cast<Instruction>(V);
1010 return I.getOperand(0);
1011}
1012
1014 InstrumentationConfig &IConf,
1016 auto &I = cast<Instruction>(V);
1017 if (I.getNumOperands() > 1)
1018 return I.getOperand(1);
1019 return PoisonValue::get(&Ty);
1020}
1021
1023 InstrumentationConfig &IConf,
1025 return getCI(&Ty, V.getType()->getTypeID());
1026}
1027
1029 InstrumentationConfig &IConf,
1031 return getSubTypeID(*V.getType(), Ty);
1032}
1033
1034/// FunctionIO
1035/// {
1037 InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig) {
1038 using namespace std::placeholders;
1039 if (UserConfig)
1040 Config = *UserConfig;
1041
1043 if (Config.has(PassAddress))
1044 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "address", "The function address.",
1046 if (Config.has(PassName))
1047 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "name", "The function name.",
1049 if (Config.has(PassNumArguments))
1050 IRTArgs.push_back(
1051 IRTArg(IIRB.Int32Ty, "num_arguments",
1052 "Number of function arguments (without varargs).", IRTArg::NONE,
1053 std::bind(&FunctionIO::getNumArguments, this, _1, _2, _3, _4)));
1054 if (Config.has(PassArguments))
1055 IRTArgs.push_back(IRTArg(
1056 IIRB.PtrTy, "arguments", "Description of the arguments.",
1058 : IRTArg::NONE) |
1060 std::bind(&FunctionIO::getArguments, this, _1, _2, _3, _4),
1061 std::bind(&FunctionIO::setArguments, this, _1, _2, _3, _4)));
1062 if (Config.has(PassIsMain))
1063 IRTArgs.push_back(IRTArg(IIRB.Int8Ty, "is_main",
1064 "Flag to indicate it is the main function.",
1066 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1067 IConf.addChoice(*this, IIRB.Ctx);
1068}
1069
1071 InstrumentationConfig &IConf,
1073 auto &Fn = cast<Function>(V);
1074 if (Fn.isIntrinsic())
1075 return Constant::getNullValue(&Ty);
1076 return &V;
1077}
1079 InstrumentationConfig &IConf,
1081 auto &Fn = cast<Function>(V);
1082 return IConf.getGlobalString(IConf.DemangleFunctionNames->getBool()
1083 ? demangle(Fn.getName())
1084 : Fn.getName(),
1085 IIRB);
1086}
1088 InstrumentationConfig &IConf,
1090 auto &Fn = cast<Function>(V);
1091 if (!Config.ArgFilter)
1092 return getCI(&Ty, Fn.arg_size());
1093 auto FRange = make_filter_range(Fn.args(), Config.ArgFilter);
1094 return getCI(&Ty, std::distance(FRange.begin(), FRange.end()));
1095}
1097 InstrumentationConfig &IConf,
1099 auto &Fn = cast<Function>(V);
1100 if (!Config.ArgFilter)
1101 return createValuePack(Fn.args(), IConf, IIRB);
1102 return createValuePack(make_filter_range(Fn.args(), Config.ArgFilter), IConf,
1103 IIRB);
1104}
1106 InstrumentationConfig &IConf,
1108 auto &Fn = cast<Function>(V);
1109 auto *AIt = Fn.arg_begin();
1110 auto CB = [&](int Idx, Value *ReplV) {
1111 while (Config.ArgFilter && !Config.ArgFilter(*AIt))
1112 ++AIt;
1113 Fn.getArg(Idx)->replaceUsesWithIf(ReplV, [&](Use &U) {
1114 return IIRB.NewInsts.lookup(cast<Instruction>(U.getUser())) != IIRB.Epoch;
1115 });
1116 ++AIt;
1117 };
1118 if (!Config.ArgFilter)
1119 readValuePack(Fn.args(), NewV, IIRB, CB);
1120 else
1121 readValuePack(make_filter_range(Fn.args(), Config.ArgFilter), NewV, IIRB,
1122 CB);
1123 return &Fn;
1124}
1126 InstrumentationConfig &IConf,
1128 auto &Fn = cast<Function>(V);
1129 return getCI(&Ty, Fn.getName() == "main");
1130}
1131
1132/// UnreachableIO
1133///{
1135 InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig) {
1136 if (UserConfig)
1137 Config = *UserConfig;
1138 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1139 IConf.addChoice(*this, IIRB.Ctx);
1140}
1141///}
1142
1143/// AllocaIO
1144///{
1146 ConfigTy *UserConfig) {
1147 if (UserConfig)
1148 Config = *UserConfig;
1149
1151 if (!IsPRE && Config.has(PassAddress))
1152 IRTArgs.push_back(
1153 IRTArg(IIRB.PtrTy, "address", "The allocated memory address.",
1157 if (Config.has(PassSize))
1158 IRTArgs.push_back(IRTArg(
1159 IIRB.Int64Ty, "size", "The allocation size.",
1161 getSize, setSize));
1162 if (Config.has(PassAlignment))
1163 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "alignment",
1164 "The allocation alignment.", IRTArg::NONE,
1165 getAlignment));
1166
1167 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1168 IConf.addChoice(*this, IIRB.Ctx);
1169}
1170
1173 auto &AI = cast<AllocaInst>(V);
1174 return IIRB.IRB.CreateAllocationSize(&Ty, &AI);
1175}
1176
1179 auto &AI = cast<AllocaInst>(V);
1180 const DataLayout &DL = AI.getDataLayout();
1181 auto *NewAI = IIRB.IRB.CreateAlloca(IIRB.IRB.getInt8Ty(),
1182 DL.getAllocaAddrSpace(), &NewV);
1183 NewAI->setAlignment(AI.getAlign());
1184 AI.replaceAllUsesWith(NewAI);
1185 IIRB.eraseLater(&AI);
1186 return NewAI;
1187}
1188
1191 return getCI(&Ty, cast<AllocaInst>(V).getAlign().value());
1192}
1193///}
1194
1196 ConfigTy *UserConfig) {
1197 if (UserConfig)
1198 Config = *UserConfig;
1199
1201 if (Config.has(PassPointer)) {
1202 IRTArgs.push_back(
1203 IRTArg(IIRB.PtrTy, "pointer", "The accessed pointer.",
1204 ((IsPRE && Config.has(ReplacePointer)) ? IRTArg::REPLACABLE
1205 : IRTArg::NONE),
1207 }
1208 if (Config.has(PassPointerAS)) {
1209 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "pointer_as",
1210 "The address space of the accessed pointer.",
1212 }
1213 if (Config.has(PassBasePointerInfo)) {
1214 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "base_pointer_info",
1215 "The runtime provided base pointer info.",
1217 }
1218 if (Config.has(PassStoredValue)) {
1219 IRTArgs.push_back(
1220 IRTArg(getValueType(IIRB), "value", "The stored value.",
1223 : IRTArg::NONE),
1224 getValue));
1225 }
1226 if (Config.has(PassStoredValueSize)) {
1227 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "value_size",
1228 "The size of the stored value.", IRTArg::NONE,
1229 getValueSize));
1230 }
1231 if (Config.has(PassAlignment)) {
1232 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "alignment",
1233 "The known access alignment.", IRTArg::NONE,
1234 getAlignment));
1235 }
1236 if (Config.has(PassValueTypeId)) {
1237 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "value_type_id",
1238 "The type id of the stored value.", IRTArg::TYPEID,
1240 }
1241 if (Config.has(PassValueSubTypeId)) {
1242 IRTArgs.push_back(IRTArg(
1243 IIRB.Int32Ty, "value_sub_type_id",
1244 "The type id of the stored value (for arrays and vectors, or -1).",
1246 }
1247 if (Config.has(PassAtomicityOrdering)) {
1248 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "atomicity_ordering",
1249 "The atomicity ordering of the store.",
1251 }
1252 if (Config.has(PassSyncScopeId)) {
1253 IRTArgs.push_back(IRTArg(IIRB.Int8Ty, "sync_scope_id",
1254 "The sync scope id of the store.", IRTArg::NONE,
1256 }
1257 if (Config.has(PassIsVolatile)) {
1258 IRTArgs.push_back(IRTArg(IIRB.Int8Ty, "is_volatile",
1259 "Flag indicating a volatile store.", IRTArg::NONE,
1260 isVolatile));
1261 }
1262
1263 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1264 IConf.addChoice(*this, IIRB.Ctx);
1265}
1266
1269 auto &SI = cast<StoreInst>(V);
1270 return SI.getPointerOperand();
1271}
1272
1275 auto &SI = cast<StoreInst>(V);
1276 SI.setOperand(SI.getPointerOperandIndex(), &NewV);
1277 return &SI;
1278}
1279
1282 auto &SI = cast<StoreInst>(V);
1283 return getCI(&Ty, SI.getPointerAddressSpace());
1284}
1285
1287 InstrumentationConfig &IConf,
1289 auto &SI = cast<StoreInst>(V);
1290 return IConf.getBasePointerInfo(*SI.getPointerOperand(), IIRB);
1291}
1292
1295 auto &SI = cast<StoreInst>(V);
1296 return SI.getValueOperand();
1297}
1298
1301 auto &SI = cast<StoreInst>(V);
1302 auto &DL = SI.getDataLayout();
1303 return getCI(&Ty, DL.getTypeStoreSize(SI.getValueOperand()->getType()));
1304}
1305
1308 auto &SI = cast<StoreInst>(V);
1309 return getCI(&Ty, SI.getAlign().value());
1310}
1311
1314 auto &SI = cast<StoreInst>(V);
1315 return getCI(&Ty, SI.getValueOperand()->getType()->getTypeID());
1316}
1317
1319 InstrumentationConfig &IConf,
1321 auto &SI = cast<StoreInst>(V);
1322 return getSubTypeID(*SI.getValueOperand()->getType(), Ty);
1323}
1324
1326 InstrumentationConfig &IConf,
1328 auto &SI = cast<StoreInst>(V);
1329 return getCI(&Ty, uint64_t(SI.getOrdering()));
1330}
1331
1334 auto &SI = cast<StoreInst>(V);
1335 return getCI(&Ty, uint64_t(SI.getSyncScopeID()));
1336}
1337
1340 auto &SI = cast<StoreInst>(V);
1341 return getCI(&Ty, SI.isVolatile());
1342}
1343
1345 ConfigTy *UserConfig) {
1347 if (UserConfig)
1348 Config = *UserConfig;
1349 if (Config.has(PassPointer)) {
1350 IRTArgs.push_back(
1351 IRTArg(IIRB.PtrTy, "pointer", "The accessed pointer.",
1352 ((IsPRE && Config.has(ReplacePointer)) ? IRTArg::REPLACABLE
1353 : IRTArg::NONE),
1355 }
1356 if (Config.has(PassPointerAS)) {
1357 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "pointer_as",
1358 "The address space of the accessed pointer.",
1360 }
1361 if (Config.has(PassBasePointerInfo)) {
1362 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "base_pointer_info",
1363 "The runtime provided base pointer info.",
1365 }
1366 if (!IsPRE && Config.has(PassValue)) {
1367 IRTArgs.push_back(
1368 IRTArg(getValueType(IIRB), "value", "The loaded value.",
1369 Config.has(ReplaceValue)
1372 : IRTArg::NONE)
1373 : IRTArg::NONE,
1374 getValue, Config.has(ReplaceValue) ? replaceValue : nullptr));
1375 }
1376 if (Config.has(PassValueSize)) {
1377 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "value_size",
1378 "The size of the loaded value.", IRTArg::NONE,
1379 getValueSize));
1380 }
1381 if (Config.has(PassAlignment)) {
1382 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "alignment",
1383 "The known access alignment.", IRTArg::NONE,
1384 getAlignment));
1385 }
1386 if (Config.has(PassValueTypeId)) {
1387 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "value_type_id",
1388 "The type id of the loaded value.", IRTArg::TYPEID,
1390 }
1391 if (Config.has(PassValueSubTypeId)) {
1392 IRTArgs.push_back(IRTArg(
1393 IIRB.Int32Ty, "value_sub_type_id",
1394 "The sub type id of the loaded value (for arrays and vectors, or -1).",
1396 }
1397 if (Config.has(PassAtomicityOrdering)) {
1398 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "atomicity_ordering",
1399 "The atomicity ordering of the load.",
1401 }
1402 if (Config.has(PassSyncScopeId)) {
1403 IRTArgs.push_back(IRTArg(IIRB.Int8Ty, "sync_scope_id",
1404 "The sync scope id of the load.", IRTArg::NONE,
1406 }
1407 if (Config.has(PassIsVolatile)) {
1408 IRTArgs.push_back(IRTArg(IIRB.Int8Ty, "is_volatile",
1409 "Flag indicating a volatile load.", IRTArg::NONE,
1410 isVolatile));
1411 }
1412
1413 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1414 IConf.addChoice(*this, IIRB.Ctx);
1415}
1416
1419 auto &LI = cast<LoadInst>(V);
1420 return LI.getPointerOperand();
1421}
1422
1425 auto &LI = cast<LoadInst>(V);
1426 LI.setOperand(LI.getPointerOperandIndex(), &NewV);
1427 return &LI;
1428}
1429
1432 auto &LI = cast<LoadInst>(V);
1433 return getCI(&Ty, LI.getPointerAddressSpace());
1434}
1435
1437 InstrumentationConfig &IConf,
1439 auto &LI = cast<LoadInst>(V);
1440 return IConf.getBasePointerInfo(*LI.getPointerOperand(), IIRB);
1441}
1442
1445 return &V;
1446}
1447
1450 auto &LI = cast<LoadInst>(V);
1451 auto &DL = LI.getDataLayout();
1452 return getCI(&Ty, DL.getTypeStoreSize(LI.getType()));
1453}
1454
1457 auto &LI = cast<LoadInst>(V);
1458 return getCI(&Ty, LI.getAlign().value());
1459}
1460
1463 auto &LI = cast<LoadInst>(V);
1464 return getCI(&Ty, LI.getType()->getTypeID());
1465}
1466
1468 InstrumentationConfig &IConf,
1470 auto &LI = cast<LoadInst>(V);
1471 return getSubTypeID(*LI.getType(), Ty);
1472}
1473
1475 InstrumentationConfig &IConf,
1477 auto &LI = cast<LoadInst>(V);
1478 return getCI(&Ty, uint64_t(LI.getOrdering()));
1479}
1480
1483 auto &LI = cast<LoadInst>(V);
1484 return getCI(&Ty, uint64_t(LI.getSyncScopeID()));
1485}
1486
1489 auto &LI = cast<LoadInst>(V);
1490 return getCI(&Ty, LI.isVolatile());
1491}
1492
1494 InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig) {
1495 if (UserConfig)
1496 Config = *UserConfig;
1497 if (Config.has(PassPointer))
1498 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "base_pointer",
1499 "The base pointer in question.",
1501 if (Config.has(PassPointerKind))
1502 IRTArgs.push_back(IRTArg(
1503 IIRB.Int32Ty, "base_pointer_kind",
1504 "The base pointer kind (argument, global, instruction, unknown).",
1506 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1507 IConf.addChoice(*this, IIRB.Ctx);
1508}
1509
1511 InstrumentationConfig &IConf,
1513 if (isa<Argument>(V))
1514 return getCI(&Ty, 0);
1515 if (isa<GlobalValue>(V))
1516 return getCI(&Ty, 1);
1517 if (isa<Instruction>(V))
1518 return getCI(&Ty, 2);
1519 return getCI(&Ty, 3);
1520}
1521
1523 ConfigTy *UserConfig) {
1524 if (UserConfig)
1525 Config = *UserConfig;
1526
1527 if (Config.has(PassName))
1528 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "module_name",
1529 "The module/translation unit name.",
1531 if (Config.has(PassTargetTriple))
1532 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "target_triple", "The target triple.",
1534
1535 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1536 IConf.addChoice(*this, IIRB.Ctx);
1537}
1540 // V is a constructor or destructor of the module we can place code in.
1541 auto &Fn = cast<Function>(V);
1542 return IConf.getGlobalString(Fn.getParent()->getName(), IIRB);
1543}
1545 InstrumentationConfig &IConf,
1547 // V is a constructor or destructor of the module we can place code in.
1548 auto &Fn = cast<Function>(V);
1549 return IConf.getGlobalString(Fn.getParent()->getTargetTriple().getTriple(),
1550 IIRB);
1551}
1552
1554 InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig) {
1555 if (UserConfig)
1556 Config = *UserConfig;
1558 if (Config.has(PassAddress))
1559 IRTArgs.push_back(IRTArg(
1560 IIRB.PtrTy, "address",
1561 "The address of the global (replaceable for definitions).",
1564 if (Config.has(PassAS))
1565 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "address_space",
1566 "The address space of the global.", IRTArg::NONE,
1567 getAS));
1568 if (Config.has(PassDeclaredSize))
1569 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "declared_size",
1570 "The size of the declared type of the global.",
1572 if (Config.has(PassAlignment))
1573 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "alignment",
1574 "The allocation alignment.", IRTArg::NONE,
1575 getAlignment));
1576 if (Config.has(PassName))
1577 IRTArgs.push_back(IRTArg(IIRB.PtrTy, "name", "The name of the global.",
1579 if (Config.has(PassInitialValue))
1580 IRTArgs.push_back(IRTArg(
1581 IIRB.Int64Ty, "initial_value", "The initial value of the global.",
1584 if (Config.has(PassIsConstant))
1585 IRTArgs.push_back(IRTArg(IIRB.Int8Ty, "is_constant",
1586 "Flag to indicate constant globals.", IRTArg::NONE,
1587 isConstant));
1588 if (Config.has(PassIsDefinition))
1589 IRTArgs.push_back(IRTArg(IIRB.Int8Ty, "is_definition",
1590 "Flag to indicate global definitions.",
1592 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1593 IConf.addChoice(*this, IIRB.Ctx);
1594}
1598 if (GV.getAddressSpace())
1599 return ConstantExpr::getAddrSpaceCast(&GV, IIRB.PtrTy);
1600 return &GV;
1601}
1603 InstrumentationConfig &IConf,
1606
1607 GlobalVariable *ShadowGV = nullptr;
1608 auto ShadowName = IConf.getRTName("shadow.", GV.getName());
1609 auto &DL = GV.getDataLayout();
1610 if (GV.isDeclaration()) {
1611 ShadowGV = new GlobalVariable(*GV.getParent(), GV.getType(), false,
1613 ShadowName, &GV, GV.getThreadLocalMode(),
1614 DL.getDefaultGlobalsAddressSpace());
1615 } else {
1616 ShadowGV = new GlobalVariable(
1617 *GV.getParent(), NewV.getType(), false, GV.getLinkage(),
1618 PoisonValue::get(NewV.getType()), ShadowName, &GV);
1619 IIRB.IRB.CreateStore(&NewV, ShadowGV);
1620 }
1621
1624 DenseMap<Value *, Instruction *> ConstToInstMap;
1626
1627 auto MakeInstForConst = [&](Use &U) {
1628 Instruction *&I = ConstToInstMap[U];
1629 if (I)
1630 return;
1631 if (U == &GV) {
1632 } else if (auto *CE = dyn_cast<ConstantExpr>(U)) {
1633 I = CE->getAsInstruction();
1634 }
1635 };
1636
1637 auto InsertConsts = [&](Instruction *UserI, Use &UserU) {
1639 auto *&Reload = ReloadMap[UserI->getFunction()];
1640 if (!Reload) {
1641 Reload = new LoadInst(
1642 GV.getType(), ShadowGV, GV.getName() + ".shadow_load",
1644 IIRB.NewInsts.insert({Reload, IIRB.Epoch});
1645 }
1646 Worklist.push_back({UserI, &UserU});
1647 while (!Worklist.empty()) {
1648 auto [I, U] = Worklist.pop_back_val();
1649 if (*U == &GV) {
1650 U->set(ReloadMap[I->getFunction()]);
1651 continue;
1652 }
1653 if (auto *CI = ConstToInstMap[*U]) {
1654 auto *CIClone = CI->clone();
1655 IIRB.NewInsts.insert({CIClone, IIRB.Epoch});
1656 if (auto *PHI = dyn_cast<PHINode>(I)) {
1657 auto *BB = PHI->getIncomingBlock(U->getOperandNo());
1658 CIClone->insertBefore(BB->getTerminator()->getIterator());
1659 } else {
1660 CIClone->insertBefore(I->getIterator());
1661 }
1662 U->set(CIClone);
1663 for (auto &CICUse : CIClone->operands()) {
1664 Worklist.push_back({CIClone, &CICUse});
1665 }
1666 }
1667 }
1668 };
1669
1670 while (!Worklist.empty()) {
1671 Use *U = Worklist.pop_back_val();
1672 if (!Done.insert(U).second)
1673 continue;
1674 MakeInstForConst(*U);
1675 auto *I = dyn_cast<Instruction>(U->getUser());
1676 if (!I) {
1677 append_range(Worklist, make_pointer_range(U->getUser()->uses()));
1678 continue;
1679 }
1680 if (IIRB.NewInsts.lookup(I) == IIRB.Epoch)
1681 continue;
1683 continue;
1684 if (auto *II = dyn_cast<IntrinsicInst>(I))
1685 if (II->getIntrinsicID() == Intrinsic::eh_typeid_for)
1686 continue;
1687 if (I->getParent())
1688 InsertConsts(I, *U);
1689 }
1690
1691 for (auto &It : ConstToInstMap)
1692 if (It.second)
1693 It.second->deleteValue();
1694
1695 return &V;
1696}
1700 return getCI(&Ty, GV.getAddressSpace());
1701}
1703 InstrumentationConfig &IConf,
1706 MaybeAlign Alignment = GV.getAlign();
1707 return getCI(&Ty, Alignment ? Alignment->value() : 0);
1708}
1710 InstrumentationConfig &IConf,
1713 auto &DL = GV.getDataLayout();
1714 return getCI(&Ty, DL.getTypeAllocSize(GV.getValueType()));
1715}
1717 InstrumentationConfig &IConf,
1720 return IConf.getGlobalString(GV.getName(), IIRB);
1721}
1732 return getCI(&Ty, GV.isConstant());
1733}
1735 InstrumentationConfig &IConf,
1738 return getCI(&Ty, !GV.isDeclaration());
1739}
1740
1741/// CastIO
1742/// {
1744 ConfigTy *UserConfig) {
1745 if (UserConfig)
1746 Config = *UserConfig;
1748 if (Config.has(PassInput))
1749 IRTArgs.push_back(
1750 IRTArg(IIRB.Int64Ty, "input", "Input value of the cast.",
1753 : IRTArg::NONE),
1754 getInput));
1755 if (Config.has(PassInputTypeId))
1756 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "input_type_id",
1757 "The type id of the input value.", IRTArg::TYPEID,
1759 if (Config.has(PassInputSubTypeId))
1760 IRTArgs.push_back(IRTArg(
1761 IIRB.Int32Ty, "input_sub_type_id",
1762 "The sub type id of the input value (for arrays and vectors, or -1).",
1764 if (Config.has(PassInputSize))
1765 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "input_size",
1766 "The size of the input value.", IRTArg::NONE,
1767 getInputSize));
1768 if (!IsPRE && Config.has(PassResult))
1769 IRTArgs.push_back(
1770 IRTArg(IIRB.Int64Ty, "result", "Result of the cast.",
1773 : IRTArg::NONE),
1774 getValue, Config.has(ReplaceResult) ? replaceValue : nullptr));
1775 if (Config.has(PassResultTypeId))
1776 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "result_type_id",
1777 "The type id of the result value.", IRTArg::TYPEID,
1779 if (Config.has(PassResultSubTypeId))
1780 IRTArgs.push_back(IRTArg(
1781 IIRB.Int32Ty, "result_sub_type_id",
1782 "The sub type id of the result value (for arrays and vectors, or -1).",
1784 if (Config.has(PassResultSize))
1785 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "result_size",
1786 "The size of the result value.", IRTArg::NONE,
1787 getResultSize));
1788 if (Config.has(PassOpcode))
1789 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "opcode",
1790 "The opcode of the cast instruction.",
1792
1793 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1794 IConf.addChoice(*this, IIRB.Ctx);
1795}
1796
1799 auto &CI = cast<CastInst>(V);
1800 return CI.getOperand(0);
1801}
1802
1805 auto &CI = cast<CastInst>(V);
1806 return getCI(&Ty, CI.getSrcTy()->getTypeID());
1807}
1808
1810 InstrumentationConfig &IConf,
1812 auto &CI = cast<CastInst>(V);
1813 return getSubTypeID(*CI.getSrcTy(), Ty);
1814}
1815
1818 auto &CI = cast<CastInst>(V);
1819 auto &DL = CI.getDataLayout();
1820 return getCI(&Ty, DL.getTypeStoreSize(CI.getSrcTy()));
1821}
1822
1825 auto &CI = cast<CastInst>(V);
1826 return getCI(&Ty, CI.getDestTy()->getTypeID());
1827}
1828
1830 InstrumentationConfig &IConf,
1832 auto &CI = cast<CastInst>(V);
1833 return getSubTypeID(*CI.getDestTy(), Ty);
1834}
1835
1838 auto &CI = cast<CastInst>(V);
1839 auto &DL = CI.getDataLayout();
1840 return getCI(&Ty, DL.getTypeStoreSize(CI.getDestTy()));
1841}
1842///}
1843
1846 auto &I = cast<Instruction>(V);
1847 uint64_t Flag = NUMERIC_FLAG_NONE;
1848
1849 switch (I.getOpcode()) {
1850 case Instruction::Add:
1851 case Instruction::Sub:
1852 case Instruction::Mul:
1853 case Instruction::Shl:
1854 if (I.hasNoSignedWrap())
1856 if (I.hasNoUnsignedWrap())
1858 break;
1859 case Instruction::FAdd:
1860 case Instruction::FSub:
1861 case Instruction::FMul:
1862 case Instruction::FDiv:
1863 case Instruction::FNeg:
1864 if (I.hasNoNaNs())
1866 if (I.hasNoInfs())
1868 if (I.hasNoSignedZeros())
1870 break;
1871 case Instruction::AShr:
1872 case Instruction::LShr:
1873 case Instruction::SDiv:
1874 case Instruction::UDiv:
1875 if (I.isExact())
1876 Flag |= NUMERIC_FLAG_IS_EXACT;
1877 break;
1878 }
1879
1880 if (auto *DI = dyn_cast<PossiblyDisjointInst>(&V))
1881 if (DI->isDisjoint())
1883
1884 return getCI(&Ty, Flag);
1885}
1886
1895
1897 InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig) {
1898 if (UserConfig)
1899 Config = UserConfig;
1901 const auto ValArgOpts =
1904 if (Config.has(PassTypeId))
1905 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "type_id",
1906 "The operation's type id.", IRTArg::TYPEID,
1907 getTypeId));
1908 if (Config.has(PassSubTypeId))
1909 IRTArgs.push_back(
1910 IRTArg(IIRB.Int32Ty, "sub_type_id",
1911 "The operation's sub type id (for arrays and vectors, or -1).",
1913 if (Config.has(PassSize))
1914 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "size", "The operation's type size.",
1916 if (Config.has(PassOpcode))
1917 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "opcode", "The instruction opcode.",
1919 if (Config.has(PassLeft))
1920 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "left",
1921 "The operation's left operand.", ValArgOpts,
1923 if (Config.has(PassRight))
1924 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "right",
1925 "The operation's right operand. This value is "
1926 "poison for unary operations.",
1927 ValArgOpts, getRightOperand));
1928 if (!IsPRE && Config.has(PassResult))
1929 IRTArgs.push_back(
1930 IRTArg(IIRB.Int64Ty, "result", "Result of the operation.",
1931 IRTArg::REPLACABLE | ValArgOpts, getValue,
1932 Config.has(ReplaceResult) ? replaceValue : nullptr));
1933 if (Config.has(PassFlags))
1934 IRTArgs.push_back(
1935 IRTArg(IIRB.Int64Ty, "flags",
1936 "A bitmask value signaling which instruction flags are present.",
1938 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
1939 addFlagNames();
1940 IConf.addChoice(*this, IIRB.Ctx);
1941}
1942
1944 InstrumentationConfig &IConf,
1946 auto &I = cast<Instruction>(V);
1947 return getCI(&Ty, I.getOperand(0)->getType()->getTypeID());
1948}
1949
1951 InstrumentationConfig &IConf,
1953 auto &I = cast<Instruction>(V);
1954 auto &DL = I.getDataLayout();
1955 return getCI(&Ty, DL.getTypeStoreSize(I.getOperand(0)->getType()));
1956}
1957
1960 auto *CI = dyn_cast<CmpInst>(&V);
1961 return getCI(&Ty, CI->getPredicate());
1962}
1963
1970
1973 auto &I = cast<Instruction>(V);
1974 uint64_t Flag = NUMERIC_FLAG_NONE;
1975
1976 switch (I.getOpcode()) {
1977 case Instruction::ICmp:
1978 if (dyn_cast<ICmpInst>(&V)->hasSameSign())
1979 Flag |= COMPARE_FLAG_SAMESIGN;
1980 break;
1981 case Instruction::FCmp:
1982 if (I.hasNoNaNs())
1984 if (I.hasNoInfs())
1986 if (I.hasNoSignedZeros())
1988 break;
1989 }
1990
1991 return getCI(&Ty, Flag);
1992}
1993
1995 InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig) {
1996 if (UserConfig)
1997 Config = UserConfig;
1999 const auto OperandArgOpts =
2002 if (Config.has(PassOpTypeId))
2003 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "operand_type_id",
2004 "The operand type id.", IRTArg::NONE,
2006 if (Config.has(PassOpSize))
2007 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "operand_size",
2008 "The operand type size.", IRTArg::NONE,
2010 if (Config.has(PassOpcode))
2011 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "opcode", "The instruction opcode.",
2013 if (Config.has(PassPredicate))
2014 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "predicate",
2015 "The comparison predicate ID.", IRTArg::NONE,
2016 getPredicate));
2017 if (Config.has(PassLeft))
2018 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "left",
2019 "The comparison's left operand.", OperandArgOpts,
2021 if (Config.has(PassRight))
2022 IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "right",
2023 "The comparison's right operand.", OperandArgOpts,
2025 if (!IsPRE && Config.has(PassResultSize))
2026 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "result_type_id",
2027 "The result value's type ID.", IRTArg::NONE,
2028 getTypeId));
2029 if (!IsPRE && Config.has(PassResultSize))
2030 IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "result_size",
2031 "Size of the result value.", IRTArg::NONE,
2032 getTypeSize));
2033 if (!IsPRE && Config.has(PassResult))
2034 IRTArgs.push_back(
2035 IRTArg(IIRB.Int64Ty, "result", "Result of the operation.",
2038 : IRTArg::NONE),
2039 getValue, Config.has(ReplaceResult) ? replaceValue : nullptr));
2040 if (Config.has(PassFlags))
2041 IRTArgs.push_back(
2042 IRTArg(IIRB.Int64Ty, "flags",
2043 "A bitmask value signaling which instruction flags are present.",
2045 addFlagNames();
2046 addCommonArgs(IConf, IIRB.Ctx, Config.has(PassId));
2047 IConf.addChoice(*this, IIRB.Ctx);
2048}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
uint64_t uint64_t
Rewrite undef for PHI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
post inline ee instrument
Hexagon Lower HLX Pair Allocas
#define _
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
@ COMPARE_FLAG_HAS_NO_NANS
@ COMPARE_FLAG_HAS_NO_INFS
@ COMPARE_FLAG_HAS_NO_SIGNED_ZEROS
@ NUMERIC_FLAG_NO_SIGNED_WRAP
@ NUMERIC_FLAG_NO_UNSIGNED_WRAP
@ NUMERIC_FLAG_HAS_NO_SIGNED_ZEROS
@ NUMERIC_FLAG_HAS_NO_INFS
@ NUMERIC_FLAG_HAS_NO_NANS
@ NUMERIC_FLAG_IS_DISJOINT
static void readValuePack(const Range &R, Value &Pack, InstrumentorIRBuilderTy &IIRB, function_ref< void(int, Value *)> SetterCB)
static constexpr Value * getValue(Ty &ValueOrUse)
static Value * createValuePack(const Range &R, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
static Regex createRegex(StringRef Str, StringRef Name, LLVMContext &Ctx)
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
ModuleAnalysisManager MAM
if(PassOpts->AAPipeline)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
Defines the virtual file system interface vfs::FileSystem.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
LLVM_ABI const_iterator getFirstNonPHIOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a static alloca,...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
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)
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
Definition Constant.h:44
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Diagnostic information for IR instrumentation reporting.
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:169
const BasicBlock & getEntryBlock() const
Definition Function.h:803
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
Definition Function.cpp:356
iterator_range< arg_iterator > args()
Definition Function.h:886
arg_iterator arg_begin()
Definition Function.h:862
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition Function.h:252
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:352
size_t arg_size() const
Definition Function.h:895
Argument * getArg(unsigned i) const
Definition Function.h:880
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:731
StringRef getSection() const
Get the custom section of this global if it has one.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition Globals.cpp:408
LinkageTypes getLinkage() const
ThreadLocalMode getThreadLocalMode() const
unsigned getAddressSpace() const
Module * getParent()
Get the module that this global value is contained inside of...
PointerType * getType() const
Global values are always pointers.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:205
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition GlobalValue.h:61
@ InternalLinkage
Rename collisions when linking (static functions).
Definition GlobalValue.h:60
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:58
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
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:76
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static LLVM_ABI bool linkModules(Module &Dest, std::unique_ptr< Module > Src, unsigned Flags=Flags::None, std::function< void(Module &, const StringSet<> &)> InternalizeCallback={})
This function links two modules together, with the resulting Dest module modified to be the composite...
An instruction for reading from memory.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1588
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition Module.h:328
LLVMContext & getContext() const
Get the global data context.
Definition Module.h:332
size_t global_size() const
Definition Module.h:807
StringRef getName() const
Get a short "name" for the module.
Definition Module.h:316
iterator_range< global_iterator > globals()
Definition Module.h:810
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
LLVM_ABI bool isValid(std::string &Error) const
isValid - returns the error encountered during regex compilation, if any.
Definition Regex.cpp:70
LLVM_ABI bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
Definition Regex.cpp:84
StringRef getMessage() const
Definition SourceMgr.h:338
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void reserve(size_type N)
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:462
const std::string & getTriple() const
Definition Triple.h:584
bool isAMDGPU() const
Definition Triple.h:1000
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:283
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition Type.h:314
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:186
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI bool replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
Definition Value.cpp:556
iterator_range< use_iterator > uses()
Definition Value.h:382
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI void writeConfigToJSON(InstrumentationConfig &IConf, StringRef OutputFile, LLVMContext &Ctx)
Write the configuration in /p IConf to the file with path OutputFile.
LLVM_ABI bool readConfigFromJSON(InstrumentationConfig &IConf, StringRef InputFile, LLVMContext &Ctx, vfs::FileSystem &FS)
Read the configuration from the file with path InputFile into /p IConf.
LLVM_ABI void printRuntimeStub(const InstrumentationConfig &IConf, StringRef StubRuntimeName, LLVMContext &Ctx)
Print a runtime stub file with the implementation of the instrumentation runtime functions correspond...
LLVM_ABI bool readConfigPathsFile(StringRef InputFile, SmallVectorImpl< std::string > &Configs, LLVMContext &Ctx, vfs::FileSystem &FS)
Read the configuration paths from the file with path InputFile into Configs.
LLVM_ABI IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
LLVM_ABI void PromoteMemToReg(ArrayRef< AllocaInst * > Allocas, DominatorTree &DT, AssumptionCache *AC=nullptr)
Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2575
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Done
Definition Threading.h:60
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2229
LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, bool TrackInlineHistory=false, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
This function inlines the called function into the basic block of the caller.
LLVM_ABI bool isAllocaPromotable(const AllocaInst *AI)
Return true if this alloca is legal for promotion.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
const IPOOptions & getIPOOptions(const LLVMContext &C)
Definition IPOOptions.h:36
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
LLVM_ABI const Value * getUnderlyingObjectAggressive(const Value *V, bool MustPreserveProvenance=false)
Like getUnderlyingObject(), but will try harder to find a single underlying object.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition STLExtras.h:2210
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition iterator.h:368
LLVM_ABI std::unique_ptr< Module > parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, ParserCallbacks Callbacks={}, AsmParserContext *ParserContext=nullptr)
If the given file holds a bitcode image, return a Module for it.
Definition IRReader.cpp:94
LLVM_ABI void appendToGlobalDtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Same as appendToGlobalCtors(), but for global dtors.
SmallVector< Out, Size > to_vector_of(R &&Range)
DEMANGLE_ABI std::string demangle(std::string_view MangledName)
Attempt to demangle a string using different demangling schemes.
Definition Demangle.cpp:21
LLVM_ABI bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
}
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)
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...
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...
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)
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.
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
static LLVM_ABI Value * getInputTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
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
static LLVM_ABI Value * getPredicate(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
LLVM_ABI void init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB, ConfigTy *UserConfig=nullptr)
llvm::instrumentor::FunctionIO::ConfigTy Config
static void populate(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
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)
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)
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)
BaseConfigTy< ConfigKind > ConfigTy
static LLVM_ABI Value * isConstant(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
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 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.
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.
Helper that represent the caches for instrumentation call arguments.
DenseMap< std::tuple< unsigned, StringRef, StringRef >, Value * > DirectArgCache
A cache for direct and indirect arguments.
DenseMap< std::tuple< unsigned, StringRef, StringRef >, Value * > IndirectArgCache
The class that contains the configuration for the instrumentor.
virtual void populate(InstrumentorIRBuilderTy &IIRB)
Populate the instrumentation opportunities.
std::unique_ptr< BaseConfigurationOption > InlineRuntimeEagerly
void addChoice(InstrumentationOpportunity &IO, LLVMContext &Ctx)
Register instrumentation opportunity IO.
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.
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.
std::unique_ptr< BaseConfigurationOption > FunctionRegex
std::unique_ptr< BaseConfigurationOption > TargetRegex
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.
static LLVM_ABI Value * getIdPre(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
Get the opportunity identifier for the pre and post positions.
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)
}
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.
SmallVector< IRTArg > IRTArgs
The list of possible arguments for the instrumentation runtime function.
void addCommonArgs(InstrumentationConfig &IConf, LLVMContext &Ctx, bool PassId)
}
An IR builder augmented with extra information for the instrumentor pass.
IRBuilder< ConstantFolder, IRBuilderCallbackInserter > IRB
The underlying IR builder with insertion callback.
unsigned Epoch
The current epoch number.
AllocaInst * getAlloca(Function *Fn, Type *Ty)
Get a temporary alloca to communicate (large) values with the runtime.
void returnAllocas()
Return the temporary allocas.
DenseMap< Instruction *, unsigned > NewInsts
A mapping from instrumentation instructions to the epoch they have been created.
DenseMap< std::pair< Function *, unsigned >, AllocaListTy * > AllocaMap
Map that holds a list of currently available allocas for a function and alloca size.
void eraseLater(Instruction *I)
Save instruction I to be erased later.
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)
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)
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
static LLVM_ABI Value * getFlags(Value &V, Type &Ty, InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB)
}
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)
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)
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