mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-14 08:31:04 +00:00
9e52f8ee8b
This patch optimizes two memory intrinsic operations: memset and memcpy based on the profiled size of the operation. The high level transformation is like: mem_op(..., size) ==> switch (size) { case s1: mem_op(..., s1); goto merge_bb; case s2: mem_op(..., s2); goto merge_bb; ... default: mem_op(..., size); goto merge_bb; } merge_bb: Differential Revision: http://reviews.llvm.org/D28966 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299446 91177308-0d34-0410-b5e6-96231b3b80d8
80 lines
3.0 KiB
C++
80 lines
3.0 KiB
C++
//===-- 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.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Transforms/Instrumentation.h"
|
|
#include "llvm-c/Initialization.h"
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
#include "llvm/InitializePasses.h"
|
|
#include "llvm/PassRegistry.h"
|
|
|
|
using namespace llvm;
|
|
|
|
/// 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.
|
|
I->moveBefore(&*IP);
|
|
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;
|
|
}
|
|
|
|
/// initializeInstrumentation - Initialize all passes in the TransformUtils
|
|
/// library.
|
|
void llvm::initializeInstrumentation(PassRegistry &Registry) {
|
|
initializeAddressSanitizerPass(Registry);
|
|
initializeAddressSanitizerModulePass(Registry);
|
|
initializeBoundsCheckingPass(Registry);
|
|
initializeGCOVProfilerLegacyPassPass(Registry);
|
|
initializePGOInstrumentationGenLegacyPassPass(Registry);
|
|
initializePGOInstrumentationUseLegacyPassPass(Registry);
|
|
initializePGOIndirectCallPromotionLegacyPassPass(Registry);
|
|
initializePGOMemOPSizeOptLegacyPassPass(Registry);
|
|
initializeInstrProfilingLegacyPassPass(Registry);
|
|
initializeMemorySanitizerPass(Registry);
|
|
initializeThreadSanitizerPass(Registry);
|
|
initializeSanitizerCoverageModulePass(Registry);
|
|
initializeDataFlowSanitizerPass(Registry);
|
|
initializeEfficiencySanitizerPass(Registry);
|
|
}
|
|
|
|
/// LLVMInitializeInstrumentation - C binding for
|
|
/// initializeInstrumentation.
|
|
void LLVMInitializeInstrumentation(LLVMPassRegistryRef R) {
|
|
initializeInstrumentation(*unwrap(R));
|
|
}
|