2010-10-08 04:17:24 +08:00
|
|
|
//===-- Instrumentation.cpp - TransformUtils Infrastructure ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the common initialization infrastructure for the
|
|
|
|
// Instrumentation library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-08-15 00:45:42 +08:00
|
|
|
#include "llvm/Transforms/Instrumentation.h"
|
2010-10-08 04:17:24 +08:00
|
|
|
#include "llvm-c/Initialization.h"
|
2015-08-15 00:45:42 +08:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/InitializePasses.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/PassRegistry.h"
|
2010-10-08 04:17:24 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-08-15 00:45:42 +08:00
|
|
|
/// Moves I before IP. Returns new insert point.
|
|
|
|
static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I, BasicBlock::iterator IP) {
|
|
|
|
// If I is IP, move the insert point down.
|
|
|
|
if (I == IP)
|
|
|
|
return ++IP;
|
|
|
|
// Otherwise, move I before IP and return IP.
|
2015-10-14 01:39:10 +08:00
|
|
|
I->moveBefore(&*IP);
|
2015-08-15 00:45:42 +08:00
|
|
|
return IP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Instrumentation passes often insert conditional checks into entry blocks.
|
|
|
|
/// Call this function before splitting the entry block to move instructions
|
|
|
|
/// that must remain in the entry block up before the split point. Static
|
|
|
|
/// allocas and llvm.localescape calls, for example, must remain in the entry
|
|
|
|
/// block.
|
|
|
|
BasicBlock::iterator llvm::PrepareToSplitEntryBlock(BasicBlock &BB,
|
|
|
|
BasicBlock::iterator IP) {
|
|
|
|
assert(&BB.getParent()->getEntryBlock() == &BB);
|
|
|
|
for (auto I = IP, E = BB.end(); I != E; ++I) {
|
|
|
|
bool KeepInEntry = false;
|
|
|
|
if (auto *AI = dyn_cast<AllocaInst>(I)) {
|
|
|
|
if (AI->isStaticAlloca())
|
|
|
|
KeepInEntry = true;
|
|
|
|
} else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
|
|
|
|
if (II->getIntrinsicID() == llvm::Intrinsic::localescape)
|
|
|
|
KeepInEntry = true;
|
|
|
|
}
|
|
|
|
if (KeepInEntry)
|
|
|
|
IP = moveBeforeInsertPoint(I, IP);
|
|
|
|
}
|
|
|
|
return IP;
|
|
|
|
}
|
|
|
|
|
2010-10-08 04:17:24 +08:00
|
|
|
/// initializeInstrumentation - Initialize all passes in the TransformUtils
|
|
|
|
/// library.
|
|
|
|
void llvm::initializeInstrumentation(PassRegistry &Registry) {
|
2012-07-22 13:19:32 +08:00
|
|
|
initializeAddressSanitizerPass(Registry);
|
2012-11-28 18:31:36 +08:00
|
|
|
initializeAddressSanitizerModulePass(Registry);
|
2012-07-22 13:19:32 +08:00
|
|
|
initializeBoundsCheckingPass(Registry);
|
|
|
|
initializeGCOVProfilerPass(Registry);
|
2015-12-10 02:08:16 +08:00
|
|
|
initializePGOInstrumentationGenPass(Registry);
|
|
|
|
initializePGOInstrumentationUsePass(Registry);
|
2014-12-09 02:02:35 +08:00
|
|
|
initializeInstrProfilingPass(Registry);
|
2012-11-29 17:57:20 +08:00
|
|
|
initializeMemorySanitizerPass(Registry);
|
2012-02-14 06:50:51 +08:00
|
|
|
initializeThreadSanitizerPass(Registry);
|
2014-11-12 06:14:37 +08:00
|
|
|
initializeSanitizerCoverageModulePass(Registry);
|
2013-08-08 06:47:18 +08:00
|
|
|
initializeDataFlowSanitizerPass(Registry);
|
2010-10-08 04:17:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// LLVMInitializeInstrumentation - C binding for
|
|
|
|
/// initializeInstrumentation.
|
|
|
|
void LLVMInitializeInstrumentation(LLVMPassRegistryRef R) {
|
|
|
|
initializeInstrumentation(*unwrap(R));
|
|
|
|
}
|