From ba5ddc1599ec71b2ab481b6a6c977c04dc1630a0 Mon Sep 17 00:00:00 2001
From: jdh8d <jdh8d@git.zephyr-software.com>
Date: Sat, 28 Jun 2008 01:44:36 +0000
Subject: [PATCH] *** empty log message ***

---
 SMPInstr.cpp | 48 ++++++++++++++++++++++++++++++++++++++----------
 SMPInstr.h   |  2 ++
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/SMPInstr.cpp b/SMPInstr.cpp
index cc31e7de..a1d70ca9 100644
--- a/SMPInstr.cpp
+++ b/SMPInstr.cpp
@@ -392,7 +392,8 @@ void SMPInstr::SetAddSubSourceType(void) {
 } // end of SMPInstr::SetAddSubSourceType()
 
 // Are all DEFs in the DEF set NUMERIC type?
-bool SMPInstr::AllDefsNumeric(void) {
+bool SMPInstr::AllDefsNumeric(void) 
+{
 	bool AllNumeric = (this->Defs.GetSize() > 0);  // false if no DEFs, true otherwise
 	set<DefOrUse, LessDefUse>::iterator CurrDef;
 	for (CurrDef = this->GetFirstDef(); CurrDef != this->GetLastDef(); ++CurrDef) {
@@ -401,6 +402,17 @@ bool SMPInstr::AllDefsNumeric(void) {
 	return AllNumeric;
 } // end of SMPInstr::AllDefsNumeric()
 
+bool SMPInstr::AnyDefsProfiled(void) 
+{
+	bool profd = false;
+	set<DefOrUse, LessDefUse>::iterator CurrDef;
+	for (CurrDef = this->GetFirstDef(); CurrDef != this->GetLastDef(); ++CurrDef) 
+	{
+		profd = (profd || IsProfDerived(CurrDef->GetType()));
+	}
+	return profd;
+} 
+
 // Do all DEFs have DEF_METADATA_UNUSED status?
 bool SMPInstr::AllDefMetadataUnused(void) {
 	bool AllUnused = (this->Defs.GetSize() > 0);  // false if no DEFs, true otherwise
@@ -2504,7 +2516,7 @@ void SMPInstr::EmitAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile) {
 	flags_t InstrFlags = getFlags(addr);
 	bool MemDest = this->HasDestMemoryOperand();
 	bool MemSrc = this->HasSourceMemoryOperand();
-	bool SecondSrcOperandNum = this->IsSecondSrcOperandNumeric(InstrFlags);
+	bool SecondSrcOperandNum = this->IsSecondSrcOperandNumeric(InstrFlags); 	// assumes 2nd source is Imm or not-numeric?!
 
 	++OptCount[OptType]; // keep count for debugging info
 
@@ -2634,6 +2646,10 @@ void SMPInstr::EmitAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile) {
 			break;
 		}
 	} // end switch (OptType)
+
+	// always emit stack constant annotations, in case strata is 
+	// instrumenting all instructions, or trying to verify speculative annotations. 
+	this->AnnotateStackConstants(UseFP, AnnotFile);
 	
 	// If mmStrata is going to have to deal with the
 	//  instruction, then we can annotate EBP and ESP
@@ -2641,7 +2657,6 @@ void SMPInstr::EmitAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile) {
 	//  an annotation of type -1, there is no point
 	//  in telling mmStrata about these constants.
 	if (SDTInstrumentation) {
-		this->AnnotateStackConstants(UseFP, AnnotFile);
 		if (strlen(this->DeadRegsString) > 0) {
 			// Optimize by informing mmStrata of dead registers. It can avoid saving
 			//  and restoring dead state. This is particularly important for EFLAGS,
@@ -2670,10 +2685,11 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 	flags_t InstrFlags = getFlags(addr);
 	int TypeGroup = SMPTypeCategory[this->SMPcmd.itype];
 	bool NumericDEFs = this->AllDefsNumeric();  // all DEFs are NUMERIC or CODEPTR
+	bool ProfiledDEFs = this->AnyDefsProfiled();  // all DEFs are NUMERIC or CODEPTR
 	bool UnusedMetadata = this->AllDefMetadataUnused();
 	bool MemDest = this->HasDestMemoryOperand();
 	bool MemSrc = this->HasSourceMemoryOperand();
-	bool SecondSrcOperandNum = this->IsSecondSrcOperandNumeric(InstrFlags);
+	bool SecondSrcOperandNum = this->IsSecondSrcOperandNumeric(InstrFlags); // assumes 2nd source is imm or not-numeric??
 	SMPMetadataType DefMetadataType = this->GetDefMetadataType();
 
 	++OptCount[this->OptType]; // keep count for debugging info
@@ -2709,6 +2725,13 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 	switch (TypeGroup) {
 		case 0:  // SDT will have to handle these
 		case 11: // PUSH/POP  **!!** What if we push/pop NUMERIC type? Optimize?
+
+			// --jdh
+			// pop numeric's can be optimized with a numericdef annotation.
+			// numeric push's can't immediately be optimized, but if the stack location
+			// can be proven as dead metadata, then perhaps optimize.
+			// --jdh
+
 			// mmStrata wants to suppress warnings on the PUSH
 			//  instructions that precede the LocalVarsAllocInstr
 			//  (i.e. the PUSHes of callee-saved regs).
@@ -2735,6 +2758,7 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 
 		case 4:  // INC, DEC, etc.: no SDT work unless MemDest
 			if (MemDest || MemSrc) { // pretty conservative here?
+						// could be more aggressive if we know there's no overflow. -- jdh
 				SDTInstrumentation = true;
 				break;  // treat as category 0
 	 		}
@@ -2767,7 +2791,7 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 			}
 			else if (NumericDEFs) {
 				qfprintf(AnnotFile, "%10x %6d INSTR LOCAL n %s NumericDEFs %s \n",
-						addr, -2, this->DestString(this->OptType), disasm);
+						addr, ProfiledDEFs ? -256-2 : -2, this->DestString(this->OptType), disasm);
 				++AnnotationCount[this->OptType];
 			}
 #if SMP_OPTIMIZE_ADD_TO_NUMERIC
@@ -2811,7 +2835,7 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 #if 0
 				if (NumericDEFs) {
 					qfprintf(AnnotFile, "%10x %6d INSTR LOCAL n %s NumericDEFs %s \n",
-						addr, -2, this->DestString(this->OptType), disasm);
+						addr, ProfiledDEFs ? -256-2 : -2, this->DestString(this->OptType), disasm);
 					++AnnotationCount[this->OptType];
 				}
 #endif
@@ -2831,7 +2855,7 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 			}
 			else if (NumericDEFs) { // NUMERIC result because of NUMERIC sources
 				qfprintf(AnnotFile, "%10x %6d INSTR LOCAL n %s NumericDEFs %s \n",
-						addr, -2, this->DestString(this->OptType), disasm);
+						addr, ProfiledDEFs ? -256-2 : -2, this->DestString(this->OptType), disasm);
 				++AnnotationCount[this->OptType];
 			}
 			break;
@@ -2844,7 +2868,7 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 			}
 			else if (NumericDEFs) { // NUMERIC result because of NUMERIC sources
 				qfprintf(AnnotFile, "%10x %6d INSTR LOCAL %s %s \n", addr,
-						-1, OptExplanation[TypeGroup], disasm);
+						ProfiledDEFs ? -256-1 : -1, OptExplanation[TypeGroup], disasm);
 				++AnnotationCount[this->OptType];
 			}
 			else 
@@ -2878,19 +2902,23 @@ void SMPInstr::EmitTypeAnnotations(bool UseFP, bool AllocSeen, FILE *AnnotFile)
 			}
 			else if (NumericDEFs) { // NUMERIC move instruction
 				qfprintf(AnnotFile, "%10x %6d INSTR LOCAL n %s NumericDEFs %s \n",
-						addr, -2, this->DestString(this->OptType), disasm);
+						addr, ProfiledDEFs ? -256-2 : -2, this->DestString(this->OptType), disasm);
 				++AnnotationCount[this->OptType];
 			}
 			break;
 	} // end switch (OptType)
 	
+
+
+	// always annotate stack constants for the profiler, etc.
+	this->AnnotateStackConstants(UseFP, AnnotFile);
+
 	// If mmStrata is going to have to deal with the
 	//  instruction, then we can annotate EBP and ESP
 	//  relative constant offsets. If we have emitted
 	//  an annotation of type -1, there is no point
 	//  in telling mmStrata about these constants.
 	if (SDTInstrumentation) {
-		this->AnnotateStackConstants(UseFP, AnnotFile);
 		if (strlen(this->DeadRegsString) > 0) {
 			// Optimize by informing mmStrata of dead registers. It can avoid saving
 			//  and restoring dead state. This is particularly important for EFLAGS,
diff --git a/SMPInstr.h b/SMPInstr.h
index adbb0e37..d3f18242 100644
--- a/SMPInstr.h
+++ b/SMPInstr.h
@@ -283,6 +283,8 @@ private:
 
 	// Methods
 	bool AllDefsNumeric(void);  // true if all DEFs are NUMERIC or CODEPTR
+	bool AnyDefsProfiled(void);	// true if any defs are profile derived
+
 	bool AllDefMetadataUnused(void); // true if all DEF metadata not needed
 	void BuildSMPDefUseLists(void); // Build DEF and USE lists for instruction
 	void MDFixupDefUseLists(void); // Machine-dependent ad hoc fixes
-- 
GitLab