Branch: refs/heads/master
Revision: 9ef62f4
Author: ekayrakli
Log Message:
Merge pull request #16397 from ekayrakli/constdomainfix
Fix some issues with constant domain optimization
This PR improves constant domain optimization in several ways.

Make domain literals always constant

Fix domain constness w.r.t. argument/task intents

Fix constant domain views

Fix array views and how their domains’ constness are handled

Add bunch of tests
Implementation details:
 Creates a
compiler/optimizations/propagateDomainConstness.cpp
that contains
all the relevant support functions.  Adjusts where we remove init/autoCopy during
callDestructors
and
removeUnnecessaryAutoCopyCalls
 Make domain literals always be constant (through parser changes), but unset
constness if those literals are assigned to avar
variable.  Add
FLAG_CONST
to field initialization temps, if the field itself has that
flag.  Add adjustment code after replacing
PRIM_MOVE
s withPRIM_SET_MEMBER
s in
initializers  Adjust
test/studies/amr
to not define irregular const domain fields in user
types
Future steps:

Depending on what happens with https://github.com/chapellang/chapel/issues/16398
we may need to do some adjustments in this implementation. 
@mppf brings up a good point about how the domain constness is handled in two
different ways. (1) we manipulate an additional argument to initCopy et al, to
set the constness of the LHS, (2) set the definedConst field after the
assignment [this mostly starts to happen with this PR].Initial hope was that with (1) we can handle many cases, and use (2) in
limited number of scenarios. However, after this PR, I can’t tell which one is
the “main” way to handle this optimization, as there are some pretty
significant scenarios where we can’t do (1).I still hope that there can be something we can do with the types, and not
have to have so many AST modifications only to set the constness of a
variable. But, lumping constness into the type has its own challanges. 
Can we do something to optimize functions where a var domain is captured with
const [ref]
intent?
proc foo(const d: domain) {
var a: [d] int;
// do something with a but do *not* return it
}
var d = {1..10};
foo(d);
As a
’s scope is a scope where d
is constant, we can avoid tracking it, however, we don’t
do that today because d
in foo
is just a reference to a nonconst domain.
 Improve how we handle
definedConst
for privatized instances to reduce
commcounts.
[Reviewed by @mppf]
Test:
 [x] standard
 [x] gasnet
Modified Files:
A compiler/optimizations/propagateDomainConstness.cpp
A test/optimizations/constDomain/arrView.chpl
A test/optimizations/constDomain/arrView.good
A test/optimizations/constDomain/constIntoVar.chpl
A test/optimizations/constDomain/constIntoVar.good
A test/optimizations/constDomain/constIntoVar2.chpl
A test/optimizations/constDomain/constIntoVar2.good
A test/optimizations/constDomain/domainArgs.chpl
A test/optimizations/constDomain/domainArgs.good
A test/optimizations/constDomain/domainField.chpl
A test/optimizations/constDomain/domainField.good
A test/optimizations/constDomain/domainFieldUserInit.chpl
A test/optimizations/constDomain/domainFieldUserInit.good
A test/optimizations/constDomain/domainView.chpl
A test/optimizations/constDomain/domainView.good
A test/optimizations/constDomain/forallIntent.chpl
A test/optimizations/constDomain/forallIntent.good
M compiler/AST/build.cpp
M compiler/include/optimizations.h
M compiler/optimizations/Makefile.share
M compiler/optimizations/removeUnnecessaryAutoCopyCalls.cpp
M compiler/parser/bisonchapel.cpp
M compiler/parser/chapel.ypp
M compiler/passes/InitNormalize.cpp
M compiler/resolution/callDestructors.cpp
M compiler/resolution/cleanups.cpp
M compiler/resolution/functionResolution.cpp
M compiler/resolution/initializerResolution.cpp
M compiler/resolution/wrappers.cpp
M modules/internal/ArrayViewSlice.chpl
M modules/internal/ChapelArray.chpl
M test/arrays/slices/commCounts/sliceBlockWithRanges.good
M test/arrays/slices/commCounts/sliceBlockWithRanges.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/assignReindex.block.good
M test/distributions/robust/arithmetic/performance/multilocale/assignReindex.block.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/assignReindex.cyclic.good
M test/distributions/robust/arithmetic/performance/multilocale/assignReindex.cyclic.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/assignReindex.replicated.good
M test/distributions/robust/arithmetic/performance/multilocale/assignReindex.replicated.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/assignSlice.block.good
M test/distributions/robust/arithmetic/performance/multilocale/assignSlice.block.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/assignSlice.cyclic.good
M test/distributions/robust/arithmetic/performance/multilocale/assignSlice.cyclic.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/assignSlice.replicated.good
M test/distributions/robust/arithmetic/performance/multilocale/assignSlice.replicated.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/reduceSlice.block.good
M test/distributions/robust/arithmetic/performance/multilocale/reduceSlice.block.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/reduceSlice.cyclic.good
M test/distributions/robust/arithmetic/performance/multilocale/reduceSlice.cyclic.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/reduceSlice.replicated.good
M test/distributions/robust/arithmetic/performance/multilocale/reduceSlice.replicated.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/sliceOps.block.good
M test/distributions/robust/arithmetic/performance/multilocale/sliceOps.block.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/sliceOps.cyclic.good
M test/distributions/robust/arithmetic/performance/multilocale/sliceOps.cyclic.nanone.good
M test/distributions/robust/arithmetic/performance/multilocale/sliceOps.replicated.good
M test/studies/amr/lib/amr/AMRHierarchy_def.chpl
M test/studies/amr/lib/amr/BergerRigoutsosClustering.chpl
M test/studies/amr/lib/cfboundary/CoarseningTransfer.chpl
M test/studies/amr/lib/grid/Grid_def.chpl
M test/studies/amr/lib/level/Level_def.chpl
Compare: https://github.com/chapellang/chapel/compare/50284c3953f3...9ef62f423eb4