X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FInlineCost.cpp;h=bd9377bf87fbec2caa3ca07cd8dfeea6ea9d2403;hb=4850a89b77e7dc677c2b73508f2a4c10386c844f;hp=b833baacedef4a8607f731b4d203e46725f71e39;hpb=a276c603b82a11b0bf0b59f0517a69e4b63adeab;p=oota-llvm.git diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp index b833baacede..bd9377bf87f 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