2015-03-05 14:52:42 +08:00
|
|
|
//===- DependenceInfo.cpp - Calculate dependency information for a Scop. --===//
|
2011-04-29 14:27:02 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Calculate the data dependency relations for a Scop using ISL.
|
|
|
|
//
|
|
|
|
// The integer set library (ISL) from Sven, has a integrated dependency analysis
|
|
|
|
// to calculate data dependences. This pass takes advantage of this and
|
|
|
|
// calculate those dependences a Scop.
|
|
|
|
//
|
|
|
|
// The dependences in this pass are exact in terms that for a specific read
|
|
|
|
// statement instance only the last write statement instance is returned. In
|
|
|
|
// case of may writes a set of possible write instances is returned. This
|
|
|
|
// analysis will never produce redundant dependences.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2015-03-05 06:43:40 +08:00
|
|
|
#include "polly/DependenceInfo.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "polly/LinkAllPasses.h"
|
2013-05-07 15:31:10 +08:00
|
|
|
#include "polly/Options.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "polly/ScopInfo.h"
|
|
|
|
#include "polly/Support/GICHelper.h"
|
2014-04-22 11:30:19 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2012-03-08 00:10:40 +08:00
|
|
|
#include <isl/aff.h>
|
2014-01-27 03:38:34 +08:00
|
|
|
#include <isl/ctx.h>
|
2012-05-22 16:46:07 +08:00
|
|
|
#include <isl/flow.h>
|
|
|
|
#include <isl/map.h>
|
2014-01-27 03:38:34 +08:00
|
|
|
#include <isl/options.h>
|
2015-04-21 19:01:34 +08:00
|
|
|
#include <isl/schedule.h>
|
2015-05-09 17:13:42 +08:00
|
|
|
#include <isl/set.h>
|
2015-05-09 17:36:38 +08:00
|
|
|
#include <isl/union_map.h>
|
|
|
|
#include <isl/union_set.h>
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
using namespace polly;
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 11:30:19 +08:00
|
|
|
#define DEBUG_TYPE "polly-dependence"
|
|
|
|
|
2014-07-09 18:50:10 +08:00
|
|
|
static cl::opt<int> OptComputeOut(
|
|
|
|
"polly-dependences-computeout",
|
|
|
|
cl::desc("Bound the dependence analysis by a maximal amount of "
|
2015-04-19 15:07:26 +08:00
|
|
|
"computational steps (0 means no bound)"),
|
2015-07-14 17:33:13 +08:00
|
|
|
cl::Hidden, cl::init(500000), cl::ZeroOrMore, cl::cat(PollyCategory));
|
2014-01-27 03:38:34 +08:00
|
|
|
|
2014-07-09 18:50:10 +08:00
|
|
|
static cl::opt<bool> LegalityCheckDisabled(
|
|
|
|
"disable-polly-legality", cl::desc("Disable polly legality check"),
|
|
|
|
cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-09-16 17:50:17 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
UseReductions("polly-dependences-use-reductions",
|
|
|
|
cl::desc("Exploit reductions in dependence analysis"),
|
|
|
|
cl::Hidden, cl::init(true), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
2014-01-06 09:37:13 +08:00
|
|
|
enum AnalysisType { VALUE_BASED_ANALYSIS, MEMORY_BASED_ANALYSIS };
|
2013-07-14 01:37:55 +08:00
|
|
|
|
|
|
|
static cl::opt<enum AnalysisType> OptAnalysisType(
|
|
|
|
"polly-dependences-analysis-type",
|
|
|
|
cl::desc("The kind of dependence analysis to use"),
|
|
|
|
cl::values(clEnumValN(VALUE_BASED_ANALYSIS, "value-based",
|
|
|
|
"Exact dependences without transitive dependences"),
|
|
|
|
clEnumValN(MEMORY_BASED_ANALYSIS, "memory-based",
|
2016-10-09 03:41:06 +08:00
|
|
|
"Overapproximation of dependences")),
|
2014-03-14 07:37:43 +08:00
|
|
|
cl::Hidden, cl::init(VALUE_BASED_ANALYSIS), cl::ZeroOrMore,
|
|
|
|
cl::cat(PollyCategory));
|
2012-11-02 05:28:32 +08:00
|
|
|
|
2016-11-24 05:59:33 +08:00
|
|
|
static cl::opt<Dependences::AnalysisLevel> OptAnalysisLevel(
|
2016-02-27 01:05:24 +08:00
|
|
|
"polly-dependences-analysis-level",
|
|
|
|
cl::desc("The level of dependence analysis"),
|
2016-03-28 20:41:49 +08:00
|
|
|
cl::values(clEnumValN(Dependences::AL_Statement, "statement-wise",
|
2016-02-27 01:05:24 +08:00
|
|
|
"Statement-level analysis"),
|
2016-03-28 20:41:49 +08:00
|
|
|
clEnumValN(Dependences::AL_Reference, "reference-wise",
|
2016-02-27 01:05:24 +08:00
|
|
|
"Memory reference level analysis that distinguish"
|
|
|
|
" accessed references in the same statement"),
|
2016-03-28 20:41:49 +08:00
|
|
|
clEnumValN(Dependences::AL_Access, "access-wise",
|
2016-02-27 01:05:24 +08:00
|
|
|
"Memory reference level analysis that distinguish"
|
2016-10-09 03:41:06 +08:00
|
|
|
" access instructions in the same statement")),
|
2016-03-03 16:15:33 +08:00
|
|
|
cl::Hidden, cl::init(Dependences::AL_Statement), cl::ZeroOrMore,
|
2016-02-27 01:05:24 +08:00
|
|
|
cl::cat(PollyCategory));
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Tag the @p Relation domain with @p TagId
|
2016-02-27 01:05:24 +08:00
|
|
|
static __isl_give isl_map *tag(__isl_take isl_map *Relation,
|
|
|
|
__isl_take isl_id *TagId) {
|
|
|
|
isl_space *Space = isl_map_get_space(Relation);
|
2017-03-17 20:59:01 +08:00
|
|
|
Space = isl_space_drop_dims(Space, isl_dim_out, 0,
|
|
|
|
isl_map_dim(Relation, isl_dim_out));
|
2016-02-27 01:05:24 +08:00
|
|
|
Space = isl_space_set_tuple_id(Space, isl_dim_out, TagId);
|
|
|
|
isl_multi_aff *Tag = isl_multi_aff_domain_map(Space);
|
|
|
|
Relation = isl_map_preimage_domain_multi_aff(Relation, Tag);
|
|
|
|
return Relation;
|
|
|
|
}
|
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Tag the @p Relation domain with either MA->getArrayId() or
|
2016-02-27 01:05:24 +08:00
|
|
|
/// MA->getId() based on @p TagLevel
|
|
|
|
static __isl_give isl_map *tag(__isl_take isl_map *Relation, MemoryAccess *MA,
|
2016-11-24 05:59:33 +08:00
|
|
|
Dependences::AnalysisLevel TagLevel) {
|
2016-03-03 16:15:33 +08:00
|
|
|
if (TagLevel == Dependences::AL_Reference)
|
2017-07-23 12:08:59 +08:00
|
|
|
return tag(Relation, MA->getArrayId().release());
|
2016-02-27 01:05:24 +08:00
|
|
|
|
2016-03-03 16:15:33 +08:00
|
|
|
if (TagLevel == Dependences::AL_Access)
|
2017-07-23 12:08:11 +08:00
|
|
|
return tag(Relation, MA->getId().release());
|
2016-02-27 01:05:24 +08:00
|
|
|
|
|
|
|
// No need to tag at the statement level.
|
|
|
|
return Relation;
|
|
|
|
}
|
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Collect information about the SCoP @p S.
|
2017-03-21 19:54:08 +08:00
|
|
|
static void collectInfo(Scop &S, isl_union_map *&Read,
|
|
|
|
isl_union_map *&MustWrite, isl_union_map *&MayWrite,
|
2017-02-23 23:40:56 +08:00
|
|
|
isl_union_map *&ReductionTagMap,
|
|
|
|
isl_union_set *&TaggedStmtDomain,
|
2016-11-24 05:59:33 +08:00
|
|
|
Dependences::AnalysisLevel Level) {
|
2017-08-07 04:11:59 +08:00
|
|
|
isl_space *Space = S.getParamSpace().release();
|
2017-02-23 23:40:56 +08:00
|
|
|
Read = isl_union_map_empty(isl_space_copy(Space));
|
2017-03-21 19:54:08 +08:00
|
|
|
MustWrite = isl_union_map_empty(isl_space_copy(Space));
|
2017-02-23 23:40:56 +08:00
|
|
|
MayWrite = isl_union_map_empty(isl_space_copy(Space));
|
|
|
|
ReductionTagMap = isl_union_map_empty(isl_space_copy(Space));
|
2017-02-23 23:40:46 +08:00
|
|
|
isl_union_map *StmtSchedule = isl_union_map_empty(Space);
|
2014-06-27 02:38:08 +08:00
|
|
|
|
2017-02-09 16:06:05 +08:00
|
|
|
SmallPtrSet<const ScopArrayInfo *, 8> ReductionArrays;
|
2015-09-16 17:50:17 +08:00
|
|
|
if (UseReductions)
|
|
|
|
for (ScopStmt &Stmt : S)
|
|
|
|
for (MemoryAccess *MA : Stmt)
|
|
|
|
if (MA->isReductionLike())
|
2017-02-09 16:06:05 +08:00
|
|
|
ReductionArrays.insert(MA->getScopArrayInfo());
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
|
|
|
for (MemoryAccess *MA : Stmt) {
|
2017-08-07 00:39:52 +08:00
|
|
|
isl_set *domcp = Stmt.getDomain().release();
|
2017-07-23 12:08:38 +08:00
|
|
|
isl_map *accdom = MA->getAccessRelation().release();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
accdom = isl_map_intersect_domain(accdom, domcp);
|
|
|
|
|
2017-02-09 16:06:05 +08:00
|
|
|
if (ReductionArrays.count(MA->getScopArrayInfo())) {
|
2015-04-21 19:37:25 +08:00
|
|
|
// Wrap the access domain and adjust the schedule accordingly.
|
2014-06-27 02:38:08 +08:00
|
|
|
//
|
|
|
|
// An access domain like
|
|
|
|
// Stmt[i0, i1] -> MemAcc_A[i0 + i1]
|
|
|
|
// will be transformed into
|
|
|
|
// [Stmt[i0, i1] -> MemAcc_A[i0 + i1]] -> MemAcc_A[i0 + i1]
|
|
|
|
//
|
2017-02-21 23:38:31 +08:00
|
|
|
// We collect all the access domains in the ReductionTagMap.
|
|
|
|
// This is used in Dependences::calculateDependences to create
|
|
|
|
// a tagged Schedule tree.
|
2016-02-27 01:05:24 +08:00
|
|
|
|
2017-02-23 23:40:56 +08:00
|
|
|
ReductionTagMap =
|
|
|
|
isl_union_map_add_map(ReductionTagMap, isl_map_copy(accdom));
|
2017-02-21 23:38:31 +08:00
|
|
|
accdom = isl_map_range_map(accdom);
|
2016-02-27 01:05:24 +08:00
|
|
|
} else {
|
2016-03-03 16:15:33 +08:00
|
|
|
accdom = tag(accdom, MA, Level);
|
|
|
|
if (Level > Dependences::AL_Statement) {
|
2017-08-07 01:45:28 +08:00
|
|
|
isl_map *StmtScheduleMap = Stmt.getSchedule().release();
|
2017-01-16 22:08:10 +08:00
|
|
|
assert(StmtScheduleMap &&
|
|
|
|
"Schedules that contain extension nodes require special "
|
|
|
|
"handling.");
|
2016-09-14 14:26:09 +08:00
|
|
|
isl_map *Schedule = tag(StmtScheduleMap, MA, Level);
|
2017-02-23 23:40:46 +08:00
|
|
|
StmtSchedule = isl_union_map_add_map(StmtSchedule, Schedule);
|
2016-02-27 01:05:24 +08:00
|
|
|
}
|
2014-06-27 02:38:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-14 02:01:45 +08:00
|
|
|
if (MA->isRead())
|
2017-02-23 23:40:56 +08:00
|
|
|
Read = isl_union_map_add_map(Read, accdom);
|
2017-03-17 20:31:28 +08:00
|
|
|
else if (MA->isMayWrite())
|
|
|
|
MayWrite = isl_union_map_add_map(MayWrite, accdom);
|
2011-04-29 14:27:02 +08:00
|
|
|
else
|
2017-03-21 19:54:08 +08:00
|
|
|
MustWrite = isl_union_map_add_map(MustWrite, accdom);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
2016-02-27 01:05:24 +08:00
|
|
|
|
2017-02-09 16:06:05 +08:00
|
|
|
if (!ReductionArrays.empty() && Level == Dependences::AL_Statement)
|
2017-08-07 01:45:28 +08:00
|
|
|
StmtSchedule =
|
|
|
|
isl_union_map_add_map(StmtSchedule, Stmt.getSchedule().release());
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
Assume GetElementPtr offsets to be inbounds
In case a GEP instruction references into a fixed size array e.g., an access
A[i][j] into an array A[100x100], LLVM-IR does not guarantee that the subscripts
always compute values that are within array bounds. We now derive the set of
parameter values for which all accesses are within bounds and add the assumption
that the scop is only every executed with this set of parameter values.
Example:
void foo(float A[][20], long n, long m {
for (long i = 0; i < n; i++)
for (long j = 0; j < m; j++)
A[i][j] = ...
This loop yields out-of-bound accesses if m is at least 20 and at the same time
at least one iteration of the outer loop is executed. Hence, we assume:
n <= 0 or m <= 20.
Doing so simplifies the dependence analysis problem, allows us to perform
more optimizations and generate better code.
TODO: The location where the GEP instruction is executed is not necessarily the
location where the memory is actually accessed. As a result scanning for GEP[s]
is imprecise. Even though this is not a correctness problem, this imprecision
may result in missed optimizations or non-optimal run-time checks.
In polybench where this mismatch between parametric loop bounds and fixed size
arrays is common, we see with this patch significant reductions in compile time
(up to 50%) and execution time (up to 70%). We see two significant compile time
regressions (fdtd-2d, jacobi-2d-imper), and one execution time regression
(trmm). Both regressions arise due to additional optimizations that have been
enabled by this patch. They can be addressed in subsequent commits.
http://reviews.llvm.org/D6369
llvm-svn: 222754
2014-11-25 18:51:12 +08:00
|
|
|
|
2017-08-07 05:42:09 +08:00
|
|
|
StmtSchedule = isl_union_map_intersect_params(
|
|
|
|
StmtSchedule, S.getAssumedContext().release());
|
2017-02-23 23:40:56 +08:00
|
|
|
TaggedStmtDomain = isl_union_map_domain(StmtSchedule);
|
2016-02-26 17:47:08 +08:00
|
|
|
|
2017-02-23 23:40:56 +08:00
|
|
|
ReductionTagMap = isl_union_map_coalesce(ReductionTagMap);
|
|
|
|
Read = isl_union_map_coalesce(Read);
|
2017-03-21 19:54:08 +08:00
|
|
|
MustWrite = isl_union_map_coalesce(MustWrite);
|
2017-02-23 23:40:56 +08:00
|
|
|
MayWrite = isl_union_map_coalesce(MayWrite);
|
2012-03-08 01:42:45 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Fix all dimension of @p Zero to 0 and add it to @p user
|
2015-05-28 21:32:11 +08:00
|
|
|
static isl_stat fixSetToZero(__isl_take isl_set *Zero, void *user) {
|
2014-07-15 08:00:35 +08:00
|
|
|
isl_union_set **User = (isl_union_set **)user;
|
|
|
|
for (unsigned i = 0; i < isl_set_dim(Zero, isl_dim_set); i++)
|
|
|
|
Zero = isl_set_fix_si(Zero, isl_dim_set, i, 0);
|
|
|
|
*User = isl_union_set_add_set(*User, Zero);
|
2015-05-28 21:32:11 +08:00
|
|
|
return isl_stat_ok;
|
2014-07-15 08:00:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Compute the privatization dependences for a given dependency @p Map
|
2014-06-21 00:37:11 +08:00
|
|
|
///
|
|
|
|
/// Privatization dependences are widened original dependences which originate
|
|
|
|
/// or end in a reduction access. To compute them we apply the transitive close
|
|
|
|
/// of the reduction dependences (which maps each iteration of a reduction
|
|
|
|
/// statement to all following ones) on the RAW/WAR/WAW dependences. The
|
|
|
|
/// dependences which start or end at a reduction statement will be extended to
|
|
|
|
/// depend on all following reduction statement iterations as well.
|
|
|
|
/// Note: "Following" here means according to the reduction dependences.
|
|
|
|
///
|
|
|
|
/// For the input:
|
|
|
|
///
|
|
|
|
/// S0: *sum = 0;
|
|
|
|
/// for (int i = 0; i < 1024; i++)
|
|
|
|
/// S1: *sum += i;
|
|
|
|
/// S2: *sum = *sum * 3;
|
|
|
|
///
|
|
|
|
/// we have the following dependences before we add privatization dependences:
|
|
|
|
///
|
|
|
|
/// RAW:
|
|
|
|
/// { S0[] -> S1[0]; S1[1023] -> S2[] }
|
|
|
|
/// WAR:
|
|
|
|
/// { }
|
|
|
|
/// WAW:
|
|
|
|
/// { S0[] -> S1[0]; S1[1024] -> S2[] }
|
|
|
|
/// RED:
|
|
|
|
/// { S1[i0] -> S1[1 + i0] : i0 >= 0 and i0 <= 1022 }
|
|
|
|
///
|
|
|
|
/// and afterwards:
|
|
|
|
///
|
|
|
|
/// RAW:
|
|
|
|
/// { S0[] -> S1[i0] : i0 >= 0 and i0 <= 1023;
|
|
|
|
/// S1[i0] -> S2[] : i0 >= 0 and i0 <= 1023}
|
|
|
|
/// WAR:
|
|
|
|
/// { }
|
|
|
|
/// WAW:
|
|
|
|
/// { S0[] -> S1[i0] : i0 >= 0 and i0 <= 1023;
|
|
|
|
/// S1[i0] -> S2[] : i0 >= 0 and i0 <= 1023}
|
|
|
|
/// RED:
|
|
|
|
/// { S1[i0] -> S1[1 + i0] : i0 >= 0 and i0 <= 1022 }
|
2014-07-15 08:00:35 +08:00
|
|
|
///
|
|
|
|
/// Note: This function also computes the (reverse) transitive closure of the
|
|
|
|
/// reduction dependences.
|
2015-03-05 08:43:48 +08:00
|
|
|
void Dependences::addPrivatizationDependences() {
|
2014-07-15 08:00:35 +08:00
|
|
|
isl_union_map *PrivRAW, *PrivWAW, *PrivWAR;
|
|
|
|
|
|
|
|
// The transitive closure might be over approximated, thus could lead to
|
|
|
|
// dependency cycles in the privatization dependences. To make sure this
|
|
|
|
// will not happen we remove all negative dependences after we computed
|
|
|
|
// the transitive closure.
|
2016-06-23 00:22:00 +08:00
|
|
|
TC_RED = isl_union_map_transitive_closure(isl_union_map_copy(RED), nullptr);
|
2014-07-15 08:00:35 +08:00
|
|
|
|
|
|
|
// FIXME: Apply the current schedule instead of assuming the identity schedule
|
|
|
|
// here. The current approach is only valid as long as we compute the
|
|
|
|
// dependences only with the initial (identity schedule). Any other
|
2014-10-23 07:26:48 +08:00
|
|
|
// schedule could change "the direction of the backward dependences" we
|
2014-07-15 08:00:35 +08:00
|
|
|
// want to eliminate here.
|
|
|
|
isl_union_set *UDeltas = isl_union_map_deltas(isl_union_map_copy(TC_RED));
|
|
|
|
isl_union_set *Universe = isl_union_set_universe(isl_union_set_copy(UDeltas));
|
|
|
|
isl_union_set *Zero = isl_union_set_empty(isl_union_set_get_space(Universe));
|
|
|
|
isl_union_set_foreach_set(Universe, fixSetToZero, &Zero);
|
|
|
|
isl_union_map *NonPositive = isl_union_set_lex_le_union_set(UDeltas, Zero);
|
|
|
|
|
|
|
|
TC_RED = isl_union_map_subtract(TC_RED, NonPositive);
|
|
|
|
|
|
|
|
TC_RED = isl_union_map_union(
|
|
|
|
TC_RED, isl_union_map_reverse(isl_union_map_copy(TC_RED)));
|
|
|
|
TC_RED = isl_union_map_coalesce(TC_RED);
|
2014-06-21 00:37:11 +08:00
|
|
|
|
|
|
|
isl_union_map **Maps[] = {&RAW, &WAW, &WAR};
|
|
|
|
isl_union_map **PrivMaps[] = {&PrivRAW, &PrivWAW, &PrivWAR};
|
|
|
|
for (unsigned u = 0; u < 3; u++) {
|
|
|
|
isl_union_map **Map = Maps[u], **PrivMap = PrivMaps[u];
|
|
|
|
|
|
|
|
*PrivMap = isl_union_map_apply_range(isl_union_map_copy(*Map),
|
2014-07-15 08:00:35 +08:00
|
|
|
isl_union_map_copy(TC_RED));
|
2014-06-21 00:37:11 +08:00
|
|
|
*PrivMap = isl_union_map_union(
|
2017-02-01 17:31:42 +08:00
|
|
|
*PrivMap, isl_union_map_apply_range(isl_union_map_copy(TC_RED),
|
|
|
|
isl_union_map_copy(*Map)));
|
2014-06-21 00:37:11 +08:00
|
|
|
|
|
|
|
*Map = isl_union_map_union(*Map, *PrivMap);
|
|
|
|
}
|
|
|
|
|
2014-07-15 08:00:35 +08:00
|
|
|
isl_union_set_free(Universe);
|
2014-06-21 00:37:11 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 22:45:48 +08:00
|
|
|
static __isl_give isl_union_flow *buildFlow(__isl_keep isl_union_map *Snk,
|
|
|
|
__isl_keep isl_union_map *Src,
|
|
|
|
__isl_keep isl_union_map *MaySrc,
|
|
|
|
__isl_keep isl_schedule *Schedule) {
|
|
|
|
isl_union_access_info *AI;
|
|
|
|
|
|
|
|
AI = isl_union_access_info_from_sink(isl_union_map_copy(Snk));
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
if (MaySrc)
|
|
|
|
AI = isl_union_access_info_set_may_source(AI, isl_union_map_copy(MaySrc));
|
2016-02-20 22:45:48 +08:00
|
|
|
if (Src)
|
|
|
|
AI = isl_union_access_info_set_must_source(AI, isl_union_map_copy(Src));
|
|
|
|
AI = isl_union_access_info_set_schedule(AI, isl_schedule_copy(Schedule));
|
2016-02-27 01:05:24 +08:00
|
|
|
auto Flow = isl_union_access_info_compute_flow(AI);
|
|
|
|
DEBUG(if (!Flow) dbgs() << "last error: "
|
|
|
|
<< isl_ctx_last_error(isl_schedule_get_ctx(Schedule))
|
|
|
|
<< '\n';);
|
|
|
|
return Flow;
|
2016-02-20 22:45:48 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 06:23:12 +08:00
|
|
|
/// Compute exact WAR dependences
|
|
|
|
/// We need exact WAR dependences. That is, if there are
|
|
|
|
/// dependences of the form:
|
|
|
|
/// must-W2 (sink) <- must-W1 (sink) <- R (source)
|
|
|
|
/// We wish to generate *ONLY*:
|
|
|
|
/// { R -> W1 },
|
|
|
|
/// NOT:
|
|
|
|
/// { R -> W2, R -> W1 }
|
|
|
|
///
|
|
|
|
/// However, in the case of may-writes, we do *not* wish to allow
|
|
|
|
/// may-writes to block must-writes. This makes sense, since perhaps the
|
|
|
|
/// may-write will not happen. In that case, the exact dependence will
|
|
|
|
/// be the (read -> must-write).
|
|
|
|
/// Example:
|
|
|
|
/// must-W2 (sink) <- may-W1 (sink) <- R (source)
|
|
|
|
/// We wish to generate:
|
|
|
|
/// { R-> W1, R -> W2 }
|
|
|
|
///
|
|
|
|
/// We use the fact that may dependences are not allowed to flow
|
|
|
|
/// through a must source. That way, reads will be stopped by intermediate
|
|
|
|
/// must-writes.
|
|
|
|
/// However, may-sources may not interfere with one another. Hence, reads
|
|
|
|
/// will not block each other from generating dependences.
|
|
|
|
///
|
|
|
|
/// Write (Sink) <- MustWrite (Must-Source) <- Read (MaySource) is
|
|
|
|
/// present, then the dependence
|
|
|
|
/// { Write <- Read }
|
|
|
|
/// is not tracked.
|
|
|
|
///
|
|
|
|
/// We would like to specify the Must-Write as kills, source as Read
|
|
|
|
/// and sink as Write.
|
|
|
|
/// ISL does not have the functionality currently to support "kills".
|
|
|
|
/// Use the Must-Source as a way to specify "kills".
|
|
|
|
/// The drawback is that we will have both
|
|
|
|
/// { Write <- MustWrite, Write <- Read }
|
|
|
|
///
|
|
|
|
/// We need to filter this to track only { Write <- Read }.
|
|
|
|
///
|
|
|
|
/// Filtering { Write <- Read } from WAROverestimated:
|
|
|
|
/// --------------------------------------------------
|
|
|
|
/// isl_union_flow_get_full_may_dependence gives us dependences of the form
|
|
|
|
/// WAROverestimated = { Read+MustWrite -> [Write -> MemoryAccess]}
|
|
|
|
///
|
|
|
|
/// We need to intersect the domain with Read to get only
|
|
|
|
/// Read dependences.
|
|
|
|
/// Read = { Read -> MemoryAccess }
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// 1. Construct:
|
|
|
|
/// WARMemAccesses = { Read+Write -> [Read+Write -> MemoryAccess] }
|
|
|
|
/// This takes a Read+Write from WAROverestimated and maps it to the
|
|
|
|
/// corresponding wrapped memory access from WAROverestimated.
|
|
|
|
///
|
|
|
|
/// 2. Apply WARMemAcesses to the domain of WAR Overestimated to give:
|
|
|
|
/// WAR = { [Read+Write -> MemoryAccess] -> [Write -> MemoryAccess] }
|
|
|
|
///
|
|
|
|
/// WAR is in a state where we can intersect with Read, since they
|
|
|
|
/// have the same structure.
|
|
|
|
///
|
|
|
|
/// 3. Intersect this with a wrapped Read. Read is wrapped
|
|
|
|
/// to ensure the domains look the same.
|
|
|
|
/// WAR = WAR \intersect (wrapped Read)
|
|
|
|
/// WAR = { [Read -> MemoryAccesss] -> [Write -> MemoryAccess] }
|
|
|
|
///
|
|
|
|
/// 4. Project out the memory access in the domain to get
|
|
|
|
/// WAR = { Read -> Write }
|
|
|
|
static isl_union_map *buildWAR(isl_union_map *Write, isl_union_map *MustWrite,
|
|
|
|
isl_union_map *Read, isl_schedule *Schedule) {
|
|
|
|
isl_union_flow *Flow = buildFlow(Write, MustWrite, Read, Schedule);
|
|
|
|
auto *WAROverestimated = isl_union_flow_get_full_may_dependence(Flow);
|
|
|
|
|
|
|
|
// 1. Constructing WARMemAccesses
|
|
|
|
// WarMemAccesses = { Read+Write -> [Write -> MemAccess] }
|
|
|
|
// Range factor of range product
|
|
|
|
// { Read+Write -> MemAcesss }
|
|
|
|
// Domain projection
|
|
|
|
// { [Read+Write -> MemAccess] -> Read+Write }
|
|
|
|
// Reverse
|
|
|
|
// { Read+Write -> [Read+Write -> MemAccess] }
|
|
|
|
auto WARMemAccesses = isl_union_map_copy(WAROverestimated);
|
|
|
|
WARMemAccesses = isl_union_map_range_factor_range(WAROverestimated);
|
|
|
|
WARMemAccesses = isl_union_map_domain_map(WARMemAccesses);
|
|
|
|
WARMemAccesses = isl_union_map_reverse(WARMemAccesses);
|
|
|
|
|
|
|
|
// 2. Apply to get domain tagged with memory accesses
|
|
|
|
isl_union_map *WAR =
|
|
|
|
isl_union_map_apply_domain(WAROverestimated, WARMemAccesses);
|
|
|
|
|
|
|
|
// 3. Intersect with Read to extract only reads
|
|
|
|
auto ReadWrapped = isl_union_map_wrap(isl_union_map_copy(Read));
|
|
|
|
WAR = isl_union_map_intersect_domain(WAR, ReadWrapped);
|
|
|
|
|
|
|
|
// 4. Project out memory accesses to get usual style dependences
|
|
|
|
WAR = isl_union_map_range_factor_domain(WAR);
|
|
|
|
WAR = isl_union_map_domain_factor_domain(WAR);
|
|
|
|
|
|
|
|
isl_union_flow_free(Flow);
|
|
|
|
return WAR;
|
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
void Dependences::calculateDependences(Scop &S) {
|
2017-03-21 19:54:08 +08:00
|
|
|
isl_union_map *Read, *MustWrite, *MayWrite, *ReductionTagMap;
|
2015-07-14 17:33:13 +08:00
|
|
|
isl_schedule *Schedule;
|
2017-02-23 23:40:52 +08:00
|
|
|
isl_union_set *TaggedStmtDomain;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2014-03-19 02:05:38 +08:00
|
|
|
DEBUG(dbgs() << "Scop: \n" << S << "\n");
|
2013-07-31 22:35:17 +08:00
|
|
|
|
2017-03-21 19:54:08 +08:00
|
|
|
collectInfo(S, Read, MustWrite, MayWrite, ReductionTagMap, TaggedStmtDomain,
|
2017-02-23 23:40:52 +08:00
|
|
|
Level);
|
2014-06-27 02:38:08 +08:00
|
|
|
|
2017-02-21 23:38:31 +08:00
|
|
|
bool HasReductions = !isl_union_map_is_empty(ReductionTagMap);
|
2016-09-03 07:29:38 +08:00
|
|
|
|
2016-02-27 01:05:24 +08:00
|
|
|
DEBUG(dbgs() << "Read: " << Read << '\n';
|
2017-03-21 19:54:08 +08:00
|
|
|
dbgs() << "MustWrite: " << MustWrite << '\n';
|
2016-02-27 01:05:24 +08:00
|
|
|
dbgs() << "MayWrite: " << MayWrite << '\n';
|
2017-02-21 23:38:31 +08:00
|
|
|
dbgs() << "ReductionTagMap: " << ReductionTagMap << '\n';
|
2017-02-23 23:40:52 +08:00
|
|
|
dbgs() << "TaggedStmtDomain: " << TaggedStmtDomain << '\n';);
|
2016-02-27 01:05:24 +08:00
|
|
|
|
2017-08-07 05:42:38 +08:00
|
|
|
Schedule = S.getScheduleTree().release();
|
2017-02-19 00:41:28 +08:00
|
|
|
|
2016-09-03 07:29:38 +08:00
|
|
|
if (!HasReductions) {
|
2017-02-21 23:38:31 +08:00
|
|
|
isl_union_map_free(ReductionTagMap);
|
2016-02-27 01:05:24 +08:00
|
|
|
// Tag the schedule tree if we want fine-grain dependence info
|
2016-03-03 16:15:33 +08:00
|
|
|
if (Level > AL_Statement) {
|
2017-02-23 23:40:46 +08:00
|
|
|
auto TaggedMap =
|
2017-02-23 23:40:52 +08:00
|
|
|
isl_union_set_unwrap(isl_union_set_copy(TaggedStmtDomain));
|
2016-02-27 01:05:24 +08:00
|
|
|
auto Tags = isl_union_map_domain_map_union_pw_multi_aff(TaggedMap);
|
|
|
|
Schedule = isl_schedule_pullback_union_pw_multi_aff(Schedule, Tags);
|
|
|
|
}
|
2015-07-14 17:33:13 +08:00
|
|
|
} else {
|
2017-02-21 23:38:31 +08:00
|
|
|
isl_union_map *IdentityMap;
|
2017-02-19 00:39:04 +08:00
|
|
|
isl_union_pw_multi_aff *ReductionTags, *IdentityTags, *Tags;
|
|
|
|
|
2017-02-21 23:38:31 +08:00
|
|
|
// Extract Reduction tags from the combined access domains in the given
|
|
|
|
// SCoP. The result is a map that maps each tagged element in the domain to
|
|
|
|
// the memory location it accesses. ReductionTags = {[Stmt[i] ->
|
|
|
|
// Array[f(i)]] -> Stmt[i] }
|
|
|
|
ReductionTags =
|
|
|
|
isl_union_map_domain_map_union_pw_multi_aff(ReductionTagMap);
|
2017-02-19 00:39:04 +08:00
|
|
|
|
|
|
|
// Compute an identity map from each statement in domain to itself.
|
|
|
|
// IdentityTags = { [Stmt[i] -> Stmt[i] }
|
2017-02-23 23:40:52 +08:00
|
|
|
IdentityMap = isl_union_set_identity(isl_union_set_copy(TaggedStmtDomain));
|
2017-02-19 00:39:04 +08:00
|
|
|
IdentityTags = isl_union_pw_multi_aff_from_union_map(IdentityMap);
|
|
|
|
|
|
|
|
Tags = isl_union_pw_multi_aff_union_add(ReductionTags, IdentityTags);
|
|
|
|
|
|
|
|
// By pulling back Tags from Schedule, we have a schedule tree that can
|
|
|
|
// be used to compute normal dependences, as well as 'tagged' reduction
|
|
|
|
// dependences.
|
|
|
|
Schedule = isl_schedule_pullback_union_pw_multi_aff(Schedule, Tags);
|
2015-07-14 17:33:13 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-10-10 19:45:59 +08:00
|
|
|
DEBUG(dbgs() << "Read: " << Read << "\n";
|
2017-03-21 19:54:08 +08:00
|
|
|
dbgs() << "MustWrite: " << MustWrite << "\n";
|
2016-10-10 19:45:59 +08:00
|
|
|
dbgs() << "MayWrite: " << MayWrite << "\n";
|
|
|
|
dbgs() << "Schedule: " << Schedule << "\n");
|
|
|
|
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
isl_union_map *StrictWAW = nullptr;
|
2016-10-10 19:45:54 +08:00
|
|
|
{
|
|
|
|
IslMaxOperationsGuard MaxOpGuard(IslCtx.get(), OptComputeOut);
|
2016-07-01 04:42:58 +08:00
|
|
|
|
2016-10-10 19:45:54 +08:00
|
|
|
RAW = WAW = WAR = RED = nullptr;
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
isl_union_map *Write = isl_union_map_union(isl_union_map_copy(MustWrite),
|
|
|
|
isl_union_map_copy(MayWrite));
|
|
|
|
|
|
|
|
// We are interested in detecting reductions that do not have intermediate
|
|
|
|
// computations that are captured by other statements.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
// void f(int *A, int *B) {
|
|
|
|
// for(int i = 0; i <= 100; i++) {
|
|
|
|
//
|
|
|
|
// *-WAR (S0[i] -> S0[i + 1] 0 <= i <= 100)------------*
|
|
|
|
// | |
|
|
|
|
// *-WAW (S0[i] -> S0[i + 1] 0 <= i <= 100)------------*
|
|
|
|
// | |
|
|
|
|
// v |
|
|
|
|
// S0: *A += i; >------------------*-----------------------*
|
|
|
|
// |
|
|
|
|
// if (i >= 98) { WAR (S0[i] -> S1[i]) 98 <= i <= 100
|
|
|
|
// |
|
|
|
|
// S1: *B = *A; <--------------*
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// S0[0 <= i <= 100] has a reduction. However, the values in
|
|
|
|
// S0[98 <= i <= 100] is captured in S1[98 <= i <= 100].
|
|
|
|
// Since we allow free reordering on our reduction dependences, we need to
|
|
|
|
// remove all instances of a reduction statement that have data dependences
|
2017-06-08 20:06:15 +08:00
|
|
|
// originating from them.
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
// In the case of the example, we need to remove S0[98 <= i <= 100] from
|
|
|
|
// our reduction dependences.
|
|
|
|
//
|
|
|
|
// When we build up the WAW dependences that are used to detect reductions,
|
|
|
|
// we consider only **Writes that have no intermediate Reads**.
|
|
|
|
//
|
|
|
|
// `isl_union_flow_get_must_dependence` gives us dependences of the form:
|
|
|
|
// (sink <- must_source).
|
|
|
|
//
|
|
|
|
// It *will not give* dependences of the form:
|
|
|
|
// 1. (sink <- ... <- may_source <- ... <- must_source)
|
|
|
|
// 2. (sink <- ... <- must_source <- ... <- must_source)
|
|
|
|
//
|
|
|
|
// For a detailed reference on ISL's flow analysis, see:
|
|
|
|
// "Presburger Formulas and Polyhedral Compilation" - Approximate Dataflow
|
|
|
|
// Analysis.
|
|
|
|
//
|
|
|
|
// Since we set "Write" as a must-source, "Read" as a may-source, and ask
|
|
|
|
// for must dependences, we get all Writes to Writes that **do not flow
|
|
|
|
// through a Read**.
|
|
|
|
//
|
|
|
|
// ScopInfo::checkForReductions makes sure that if something captures
|
|
|
|
// the reduction variable in the same basic block, then it is rejected
|
|
|
|
// before it is even handed here. This makes sure that there is exactly
|
|
|
|
// one read and one write to a reduction variable in a Statement.
|
|
|
|
// Example:
|
|
|
|
// void f(int *sum, int A[N], int B[N]) {
|
|
|
|
// for (int i = 0; i < N; i++) {
|
|
|
|
// *sum += A[i]; < the store and the load is not tagged as a
|
2017-06-08 20:06:15 +08:00
|
|
|
// B[i] = *sum; < reduction-like access due to the overlap.
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
isl_union_flow *Flow = buildFlow(Write, Write, Read, Schedule);
|
|
|
|
StrictWAW = isl_union_flow_get_must_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
2013-07-31 22:35:17 +08:00
|
|
|
|
2016-10-10 19:45:54 +08:00
|
|
|
if (OptAnalysisType == VALUE_BASED_ANALYSIS) {
|
2017-03-21 19:54:08 +08:00
|
|
|
Flow = buildFlow(Read, MustWrite, MayWrite, Schedule);
|
2017-03-17 21:26:10 +08:00
|
|
|
RAW = isl_union_flow_get_may_dependence(Flow);
|
2016-10-10 19:45:54 +08:00
|
|
|
isl_union_flow_free(Flow);
|
2015-04-21 16:47:29 +08:00
|
|
|
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
|
|
|
|
WAW = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
2015-04-21 16:47:29 +08:00
|
|
|
|
2017-04-25 06:23:12 +08:00
|
|
|
WAR = buildWAR(Write, MustWrite, Read, Schedule);
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
isl_union_map_free(Write);
|
2016-10-10 19:45:54 +08:00
|
|
|
isl_schedule_free(Schedule);
|
|
|
|
} else {
|
|
|
|
isl_union_flow *Flow;
|
2016-02-20 22:45:48 +08:00
|
|
|
|
2016-10-10 19:45:54 +08:00
|
|
|
Flow = buildFlow(Read, nullptr, Write, Schedule);
|
|
|
|
RAW = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
2015-04-21 16:47:29 +08:00
|
|
|
|
2016-10-10 19:45:54 +08:00
|
|
|
Flow = buildFlow(Write, nullptr, Read, Schedule);
|
|
|
|
WAR = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
2015-04-21 16:47:29 +08:00
|
|
|
|
2016-10-10 19:45:54 +08:00
|
|
|
Flow = buildFlow(Write, nullptr, Write, Schedule);
|
|
|
|
WAW = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
|
2017-03-21 19:54:08 +08:00
|
|
|
isl_union_map_free(Write);
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
isl_schedule_free(Schedule);
|
2016-10-10 19:45:54 +08:00
|
|
|
}
|
2015-04-21 16:47:29 +08:00
|
|
|
|
2017-03-21 19:54:08 +08:00
|
|
|
isl_union_map_free(MustWrite);
|
2016-10-10 19:45:54 +08:00
|
|
|
isl_union_map_free(MayWrite);
|
|
|
|
isl_union_map_free(Read);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-10-10 19:45:54 +08:00
|
|
|
RAW = isl_union_map_coalesce(RAW);
|
|
|
|
WAW = isl_union_map_coalesce(WAW);
|
|
|
|
WAR = isl_union_map_coalesce(WAR);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-10-10 19:45:54 +08:00
|
|
|
// End of max_operations scope.
|
|
|
|
}
|
2013-07-31 22:35:17 +08:00
|
|
|
|
2016-02-17 23:49:21 +08:00
|
|
|
if (isl_ctx_last_error(IslCtx.get()) == isl_error_quota) {
|
2014-01-27 03:38:34 +08:00
|
|
|
isl_union_map_free(RAW);
|
|
|
|
isl_union_map_free(WAW);
|
|
|
|
isl_union_map_free(WAR);
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
isl_union_map_free(StrictWAW);
|
|
|
|
RAW = WAW = WAR = StrictWAW = nullptr;
|
2016-02-17 23:49:21 +08:00
|
|
|
isl_ctx_reset_error(IslCtx.get());
|
2014-01-27 03:38:34 +08:00
|
|
|
}
|
|
|
|
|
2016-09-03 07:29:38 +08:00
|
|
|
// Drop out early, as the remaining computations are only needed for
|
|
|
|
// reduction dependences or dependences that are finer than statement
|
|
|
|
// level dependences.
|
|
|
|
if (!HasReductions && Level == AL_Statement) {
|
2017-03-17 04:06:49 +08:00
|
|
|
RED = isl_union_map_empty(isl_union_map_get_space(RAW));
|
2017-02-23 23:40:52 +08:00
|
|
|
TC_RED = isl_union_map_empty(isl_union_set_get_space(TaggedStmtDomain));
|
|
|
|
isl_union_set_free(TaggedStmtDomain);
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
isl_union_map_free(StrictWAW);
|
2016-09-03 07:29:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-27 02:38:08 +08:00
|
|
|
isl_union_map *STMT_RAW, *STMT_WAW, *STMT_WAR;
|
|
|
|
STMT_RAW = isl_union_map_intersect_domain(
|
2017-02-23 23:40:52 +08:00
|
|
|
isl_union_map_copy(RAW), isl_union_set_copy(TaggedStmtDomain));
|
2014-06-27 02:38:08 +08:00
|
|
|
STMT_WAW = isl_union_map_intersect_domain(
|
2017-02-23 23:40:52 +08:00
|
|
|
isl_union_map_copy(WAW), isl_union_set_copy(TaggedStmtDomain));
|
|
|
|
STMT_WAR =
|
|
|
|
isl_union_map_intersect_domain(isl_union_map_copy(WAR), TaggedStmtDomain);
|
2014-10-23 07:00:03 +08:00
|
|
|
DEBUG({
|
|
|
|
dbgs() << "Wrapped Dependences:\n";
|
2015-03-05 08:43:48 +08:00
|
|
|
dump();
|
2014-10-23 07:00:03 +08:00
|
|
|
dbgs() << "\n";
|
|
|
|
});
|
2014-06-27 02:38:08 +08:00
|
|
|
|
2014-06-21 00:37:11 +08:00
|
|
|
// To handle reduction dependences we proceed as follows:
|
|
|
|
// 1) Aggregate all possible reduction dependences, namely all self
|
|
|
|
// dependences on reduction like statements.
|
|
|
|
// 2) Intersect them with the actual RAW & WAW dependences to the get the
|
|
|
|
// actual reduction dependences. This will ensure the load/store memory
|
|
|
|
// addresses were __identical__ in the two iterations of the statement.
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
// 3) Relax the original RAW, WAW and WAR dependences by subtracting the
|
|
|
|
// actual reduction dependences. Binary reductions (sum += A[i]) cause
|
|
|
|
// the same, RAW, WAW and WAR dependences.
|
2014-06-21 00:37:11 +08:00
|
|
|
// 4) Add the privatization dependences which are widened versions of
|
|
|
|
// already present dependences. They model the effect of manual
|
|
|
|
// privatization at the outermost possible place (namely after the last
|
|
|
|
// write and before the first access to a reduction location).
|
|
|
|
|
|
|
|
// Step 1)
|
|
|
|
RED = isl_union_map_empty(isl_union_map_get_space(RAW));
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
|
|
|
for (MemoryAccess *MA : Stmt) {
|
2014-06-21 00:58:12 +08:00
|
|
|
if (!MA->isReductionLike())
|
|
|
|
continue;
|
2017-07-23 12:08:38 +08:00
|
|
|
isl_set *AccDomW = isl_map_wrap(MA->getAccessRelation().release());
|
2014-06-21 00:58:12 +08:00
|
|
|
isl_map *Identity =
|
2014-06-27 02:44:14 +08:00
|
|
|
isl_map_from_domain_and_range(isl_set_copy(AccDomW), AccDomW);
|
2014-06-21 00:58:12 +08:00
|
|
|
RED = isl_union_map_add_map(RED, Identity);
|
|
|
|
}
|
2014-06-21 00:37:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Step 2)
|
|
|
|
RED = isl_union_map_intersect(RED, isl_union_map_copy(RAW));
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
RED = isl_union_map_intersect(RED, StrictWAW);
|
2014-06-21 00:37:11 +08:00
|
|
|
|
|
|
|
if (!isl_union_map_is_empty(RED)) {
|
|
|
|
|
|
|
|
// Step 3)
|
|
|
|
RAW = isl_union_map_subtract(RAW, isl_union_map_copy(RED));
|
|
|
|
WAW = isl_union_map_subtract(WAW, isl_union_map_copy(RED));
|
[Polly] [DependenceInfo] change WAR, WAW generation to correct semantics
= Change of WAR, WAW generation: =
- `buildFlow(Sink, MustSource, MaySource, Sink)` treates any flow of the form
`sink <- may source <- must source` as a *may* dependence.
- we used to call:
```lang=cpp, name=old-flow-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This caused some WAW dependences to be treated as WAR dependences.
- Incorrect semantics.
- Now, we call WAR and WAW correctly.
== Correct WAW: ==
```lang=cpp, name=new-waw-call.cpp
Flow = buildFlow(Write, MustWrite, MayWrite, Schedule);
WAW = isl_union_flow_get_may_dependence(Flow);
isl_union_flow_free(Flow);
```
== Correct WAR: ==
```lang=cpp, name=new-war-call.cpp
Flow = buildFlow(Write, Read, MustaWrite, Schedule);
WAR = isl_union_flow_get_must_dependence(Flow);
isl_union_flow_free(Flow);
```
- We want the "shortest" WAR possible (exact dependences).
- We mark all the *must-writes* as may-source, reads as must-souce.
- Then, we ask for *must* dependence.
- This removes all the reads that flow through a *must-write*
before reaching a sink.
- Note that we only block ealier writes with *must-writes*. This is
intuitively correct, as we do not want may-writes to block
must-writes.
- Leaves us with direct (R -> W).
- This affects reduction generation since RED is built using WAW and WAR.
= New StrictWAW for Reductions: =
- We used to call:
```lang=cpp,name=old-waw-war-call.cpp
Flow = buildFlow(MustWrite, MustWrite, Read, Schedule);
WAW = isl_union_flow_get_must_dependence(Flow);
WAR = isl_union_flow_get_may_dependence(Flow);
```
- This *is* the right model of WAW we need for reductions, just not in general.
- Reductions need to track only *strict* WAW, without any interfering reductions.
= Explanation: Why the new WAR dependences in tests are correct: =
- We no longer set WAR = WAR - WAW
- Hence, we will have WAR dependences that were originally removed.
- These may look incorrect, but in fact make sense.
== Code: ==
```lang=llvm, name=new-war-dependence.ll
; void manyreductions(long *A) {
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S0: *A += 42;
;
; for (long i = 0; i < 1024; i++)
; for (long j = 0; j < 1024; j++)
; S1: *A += 42;
;
```
=== WAR dependence: ===
{ S0[1023, 1023] -> S1[0, 0] }
- Between `S0[1023, 1023]` and `S1[0, 0]`, we will have the dependences:
```lang=cpp, name=dependence-incorrect, counterexample
S0[1023, 1023]:
*-- tmp = *A (load0)--*
WAR 2 add = tmp + 42 |
*-> *A = add (store0) |
WAR 1
S1[0, 0]: |
tmp = *A (load1) |
add = tmp + 42 |
A = add (store1)<-*
```
- One may assume that WAR2 *hides* WAR1 (since store0 happens before
store1). However, within a statement, Polly has no idea about the
ordering of loads and stores.
- Hence, according to Polly, the code may have looked like this:
```lang=cpp, name=dependence-correct
S0[1023, 1023]:
A = add (store0)
tmp = A (load0) ---*
add = A + 42 |
WAR 1
S1[0, 0]: |
tmp = A (load1) |
add = A + 42 |
A = add (store1) <-*
```
- So, Polly generates (correct) WAR dependences. It does not make sense
to remove these dependences, since they are correct with respect to
Polly's model.
Reviewers: grosser, Meinersbur
tags: #polly
Differential revision: https://reviews.llvm.org/D31386
llvm-svn: 299429
2017-04-04 21:08:23 +08:00
|
|
|
WAR = isl_union_map_subtract(WAR, isl_union_map_copy(RED));
|
2014-06-21 00:37:11 +08:00
|
|
|
|
|
|
|
// Step 4)
|
|
|
|
addPrivatizationDependences();
|
2018-04-05 02:08:13 +08:00
|
|
|
} else
|
|
|
|
TC_RED = isl_union_map_empty(isl_union_map_get_space(RED));
|
2014-06-21 00:37:11 +08:00
|
|
|
|
2014-10-23 07:00:03 +08:00
|
|
|
DEBUG({
|
|
|
|
dbgs() << "Final Wrapped Dependences:\n";
|
2015-03-05 08:43:48 +08:00
|
|
|
dump();
|
2014-10-23 07:00:03 +08:00
|
|
|
dbgs() << "\n";
|
|
|
|
});
|
2014-06-27 02:44:14 +08:00
|
|
|
|
2014-08-01 16:17:19 +08:00
|
|
|
// RED_SIN is used to collect all reduction dependences again after we
|
|
|
|
// split them according to the causing memory accesses. The current assumption
|
|
|
|
// is that our method of splitting will not have any leftovers. In the end
|
|
|
|
// we validate this assumption until we have more confidence in this method.
|
|
|
|
isl_union_map *RED_SIN = isl_union_map_empty(isl_union_map_get_space(RAW));
|
|
|
|
|
|
|
|
// For each reduction like memory access, check if there are reduction
|
|
|
|
// dependences with the access relation of the memory access as a domain
|
|
|
|
// (wrapped space!). If so these dependences are caused by this memory access.
|
|
|
|
// We then move this portion of reduction dependences back to the statement ->
|
|
|
|
// statement space and add a mapping from the memory access to these
|
|
|
|
// dependences.
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
|
|
|
for (MemoryAccess *MA : Stmt) {
|
2014-08-01 16:17:19 +08:00
|
|
|
if (!MA->isReductionLike())
|
|
|
|
continue;
|
|
|
|
|
2017-07-23 12:08:38 +08:00
|
|
|
isl_set *AccDomW = isl_map_wrap(MA->getAccessRelation().release());
|
2014-08-01 16:17:19 +08:00
|
|
|
isl_union_map *AccRedDepU = isl_union_map_intersect_domain(
|
|
|
|
isl_union_map_copy(TC_RED), isl_union_set_from_set(AccDomW));
|
2016-09-08 22:08:01 +08:00
|
|
|
if (isl_union_map_is_empty(AccRedDepU)) {
|
|
|
|
isl_union_map_free(AccRedDepU);
|
2014-08-01 16:17:19 +08:00
|
|
|
continue;
|
2016-09-08 22:08:01 +08:00
|
|
|
}
|
2014-08-01 16:17:19 +08:00
|
|
|
|
|
|
|
isl_map *AccRedDep = isl_map_from_union_map(AccRedDepU);
|
|
|
|
RED_SIN = isl_union_map_add_map(RED_SIN, isl_map_copy(AccRedDep));
|
|
|
|
AccRedDep = isl_map_zip(AccRedDep);
|
|
|
|
AccRedDep = isl_set_unwrap(isl_map_domain(AccRedDep));
|
|
|
|
setReductionDependences(MA, AccRedDep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(isl_union_map_is_equal(RED_SIN, TC_RED) &&
|
|
|
|
"Intersecting the reduction dependence domain with the wrapped access "
|
|
|
|
"relation is not enough, we need to loosen the access relation also");
|
|
|
|
isl_union_map_free(RED_SIN);
|
|
|
|
|
2014-06-27 02:44:14 +08:00
|
|
|
RAW = isl_union_map_zip(RAW);
|
|
|
|
WAW = isl_union_map_zip(WAW);
|
|
|
|
WAR = isl_union_map_zip(WAR);
|
|
|
|
RED = isl_union_map_zip(RED);
|
2014-07-15 08:00:35 +08:00
|
|
|
TC_RED = isl_union_map_zip(TC_RED);
|
2014-06-27 02:44:14 +08:00
|
|
|
|
2014-10-23 07:00:03 +08:00
|
|
|
DEBUG({
|
|
|
|
dbgs() << "Zipped Dependences:\n";
|
2015-03-05 08:43:48 +08:00
|
|
|
dump();
|
2014-10-23 07:00:03 +08:00
|
|
|
dbgs() << "\n";
|
|
|
|
});
|
2014-06-27 02:44:14 +08:00
|
|
|
|
|
|
|
RAW = isl_union_set_unwrap(isl_union_map_domain(RAW));
|
|
|
|
WAW = isl_union_set_unwrap(isl_union_map_domain(WAW));
|
|
|
|
WAR = isl_union_set_unwrap(isl_union_map_domain(WAR));
|
|
|
|
RED = isl_union_set_unwrap(isl_union_map_domain(RED));
|
2014-07-15 08:00:35 +08:00
|
|
|
TC_RED = isl_union_set_unwrap(isl_union_map_domain(TC_RED));
|
2014-06-27 02:44:14 +08:00
|
|
|
|
2014-10-23 07:00:03 +08:00
|
|
|
DEBUG({
|
|
|
|
dbgs() << "Unwrapped Dependences:\n";
|
2015-03-05 08:43:48 +08:00
|
|
|
dump();
|
2014-10-23 07:00:03 +08:00
|
|
|
dbgs() << "\n";
|
|
|
|
});
|
2014-06-27 02:44:14 +08:00
|
|
|
|
|
|
|
RAW = isl_union_map_union(RAW, STMT_RAW);
|
|
|
|
WAW = isl_union_map_union(WAW, STMT_WAW);
|
|
|
|
WAR = isl_union_map_union(WAR, STMT_WAR);
|
|
|
|
|
2014-06-21 00:37:11 +08:00
|
|
|
RAW = isl_union_map_coalesce(RAW);
|
|
|
|
WAW = isl_union_map_coalesce(WAW);
|
|
|
|
WAR = isl_union_map_coalesce(WAR);
|
|
|
|
RED = isl_union_map_coalesce(RED);
|
2014-07-15 08:00:35 +08:00
|
|
|
TC_RED = isl_union_map_coalesce(TC_RED);
|
2014-06-21 00:37:11 +08:00
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
DEBUG(dump());
|
2012-03-08 01:42:45 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-04-21 19:37:25 +08:00
|
|
|
bool Dependences::isValidSchedule(Scop &S,
|
2015-04-21 19:42:01 +08:00
|
|
|
StatementToIslMapTy *NewSchedule) const {
|
2011-04-29 14:27:02 +08:00
|
|
|
if (LegalityCheckDisabled)
|
|
|
|
return true;
|
|
|
|
|
2014-06-27 04:24:17 +08:00
|
|
|
isl_union_map *Dependences = getDependences(TYPE_RAW | TYPE_WAW | TYPE_WAR);
|
2017-08-07 04:11:59 +08:00
|
|
|
isl_space *Space = S.getParamSpace().release();
|
2015-04-21 19:37:25 +08:00
|
|
|
isl_union_map *Schedule = isl_union_map_empty(Space);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-04-21 19:37:25 +08:00
|
|
|
isl_space *ScheduleSpace = nullptr;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
2012-03-08 00:10:40 +08:00
|
|
|
isl_map *StmtScat;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
if (NewSchedule->find(&Stmt) == NewSchedule->end())
|
2017-08-07 01:45:28 +08:00
|
|
|
StmtScat = Stmt.getSchedule().release();
|
2011-04-29 14:27:02 +08:00
|
|
|
else
|
2015-05-27 13:16:57 +08:00
|
|
|
StmtScat = isl_map_copy((*NewSchedule)[&Stmt]);
|
2016-09-14 14:26:09 +08:00
|
|
|
assert(StmtScat &&
|
|
|
|
"Schedules that contain extension nodes require special handling.");
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-04-21 19:37:25 +08:00
|
|
|
if (!ScheduleSpace)
|
|
|
|
ScheduleSpace = isl_space_range(isl_map_get_space(StmtScat));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-04-21 19:37:25 +08:00
|
|
|
Schedule = isl_union_map_add_map(Schedule, StmtScat);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-02-05 20:27:22 +08:00
|
|
|
Dependences =
|
2015-04-21 19:37:25 +08:00
|
|
|
isl_union_map_apply_domain(Dependences, isl_union_map_copy(Schedule));
|
|
|
|
Dependences = isl_union_map_apply_range(Dependences, Schedule);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-04-21 19:37:25 +08:00
|
|
|
isl_set *Zero = isl_set_universe(isl_space_copy(ScheduleSpace));
|
2012-03-08 00:10:40 +08:00
|
|
|
for (unsigned i = 0; i < isl_set_dim(Zero, isl_dim_set); i++)
|
|
|
|
Zero = isl_set_fix_si(Zero, isl_dim_set, i, 0);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-03-08 00:10:40 +08:00
|
|
|
isl_union_set *UDeltas = isl_union_map_deltas(Dependences);
|
2015-04-21 19:37:25 +08:00
|
|
|
isl_set *Deltas = isl_union_set_extract_set(UDeltas, ScheduleSpace);
|
2012-03-08 00:10:40 +08:00
|
|
|
isl_union_set_free(UDeltas);
|
2011-08-20 19:11:25 +08:00
|
|
|
|
2012-03-08 00:10:40 +08:00
|
|
|
isl_map *NonPositive = isl_set_lex_le_set(Deltas, Zero);
|
|
|
|
bool IsValid = isl_map_is_empty(NonPositive);
|
|
|
|
isl_map_free(NonPositive);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-03-08 00:10:40 +08:00
|
|
|
return IsValid;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2014-07-28 11:46:28 +08:00
|
|
|
// Check if the current scheduling dimension is parallel.
|
|
|
|
//
|
|
|
|
// We check for parallelism by verifying that the loop does not carry any
|
|
|
|
// dependences.
|
|
|
|
//
|
|
|
|
// Parallelism test: if the distance is zero in all outer dimensions, then it
|
|
|
|
// has to be zero in the current dimension as well.
|
|
|
|
//
|
|
|
|
// Implementation: first, translate dependences into time space, then force
|
|
|
|
// outer dimensions to be equal. If the distance is zero in the current
|
|
|
|
// dimension, then the loop is parallel. The distance is zero in the current
|
|
|
|
// dimension if it is a subset of a map with equal values for the current
|
|
|
|
// dimension.
|
2015-03-05 08:43:48 +08:00
|
|
|
bool Dependences::isParallel(isl_union_map *Schedule, isl_union_map *Deps,
|
|
|
|
isl_pw_aff **MinDistancePtr) const {
|
2014-09-14 01:34:11 +08:00
|
|
|
isl_set *Deltas, *Distance;
|
|
|
|
isl_map *ScheduleDeps;
|
|
|
|
unsigned Dimension;
|
|
|
|
bool IsParallel;
|
2012-04-20 00:38:16 +08:00
|
|
|
|
2012-03-08 01:42:49 +08:00
|
|
|
Deps = isl_union_map_apply_range(Deps, isl_union_map_copy(Schedule));
|
2014-07-28 11:46:28 +08:00
|
|
|
Deps = isl_union_map_apply_domain(Deps, isl_union_map_copy(Schedule));
|
2014-04-16 04:14:57 +08:00
|
|
|
|
|
|
|
if (isl_union_map_is_empty(Deps)) {
|
|
|
|
isl_union_map_free(Deps);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-20 00:38:16 +08:00
|
|
|
ScheduleDeps = isl_map_from_union_map(Deps);
|
2014-07-28 11:46:28 +08:00
|
|
|
Dimension = isl_map_dim(ScheduleDeps, isl_dim_out) - 1;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2014-07-28 11:46:28 +08:00
|
|
|
for (unsigned i = 0; i < Dimension; i++)
|
|
|
|
ScheduleDeps = isl_map_equate(ScheduleDeps, isl_dim_out, i, isl_dim_in, i);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2014-09-14 01:34:11 +08:00
|
|
|
Deltas = isl_map_deltas(ScheduleDeps);
|
|
|
|
Distance = isl_set_universe(isl_set_get_space(Deltas));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2014-09-14 01:34:11 +08:00
|
|
|
// [0, ..., 0, +] - All zeros and last dimension larger than zero
|
|
|
|
for (unsigned i = 0; i < Dimension; i++)
|
|
|
|
Distance = isl_set_fix_si(Distance, isl_dim_set, i, 0);
|
|
|
|
|
|
|
|
Distance = isl_set_lower_bound_si(Distance, isl_dim_set, Dimension, 1);
|
|
|
|
Distance = isl_set_intersect(Distance, Deltas);
|
|
|
|
|
|
|
|
IsParallel = isl_set_is_empty(Distance);
|
|
|
|
if (IsParallel || !MinDistancePtr) {
|
|
|
|
isl_set_free(Distance);
|
|
|
|
return IsParallel;
|
|
|
|
}
|
2012-03-08 01:42:49 +08:00
|
|
|
|
2014-09-14 01:34:11 +08:00
|
|
|
Distance = isl_set_project_out(Distance, isl_dim_set, 0, Dimension);
|
|
|
|
Distance = isl_set_coalesce(Distance);
|
|
|
|
|
|
|
|
// This last step will compute a expression for the minimal value in the
|
|
|
|
// distance polyhedron Distance with regards to the first (outer most)
|
|
|
|
// dimension.
|
|
|
|
*MinDistancePtr = isl_pw_aff_coalesce(isl_set_dim_min(Distance, 0));
|
|
|
|
|
|
|
|
return false;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2014-06-14 02:00:22 +08:00
|
|
|
static void printDependencyMap(raw_ostream &OS, __isl_keep isl_union_map *DM) {
|
|
|
|
if (DM)
|
|
|
|
OS << DM << "\n";
|
2014-01-27 03:38:34 +08:00
|
|
|
else
|
|
|
|
OS << "n/a\n";
|
2014-06-14 02:00:22 +08:00
|
|
|
}
|
2014-01-27 03:38:34 +08:00
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
void Dependences::print(raw_ostream &OS) const {
|
2014-06-14 02:00:22 +08:00
|
|
|
OS << "\tRAW dependences:\n\t\t";
|
|
|
|
printDependencyMap(OS, RAW);
|
2014-01-27 03:38:34 +08:00
|
|
|
OS << "\tWAR dependences:\n\t\t";
|
2014-06-14 02:00:22 +08:00
|
|
|
printDependencyMap(OS, WAR);
|
2014-01-27 03:38:34 +08:00
|
|
|
OS << "\tWAW dependences:\n\t\t";
|
2014-06-14 02:00:22 +08:00
|
|
|
printDependencyMap(OS, WAW);
|
2014-06-21 00:37:11 +08:00
|
|
|
OS << "\tReduction dependences:\n\t\t";
|
|
|
|
printDependencyMap(OS, RED);
|
2014-07-15 08:00:35 +08:00
|
|
|
OS << "\tTransitive closure of reduction dependences:\n\t\t";
|
|
|
|
printDependencyMap(OS, TC_RED);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
void Dependences::dump() const { print(dbgs()); }
|
|
|
|
|
|
|
|
void Dependences::releaseMemory() {
|
2012-03-08 01:42:45 +08:00
|
|
|
isl_union_map_free(RAW);
|
|
|
|
isl_union_map_free(WAR);
|
|
|
|
isl_union_map_free(WAW);
|
2014-06-21 00:37:11 +08:00
|
|
|
isl_union_map_free(RED);
|
2014-07-15 08:00:35 +08:00
|
|
|
isl_union_map_free(TC_RED);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2014-07-15 08:00:35 +08:00
|
|
|
RED = RAW = WAR = WAW = TC_RED = nullptr;
|
2014-08-01 16:17:19 +08:00
|
|
|
|
|
|
|
for (auto &ReductionDeps : ReductionDependences)
|
|
|
|
isl_map_free(ReductionDeps.second);
|
|
|
|
ReductionDependences.clear();
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2016-04-10 05:55:23 +08:00
|
|
|
__isl_give isl_union_map *Dependences::getDependences(int Kinds) const {
|
2014-02-23 23:15:44 +08:00
|
|
|
assert(hasValidDependences() && "No valid dependences available");
|
2012-03-08 01:42:45 +08:00
|
|
|
isl_space *Space = isl_union_map_get_space(RAW);
|
|
|
|
isl_union_map *Deps = isl_union_map_empty(Space);
|
2011-05-07 03:52:09 +08:00
|
|
|
|
2012-03-08 01:42:45 +08:00
|
|
|
if (Kinds & TYPE_RAW)
|
|
|
|
Deps = isl_union_map_union(Deps, isl_union_map_copy(RAW));
|
2011-05-07 03:52:09 +08:00
|
|
|
|
2012-03-08 01:42:45 +08:00
|
|
|
if (Kinds & TYPE_WAR)
|
|
|
|
Deps = isl_union_map_union(Deps, isl_union_map_copy(WAR));
|
2011-05-07 03:52:09 +08:00
|
|
|
|
2012-03-08 01:42:45 +08:00
|
|
|
if (Kinds & TYPE_WAW)
|
|
|
|
Deps = isl_union_map_union(Deps, isl_union_map_copy(WAW));
|
2011-05-07 03:52:09 +08:00
|
|
|
|
2014-06-21 00:37:11 +08:00
|
|
|
if (Kinds & TYPE_RED)
|
|
|
|
Deps = isl_union_map_union(Deps, isl_union_map_copy(RED));
|
|
|
|
|
2014-07-15 08:00:35 +08:00
|
|
|
if (Kinds & TYPE_TC_RED)
|
|
|
|
Deps = isl_union_map_union(Deps, isl_union_map_copy(TC_RED));
|
|
|
|
|
2012-03-08 01:42:45 +08:00
|
|
|
Deps = isl_union_map_coalesce(Deps);
|
|
|
|
Deps = isl_union_map_detect_equalities(Deps);
|
|
|
|
return Deps;
|
2011-05-07 03:52:09 +08:00
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
bool Dependences::hasValidDependences() const {
|
2014-04-16 15:33:47 +08:00
|
|
|
return (RAW != nullptr) && (WAR != nullptr) && (WAW != nullptr);
|
2014-02-23 23:15:44 +08:00
|
|
|
}
|
|
|
|
|
2016-04-10 05:55:23 +08:00
|
|
|
__isl_give isl_map *
|
|
|
|
Dependences::getReductionDependences(MemoryAccess *MA) const {
|
2015-03-05 08:43:48 +08:00
|
|
|
return isl_map_copy(ReductionDependences.lookup(MA));
|
2014-08-01 16:17:19 +08:00
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
void Dependences::setReductionDependences(MemoryAccess *MA, isl_map *D) {
|
2014-08-01 16:17:19 +08:00
|
|
|
assert(ReductionDependences.count(MA) == 0 &&
|
|
|
|
"Reduction dependences set twice!");
|
|
|
|
ReductionDependences[MA] = D;
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:09:06 +08:00
|
|
|
const Dependences &
|
|
|
|
DependenceAnalysis::Result::getDependences(Dependences::AnalysisLevel Level) {
|
|
|
|
if (Dependences *d = D[Level].get())
|
|
|
|
return *d;
|
|
|
|
|
|
|
|
return recomputeDependences(Level);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Dependences &DependenceAnalysis::Result::recomputeDependences(
|
|
|
|
Dependences::AnalysisLevel Level) {
|
|
|
|
D[Level].reset(new Dependences(S.getSharedIslCtx(), Level));
|
|
|
|
D[Level]->calculateDependences(S);
|
|
|
|
return *D[Level];
|
|
|
|
}
|
|
|
|
|
|
|
|
DependenceAnalysis::Result
|
|
|
|
DependenceAnalysis::run(Scop &S, ScopAnalysisManager &SAM,
|
|
|
|
ScopStandardAnalysisResults &SAR) {
|
|
|
|
return {S, {}};
|
|
|
|
}
|
|
|
|
|
|
|
|
AnalysisKey DependenceAnalysis::Key;
|
|
|
|
|
|
|
|
PreservedAnalyses
|
|
|
|
DependenceInfoPrinterPass::run(Scop &S, ScopAnalysisManager &SAM,
|
|
|
|
ScopStandardAnalysisResults &SAR,
|
|
|
|
SPMUpdater &U) {
|
|
|
|
auto &DI = SAM.getResult<DependenceAnalysis>(S, SAR);
|
|
|
|
|
|
|
|
if (auto d = DI.D[OptAnalysisLevel].get()) {
|
|
|
|
d->print(OS);
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
2017-05-23 19:25:05 +08:00
|
|
|
// Otherwise create the dependences on-the-fly and print them
|
2017-05-23 18:09:06 +08:00
|
|
|
Dependences D(S.getSharedIslCtx(), OptAnalysisLevel);
|
|
|
|
D.calculateDependences(S);
|
|
|
|
D.print(OS);
|
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
2016-03-03 16:15:33 +08:00
|
|
|
const Dependences &
|
2016-11-24 05:59:33 +08:00
|
|
|
DependenceInfo::getDependences(Dependences::AnalysisLevel Level) {
|
2016-03-03 16:15:33 +08:00
|
|
|
if (Dependences *d = D[Level].get())
|
|
|
|
return *d;
|
|
|
|
|
|
|
|
return recomputeDependences(Level);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Dependences &
|
2016-11-24 05:59:33 +08:00
|
|
|
DependenceInfo::recomputeDependences(Dependences::AnalysisLevel Level) {
|
2016-03-03 16:15:33 +08:00
|
|
|
D[Level].reset(new Dependences(S->getSharedIslCtx(), Level));
|
|
|
|
D[Level]->calculateDependences(*S);
|
|
|
|
return *D[Level];
|
2015-03-05 08:43:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DependenceInfo::runOnScop(Scop &ScopVar) {
|
|
|
|
S = &ScopVar;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-02 14:33:33 +08:00
|
|
|
/// Print the dependences for the given SCoP to @p OS.
|
2016-03-03 16:15:33 +08:00
|
|
|
|
|
|
|
void polly::DependenceInfo::printScop(raw_ostream &OS, Scop &S) const {
|
|
|
|
if (auto d = D[OptAnalysisLevel].get()) {
|
|
|
|
d->print(OS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise create the dependences on-the-fly and print it
|
|
|
|
Dependences D(S.getSharedIslCtx(), OptAnalysisLevel);
|
|
|
|
D.calculateDependences(S);
|
|
|
|
D.print(OS);
|
|
|
|
}
|
|
|
|
|
2015-03-05 06:43:40 +08:00
|
|
|
void DependenceInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
2016-05-31 17:41:04 +08:00
|
|
|
AU.addRequiredTransitive<ScopInfoRegionPass>();
|
2016-03-03 16:15:33 +08:00
|
|
|
AU.setPreservesAll();
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2015-03-05 06:43:40 +08:00
|
|
|
char DependenceInfo::ID = 0;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-03-05 06:43:40 +08:00
|
|
|
Pass *polly::createDependenceInfoPass() { return new DependenceInfo(); }
|
2013-03-23 09:05:07 +08:00
|
|
|
|
2015-03-05 06:43:40 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(DependenceInfo, "polly-dependences",
|
2013-03-23 09:05:07 +08:00
|
|
|
"Polly - Calculate dependences", false, false);
|
2016-05-31 17:41:04 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass);
|
2015-03-05 06:43:40 +08:00
|
|
|
INITIALIZE_PASS_END(DependenceInfo, "polly-dependences",
|
2011-10-08 08:30:40 +08:00
|
|
|
"Polly - Calculate dependences", false, false)
|
2016-06-27 22:47:38 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
const Dependences &
|
|
|
|
DependenceInfoWrapperPass::getDependences(Scop *S,
|
2016-11-24 05:59:33 +08:00
|
|
|
Dependences::AnalysisLevel Level) {
|
2016-06-27 22:47:38 +08:00
|
|
|
auto It = ScopToDepsMap.find(S);
|
|
|
|
if (It != ScopToDepsMap.end())
|
|
|
|
if (It->second) {
|
|
|
|
if (It->second->getDependenceLevel() == Level)
|
|
|
|
return *It->second.get();
|
|
|
|
}
|
|
|
|
return recomputeDependences(S, Level);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Dependences &DependenceInfoWrapperPass::recomputeDependences(
|
2016-11-24 05:59:33 +08:00
|
|
|
Scop *S, Dependences::AnalysisLevel Level) {
|
2016-06-27 22:47:38 +08:00
|
|
|
std::unique_ptr<Dependences> D(new Dependences(S->getSharedIslCtx(), Level));
|
|
|
|
D->calculateDependences(*S);
|
|
|
|
auto Inserted = ScopToDepsMap.insert(std::make_pair(S, std::move(D)));
|
|
|
|
return *Inserted.first->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DependenceInfoWrapperPass::runOnFunction(Function &F) {
|
2017-05-15 20:55:14 +08:00
|
|
|
auto &SI = *getAnalysis<ScopInfoWrapperPass>().getSI();
|
2016-07-25 20:40:59 +08:00
|
|
|
for (auto &It : SI) {
|
|
|
|
assert(It.second && "Invalid SCoP object!");
|
2016-06-27 22:47:38 +08:00
|
|
|
recomputeDependences(It.second.get(), Dependences::AL_Access);
|
2016-07-25 20:40:59 +08:00
|
|
|
}
|
2016-06-27 22:47:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DependenceInfoWrapperPass::print(raw_ostream &OS, const Module *M) const {
|
|
|
|
for (auto &It : ScopToDepsMap) {
|
|
|
|
assert((It.first && It.second) && "Invalid Scop or Dependence object!\n");
|
|
|
|
It.second->print(OS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DependenceInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequiredTransitive<ScopInfoWrapperPass>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
char DependenceInfoWrapperPass::ID = 0;
|
|
|
|
|
|
|
|
Pass *polly::createDependenceInfoWrapperPassPass() {
|
|
|
|
return new DependenceInfoWrapperPass();
|
|
|
|
}
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(
|
|
|
|
DependenceInfoWrapperPass, "polly-function-dependences",
|
|
|
|
"Polly - Calculate dependences for all the SCoPs of a function", false,
|
|
|
|
false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScopInfoWrapperPass);
|
|
|
|
INITIALIZE_PASS_END(
|
|
|
|
DependenceInfoWrapperPass, "polly-function-dependences",
|
|
|
|
"Polly - Calculate dependences for all the SCoPs of a function", false,
|
|
|
|
false)
|