From 6ceb5a6c2240b7bd6a748bbeb54070ca62e3068c Mon Sep 17 00:00:00 2001 From: clc5q <clc5q@git.zephyr-software.com> Date: Mon, 11 May 2015 18:26:14 +0000 Subject: [PATCH] Minor optimization, reducing operand canonicalization. Former-commit-id: d974e58bf5dfdcefafbd47ce9f0d326a0dbb8b70 --- src/base/SMPBasicBlock.cpp | 70 +++++++++++++++----------------- src/base/SMPDataFlowAnalysis.cpp | 7 ++-- src/base/SMPInstr.cpp | 2 +- 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/src/base/SMPBasicBlock.cpp b/src/base/SMPBasicBlock.cpp index cb973a88..415e368e 100644 --- a/src/base/SMPBasicBlock.cpp +++ b/src/base/SMPBasicBlock.cpp @@ -19,7 +19,7 @@ * e-mail: jwd@virginia.com * URL : http://www.cs.virginia.edu/ * - * Additional copyrights 2010, 2011 by Zephyr Software LLC + * Additional copyrights 2010, 2011, 2012, 2013, 2014, 2015 by Zephyr Software LLC * e-mail: {clc,jwd}@zephyr-software.com * URL : http://www.zephyr-software.com/ * @@ -809,29 +809,29 @@ set<DefOrUse, LessDefUse>::iterator SMPBasicBlock::GetGlobalDefIterFromDefAddr(S // If DEF is in a Phi function, we return the block number, which (hopefully) never conflicts with instruction // addresses. STARS_ea_t SMPBasicBlock::GetDefAddrFromUseAddr(STARSOpndTypePtr UseOp, STARS_ea_t InstAddr, int SSANum, bool LocalName) { - STARS_ea_t DefAddr = BADADDR; + STARS_ea_t DefAddr = STARS_BADADDR; bool RegisterOp = (UseOp->IsRegOp()); bool PhiUse = (STARS_IsBlockNumPseudoID(InstAddr)); if (RegisterOp && (!LocalName)) { // Global DEF for this SSANum must be in the Phi functions or within a block. DefAddr = this->MyFunc->GetGlobalDefAddr(UseOp, SSANum); // only works on registers - if (DefAddr == BADADDR) { // Could not find it anywhere. + if (DefAddr == STARS_BADADDR) { // Could not find it anywhere. this->GetFunc()->Dump(); SMP_msg("ERROR: Failure in GetDefAddrFromUseAddr(): InstAddr %lx SSANum %d\n", (unsigned long) InstAddr, SSANum); SMP_msg(" LocalName: %d UseOp.reg: %d\n", LocalName, UseOp->GetReg()); - assert(DefAddr != BADADDR); // kablooey! + assert(DefAddr != STARS_BADADDR); // kablooey! } } else if (LocalName || MDIsDirectStackAccessOpnd(UseOp, this->GetFunc()->UsesFramePointer())) { if (PhiUse) { // Need to find DEF for a PhiUse. Temporarily, we will use the slow linear search method. DefAddr = this->GetFunc()->GetGlobalDefAddr(UseOp, SSANum); - if (BADADDR == DefAddr) { // Need to search Phi functions. + if (STARS_BADADDR == DefAddr) { // Need to search Phi functions. // Rare case in which a Phi USE was traced only to a Phi DEF in an earlier block. DefAddr = (STARS_ea_t) this->GetFunc()->GetBlockNumForPhiDef(UseOp, SSANum); - assert(BADADDR != DefAddr); + assert(STARS_BADADDR != DefAddr); DefAddr += STARS_PSEUDO_ID_MIN; } } @@ -850,7 +850,7 @@ STARS_ea_t SMPBasicBlock::GetDefAddrFromUseAddr(STARSOpndTypePtr UseOp, STARS_ea ++RevInstIter; } } - if (DefAddr == BADADDR) { // not found yet + if (DefAddr == STARS_BADADDR) { // not found yet // Must be a global name defined in the Phi functions or LiveIn and UpExposed to the block, or a non-stack mem access. bool UseFP = this->GetFunc()->UsesFramePointer(); assert(!LocalName || (!MDIsDataFlowOpnd(UseOp, UseFP))); @@ -873,7 +873,7 @@ STARS_ea_t SMPBasicBlock::GetDefAddrFromUseAddr(STARSOpndTypePtr UseOp, STARS_ea } // end of SMPBasicBlock::GetDefAddrFromUseAddr() STARS_ea_t SMPBasicBlock::GetUltimateDefAddr(STARSOpndTypePtr UseOp, STARS_ea_t InstAddr, int SSANum, bool LocalName) { - STARS_ea_t DefAddr = BADADDR; + STARS_ea_t DefAddr = STARS_BADADDR; DefAddr = this->GetDefAddrFromUseAddr(UseOp, InstAddr, SSANum, LocalName); bool LiveInAddr = STARS_IsLiveInPseudoID(DefAddr); if (LiveInAddr && this->IsLiveIn(UseOp)) { // UpExposed or pass-through case @@ -952,7 +952,7 @@ STARS_ea_t SMPBasicBlock::GetUltimateDefAddr(STARSOpndTypePtr UseOp, STARS_ea_t else { // We can use LastPredInst addr as pseudo-UseAddr. DefAddr = PredBlock->GetUltimateDefAddr(UseOp, LastPredAddr, SSANum, LocalName); } - if (BADADDR != DefAddr) { + if (STARS_BADADDR != DefAddr) { break; } } @@ -961,10 +961,10 @@ STARS_ea_t SMPBasicBlock::GetUltimateDefAddr(STARSOpndTypePtr UseOp, STARS_ea_t } // end if LiveIn #if 0 if (LiveInAddr) { - DefAddr = BADADDR; + DefAddr = STARS_BADADDR; } #endif - assert(BADADDR != DefAddr); + assert(STARS_BADADDR != DefAddr); return DefAddr; } // end of SMPBasicBlock::GetUltimateDefAddr() @@ -975,7 +975,7 @@ STARS_ea_t SMPBasicBlock::GetUltimateOperandSource(STARS_ea_t UseAddr, STARSOpnd SMPBasicBlock *CurrBlock; // We have four possibilities for DefiningAddr: - // 1: BADADDR means we cannot trace the operand. + // 1: STARS_BADADDR means we cannot trace the operand. // 2: An instruction address, in which case we recurse if inst is a move. // 3: Our block number, which means a Phi DEF, so we need to recurse into our predecessors. // 4: Our block's first addr minus one, indicating upexposed in this block, need to recurse into predecessors. @@ -991,7 +991,7 @@ bool SMPBasicBlock::IsOpDestTruncatedWrite(STARSOpndTypePtr DefOp, int DefSSANum set<DefOrUse, LessDefUse>::iterator DefIter; bool RegisterOp = (DefOp->IsRegOp()); bool LastUseIsTruncatedWrite = false; - STARS_ea_t LastAddr = BADADDR; + STARS_ea_t LastAddr = STARS_BADADDR; if (!RegisterOp || (DefSSANum == SMP_SSA_UNINIT)) return false; @@ -1010,7 +1010,7 @@ bool SMPBasicBlock::IsOpDestTruncatedWrite(STARSOpndTypePtr DefOp, int DefSSANum ++InstIter; } - if (BADADDR != LastAddr) { + if (STARS_BADADDR != LastAddr) { InstIter = this->GetInstIterFromAddr(LastAddr); LastUseInst = (*InstIter); if (LastUseInst->MDDoublesWidth()) { @@ -1748,7 +1748,7 @@ void SMPBasicBlock::PropagateBranchSignedness(STARS_ea_t DefAddr, STARSOpndTypeP if (OldSignInfo != (OldSignInfo | SignMask)) { // sign info will change this->MyFunc->UpdateUseSignMiscInfo(UseHashValue, SignMask); PhiUseDefAddr = this->MyFunc->GetGlobalDefAddr(SearchOp, UseSSANum); - assert(BADADDR != PhiUseDefAddr); + assert(STARS_BADADDR != PhiUseDefAddr); if (STARS_IsBlockNumPseudoID(PhiUseDefAddr)) { // DEF of current Phi USE is in another Phi function. DefBlock = this->MyFunc->GetBlockByNum(STARS_GetBlockNumFromPseudoID(PhiUseDefAddr)); @@ -1862,7 +1862,7 @@ void SMPBasicBlock::PropagateBranchSignedness(STARS_ea_t DefAddr, STARSOpndTypeP #else bool PropagateThroughUses = false; #endif - STARS_ea_t UseDefAddr = BADADDR; + STARS_ea_t UseDefAddr = STARS_BADADDR; for (UseIter = DefInst->GetFirstUse(); UseIter != DefInst->GetLastUse(); ++UseIter) { STARSOpndTypePtr UseOp = UseIter->GetOp(); if (UseOp->IsRegOp() && ((!ReadsMemory) || (DefInst->IsNonAddressReg(UseOp)))) { // don't want addressing registers @@ -2560,7 +2560,7 @@ bool SMPBasicBlock::PropagateLocalMetadata(STARSOpndTypePtr UseOp, SMPMetadataTy assert(0 <= SSANum); STARS_ea_t DefAddr = this->GetDefAddrFromUseAddr(UseOp, UseAddr, SSANum, true); - if ((DefAddr == BADADDR) || STARS_IsLiveInPseudoID(DefAddr)) { + if ((DefAddr == STARS_BADADDR) || STARS_IsLiveInPseudoID(DefAddr)) { return false; } @@ -2787,7 +2787,7 @@ void SMPBasicBlock::InferGlobalDefType(STARSOpndTypePtr DefOp, int SSANum, STARS // boolean in-out arguments. SMPOperandType UseType = UNINIT; - if (BADADDR == DefAddr) { // DEF is USEd (and thus re-DEFed) in a Phi function + if (STARS_BADADDR == DefAddr) { // DEF is USEd (and thus re-DEFed) in a Phi function DefEscapes = false; set<SMPPhiFunction, LessPhi>::iterator UsePhi; UsePhi = this->FindPhi(DefOp); @@ -2861,10 +2861,10 @@ void SMPBasicBlock::InferGlobalDefType(STARSOpndTypePtr DefOp, int SSANum, STARS PhiIter = CurrBlock->FindPhi(DefOp); TempAddr = DefAddr; if (PhiIter != CurrBlock->GetLastPhi()) { - TempAddr = BADADDR; // signals that DefOp will get re-DEFed in a Phi function. + TempAddr = STARS_BADADDR; // signals that DefOp will get re-DEFed in a Phi function. } - else if (BADADDR == TempAddr) { // was BADADDR coming in to this function - // We don't want to pass BADADDR down the recursion chain, because it will be interpreted + else if (STARS_BADADDR == TempAddr) { // was STARS_BADADDR coming in to this function + // We don't want to pass STARS_BADADDR down the recursion chain, because it will be interpreted // by each successor block to mean that DefOp was a Phi USE that got re-DEFed in a Phi function // within itself. Pass the dummy address that indicates LiveIn to the block. TempAddr = STARS_LIVEIN_PSEUDO_ID; @@ -2945,7 +2945,7 @@ set<SMPPhiFunction, LessPhi>::iterator SMPBasicBlock::InferPhiDefType(set<SMPPhi } else if (!UnsafeOp) { // try back inference from USEs of Phi DEF SMPOperandType DefType; - DefType = this->MyFunc->InferGlobalDefType(DefOp, SSANum, this, false, BADADDR); + DefType = this->MyFunc->InferGlobalDefType(DefOp, SSANum, this, false, STARS_BADADDR); if (IsNotEqType(UNINIT, DefType)) { // Don't set changed, because there is no downward propagation // to do. Instead, propagate only to UNINIT Phi USEs. @@ -4245,7 +4245,7 @@ bool SMPBasicBlock::IsBenignOverflowDEF(STARSOpndTypePtr DefOp, int DefSSANum, s // only capable of two-address instructions. For either of the source operands, we want to // suppress annotations if the ultimate source was any special operation, such as bitwise operations // or zero-extended moves. - STARS_ea_t SourceInstAddr = BADADDR; + STARS_ea_t SourceInstAddr = STARS_BADADDR; int UseSSANum = SMP_SSA_UNINIT; bool SpecialSourceFound = false; if (DefInst->MDIsLoadEffectiveAddressInstr()) { @@ -4270,7 +4270,7 @@ bool SMPBasicBlock::IsBenignOverflowDEF(STARSOpndTypePtr DefOp, int DefSSANum, s } SMPInstr *SourceInst = NULL; - SourceInstAddr = BADADDR; + SourceInstAddr = STARS_BADADDR; UseSSANum = SMP_SSA_UNINIT; SpecialSourceFound = false; UseIter = DefInst->FindUse(DefOp); // DEF is also USE in addition, subtraction, etc. @@ -4953,7 +4953,7 @@ bool SMPBasicBlock::IsBenignTruncationDEF(STARSOpndTypePtr DefOp, int DefSSANum, return true; SMPInstr *DefInst = this->GetFunc()->GetInstFromAddr(DefAddr); - STARS_ea_t SourceInstAddr = BADADDR; + STARS_ea_t SourceInstAddr = STARS_BADADDR; SMPInstr *SourceInst = NULL; int DefUseSSANum = SMP_SSA_UNINIT; bool SpecialSourceFound = false; @@ -4977,7 +4977,7 @@ bool SMPBasicBlock::IsBenignTruncationDEF(STARSOpndTypePtr DefOp, int DefSSANum, // is a sign that the truncation use is also only valid for the lower bits. bool LocalName = this->IsLocalName(SearchOp); STARS_ea_t UseDefAddr = this->GetDefAddrFromUseAddr(SearchOp, DefAddr, UseSSANum, LocalName); - if ((BADADDR != UseDefAddr) && (!STARS_IsBlockNumPseudoID(UseDefAddr))) { + if ((STARS_BADADDR != UseDefAddr) && (!STARS_IsBlockNumPseudoID(UseDefAddr))) { // We have a valid inst addr (not Phi block number). See if it is a reg to reg copy. SMPInstr *CopyInst = this->GetFunc()->GetInstFromAddr(UseDefAddr); if (CopyInst->MDIsMoveInstr()) { @@ -5048,7 +5048,7 @@ bool SMPBasicBlock::IsBenignTruncationDEF(STARSOpndTypePtr DefOp, int DefSSANum, // write subword of edx ; not really a truncation bool LocalName = this->IsLocalName(SearchOp); STARS_ea_t UseDefAddr = this->GetDefAddrFromUseAddr(SearchOp, DefAddr, UseSSANum, LocalName); - if (BADADDR != UseDefAddr) { + if (STARS_BADADDR != UseDefAddr) { // Check for Phi DEF instead of inst DEF. bool PhiDEF = false; if (STARS_IsBlockNumPseudoID(UseDefAddr)) { // Phi DEF; UseDefAddr is pseudo-addr @@ -5079,20 +5079,18 @@ bool SMPBasicBlock::IsDefMaskedOrShiftedRight(STARSOpndTypePtr DefOp, int DefSSA vector<SMPInstr *>::iterator InstIter; set<DefOrUse, LessDefUse>::iterator UseIter, DefIter; - STARSOpndTypePtr SearchOp = CloneIfSubwordReg(DefOp); int UseSSANum; STARS_ea_t InstAddr; size_t BytesMasked; if (DefOp->IsRegOp()) { - CanonicalizeOpnd(SearchOp); for (InstIter = this->GetFirstInst(); InstIter != this->GetLastInst(); ++InstIter) { SMPInstr *CurrInst = (*InstIter); InstAddr = CurrInst->GetAddr(); if (CurrInst->IsMarkerInst()) continue; if (InstAddr > DefAddr) { - UseIter = CurrInst->FindUse(SearchOp); + UseIter = CurrInst->FindUse(DefOp); if (UseIter != CurrInst->GetLastUse()) { UseSSANum = UseIter->GetSSANum(); if (UseSSANum == DefSSANum) { @@ -5115,7 +5113,7 @@ bool SMPBasicBlock::IsDefMaskedOrShiftedRight(STARSOpndTypePtr DefOp, int DefSSA break; } } - DefIter = CurrInst->FindDef(SearchOp); + DefIter = CurrInst->FindDef(DefOp); if (DefIter != CurrInst->GetLastDef()) { // Re-DEF. Did not find masking inst. break; @@ -5226,11 +5224,9 @@ bool SMPBasicBlock::UseHasCriticalSink(STARSOpndTypePtr DefOp, int DefSSANum, ST // it is a register or stack location. DefIter = CurrInst->GetFirstNonFlagsDef(); assert(DefIter != CurrInst->GetLastDef()); - STARSOpndTypePtr NewDefOp = CloneIfSubwordReg(DefIter->GetOp()); - if (MDIsDataFlowOpnd(NewDefOp, this->GetFunc()->UsesFramePointer())) { - // Follow NewDefOp from now on in addition to DefOp. - CanonicalizeOpnd(NewDefOp); - DefOp2 = NewDefOp; + if (MDIsDataFlowOpnd(DefIter->GetOp(), this->GetFunc()->UsesFramePointer())) { + // Follow DefOp2 from now on in addition to DefOp. + DefOp2 = DefIter->GetOp(); SearchSSANum2 = DefIter->GetSSANum(); } } @@ -5596,7 +5592,7 @@ bool SMPBasicBlock::IsBranchSignednessUnreliable(void) { // UNSIGNED. bool JumpAbove = false; bool JumpBelow = false; - STARS_ea_t TargetAddr = BADADDR, BranchAddr = BADADDR; + STARS_ea_t TargetAddr = STARS_BADADDR, BranchAddr = STARS_BADADDR; SMPInstr *BranchInst; unsigned short opcode; vector<SMPInstr *>::reverse_iterator InstRevIter; diff --git a/src/base/SMPDataFlowAnalysis.cpp b/src/base/SMPDataFlowAnalysis.cpp index f6123678..81f3a905 100644 --- a/src/base/SMPDataFlowAnalysis.cpp +++ b/src/base/SMPDataFlowAnalysis.cpp @@ -2626,17 +2626,16 @@ DefOrUse::DefOrUse(void) { // Constructor. DefOrUse::DefOrUse(STARSOpndTypePtr Ref, SMPOperandType Type, int SSASub) { - STARSOpndTypePtr Ref2 = nullptr; if (Ref->IsRegOp()) { // We want to map AH, AL, and AX to EAX, etc. throughout our data flow analysis // and type inference systems. - Ref2 = CloneIfSubwordReg(Ref); + STARSOpndTypePtr Ref2 = CloneIfSubwordReg(Ref); CanonicalizeOpnd(Ref2); + this->Operand = Ref2; } else { - Ref2 = Ref; + this->Operand = Ref; } - this->Operand = Ref2; this->SSANumber = SSASub; this->OpType = Type; diff --git a/src/base/SMPInstr.cpp b/src/base/SMPInstr.cpp index d6446161..ecdb2916 100644 --- a/src/base/SMPInstr.cpp +++ b/src/base/SMPInstr.cpp @@ -7134,7 +7134,7 @@ void SMPInstr::MDSetWidthSignInfo(bool UseFP) { for (std::size_t index = 0; index < this->RTL.GetCount(); ++index) { CurrRT = this->RTL.GetRT(index); STARSOpndTypePtr LeftOp = CurrRT->GetLeftOperand(); - if (nullptr != LeftOp) + if ((nullptr != LeftOp) && (!case2)) DefOp = CloneIfSubwordReg(LeftOp); else DefOp = nullptr; -- GitLab