Owen Anderson | 9786868 | 2010-10-07 20:17:24 +0000 | [diff] [blame] | 1 | //===-- 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 Kleckner | a57d015 | 2015-08-14 16:45:42 +0000 | [diff] [blame] | 15 | #include "llvm/Transforms/Instrumentation.h" |
Owen Anderson | 9786868 | 2010-10-07 20:17:24 +0000 | [diff] [blame] | 16 | #include "llvm-c/Initialization.h" |
Reid Kleckner | a57d015 | 2015-08-14 16:45:42 +0000 | [diff] [blame] | 17 | #include "llvm/IR/IntrinsicInst.h" |
| 18 | #include "llvm/InitializePasses.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 19 | #include "llvm/PassRegistry.h" |
Owen Anderson | 9786868 | 2010-10-07 20:17:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | |
Reid Kleckner | a57d015 | 2015-08-14 16:45:42 +0000 | [diff] [blame] | 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. |
| 26 | if (I == IP) |
| 27 | return ++IP; |
| 28 | // Otherwise, move I before IP and return IP. |
Duncan P. N. Exon Smith | e82c286 | 2015-10-13 17:39:10 +0000 | [diff] [blame] | 29 | I->moveBefore(&*IP); |
Reid Kleckner | a57d015 | 2015-08-14 16:45:42 +0000 | [diff] [blame] | 30 | 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. |
| 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()) |
| 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 Anderson | 9786868 | 2010-10-07 20:17:24 +0000 | [diff] [blame] | 56 | /// initializeInstrumentation - Initialize all passes in the TransformUtils |
| 57 | /// library. |
| 58 | void llvm::initializeInstrumentation(PassRegistry &Registry) { |
Chandler Carruth | c8acd7c | 2012-07-22 05:19:32 +0000 | [diff] [blame] | 59 | initializeAddressSanitizerPass(Registry); |
Kostya Serebryany | dfe9e79 | 2012-11-28 10:31:36 +0000 | [diff] [blame] | 60 | initializeAddressSanitizerModulePass(Registry); |
Chandler Carruth | c8acd7c | 2012-07-22 05:19:32 +0000 | [diff] [blame] | 61 | initializeBoundsCheckingPass(Registry); |
Xinliang David Li | fb3137c | 2016-06-05 03:40:03 +0000 | [diff] [blame] | 62 | initializeGCOVProfilerLegacyPassPass(Registry); |
Xinliang David Li | 8aebf44 | 2016-05-06 05:49:19 +0000 | [diff] [blame] | 63 | initializePGOInstrumentationGenLegacyPassPass(Registry); |
Xinliang David Li | d55827f | 2016-05-07 05:39:12 +0000 | [diff] [blame] | 64 | initializePGOInstrumentationUseLegacyPassPass(Registry); |
Xinliang David Li | 7261618 | 2016-05-15 01:04:24 +0000 | [diff] [blame] | 65 | initializePGOIndirectCallPromotionLegacyPassPass(Registry); |
Rong Xu | 48596b6 | 2017-04-04 16:42:20 +0000 | [diff] [blame^] | 66 | initializePGOMemOPSizeOptLegacyPassPass(Registry); |
Xinliang David Li | e6b8929 | 2016-04-18 17:47:38 +0000 | [diff] [blame] | 67 | initializeInstrProfilingLegacyPassPass(Registry); |
Evgeniy Stepanov | d4bd7b7 | 2012-11-29 09:57:20 +0000 | [diff] [blame] | 68 | initializeMemorySanitizerPass(Registry); |
Kostya Serebryany | e2a0e41 | 2012-02-13 22:50:51 +0000 | [diff] [blame] | 69 | initializeThreadSanitizerPass(Registry); |
Kostya Serebryany | 29a18dc | 2014-11-11 22:14:37 +0000 | [diff] [blame] | 70 | initializeSanitizerCoverageModulePass(Registry); |
Peter Collingbourne | e5d5b0c | 2013-08-07 22:47:18 +0000 | [diff] [blame] | 71 | initializeDataFlowSanitizerPass(Registry); |
Derek Bruening | d862c17 | 2016-04-21 21:30:22 +0000 | [diff] [blame] | 72 | initializeEfficiencySanitizerPass(Registry); |
Owen Anderson | 9786868 | 2010-10-07 20:17:24 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /// LLVMInitializeInstrumentation - C binding for |
| 76 | /// initializeInstrumentation. |
| 77 | void LLVMInitializeInstrumentation(LLVMPassRegistryRef R) { |
| 78 | initializeInstrumentation(*unwrap(R)); |
| 79 | } |