Mercurial > hg > Members > tobaru > cbc > CbC_llvm
changeset 82:e218c19a8176
markTailToCodeSegments ensure code segments are marked tail
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 27 Oct 2014 20:20:15 +0900 |
parents | 97a220dc594f |
children | 5e5d649e25d2 |
files | lib/Transforms/Scalar/TailRecursionElimination.cpp |
diffstat | 1 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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<CallInst>(&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