Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/SMPStaticAnalyzer
1 result
Show changes
Commits on Source (2)
...@@ -271,8 +271,8 @@ public: ...@@ -271,8 +271,8 @@ public:
STARSOpndTypePtr GetRightOperand(void) const; STARSOpndTypePtr GetRightOperand(void) const;
STARSOpndTypePtr GetLeftOperandNoNorm(void) const { return LeftOperand; }; // don't normalize stack ops; for SPARK translation STARSOpndTypePtr GetLeftOperandNoNorm(void) const { return LeftOperand; }; // don't normalize stack ops; for SPARK translation
STARSOpndTypePtr GetRightOperandNoNorm(void) const { return RightOperand; }; // don't normalize stack ops; for SPARK translation STARSOpndTypePtr GetRightOperandNoNorm(void) const { return RightOperand; }; // don't normalize stack ops; for SPARK translation
inline const STARSOpndTypePtr &GetConstLeftOperandNoNorm(void) { return LeftOperand; }; inline const STARSOpndTypePtr &GetConstLeftOperandNoNorm(void) const { return LeftOperand; };
inline const STARSOpndTypePtr &GetConstRightOperandNoNorm(void) { return RightOperand; }; inline const STARSOpndTypePtr &GetConstRightOperandNoNorm(void) const { return RightOperand; };
inline SMPRegTransfer *GetRightTree(void) const { return RightRT; }; inline SMPRegTransfer *GetRightTree(void) const { return RightRT; };
inline SMPGuard *GetGuard(void) const { return Guard; }; inline SMPGuard *GetGuard(void) const { return Guard; };
inline SMPInstr *GetParentInst(void) const { return ParentInst; }; inline SMPInstr *GetParentInst(void) const { return ParentInst; };
...@@ -337,15 +337,20 @@ public: ...@@ -337,15 +337,20 @@ public:
// Constructors and destructors. // Constructors and destructors.
SMPRTL(); SMPRTL();
~SMPRTL(); ~SMPRTL();
// Get methods // Get methods
inline std::size_t GetCount(void) const { return RTCount; }; inline std::size_t GetCount(void) const { return RTCount; };
SMPRegTransfer *GetRT(std::size_t index) const; SMPRegTransfer *GetRT(std::size_t index) const;
// Set methods // Set methods
void push_back(SMPRegTransfer *NewEffect); void push_back(SMPRegTransfer *NewEffect);
// Printing methods // Printing methods
void Dump(void) const; void Dump(void) const;
// Analysis methods. // Analysis methods.
STARS_sval_t TotalStackPointerAlteration(bool IsLeaveInstr, STARS_sval_t IncomingDelta, STARS_sval_t FramePtrDelta); // sum across all RTs in RTL STARS_sval_t TotalStackPointerAlteration(bool IsLeaveInstr, STARS_sval_t IncomingDelta, STARS_sval_t FramePtrDelta); // sum across all RTs in RTL
// Public data for ease of use. // Public data for ease of use.
std::vector<STARSOpndTypePtr> ExtraKills; // kills other than left operands std::vector<STARSOpndTypePtr> ExtraKills; // kills other than left operands
private: private:
...@@ -492,7 +497,7 @@ private: ...@@ -492,7 +497,7 @@ private:
bool ElevateLeftSide(STARSExpression *ParentExpr); // Expr simplifies to LeftExpr or LeftOperand, so raise it into ParentExpr; return true if LeftOperand bool ElevateLeftSide(STARSExpression *ParentExpr); // Expr simplifies to LeftExpr or LeftOperand, so raise it into ParentExpr; return true if LeftOperand
bool ExpandOperand(std::size_t LoopIndex, bool Left, bool StopOnIV, STARS_ea_t UseAddr, bool StopOnLoopBoundary, bool RecordLoopRegs, bool InitCase, bool ExpandOperand(std::size_t LoopIndex, bool Left, bool StopOnIV, STARS_ea_t UseAddr, bool StopOnLoopBoundary, bool RecordLoopRegs, bool InitCase,
std::set<int> &LoopRegHashes, bool &StoppedOnIV, bool &changed, std::set<STARS_ea_t> &StackPtrCopySet, int &DepthCounter); // return false if expansion is forced to stop before constant DEF or InArg DEF or IndVAr. std::set<int> &LoopRegHashes, bool &StoppedOnIV, bool &changed, std::set<STARS_ea_t> &StackPtrCopySet, int &DepthCounter); // return false if expansion is forced to stop before constant DEF or InArg DEF or IndVAr.
bool ExpandOperandHelper(STARS_ea_t DefAddr, STARSOpndTypePtr &SearchOp, std::size_t LoopIndex, bool Left, bool StopOnIV, bool StopOnLoopBoundary, bool RecordLoopRegs, bool InitCase, bool ExpandOperandHelper(STARS_ea_t DefAddr, const STARSOpndTypePtr &SearchOp, std::size_t LoopIndex, bool Left, bool StopOnIV, bool StopOnLoopBoundary, bool RecordLoopRegs, bool InitCase,
std::set<int> &LoopRegHashes, bool &StoppedOnIV, bool &changed, std::set<STARS_ea_t> &StackPtrCopySet, int &DepthCounter); // recursive helper for ExpandOperand() std::set<int> &LoopRegHashes, bool &StoppedOnIV, bool &changed, std::set<STARS_ea_t> &StackPtrCopySet, int &DepthCounter); // recursive helper for ExpandOperand()
void PrintSPARKArgLocationStringsHelper(FILE *OutputFile, bool LoopInvariant, std::size_t &OutputCount, const STARSOpndTypePtr &LeafOp, STARS_ea_t PreLoopDefAddr); void PrintSPARKArgLocationStringsHelper(FILE *OutputFile, bool LoopInvariant, std::size_t &OutputCount, const STARSOpndTypePtr &LeafOp, STARS_ea_t PreLoopDefAddr);
...@@ -648,7 +653,7 @@ public: ...@@ -648,7 +653,7 @@ public:
inline STARS_InstructionID_t GetInstID(void) const { return STARS_ID; }; inline STARS_InstructionID_t GetInstID(void) const { return STARS_ID; };
inline uint16_t GetIDAOpcode(void) const { return STARSInstPtr->GetIDAOpcode(); }; inline uint16_t GetIDAOpcode(void) const { return STARSInstPtr->GetIDAOpcode(); };
inline STARS_ea_t GetCallTarget(void) const { return IsFixedCallJump() ? GetJumpTarget() : CallTarget; }; inline STARS_ea_t GetCallTarget(void) const { return IsFixedCallJump() ? GetJumpTarget() : CallTarget; };
inline STARSOpndTypePtr GetControlFlowTarget(void) const { return RTL.GetRT(0)->GetRightOperand(); }; inline const STARSOpndTypePtr &GetControlFlowTarget(void) const { return RTL.GetRT(0)->GetConstRightOperandNoNorm(); };
char *GetDisasm(void) const; char *GetDisasm(void) const;
inline SMPBasicBlock *GetBlock(void) const { return BasicBlock; }; inline SMPBasicBlock *GetBlock(void) const { return BasicBlock; };
inline std::set<DefOrUse, LessDefUse>::iterator GetFirstUse(void) { return Uses.GetFirstRef(); }; inline std::set<DefOrUse, LessDefUse>::iterator GetFirstUse(void) { return Uses.GetFirstRef(); };
...@@ -936,7 +941,7 @@ public: ...@@ -936,7 +941,7 @@ public:
void EmitSPARKAda(FILE *OutFile); // Emit SPARK-Ada translation of instruction void EmitSPARKAda(FILE *OutFile); // Emit SPARK-Ada translation of instruction
// Analysis methods // Analysis methods
STARSOpndTypePtr GetSourceOnlyOperand(void); // return non-flags-reg non-dest source operand STARSOpndTypePtr GetSourceOnlyOperand(void) const; // return non-flags-reg non-dest source operand
std::set<DefOrUse, LessDefUse>::iterator GetPointerAddressReg(const STARSOpndTypePtr &MemOp); std::set<DefOrUse, LessDefUse>::iterator GetPointerAddressReg(const STARSOpndTypePtr &MemOp);
bool FillCmd(void); // Fetch "cmd" instruction description from disassembler. bool FillCmd(void); // Fetch "cmd" instruction description from disassembler.
void Analyze(void); // Fill in basic data for instruction. void Analyze(void); // Fill in basic data for instruction.
......
...@@ -593,7 +593,7 @@ void SMPBasicBlock::EmitSPARKAdaForExpression(FILE *BodyFile) { ...@@ -593,7 +593,7 @@ void SMPBasicBlock::EmitSPARKAdaForExpression(FILE *BodyFile) {
CompareRT = CompareRT->GetRightTree(); CompareRT = CompareRT->GetRightTree();
SMPoperator CompareOperator = CompareRT->GetOperator(); SMPoperator CompareOperator = CompareRT->GetOperator();
bool SignedCompareCase = (SMP_S_COMPARE == CompareOperator); bool SignedCompareCase = (SMP_S_COMPARE == CompareOperator);
bool UnsignedSelfCompareCase = ((SMP_U_COMPARE == CompareOperator) && IsEqOp(CompareRT->GetRightOperandNoNorm(), CompareRT->GetLeftOperandNoNorm())); bool UnsignedSelfCompareCase = ((SMP_U_COMPARE == CompareOperator) && IsEqOp(CompareRT->GetConstRightOperandNoNorm(), CompareRT->GetConstLeftOperandNoNorm()));
// Emit the SPARK Ada for the left operand of the comparison. // Emit the SPARK Ada for the left operand of the comparison.
STARSOpndTypePtr LeftOp = CompareRT->GetLeftOperand(); STARSOpndTypePtr LeftOp = CompareRT->GetLeftOperand();
...@@ -697,7 +697,7 @@ bool SMPBasicBlock::EmitSPARKAdaForExprUse(FILE *BodyFile, vector<SMPInstr *>::c ...@@ -697,7 +697,7 @@ bool SMPBasicBlock::EmitSPARKAdaForExprUse(FILE *BodyFile, vector<SMPInstr *>::c
} }
else { else {
SMPRegTransfer *DefRT = CurrInst->GetRT(0); SMPRegTransfer *DefRT = CurrInst->GetRT(0);
assert(IsEqOp(DefRT->GetLeftOperandNoNorm(), UseOp)); assert(IsEqOp(DefRT->GetConstLeftOperandNoNorm(), UseOp));
assert(SMP_ASSIGN == DefRT->GetOperator()); assert(SMP_ASSIGN == DefRT->GetOperator());
assert(DefRT->HasRightSubTree()); assert(DefRT->HasRightSubTree());
DefRT = DefRT->GetRightTree(); DefRT = DefRT->GetRightTree();
...@@ -705,7 +705,7 @@ bool SMPBasicBlock::EmitSPARKAdaForExprUse(FILE *BodyFile, vector<SMPInstr *>::c ...@@ -705,7 +705,7 @@ bool SMPBasicBlock::EmitSPARKAdaForExprUse(FILE *BodyFile, vector<SMPInstr *>::c
string OperatorString; string OperatorString;
bool OperatorIsProcCall = false; bool OperatorIsProcCall = false;
bool PrefixUnaryOperator = false; bool PrefixUnaryOperator = false;
bool ConstFollows = (!DefRT->HasRightSubTree()) && DefRT->GetRightOperandNoNorm()->IsImmedOp(); bool ConstFollows = (!DefRT->HasRightSubTree()) && DefRT->GetConstRightOperandNoNorm()->IsImmedOp();
PrintSPARKAdaOperator(DefRT->GetOperator(), OperatorString, OperatorIsProcCall, PrefixUnaryOperator, ConstFollows); PrintSPARKAdaOperator(DefRT->GetOperator(), OperatorString, OperatorIsProcCall, PrefixUnaryOperator, ConstFollows);
if (OperatorIsProcCall) { if (OperatorIsProcCall) {
SMP_fprintf(BodyFile, "ERROR "); SMP_fprintf(BodyFile, "ERROR ");
...@@ -733,7 +733,7 @@ bool SMPBasicBlock::EmitSPARKAdaForExprUse(FILE *BodyFile, vector<SMPInstr *>::c ...@@ -733,7 +733,7 @@ bool SMPBasicBlock::EmitSPARKAdaForExprUse(FILE *BodyFile, vector<SMPInstr *>::c
} }
else { else {
SMP_fprintf(BodyFile, " %s ", OperatorString.c_str()); SMP_fprintf(BodyFile, " %s ", OperatorString.c_str());
STARSOpndTypePtr DefRightOp = DefRT->GetRightOperandNoNorm(); const STARSOpndTypePtr DefRightOp = DefRT->GetConstRightOperandNoNorm();
// NOTE: Should handle RightTree possibility. // NOTE: Should handle RightTree possibility.
if (DefRightOp->IsImmedOp()) { if (DefRightOp->IsImmedOp()) {
CurrInst->PrintSPARKAdaOperand(DefRightOp, BodyFile, false, false, true, false); CurrInst->PrintSPARKAdaOperand(DefRightOp, BodyFile, false, false, true, false);
......
...@@ -6205,7 +6205,7 @@ void SMPFunction::AuditSCCPForIndirectTargets(void) { ...@@ -6205,7 +6205,7 @@ void SMPFunction::AuditSCCPForIndirectTargets(void) {
SMPInstr *CurrInst = (*InstIter); SMPInstr *CurrInst = (*InstIter);
SMPitype CurrDataFlow = CurrInst->GetDataFlowType(); SMPitype CurrDataFlow = CurrInst->GetDataFlowType();
if (((CurrDataFlow == INDIR_CALL) || (CurrDataFlow == INDIR_JUMP)) && (!CurrInst->IsInterruptCall())) { if (((CurrDataFlow == INDIR_CALL) || (CurrDataFlow == INDIR_JUMP)) && (!CurrInst->IsInterruptCall())) {
STARSOpndTypePtr TargetOp = CurrInst->GetControlFlowTarget(); const STARSOpndTypePtr &TargetOp = CurrInst->GetControlFlowTarget();
STARSOpndTypePtr SearchOp = CloneIfSubwordReg(TargetOp); STARSOpndTypePtr SearchOp = CloneIfSubwordReg(TargetOp);
CanonicalizeOpnd(SearchOp); CanonicalizeOpnd(SearchOp);
if (TargetOp->IsRegOp()) { // can only find SCCP constant values for regs if (TargetOp->IsRegOp()) { // can only find SCCP constant values for regs
...@@ -13248,8 +13248,11 @@ void SMPFunction::AnalyzeLoopIterations(void) { ...@@ -13248,8 +13248,11 @@ void SMPFunction::AnalyzeLoopIterations(void) {
int InstSize = MemWriteInst->GetSize(); int InstSize = MemWriteInst->GetSize();
STARS_uval_t LowerBoundVal = MemWriteLowerBoundExpanded->GetConstLeftOperand()->GetImmedValue(); STARS_uval_t LowerBoundVal = MemWriteLowerBoundExpanded->GetConstLeftOperand()->GetImmedValue();
STARS_uval_t UpperBoundVal = (STARS_uval_t) 0xfffffffffffffffe; // Code for unknown limit value STARS_uval_t UpperBoundVal = (STARS_uval_t) 0xfffffffffffffffe; // Code for unknown limit value
if (LimitSuccess && (nullptr != MemWriteUpperBoundExpanded->GetConstLeftOperand())) if (LimitSuccess
&& (nullptr != MemWriteUpperBoundExpanded->GetConstLeftOperand())
&& (MemWriteUpperBoundExpanded->GetConstLeftOperand()->IsImmedOp())) {
UpperBoundVal = MemWriteUpperBoundExpanded->GetConstLeftOperand()->GetImmedValue(); UpperBoundVal = MemWriteUpperBoundExpanded->GetConstLeftOperand()->GetImmedValue();
}
FILE *InfoAnnotFile = global_STARS_program->GetInfoAnnotFile(); FILE *InfoAnnotFile = global_STARS_program->GetInfoAnnotFile();
SMP_fprintf(InfoAnnotFile, "%18llx %6zu INSTR STATICMEMWRITE MIN ", (uint64_t)MemWriteAddr, InstSize); SMP_fprintf(InfoAnnotFile, "%18llx %6zu INSTR STATICMEMWRITE MIN ", (uint64_t)MemWriteAddr, InstSize);
if (LowerBoundVal == UpperBoundVal) { if (LowerBoundVal == UpperBoundVal) {
......
...@@ -1362,16 +1362,11 @@ bool SMPRegTransfer::OperandTransfersHelper(const STARSOpndTypePtr &UseOp) const ...@@ -1362,16 +1362,11 @@ bool SMPRegTransfer::OperandTransfersHelper(const STARSOpndTypePtr &UseOp) const
// Does RTL show LeftOp has smaller bitwidth than the right hand side operands? // Does RTL show LeftOp has smaller bitwidth than the right hand side operands?
bool SMPRegTransfer::IsTruncatedWidthRTL(std::size_t &LeftBitWidth, std::size_t &RightBitWidth) const { bool SMPRegTransfer::IsTruncatedWidthRTL(std::size_t &LeftBitWidth, std::size_t &RightBitWidth) const {
bool TruncatedWidth = false; bool TruncatedWidth = false;
STARSOpndTypePtr LeftOp = this->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = this->GetConstLeftOperandNoNorm();
std::size_t LeftOpByteWidth = (std::size_t) LeftOp->GetByteWidth(); std::size_t LeftOpByteWidth = (std::size_t) LeftOp->GetByteWidth();
std::size_t RightOpByteWidth = 0; std::size_t RightOpByteWidth = 0;
STARSOpndTypePtr RightOp = nullptr; const STARSOpndTypePtr RightOp = (this->HasRightSubTree()) ? this->GetRightTree()->GetConstLeftOperandNoNorm()
if (this->HasRightSubTree()) { : this->GetConstRightOperandNoNorm();
RightOp = this->GetRightTree()->GetLeftOperandNoNorm();
}
else {
RightOp = this->GetRightOperandNoNorm();
}
if (nullptr != RightOp) { if (nullptr != RightOp) {
RightOpByteWidth = RightOp->GetByteWidth(); RightOpByteWidth = RightOp->GetByteWidth();
} }
...@@ -1389,17 +1384,12 @@ bool SMPRegTransfer::IsTruncatedWidthRTL(std::size_t &LeftBitWidth, std::size_t ...@@ -1389,17 +1384,12 @@ bool SMPRegTransfer::IsTruncatedWidthRTL(std::size_t &LeftBitWidth, std::size_t
// Does RTL show LeftOp has larger bitwidth than the right hand side operands? // Does RTL show LeftOp has larger bitwidth than the right hand side operands?
bool SMPRegTransfer::IsExpandedWidthRTL(std::size_t &LeftBitWidth, std::size_t &RightBitWidth) const { bool SMPRegTransfer::IsExpandedWidthRTL(std::size_t &LeftBitWidth, std::size_t &RightBitWidth) const {
bool ExpandedWidth = false; bool ExpandedWidth = false;
STARSOpndTypePtr LeftOp = this->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = this->GetConstLeftOperandNoNorm();
std::size_t LeftOpByteWidth = (std::size_t) LeftOp->GetByteWidth(); std::size_t LeftOpByteWidth = (std::size_t) LeftOp->GetByteWidth();
if (LeftOpByteWidth > global_STARS_program->GetSTARS_ISA_Bytewidth()) { // Forget it unless LeftOp is wide, e.g. FP stack. if (LeftOpByteWidth > global_STARS_program->GetSTARS_ISA_Bytewidth()) { // Forget it unless LeftOp is wide, e.g. FP stack.
// Search right hand side for narrower operands. // Search right hand side for narrower operands.
STARSOpndTypePtr RightOp = nullptr; const STARSOpndTypePtr RightOp = (this->HasRightSubTree()) ? this->GetRightTree()->GetConstLeftOperandNoNorm()
if (this->HasRightSubTree()) { : this->GetConstRightOperandNoNorm();
RightOp = this->GetRightTree()->GetLeftOperandNoNorm();
}
else {
RightOp = this->GetRightOperandNoNorm();
}
size_t RightOpByteWidth = RightOp->GetByteWidth(); size_t RightOpByteWidth = RightOp->GetByteWidth();
if (nullptr != RightOp) { if (nullptr != RightOp) {
ExpandedWidth = ((RightOpByteWidth < LeftOpByteWidth) && (RightOp->IsRegOp() || RightOp->IsMemOp() || RightOp->IsFloatingPointRegOp())); ExpandedWidth = ((RightOpByteWidth < LeftOpByteWidth) && (RightOp->IsRegOp() || RightOp->IsMemOp() || RightOp->IsFloatingPointRegOp()));
...@@ -1413,7 +1403,7 @@ bool SMPRegTransfer::IsExpandedWidthRTL(std::size_t &LeftBitWidth, std::size_t & ...@@ -1413,7 +1403,7 @@ bool SMPRegTransfer::IsExpandedWidthRTL(std::size_t &LeftBitWidth, std::size_t &
   
// fix machine-specific FP reg encodings // fix machine-specific FP reg encodings
void SMPRegTransfer::MDFixFloatingPointRTL(void) { void SMPRegTransfer::MDFixFloatingPointRTL(void) {
STARSOpndTypePtr LeftOp = this->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = this->GetConstLeftOperandNoNorm();
if ((nullptr != LeftOp) && LeftOp->IsFloatingPointRegOp()) { if ((nullptr != LeftOp) && LeftOp->IsFloatingPointRegOp()) {
STARS_regnum_t FPRegNum = LeftOp->GetReg(); STARS_regnum_t FPRegNum = LeftOp->GetReg();
if (FPRegNum < STARS_x86_R_st0) { if (FPRegNum < STARS_x86_R_st0) {
...@@ -1427,7 +1417,7 @@ void SMPRegTransfer::MDFixFloatingPointRTL(void) { ...@@ -1427,7 +1417,7 @@ void SMPRegTransfer::MDFixFloatingPointRTL(void) {
this->GetRightTree()->MDFixFloatingPointRTL(); // recurse into right tree this->GetRightTree()->MDFixFloatingPointRTL(); // recurse into right tree
} }
else { else {
STARSOpndTypePtr RightOp = this->GetRightOperandNoNorm(); const STARSOpndTypePtr RightOp = this->GetConstRightOperandNoNorm();
if ((nullptr != RightOp) && RightOp->IsFloatingPointRegOp()) { if ((nullptr != RightOp) && RightOp->IsFloatingPointRegOp()) {
STARS_regnum_t FPRegNum = RightOp->GetReg(); STARS_regnum_t FPRegNum = RightOp->GetReg();
if (FPRegNum < STARS_x86_R_st0) { if (FPRegNum < STARS_x86_R_st0) {
...@@ -1778,7 +1768,7 @@ bool SMPRegTransfer::IsStackPtrUsedInRT(bool UseFP) const { ...@@ -1778,7 +1768,7 @@ bool SMPRegTransfer::IsStackPtrUsedInRT(bool UseFP) const {
// Is RT a move of a const or subreg into a subreg? // Is RT a move of a const or subreg into a subreg?
bool SMPRegTransfer::IsSubregMove(void) const { bool SMPRegTransfer::IsSubregMove(void) const {
bool SubregMove = false; bool SubregMove = false;
STARSOpndTypePtr LeftOp = this->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = this->GetConstLeftOperandNoNorm();
if ((nullptr != LeftOp) && (LeftOp->IsRegOp())) { if ((nullptr != LeftOp) && (LeftOp->IsRegOp())) {
bool SubregDest = (LeftOp->GetByteWidth() < 4); // move into EAX zeroes out upper RAX, but move into AX does not. bool SubregDest = (LeftOp->GetByteWidth() < 4); // move into EAX zeroes out upper RAX, but move into AX does not.
SubregMove = (SubregDest && (!this->HasRightSubTree()) && (SMP_ASSIGN == this->GetOperator())); SubregMove = (SubregDest && (!this->HasRightSubTree()) && (SMP_ASSIGN == this->GetOperator()));
...@@ -1820,14 +1810,14 @@ bool SMPRegTransfer::RightTreeNeedsWidthCast(FILE *OutFile, std::size_t LeftBitW ...@@ -1820,14 +1810,14 @@ bool SMPRegTransfer::RightTreeNeedsWidthCast(FILE *OutFile, std::size_t LeftBitW
assert(NULL != RightRT); assert(NULL != RightRT);
// Initial cases: zero-extension and sign-extension; add more cases as required // Initial cases: zero-extension and sign-extension; add more cases as required
if (SMP_ZERO_EXTEND == RightRT->GetOperator()) { if (SMP_ZERO_EXTEND == RightRT->GetOperator()) {
STARSOpndTypePtr RightLeftOp = RightRT->GetLeftOperandNoNorm(); const STARSOpndTypePtr RightLeftOp = RightRT->GetConstLeftOperandNoNorm();
RightBitWidth = RightLeftOp->GetByteWidth() * 8; RightBitWidth = RightLeftOp->GetByteWidth() * 8;
if (LeftBitWidth != RightBitWidth) { if (LeftBitWidth != RightBitWidth) {
SMP_fprintf(OutFile, "Unsigned%u(", LeftBitWidth); SMP_fprintf(OutFile, "Unsigned%u(", LeftBitWidth);
} }
} }
else if (SMP_SIGN_EXTEND == RightRT->GetOperator()) { else if (SMP_SIGN_EXTEND == RightRT->GetOperator()) {
STARSOpndTypePtr RightLeftOp = RightRT->GetLeftOperandNoNorm(); const STARSOpndTypePtr RightLeftOp = RightRT->GetConstLeftOperandNoNorm();
RightBitWidth = RightLeftOp->GetByteWidth() * 8; RightBitWidth = RightLeftOp->GetByteWidth() * 8;
if (LeftBitWidth != RightBitWidth) { if (LeftBitWidth != RightBitWidth) {
SMP_fprintf(OutFile, "X86.SignExtend%uTo%u(", RightBitWidth, LeftBitWidth); SMP_fprintf(OutFile, "X86.SignExtend%uTo%u(", RightBitWidth, LeftBitWidth);
...@@ -1849,8 +1839,8 @@ bool SMPRegTransfer::IsSPARKAdaNop(void) const { ...@@ -1849,8 +1839,8 @@ bool SMPRegTransfer::IsSPARKAdaNop(void) const {
SPARKNop = this->GetRightTree()->IsSPARKAdaNop(); SPARKNop = this->GetRightTree()->IsSPARKAdaNop();
} }
if (!SPARKNop && (SMP_ASSIGN == CurrOperator)) { if (!SPARKNop && (SMP_ASSIGN == CurrOperator)) {
STARSOpndTypePtr LeftOp = this->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = this->GetConstLeftOperandNoNorm();
STARSOpndTypePtr RightOp = this->GetRightOperandNoNorm(); const STARSOpndTypePtr RightOp = this->GetConstRightOperandNoNorm();
if ((nullptr != LeftOp) && (nullptr != RightOp) && LeftOp->IsFloatingPointRegOp() && RightOp->IsFloatingPointRegOp()) { if ((nullptr != LeftOp) && (nullptr != RightOp) && LeftOp->IsFloatingPointRegOp() && RightOp->IsFloatingPointRegOp()) {
SPARKNop = (LeftOp->GetReg() == RightOp->GetReg()); // e.g. fld st just duplicates top of stack SPARKNop = (LeftOp->GetReg() == RightOp->GetReg()); // e.g. fld st just duplicates top of stack
} }
...@@ -1910,7 +1900,7 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const ...@@ -1910,7 +1900,7 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const
} }
if (this->HasRightSubTree()) { // NOTE: Handle operators like Shift_right() !!!!****!!!! if (this->HasRightSubTree()) { // NOTE: Handle operators like Shift_right() !!!!****!!!!
SMPRegTransfer *RightRT = this->GetRightTree(); SMPRegTransfer *RightRT = this->GetRightTree();
size_t LeftByteWidth = this->GetLeftOperandNoNorm()->GetByteWidth(); size_t LeftByteWidth = this->GetConstLeftOperandNoNorm()->GetByteWidth();
LeftOpBitWidth = LeftByteWidth * 8; LeftOpBitWidth = LeftByteWidth * 8;
bool ShortLeftWidth = (ISA_ByteWidth > LeftByteWidth); bool ShortLeftWidth = (ISA_ByteWidth > LeftByteWidth);
   
...@@ -1921,9 +1911,9 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const ...@@ -1921,9 +1911,9 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const
bool PrefixUnaryOperator = false; bool PrefixUnaryOperator = false;
SMP_fprintf(OutFile, "("); SMP_fprintf(OutFile, "(");
SMPoperator CurrOper = RightRT->GetOperator(); SMPoperator CurrOper = RightRT->GetOperator();
bool ConstFollows = (!RightRT->HasRightSubTree()) && RightRT->GetRightOperandNoNorm()->IsImmedOp(); bool ConstFollows = (!RightRT->HasRightSubTree()) && RightRT->GetConstRightOperandNoNorm()->IsImmedOp();
PrintSPARKAdaOperator(CurrOper, OperatorString, OperatorIsProcCall, PrefixUnaryOperator, ConstFollows); PrintSPARKAdaOperator(CurrOper, OperatorString, OperatorIsProcCall, PrefixUnaryOperator, ConstFollows);
STARSOpndTypePtr LeftOp = RightRT->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = RightRT->GetConstLeftOperandNoNorm();
if (!OperatorIsProcCall) { if (!OperatorIsProcCall) {
if (!PrefixUnaryOperator) { if (!PrefixUnaryOperator) {
this->ParentInst->PrintSPARKAdaOperand(LeftOp, OutFile, false, UseFP, true, false); this->ParentInst->PrintSPARKAdaOperand(LeftOp, OutFile, false, UseFP, true, false);
...@@ -1953,7 +1943,7 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const ...@@ -1953,7 +1943,7 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const
SMP_fprintf(OutFile, ")"); SMP_fprintf(OutFile, ")");
} }
else { else {
STARSOpndTypePtr RightOp = this->GetRightOperandNoNorm(); const STARSOpndTypePtr RightOp = this->GetConstRightOperandNoNorm();
this->ParentInst->PrintSPARKAdaOperand(RightOp, OutFile, false, UseFP, true, false); this->ParentInst->PrintSPARKAdaOperand(RightOp, OutFile, false, UseFP, true, false);
} }
if (!RecursiveCall && Truncated) { if (!RecursiveCall && Truncated) {
...@@ -1965,7 +1955,7 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const ...@@ -1965,7 +1955,7 @@ void SMPRegTransfer::EmitSPARKAdaForRHS(FILE *OutFile, bool RecursiveCall) const
   
// Emit SPARK-Ada translation of RT // Emit SPARK-Ada translation of RT
void SMPRegTransfer::EmitSPARKAda(FILE *OutFile) { void SMPRegTransfer::EmitSPARKAda(FILE *OutFile) {
STARSOpndTypePtr LeftOp = this->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = this->GetConstLeftOperandNoNorm();
if ((nullptr == LeftOp) || this->IsSPARKAdaNop()) { if ((nullptr == LeftOp) || this->IsSPARKAdaNop()) {
PrintSPARKIndentTabs(OutFile); PrintSPARKIndentTabs(OutFile);
SMP_fprintf(OutFile, "null;\n"); // Ada no-op SMP_fprintf(OutFile, "null;\n"); // Ada no-op
...@@ -4081,7 +4071,7 @@ bool STARSExpression::ExpandOperand(std::size_t LoopIndex, bool Left, bool StopO ...@@ -4081,7 +4071,7 @@ bool STARSExpression::ExpandOperand(std::size_t LoopIndex, bool Left, bool StopO
} // end of STARSExpression::ExpandOperand() } // end of STARSExpression::ExpandOperand()
   
// recursive helper for ExpandOperand() // recursive helper for ExpandOperand()
bool STARSExpression::ExpandOperandHelper(STARS_ea_t DefAddr, STARSOpndTypePtr &SearchOp, size_t LoopIndex, bool Left, bool StopOnIV, bool StopOnLoopBoundary, bool RecordLoopRegs, bool InitCase, bool STARSExpression::ExpandOperandHelper(STARS_ea_t DefAddr, const STARSOpndTypePtr &SearchOp, size_t LoopIndex, bool Left, bool StopOnIV, bool StopOnLoopBoundary, bool RecordLoopRegs, bool InitCase,
set<int> &LoopRegHashes, bool &StoppedOnIV, bool &changed, set<STARS_ea_t> &StackPtrCopySet, int &DepthCounter) { set<int> &LoopRegHashes, bool &StoppedOnIV, bool &changed, set<STARS_ea_t> &StackPtrCopySet, int &DepthCounter) {
bool success = true; bool success = true;
bool UseFP = this->GetParentFunc()->UsesFramePointer(); bool UseFP = this->GetParentFunc()->UsesFramePointer();
...@@ -4252,15 +4242,15 @@ bool STARSExpression::ExpandOperandHelper(STARS_ea_t DefAddr, STARSOpndTypePtr & ...@@ -4252,15 +4242,15 @@ bool STARSExpression::ExpandOperandHelper(STARS_ea_t DefAddr, STARSOpndTypePtr &
SMP_msg("\nINFO: SPARK: ExpandOperandHelper() hit non-DataFlow UseOp at %llx\n", (uint64_t) DefAddr); SMP_msg("\nINFO: SPARK: ExpandOperandHelper() hit non-DataFlow UseOp at %llx\n", (uint64_t) DefAddr);
} }
else { else {
STARSOpndTypePtr SearchOp = CloneIfSubwordReg(UseOp); STARSOpndTypePtr SearchOp2 = CloneIfSubwordReg(UseOp);
CanonicalizeOpnd(SearchOp); CanonicalizeOpnd(SearchOp2);
if (!ConstUse) { if (!ConstUse) {
STARSDefUseIter UseIter = DefInst->FindUse(SearchOp); STARSDefUseIter UseIter = DefInst->FindUse(SearchOp2);
assert(UseIter != DefInst->GetLastUse()); assert(UseIter != DefInst->GetLastUse());
int UseSSANum = UseIter->GetSSANum(); int UseSSANum = UseIter->GetSSANum();
// Until we have alias analysis, cannot trace non-stack memory // Until we have alias analysis, cannot trace non-stack memory
// operands, which will not be SSA numbered. // operands, which will not be SSA numbered.
if (SearchOp->IsMemOp() && (-1 == UseSSANum)) { if (SearchOp2->IsMemOp() && (-1 == UseSSANum)) {
--DepthCounter; --DepthCounter;
return true; return true;
} }
...@@ -4271,7 +4261,7 @@ bool STARSExpression::ExpandOperandHelper(STARS_ea_t DefAddr, STARSOpndTypePtr & ...@@ -4271,7 +4261,7 @@ bool STARSExpression::ExpandOperandHelper(STARS_ea_t DefAddr, STARSOpndTypePtr &
this->SetRightSSANum(UseSSANum); this->SetRightSSANum(UseSSANum);
this->ParentInst = DefInst; this->ParentInst = DefInst;
if (!WentBeforeLoop && RecordLoopRegs && UseOp->IsRegOp()) { if (!WentBeforeLoop && RecordLoopRegs && UseOp->IsRegOp()) {
int RegHash = HashGlobalNameAndSSA(SearchOp, UseSSANum); int RegHash = HashGlobalNameAndSSA(SearchOp2, UseSSANum);
pair<set<int>::iterator, bool> InsertResult = LoopRegHashes.insert(RegHash); pair<set<int>::iterator, bool> InsertResult = LoopRegHashes.insert(RegHash);
#if 1 #if 1
if (InsertResult.second) { if (InsertResult.second) {
...@@ -5701,8 +5691,8 @@ void SMPInstr::MDEmitSPARKAdaCompareOrTest(FILE *OutFile) { ...@@ -5701,8 +5691,8 @@ void SMPInstr::MDEmitSPARKAdaCompareOrTest(FILE *OutFile) {
SMPRegTransfer *CurrRT = this->RTL.GetRT(0); SMPRegTransfer *CurrRT = this->RTL.GetRT(0);
assert(CurrRT->HasRightSubTree()); assert(CurrRT->HasRightSubTree());
CurrRT = CurrRT->GetRightTree(); CurrRT = CurrRT->GetRightTree();
STARSOpndTypePtr LeftOp = CurrRT->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = CurrRT->GetConstLeftOperandNoNorm();
STARSOpndTypePtr RightOp = CurrRT->GetRightOperandNoNorm(); const STARSOpndTypePtr RightOp = CurrRT->GetConstRightOperandNoNorm();
bool ReflexiveOperation = IsEqOp(LeftOp, RightOp); bool ReflexiveOperation = IsEqOp(LeftOp, RightOp);
std::size_t LeftBitWidth = 8 * LeftOp->GetByteWidth(); std::size_t LeftBitWidth = 8 * LeftOp->GetByteWidth();
   
...@@ -5799,8 +5789,8 @@ void SMPInstr::MDEmitSPARKAdaArithmeticSetsCondCodes(FILE *OutFile) { ...@@ -5799,8 +5789,8 @@ void SMPInstr::MDEmitSPARKAdaArithmeticSetsCondCodes(FILE *OutFile) {
bool UseFP = this->GetBlock()->GetFunc()->UsesFramePointer(); bool UseFP = this->GetBlock()->GetFunc()->UsesFramePointer();
bool PrefixProcCall = false; bool PrefixProcCall = false;
bool PrefixUnary = false; bool PrefixUnary = false;
STARSOpndTypePtr LeftOp = CurrRT->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = CurrRT->GetConstLeftOperandNoNorm();
STARSOpndTypePtr RightOp = CurrRT->GetRightTree()->GetRightOperandNoNorm(); const STARSOpndTypePtr RightOp = CurrRT->GetRightTree()->GetConstRightOperandNoNorm();
assert((nullptr != LeftOp) && (nullptr != RightOp)); assert((nullptr != LeftOp) && (nullptr != RightOp));
std::size_t LeftBitWidth = 8 * LeftOp->GetByteWidth(); std::size_t LeftBitWidth = 8 * LeftOp->GetByteWidth();
bool ConstFollows = RightOp->IsImmedOp(); bool ConstFollows = RightOp->IsImmedOp();
...@@ -5956,7 +5946,7 @@ void SMPInstr::MDEmitSPARKAdaArithmeticSetsCondCodes(FILE *OutFile) { ...@@ -5956,7 +5946,7 @@ void SMPInstr::MDEmitSPARKAdaArithmeticSetsCondCodes(FILE *OutFile) {
void SMPInstr::MDEmitSPARKAdaSetCondCodeIntoReg(FILE *OutFile) { void SMPInstr::MDEmitSPARKAdaSetCondCodeIntoReg(FILE *OutFile) {
bool ErrorFound = false; bool ErrorFound = false;
SMPRegTransfer *CurrRT = this->RTL.GetRT(0); SMPRegTransfer *CurrRT = this->RTL.GetRT(0);
STARSOpndTypePtr LeftOp = CurrRT->GetLeftOperandNoNorm(); const STARSOpndTypePtr LeftOp = CurrRT->GetConstLeftOperandNoNorm();
std::size_t LeftOpndByteWidth = LeftOp->GetByteWidth(); std::size_t LeftOpndByteWidth = LeftOp->GetByteWidth();
bool LeftSubwordWidth = (global_STARS_program->GetSTARS_ISA_Bytewidth() > LeftOpndByteWidth); bool LeftSubwordWidth = (global_STARS_program->GetSTARS_ISA_Bytewidth() > LeftOpndByteWidth);
bool UseFP = this->GetBlock()->GetFunc()->UsesFramePointer(); bool UseFP = this->GetBlock()->GetFunc()->UsesFramePointer();
...@@ -6782,7 +6772,7 @@ void SMPInstr::EmitSPARKAda(FILE *OutFile) { ...@@ -6782,7 +6772,7 @@ void SMPInstr::EmitSPARKAda(FILE *OutFile) {
// Start switch table translation. // Start switch table translation.
PrintSPARKIndentTabs(OutFile); PrintSPARKIndentTabs(OutFile);
SMP_fprintf(OutFile, "case "); SMP_fprintf(OutFile, "case ");
this->PrintSPARKAdaOperand(this->RTL.GetRT(0)->GetRightOperandNoNorm(), OutFile, false, UseFP, true, false); this->PrintSPARKAdaOperand(this->RTL.GetRT(0)->GetConstRightOperandNoNorm(), OutFile, false, UseFP, true, false);
SMP_fprintf(OutFile, " is\n"); SMP_fprintf(OutFile, " is\n");
++STARS_SPARK_IndentCount; ++STARS_SPARK_IndentCount;
break; break;
...@@ -7182,7 +7172,7 @@ bool SMPInstr::MDIsUpperBitsClear(void) { ...@@ -7182,7 +7172,7 @@ bool SMPInstr::MDIsUpperBitsClear(void) {
// Correct the RTL. reg1 := reg2 becomes reg1 := (zero-extend reg2) // Correct the RTL. reg1 := reg2 becomes reg1 := (zero-extend reg2)
SMPRegTransfer *TempRT = new SMPRegTransfer; SMPRegTransfer *TempRT = new SMPRegTransfer;
TempRT->SetParentInst(this); TempRT->SetParentInst(this);
TempRT->SetLeftOperand(this->RTL.GetRT(0)->GetRightOperandNoNorm()); TempRT->SetLeftOperand(this->RTL.GetRT(0)->GetConstRightOperandNoNorm());
TempRT->SetOperator(SMP_ZERO_EXTEND); TempRT->SetOperator(SMP_ZERO_EXTEND);
STARSOpndTypePtr VoidOp = this->STARSInstPtr->MakeVoidOpnd(); STARSOpndTypePtr VoidOp = this->STARSInstPtr->MakeVoidOpnd();
TempRT->SetRightOperand(VoidOp); TempRT->SetRightOperand(VoidOp);
...@@ -7626,7 +7616,7 @@ bool SMPInstr::IsJumpOrBranchInstr(void) const { ...@@ -7626,7 +7616,7 @@ bool SMPInstr::IsJumpOrBranchInstr(void) const {
// A jump is IP := address; a conditional branch is the same with a Guard RT. // A jump is IP := address; a conditional branch is the same with a Guard RT.
SMPRegTransfer *RT = this->GetRT(0); SMPRegTransfer *RT = this->GetRT(0);
return ((1 == this->RTL.GetCount()) && (!RT->HasRightSubTree()) return ((1 == this->RTL.GetCount()) && (!RT->HasRightSubTree())
&& RT->GetLeftOperandNoNorm()->MatchesReg(MD_INSTRUCTION_POINTER_REG)); && RT->GetConstLeftOperandNoNorm()->MatchesReg(MD_INSTRUCTION_POINTER_REG));
// return ((STARS_NN_ja <= this->GetIDAOpcode()) && (STARS_NN_jmpshort >= this->GetIDAOpcode())); // return ((STARS_NN_ja <= this->GetIDAOpcode()) && (STARS_NN_jmpshort >= this->GetIDAOpcode()));
} }
   
...@@ -7838,7 +7828,7 @@ bool SMPInstr::IsLoadGlobalStaticDataAddress(STARS_uval_t &GlobalAddr) { ...@@ -7838,7 +7828,7 @@ bool SMPInstr::IsLoadGlobalStaticDataAddress(STARS_uval_t &GlobalAddr) {
bool GlobalFound = false; bool GlobalFound = false;
if (nullptr != FirstRT) { if (nullptr != FirstRT) {
if ((SMP_ASSIGN == FirstRT->GetOperator()) && (!FirstRT->HasRightSubTree())) { if ((SMP_ASSIGN == FirstRT->GetOperator()) && (!FirstRT->HasRightSubTree())) {
STARSOpndTypePtr RightOp = FirstRT->GetRightOperandNoNorm(); const STARSOpndTypePtr RightOp = FirstRT->GetConstRightOperandNoNorm();
if (RightOp->IsImmedOp()) { if (RightOp->IsImmedOp()) {
GlobalAddr = RightOp->GetImmedValue(); GlobalAddr = RightOp->GetImmedValue();
if (IsImmedGlobalAddress((STARS_ea_t)GlobalAddr)) { if (IsImmedGlobalAddress((STARS_ea_t)GlobalAddr)) {
...@@ -9413,7 +9403,7 @@ void SMPInstr::MDGetUnnormalizedOp(STARSOpndTypePtr &NormOp) { ...@@ -9413,7 +9403,7 @@ void SMPInstr::MDGetUnnormalizedOp(STARSOpndTypePtr &NormOp) {
} // end of SMPInstr::MDGetUnnormalizedOp() } // end of SMPInstr::MDGetUnnormalizedOp()
   
// Find USE-not-DEF operand that is not the flags register. // Find USE-not-DEF operand that is not the flags register.
STARSOpndTypePtr SMPInstr::GetSourceOnlyOperand(void) { STARSOpndTypePtr SMPInstr::GetSourceOnlyOperand(void) const {
std::size_t OpNum; std::size_t OpNum;
// loop through all operands // loop through all operands
for (OpNum = 0; OpNum < STARS_UA_MAXOP; ++OpNum) { for (OpNum = 0; OpNum < STARS_UA_MAXOP; ++OpNum) {
...@@ -11475,8 +11465,8 @@ bool SMPInstr::MDIsSystemCall(void) { ...@@ -11475,8 +11465,8 @@ bool SMPInstr::MDIsSystemCall(void) {
SMPRegTransfer *CurrRT = this->RTL.GetRT(0); SMPRegTransfer *CurrRT = this->RTL.GetRT(0);
assert(NULL != CurrRT); assert(NULL != CurrRT);
if (!CurrRT->HasRightSubTree()) { if (!CurrRT->HasRightSubTree()) {
if (CurrRT->GetRightOperandNoNorm()->IsImmedOp()) { if (CurrRT->GetConstRightOperandNoNorm()->IsImmedOp()) {
SystemCall = (0x80 == CurrRT->GetRightOperandNoNorm()->GetImmedValue()); SystemCall = (0x80 == CurrRT->GetConstRightOperandNoNorm()->GetImmedValue());
} }
} }
} }
...@@ -12580,9 +12570,9 @@ void SMPInstr::SCCPEvaluateCondBranch(enum STARSBranchConst &BranchEval) { ...@@ -12580,9 +12570,9 @@ void SMPInstr::SCCPEvaluateCondBranch(enum STARSBranchConst &BranchEval) {
SMPRegTransfer *CurrRT = this->RTL.GetRT(0); SMPRegTransfer *CurrRT = this->RTL.GetRT(0);
SMPGuard *BranchCondition = CurrRT->GetGuard(); SMPGuard *BranchCondition = CurrRT->GetGuard();
assert(NULL != BranchCondition); assert(NULL != BranchCondition);
STARSOpndTypePtr LeftOp = CloneIfSubwordReg(BranchCondition->GetLeftOperand()); STARSOpndTypePtr LeftOp = CloneIfSubwordReg(BranchCondition->GetConstLeftOperand());
CanonicalizeOpnd(LeftOp); CanonicalizeOpnd(LeftOp);
STARSOpndTypePtr RightOp = CloneIfSubwordReg(BranchCondition->GetRightOperand()); STARSOpndTypePtr RightOp = CloneIfSubwordReg(BranchCondition->GetConstRightOperand());
CanonicalizeOpnd(RightOp); CanonicalizeOpnd(RightOp);
STARS_SCCP_Const_Struct LeftValue, RightValue; STARS_SCCP_Const_Struct LeftValue, RightValue;
this->SCCPFetchConstUseValue(LeftOp, LeftValue); this->SCCPFetchConstUseValue(LeftOp, LeftValue);