blob: a3727579ee4aa1e80e63158b4c9ccbd7a5eca710 [file] [log] [blame]
Owen Anderson97868682010-10-07 20:17:24 +00001//===-- Instrumentation.cpp - TransformUtils Infrastructure ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the common initialization infrastructure for the
11// Instrumentation library.
12//
13//===----------------------------------------------------------------------===//
14
Reid Klecknera57d0152015-08-14 16:45:42 +000015#include "llvm/Transforms/Instrumentation.h"
Owen Anderson97868682010-10-07 20:17:24 +000016#include "llvm-c/Initialization.h"
Reid Klecknera57d0152015-08-14 16:45:42 +000017#include "llvm/IR/IntrinsicInst.h"
18#include "llvm/InitializePasses.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000019#include "llvm/PassRegistry.h"
Owen Anderson97868682010-10-07 20:17:24 +000020
21using namespace llvm;
22
Reid Klecknera57d0152015-08-14 16:45:42 +000023/// Moves I before IP. Returns new insert point.
24static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I, BasicBlock::iterator IP) {
25 // If I is IP, move the insert point down.
26 if (I == IP)
27 return ++IP;
28 // Otherwise, move I before IP and return IP.
Duncan P. N. Exon Smithe82c2862015-10-13 17:39:10 +000029 I->moveBefore(&*IP);
Reid Klecknera57d0152015-08-14 16:45:42 +000030 return IP;
31}
32
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
37/// block.
38BasicBlock::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())
45 KeepInEntry = true;
46 } else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
47 if (II->getIntrinsicID() == llvm::Intrinsic::localescape)
48 KeepInEntry = true;
49 }
50 if (KeepInEntry)
51 IP = moveBeforeInsertPoint(I, IP);
52 }
53 return IP;
54}
55
Owen Anderson97868682010-10-07 20:17:24 +000056/// initializeInstrumentation - Initialize all passes in the TransformUtils
57/// library.
58void llvm::initializeInstrumentation(PassRegistry &Registry) {
Chandler Carruthc8acd7c2012-07-22 05:19:32 +000059 initializeAddressSanitizerPass(Registry);
Kostya Serebryanydfe9e792012-11-28 10:31:36 +000060 initializeAddressSanitizerModulePass(Registry);
Chandler Carruthc8acd7c2012-07-22 05:19:32 +000061 initializeBoundsCheckingPass(Registry);
Chandler Carruthc8acd7c2012-07-22 05:19:32 +000062 initializeGCOVProfilerPass(Registry);
Rong Xuf430ae42015-12-09 18:08:16 +000063 initializePGOInstrumentationGenPass(Registry);
64 initializePGOInstrumentationUsePass(Registry);
Xinliang David Lie6b89292016-04-18 17:47:38 +000065 initializeInstrProfilingLegacyPassPass(Registry);
Evgeniy Stepanovd4bd7b72012-11-29 09:57:20 +000066 initializeMemorySanitizerPass(Registry);
Kostya Serebryanye2a0e412012-02-13 22:50:51 +000067 initializeThreadSanitizerPass(Registry);
Kostya Serebryany29a18dc2014-11-11 22:14:37 +000068 initializeSanitizerCoverageModulePass(Registry);
Peter Collingbournee5d5b0c2013-08-07 22:47:18 +000069 initializeDataFlowSanitizerPass(Registry);
Derek Brueningd862c172016-04-21 21:30:22 +000070 initializeEfficiencySanitizerPass(Registry);
Owen Anderson97868682010-10-07 20:17:24 +000071}
72
73/// LLVMInitializeInstrumentation - C binding for
74/// initializeInstrumentation.
75void LLVMInitializeInstrumentation(LLVMPassRegistryRef R) {
76 initializeInstrumentation(*unwrap(R));
77}