Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SMPStaticAnalyzer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
SMPStaticAnalyzer
Compare revisions
482e04eeb508f5c2de640f652cedef768e791408 to 9ae06334b00d435f1dbd46a55a877b9045cc15bd
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
opensrc/SMPStaticAnalyzer
Select target project
No results found
9ae06334b00d435f1dbd46a55a877b9045cc15bd
Select Git revision
Swap
Target
opensrc/SMPStaticAnalyzer
Select target project
opensrc/SMPStaticAnalyzer
1 result
482e04eeb508f5c2de640f652cedef768e791408
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (1)
Crash fix for tar binary; loop analysis fixes for move_globals annotations.
· 9ae06334
Clark Coleman
authored
6 years ago
9ae06334
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/base/SMPFunction.cpp
+113
-84
113 additions, 84 deletions
src/base/SMPFunction.cpp
src/base/SMPInstr.cpp
+19
-13
19 additions, 13 deletions
src/base/SMPInstr.cpp
with
132 additions
and
97 deletions
src/base/SMPFunction.cpp
View file @
9ae06334
...
...
@@ -7118,9 +7118,9 @@ bool SMPFunction::IsUseLoopInvariantDEF(std::size_t LoopIndex, const STARSOpndTy
if (!this->LoopInvariantDEFs.empty() && (!this->LoopInvariantDEFs[LoopIndex].empty())) {
if (!UseOp->IsMemOp()) {
bool LocalName = UseInst->GetBlock()->IsLocalName(UseOp);
STARSOpndTypePtr SearchOp = CloneIfNecessary(UseOp, this->UsesFramePointer());
CanonicalizeOpnd(SearchOp);
bool LocalName = UseInst->GetBlock()->IsLocalName(SearchOp);
STARSDefUseIter UseIter = UseInst->FindUse(SearchOp);
if (UseIter != UseInst->GetLastUse()) {
int UseSSANum = UseIter->GetSSANum();
...
...
@@ -7206,7 +7206,6 @@ void SMPFunction::DetectLoopInductionVars(void) {
// same induction var arithmetic.
int HeaderBlockNum = this->LoopHeadBlockNumbers[LoopIndex];
bool FoundBIV = false;
++STARS_LoopInductionVarIDFailures; // decrement later if we succeed
SMPBasicBlock *HeaderBlock = this->GetBlockByNum((size_t) HeaderBlockNum);
// Look at all register Phi functions in the HeaderBlock.
for (PhiSetIter PhiIter = HeaderBlock->GetFirstPhi(); PhiIter != HeaderBlock->GetLastPhi(); ++PhiIter) {
...
...
@@ -7397,13 +7396,15 @@ void SMPFunction::DetectLoopInductionVars(void) {
if (InsideBIVFoundCount == CurrentFamily.BIVInsideLoopDefAddrs.size()) {
this->LoopInductionVars[LoopIndex].push_back(CurrentFamily);
SMP_msg("INFO: BIVFoundCount success for func at %llx for Loop %d \n", (uint64_t) this->GetFirstFuncAddr(), LoopIndex);
++STARS_LoopInductionVarIDSuccesses;
--STARS_LoopInductionVarIDFailures; // undo increment from top of loop
}
} // end for all Phi functions in current loop header block
if (!FoundBIV) {
SMP_msg("
WARNING
: BIV not found for loop %d at %llx in func %s\n", LoopIndex,
SMP_msg("
ERROR: LOOP
: BIV not found for loop %d at %llx in func %s\n", LoopIndex,
(uint64_t) HeaderBlock->GetFirstAddr(), this->GetFuncName());
++STARS_LoopInductionVarIDFailures;
}
else {
++STARS_LoopInductionVarIDSuccesses;
}
} // end for all loops
...
...
@@ -7515,10 +7516,19 @@ bool SMPFunction::IsLoopNestInductionVar(const STARSOpndTypePtr &CurrOp, SMPInst
int InnerLoopIndex = this->GetInnermostLoopNum(UseBlockNum);
int OuterLoopIndex = this->GetOutermostLoopNum(UseBlockNum);
if ((0 <= InnerLoopIndex) && (0 <= OuterLoopIndex)) { // if block is in a loop
for (int TempLoopIndex = InnerLoopIndex; !success && (TempLoopIndex <= OuterLoopIndex); ++TempLoopIndex) {
success = this->IsLoopInductionVarForAnySSANum((size_t)TempLoopIndex, CurrOp, ListIter, FamilyIndex);
if (success)
LoopIndex = TempLoopIndex;
if (InnerLoopIndex > OuterLoopIndex) { // swap directions
for (int TempLoopIndex = InnerLoopIndex; !success && (TempLoopIndex >= OuterLoopIndex); --TempLoopIndex) {
success = this->IsLoopInductionVarForAnySSANum((size_t)TempLoopIndex, CurrOp, ListIter, FamilyIndex);
if (success)
LoopIndex = TempLoopIndex;
}
}
else {
for (int TempLoopIndex = InnerLoopIndex; !success && (TempLoopIndex <= OuterLoopIndex); ++TempLoopIndex) {
success = this->IsLoopInductionVarForAnySSANum((size_t)TempLoopIndex, CurrOp, ListIter, FamilyIndex);
if (success)
LoopIndex = TempLoopIndex;
}
}
}
return success;
...
...
@@ -7976,6 +7986,9 @@ STARSExpression *SMPFunction::CreateDIVInitExpr(const std::size_t &LoopIndex, co
// Create DIV limit expr as linear function of its BIV limit expr
STARSExpression *SMPFunction::CreateDIVLimitExpr(const std::size_t &LoopIndex, const struct InductionVarFamily &IVFamily, const std::size_t DIVIndex) {
if (nullptr == IVFamily.BIVLimitExpr)
return nullptr;
struct DependentInductionVar DIV = IVFamily.DependentInductionVars[DIVIndex];
STARSOpndTypePtr MulOp = DIV.IVExpr.Multiplier.GetOp();
bool ConstMul = MulOp->IsImmedOp();
...
...
@@ -8337,8 +8350,8 @@ bool SMPFunction::CreateSPARKMemoryWriteRangeExpr(size_t LoopIndex, bool RecordL
// Triple: STARSExprSetIter, ByteWidth, index into vector of StackPtrCopiesVector
uint16_t ByteWidth;
for (
list<
size_t
>::const_iterator
BlockNum
Iter =
LoopBlockList
.cbegin(); BlockNumIter != LoopBlockList.cend(); ++BlockNumIter
) {
SMPBasicBlock *CurrBlock = this->GetBlockByNum(
*
BlockNum
Iter
);
for (size_t BlockNum
:
LoopBlockList) {
SMPBasicBlock *CurrBlock = this->GetBlockByNum(BlockNum);
if (CurrBlock->HasIndirectMemWrite() || CurrBlock->HasStaticMemWrite()) {
for (vector<SMPInstr *>::iterator InstIter = CurrBlock->GetFirstInst(); InstIter != CurrBlock->GetLastInst(); ++InstIter) {
SMPInstr *CurrInst = (*InstIter);
...
...
@@ -8394,7 +8407,7 @@ bool SMPFunction::CreateSPARKMemoryWriteRangeExpr(size_t LoopIndex, bool RecordL
bool changed = false;
set<STARS_ea_t> StackPtrCopySet;
int DepthCounter = 0;
success = MemoryRangeExpr->ExpandExpr(MemoryRangeExpr->GetParentInst()->GetAddr(), LoopIndex, false, true, RecordLoopRegs,
true,
false, LoopRegHashes, StoppedOnIV, changed, StackPtrCopySet, DepthCounter);
success = MemoryRangeExpr->ExpandExpr(MemoryRangeExpr->GetParentInst()->GetAddr(), LoopIndex, false, true,
true,
RecordLoopRegs, false, LoopRegHashes, StoppedOnIV, changed, StackPtrCopySet, DepthCounter);
if (!success) {
delete MemoryRangeExpr;
MemoryRangeExpr = nullptr;
...
...
@@ -9432,13 +9445,13 @@ bool SMPFunction::ExpandExprToInArgs(std::size_t LoopIndex, STARSExpression *Cur
if (success && StoppedOnIV) {
success = this->ReplaceAllIVsWithExprs(LoopIndex, CurrExpr, InitCase, changed);
if (!success) {
SMP_msg("ERROR: ReplaceAllIVs failure in ExpandExprToInArgs, InitCase %d iteration %u for UseAddr %llx\n",
InitCase, IterationCount, (uint64_t)OrigUseAddr);
SMP_msg("ERROR:
LOOP:
ReplaceAllIVs failure in ExpandExprToInArgs, InitCase %d iteration %u for UseAddr %llx
loop %zu
\n",
InitCase, IterationCount, (uint64_t)OrigUseAddr
, LoopIndex
);
}
}
else {
SMP_msg("ERROR: ExpandExpr failure in ExpandExprToInArgs, InitCase %d iteration %u for UseAddr %llx\n",
InitCase, IterationCount, (uint64_t) OrigUseAddr);
SMP_msg("ERROR:
LOOP:
ExpandExpr failure in ExpandExprToInArgs, InitCase %d iteration %u for UseAddr %llx
loop %zu
\n",
InitCase, IterationCount, (uint64_t) OrigUseAddr
, LoopIndex
);
}
if (success) {
CurrExpr->EvaluateConsts();
...
...
@@ -12732,7 +12745,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
int FollowBlockNum = this->LoopFollowNodes[LoopIndex];
list<SMPBasicBlock *>::const_iterator TestTargBlockIter = TestBlock->GetCondNonFallThroughSucc();
if (TestTargBlockIter == TestBlock->GetLastConstSucc()) {
SMP_msg("ERROR: Could not find FallThroughSuccessor in test block %d loop %u in func at %llx\n",
SMP_msg("ERROR:
LOOP:
Could not find FallThroughSuccessor in test block %d loop %u in func at %llx\n",
TestBlockNum, LoopIndex, (uint64_t) this->GetFirstFuncAddr());
this->LoopComparisonExprs.push_back(CurrentLoopComparisonExpr);
this->LoopAnalysisProblems[LoopIndex] = true;
...
...
@@ -12766,7 +12779,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
this->LoopComparisonExprs.push_back(CurrentLoopComparisonExpr);
}
else {
SMP_msg("ERROR: Decrement with BranchOperator %d in test block %d DecrementAddr %llx loop %u in func %s at %llx\n",
SMP_msg("ERROR:
LOOP:
Decrement with BranchOperator %d in test block %d DecrementAddr %llx loop %u in func %s at %llx\n",
BranchOperator, TestBlockNum, (uint64_t) DecrementAddr, LoopIndex, this->GetFuncName(), (uint64_t) this->GetFirstFuncAddr());
this->LoopComparisonExprs.push_back(CurrentLoopComparisonExpr);
this->LoopAnalysisProblems[LoopIndex] = true;
...
...
@@ -12774,7 +12787,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
}
else {
SMP_msg("ERROR: Could not find compare or test in test block %d loop %zu in func %s at %llx\n",
SMP_msg("ERROR:
LOOP:
Could not find compare or test in test block %d loop %zu in func %s at %llx\n",
TestBlockNum, LoopIndex, this->GetFuncName(), (uint64_t) this->GetFirstFuncAddr());
this->LoopComparisonExprs.push_back(CurrentLoopComparisonExpr);
this->LoopAnalysisProblems[LoopIndex] = true;
...
...
@@ -12782,7 +12795,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
}
else {
SMP_msg("ERROR: Could not do iteration analysis on loop of type %d loop %zu in func %s at %llx\n",
SMP_msg("ERROR:
LOOP:
Could not do iteration analysis on loop of type %d loop %zu in func %s at %llx\n",
LoopType, LoopIndex, this->GetFuncName(), (uint64_t) this->GetFirstFuncAddr());
this->LoopComparisonExprs.push_back(CurrentLoopComparisonExpr);
this->LoopAnalysisProblems[LoopIndex] = true;
...
...
@@ -12790,7 +12803,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
if (LoopIndex < this->LoopInductionVars.size()) {
SMP_msg("INFO: Analyzing loop iteration exprs for function %s loop %zu\n", this->GetFuncName(), LoopIndex);
SMP_msg("INFO:
LOOP:
Analyzing loop iteration exprs for function %s loop %zu\n", this->GetFuncName(), LoopIndex);
for (STARSInductionVarFamilyIter IVarVecIter = this->LoopInductionVars[LoopIndex].begin();
IVarVecIter != this->LoopInductionVars[LoopIndex].end();
++IVarVecIter) {
...
...
@@ -12841,7 +12854,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
InitExpr->EvaluateConsts();
ParentChanged = InitExpr->SimplifyDriver();
if (VerboseOutput) {
SMP_msg("INFO: Init EXPR:");
SMP_msg("INFO:
LOOP:
Init EXPR:");
InitExpr->Dump(0);
}
...
...
@@ -12857,7 +12870,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
LimitExpr->EvaluateConsts();
ParentChanged = LimitExpr->SimplifyDriver();
if (VerboseOutput) {
SMP_msg("INFO: Limit EXPR:");
SMP_msg("INFO:
LOOP:
Limit EXPR:");
LimitExpr->Dump(0);
}
...
...
@@ -12906,7 +12919,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
this->LoopIterationsInitExprs[LoopIndex] = InitExpr;
this->LoopIterationsLimitExprs[LoopIndex] = LimitExpr;
this->LoopIterationsCountExprs[LoopIndex] = IterationCountExpr;
SMP_msg("INFO: Computed IterationCountExpr for loop %d in function at %llx\n",
SMP_msg("INFO:
LOOP:
Computed IterationCountExpr for loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
// Save the InitExpr and LimitExpr in case this BIV
// is encountered in symbolic ExpandExpr() work later
...
...
@@ -12917,31 +12930,31 @@ void SMPFunction::AnalyzeLoopIterations(void) {
--STARS_LoopIterationExprFailures; // undo top of loop increment
++STARS_LoopIterationExprSuccesses;
if (VerboseOutput) {
SMP_msg("INFO: IterationCount EXPR:");
SMP_msg("INFO:
LOOP:
IterationCount EXPR:");
IterationCountExpr->Dump(0);
}
break; // Found the primary BIV for this LoopIndex
}
else {
SMP_msg("ERROR: Failure to create IterationCountExpr for loop %zu in function at %llx\n",
SMP_msg("ERROR:
LOOP:
Failure to create IterationCountExpr for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
this->LoopAnalysisProblems[LoopIndex] = true;
}
}
else {
SMP_msg("ERROR: Failure on ExpandExpr() for LimitExpr in AnalyzeLoopIterations() for loop %zu in function at %llx\n",
SMP_msg("ERROR:
LOOP:
Failure on ExpandExpr() for LimitExpr in AnalyzeLoopIterations() for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
this->LoopAnalysisProblems[LoopIndex] = true;
}
}
else {
SMP_msg("ERROR: Failure to create LimitExpr for loop %zu in function at %llx\n",
SMP_msg("ERROR:
LOOP:
Failure to create LimitExpr for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
this->LoopAnalysisProblems[LoopIndex] = true;
}
}
else {
SMP_msg("ERROR: Failure on ExpandExpr() for InitExpr in AnalyzeLoopIterations() for loop %zu in function at %llx\n",
SMP_msg("ERROR:
LOOP:
Failure on ExpandExpr() for InitExpr in AnalyzeLoopIterations() for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
this->LoopAnalysisProblems[LoopIndex] = true;
}
...
...
@@ -12956,11 +12969,11 @@ void SMPFunction::AnalyzeLoopIterations(void) {
if (nullptr == this->LoopIterationsCountExprs[LoopIndex]) {
this->LoopAnalysisProblems[LoopIndex] = true;
if (this->DoesLoopWriteMemory(LoopIndex)) {
SMP_msg("ERROR: Failure to create iteration count expr for loop %d in function at %llx\n",
SMP_msg("ERROR:
LOOP:
Failure to create iteration count expr for loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
}
else {
SMP_msg("SERIOUS WARNING: Failure to create iteration count expr for non-mem-writing loop %d starting at %llx in function at %llx\n",
SMP_msg("SERIOUS WARNING:
LOOP:
Failure to create iteration count expr for non-mem-writing loop %d starting at %llx in function at %llx\n",
LoopIndex, (uint64_t)(this->GetBlockByNum((size_t) this->LoopHeadBlockNumbers[LoopIndex])->GetFirstAddr()), (uint64_t) this->GetFirstFuncAddr());
}
}
...
...
@@ -12974,7 +12987,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
bool AttemptAnalysis = (LoopIndex < this->LoopInductionVars.size());
if (AttemptAnalysis) {
if (VerboseOutput) {
SMP_msg("INFO: Analyzing secondary BIVs for function %s loop %zu\n", this->GetFuncName(), LoopIndex);
SMP_msg("INFO:
LOOP:
Analyzing secondary BIVs for function %s loop %zu\n", this->GetFuncName(), LoopIndex);
}
for (STARSInductionVarFamilyIter IVarVecIter = this->LoopInductionVars[LoopIndex].begin();
IVarVecIter != this->LoopInductionVars[LoopIndex].end();
...
...
@@ -13005,14 +13018,14 @@ void SMPFunction::AnalyzeLoopIterations(void) {
InitExpr->EvaluateConsts();
bool ParentChanged = InitExpr->SimplifyDriver();
if (VerboseOutput) {
SMP_msg("INFO: Init EXPR for secondary BIV:");
SMP_msg("INFO:
LOOP:
Init EXPR for secondary BIV:");
InitExpr->Dump(0);
}
// Record the InitExpr in the IV structure.
(*IVarVecIter).BIVInitExpr = InitExpr;
}
else {
SMP_msg("ERROR: Cannot analyze BIV with OutsideDefAddr of %llx\n", (uint64_t)OutsideDefAddr);
SMP_msg("ERROR:
LOOP:
Cannot analyze BIV with OutsideDefAddr of %llx\n", (uint64_t)OutsideDefAddr);
continue;
}
} // end if nullptr == InitExpr
...
...
@@ -13023,16 +13036,14 @@ void SMPFunction::AnalyzeLoopIterations(void) {
LimitExpr->EvaluateConsts();
bool ParentChanged = LimitExpr->SimplifyDriver();
if (VerboseOutput) {
SMP_msg("INFO: Limit EXPR for secondary BIV:");
SMP_msg("INFO:
LOOP:
Limit EXPR for secondary BIV:");
LimitExpr->Dump(0);
}
// Record the LimitExpr in the IV structure.
(*IVarVecIter).BIVLimitExpr = LimitExpr;
}
else {
if (VerboseOutput) {
SMP_msg("ERROR: Failure to create secondary BIV LimitExpr\n");
}
SMP_msg("ERROR: LOOP: Failure to create secondary BIV LimitExpr\n");
}
}
}
...
...
@@ -13058,7 +13069,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
// We have a valid basic induction variable.
// See if it had InitExpr and LimitExpr analyzed successfully.
InductionVarFamily IVFamily = (*IVarVecIter);
if
(
(nullptr == IVFamily.BIVInitExpr)
|| (nullptr == IVFamily.BIVLimitExpr))
{
if (nullptr == IVFamily.BIVInitExpr) {
continue;
}
// We have a valid and analyzed BIV.
...
...
@@ -13067,38 +13078,46 @@ void SMPFunction::AnalyzeLoopIterations(void) {
STARSExpression *DIVInitExpr = this->CreateDIVInitExpr(LoopIndex, IVFamily, DIVIndex);
bool success = (nullptr != DIVInitExpr);
if (!success) {
SMP_msg("ERROR: CreateDIVInitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
SMP_msg("ERROR:
LOOP:
CreateDIVInitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
continue;
}
STARSExpression *DIVLimitExpr = this->CreateDIVLimitExpr(LoopIndex, IVFamily, DIVIndex);
success = (nullptr != DIVLimitExpr);
if (!success) {
SMP_msg("ERROR: CreateDIVLimitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
continue;
STARSExpression *DIVLimitExpr = nullptr;
if (nullptr != IVFamily.BIVLimitExpr) {
DIVLimitExpr = this->CreateDIVLimitExpr(LoopIndex, IVFamily, DIVIndex);
success = (nullptr != DIVLimitExpr);
if (!success) {
SMP_msg("ERROR: LOOP: CreateDIVLimitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
}
}
#if 0
bool changed = false;
success = this->ReplaceAllBIVsWithExprs(LoopIndex, DIVInitExpr, true, changed);
if (!success) {
SMP_msg("ERROR: ReplaceAllBIVsWithExprs on InitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
SMP_msg("ERROR:
LOOP:
ReplaceAllBIVsWithExprs on InitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
continue;
}
success = this->ReplaceAllBIVsWithExprs(LoopIndex, DIVLimitExpr, false, changed);
if (!success) {
SMP_msg("ERROR: ReplaceAllBIVsWithExprs on LimitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
SMP_msg("ERROR:
LOOP:
ReplaceAllBIVsWithExprs on LimitExpr failed for loop %zu DIVIndex %zu\n", LoopIndex, DIVIndex);
continue;
}
#endif
DIVInitExpr->EvaluateConsts();
(void) DIVInitExpr->SimplifyDriver();
DIVLimitExpr->EvaluateConsts();
(void) DIVLimitExpr->SimplifyDriver();
if (nullptr != DIVLimitExpr) {
DIVLimitExpr->EvaluateConsts();
(void)DIVLimitExpr->SimplifyDriver();
}
// Record InitExpr and LimitExpr for DIV.
IVFamily.DependentInductionVars[DIVIndex].DIVInitExpr = DIVInitExpr;
IVFamily.DependentInductionVars[DIVIndex].DIVLimitExpr = DIVLimitExpr;
if (VerboseOutput) {
SMP_msg("INFO: DIV Init Expr for DIVIndex = %zu\n", DIVIndex);
DIVInitExpr->Dump(0);
SMP_msg("INFO: DIV Limit Expr for DIVIndex = %zu\n", DIVIndex);
DIVLimitExpr->Dump(0);
if (nullptr != DIVLimitExpr) {
SMP_msg("INFO: DIV Limit Expr for DIVIndex = %zu\n", DIVIndex);
DIVLimitExpr->Dump(0);
}
}
}
}
...
...
@@ -13124,9 +13143,10 @@ void SMPFunction::AnalyzeLoopIterations(void) {
bool MemRangeSuccess = this->CreateSPARKMemoryWriteRangeExpr(LoopIndex, true, LoopRegHashes, MemWriteExprs, MemWriteExprWidths, StackPtrCopiesVector);
if (MemRangeSuccess) {
this->LoopRegHashSets[LoopIndex] = LoopRegHashes;
SMP_msg("INFO: Computed %zu LoopMemWriteExprs for loop %d in function at %llx\n",
SMP_msg("INFO:
LOOP:
Computed %zu LoopMemWriteExprs for loop %d in function at %llx\n",
MemWriteExprs.size(), LoopIndex, (uint64_t) this->GetFirstFuncAddr());
for (STARSMemWriteExprListIter MemListIter = MemWriteExprWidths.begin(); MemListIter != MemWriteExprWidths.end(); ++MemListIter) {
size_t MemListIndex = 0; // for debugging
for (STARSMemWriteExprListIter MemListIter = MemWriteExprWidths.begin(); MemListIter != MemWriteExprWidths.end(); ++MemListIter, ++MemListIndex) {
STARSExprSetIter ExprIter = (*MemListIter).first;
STARSExpression *MemAddressRangeExpr = (*ExprIter);
pair<STARSExprSetIter, bool> InsertResult = this->LoopMemWriteRangeExprs[LoopIndex].insert(MemAddressRangeExpr);
...
...
@@ -13161,8 +13181,8 @@ void SMPFunction::AnalyzeLoopIterations(void) {
delete MemWriteUpperBound;
MemWriteUpperBound = nullptr;
this->LoopAnalysisProblems[LoopIndex] = true;
SMP_msg("INFO: Failure to ReplaceIVsWithLimitExpr for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
SMP_msg("INFO: Failure to ReplaceIVsWithLimitExpr for
MemListIndex %zu
loop %zu in function at %llx\n",
MemListIndex,
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
}
if (PositiveIncrement) {
STARSExprBoundsPair InsertVal(MemWriteLowerBound, MemWriteUpperBound);
...
...
@@ -13217,8 +13237,10 @@ void SMPFunction::AnalyzeLoopIterations(void) {
// The annotation should look like:
// [hex InstAddr] [InstSize] INSTR STACKMEMRANGE MIN [ESP-k] MAX [ESP-j] ZZ
set<STARS_ea_t> StaticMemLeaAddrSet;
bool StackAnnotation = false;
if (LimitSuccess && MemWriteLowerBoundExpanded->IsStackPtrPlusOffset() && MemWriteUpperBoundExpanded->IsStackPtrPlusOffset()) {
this->EmitStackMemRangeAnnotations(MemWriteLowerBoundExpanded, MemWriteUpperBoundExpanded, PositiveIncrement, UnionedStackPtrCopiesSet, StaticMemLeaAddrSet);
StackAnnotation = true;
}
if (!StaticMemLeaAddrSet.empty()) {
SMP_msg("INFO: StaticMemLeaAddrSet size (writes): %zu \n", StaticMemLeaAddrSet.size());
...
...
@@ -13247,8 +13269,8 @@ void SMPFunction::AnalyzeLoopIterations(void) {
STARS_ea_t MemWriteAddr = MemWriteInst->GetAddr();
if (StaticMemWriteAddrsEmitted.find(MemWriteAddr) == StaticMemWriteAddrsEmitted.cend()) {
if (LimitSuccess && (MemWriteAddr != MemWriteUpperBoundExpanded->GetOriginalParentInst()->GetAddr())) {
SMP_msg("ERROR: Constant lower and upper bound exprs don't have same InstAddr for loop %zu in func %s.\n",
LoopIndex, this->GetFuncName());
SMP_msg("ERROR:
LOOP:
Constant lower and upper bound exprs don't have same InstAddr for
MemListIndex %zu
loop %zu in func %s.\n",
MemListIndex,
LoopIndex, this->GetFuncName());
}
else {
int InstSize = MemWriteInst->GetSize();
...
...
@@ -13280,18 +13302,25 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
}
}
else if (!StackAnnotation) {
// LowerBoundExpanded expr was neither static mem nor stack.
SMP_msg("INFO: LOOP: Expr neither static mem nor stack mem: \n");
if (VerboseOutput) {
MemWriteLowerBoundExpanded->Dump(0);
}
}
}
else {
SMP_msg("ERROR: ExpandExprToInArg failure for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
SMP_msg("ERROR:
LOOP:
ExpandExprToInArg failure for
MemListIndex %zu
loop %zu in function at %llx\n",
MemListIndex,
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
delete MemWriteLowerBoundExpanded;
delete MemWriteUpperBoundExpanded;
this->LoopAnalysisProblems[LoopIndex] = true;
}
}
else {
SMP_msg("
INFO
: Failure to ReplaceIVsWithInitExpr
for
loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
SMP_msg("
ERROR: LOOP
: Failure to ReplaceIVsWithInitExpr
(writes) for MemListIndex %zu
loop %d in function at %llx\n",
MemListIndex,
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
delete MemWriteLowerBound;
if (nullptr != MemWriteUpperBound)
delete MemWriteUpperBound;
...
...
@@ -13299,21 +13328,22 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
}
else {
SMP_msg("INFO: Failure to ReplaceIVsWithInitExpr for loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
SMP_msg("ERROR: LOOP: Failure to ReplaceIVsWithInitExpr (writes) for MemListIndex %zu loop %d in function at %llx\n",
MemListIndex, LoopIndex, (uint64_t) this->GetFirstFuncAddr());
MemWriteLowerBound->Dump(0);
delete MemWriteLowerBound;
this->LoopAnalysisProblems[LoopIndex] = true;
}
}
}
// end for all entries in MemWriteExprWidths
}
else {
if (this->LoopWritesMemory[LoopIndex]) {
SMP_msg("ERROR: Failure to CreateSPARKMemRangeExpr for loop %d in function at %llx\n",
SMP_msg("ERROR:
LOOP:
Failure to CreateSPARKMemRangeExpr for loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
this->LoopAnalysisProblems[LoopIndex] = true;
}
else {
SMP_msg("INFO: No memory writes in loop %d in function at %llx\n",
SMP_msg("INFO:
LOOP:
No memory writes in loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
}
}
...
...
@@ -13324,17 +13354,17 @@ void SMPFunction::AnalyzeLoopIterations(void) {
StackPtrCopiesVector.clear();
MemRangeSuccess = this->CreateSPARKMemoryReadRangeExprs(LoopIndex, false, LoopRegHashes, MemReadExprs, MemReadExprWidths, StackPtrCopiesVector);
if (MemRangeSuccess) {
SMP_msg("INFO: Computed %zu LoopMemReadExprs for loop %d in function at %llx\n",
SMP_msg("INFO:
LOOP:
Computed %zu LoopMemReadExprs for loop %d in function at %llx\n",
MemReadExprs.size(), LoopIndex, (uint64_t) this->GetFirstFuncAddr());
for (STARSMemWriteExprListIter MemListIter = MemReadExprWidths.begin(); MemListIter != MemReadExprWidths.end(); ++MemListIter) {
STARSExprSetIter ExprIter = (*MemListIter).first;
STARSExpression *MemAddressRangeExpr = (*ExprIter);
// pair<STARSExprSetIter, bool> InsertResult = this->LoopMemWriteRangeExprs[LoopIndex].insert(MemAddressRangeExpr);
if (VerboseOutput) {
SMP_msg("INFO: LoopMemRead EXPR:");
SMP_msg("INFO:
LOOP:
LoopMemRead EXPR:");
MemAddressRangeExpr->Dump(0);
if (MemAddressRangeExpr->IsStackPtrRegUsed()) {
SMP_msg("INFO: LoopMemRead EXPR is stack-based.\n");
SMP_msg("INFO:
LOOP:
LoopMemRead EXPR is stack-based.\n");
}
}
// Create the lower and upper bounds of the memory writing range.
...
...
@@ -13346,7 +13376,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
success = this->ReplaceAllIVsWithExprs(LoopIndex, MemReadUpperBound, false, changed);
if (success) {
if (VerboseOutput) {
SMP_msg("INFO: Successfully replaced read IVs with InitExpr and LimitExpr for loop %d in function at %llx\n",
SMP_msg("INFO:
LOOP:
Successfully replaced read IVs with InitExpr and LimitExpr for loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
}
(void) MemReadLowerBound->SimplifyDriver();
...
...
@@ -13354,9 +13384,9 @@ void SMPFunction::AnalyzeLoopIterations(void) {
int StackPtrCopiesVecIndex = (*MemListIter).second.second;
if (VerboseOutput) {
SMP_msg("INFO: MemReadLowerBound EXPR:");
SMP_msg("INFO:
LOOP:
MemReadLowerBound EXPR:");
MemReadLowerBound->Dump(0);
SMP_msg("INFO: MemReadUpperBound EXPR:");
SMP_msg("INFO:
LOOP:
MemReadUpperBound EXPR:");
MemReadUpperBound->Dump(0);
}
...
...
@@ -13364,9 +13394,8 @@ void SMPFunction::AnalyzeLoopIterations(void) {
STARSExpression *MemReadLowerBoundExpanded = MemReadLowerBound->Clone();
STARSExpression *MemReadUpperBoundExpanded = MemReadUpperBound->Clone();
// For inheritance into the callers of this function, we want
// to expand the expressions beyond loop boundaries, hopefully
// as far as incoming args or constant initializers.
// For annotation output, we want to expand the expressions beyond loop boundaries,
// hopefully as far as incoming args or constant initializers.
set<STARS_ea_t> NewStackPtrCopiesSet;
success = this->ExpandExprToInArgs(LoopIndex, MemReadLowerBoundExpanded, true, NewStackPtrCopiesSet);
if (success) {
...
...
@@ -13374,9 +13403,9 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
if (success) {
if (VerboseOutput) {
SMP_msg("INFO: MemReadLowerBoundExpanded EXPR:");
SMP_msg("INFO:
LOOP:
MemReadLowerBoundExpanded EXPR:");
MemReadLowerBoundExpanded->Dump(0);
SMP_msg("INFO: MemReadUpperBoundExpanded EXPR:");
SMP_msg("INFO:
LOOP:
MemReadUpperBoundExpanded EXPR:");
MemReadUpperBoundExpanded->Dump(0);
}
...
...
@@ -13403,7 +13432,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
this->EmitStackMemRangeAnnotations(MemReadLowerBoundExpanded, MemReadUpperBoundExpanded, PositiveIncrement, UnionedStackPtrCopiesSet, StaticMemLeaAddrSet);
}
if (!StaticMemLeaAddrSet.empty()) {
SMP_msg("INFO: StaticMemLeaAddrSet size (reads): %zu \n", StaticMemLeaAddrSet.size());
SMP_msg("INFO:
LOOP:
StaticMemLeaAddrSet size (reads): %zu \n", StaticMemLeaAddrSet.size());
}
// To assist in defenses related to static global memory, output ranges
...
...
@@ -13414,7 +13443,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
STARS_ea_t MemReadAddr = MemReadInst->GetAddr();
if (StaticMemReadAddrsEmitted.find(MemReadAddr) == StaticMemReadAddrsEmitted.cend()) {
if (MemReadAddr != MemReadUpperBoundExpanded->GetOriginalParentInst()->GetAddr()) {
SMP_msg("ERROR: Constant lower and upper bound exprs don't have same InstAddr for loop %zu in func %s.\n",
SMP_msg("ERROR:
LOOP:
Constant lower and upper bound exprs don't have same InstAddr for loop %zu in func %s.\n",
LoopIndex, this->GetFuncName());
}
else {
...
...
@@ -13445,7 +13474,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
}
else {
SMP_msg("ERROR: ExpandExprToInArg failure for loop %zu in function at %llx\n",
SMP_msg("ERROR:
LOOP:
ExpandExprToInArg failure for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
delete MemReadLowerBoundExpanded;
delete MemReadUpperBoundExpanded;
...
...
@@ -13453,7 +13482,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
}
else {
SMP_msg("
INFO
: Failure to ReplaceIVsWithLimitExpr for loop %zu in function at %llx\n",
SMP_msg("
ERROR: LOOP
: Failure to ReplaceIVsWithLimitExpr for loop %zu in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
delete MemReadLowerBound;
delete MemReadUpperBound;
...
...
@@ -13462,7 +13491,7 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
}
else {
SMP_msg("
INFO
: Failure to ReplaceIVsWithInitExpr for loop %d in function at %llx\n",
SMP_msg("
ERROR: LOOP
: Failure to ReplaceIVsWithInitExpr
(reads)
for loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
delete MemReadLowerBound;
// this->LoopAnalysisProblems[LoopIndex] = true;
...
...
@@ -13472,13 +13501,13 @@ void SMPFunction::AnalyzeLoopIterations(void) {
}
else {
if (this->LoopReadsMemory[LoopIndex]) {
SMP_msg("ERROR: Failure to CreateSPARKMemRangeExpr (reads) for loop %d in function at %llx\n",
SMP_msg("ERROR:
LOOP:
Failure to CreateSPARKMemRangeExpr (reads) for loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
// this->LoopAnalysisProblems[LoopIndex] = true;
// this->LoopWritesGlobalStaticMemory[LoopIndex] = false; // reset
}
else {
SMP_msg("INFO: No memory reads in loop %d in function at %llx\n",
SMP_msg("INFO:
LOOP:
No memory reads in loop %d in function at %llx\n",
LoopIndex, (uint64_t) this->GetFirstFuncAddr());
}
}
...
...
This diff is collapsed.
Click to expand it.
src/base/SMPInstr.cpp
View file @
9ae06334
...
...
@@ -3433,16 +3433,9 @@ bool STARSExpression::SimplifyExpr(STARSExpression *ParentExpr) {
if (ConstRightOperand) {
STARS_uval_t RightValue = this->GetConstRightOperand()->GetImmedValue();
SMPoperator CurrOperator = this->GetOperator();
// Simplify multiplication by 0 or 1, division by 1, addition or subtraction of 0.
if (1 == RightValue) {
if ((SMP_U_MULTIPLY <= CurrOperator) && (SMP_S_DIVIDE >= CurrOperator)) {
// Multiply or divide by 1, produces left tree as result.
// We can simplify the current expr by making it just be the RightTree or RightOperand.
LeftOperandLifted = this->ElevateLeftSide(ParentExpr);
LeftNullTree = (!this->HasLeftSubTree());
}
}
else if (0 == RightValue) {
// Simplify multiplication by 0 or 1, division by 1, addition or subtraction of 0,
// and transform shifts into multiplies or divides.
if (0 == RightValue) {
if ((SMP_U_MULTIPLY == CurrOperator) && (SMP_S_MULTIPLY == CurrOperator)) {
// Multiply by 0, produces zero as result.
// We can simplify the current expr by making it just be the RightOperand, zero.
...
...
@@ -3464,7 +3457,7 @@ bool STARSExpression::SimplifyExpr(STARSExpression *ParentExpr) {
if (RightValue < (8 * sizeof(STARS_uval_t))) { // don't overflow
int ShiftCount = (int) RightValue;
RightValue = 1;
while (ShiftCount > 16) {
while (ShiftCount > 16) {
// C/C++ limit on shifting
RightValue = (RightValue << 16);
ShiftCount -= 16;
}
...
...
@@ -3484,6 +3477,14 @@ bool STARSExpression::SimplifyExpr(STARSExpression *ParentExpr) {
this->SetOperator(CurrOperator);
}
}
else if (1 == RightValue) {
if ((SMP_U_MULTIPLY <= CurrOperator) && (SMP_S_DIVIDE >= CurrOperator)) {
// Multiply or divide by 1, produces left tree as result.
// We can simplify the current expr by making it just be the RightTree or RightOperand.
LeftOperandLifted = this->ElevateLeftSide(ParentExpr);
LeftNullTree = (!this->HasLeftSubTree());
}
}
// Handle the multiply by stride and then divide by stride, or vice versa, that are common
// in loop iteration count and memory range analyses, e.g. (x / 8) * 8.
if (!LeftNullTree && (RightValue > 1) && ((SMP_U_MULTIPLY <= CurrOperator) && (SMP_S_DIVIDE >= CurrOperator))) {
...
...
@@ -3568,10 +3569,15 @@ bool STARSExpression::SimplifyExpr(STARSExpression *ParentExpr) {
}
this->SetLeftUseAddr(this->GetLeftTree()->GetLeftUseAddr());
this->SetLeftSSANum(this->GetLeftTree()->GetLeftSSANum());
this->SetLeftOperand(this->GetLeftTree()->GetConstLeftOperand());
if (this->GetLeftTree()->HasLeftSubTree()) {
LeftOperandLifted = this->GetLeftTree()->ElevateLeftSide(this);
}
else {
this->SetLeftOperand(this->GetLeftTree()->GetConstLeftOperand());
LeftNullTree = true;
}
SumValue = (STARS_uval_t)SignedSumValue;
this->SetRightOperand(this->GetParentInst()->MakeImmediateOpnd(SumValue));
LeftNullTree = true;
}
}
} // end of cascading additions and subtractions
This diff is collapsed.
Click to expand it.