From e53dc758fd8b85e0b0b97f230f965c87fec49e7f Mon Sep 17 00:00:00 2001 From: clc5q <clc5q@git.zephyr-software.com> Date: Thu, 25 Sep 2014 15:36:16 +0000 Subject: [PATCH] Handle fast return suppression on tail call cases. --- SMPDataFlowAnalysis.cpp | 2 ++ SMPFunction.cpp | 8 ++++++++ SMPFunction.h | 3 ++- SMPInstr.cpp | 5 +++++ SMPProgram.cpp | 12 +++++++----- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/SMPDataFlowAnalysis.cpp b/SMPDataFlowAnalysis.cpp index b4cdb0b6..db842c2e 100644 --- a/SMPDataFlowAnalysis.cpp +++ b/SMPDataFlowAnalysis.cpp @@ -3200,8 +3200,10 @@ SMPOperandType SMPPhiFunction::ConditionalMeetType(SMPBasicBlock *CurrBlock) con if ((BADADDR != DefAddr) && (DefAddr >= CurrBlock->GetFunc()->GetFirstFuncAddr())) { SMPInstr *DefInst = CurrBlock->GetFunc()->GetInstFromAddr(DefAddr); set<DefOrUse, LessDefUse>::iterator DefIter = DefInst->SetDefType(PhiOp, PtrType); +#if 0 SMP_msg("INFO: Converting zeroed reg from NUMERIC to POINTER at %lx for Block at %lx\n", (unsigned long) DefAddr, (unsigned long) BlockStartAddr); +#endif CurrBlock->GetFunc()->ResetProcessedBlocks(); SMPBasicBlock *DefBlock = CurrBlock->GetFunc()->GetBlockFromInstAddr(DefAddr); #if 0 // Causes infinite loops, crashes; need to debug !!!!****!!!! diff --git a/SMPFunction.cpp b/SMPFunction.cpp index 5875d0fa..48bffd01 100644 --- a/SMPFunction.cpp +++ b/SMPFunction.cpp @@ -8619,6 +8619,7 @@ void SMPFunction::MarkFunctionSafe() { bool HasIndirectWrite = false; bool IsIndirectCallTarget = false; // could be called indirectly bool IsTailCallTarget = false; // could be called by jump instruction used as tail call + bool MakesTailCall = false; // problem for Fast Returns, not fo return address safety bool HasNoCallers = this->AllCallSources.empty(); this->ReturnAddrStatus = FUNC_SAFE; @@ -8730,6 +8731,9 @@ void SMPFunction::MarkFunctionSafe() { } continue; } + if ((CurrInst->IsTailCall()) || (CurrInst->IsCondTailCall())) { + MakesTailCall = true; + } if (CurrInst->MDIsPopInstr() || CurrInst->MDIsReturnInstr()) { // ignore pops and returns for the moment continue; @@ -8868,6 +8872,10 @@ void SMPFunction::MarkFunctionSafe() { SMP_msg("INFO: Function at %lx becoming unsafe for fast returns because it has no callers.\n", (unsigned long) this->FirstEA); this->SetUnsafeForFastReturns(true, NO_CALLERS); } + if (MakesTailCall) { + SMP_msg("INFO: Function at %lx becoming unsafe for fast returns because it makes a tail call.\n", (unsigned long) this->FirstEA); + this->SetUnsafeForFastReturns(true, MAKES_TAIL_CALL); + } if (UnsafeReturnAddr) { SMP_msg("INFO: Function at %lx becoming unsafe for fast returns because its return addr is UNSAFE.\n", (unsigned long) this->FirstEA); diff --git a/SMPFunction.h b/SMPFunction.h index 8fdbeaaa..26b7d31d 100644 --- a/SMPFunction.h +++ b/SMPFunction.h @@ -120,7 +120,8 @@ enum UnsafeFastReturnReason { INDIRECTLY_CALLED = 8, NO_CALLERS = 16, TAIL_CALL_TARGET = 32, - RAUNSAFE_CALLEES = 64 + RAUNSAFE_CALLEES = 64, + MAKES_TAIL_CALL = 128 }; enum ControlFlowType { diff --git a/SMPInstr.cpp b/SMPInstr.cpp index b19fbc6f..a7daf19e 100644 --- a/SMPInstr.cpp +++ b/SMPInstr.cpp @@ -9682,6 +9682,9 @@ void SMPInstr::EmitFastReturnStatus(unsigned short FastReturnStatus) { if (TAIL_CALL_TARGET & FastReturnStatus) { SMP_fprintf(STARS_CallReturnFile, "TAILCALLED "); } + if (MAKES_TAIL_CALL & FastReturnStatus) { + SMP_fprintf(STARS_CallReturnFile, "MAKES_TAIL_CALL "); + } if (RAUNSAFE_CALLEES & FastReturnStatus) { SMP_fprintf(STARS_CallReturnFile, "UNSAFE_CALLEES "); } @@ -10552,6 +10555,8 @@ void SMPInstr::EmitIntegerErrorAnnotations(FILE *InfoAnnotFile, list<size_t> &Lo SSANum = DefIter->GetSSANum(); SMPOperandType DefType = DefIter->GetType(); SMPOperandType MemType; + SMPMetadataType DefMetaStatus = DefIter->GetMetadataStatus(); + bool DefUnusedMetadata = (DEF_METADATA_UNUSED == DefMetaStatus); bool IgnoreOverflow = this->IsBenignOverflow(IdiomCode); uval_t ConstValue = 0; // NOTE: We no longer suppress the IgnoreOverflow annotations. Instead, we print diff --git a/SMPProgram.cpp b/SMPProgram.cpp index 564d62aa..60f5debb 100644 --- a/SMPProgram.cpp +++ b/SMPProgram.cpp @@ -746,18 +746,20 @@ void SMPProgram::Analyze(ProfilerInformation *pi) { if (CurrFunc->StackPtrAnalysisSucceeded() && CurrFunc->HasGoodRTLs() && !CurrFunc->HasIndirectJumps() && !CurrFunc->HasSharedChunks()) { #endif changed |= CurrFunc->InferInterproceduralTypes(); + } #if 0 - if (0 == strcmp("__mktime_internal", CurrFunc->GetFuncName())) { - CurrFunc->Dump(); - } -#endif + if ((!changed || (IterationCounter > STARS_INTERPROCEDURAL_ITERATION_LIMIT)) && (0 == strcmp("__mktime_internal", CurrFunc->GetFuncName()))) { + CurrFunc->Dump(); } +#endif } } while (changed && (IterationCounter <= STARS_INTERPROCEDURAL_ITERATION_LIMIT)); SMP_msg("Interprocedural type inference terminated after iteration %zu changed: %d\n", IterationCounter, changed); #endif - // Free memory not needed to emit annotations, now that type inference is done. + + + // Free memory not needed to emit annotations, now that type inference is done. CurrFunc->FreeUnusedMemory4(); #if SMP_COUNT_MEMORY_ALLOCATIONS -- GitLab