From 7ff99155c39edd73ebf1c6adfa023b1048fee9a4 Mon Sep 17 00:00:00 2001 From: rdivacky Date: Wed, 4 Nov 2009 14:58:56 +0000 Subject: Update LLVM to r86025. --- lib/Analysis/InlineCost.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/Analysis/InlineCost.cpp') diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp index b833baa..bd9377b 100644 --- a/lib/Analysis/InlineCost.cpp +++ b/lib/Analysis/InlineCost.cpp @@ -31,6 +31,9 @@ unsigned InlineCostAnalyzer::FunctionInfo:: // Eliminating a switch is a big win, proportional to the number of edges // deleted. Reduction += (SI->getNumSuccessors()-1) * 40; + else if (isa(*UI)) + // Eliminating an indirect branch is a big win. + Reduction += 200; else if (CallInst *CI = dyn_cast(*UI)) { // Turning an indirect call into a direct call is a BIG win Reduction += CI->getCalledValue() == V ? 500 : 0; @@ -50,7 +53,7 @@ unsigned InlineCostAnalyzer::FunctionInfo:: // Unfortunately, we don't know the pointer that may get propagated here, // so we can't make this decision. if (Inst.mayReadFromMemory() || Inst.mayHaveSideEffects() || - isa(Inst)) + isa(Inst)) continue; bool AllOperandsConstant = true; @@ -130,10 +133,6 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) { NumInsts += InlineConstants::CallPenalty; } - // These, too, are calls. - if (isa(II)) - NumInsts += InlineConstants::CallPenalty; - if (const AllocaInst *AI = dyn_cast(II)) { if (!AI->isStaticAlloca()) this->usesDynamicAlloca = true; @@ -147,19 +146,26 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) { if (CI->isLosslessCast() || isa(CI) || isa(CI)) continue; - } else if (const GetElementPtrInst *GEPI = - dyn_cast(II)) { + } else if (const GetElementPtrInst *GEPI = dyn_cast(II)){ // If a GEP has all constant indices, it will probably be folded with // a load/store. if (GEPI->hasAllConstantIndices()) continue; } - if (isa(II)) - ++NumRets; - ++NumInsts; } + + if (isa(BB->getTerminator())) + ++NumRets; + + // We never want to inline functions that contain an indirectbr. This is + // incorrect because all the blockaddress's (in static global initializers + // for example) would be referring to the original function, and this indirect + // jump would jump from the inlined copy of the function into the original + // function which is extremely undefined behavior. + if (isa(BB->getTerminator())) + NeverInline = true; } /// analyzeFunction - Fill in the current structure with information gleaned -- cgit v1.1