mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-10 16:24:04 +00:00
Clear the cached cost when removing a function in
the inliner; prevents nondeterministic behavior when the same address is reallocated. Don't build call graph nodes for debug intrinsic calls; they're useless, and there were typically a lot of them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67311 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3751f564e3
commit
1f67ce4aa3
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
#include "llvm/CallGraphSCCPass.h"
|
#include "llvm/CallGraphSCCPass.h"
|
||||||
#include "llvm/Transforms/Utils/InlineCost.h"
|
#include "llvm/Transforms/Utils/InlineCost.h"
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class CallSite;
|
class CallSite;
|
||||||
@ -43,6 +46,10 @@ struct Inliner : public CallGraphSCCPass {
|
|||||||
// processing to avoid breaking the SCC traversal.
|
// processing to avoid breaking the SCC traversal.
|
||||||
virtual bool doFinalization(CallGraph &CG);
|
virtual bool doFinalization(CallGraph &CG);
|
||||||
|
|
||||||
|
// InlineCallIfPossible
|
||||||
|
bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
|
||||||
|
const std::set<Function*> &SCCFunctions,
|
||||||
|
const TargetData &TD);
|
||||||
|
|
||||||
/// This method returns the value specified by the -inline-threshold value,
|
/// This method returns the value specified by the -inline-threshold value,
|
||||||
/// specified on the command line. This is typically not directly needed.
|
/// specified on the command line. This is typically not directly needed.
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "llvm/Analysis/CallGraph.h"
|
#include "llvm/Analysis/CallGraph.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/Streams.h"
|
#include "llvm/Support/Streams.h"
|
||||||
@ -143,7 +144,7 @@ private:
|
|||||||
for (BasicBlock::iterator II = BB->begin(), IE = BB->end();
|
for (BasicBlock::iterator II = BB->begin(), IE = BB->end();
|
||||||
II != IE; ++II) {
|
II != IE; ++II) {
|
||||||
CallSite CS = CallSite::get(II);
|
CallSite CS = CallSite::get(II);
|
||||||
if (CS.getInstruction()) {
|
if (CS.getInstruction() && !isa<DbgInfoIntrinsic>(II)) {
|
||||||
const Function *Callee = CS.getCalledFunction();
|
const Function *Callee = CS.getCalledFunction();
|
||||||
if (Callee)
|
if (Callee)
|
||||||
Node->addCalledFunction(CS, getOrInsertFunction(Callee));
|
Node->addCalledFunction(CS, getOrInsertFunction(Callee));
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#define DEBUG_TYPE "inline"
|
#define DEBUG_TYPE "inline"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/Analysis/CallGraph.h"
|
#include "llvm/Analysis/CallGraph.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
@ -50,7 +51,7 @@ void Inliner::getAnalysisUsage(AnalysisUsage &Info) const {
|
|||||||
|
|
||||||
// InlineCallIfPossible - If it is possible to inline the specified call site,
|
// InlineCallIfPossible - If it is possible to inline the specified call site,
|
||||||
// do so and update the CallGraph for this operation.
|
// do so and update the CallGraph for this operation.
|
||||||
static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
|
bool Inliner::InlineCallIfPossible(CallSite CS, CallGraph &CG,
|
||||||
const std::set<Function*> &SCCFunctions,
|
const std::set<Function*> &SCCFunctions,
|
||||||
const TargetData &TD) {
|
const TargetData &TD) {
|
||||||
Function *Callee = CS.getCalledFunction();
|
Function *Callee = CS.getCalledFunction();
|
||||||
@ -76,6 +77,8 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
|
|||||||
// Remove any call graph edges from the callee to its callees.
|
// Remove any call graph edges from the callee to its callees.
|
||||||
CalleeNode->removeAllCalledFunctions();
|
CalleeNode->removeAllCalledFunctions();
|
||||||
|
|
||||||
|
resetCachedCostInfo(CalleeNode->getFunction());
|
||||||
|
|
||||||
// Removing the node for callee from the call graph and delete it.
|
// Removing the node for callee from the call graph and delete it.
|
||||||
delete CG.removeFunctionFromModule(CalleeNode);
|
delete CG.removeFunctionFromModule(CalleeNode);
|
||||||
++NumDeleted;
|
++NumDeleted;
|
||||||
@ -123,6 +126,7 @@ bool Inliner::shouldInline(CallSite CS) {
|
|||||||
|
|
||||||
bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
|
bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
|
||||||
CallGraph &CG = getAnalysis<CallGraph>();
|
CallGraph &CG = getAnalysis<CallGraph>();
|
||||||
|
TargetData &TD = getAnalysis<TargetData>();
|
||||||
|
|
||||||
std::set<Function*> SCCFunctions;
|
std::set<Function*> SCCFunctions;
|
||||||
DOUT << "Inliner visiting SCC:";
|
DOUT << "Inliner visiting SCC:";
|
||||||
@ -142,7 +146,8 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
|
|||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
||||||
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
|
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
|
||||||
CallSite CS = CallSite::get(I);
|
CallSite CS = CallSite::get(I);
|
||||||
if (CS.getInstruction() && (!CS.getCalledFunction() ||
|
if (CS.getInstruction() && !isa<DbgInfoIntrinsic>(I) &&
|
||||||
|
(!CS.getCalledFunction() ||
|
||||||
!CS.getCalledFunction()->isDeclaration()))
|
!CS.getCalledFunction()->isDeclaration()))
|
||||||
CallSites.push_back(CS);
|
CallSites.push_back(CS);
|
||||||
}
|
}
|
||||||
@ -186,11 +191,10 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
|
|||||||
if (shouldInline(CS)) {
|
if (shouldInline(CS)) {
|
||||||
Function *Caller = CS.getCaller();
|
Function *Caller = CS.getCaller();
|
||||||
// Attempt to inline the function...
|
// Attempt to inline the function...
|
||||||
if (InlineCallIfPossible(CS, CG, SCCFunctions,
|
if (InlineCallIfPossible(CS, CG, SCCFunctions, TD)) {
|
||||||
getAnalysis<TargetData>())) {
|
// Remove any cached cost info for this caller, as inlining the
|
||||||
// Remove any cached cost info for this caller, as inlining the callee
|
// callee has increased the size of the caller (which may be the
|
||||||
// has increased the size of the caller (which may be the same as the
|
// same as the callee).
|
||||||
// callee).
|
|
||||||
resetCachedCostInfo(Caller);
|
resetCachedCostInfo(Caller);
|
||||||
|
|
||||||
// Remove this call site from the list. If possible, use
|
// Remove this call site from the list. If possible, use
|
||||||
@ -263,6 +267,7 @@ bool Inliner::removeDeadFunctions(CallGraph &CG,
|
|||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (std::set<CallGraphNode*>::iterator I = FunctionsToRemove.begin(),
|
for (std::set<CallGraphNode*>::iterator I = FunctionsToRemove.begin(),
|
||||||
E = FunctionsToRemove.end(); I != E; ++I) {
|
E = FunctionsToRemove.end(); I != E; ++I) {
|
||||||
|
resetCachedCostInfo((*I)->getFunction());
|
||||||
delete CG.removeFunctionFromModule(*I);
|
delete CG.removeFunctionFromModule(*I);
|
||||||
++NumDeleted;
|
++NumDeleted;
|
||||||
Changed = true;
|
Changed = true;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/IntrinsicInst.h"
|
||||||
#include "llvm/Analysis/CallGraph.h"
|
#include "llvm/Analysis/CallGraph.h"
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
@ -235,9 +236,10 @@ void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
|
|||||||
CallGraphNode *CGN = CG[BB->getParent()];
|
CallGraphNode *CGN = CG[BB->getParent()];
|
||||||
for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; ) {
|
for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; ) {
|
||||||
--I;
|
--I;
|
||||||
if (CallInst *CI = dyn_cast<CallInst>(I))
|
if (CallInst *CI = dyn_cast<CallInst>(I)) {
|
||||||
CGN->removeCallEdgeFor(CI);
|
if (!isa<DbgInfoIntrinsic>(I))
|
||||||
else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
|
CGN->removeCallEdgeFor(CI);
|
||||||
|
} else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
|
||||||
CGN->removeCallEdgeFor(II);
|
CGN->removeCallEdgeFor(II);
|
||||||
if (!I->use_empty())
|
if (!I->use_empty())
|
||||||
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
||||||
|
Loading…
Reference in New Issue
Block a user