void SimpleInliner::doAnalysis(void) { getValidFunctionDecls(); for (SmallVector<CallExpr *, 10>::iterator CI = AllCallExprs.begin(), CE = AllCallExprs.end(); CI != CE; ++CI) { FunctionDecl *CalleeDecl = (*CI)->getDirectCallee(); TransAssert(CalleeDecl && "Bad CalleeDecl!"); FunctionDecl *CanonicalDecl = CalleeDecl->getCanonicalDecl(); if (!ValidFunctionDecls.count(CanonicalDecl)) continue; if (!hasValidArgExprs(*CI)) continue; ValidInstanceNum++; if (TransformationCounter == ValidInstanceNum) { // It's possible the direct callee is not a definition if (!CalleeDecl->isThisDeclarationADefinition()) { CalleeDecl = CalleeDecl->getCanonicalDecl(); for(FunctionDecl::redecl_iterator RI = CalleeDecl->redecls_begin(), RE = CalleeDecl->redecls_end(); RI != RE; ++RI) { if ((*RI)->isThisDeclarationADefinition()) { CalleeDecl = (*RI); break; } } } TransAssert(CalleeDecl->isThisDeclarationADefinition() && "Bad CalleeDecl!"); CurrentFD = CalleeDecl; TheCaller = CalleeToCallerMap[(*CI)]; TransAssert(TheCaller && "NULL TheCaller!"); TheCallExpr = (*CI); } } }
bool SimpleInlinerCollectionVisitor::VisitCallExpr(CallExpr *CE) { FunctionDecl *FD = CE->getDirectCallee(); if (!FD) return true; ConsumerInstance->AllCallExprs.push_back(CE); ConsumerInstance->CalleeToCallerMap[CE] = ConsumerInstance->CurrentFD; FunctionDecl *CanonicalFD = FD->getCanonicalDecl(); unsigned int NumCalls = ConsumerInstance->FunctionDeclNumCalls[CanonicalFD]; NumCalls++; ConsumerInstance->FunctionDeclNumCalls[CanonicalFD] = NumCalls; NumStmts++; return true; }
bool MoveFunctionBody::HandleTopLevelDecl(DeclGroupRef D) { for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { FunctionDecl *FD = dyn_cast<FunctionDecl>(*I); if (!FD) { PrevFunctionDecl = NULL; continue; } FunctionDecl *CanonicalFD = FD->getCanonicalDecl(); if (FD->isThisDeclarationADefinition()) { FunctionDecl *FDDecl = AllValidFunctionDecls[CanonicalFD]; if (!FDDecl) { PrevFunctionDecl = NULL; continue; } // Declaration and Definition are next to each other if (PrevFunctionDecl) { FunctionDecl *CanonicalPrevFD = PrevFunctionDecl->getCanonicalDecl(); if (CanonicalFD == CanonicalPrevFD) { PrevFunctionDecl = NULL; continue; } } FuncDeclToFuncDef[FDDecl] = FD; } PrevFunctionDecl = FD; // We only need the first FunctionDecl if (AllValidFunctionDecls[CanonicalFD]) continue; AllValidFunctionDecls[CanonicalFD] = FD; } return true; }
void SimpleInliner::doAnalysis(void) { #ifdef DEBUGCL std::cerr << "SimpleInliner::doAnalysis" << std::endl; std::cerr << "Size of AllCallExprs = " << AllCallExprs.size() << std::endl; #endif getValidFunctionDecls(); for (SmallVector<CallExpr *, 10>::iterator CI = AllCallExprs.begin(), CE = AllCallExprs.end(); CI != CE; ++CI) { FunctionDecl *CalleeDecl = (*CI)->getDirectCallee(); TransAssert(CalleeDecl && "Bad CalleeDecl!"); FunctionDecl *CanonicalDecl = CalleeDecl->getCanonicalDecl(); #ifdef DEBUGCL std::cerr << "CanonicalDecl = " << CanonicalDecl->getName().str() << std::endl; #endif if (!ValidFunctionDecls.count(CanonicalDecl)) { #ifdef DEBUGCL std::cerr << "!ValidFunctionDecls.count" << std::endl; #endif continue; } if (!hasValidArgExprs(*CI)) { #ifdef DEBUGCL std::cerr << "!hasValidArgExprs" << std::endl; #endif continue; } ValidInstanceNum++; #ifdef DEBUGCL std::cerr << "TransformationCounter = " << TransformationCounter << " and ValidInstanceNum = " << ValidInstanceNum << std::endl; #endif if (TransformationCounter == ValidInstanceNum) { #ifdef DEBUGCL std::cerr << "TransformationCounter == ValidInstanceNum" << std::endl; #endif // It's possible the direct callee is not a definition if (!CalleeDecl->isThisDeclarationADefinition()) { CalleeDecl = CalleeDecl->getFirstDeclaration(); for(FunctionDecl::redecl_iterator RI = CalleeDecl->redecls_begin(), RE = CalleeDecl->redecls_end(); RI != RE; ++RI) { if ((*RI)->isThisDeclarationADefinition()) { CalleeDecl = (*RI); break; } } } TransAssert(CalleeDecl->isThisDeclarationADefinition() && "Bad CalleeDecl!"); CurrentFD = CalleeDecl; TheCaller = CalleeToCallerMap[(*CI)]; TransAssert(TheCaller && "NULL TheCaller!"); #ifdef DEBUGCL std::cerr << "Assigning TheCallExpr" << std::endl; #endif TheCallExpr = (*CI); } } }