2017-02-16 01:19:22 +08:00
|
|
|
//===- DeLICMTest.cpp ----------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "polly/DeLICM.h"
|
2018-07-17 14:08:04 +08:00
|
|
|
#include "polly/Support/ISLTools.h"
|
2017-02-16 01:19:22 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <isl/map.h>
|
|
|
|
#include <isl/set.h>
|
|
|
|
#include <isl/stream.h>
|
|
|
|
#include <isl/union_map.h>
|
|
|
|
#include <isl/union_set.h>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace polly;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// Get the universes of all spaces in @p USet.
|
Introduce isl C++ bindings, Part 1: value_ptr style interface
Over the last couple of months several authors of independent isl C++ bindings
worked together to jointly design an official set of isl C++ bindings which
combines their experience in developing isl C++ bindings. The new bindings have
been designed around a value pointer style interface and remove the need for
explicit pointer managenent and instead use C++ language features to manage isl
objects.
This commit introduces the smart-pointer part of the isl C++ bindings and
replaces the current IslPtr<T> classes, which served the very same purpose, but
had to be manually maintained. Instead, we now rely on automatically generated
classes for each isl object, which provide value_ptr semantics.
An isl object has the following smart pointer interface:
inline set manage(__isl_take isl_set *ptr);
class set {
friend inline set manage(__isl_take isl_set *ptr);
isl_set *ptr = nullptr;
inline explicit set(__isl_take isl_set *ptr);
public:
inline set();
inline set(const set &obj);
inline set &operator=(set obj);
inline ~set();
inline __isl_give isl_set *copy() const &;
inline __isl_give isl_set *copy() && = delete;
inline __isl_keep isl_set *get() const;
inline __isl_give isl_set *release();
inline bool is_null() const;
}
The interface and behavior of the new value pointer style classes is inspired
by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which
proposes a std::value_ptr, a smart pointer that applies value semantics to its
pointee.
We currently only provide a limited set of public constructors and instead
require provide a global overloaded type constructor method "isl::obj
isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by
calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor
for unique pointers.
The next two functions isl::obj::get() and isl::obj::release() are taken
directly from the std::value_ptr proposal:
S.get() extracts the raw pointer of the object managed by S.
S.release() extracts the raw pointer of the object managed by S and sets the
object in S to null.
We additionally add std::obj::copy(). S.copy() returns a raw pointer refering
to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a
functionality commonly needed when interacting directly with the isl C
interface where all methods marked with __isl_take require consumable raw
pointers.
S.is_null() checks if S manages a pointer or if the managed object is currently
null. We add this function to provide a more explicit way to check if the
pointer is empty compared to a direct conversion to bool.
This commit also introduces a couple of polly-specific extensions that cover
features currently not handled by the official isl C++ bindings draft, but
which have been provided by IslPtr<T> and are consequently added to avoid code
churn. These extensions include:
- operator bool() : Conversion from objects to bool
- construction from nullptr_t
- get_ctx() method
- take/keep/give methods, which match the currently used naming
convention of IslPtr<T> in Polly. They just forward to
(release/get/manage).
- raw_ostream printers
We expect that these extensions are over time either removed or upstreamed to
the official isl bindings.
We also export a couple of classes that have not yet been exported in isl (e.g.,
isl::space)
As part of the code review, the following two questions were asked:
- Why do we not use a standard smart pointer?
std::value_ptr was a proposal that has not been accepted. It is consequently
not available in the standard library. Even if it would be available, we want
to expand this interface with a complete method interface that is conveniently
available from each managed pointer. The most direct way to achieve this is to
generate a specialiced value style pointer class for each isl object type and
add any additional methods to this class. The relevant changes follow in
subsequent commits.
- Why do we not use templates or macros to avoid code duplication?
It is certainly possible to use templates or macros, but as this code is
auto-generated there is no need to make writing this code more efficient. Also,
most of these classes will be specialized with individual member functions in
subsequent commits, such that there will be little code reuse to exploit. Hence,
we decided to do so at the moment.
These bindings are not yet officially part of isl, but the draft is already very
stable. The smart pointer interface itself did not change since serveral months.
Adding this code to Polly is against our normal policy of only importing
official isl code. In this case however, we make an exception to showcase a
non-trivial use case of these bindings which should increase confidence in these
bindings and will help upstreaming them to isl.
Tags: #polly
Reviewed By: Meinersbur
Differential Revision: https://reviews.llvm.org/D30325
llvm-svn: 297452
2017-03-10 19:41:03 +08:00
|
|
|
isl::union_set unionSpace(const isl::union_set &USet) {
|
2018-04-29 05:06:14 +08:00
|
|
|
auto Result = isl::union_set::empty(USet.get_space());
|
2018-07-17 14:08:04 +08:00
|
|
|
for (isl::set Set : USet.get_set_list()) {
|
|
|
|
isl::space Space = Set.get_space();
|
|
|
|
isl::set Universe = isl::set::universe(Space);
|
2018-04-29 05:06:14 +08:00
|
|
|
Result = Result.add_set(Universe);
|
2018-07-17 14:08:04 +08:00
|
|
|
}
|
2017-02-16 01:19:22 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-04-14 00:32:46 +08:00
|
|
|
void completeLifetime(isl::union_set Universe, isl::union_map OccupiedAndKnown,
|
|
|
|
isl::union_set &Occupied, isl::union_map &Known,
|
Introduce isl C++ bindings, Part 1: value_ptr style interface
Over the last couple of months several authors of independent isl C++ bindings
worked together to jointly design an official set of isl C++ bindings which
combines their experience in developing isl C++ bindings. The new bindings have
been designed around a value pointer style interface and remove the need for
explicit pointer managenent and instead use C++ language features to manage isl
objects.
This commit introduces the smart-pointer part of the isl C++ bindings and
replaces the current IslPtr<T> classes, which served the very same purpose, but
had to be manually maintained. Instead, we now rely on automatically generated
classes for each isl object, which provide value_ptr semantics.
An isl object has the following smart pointer interface:
inline set manage(__isl_take isl_set *ptr);
class set {
friend inline set manage(__isl_take isl_set *ptr);
isl_set *ptr = nullptr;
inline explicit set(__isl_take isl_set *ptr);
public:
inline set();
inline set(const set &obj);
inline set &operator=(set obj);
inline ~set();
inline __isl_give isl_set *copy() const &;
inline __isl_give isl_set *copy() && = delete;
inline __isl_keep isl_set *get() const;
inline __isl_give isl_set *release();
inline bool is_null() const;
}
The interface and behavior of the new value pointer style classes is inspired
by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which
proposes a std::value_ptr, a smart pointer that applies value semantics to its
pointee.
We currently only provide a limited set of public constructors and instead
require provide a global overloaded type constructor method "isl::obj
isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by
calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor
for unique pointers.
The next two functions isl::obj::get() and isl::obj::release() are taken
directly from the std::value_ptr proposal:
S.get() extracts the raw pointer of the object managed by S.
S.release() extracts the raw pointer of the object managed by S and sets the
object in S to null.
We additionally add std::obj::copy(). S.copy() returns a raw pointer refering
to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a
functionality commonly needed when interacting directly with the isl C
interface where all methods marked with __isl_take require consumable raw
pointers.
S.is_null() checks if S manages a pointer or if the managed object is currently
null. We add this function to provide a more explicit way to check if the
pointer is empty compared to a direct conversion to bool.
This commit also introduces a couple of polly-specific extensions that cover
features currently not handled by the official isl C++ bindings draft, but
which have been provided by IslPtr<T> and are consequently added to avoid code
churn. These extensions include:
- operator bool() : Conversion from objects to bool
- construction from nullptr_t
- get_ctx() method
- take/keep/give methods, which match the currently used naming
convention of IslPtr<T> in Polly. They just forward to
(release/get/manage).
- raw_ostream printers
We expect that these extensions are over time either removed or upstreamed to
the official isl bindings.
We also export a couple of classes that have not yet been exported in isl (e.g.,
isl::space)
As part of the code review, the following two questions were asked:
- Why do we not use a standard smart pointer?
std::value_ptr was a proposal that has not been accepted. It is consequently
not available in the standard library. Even if it would be available, we want
to expand this interface with a complete method interface that is conveniently
available from each managed pointer. The most direct way to achieve this is to
generate a specialiced value style pointer class for each isl object type and
add any additional methods to this class. The relevant changes follow in
subsequent commits.
- Why do we not use templates or macros to avoid code duplication?
It is certainly possible to use templates or macros, but as this code is
auto-generated there is no need to make writing this code more efficient. Also,
most of these classes will be specialized with individual member functions in
subsequent commits, such that there will be little code reuse to exploit. Hence,
we decided to do so at the moment.
These bindings are not yet officially part of isl, but the draft is already very
stable. The smart pointer interface itself did not change since serveral months.
Adding this code to Polly is against our normal policy of only importing
official isl code. In this case however, we make an exception to showcase a
non-trivial use case of these bindings which should increase confidence in these
bindings and will help upstreaming them to isl.
Tags: #polly
Reviewed By: Meinersbur
Differential Revision: https://reviews.llvm.org/D30325
llvm-svn: 297452
2017-03-10 19:41:03 +08:00
|
|
|
isl::union_set &Undef) {
|
2018-04-29 05:06:14 +08:00
|
|
|
auto ParamSpace = Universe.get_space();
|
2017-04-14 00:32:46 +08:00
|
|
|
|
2017-04-25 08:30:42 +08:00
|
|
|
if (Undef && !Occupied) {
|
2017-04-14 00:32:46 +08:00
|
|
|
assert(!Occupied);
|
2018-04-29 05:06:14 +08:00
|
|
|
Occupied = Universe.subtract(Undef);
|
2017-04-25 08:30:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (OccupiedAndKnown) {
|
2017-04-14 00:32:46 +08:00
|
|
|
assert(!Known);
|
|
|
|
|
|
|
|
Known = isl::union_map::empty(ParamSpace);
|
2017-04-25 08:30:42 +08:00
|
|
|
|
|
|
|
if (!Occupied)
|
|
|
|
Occupied = OccupiedAndKnown.domain();
|
|
|
|
|
2018-07-17 14:08:04 +08:00
|
|
|
for (isl::map Map : OccupiedAndKnown.get_map_list()) {
|
2018-04-29 08:28:26 +08:00
|
|
|
if (!Map.has_tuple_name(isl::dim::out))
|
2018-07-17 14:08:04 +08:00
|
|
|
continue;
|
2018-04-29 05:06:14 +08:00
|
|
|
Known = Known.add_map(Map);
|
2018-07-17 14:08:04 +08:00
|
|
|
}
|
2017-04-14 00:32:46 +08:00
|
|
|
}
|
|
|
|
|
2017-02-16 01:19:22 +08:00
|
|
|
if (!Undef) {
|
2017-04-14 00:32:46 +08:00
|
|
|
assert(Occupied);
|
2018-04-29 05:06:14 +08:00
|
|
|
Undef = Universe.subtract(Occupied);
|
2017-04-14 00:32:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!Known) { // By default, nothing is known.
|
|
|
|
Known = isl::union_map::empty(ParamSpace);
|
2017-02-16 01:19:22 +08:00
|
|
|
}
|
2017-04-25 08:30:32 +08:00
|
|
|
|
|
|
|
// Conditions that must hold when returning.
|
|
|
|
assert(Occupied);
|
|
|
|
assert(Undef);
|
|
|
|
assert(Known);
|
2017-02-16 01:19:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *OccupiedStr;
|
|
|
|
const char *UndefStr;
|
|
|
|
const char *WrittenStr;
|
2017-04-14 00:32:16 +08:00
|
|
|
} KnowledgeStr;
|
2017-02-16 01:19:22 +08:00
|
|
|
|
2017-03-20 23:37:32 +08:00
|
|
|
isl::union_set parseSetOrNull(isl_ctx *Ctx, const char *Str) {
|
|
|
|
if (!Str)
|
|
|
|
return nullptr;
|
|
|
|
return isl::union_set(Ctx, Str);
|
|
|
|
}
|
|
|
|
|
2017-04-14 00:32:46 +08:00
|
|
|
isl::union_map parseMapOrNull(isl_ctx *Ctx, const char *Str) {
|
|
|
|
if (!Str)
|
|
|
|
return nullptr;
|
|
|
|
return isl::union_map(Ctx, Str);
|
|
|
|
}
|
2017-02-16 01:19:22 +08:00
|
|
|
|
2017-04-14 00:32:46 +08:00
|
|
|
bool checkIsConflictingNonsymmetricCommon(
|
|
|
|
isl_ctx *Ctx, isl::union_map ExistingOccupiedAndKnown,
|
|
|
|
isl::union_set ExistingUnused, isl::union_map ExistingWritten,
|
|
|
|
isl::union_map ProposedOccupiedAndKnown, isl::union_set ProposedUnused,
|
|
|
|
isl::union_map ProposedWritten) {
|
2017-02-16 01:19:22 +08:00
|
|
|
// Determine universe (set of all possible domains).
|
2018-04-29 05:06:14 +08:00
|
|
|
auto Universe = isl::union_set::empty(isl::space::params_alloc(Ctx, 0));
|
2017-04-14 00:32:46 +08:00
|
|
|
if (ExistingOccupiedAndKnown)
|
2018-04-29 05:06:14 +08:00
|
|
|
Universe = Universe.unite(ExistingOccupiedAndKnown.domain());
|
2017-02-16 01:19:22 +08:00
|
|
|
if (ExistingUnused)
|
2018-04-29 05:06:14 +08:00
|
|
|
Universe = Universe.unite(ExistingUnused);
|
2017-02-16 01:19:22 +08:00
|
|
|
if (ExistingWritten)
|
2018-04-29 05:06:14 +08:00
|
|
|
Universe = Universe.unite(ExistingWritten.domain());
|
2017-04-14 00:32:46 +08:00
|
|
|
if (ProposedOccupiedAndKnown)
|
2018-04-29 05:06:14 +08:00
|
|
|
Universe = Universe.unite(ProposedOccupiedAndKnown.domain());
|
2017-02-16 01:19:22 +08:00
|
|
|
if (ProposedUnused)
|
2018-04-29 05:06:14 +08:00
|
|
|
Universe = Universe.unite(ProposedUnused);
|
2017-02-16 01:19:22 +08:00
|
|
|
if (ProposedWritten)
|
2018-04-29 05:06:14 +08:00
|
|
|
Universe = Universe.unite(ProposedWritten.domain());
|
2017-04-14 00:32:46 +08:00
|
|
|
|
2017-02-16 01:19:22 +08:00
|
|
|
Universe = unionSpace(Universe);
|
|
|
|
|
|
|
|
// Add a space the universe that does not occur anywhere else to ensure
|
|
|
|
// robustness. Use &NewId to ensure that this Id is unique.
|
2018-04-29 05:06:14 +08:00
|
|
|
isl::id NewId = isl::id::alloc(Ctx, "Unrelated", &NewId);
|
2017-02-16 01:19:22 +08:00
|
|
|
// The space must contains at least one dimension to allow order
|
|
|
|
// modifications.
|
2018-04-29 05:06:14 +08:00
|
|
|
auto NewSpace = isl::space(Ctx, 0, 1);
|
|
|
|
NewSpace = NewSpace.set_tuple_id(isl::dim::set, NewId);
|
|
|
|
auto NewSet = isl::set::universe(NewSpace);
|
|
|
|
Universe = Universe.add_set(NewSet);
|
2017-02-16 01:19:22 +08:00
|
|
|
|
|
|
|
// Using the universe, fill missing data.
|
2017-04-14 00:32:46 +08:00
|
|
|
isl::union_set ExistingOccupied;
|
|
|
|
isl::union_map ExistingKnown;
|
|
|
|
completeLifetime(Universe, ExistingOccupiedAndKnown, ExistingOccupied,
|
|
|
|
ExistingKnown, ExistingUnused);
|
|
|
|
|
|
|
|
isl::union_set ProposedOccupied;
|
|
|
|
isl::union_map ProposedKnown;
|
|
|
|
completeLifetime(Universe, ProposedOccupiedAndKnown, ProposedOccupied,
|
|
|
|
ProposedKnown, ProposedUnused);
|
|
|
|
|
|
|
|
auto Result = isConflicting(ExistingOccupied, ExistingUnused, ExistingKnown,
|
|
|
|
ExistingWritten, ProposedOccupied, ProposedUnused,
|
|
|
|
ProposedKnown, ProposedWritten);
|
2017-02-16 01:19:22 +08:00
|
|
|
|
|
|
|
// isConflicting does not require ExistingOccupied nor ProposedUnused and are
|
|
|
|
// implicitly assumed to be the remainder elements. Test the implicitness as
|
|
|
|
// well.
|
|
|
|
EXPECT_EQ(Result,
|
2017-04-14 00:32:46 +08:00
|
|
|
isConflicting(ExistingOccupied, ExistingUnused, ExistingKnown,
|
|
|
|
ExistingWritten, ProposedOccupied, {}, ProposedKnown,
|
|
|
|
ProposedWritten));
|
2017-02-16 01:19:22 +08:00
|
|
|
EXPECT_EQ(Result,
|
2017-04-14 00:32:46 +08:00
|
|
|
isConflicting({}, ExistingUnused, ExistingKnown, ExistingWritten,
|
|
|
|
ProposedOccupied, ProposedUnused, ProposedKnown,
|
|
|
|
ProposedWritten));
|
|
|
|
EXPECT_EQ(Result, isConflicting({}, ExistingUnused, ExistingKnown,
|
|
|
|
ExistingWritten, ProposedOccupied, {},
|
|
|
|
ProposedKnown, ProposedWritten));
|
2017-02-16 01:19:22 +08:00
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-04-14 00:32:46 +08:00
|
|
|
bool checkIsConflictingNonsymmetricKnown(KnowledgeStr Existing,
|
|
|
|
KnowledgeStr Proposed) {
|
|
|
|
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
|
|
|
|
&isl_ctx_free);
|
|
|
|
|
|
|
|
// Parse knowledge.
|
|
|
|
auto ExistingOccupiedAndKnown =
|
|
|
|
parseMapOrNull(Ctx.get(), Existing.OccupiedStr);
|
|
|
|
auto ExistingUnused = parseSetOrNull(Ctx.get(), Existing.UndefStr);
|
|
|
|
auto ExistingWritten = parseMapOrNull(Ctx.get(), Existing.WrittenStr);
|
|
|
|
|
|
|
|
auto ProposedOccupiedAndKnown =
|
|
|
|
parseMapOrNull(Ctx.get(), Proposed.OccupiedStr);
|
|
|
|
auto ProposedUnused = parseSetOrNull(Ctx.get(), Proposed.UndefStr);
|
|
|
|
auto ProposedWritten = parseMapOrNull(Ctx.get(), Proposed.WrittenStr);
|
|
|
|
|
|
|
|
return checkIsConflictingNonsymmetricCommon(
|
|
|
|
Ctx.get(), ExistingOccupiedAndKnown, ExistingUnused, ExistingWritten,
|
|
|
|
ProposedOccupiedAndKnown, ProposedUnused, ProposedWritten);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkIsConflictingNonsymmetric(KnowledgeStr Existing,
|
|
|
|
KnowledgeStr Proposed) {
|
|
|
|
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
|
|
|
|
&isl_ctx_free);
|
|
|
|
|
|
|
|
// Parse knowledge.
|
|
|
|
auto ExistingOccupied = parseSetOrNull(Ctx.get(), Existing.OccupiedStr);
|
|
|
|
auto ExistingUnused = parseSetOrNull(Ctx.get(), Existing.UndefStr);
|
|
|
|
auto ExistingWritten = parseSetOrNull(Ctx.get(), Existing.WrittenStr);
|
|
|
|
|
|
|
|
auto ProposedOccupied = parseSetOrNull(Ctx.get(), Proposed.OccupiedStr);
|
|
|
|
auto ProposedUnused = parseSetOrNull(Ctx.get(), Proposed.UndefStr);
|
|
|
|
auto ProposedWritten = parseSetOrNull(Ctx.get(), Proposed.WrittenStr);
|
|
|
|
|
|
|
|
return checkIsConflictingNonsymmetricCommon(
|
2018-04-29 08:28:14 +08:00
|
|
|
Ctx.get(), isl::union_map::from_domain(ExistingOccupied), ExistingUnused,
|
2018-04-29 06:11:55 +08:00
|
|
|
isl::union_map::from_domain(ExistingWritten),
|
2018-04-29 08:28:14 +08:00
|
|
|
isl::union_map::from_domain(ProposedOccupied), ProposedUnused,
|
2018-04-29 06:11:55 +08:00
|
|
|
isl::union_map::from_domain(ProposedWritten));
|
2017-04-14 00:32:46 +08:00
|
|
|
}
|
|
|
|
|
2017-04-14 00:32:16 +08:00
|
|
|
bool checkIsConflicting(KnowledgeStr Existing, KnowledgeStr Proposed) {
|
2017-02-16 01:19:22 +08:00
|
|
|
auto Forward = checkIsConflictingNonsymmetric(Existing, Proposed);
|
|
|
|
auto Backward = checkIsConflictingNonsymmetric(Proposed, Existing);
|
|
|
|
|
|
|
|
// isConflicting should be symmetric.
|
2017-04-14 00:32:46 +08:00
|
|
|
EXPECT_EQ(Forward, Backward);
|
|
|
|
|
|
|
|
return Forward || Backward;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkIsConflictingKnown(KnowledgeStr Existing, KnowledgeStr Proposed) {
|
|
|
|
auto Forward = checkIsConflictingNonsymmetricKnown(Existing, Proposed);
|
|
|
|
auto Backward = checkIsConflictingNonsymmetricKnown(Proposed, Existing);
|
|
|
|
|
|
|
|
// checkIsConflictingKnown should be symmetric.
|
2017-02-16 01:19:22 +08:00
|
|
|
EXPECT_EQ(Forward, Backward);
|
|
|
|
|
|
|
|
return Forward || Backward;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeLICM, isConflicting) {
|
|
|
|
|
|
|
|
// Check occupied vs. occupied.
|
|
|
|
EXPECT_TRUE(
|
|
|
|
checkIsConflicting({"{ Dom[i] }", nullptr, "{}"}, {nullptr, "{}", "{}"}));
|
|
|
|
EXPECT_TRUE(checkIsConflicting({"{ Dom[i] }", nullptr, "{}"},
|
|
|
|
{"{ Dom[i] }", nullptr, "{}"}));
|
|
|
|
EXPECT_FALSE(checkIsConflicting({"{ Dom[0] }", nullptr, "{}"},
|
|
|
|
{nullptr, "{ Dom[0] }", "{}"}));
|
|
|
|
EXPECT_FALSE(checkIsConflicting({"{ Dom[i] : i != 0 }", nullptr, "{}"},
|
|
|
|
{"{ Dom[0] }", nullptr, "{}"}));
|
|
|
|
|
2017-04-25 18:57:32 +08:00
|
|
|
// Check occupied vs. occupied with known values.
|
|
|
|
EXPECT_FALSE(checkIsConflictingKnown({"{ Dom[i] -> Val[] }", nullptr, "{}"},
|
|
|
|
{"{ Dom[i] -> Val[] }", nullptr, "{}"}));
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown({"{ Dom[i] -> ValA[] }", nullptr, "{}"},
|
|
|
|
{"{ Dom[i] -> ValB[] }", nullptr, "{}"}));
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown({"{ Dom[i] -> Val[] }", nullptr, "{}"},
|
|
|
|
{"{ Dom[i] -> [] }", nullptr, "{}"}));
|
|
|
|
EXPECT_FALSE(checkIsConflictingKnown({"{ Dom[0] -> Val[] }", nullptr, "{}"},
|
|
|
|
{nullptr, "{ Dom[0] }", "{}"}));
|
2017-04-27 05:52:51 +08:00
|
|
|
EXPECT_FALSE(checkIsConflictingKnown(
|
|
|
|
{"{ Dom[i] -> Val[]; Dom[i] -> Phi[] }", nullptr, "{}"},
|
|
|
|
{"{ Dom[i] -> Val[] }", nullptr, "{}"}));
|
2017-04-25 18:57:32 +08:00
|
|
|
|
|
|
|
// An implementation using subtract would have exponential runtime on patterns
|
|
|
|
// such as this one.
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown(
|
|
|
|
{"{ Dom[i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15]"
|
|
|
|
"-> Val[] }",
|
|
|
|
nullptr, "{}"},
|
|
|
|
{"[p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,q0,"
|
|
|
|
"q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15] -> {"
|
|
|
|
"Dom[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -> Val[];"
|
|
|
|
"Dom[p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15] -> Val[];"
|
|
|
|
"Dom[q0,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15] -> Val[] }",
|
|
|
|
"{}", "{}"}));
|
|
|
|
|
2017-02-16 01:19:22 +08:00
|
|
|
// Check occupied vs. written.
|
|
|
|
EXPECT_TRUE(
|
|
|
|
checkIsConflicting({nullptr, "{}", "{}"}, {"{}", nullptr, "{ Dom[0] }"}));
|
|
|
|
EXPECT_FALSE(
|
|
|
|
checkIsConflicting({"{}", nullptr, "{}"}, {"{}", nullptr, "{ Dom[0] }"}));
|
|
|
|
|
|
|
|
EXPECT_TRUE(checkIsConflicting({"{ Dom[i] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] }"}));
|
|
|
|
EXPECT_FALSE(checkIsConflicting({"{ DomA[i] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ DomB[0] }"}));
|
|
|
|
|
|
|
|
// Dom[1] represents the time between 0 and 1. Now Proposed writes at timestep
|
|
|
|
// 0 such that will have a different value between 0 and 1. Hence it is
|
|
|
|
// conflicting with Existing.
|
|
|
|
EXPECT_TRUE(checkIsConflicting({"{ Dom[1] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] }"}));
|
|
|
|
EXPECT_FALSE(checkIsConflicting({"{ Dom[i] : i != 1 }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] }"}));
|
|
|
|
|
2017-04-27 04:35:07 +08:00
|
|
|
// Check occupied vs. written with known values.
|
|
|
|
EXPECT_FALSE(checkIsConflictingKnown({"{ Dom[i] -> Val[] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> Val[] }"}));
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown({"{ Dom[i] -> ValA[] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> ValB[] }"}));
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown({"{ Dom[i] -> Val[] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> [] }"}));
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown({"{ Dom[i] -> [] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> Val[] }"}));
|
|
|
|
|
|
|
|
// The same value can be known under multiple names, for instance a PHINode
|
|
|
|
// has the same value as one of the incoming values. One matching pair
|
|
|
|
// suffices.
|
|
|
|
EXPECT_FALSE(checkIsConflictingKnown(
|
|
|
|
{"{ Dom[i] -> Val[]; Dom[i] -> Phi[] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> Val[] }"}));
|
|
|
|
EXPECT_FALSE(checkIsConflictingKnown(
|
|
|
|
{"{ Dom[i] -> Val[] }", nullptr, "{}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> Val[]; Dom[0] -> Phi[] }"}));
|
|
|
|
|
2017-02-16 01:19:22 +08:00
|
|
|
// Check written vs. written.
|
|
|
|
EXPECT_TRUE(checkIsConflicting({"{}", nullptr, "{ Dom[0] }"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] }"}));
|
|
|
|
EXPECT_FALSE(checkIsConflicting({"{}", nullptr, "{ Dom[-1] }"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] }"}));
|
|
|
|
EXPECT_FALSE(checkIsConflicting({"{}", nullptr, "{ Dom[1] }"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] }"}));
|
2017-04-21 03:16:39 +08:00
|
|
|
|
|
|
|
// Check written vs. written with known values.
|
|
|
|
EXPECT_FALSE(checkIsConflictingKnown({"{}", nullptr, "{ Dom[0] -> Val[] }"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> Val[] }"}));
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown({"{}", nullptr, "{ Dom[0] -> ValA[] }"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> ValB[] }"}));
|
|
|
|
EXPECT_TRUE(checkIsConflictingKnown({"{}", nullptr, "{ Dom[0] -> Val[] }"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> [] }"}));
|
2017-04-27 05:52:55 +08:00
|
|
|
EXPECT_FALSE(checkIsConflictingKnown(
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> Val[]}"},
|
|
|
|
{"{}", nullptr, "{ Dom[0] -> Val[]; Dom[0] -> Phi[] }"}));
|
2017-02-16 01:19:22 +08:00
|
|
|
}
|
|
|
|
} // anonymous namespace
|