Skip to content

Commit

Permalink
Merge pull request #16053 from e-kayrakli/static-fast-follower-minimal
Browse files Browse the repository at this point in the history
Add static analysis to avoid adding slow followers in some cases

This PR adds a static analysis to detect whether zippered distributed arrays
share the same domain and thus can leverage the fast follower optimization.

This is a small part of what I attempted at #16001.

This PR also rearranges the newly-added autoLocalAccess.cpp to make it more
general purpose.

Summary of changes:

- Add `staticFastFollowerAnalysis` to `autoLocalAccess.cpp`
- Do some refactor on that file:
  - Rename to `preNormalizeOptimizations.cpp`
  - Put function declarations in the beginning of the file
  - Add a function `doPreNormalizeArrayOptimizations` to handle automatic local
    access and fast follower analysis right before normalization.

Although the main motivation for this PR was to reduce the compilation time
overheads, in some of the benchmarks I have seen that clones removed by this PR
to constitute only a small partion of those extra clones. #16001 gives an idea
of what needs to be done to remove a larger number of copies, and I hope to
revisit that effort soon.

[Reviewed by @ronawho]

Test:
- [x] add a test to lock the behavior
- [x] standard
- [x] gasnet
  • Loading branch information
e-kayrakli committed Jul 15, 2020
2 parents 1240f23 + 0af5b36 commit b95172e
Show file tree
Hide file tree
Showing 34 changed files with 295 additions and 162 deletions.
1 change: 1 addition & 0 deletions compiler/AST/ForallStmt.cpp
Expand Up @@ -56,6 +56,7 @@ ForallStmt::ForallStmt(BlockStmt* body):


optInfo.autoLocalAccessChecked = false;
optInfo.confirmedFastFollower = false;

gForallStmts.add(this);
}
Expand Down
13 changes: 10 additions & 3 deletions compiler/AST/foralls.cpp
Expand Up @@ -964,9 +964,16 @@ static void buildLeaderLoopBody(ForallStmt* pfs, Expr* iterExpr) {
new_Expr("'move'(%S, %S)", T2, gFalse)));
} else {
leadForLoop->insertAtTail("'move'(%S, chpl__staticFastFollowCheckZip(%S))", T1, iterRec);
leadForLoop->insertAtTail(new CondStmt(new SymExpr(T1),
new_Expr("'move'(%S, chpl__dynamicFastFollowCheckZip(%S))", T2, iterRec),
new_Expr("'move'(%S, %S)", T2, gFalse)));

// override the dynamic check if the compiler can prove it's safe
if (pfs->optInfo.confirmedFastFollower) {
leadForLoop->insertAtTail(new_Expr("'move'(%S, %S)", T2, T1));
}
else {
leadForLoop->insertAtTail(new CondStmt(new SymExpr(T1),
new_Expr("'move'(%S, chpl__dynamicFastFollowCheckZip(%S))", T2, iterRec),
new_Expr("'move'(%S, %S)", T2, gFalse)));
}
}

SymbolMap map;
Expand Down
3 changes: 3 additions & 0 deletions compiler/include/ForallStmt.h
Expand Up @@ -46,6 +46,9 @@ class ForallOptimizationInfo {
std::vector<Symbol *> staticCheckSymsForDynamicCandidates;

bool autoLocalAccessChecked;


bool confirmedFastFollower;
};

///////////////////////////////////
Expand Down
Expand Up @@ -18,14 +18,14 @@
* limitations under the License.
*/

#ifndef _AUTO_LOCAL_ACCESS_H_
#define _AUTO_LOCAL_ACCESS_H_
#ifndef _PRE_NORMALIZE_OPTIMIZATIONS_H_
#define _PRE_NORMALIZE_OPTIMIZATIONS_H_

#include "CallExpr.h"
#include "symbol.h"

// interface for normalize
void autoLocalAccess();
void doPreNormalizeArrayOptimizations();

// interface for resolution
Expr *preFoldMaybeLocalThis(CallExpr *call);
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizations/Makefile.share
Expand Up @@ -17,7 +17,6 @@
# limitations under the License.

OPTIMIZATIONS_SRCS = \
autoLocalAccess.cpp \
bulkCopyRecords.cpp \
copyPropagation.cpp \
deadCodeElimination.cpp \
Expand All @@ -29,6 +28,7 @@ OPTIMIZATIONS_SRCS = \
noAliasSets.cpp \
optimizeForallUnorderedOps.cpp \
optimizeOnClauses.cpp \
preNormalizeOptimizations.cpp \
refPropagation.cpp \
remoteValueForwarding.cpp \
removeEmptyRecords.cpp \
Expand Down

0 comments on commit b95172e

Please sign in to comment.