# HG changeset patch # User Kaito Tokumori # Date 1414408815 -32400 # Node ID e218c19a8176f846a2ce02985928aa71e4813181 # Parent 97a220dc594f521b06627ab0987ac0fb257b977b markTailToCodeSegments ensure code segments are marked tail diff -r 97a220dc594f -r e218c19a8176 lib/Transforms/Scalar/TailRecursionElimination.cpp --- a/lib/Transforms/Scalar/TailRecursionElimination.cpp Wed Oct 22 18:26:28 2014 +0900 +++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp Mon Oct 27 20:20:15 2014 +0900 @@ -128,6 +128,7 @@ bool onlyForCbC; public: bool isOnlyForCbC(); + bool markTailToCodeSegments(Function &F); #endif }; } @@ -281,6 +282,11 @@ bool Modified = false; +#ifndef noCbC + if (F.getReturnType()->is__CodeTy()) + Modified = markTailToCodeSegments(F); +#endif + // Track whether a block is reachable after an alloca has escaped. Blocks that // contain the escaping instruction will be marked as being visited without an // escaped alloca, since that is how the block began. @@ -863,7 +869,27 @@ } #ifndef noCbC - bool TailCallElim::isOnlyForCbC(){ +bool TailCallElim::isOnlyForCbC(){ return onlyForCbC; } + +bool TailCallElim::markTailToCodeSegments(Function &F){ + bool Modified = false; + for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { + for (auto &I : *BB) { + CallInst *CI = dyn_cast(&I); + Function* Called; + if (CI) + Called = CI->getCalledFunction(); + else + continue; + // We should touch only code segment call. + if (Called && Called->getReturnType()->is__CodeTy()) { + CI->setTailCall(); + Modified = true; + } + } + } + return Modified; +} #endif