Skip to content

Commit

Permalink
Port ScopInfo to the isl cpp bindings
Browse files Browse the repository at this point in the history
Summary:
Most changes are mechanical, but in one place I changed the program semantics
by fixing a likely bug:

In `Scop::hasFeasibleRuntimeContext()`, I'm now explicitely handling the
error-case. Before, when the call to `addNonEmptyDomainConstraints()`
returned a null set, this (probably) accidentally worked because
isl_bool_error converts to true. I'm checking for nullptr now.

Reviewers: grosser, Meinersbur, bollu

Reviewed By: Meinersbur

Subscribers: nemanjai, kbarton, pollydev, llvm-commits

Differential Revision: https://reviews.llvm.org/D39971

llvm-svn: 318632
  • Loading branch information
pfaffe committed Nov 19, 2017
1 parent 0f45abd commit 00fd43b
Show file tree
Hide file tree
Showing 23 changed files with 233 additions and 308 deletions.
1 change: 0 additions & 1 deletion polly/include/polly/ScheduleOptimizer.h
Expand Up @@ -353,5 +353,4 @@ class ScheduleTreeOptimizer {
/// @param ScheduleRange A range of a map, which describes a prefix schedule
/// relation.
isl::set getPartialTilePrefixes(isl::set ScheduleRange, int VectorWidth);

#endif // POLLY_SCHEDULEOPTIMIZER_H
75 changes: 35 additions & 40 deletions polly/include/polly/ScopInfo.h
Expand Up @@ -40,10 +40,7 @@
#include "llvm/IR/ValueHandle.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "isl/aff.h"
#include "isl/ctx.h"
#include "isl/isl-noexceptions.h"
#include "isl/set.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
Expand Down Expand Up @@ -1174,7 +1171,7 @@ struct InvariantEquivClassTy {
///
/// It is the union of the execution domains of the memory accesses in the
/// InvariantAccesses list.
isl_set *ExecutionContext;
isl::set ExecutionContext;

/// The type of the invariant access
///
Expand Down Expand Up @@ -1326,7 +1323,7 @@ class ScopStmt {

public:
/// Get an isl_ctx pointer.
isl_ctx *getIslCtx() const;
isl::ctx getIslCtx() const;

/// Get the iteration domain of this ScopStmt.
///
Expand Down Expand Up @@ -1680,7 +1677,7 @@ raw_ostream &operator<<(raw_ostream &OS, const ScopStmt &S);
class Scop {
public:
/// Type to represent a pair of minimal/maximal access to an array.
using MinMaxAccessTy = std::pair<isl_pw_multi_aff *, isl_pw_multi_aff *>;
using MinMaxAccessTy = std::pair<isl::pw_multi_aff, isl::pw_multi_aff>;

/// Vector of minimal/maximal accesses to different arrays.
using MinMaxVectorTy = SmallVector<MinMaxAccessTy, 4>;
Expand All @@ -1696,6 +1693,17 @@ class Scop {
private:
friend class ScopBuilder;

/// Isl context.
///
/// We need a shared_ptr with reference counter to delete the context when all
/// isl objects are deleted. We will distribute the shared_ptr to all objects
/// that use the context to create isl objects, and increase the reference
/// counter. By doing this, we guarantee that the context is deleted when we
/// delete the last object that creates isl objects with the context. This
/// declaration needs to be the first in class to gracefully destroy all isl
/// objects before the context.
std::shared_ptr<isl_ctx> IslCtx;

ScalarEvolution *SE;
DominatorTree *DT;

Expand Down Expand Up @@ -1751,15 +1759,6 @@ class Scop {
/// OptimizationRemarkEmitter object for displaying diagnostic remarks
OptimizationRemarkEmitter &ORE;

/// Isl context.
///
/// We need a shared_ptr with reference counter to delete the context when all
/// isl objects are deleted. We will distribute the shared_ptr to all objects
/// that use the context to create isl objects, and increase the reference
/// counter. By doing this, we guarantee that the context is deleted when we
/// delete the last object that creates isl objects with the context.
std::shared_ptr<isl_ctx> IslCtx;

/// A map from basic blocks to vector of SCoP statements. Currently this
/// vector comprises only of a single statement.
DenseMap<BasicBlock *, std::vector<ScopStmt *>> StmtMap;
Expand All @@ -1771,7 +1770,7 @@ class Scop {
DenseMap<BasicBlock *, isl::set> DomainMap;

/// Constraints on parameters.
isl_set *Context = nullptr;
isl::set Context = nullptr;

/// The affinator used to translate SCEVs to isl expressions.
SCEVAffinator Affinator;
Expand Down Expand Up @@ -1806,15 +1805,15 @@ class Scop {
/// lot simpler, but which is only valid under certain assumptions. The
/// assumed context records the assumptions taken during the construction of
/// this scop and that need to be code generated as a run-time test.
isl_set *AssumedContext = nullptr;
isl::set AssumedContext;

/// The restrictions under which this SCoP was built.
///
/// The invalid context is similar to the assumed context as it contains
/// constraints over the parameters. However, while we need the constraints
/// in the assumed context to be "true" the constraints in the invalid context
/// need to be "false". Otherwise they behave the same.
isl_set *InvalidContext = nullptr;
isl::set InvalidContext;

/// Helper struct to remember assumptions.
struct Assumption {
Expand All @@ -1825,7 +1824,7 @@ class Scop {
AssumptionSign Sign;

/// The valid/invalid context if this is an assumption/restriction.
isl_set *Set;
isl::set Set;

/// The location that caused this assumption.
DebugLoc Loc;
Expand Down Expand Up @@ -1880,7 +1879,7 @@ class Scop {
/// set of statement instances that will be scheduled in a subtree. There
/// are also several other nodes. A full description of the different nodes
/// in a schedule tree is given in the isl manual.
isl_schedule *Schedule = nullptr;
isl::schedule Schedule = nullptr;

/// The set of minimal/maximal accesses for each alias group.
///
Expand Down Expand Up @@ -2305,14 +2304,13 @@ class Scop {
Loop *L;

// The (possibly incomplete) schedule for this loop.
isl_schedule *Schedule;
isl::schedule Schedule;

// The number of basic blocks in the current loop, for which a schedule has
// already been constructed.
unsigned NumBlocksProcessed;

LoopStackElement(Loop *L, __isl_give isl_schedule *S,
unsigned NumBlocksProcessed)
LoopStackElement(Loop *L, isl::schedule S, unsigned NumBlocksProcessed)
: L(L), Schedule(S), NumBlocksProcessed(NumBlocksProcessed) {}
};

Expand Down Expand Up @@ -2599,7 +2597,7 @@ class Scop {
/// (needed/assumptions) or negative (invalid/restrictions).
///
/// @returns True if the assumption @p Set is not trivial.
bool isEffectiveAssumption(__isl_keep isl_set *Set, AssumptionSign Sign);
bool isEffectiveAssumption(isl::set Set, AssumptionSign Sign);

/// Track and report an assumption.
///
Expand All @@ -2615,8 +2613,8 @@ class Scop {
/// calculate hotness when emitting remark.
///
/// @returns True if the assumption is not trivial.
bool trackAssumption(AssumptionKind Kind, __isl_keep isl_set *Set,
DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB);
bool trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
AssumptionSign Sign, BasicBlock *BB);

/// Add assumptions to assumed context.
///
Expand All @@ -2636,7 +2634,7 @@ class Scop {
/// (needed/assumptions) or negative (invalid/restrictions).
/// @param BB The block in which this assumption was taken. Used to
/// calculate hotness when emitting remark.
void addAssumption(AssumptionKind Kind, __isl_take isl_set *Set, DebugLoc Loc,
void addAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
AssumptionSign Sign, BasicBlock *BB);

/// Record an assumption for later addition to the assumed context.
Expand All @@ -2654,9 +2652,8 @@ class Scop {
/// set, the domain of that block will be used to simplify the
/// actual assumption in @p Set once it is added. This is useful
/// if the assumption was created prior to the domain.
void recordAssumption(AssumptionKind Kind, __isl_take isl_set *Set,
DebugLoc Loc, AssumptionSign Sign,
BasicBlock *BB = nullptr);
void recordAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
AssumptionSign Sign, BasicBlock *BB = nullptr);

/// Add all recorded assumptions to the assumed context.
void addRecordedAssumptions();
Expand All @@ -2679,9 +2676,7 @@ class Scop {
isl::set getInvalidContext() const;

/// Return true if and only if the InvalidContext is trivial (=empty).
bool hasTrivialInvalidContext() const {
return isl_set_is_empty(InvalidContext);
}
bool hasTrivialInvalidContext() const { return InvalidContext.is_empty(); }

/// A vector of memory accesses that belong to an alias group.
using AliasGroupTy = SmallVector<MemoryAccess *, 4>;
Expand Down Expand Up @@ -2867,7 +2862,7 @@ class Scop {
ScopArrayInfoMap.erase(It);
}

void setContext(__isl_take isl_set *NewContext);
void setContext(isl::set NewContext);

/// Align the parameters in the statement to the scop context
void realignParams();
Expand Down Expand Up @@ -2901,7 +2896,7 @@ class Scop {
/// Get the isl context of this static control part.
///
/// @return The isl context of this static control part.
isl_ctx *getIslCtx() const;
isl::ctx getIslCtx() const;

/// Directly return the shared_ptr of the context.
const std::shared_ptr<isl_ctx> &getSharedIslCtx() const { return IslCtx; }
Expand All @@ -2918,8 +2913,8 @@ class Scop {
/// the translation of @p E was deemed to complex the SCoP is invalidated and
/// a dummy value of appropriate dimension is returned. This allows to bail
/// for complex cases without "error handling code" needed on the users side.
__isl_give PWACtx getPwAff(const SCEV *E, BasicBlock *BB = nullptr,
bool NonNegative = false);
PWACtx getPwAff(const SCEV *E, BasicBlock *BB = nullptr,
bool NonNegative = false);

/// Compute the isl representation for the SCEV @p E
///
Expand Down Expand Up @@ -2972,12 +2967,12 @@ class Scop {
/// Update the current schedule
///
/// NewSchedule The new schedule (given as a flat union-map).
void setSchedule(__isl_take isl_union_map *NewSchedule);
void setSchedule(isl::union_map NewSchedule);

/// Update the current schedule
///
/// NewSchedule The new schedule (given as schedule tree).
void setScheduleTree(__isl_take isl_schedule *NewSchedule);
void setScheduleTree(isl::schedule NewSchedule);

/// Intersects the domains of all statements in the SCoP.
///
Expand All @@ -2999,7 +2994,7 @@ class Scop {
/// Check whether @p Schedule contains extension nodes.
///
/// @return true if @p Schedule contains extension nodes.
static bool containsExtensionNode(__isl_keep isl_schedule *Schedule);
static bool containsExtensionNode(isl::schedule Schedule);

/// Simplify the SCoP representation.
///
Expand Down
1 change: 1 addition & 0 deletions polly/include/polly/Support/ISLOStream.h
Expand Up @@ -35,6 +35,7 @@ ADD_OSTREAM_PRINTER(isl::multi_pw_aff)
ADD_OSTREAM_PRINTER(isl::multi_union_pw_aff)
ADD_OSTREAM_PRINTER(isl::point)
ADD_OSTREAM_PRINTER(isl::pw_aff)
ADD_OSTREAM_PRINTER(isl::pw_multi_aff)
ADD_OSTREAM_PRINTER(isl::schedule)
ADD_OSTREAM_PRINTER(isl::schedule_node)
ADD_OSTREAM_PRINTER(isl::space)
Expand Down

0 comments on commit 00fd43b

Please sign in to comment.