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",
|
|
|
|
"Overapproximation of dependences"),
|
|
|
|
clEnumValEnd),
|
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
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
/// @brief Collect information about the SCoP @p S.
|
|
|
|
static void collectInfo(Scop &S, isl_union_map **Read, isl_union_map **Write,
|
|
|
|
isl_union_map **MayWrite,
|
|
|
|
isl_union_map **AccessSchedule,
|
|
|
|
isl_union_map **StmtSchedule) {
|
2011-10-06 08:03:42 +08:00
|
|
|
isl_space *Space = S.getParamSpace();
|
2012-03-08 01:42:45 +08:00
|
|
|
*Read = isl_union_map_empty(isl_space_copy(Space));
|
|
|
|
*Write = isl_union_map_empty(isl_space_copy(Space));
|
|
|
|
*MayWrite = isl_union_map_empty(isl_space_copy(Space));
|
2014-06-27 02:38:08 +08:00
|
|
|
*AccessSchedule = isl_union_map_empty(isl_space_copy(Space));
|
|
|
|
*StmtSchedule = isl_union_map_empty(Space);
|
|
|
|
|
|
|
|
SmallPtrSet<const Value *, 8> ReductionBaseValues;
|
2015-09-16 17:50:17 +08:00
|
|
|
if (UseReductions)
|
|
|
|
for (ScopStmt &Stmt : S)
|
|
|
|
for (MemoryAccess *MA : Stmt)
|
|
|
|
if (MA->isReductionLike())
|
|
|
|
ReductionBaseValues.insert(MA->getBaseAddr());
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
|
|
|
for (MemoryAccess *MA : Stmt) {
|
|
|
|
isl_set *domcp = Stmt.getDomain();
|
2014-06-14 02:01:45 +08:00
|
|
|
isl_map *accdom = MA->getAccessRelation();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
accdom = isl_map_intersect_domain(accdom, domcp);
|
|
|
|
|
2014-06-27 02:38:08 +08:00
|
|
|
if (ReductionBaseValues.count(MA->getBaseAddr())) {
|
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]
|
|
|
|
//
|
2015-04-21 19:37:25 +08:00
|
|
|
// The original schedule looks like
|
2014-06-27 02:38:08 +08:00
|
|
|
// Stmt[i0, i1] -> [0, i0, 2, i1, 0]
|
2015-04-21 19:37:25 +08:00
|
|
|
// but as we transformed the access domain we need the schedule
|
2014-06-27 02:38:08 +08:00
|
|
|
// to match the new access domains, thus we need
|
|
|
|
// [Stmt[i0, i1] -> MemAcc_A[i0 + i1]] -> [0, i0, 2, i1, 0]
|
2015-05-27 13:16:57 +08:00
|
|
|
isl_map *Schedule = Stmt.getSchedule();
|
2015-04-21 19:37:25 +08:00
|
|
|
Schedule = isl_map_apply_domain(
|
2015-04-21 19:42:01 +08:00
|
|
|
Schedule,
|
|
|
|
isl_map_reverse(isl_map_domain_map(isl_map_copy(accdom))));
|
2014-06-27 02:38:08 +08:00
|
|
|
accdom = isl_map_range_map(accdom);
|
2015-04-21 19:37:25 +08:00
|
|
|
*AccessSchedule = isl_union_map_add_map(*AccessSchedule, Schedule);
|
2014-06-27 02:38:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-14 02:01:45 +08:00
|
|
|
if (MA->isRead())
|
2012-03-08 01:42:45 +08:00
|
|
|
*Read = isl_union_map_add_map(*Read, accdom);
|
2011-04-29 14:27:02 +08:00
|
|
|
else
|
2012-03-08 01:42:45 +08:00
|
|
|
*Write = isl_union_map_add_map(*Write, accdom);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
2015-05-27 13:16:57 +08:00
|
|
|
*StmtSchedule = isl_union_map_add_map(*StmtSchedule, Stmt.getSchedule());
|
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
|
|
|
|
|
|
|
*StmtSchedule =
|
|
|
|
isl_union_map_intersect_params(*StmtSchedule, S.getAssumedContext());
|
2012-03-08 01:42:45 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2014-07-15 08:00:35 +08:00
|
|
|
/// @brief 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
|
|
|
}
|
|
|
|
|
2014-06-21 00:37:11 +08:00
|
|
|
/// @brief Compute the privatization dependences for a given dependency @p Map
|
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
TC_RED = isl_union_map_transitive_closure(isl_union_map_copy(RED), 0);
|
|
|
|
|
|
|
|
// 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(
|
2014-07-15 08:00:35 +08:00
|
|
|
*PrivMap, isl_union_map_apply_range(isl_union_map_copy(TC_RED),
|
2014-06-21 00:37:11 +08:00
|
|
|
isl_union_map_copy(*Map)));
|
|
|
|
|
|
|
|
*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
|
|
|
}
|
|
|
|
|
2015-08-02 21:30:33 +08:00
|
|
|
static isl_stat getMaxScheduleDim(__isl_take isl_map *Map, void *User) {
|
|
|
|
unsigned int *MaxScheduleDim = (unsigned int *)User;
|
|
|
|
*MaxScheduleDim = std::max(*MaxScheduleDim, isl_map_dim(Map, isl_dim_out));
|
|
|
|
isl_map_free(Map);
|
|
|
|
return isl_stat_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
__isl_give isl_union_map *
|
|
|
|
addZeroPaddingToSchedule(__isl_take isl_union_map *Schedule) {
|
|
|
|
unsigned int MaxScheduleDim = 0;
|
|
|
|
|
|
|
|
isl_union_map_foreach_map(Schedule, getMaxScheduleDim, &MaxScheduleDim);
|
|
|
|
|
|
|
|
auto ExtensionMap = isl_union_map_empty(isl_union_map_get_space(Schedule));
|
|
|
|
for (unsigned int i = 0; i <= MaxScheduleDim; i++) {
|
|
|
|
auto *Map = isl_map_identity(
|
|
|
|
isl_space_alloc(isl_union_map_get_ctx(Schedule), 0, i, i));
|
|
|
|
Map = isl_map_add_dims(Map, isl_dim_out, MaxScheduleDim - i);
|
|
|
|
for (unsigned int j = 0; j < MaxScheduleDim - i; j++)
|
|
|
|
Map = isl_map_fix_si(Map, isl_dim_out, i + j, 0);
|
|
|
|
|
|
|
|
ExtensionMap = isl_union_map_add_map(ExtensionMap, Map);
|
|
|
|
}
|
|
|
|
Schedule = isl_union_map_apply_range(Schedule, ExtensionMap);
|
|
|
|
|
|
|
|
return Schedule;
|
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
void Dependences::calculateDependences(Scop &S) {
|
2015-07-14 17:33:13 +08:00
|
|
|
isl_union_map *Read, *Write, *MayWrite, *AccessSchedule, *StmtSchedule;
|
|
|
|
isl_schedule *Schedule;
|
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
|
|
|
|
2014-06-27 02:38:08 +08:00
|
|
|
collectInfo(S, &Read, &Write, &MayWrite, &AccessSchedule, &StmtSchedule);
|
|
|
|
|
2015-08-18 23:05:29 +08:00
|
|
|
if (isl_union_map_is_empty(AccessSchedule)) {
|
2015-07-14 17:33:13 +08:00
|
|
|
isl_union_map_free(AccessSchedule);
|
|
|
|
Schedule = S.getScheduleTree();
|
|
|
|
} else {
|
|
|
|
auto *ScheduleMap =
|
|
|
|
isl_union_map_union(AccessSchedule, isl_union_map_copy(StmtSchedule));
|
|
|
|
Schedule = isl_schedule_from_domain(
|
|
|
|
isl_union_map_domain(isl_union_map_copy(ScheduleMap)));
|
2015-08-02 21:30:33 +08:00
|
|
|
if (!isl_union_map_is_empty(ScheduleMap)) {
|
|
|
|
ScheduleMap = addZeroPaddingToSchedule(ScheduleMap);
|
2015-07-14 17:33:13 +08:00
|
|
|
Schedule = isl_schedule_insert_partial_schedule(
|
|
|
|
Schedule, isl_multi_union_pw_aff_from_union_map(ScheduleMap));
|
2015-08-02 21:30:33 +08:00
|
|
|
} else {
|
2015-07-14 17:33:13 +08:00
|
|
|
isl_union_map_free(ScheduleMap);
|
2015-08-02 21:30:33 +08:00
|
|
|
}
|
2015-07-14 17:33:13 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-08-08 21:55:45 +08:00
|
|
|
Read = isl_union_map_coalesce(Read);
|
|
|
|
Write = isl_union_map_coalesce(Write);
|
|
|
|
MayWrite = isl_union_map_coalesce(MayWrite);
|
|
|
|
|
2014-01-27 03:38:34 +08:00
|
|
|
long MaxOpsOld = isl_ctx_get_max_operations(S.getIslCtx());
|
2015-04-19 15:07:26 +08:00
|
|
|
if (OptComputeOut)
|
|
|
|
isl_ctx_set_max_operations(S.getIslCtx(), OptComputeOut);
|
2014-01-27 03:38:34 +08:00
|
|
|
isl_options_set_on_error(S.getIslCtx(), ISL_ON_ERROR_CONTINUE);
|
|
|
|
|
2013-07-31 22:35:17 +08:00
|
|
|
DEBUG(dbgs() << "Read: " << Read << "\n";
|
|
|
|
dbgs() << "Write: " << Write << "\n";
|
2015-07-14 17:33:13 +08:00
|
|
|
dbgs() << "MayWrite: " << MayWrite << "\n");
|
2013-07-31 22:35:17 +08:00
|
|
|
|
2014-06-21 00:37:11 +08:00
|
|
|
RAW = WAW = WAR = RED = nullptr;
|
2014-01-27 03:38:34 +08:00
|
|
|
|
2013-07-14 01:37:55 +08:00
|
|
|
if (OptAnalysisType == VALUE_BASED_ANALYSIS) {
|
2015-04-21 16:47:29 +08:00
|
|
|
isl_union_access_info *AI;
|
|
|
|
isl_union_flow *Flow;
|
|
|
|
|
|
|
|
AI = isl_union_access_info_from_sink(isl_union_map_copy(Read));
|
|
|
|
AI = isl_union_access_info_set_must_source(AI, isl_union_map_copy(Write));
|
|
|
|
AI = isl_union_access_info_set_may_source(AI, isl_union_map_copy(MayWrite));
|
2015-04-21 19:01:34 +08:00
|
|
|
AI = isl_union_access_info_set_schedule(AI, isl_schedule_copy(Schedule));
|
2015-04-21 16:47:29 +08:00
|
|
|
Flow = isl_union_access_info_compute_flow(AI);
|
|
|
|
|
|
|
|
RAW = isl_union_flow_get_must_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
|
|
|
|
|
|
|
AI = isl_union_access_info_from_sink(isl_union_map_copy(Write));
|
|
|
|
AI = isl_union_access_info_set_must_source(AI, isl_union_map_copy(Write));
|
|
|
|
AI = isl_union_access_info_set_may_source(AI, isl_union_map_copy(Read));
|
2015-04-21 19:01:34 +08:00
|
|
|
AI = isl_union_access_info_set_schedule(AI, Schedule);
|
2015-04-21 16:47:29 +08:00
|
|
|
Flow = isl_union_access_info_compute_flow(AI);
|
|
|
|
|
|
|
|
WAW = isl_union_flow_get_must_dependence(Flow);
|
|
|
|
WAR = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
|
|
|
|
// This subtraction is needed to obtain the same results as were given by
|
|
|
|
// isl_union_map_compute_flow. For large sets this may add some compile-time
|
|
|
|
// cost. As there does not seem to be a need to distinguish between WAW and
|
|
|
|
// WAR, refactoring Polly to only track general non-flow dependences may
|
|
|
|
// improve performance.
|
|
|
|
WAR = isl_union_map_subtract(WAR, isl_union_map_copy(WAW));
|
|
|
|
isl_union_flow_free(Flow);
|
2012-11-02 05:28:32 +08:00
|
|
|
} else {
|
2015-04-21 16:47:29 +08:00
|
|
|
isl_union_access_info *AI;
|
|
|
|
isl_union_flow *Flow;
|
2012-11-02 05:28:32 +08:00
|
|
|
|
|
|
|
Write = isl_union_map_union(Write, isl_union_map_copy(MayWrite));
|
|
|
|
|
2015-04-21 16:47:29 +08:00
|
|
|
AI = isl_union_access_info_from_sink(isl_union_map_copy(Read));
|
|
|
|
AI = isl_union_access_info_set_may_source(AI, isl_union_map_copy(Write));
|
2015-04-21 19:01:34 +08:00
|
|
|
AI = isl_union_access_info_set_schedule(AI, isl_schedule_copy(Schedule));
|
2015-04-21 16:47:29 +08:00
|
|
|
Flow = isl_union_access_info_compute_flow(AI);
|
|
|
|
|
|
|
|
RAW = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
|
|
|
|
|
|
|
AI = isl_union_access_info_from_sink(isl_union_map_copy(Write));
|
|
|
|
AI = isl_union_access_info_set_may_source(AI, isl_union_map_copy(Read));
|
2015-04-21 19:01:34 +08:00
|
|
|
AI = isl_union_access_info_set_schedule(AI, isl_schedule_copy(Schedule));
|
2015-04-21 16:47:29 +08:00
|
|
|
Flow = isl_union_access_info_compute_flow(AI);
|
|
|
|
|
|
|
|
WAR = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
|
|
|
|
|
|
|
AI = isl_union_access_info_from_sink(isl_union_map_copy(Write));
|
|
|
|
AI = isl_union_access_info_set_may_source(AI, isl_union_map_copy(Write));
|
2015-04-21 19:01:34 +08:00
|
|
|
AI = isl_union_access_info_set_schedule(AI, Schedule);
|
2015-04-21 16:47:29 +08:00
|
|
|
Flow = isl_union_access_info_compute_flow(AI);
|
|
|
|
|
|
|
|
WAW = isl_union_flow_get_may_dependence(Flow);
|
|
|
|
isl_union_flow_free(Flow);
|
2012-11-02 05:28:32 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-03-08 01:42:45 +08:00
|
|
|
isl_union_map_free(MayWrite);
|
|
|
|
isl_union_map_free(Write);
|
2012-11-02 05:28:32 +08:00
|
|
|
isl_union_map_free(Read);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-03-08 01:42:45 +08:00
|
|
|
RAW = isl_union_map_coalesce(RAW);
|
|
|
|
WAW = isl_union_map_coalesce(WAW);
|
|
|
|
WAR = isl_union_map_coalesce(WAR);
|
2013-07-31 22:35:17 +08:00
|
|
|
|
2014-01-27 03:38:34 +08:00
|
|
|
if (isl_ctx_last_error(S.getIslCtx()) == isl_error_quota) {
|
|
|
|
isl_union_map_free(RAW);
|
|
|
|
isl_union_map_free(WAW);
|
|
|
|
isl_union_map_free(WAR);
|
2014-04-16 15:33:47 +08:00
|
|
|
RAW = WAW = WAR = nullptr;
|
2014-01-27 03:38:34 +08:00
|
|
|
isl_ctx_reset_error(S.getIslCtx());
|
|
|
|
}
|
|
|
|
isl_options_set_on_error(S.getIslCtx(), ISL_ON_ERROR_ABORT);
|
|
|
|
isl_ctx_reset_operations(S.getIslCtx());
|
|
|
|
isl_ctx_set_max_operations(S.getIslCtx(), MaxOpsOld);
|
|
|
|
|
2014-06-27 02:38:08 +08:00
|
|
|
isl_union_map *STMT_RAW, *STMT_WAW, *STMT_WAR;
|
|
|
|
STMT_RAW = isl_union_map_intersect_domain(
|
|
|
|
isl_union_map_copy(RAW),
|
|
|
|
isl_union_map_domain(isl_union_map_copy(StmtSchedule)));
|
|
|
|
STMT_WAW = isl_union_map_intersect_domain(
|
|
|
|
isl_union_map_copy(WAW),
|
|
|
|
isl_union_map_domain(isl_union_map_copy(StmtSchedule)));
|
|
|
|
STMT_WAR = isl_union_map_intersect_domain(isl_union_map_copy(WAR),
|
|
|
|
isl_union_map_domain(StmtSchedule));
|
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.
|
2015-06-15 18:52:28 +08:00
|
|
|
// 3) Relax the original RAW and WAW dependences by subtracting the actual
|
2014-06-21 00:37:11 +08:00
|
|
|
// reduction dependences. Binary reductions (sum += A[i]) cause both, and
|
|
|
|
// the same, RAW and WAW dependences.
|
|
|
|
// 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;
|
2014-06-27 02:44:14 +08:00
|
|
|
isl_set *AccDomW = isl_map_wrap(MA->getAccessRelation());
|
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));
|
|
|
|
RED = isl_union_map_intersect(RED, isl_union_map_copy(WAW));
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
// Step 4)
|
|
|
|
addPrivatizationDependences();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
isl_set *AccDomW = isl_map_wrap(MA->getAccessRelation());
|
|
|
|
isl_union_map *AccRedDepU = isl_union_map_intersect_domain(
|
|
|
|
isl_union_map_copy(TC_RED), isl_union_set_from_set(AccDomW));
|
|
|
|
if (isl_union_map_is_empty(AccRedDepU) && !isl_union_map_free(AccRedDepU))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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);
|
2011-10-06 08:03:42 +08:00
|
|
|
isl_space *Space = S.getParamSpace();
|
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())
|
|
|
|
StmtScat = Stmt.getSchedule();
|
2011-04-29 14:27:02 +08:00
|
|
|
else
|
2015-05-27 13:16:57 +08:00
|
|
|
StmtScat = isl_map_copy((*NewSchedule)[&Stmt]);
|
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
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
isl_map *Dependences::getReductionDependences(MemoryAccess *MA) const {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
void DependenceInfo::recomputeDependences() {
|
|
|
|
releaseMemory();
|
|
|
|
D.calculateDependences(*S);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DependenceInfo::runOnScop(Scop &ScopVar) {
|
|
|
|
S = &ScopVar;
|
|
|
|
recomputeDependences();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-05 06:43:40 +08:00
|
|
|
void DependenceInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
2011-04-29 14:27:02 +08:00
|
|
|
ScopPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScopInfo);
|
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)
|