1 //===-- Instrumentation.cpp - TransformUtils Infrastructure ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the common initialization infrastructure for the
11 // Instrumentation library.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Transforms/Instrumentation.h"
16 #include "llvm-c/Initialization.h"
17 #include "llvm/IR/IntrinsicInst.h"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/PassRegistry.h"
23 /// Moves I before IP. Returns new insert point.
24 static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I, BasicBlock::iterator IP) {
25 // If I is IP, move the insert point down.
28 // Otherwise, move I before IP and return IP.
33 /// Instrumentation passes often insert conditional checks into entry blocks.
34 /// Call this function before splitting the entry block to move instructions
35 /// that must remain in the entry block up before the split point. Static
36 /// allocas and llvm.localescape calls, for example, must remain in the entry
38 BasicBlock::iterator llvm::PrepareToSplitEntryBlock(BasicBlock &BB,
39 BasicBlock::iterator IP) {
40 assert(&BB.getParent()->getEntryBlock() == &BB);
41 for (auto I = IP, E = BB.end(); I != E; ++I) {
42 bool KeepInEntry = false;
43 if (auto *AI = dyn_cast<AllocaInst>(I)) {
44 if (AI->isStaticAlloca())
46 } else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
47 if (II->getIntrinsicID() == llvm::Intrinsic::localescape)
51 IP = moveBeforeInsertPoint(I, IP);
56 /// initializeInstrumentation - Initialize all passes in the TransformUtils
58 void llvm::initializeInstrumentation(PassRegistry &Registry) {
59 initializeAddressSanitizerPass(Registry);
60 initializeAddressSanitizerModulePass(Registry);
61 initializeBoundsCheckingPass(Registry);
62 initializeGCOVProfilerPass(Registry);
63 initializePGOInstrumentationGenLegacyPassPass(Registry);
64 initializePGOInstrumentationUseLegacyPassPass(Registry);
65 initializePGOIndirectCallPromotionLegacyPassPass(Registry);
66 initializeInstrProfilingLegacyPassPass(Registry);
67 initializeMemorySanitizerPass(Registry);
68 initializeThreadSanitizerPass(Registry);
69 initializeSanitizerCoverageModulePass(Registry);
70 initializeDataFlowSanitizerPass(Registry);
71 initializeEfficiencySanitizerPass(Registry);
74 /// LLVMInitializeInstrumentation - C binding for
75 /// initializeInstrumentation.
76 void LLVMInitializeInstrumentation(LLVMPassRegistryRef R) {
77 initializeInstrumentation(*unwrap(R));