2011-04-29 14:27:02 +08:00
|
|
|
//===--------- ScopInfo.cpp - Create Scops from LLVM IR ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Create a polyhedral description for a static control flow region.
|
|
|
|
//
|
|
|
|
// The pass creates a polyhedral description of the Scops detected by the Scop
|
|
|
|
// detection derived from their LLVM-IR code.
|
|
|
|
//
|
|
|
|
// This represantation is shared among several tools in the polyhedral
|
|
|
|
// community, which are e.g. Cloog, Pluto, Loopo, Graphite.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-03-23 06:07:43 +08:00
|
|
|
#include "polly/CodeGen/BlockGenerators.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "polly/LinkAllPasses.h"
|
2013-03-23 06:07:43 +08:00
|
|
|
#include "polly/ScopInfo.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "polly/Support/GICHelper.h"
|
2011-11-08 23:41:28 +08:00
|
|
|
#include "polly/Support/SCEVValidator.h"
|
2013-05-07 16:11:54 +08:00
|
|
|
#include "polly/Support/ScopHelper.h"
|
2013-03-23 06:07:43 +08:00
|
|
|
#include "polly/TempScopInfo.h"
|
2013-05-07 16:11:54 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/Analysis/RegionIterator.h"
|
2013-05-07 16:11:54 +08:00
|
|
|
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "polly-scops"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
#include "isl/constraint.h"
|
|
|
|
#include "isl/set.h"
|
|
|
|
#include "isl/map.h"
|
2011-08-18 14:31:50 +08:00
|
|
|
#include "isl/aff.h"
|
|
|
|
#include "isl/printer.h"
|
2011-10-06 08:03:35 +08:00
|
|
|
#include "isl/local_space.h"
|
2011-12-07 15:42:51 +08:00
|
|
|
#include "isl/options.h"
|
2013-06-21 14:41:31 +08:00
|
|
|
#include "isl/val.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace polly;
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
STATISTIC(ScopFound, "Number of valid Scops");
|
|
|
|
STATISTIC(RichScopFound, "Number of Scops containing a loop");
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
/// Translate a 'const SCEV *' expression in an isl_pw_aff.
|
2013-02-05 20:09:06 +08:00
|
|
|
struct SCEVAffinator : public SCEVVisitor<SCEVAffinator, isl_pw_aff *> {
|
2013-09-17 11:30:31 +08:00
|
|
|
public:
|
|
|
|
/// @brief Translate a 'const SCEV *' to an isl_pw_aff.
|
|
|
|
///
|
|
|
|
/// @param Stmt The location at which the scalar evolution expression
|
|
|
|
/// is evaluated.
|
|
|
|
/// @param Expr The expression that is translated.
|
|
|
|
static __isl_give isl_pw_aff *getPwAff(ScopStmt *Stmt, const SCEV *Expr);
|
|
|
|
|
2011-08-18 14:31:50 +08:00
|
|
|
private:
|
2012-06-07 00:33:15 +08:00
|
|
|
isl_ctx *Ctx;
|
2011-10-06 08:03:35 +08:00
|
|
|
int NbLoopSpaces;
|
2012-06-07 00:33:15 +08:00
|
|
|
const Scop *S;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
SCEVAffinator(const ScopStmt *Stmt);
|
|
|
|
int getLoopDepth(const Loop *L);
|
|
|
|
|
|
|
|
__isl_give isl_pw_aff *visit(const SCEV *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitConstant(const SCEVConstant *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitTruncateExpr(const SCEVTruncateExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitSignExtendExpr(const SCEVSignExtendExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitAddExpr(const SCEVAddExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitMulExpr(const SCEVMulExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitUDivExpr(const SCEVUDivExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitAddRecExpr(const SCEVAddRecExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitSMaxExpr(const SCEVSMaxExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitUMaxExpr(const SCEVUMaxExpr *Expr);
|
|
|
|
__isl_give isl_pw_aff *visitUnknown(const SCEVUnknown *Expr);
|
|
|
|
|
|
|
|
friend struct SCEVVisitor<SCEVAffinator, isl_pw_aff *>;
|
|
|
|
};
|
2011-11-08 23:41:28 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
SCEVAffinator::SCEVAffinator(const ScopStmt *Stmt)
|
|
|
|
: Ctx(Stmt->getIslCtx()), NbLoopSpaces(Stmt->getNumIterators()),
|
|
|
|
S(Stmt->getParent()) {}
|
2011-11-08 23:41:28 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::getPwAff(ScopStmt *Stmt,
|
|
|
|
const SCEV *Scev) {
|
|
|
|
Scop *S = Stmt->getParent();
|
|
|
|
const Region *Reg = &S->getRegion();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
S->addParams(getParamsInAffineExpr(Reg, Scev, *S->getSE()));
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
SCEVAffinator Affinator(Stmt);
|
|
|
|
return Affinator.visit(Scev);
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visit(const SCEV *Expr) {
|
|
|
|
// In case the scev is a valid parameter, we do not further analyze this
|
|
|
|
// expression, but create a new parameter in the isl_pw_aff. This allows us
|
|
|
|
// to treat subexpressions that we cannot translate into an piecewise affine
|
|
|
|
// expression, as constant parameters of the piecewise affine expression.
|
|
|
|
if (isl_id *Id = S->getIdForParam(Expr)) {
|
|
|
|
isl_space *Space = isl_space_set_alloc(Ctx, 1, NbLoopSpaces);
|
|
|
|
Space = isl_space_set_dim_id(Space, isl_dim_param, 0, Id);
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
isl_set *Domain = isl_set_universe(isl_space_copy(Space));
|
|
|
|
isl_aff *Affine = isl_aff_zero_on_domain(isl_local_space_from_space(Space));
|
|
|
|
Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
|
2011-08-18 14:31:50 +08:00
|
|
|
|
|
|
|
return isl_pw_aff_alloc(Domain, Affine);
|
|
|
|
}
|
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
return SCEVVisitor<SCEVAffinator, isl_pw_aff *>::visit(Expr);
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-10-03 21:09:19 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visitConstant(const SCEVConstant *Expr) {
|
2013-09-17 11:30:31 +08:00
|
|
|
ConstantInt *Value = Expr->getValue();
|
|
|
|
isl_val *v;
|
|
|
|
|
|
|
|
// LLVM does not define if an integer value is interpreted as a signed or
|
|
|
|
// unsigned value. Hence, without further information, it is unknown how
|
|
|
|
// this value needs to be converted to GMP. At the moment, we only support
|
|
|
|
// signed operations. So we just interpret it as signed. Later, there are
|
|
|
|
// two options:
|
|
|
|
//
|
|
|
|
// 1. We always interpret any value as signed and convert the values on
|
|
|
|
// demand.
|
|
|
|
// 2. We pass down the signedness of the calculation and use it to interpret
|
|
|
|
// this constant correctly.
|
|
|
|
v = isl_valFromAPInt(Ctx, Value->getValue(), /* isSigned */ true);
|
|
|
|
|
|
|
|
isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces);
|
|
|
|
isl_local_space *ls = isl_local_space_from_space(isl_space_copy(Space));
|
|
|
|
isl_aff *Affine = isl_aff_zero_on_domain(ls);
|
|
|
|
isl_set *Domain = isl_set_universe(Space);
|
|
|
|
|
|
|
|
Affine = isl_aff_add_constant_val(Affine, v);
|
|
|
|
|
|
|
|
return isl_pw_aff_alloc(Domain, Affine);
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *
|
|
|
|
SCEVAffinator::visitTruncateExpr(const SCEVTruncateExpr *Expr) {
|
|
|
|
llvm_unreachable("SCEVTruncateExpr not yet supported");
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *
|
|
|
|
SCEVAffinator::visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
|
|
|
|
llvm_unreachable("SCEVZeroExtendExpr not yet supported");
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *
|
|
|
|
SCEVAffinator::visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
|
|
|
|
// Assuming the value is signed, a sign extension is basically a noop.
|
|
|
|
// TODO: Reconsider this as soon as we support unsigned values.
|
|
|
|
return visit(Expr->getOperand());
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visitAddExpr(const SCEVAddExpr *Expr) {
|
|
|
|
isl_pw_aff *Sum = visit(Expr->getOperand(0));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
|
|
|
|
isl_pw_aff *NextSummand = visit(Expr->getOperand(i));
|
|
|
|
Sum = isl_pw_aff_add(Sum, NextSummand);
|
2011-08-18 14:31:50 +08:00
|
|
|
}
|
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
// TODO: Check for NSW and NUW.
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
return Sum;
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visitMulExpr(const SCEVMulExpr *Expr) {
|
|
|
|
isl_pw_aff *Product = visit(Expr->getOperand(0));
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
|
|
|
|
isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
if (!isl_pw_aff_is_cst(Product) && !isl_pw_aff_is_cst(NextOperand)) {
|
|
|
|
isl_pw_aff_free(Product);
|
|
|
|
isl_pw_aff_free(NextOperand);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
Product = isl_pw_aff_mul(Product, NextOperand);
|
2011-08-18 14:31:50 +08:00
|
|
|
}
|
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
// TODO: Check for NSW and NUW.
|
|
|
|
return Product;
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) {
|
|
|
|
llvm_unreachable("SCEVUDivExpr not yet supported");
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *
|
|
|
|
SCEVAffinator::visitAddRecExpr(const SCEVAddRecExpr *Expr) {
|
|
|
|
assert(Expr->isAffine() && "Only affine AddRecurrences allowed");
|
2013-08-05 23:14:15 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
// Directly generate isl_pw_aff for Expr if 'start' is zero.
|
|
|
|
if (Expr->getStart()->isZero()) {
|
|
|
|
assert(S->getRegion().contains(Expr->getLoop()) &&
|
|
|
|
"Scop does not contain the loop referenced in this AddRec");
|
2013-08-05 23:14:15 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
isl_pw_aff *Start = visit(Expr->getStart());
|
|
|
|
isl_pw_aff *Step = visit(Expr->getOperand(1));
|
|
|
|
isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces);
|
|
|
|
isl_local_space *LocalSpace = isl_local_space_from_space(Space);
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
int loopDimension = getLoopDepth(Expr->getLoop());
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
isl_aff *LAff = isl_aff_set_coefficient_si(
|
|
|
|
isl_aff_zero_on_domain(LocalSpace), isl_dim_in, loopDimension, 1);
|
|
|
|
isl_pw_aff *LPwAff = isl_pw_aff_from_aff(LAff);
|
2013-08-05 23:14:15 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
// TODO: Do we need to check for NSW and NUW?
|
|
|
|
return isl_pw_aff_add(Start, isl_pw_aff_mul(Step, LPwAff));
|
|
|
|
}
|
2013-08-05 23:14:15 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
// Translate AddRecExpr from '{start, +, inc}' into 'start + {0, +, inc}'
|
|
|
|
// if 'start' is not zero.
|
|
|
|
ScalarEvolution &SE = *S->getSE();
|
|
|
|
const SCEV *ZeroStartExpr = SE.getAddRecExpr(
|
|
|
|
SE.getConstant(Expr->getStart()->getType(), 0),
|
|
|
|
Expr->getStepRecurrence(SE), Expr->getLoop(), SCEV::FlagAnyWrap);
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
isl_pw_aff *ZeroStartResult = visit(ZeroStartExpr);
|
|
|
|
isl_pw_aff *Start = visit(Expr->getStart());
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
return isl_pw_aff_add(ZeroStartResult, Start);
|
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visitSMaxExpr(const SCEVSMaxExpr *Expr) {
|
|
|
|
isl_pw_aff *Max = visit(Expr->getOperand(0));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
|
|
|
|
isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
|
|
|
|
Max = isl_pw_aff_max(Max, NextOperand);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
return Max;
|
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-09-17 11:30:31 +08:00
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visitUMaxExpr(const SCEVUMaxExpr *Expr) {
|
|
|
|
llvm_unreachable("SCEVUMaxExpr not yet supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
__isl_give isl_pw_aff *SCEVAffinator::visitUnknown(const SCEVUnknown *Expr) {
|
|
|
|
llvm_unreachable("Unknowns are always parameters");
|
|
|
|
}
|
|
|
|
|
|
|
|
int SCEVAffinator::getLoopDepth(const Loop *L) {
|
|
|
|
Loop *outerLoop = S->getRegion().outermostLoopInRegion(const_cast<Loop *>(L));
|
|
|
|
assert(outerLoop && "Scop does not contain this loop");
|
|
|
|
return L->getLoopDepth() - outerLoop->getLoopDepth();
|
|
|
|
}
|
2011-08-18 14:31:50 +08:00
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
MemoryAccess::~MemoryAccess() {
|
2011-08-18 14:31:46 +08:00
|
|
|
isl_map_free(AccessRelation);
|
2011-08-15 10:33:39 +08:00
|
|
|
isl_map_free(newAccessRelation);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-05-07 15:30:56 +08:00
|
|
|
static void replace(std::string &str, const std::string &find,
|
|
|
|
const std::string &replace) {
|
2011-04-29 14:27:02 +08:00
|
|
|
size_t pos = 0;
|
2012-12-30 07:47:38 +08:00
|
|
|
while ((pos = str.find(find, pos)) != std::string::npos) {
|
2011-04-29 14:27:02 +08:00
|
|
|
str.replace(pos, find.length(), replace);
|
|
|
|
pos += replace.length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-30 07:47:38 +08:00
|
|
|
static void makeIslCompatible(std::string &str) {
|
2011-08-20 19:11:14 +08:00
|
|
|
str.erase(0, 1);
|
2011-04-29 14:27:02 +08:00
|
|
|
replace(str, ".", "_");
|
2011-08-03 08:12:11 +08:00
|
|
|
replace(str, "\"", "_");
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryAccess::setBaseName() {
|
|
|
|
raw_string_ostream OS(BaseName);
|
2014-01-09 18:42:15 +08:00
|
|
|
getBaseAddr()->printAsOperand(OS, false);
|
2011-04-29 14:27:02 +08:00
|
|
|
BaseName = OS.str();
|
|
|
|
|
|
|
|
makeIslCompatible(BaseName);
|
|
|
|
BaseName = "MemRef_" + BaseName;
|
|
|
|
}
|
|
|
|
|
2011-10-06 08:04:11 +08:00
|
|
|
isl_map *MemoryAccess::getAccessRelation() const {
|
|
|
|
return isl_map_copy(AccessRelation);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string MemoryAccess::getAccessRelationStr() const {
|
|
|
|
return stringFromIslObj(AccessRelation);
|
|
|
|
}
|
|
|
|
|
|
|
|
isl_map *MemoryAccess::getNewAccessRelation() const {
|
|
|
|
return isl_map_copy(newAccessRelation);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
isl_basic_map *MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
|
2012-05-29 17:29:44 +08:00
|
|
|
isl_space *Space = isl_space_set_alloc(Statement->getIslCtx(), 0, 1);
|
|
|
|
Space = isl_space_set_tuple_name(Space, isl_dim_set, getBaseName().c_str());
|
2012-09-11 21:50:21 +08:00
|
|
|
Space = isl_space_align_params(Space, Statement->getDomainSpace());
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-05-29 17:29:44 +08:00
|
|
|
return isl_basic_map_from_domain_and_range(
|
2013-02-05 20:09:06 +08:00
|
|
|
isl_basic_set_universe(Statement->getDomainSpace()),
|
|
|
|
isl_basic_set_universe(Space));
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2012-07-06 14:47:03 +08:00
|
|
|
MemoryAccess::MemoryAccess(const IRAccess &Access, const Instruction *AccInst,
|
2013-02-05 20:09:06 +08:00
|
|
|
ScopStmt *Statement)
|
|
|
|
: Inst(AccInst) {
|
2011-07-13 01:14:03 +08:00
|
|
|
newAccessRelation = NULL;
|
2011-04-29 14:27:02 +08:00
|
|
|
statement = Statement;
|
|
|
|
|
2011-11-10 20:44:55 +08:00
|
|
|
BaseAddr = Access.getBase();
|
2012-05-29 17:29:44 +08:00
|
|
|
setBaseName();
|
2011-11-10 06:34:34 +08:00
|
|
|
|
2011-12-20 18:43:14 +08:00
|
|
|
if (!Access.isAffine()) {
|
2013-06-23 13:21:18 +08:00
|
|
|
// We overapproximate non-affine accesses with a possible access to the
|
|
|
|
// whole array. For read accesses it does not make a difference, if an
|
|
|
|
// access must or may happen. However, for write accesses it is important to
|
|
|
|
// differentiate between writes that must happen and writes that may happen.
|
2013-06-23 14:04:54 +08:00
|
|
|
AccessRelation = isl_map_from_basic_map(createBasicAccessMap(Statement));
|
2013-07-14 04:41:24 +08:00
|
|
|
Type = Access.isRead() ? READ : MAY_WRITE;
|
2011-12-20 18:43:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-14 04:41:24 +08:00
|
|
|
Type = Access.isRead() ? READ : MUST_WRITE;
|
2013-06-23 13:21:18 +08:00
|
|
|
|
2011-12-20 18:43:14 +08:00
|
|
|
isl_pw_aff *Affine = SCEVAffinator::getPwAff(Statement, Access.getOffset());
|
|
|
|
|
2012-04-10 03:46:05 +08:00
|
|
|
// Divide the access function by the size of the elements in the array.
|
2011-08-20 07:34:28 +08:00
|
|
|
//
|
|
|
|
// A stride one array access in C expressed as A[i] is expressed in LLVM-IR
|
|
|
|
// as something like A[i * elementsize]. This hides the fact that two
|
|
|
|
// subsequent values of 'i' index two values that are stored next to each
|
2012-04-10 03:46:05 +08:00
|
|
|
// other in memory. By this division we make this characteristic obvious
|
2011-08-20 07:34:28 +08:00
|
|
|
// again.
|
2013-06-21 14:41:31 +08:00
|
|
|
isl_val *v;
|
|
|
|
v = isl_val_int_from_si(isl_pw_aff_get_ctx(Affine),
|
|
|
|
Access.getElemSizeInBytes());
|
|
|
|
Affine = isl_pw_aff_scale_down_val(Affine, v);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-08-20 07:34:28 +08:00
|
|
|
AccessRelation = isl_map_from_pw_aff(Affine);
|
2012-05-29 17:29:44 +08:00
|
|
|
isl_space *Space = Statement->getDomainSpace();
|
2013-02-05 20:09:06 +08:00
|
|
|
AccessRelation = isl_map_set_tuple_id(
|
|
|
|
AccessRelation, isl_dim_in, isl_space_get_tuple_id(Space, isl_dim_set));
|
2012-05-29 17:29:44 +08:00
|
|
|
isl_space_free(Space);
|
2011-04-29 14:27:02 +08:00
|
|
|
AccessRelation = isl_map_set_tuple_name(AccessRelation, isl_dim_out,
|
|
|
|
getBaseName().c_str());
|
2011-11-08 23:41:08 +08:00
|
|
|
}
|
2011-08-18 15:51:37 +08:00
|
|
|
|
2011-11-08 23:41:08 +08:00
|
|
|
void MemoryAccess::realignParams() {
|
|
|
|
isl_space *ParamSpace = statement->getParent()->getParamSpace();
|
2011-10-06 08:03:42 +08:00
|
|
|
AccessRelation = isl_map_align_params(AccessRelation, ParamSpace);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MemoryAccess::MemoryAccess(const Value *BaseAddress, ScopStmt *Statement) {
|
2011-07-13 01:14:03 +08:00
|
|
|
newAccessRelation = NULL;
|
2011-04-29 14:27:02 +08:00
|
|
|
BaseAddr = BaseAddress;
|
2013-07-14 04:41:24 +08:00
|
|
|
Type = READ;
|
2011-04-29 14:27:02 +08:00
|
|
|
statement = Statement;
|
|
|
|
|
|
|
|
isl_basic_map *BasicAccessMap = createBasicAccessMap(Statement);
|
|
|
|
AccessRelation = isl_map_from_basic_map(BasicAccessMap);
|
2011-10-06 08:03:42 +08:00
|
|
|
isl_space *ParamSpace = Statement->getParent()->getParamSpace();
|
|
|
|
AccessRelation = isl_map_align_params(AccessRelation, ParamSpace);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryAccess::print(raw_ostream &OS) const {
|
2013-06-23 13:21:18 +08:00
|
|
|
switch (Type) {
|
2013-07-14 04:41:24 +08:00
|
|
|
case READ:
|
2013-06-23 13:21:18 +08:00
|
|
|
OS.indent(12) << "ReadAccess := \n";
|
|
|
|
break;
|
2013-07-14 04:41:24 +08:00
|
|
|
case MUST_WRITE:
|
2013-06-23 13:21:18 +08:00
|
|
|
OS.indent(12) << "MustWriteAccess := \n";
|
|
|
|
break;
|
2013-07-14 04:41:24 +08:00
|
|
|
case MAY_WRITE:
|
2013-06-23 13:21:18 +08:00
|
|
|
OS.indent(12) << "MayWriteAccess := \n";
|
|
|
|
break;
|
|
|
|
}
|
2011-10-06 08:04:11 +08:00
|
|
|
OS.indent(16) << getAccessRelationStr() << ";\n";
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
void MemoryAccess::dump() const { print(errs()); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
// Create a map in the size of the provided set domain, that maps from the
|
|
|
|
// one element of the provided set domain to another element of the provided
|
|
|
|
// set domain.
|
|
|
|
// The mapping is limited to all points that are equal in all but the last
|
|
|
|
// dimension and for which the last dimension of the input is strict smaller
|
|
|
|
// than the last dimension of the output.
|
|
|
|
//
|
|
|
|
// getEqualAndLarger(set[i0, i1, ..., iX]):
|
|
|
|
//
|
|
|
|
// set[i0, i1, ..., iX] -> set[o0, o1, ..., oX]
|
|
|
|
// : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1), iX < oX
|
|
|
|
//
|
2011-10-06 08:03:35 +08:00
|
|
|
static isl_map *getEqualAndLarger(isl_space *setDomain) {
|
2012-02-01 22:23:36 +08:00
|
|
|
isl_space *Space = isl_space_map_from_set(setDomain);
|
|
|
|
isl_map *Map = isl_map_universe(isl_space_copy(Space));
|
|
|
|
isl_local_space *MapLocalSpace = isl_local_space_from_space(Space);
|
2013-10-05 01:14:53 +08:00
|
|
|
unsigned lastDimension = isl_map_dim(Map, isl_dim_in) - 1;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
// Set all but the last dimension to be equal for the input and output
|
|
|
|
//
|
|
|
|
// input[i0, i1, ..., iX] -> output[o0, o1, ..., oX]
|
|
|
|
// : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1)
|
2013-10-05 01:14:53 +08:00
|
|
|
for (unsigned i = 0; i < lastDimension; ++i)
|
2012-02-01 22:23:36 +08:00
|
|
|
Map = isl_map_equate(Map, isl_dim_in, i, isl_dim_out, i);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
// Set the last dimension of the input to be strict smaller than the
|
|
|
|
// last dimension of the output.
|
|
|
|
//
|
|
|
|
// input[?,?,?,...,iX] -> output[?,?,?,...,oX] : iX < oX
|
|
|
|
//
|
2013-06-21 14:41:31 +08:00
|
|
|
isl_val *v;
|
|
|
|
isl_ctx *Ctx = isl_map_get_ctx(Map);
|
2011-10-06 08:03:35 +08:00
|
|
|
isl_constraint *c = isl_inequality_alloc(isl_local_space_copy(MapLocalSpace));
|
2013-06-21 14:41:31 +08:00
|
|
|
v = isl_val_int_from_si(Ctx, -1);
|
|
|
|
c = isl_constraint_set_coefficient_val(c, isl_dim_in, lastDimension, v);
|
|
|
|
v = isl_val_int_from_si(Ctx, 1);
|
|
|
|
c = isl_constraint_set_coefficient_val(c, isl_dim_out, lastDimension, v);
|
|
|
|
v = isl_val_int_from_si(Ctx, -1);
|
|
|
|
c = isl_constraint_set_constant_val(c, v);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-02-01 22:23:36 +08:00
|
|
|
Map = isl_map_add_constraint(Map, c);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-10-17 16:32:36 +08:00
|
|
|
isl_local_space_free(MapLocalSpace);
|
2012-02-01 22:23:36 +08:00
|
|
|
return Map;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 15:46:06 +08:00
|
|
|
isl_set *MemoryAccess::getStride(__isl_take const isl_map *Schedule) const {
|
2013-02-05 20:09:06 +08:00
|
|
|
isl_map *S = const_cast<isl_map *>(Schedule);
|
2012-12-18 15:46:06 +08:00
|
|
|
isl_map *AccessRelation = getAccessRelation();
|
|
|
|
isl_space *Space = isl_space_range(isl_map_get_space(S));
|
|
|
|
isl_map *NextScatt = getEqualAndLarger(Space);
|
|
|
|
|
|
|
|
S = isl_map_reverse(S);
|
|
|
|
NextScatt = isl_map_lexmin(NextScatt);
|
|
|
|
|
|
|
|
NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(S));
|
|
|
|
NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(AccessRelation));
|
|
|
|
NextScatt = isl_map_apply_domain(NextScatt, S);
|
|
|
|
NextScatt = isl_map_apply_domain(NextScatt, AccessRelation);
|
|
|
|
|
|
|
|
isl_set *Deltas = isl_map_deltas(NextScatt);
|
|
|
|
return Deltas;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 15:46:06 +08:00
|
|
|
bool MemoryAccess::isStrideX(__isl_take const isl_map *Schedule,
|
2012-01-25 00:42:16 +08:00
|
|
|
int StrideWidth) const {
|
|
|
|
isl_set *Stride, *StrideX;
|
|
|
|
bool IsStrideX;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-12-18 15:46:06 +08:00
|
|
|
Stride = getStride(Schedule);
|
2012-01-25 00:42:16 +08:00
|
|
|
StrideX = isl_set_universe(isl_set_get_space(Stride));
|
|
|
|
StrideX = isl_set_fix_si(StrideX, isl_dim_set, 0, StrideWidth);
|
|
|
|
IsStrideX = isl_set_is_equal(Stride, StrideX);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-01-25 00:42:16 +08:00
|
|
|
isl_set_free(StrideX);
|
2012-01-18 04:34:27 +08:00
|
|
|
isl_set_free(Stride);
|
2011-08-20 19:11:25 +08:00
|
|
|
|
2012-01-25 00:42:16 +08:00
|
|
|
return IsStrideX;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 15:46:06 +08:00
|
|
|
bool MemoryAccess::isStrideZero(const isl_map *Schedule) const {
|
|
|
|
return isStrideX(Schedule, 0);
|
2012-01-25 00:42:16 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-12-18 15:46:06 +08:00
|
|
|
bool MemoryAccess::isStrideOne(const isl_map *Schedule) const {
|
|
|
|
return isStrideX(Schedule, 1);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2011-10-06 08:04:11 +08:00
|
|
|
void MemoryAccess::setNewAccessRelation(isl_map *newAccess) {
|
2011-08-20 19:11:25 +08:00
|
|
|
isl_map_free(newAccessRelation);
|
2011-08-03 21:47:59 +08:00
|
|
|
newAccessRelation = newAccess;
|
2011-07-13 01:14:03 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2011-10-06 08:04:05 +08:00
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
isl_map *ScopStmt::getScattering() const { return isl_map_copy(Scattering); }
|
2011-10-06 08:04:05 +08:00
|
|
|
|
|
|
|
void ScopStmt::setScattering(isl_map *NewScattering) {
|
2011-08-20 19:11:25 +08:00
|
|
|
isl_map_free(Scattering);
|
2011-10-06 08:04:05 +08:00
|
|
|
Scattering = NewScattering;
|
2011-08-20 19:11:25 +08:00
|
|
|
}
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
void ScopStmt::buildScattering(SmallVectorImpl<unsigned> &Scatter) {
|
2012-01-18 04:34:23 +08:00
|
|
|
unsigned NbIterators = getNumIterators();
|
|
|
|
unsigned NbScatteringDims = Parent.getMaxLoopDepth() * 2 + 1;
|
|
|
|
|
2012-05-29 17:29:44 +08:00
|
|
|
isl_space *Space = isl_space_set_alloc(getIslCtx(), 0, NbScatteringDims);
|
2011-10-06 08:03:35 +08:00
|
|
|
Space = isl_space_set_tuple_name(Space, isl_dim_out, "scattering");
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-05-29 17:29:44 +08:00
|
|
|
Scattering = isl_map_from_domain_and_range(isl_set_universe(getDomainSpace()),
|
|
|
|
isl_set_universe(Space));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-01-18 04:34:23 +08:00
|
|
|
// Loop dimensions.
|
|
|
|
for (unsigned i = 0; i < NbIterators; ++i)
|
2013-02-05 20:09:06 +08:00
|
|
|
Scattering =
|
|
|
|
isl_map_equate(Scattering, isl_dim_out, 2 * i + 1, isl_dim_in, i);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
// Constant dimensions
|
2012-01-18 04:34:23 +08:00
|
|
|
for (unsigned i = 0; i < NbIterators + 1; ++i)
|
|
|
|
Scattering = isl_map_fix_si(Scattering, isl_dim_out, 2 * i, Scatter[i]);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
// Fill scattering dimensions.
|
2012-01-18 04:34:23 +08:00
|
|
|
for (unsigned i = 2 * NbIterators + 1; i < NbScatteringDims; ++i)
|
|
|
|
Scattering = isl_map_fix_si(Scattering, isl_dim_out, i, 0);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-10-06 08:03:42 +08:00
|
|
|
Scattering = isl_map_align_params(Scattering, Parent.getParamSpace());
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScopStmt::buildAccesses(TempScop &tempScop, const Region &CurRegion) {
|
|
|
|
const AccFuncSetType *AccFuncs = tempScop.getAccessFunctions(BB);
|
|
|
|
|
|
|
|
for (AccFuncSetType::const_iterator I = AccFuncs->begin(),
|
2013-02-05 20:09:06 +08:00
|
|
|
E = AccFuncs->end();
|
|
|
|
I != E; ++I) {
|
2012-07-06 14:47:03 +08:00
|
|
|
MemAccs.push_back(new MemoryAccess(I->first, I->second, this));
|
2013-07-24 14:10:30 +08:00
|
|
|
assert(!InstructionToAccess.count(I->second) &&
|
|
|
|
"Unexpected 1-to-N mapping on instruction to access map!");
|
2011-04-29 14:27:02 +08:00
|
|
|
InstructionToAccess[I->second] = MemAccs.back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:41:08 +08:00
|
|
|
void ScopStmt::realignParams() {
|
|
|
|
for (memacc_iterator MI = memacc_begin(), ME = memacc_end(); MI != ME; ++MI)
|
|
|
|
(*MI)->realignParams();
|
|
|
|
|
|
|
|
Domain = isl_set_align_params(Domain, Parent.getParamSpace());
|
|
|
|
Scattering = isl_map_align_params(Scattering, Parent.getParamSpace());
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:41:19 +08:00
|
|
|
__isl_give isl_set *ScopStmt::buildConditionSet(const Comparison &Comp) {
|
2011-11-10 06:34:44 +08:00
|
|
|
isl_pw_aff *L = SCEVAffinator::getPwAff(this, Comp.getLHS());
|
|
|
|
isl_pw_aff *R = SCEVAffinator::getPwAff(this, Comp.getRHS());
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-08-18 15:51:40 +08:00
|
|
|
switch (Comp.getPred()) {
|
2011-04-29 14:27:02 +08:00
|
|
|
case ICmpInst::ICMP_EQ:
|
2011-10-24 04:59:20 +08:00
|
|
|
return isl_pw_aff_eq_set(L, R);
|
2011-04-29 14:27:02 +08:00
|
|
|
case ICmpInst::ICMP_NE:
|
2011-10-24 04:59:20 +08:00
|
|
|
return isl_pw_aff_ne_set(L, R);
|
2011-04-29 14:27:02 +08:00
|
|
|
case ICmpInst::ICMP_SLT:
|
2011-10-24 04:59:20 +08:00
|
|
|
return isl_pw_aff_lt_set(L, R);
|
2011-04-29 14:27:02 +08:00
|
|
|
case ICmpInst::ICMP_SLE:
|
2011-10-24 04:59:20 +08:00
|
|
|
return isl_pw_aff_le_set(L, R);
|
2011-08-18 15:51:40 +08:00
|
|
|
case ICmpInst::ICMP_SGT:
|
2011-10-24 04:59:20 +08:00
|
|
|
return isl_pw_aff_gt_set(L, R);
|
2011-04-29 14:27:02 +08:00
|
|
|
case ICmpInst::ICMP_SGE:
|
2011-10-24 04:59:20 +08:00
|
|
|
return isl_pw_aff_ge_set(L, R);
|
2011-08-18 15:51:40 +08:00
|
|
|
case ICmpInst::ICMP_ULT:
|
|
|
|
case ICmpInst::ICMP_UGT:
|
|
|
|
case ICmpInst::ICMP_ULE:
|
2011-04-29 14:27:02 +08:00
|
|
|
case ICmpInst::ICMP_UGE:
|
2011-08-18 15:51:40 +08:00
|
|
|
llvm_unreachable("Unsigned comparisons not yet supported");
|
2011-04-29 14:27:02 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Non integer predicate not supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-07 16:46:57 +08:00
|
|
|
__isl_give isl_set *ScopStmt::addLoopBoundsToDomain(__isl_take isl_set *Domain,
|
2011-11-08 23:41:28 +08:00
|
|
|
TempScop &tempScop) {
|
2011-10-07 16:46:57 +08:00
|
|
|
isl_space *Space;
|
|
|
|
isl_local_space *LocalSpace;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-10-07 16:46:57 +08:00
|
|
|
Space = isl_set_get_space(Domain);
|
|
|
|
LocalSpace = isl_local_space_from_space(Space);
|
2011-10-06 08:03:35 +08:00
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
for (int i = 0, e = getNumIterators(); i != e; ++i) {
|
2011-10-07 06:32:58 +08:00
|
|
|
isl_aff *Zero = isl_aff_zero_on_domain(isl_local_space_copy(LocalSpace));
|
2013-02-05 20:09:06 +08:00
|
|
|
isl_pw_aff *IV =
|
|
|
|
isl_pw_aff_from_aff(isl_aff_set_coefficient_si(Zero, isl_dim_in, i, 1));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-10-07 06:32:58 +08:00
|
|
|
// 0 <= IV.
|
|
|
|
isl_set *LowerBound = isl_pw_aff_nonneg_set(isl_pw_aff_copy(IV));
|
|
|
|
Domain = isl_set_intersect(Domain, LowerBound);
|
|
|
|
|
|
|
|
// IV <= LatchExecutions.
|
2011-04-30 11:26:51 +08:00
|
|
|
const Loop *L = getLoopForDimension(i);
|
2011-11-03 05:37:51 +08:00
|
|
|
const SCEV *LatchExecutions = tempScop.getLoopBound(L);
|
2011-10-07 06:32:58 +08:00
|
|
|
isl_pw_aff *UpperBound = SCEVAffinator::getPwAff(this, LatchExecutions);
|
|
|
|
isl_set *UpperBoundSet = isl_pw_aff_le_set(IV, UpperBound);
|
2011-04-29 14:27:02 +08:00
|
|
|
Domain = isl_set_intersect(Domain, UpperBoundSet);
|
|
|
|
}
|
|
|
|
|
2011-10-06 08:03:35 +08:00
|
|
|
isl_local_space_free(LocalSpace);
|
2011-10-07 16:46:57 +08:00
|
|
|
return Domain;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-05-07 15:30:56 +08:00
|
|
|
__isl_give isl_set *ScopStmt::addConditionsToDomain(__isl_take isl_set *Domain,
|
|
|
|
TempScop &tempScop,
|
|
|
|
const Region &CurRegion) {
|
2011-10-07 16:46:57 +08:00
|
|
|
const Region *TopRegion = tempScop.getMaxRegion().getParent(),
|
2013-04-10 14:55:45 +08:00
|
|
|
*CurrentRegion = &CurRegion;
|
2011-10-07 16:46:57 +08:00
|
|
|
const BasicBlock *BranchingBB = BB;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
do {
|
2011-10-07 16:46:57 +08:00
|
|
|
if (BranchingBB != CurrentRegion->getEntry()) {
|
|
|
|
if (const BBCond *Condition = tempScop.getBBCond(BranchingBB))
|
|
|
|
for (BBCond::const_iterator CI = Condition->begin(),
|
2013-02-05 20:09:06 +08:00
|
|
|
CE = Condition->end();
|
|
|
|
CI != CE; ++CI) {
|
2011-10-24 04:59:20 +08:00
|
|
|
isl_set *ConditionSet = buildConditionSet(*CI);
|
2011-10-07 16:46:57 +08:00
|
|
|
Domain = isl_set_intersect(Domain, ConditionSet);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 16:46:57 +08:00
|
|
|
BranchingBB = CurrentRegion->getEntry();
|
|
|
|
CurrentRegion = CurrentRegion->getParent();
|
|
|
|
} while (TopRegion != CurrentRegion);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-10-07 16:46:57 +08:00
|
|
|
return Domain;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-05-07 15:30:56 +08:00
|
|
|
__isl_give isl_set *ScopStmt::buildDomain(TempScop &tempScop,
|
|
|
|
const Region &CurRegion) {
|
2011-10-07 16:46:57 +08:00
|
|
|
isl_space *Space;
|
|
|
|
isl_set *Domain;
|
2012-05-29 17:29:44 +08:00
|
|
|
isl_id *Id;
|
2011-10-07 16:46:57 +08:00
|
|
|
|
|
|
|
Space = isl_space_set_alloc(getIslCtx(), 0, getNumIterators());
|
|
|
|
|
2012-05-29 17:29:44 +08:00
|
|
|
Id = isl_id_alloc(getIslCtx(), getBaseName(), this);
|
|
|
|
|
2011-10-07 16:46:57 +08:00
|
|
|
Domain = isl_set_universe(Space);
|
|
|
|
Domain = addLoopBoundsToDomain(Domain, tempScop);
|
|
|
|
Domain = addConditionsToDomain(Domain, tempScop, CurRegion);
|
2012-05-29 17:29:44 +08:00
|
|
|
Domain = isl_set_set_tuple_id(Domain, Id);
|
2011-10-07 16:46:57 +08:00
|
|
|
|
|
|
|
return Domain;
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
ScopStmt::ScopStmt(Scop &parent, TempScop &tempScop, const Region &CurRegion,
|
2013-02-16 05:26:44 +08:00
|
|
|
BasicBlock &bb, SmallVectorImpl<Loop *> &Nest,
|
2011-04-29 14:27:02 +08:00
|
|
|
SmallVectorImpl<unsigned> &Scatter)
|
2013-03-23 09:05:07 +08:00
|
|
|
: Parent(parent), BB(&bb), IVS(Nest.size()), NestLoops(Nest.size()) {
|
2011-04-29 14:27:02 +08:00
|
|
|
// Setup the induction variables.
|
2013-02-16 05:26:44 +08:00
|
|
|
for (unsigned i = 0, e = Nest.size(); i < e; ++i) {
|
2013-03-23 06:07:43 +08:00
|
|
|
if (!SCEVCodegen) {
|
|
|
|
PHINode *PN = Nest[i]->getCanonicalInductionVariable();
|
|
|
|
assert(PN && "Non canonical IV in Scop!");
|
2013-03-22 00:14:50 +08:00
|
|
|
IVS[i] = PN;
|
2013-03-23 06:07:43 +08:00
|
|
|
}
|
2013-02-16 05:26:44 +08:00
|
|
|
NestLoops[i] = Nest[i];
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
raw_string_ostream OS(BaseName);
|
2014-01-09 18:42:15 +08:00
|
|
|
bb.printAsOperand(OS, false);
|
2011-04-29 14:27:02 +08:00
|
|
|
BaseName = OS.str();
|
|
|
|
|
|
|
|
makeIslCompatible(BaseName);
|
|
|
|
BaseName = "Stmt_" + BaseName;
|
|
|
|
|
2011-10-07 16:46:57 +08:00
|
|
|
Domain = buildDomain(tempScop, CurRegion);
|
2011-04-29 14:27:02 +08:00
|
|
|
buildScattering(Scatter);
|
|
|
|
buildAccesses(tempScop, CurRegion);
|
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
std::string ScopStmt::getDomainStr() const { return stringFromIslObj(Domain); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
std::string ScopStmt::getScatteringStr() const {
|
2011-10-06 08:04:05 +08:00
|
|
|
return stringFromIslObj(Scattering);
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
unsigned ScopStmt::getNumParams() const { return Parent.getNumParams(); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
unsigned ScopStmt::getNumIterators() const {
|
|
|
|
// The final read has one dimension with one element.
|
|
|
|
if (!BB)
|
|
|
|
return 1;
|
|
|
|
|
2013-02-16 05:26:44 +08:00
|
|
|
return NestLoops.size();
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ScopStmt::getNumScattering() const {
|
|
|
|
return isl_map_dim(Scattering, isl_dim_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ScopStmt::getBaseName() const { return BaseName.c_str(); }
|
|
|
|
|
2013-02-05 20:09:06 +08:00
|
|
|
const PHINode *
|
|
|
|
ScopStmt::getInductionVariableForDimension(unsigned Dimension) const {
|
2013-02-16 05:26:48 +08:00
|
|
|
return IVS[Dimension];
|
2011-04-30 11:26:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Loop *ScopStmt::getLoopForDimension(unsigned Dimension) const {
|
2013-02-16 05:26:44 +08:00
|
|
|
return NestLoops[Dimension];
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
isl_ctx *ScopStmt::getIslCtx() const { return Parent.getIslCtx(); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
isl_set *ScopStmt::getDomain() const { return isl_set_copy(Domain); }
|
2011-05-07 03:52:19 +08:00
|
|
|
|
2012-01-18 04:34:23 +08:00
|
|
|
isl_space *ScopStmt::getDomainSpace() const {
|
|
|
|
return isl_set_get_space(Domain);
|
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
isl_id *ScopStmt::getDomainId() const { return isl_set_get_tuple_id(Domain); }
|
2012-08-30 19:49:38 +08:00
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
ScopStmt::~ScopStmt() {
|
|
|
|
while (!MemAccs.empty()) {
|
|
|
|
delete MemAccs.back();
|
|
|
|
MemAccs.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
isl_set_free(Domain);
|
|
|
|
isl_map_free(Scattering);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopStmt::print(raw_ostream &OS) const {
|
|
|
|
OS << "\t" << getBaseName() << "\n";
|
|
|
|
|
|
|
|
OS.indent(12) << "Domain :=\n";
|
|
|
|
|
|
|
|
if (Domain) {
|
|
|
|
OS.indent(16) << getDomainStr() << ";\n";
|
|
|
|
} else
|
|
|
|
OS.indent(16) << "n/a\n";
|
|
|
|
|
|
|
|
OS.indent(12) << "Scattering :=\n";
|
|
|
|
|
|
|
|
if (Domain) {
|
|
|
|
OS.indent(16) << getScatteringStr() << ";\n";
|
|
|
|
} else
|
|
|
|
OS.indent(16) << "n/a\n";
|
|
|
|
|
|
|
|
for (MemoryAccessVec::const_iterator I = MemAccs.begin(), E = MemAccs.end();
|
2012-12-30 07:47:38 +08:00
|
|
|
I != E; ++I)
|
2011-04-29 14:27:02 +08:00
|
|
|
(*I)->print(OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopStmt::dump() const { print(dbgs()); }
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// Scop class implement
|
2011-11-08 23:41:28 +08:00
|
|
|
|
2011-11-17 20:56:10 +08:00
|
|
|
void Scop::setContext(__isl_take isl_set *NewContext) {
|
2011-11-15 19:38:44 +08:00
|
|
|
NewContext = isl_set_align_params(NewContext, isl_set_get_space(Context));
|
|
|
|
isl_set_free(Context);
|
|
|
|
Context = NewContext;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:09:06 +08:00
|
|
|
void Scop::addParams(std::vector<const SCEV *> NewParameters) {
|
|
|
|
for (std::vector<const SCEV *>::iterator PI = NewParameters.begin(),
|
|
|
|
PE = NewParameters.end();
|
|
|
|
PI != PE; ++PI) {
|
2011-11-08 23:41:28 +08:00
|
|
|
const SCEV *Parameter = *PI;
|
|
|
|
|
|
|
|
if (ParameterIds.find(Parameter) != ParameterIds.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int dimension = Parameters.size();
|
|
|
|
|
|
|
|
Parameters.push_back(Parameter);
|
|
|
|
ParameterIds[Parameter] = dimension;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:41:03 +08:00
|
|
|
__isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) const {
|
|
|
|
ParamIdType::const_iterator IdIter = ParameterIds.find(Parameter);
|
2011-11-07 20:58:59 +08:00
|
|
|
|
2011-11-08 23:41:03 +08:00
|
|
|
if (IdIter == ParameterIds.end())
|
|
|
|
return NULL;
|
2011-11-07 20:58:59 +08:00
|
|
|
|
2011-11-15 19:38:55 +08:00
|
|
|
std::string ParameterName;
|
|
|
|
|
|
|
|
if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) {
|
|
|
|
Value *Val = ValueParameter->getValue();
|
2011-11-17 22:52:36 +08:00
|
|
|
ParameterName = Val->getName();
|
2011-11-15 19:38:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ParameterName == "" || ParameterName.substr(0, 2) == "p_")
|
2012-04-25 16:01:38 +08:00
|
|
|
ParameterName = "p_" + utostr_32(IdIter->second);
|
2011-11-15 19:38:55 +08:00
|
|
|
|
2013-02-05 20:09:06 +08:00
|
|
|
return isl_id_alloc(getIslCtx(), ParameterName.c_str(), (void *)Parameter);
|
2011-11-07 20:58:59 +08:00
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-11-08 23:41:13 +08:00
|
|
|
void Scop::buildContext() {
|
|
|
|
isl_space *Space = isl_space_params_alloc(IslCtx, 0);
|
2013-10-30 05:05:49 +08:00
|
|
|
Context = isl_set_universe(isl_space_copy(Space));
|
|
|
|
AssumedContext = isl_set_universe(Space);
|
2011-10-06 08:03:48 +08:00
|
|
|
}
|
|
|
|
|
2012-05-22 18:47:27 +08:00
|
|
|
void Scop::addParameterBounds() {
|
|
|
|
for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) {
|
2013-06-21 14:41:31 +08:00
|
|
|
isl_val *V;
|
2012-05-22 18:47:27 +08:00
|
|
|
isl_id *Id;
|
|
|
|
const SCEV *Scev;
|
|
|
|
const IntegerType *T;
|
|
|
|
|
|
|
|
Id = isl_set_get_dim_id(Context, isl_dim_param, i);
|
2013-02-05 20:09:06 +08:00
|
|
|
Scev = (const SCEV *)isl_id_get_user(Id);
|
2012-05-22 18:47:27 +08:00
|
|
|
T = dyn_cast<IntegerType>(Scev->getType());
|
|
|
|
isl_id_free(Id);
|
|
|
|
|
|
|
|
assert(T && "Not an integer type");
|
|
|
|
int Width = T->getBitWidth();
|
|
|
|
|
2013-06-21 14:41:31 +08:00
|
|
|
V = isl_val_int_from_si(IslCtx, Width - 1);
|
|
|
|
V = isl_val_2exp(V);
|
|
|
|
V = isl_val_neg(V);
|
|
|
|
Context = isl_set_lower_bound_val(Context, isl_dim_param, i, V);
|
2012-05-22 18:47:27 +08:00
|
|
|
|
2013-06-21 14:41:31 +08:00
|
|
|
V = isl_val_int_from_si(IslCtx, Width - 1);
|
|
|
|
V = isl_val_2exp(V);
|
|
|
|
V = isl_val_sub_ui(V, 1);
|
|
|
|
Context = isl_set_upper_bound_val(Context, isl_dim_param, i, V);
|
2012-05-22 18:47:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:41:08 +08:00
|
|
|
void Scop::realignParams() {
|
2011-11-08 23:41:13 +08:00
|
|
|
// Add all parameters into a common model.
|
2011-11-08 23:41:28 +08:00
|
|
|
isl_space *Space = isl_space_params_alloc(IslCtx, ParameterIds.size());
|
2011-11-08 23:41:13 +08:00
|
|
|
|
|
|
|
for (ParamIdType::iterator PI = ParameterIds.begin(), PE = ParameterIds.end();
|
|
|
|
PI != PE; ++PI) {
|
|
|
|
const SCEV *Parameter = PI->first;
|
|
|
|
isl_id *id = getIdForParam(Parameter);
|
|
|
|
Space = isl_space_set_dim_id(Space, isl_dim_param, PI->second, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Align the parameters of all data structures to the model.
|
|
|
|
Context = isl_set_align_params(Context, Space);
|
|
|
|
|
2011-11-08 23:41:08 +08:00
|
|
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
|
|
|
(*I)->realignParams();
|
|
|
|
}
|
|
|
|
|
2011-10-06 08:03:48 +08:00
|
|
|
Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution,
|
|
|
|
isl_ctx *Context)
|
2013-02-05 20:09:06 +08:00
|
|
|
: SE(&ScalarEvolution), R(tempScop.getMaxRegion()),
|
|
|
|
MaxLoopDepth(tempScop.getMaxLoopDepth()) {
|
2011-11-08 23:41:03 +08:00
|
|
|
IslCtx = Context;
|
2011-11-08 23:41:13 +08:00
|
|
|
buildContext();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2013-02-05 20:09:06 +08:00
|
|
|
SmallVector<Loop *, 8> NestLoops;
|
2011-04-29 14:27:02 +08:00
|
|
|
SmallVector<unsigned, 8> Scatter;
|
|
|
|
|
|
|
|
Scatter.assign(MaxLoopDepth + 1, 0);
|
|
|
|
|
|
|
|
// Build the iteration domain, access functions and scattering functions
|
|
|
|
// traversing the region tree.
|
|
|
|
buildScop(tempScop, getRegion(), NestLoops, Scatter, LI);
|
|
|
|
|
2011-11-08 23:41:08 +08:00
|
|
|
realignParams();
|
2012-05-22 18:47:27 +08:00
|
|
|
addParameterBounds();
|
2011-11-08 23:41:08 +08:00
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
assert(NestLoops.empty() && "NestLoops not empty at top level!");
|
|
|
|
}
|
|
|
|
|
|
|
|
Scop::~Scop() {
|
|
|
|
isl_set_free(Context);
|
2013-10-30 05:05:49 +08:00
|
|
|
isl_set_free(AssumedContext);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
// Free the statements;
|
|
|
|
for (iterator I = begin(), E = end(); I != E; ++I)
|
|
|
|
delete *I;
|
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
std::string Scop::getContextStr() const { return stringFromIslObj(Context); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
std::string Scop::getNameStr() const {
|
|
|
|
std::string ExitName, EntryName;
|
|
|
|
raw_string_ostream ExitStr(ExitName);
|
|
|
|
raw_string_ostream EntryStr(EntryName);
|
|
|
|
|
2014-01-09 18:42:15 +08:00
|
|
|
R.getEntry()->printAsOperand(EntryStr, false);
|
2011-04-29 14:27:02 +08:00
|
|
|
EntryStr.str();
|
|
|
|
|
|
|
|
if (R.getExit()) {
|
2014-01-09 18:42:15 +08:00
|
|
|
R.getExit()->printAsOperand(ExitStr, false);
|
2011-04-29 14:27:02 +08:00
|
|
|
ExitStr.str();
|
|
|
|
} else
|
|
|
|
ExitName = "FunctionExit";
|
|
|
|
|
|
|
|
return EntryName + "---" + ExitName;
|
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
__isl_give isl_set *Scop::getContext() const { return isl_set_copy(Context); }
|
2011-10-06 08:03:42 +08:00
|
|
|
__isl_give isl_space *Scop::getParamSpace() const {
|
|
|
|
return isl_set_get_space(this->Context);
|
|
|
|
}
|
|
|
|
|
2013-10-30 05:05:49 +08:00
|
|
|
__isl_give isl_set *Scop::getAssumedContext() const {
|
|
|
|
return isl_set_copy(AssumedContext);
|
|
|
|
}
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
void Scop::printContext(raw_ostream &OS) const {
|
|
|
|
OS << "Context:\n";
|
|
|
|
|
|
|
|
if (!Context) {
|
|
|
|
OS.indent(4) << "n/a\n\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS.indent(4) << getContextStr() << "\n";
|
2011-11-08 23:41:28 +08:00
|
|
|
|
|
|
|
for (ParamVecType::const_iterator PI = Parameters.begin(),
|
2013-02-05 20:09:06 +08:00
|
|
|
PE = Parameters.end();
|
|
|
|
PI != PE; ++PI) {
|
2011-11-08 23:41:28 +08:00
|
|
|
const SCEV *Parameter = *PI;
|
|
|
|
int Dim = ParameterIds.find(Parameter)->second;
|
|
|
|
|
|
|
|
OS.indent(4) << "p" << Dim << ": " << *Parameter << "\n";
|
|
|
|
}
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scop::printStatements(raw_ostream &OS) const {
|
|
|
|
OS << "Statements {\n";
|
|
|
|
|
2012-12-30 07:47:38 +08:00
|
|
|
for (const_iterator SI = begin(), SE = end(); SI != SE; ++SI)
|
2011-04-29 14:27:02 +08:00
|
|
|
OS.indent(4) << (**SI);
|
|
|
|
|
|
|
|
OS.indent(4) << "}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scop::print(raw_ostream &OS) const {
|
|
|
|
printContext(OS.indent(4));
|
|
|
|
printStatements(OS.indent(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scop::dump() const { print(dbgs()); }
|
|
|
|
|
2011-11-08 23:41:03 +08:00
|
|
|
isl_ctx *Scop::getIslCtx() const { return IslCtx; }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-02-14 22:02:40 +08:00
|
|
|
__isl_give isl_union_set *Scop::getDomains() {
|
|
|
|
isl_union_set *Domain = NULL;
|
|
|
|
|
|
|
|
for (Scop::iterator SI = begin(), SE = end(); SI != SE; ++SI)
|
2012-03-08 23:21:51 +08:00
|
|
|
if (!Domain)
|
2012-02-14 22:02:40 +08:00
|
|
|
Domain = isl_union_set_from_set((*SI)->getDomain());
|
|
|
|
else
|
|
|
|
Domain = isl_union_set_union(Domain,
|
2013-02-05 20:09:06 +08:00
|
|
|
isl_union_set_from_set((*SI)->getDomain()));
|
2012-02-14 22:02:40 +08:00
|
|
|
|
|
|
|
return Domain;
|
|
|
|
}
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
ScalarEvolution *Scop::getSE() const { return SE; }
|
|
|
|
|
|
|
|
bool Scop::isTrivialBB(BasicBlock *BB, TempScop &tempScop) {
|
|
|
|
if (tempScop.getAccessFunctions(BB))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-15 06:40:23 +08:00
|
|
|
void Scop::buildScop(TempScop &tempScop, const Region &CurRegion,
|
|
|
|
SmallVectorImpl<Loop *> &NestLoops,
|
|
|
|
SmallVectorImpl<unsigned> &Scatter, LoopInfo &LI) {
|
2011-04-29 14:27:02 +08:00
|
|
|
Loop *L = castToLoop(CurRegion, LI);
|
|
|
|
|
|
|
|
if (L)
|
|
|
|
NestLoops.push_back(L);
|
|
|
|
|
|
|
|
unsigned loopDepth = NestLoops.size();
|
|
|
|
assert(Scatter.size() > loopDepth && "Scatter not big enough!");
|
|
|
|
|
|
|
|
for (Region::const_element_iterator I = CurRegion.element_begin(),
|
2013-02-05 20:09:06 +08:00
|
|
|
E = CurRegion.element_end();
|
|
|
|
I != E; ++I)
|
2011-04-29 14:27:02 +08:00
|
|
|
if (I->isSubRegion())
|
|
|
|
buildScop(tempScop, *(I->getNodeAs<Region>()), NestLoops, Scatter, LI);
|
|
|
|
else {
|
|
|
|
BasicBlock *BB = I->getNodeAs<BasicBlock>();
|
|
|
|
|
|
|
|
if (isTrivialBB(BB, tempScop))
|
|
|
|
continue;
|
|
|
|
|
2013-02-05 20:09:06 +08:00
|
|
|
Stmts.push_back(
|
|
|
|
new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, Scatter));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
// Increasing the Scattering function is OK for the moment, because
|
|
|
|
// we are using a depth first iterator and the program is well structured.
|
|
|
|
++Scatter[loopDepth];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!L)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Exiting a loop region.
|
|
|
|
Scatter[loopDepth] = 0;
|
|
|
|
NestLoops.pop_back();
|
2013-01-15 06:40:23 +08:00
|
|
|
++Scatter[loopDepth - 1];
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2011-08-20 19:11:25 +08:00
|
|
|
ScopInfo::ScopInfo() : RegionPass(ID), scop(0) {
|
|
|
|
ctx = isl_ctx_alloc();
|
2011-12-07 15:42:51 +08:00
|
|
|
isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
|
2011-08-20 19:11:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopInfo::~ScopInfo() {
|
|
|
|
clear();
|
|
|
|
isl_ctx_free(ctx);
|
|
|
|
}
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<LoopInfo>();
|
|
|
|
AU.addRequired<RegionInfo>();
|
|
|
|
AU.addRequired<ScalarEvolution>();
|
|
|
|
AU.addRequired<TempScopInfo>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
|
|
|
|
LoopInfo &LI = getAnalysis<LoopInfo>();
|
|
|
|
ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
|
|
|
|
|
|
|
|
TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R);
|
|
|
|
|
|
|
|
// This region is no Scop.
|
|
|
|
if (!tempScop) {
|
|
|
|
scop = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Statistics.
|
|
|
|
++ScopFound;
|
2013-01-15 06:40:23 +08:00
|
|
|
if (tempScop->getMaxLoopDepth() > 0)
|
|
|
|
++RichScopFound;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2011-08-20 19:11:25 +08:00
|
|
|
scop = new Scop(*tempScop, LI, SE, ctx);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char ScopInfo::ID = 0;
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
Pass *polly::createScopInfoPass() { return new ScopInfo(); }
|
|
|
|
|
2011-10-08 08:30:40 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(ScopInfo, "polly-scops",
|
|
|
|
"Polly - Create polyhedral description of Scops", false,
|
2013-03-23 09:05:07 +08:00
|
|
|
false);
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LoopInfo);
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(RegionInfo);
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution);
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TempScopInfo);
|
2011-10-08 08:30:40 +08:00
|
|
|
INITIALIZE_PASS_END(ScopInfo, "polly-scops",
|
|
|
|
"Polly - Create polyhedral description of Scops", false,
|
|
|
|
false)
|