mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-14 14:24:05 +00:00
More ProfileInfo improvements.
- Part of optimal static profiling patch sequence by Andreas Neustifter. - Store edge, block, and function information separately for each functions (instead of in one giant map). - Return frequencies as double instead of int, and use a sentinel value for missing information. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78477 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -106,7 +106,8 @@ bool BlockProfiler::runOnModule(Module &M) {
|
||||
|
||||
unsigned NumBlocks = 0;
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||
NumBlocks += I->size();
|
||||
if (!I->isDeclaration())
|
||||
NumBlocks += I->size();
|
||||
|
||||
const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks);
|
||||
GlobalVariable *Counters =
|
||||
@ -115,10 +116,12 @@ bool BlockProfiler::runOnModule(Module &M) {
|
||||
|
||||
// Instrument all of the blocks...
|
||||
unsigned i = 0;
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
||||
if (I->isDeclaration()) continue;
|
||||
for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB)
|
||||
// Insert counter at the start of the block
|
||||
IncrementCounterInBlock(BB, i++, Counters);
|
||||
}
|
||||
|
||||
// Add the initialization call to main.
|
||||
InsertProfilingInitCall(Main, "llvm_start_block_profiling", Counters);
|
||||
|
@ -55,7 +55,10 @@ bool EdgeProfiler::runOnModule(Module &M) {
|
||||
|
||||
std::set<BasicBlock*> BlocksToInstrument;
|
||||
unsigned NumEdges = 0;
|
||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
|
||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
||||
if (F->isDeclaration()) continue;
|
||||
// Reserve space for (0,entry) edge.
|
||||
++NumEdges;
|
||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
||||
// Keep track of which blocks need to be instrumented. We don't want to
|
||||
// instrument blocks that are added as the result of breaking critical
|
||||
@ -63,6 +66,7 @@ bool EdgeProfiler::runOnModule(Module &M) {
|
||||
BlocksToInstrument.insert(BB);
|
||||
NumEdges += BB->getTerminator()->getNumSuccessors();
|
||||
}
|
||||
}
|
||||
|
||||
const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges);
|
||||
GlobalVariable *Counters =
|
||||
@ -71,7 +75,10 @@ bool EdgeProfiler::runOnModule(Module &M) {
|
||||
|
||||
// Instrument all of the edges...
|
||||
unsigned i = 0;
|
||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
|
||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
||||
if (F->isDeclaration()) continue;
|
||||
// Create counter for (0,entry) edge.
|
||||
IncrementCounterInBlock(&F->getEntryBlock(), i++, Counters);
|
||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
||||
if (BlocksToInstrument.count(BB)) { // Don't instrument inserted blocks
|
||||
// Okay, we have to add a counter of each outgoing edge. If the
|
||||
@ -94,6 +101,7 @@ bool EdgeProfiler::runOnModule(Module &M) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the initialization call to main.
|
||||
InsertProfilingInitCall(Main, "llvm_start_edge_profiling", Counters);
|
||||
|
@ -127,13 +127,13 @@ void BlockPlacement::PlaceBlocks(BasicBlock *BB) {
|
||||
/*empty*/;
|
||||
if (SI == E) return; // No more successors to place.
|
||||
|
||||
unsigned MaxExecutionCount = PI->getExecutionCount(*SI);
|
||||
double MaxExecutionCount = PI->getExecutionCount(*SI);
|
||||
BasicBlock *MaxSuccessor = *SI;
|
||||
|
||||
// Scan for more frequently executed successors
|
||||
for (; SI != E; ++SI)
|
||||
if (!PlacedBlocks.count(*SI)) {
|
||||
unsigned Count = PI->getExecutionCount(*SI);
|
||||
double Count = PI->getExecutionCount(*SI);
|
||||
if (Count > MaxExecutionCount ||
|
||||
// Prefer to not disturb the code.
|
||||
(Count == MaxExecutionCount && *SI == &*InsertPos)) {
|
||||
|
Reference in New Issue
Block a user