57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#ifndef PFOR_PFOR_CONDITIONS_H
|
|
#define PFOR_PFOR_CONDITIONS_H
|
|
|
|
#include "mp/pack.h"
|
|
|
|
namespace pfor {
|
|
|
|
/**
|
|
* @brief testing Bernstein's conditions on two expressions
|
|
*
|
|
* @param E0 an expression's information (I, W, R) where W and R are sets of written/read variables
|
|
* @param E1 an expression's information
|
|
*
|
|
* @return true if the expressions depend on each other
|
|
*
|
|
* Bernstein's conditions for independance are :
|
|
* - no intersection between modified variables (xW, yW)
|
|
* - no intersection between read/modified variables (xR, yW) and (yR, xW)
|
|
*/
|
|
template<typename, typename> struct ExpressionDepends;
|
|
|
|
template<typename CI, typename CW, typename CR, typename TI, typename TW, typename TR>
|
|
struct ExpressionDepends<Pack<CI, CW, CR>, Pack<TI, TW, TR>> {
|
|
static constexpr bool value = PackIntersects<CW, TW>::value || PackIntersects<CR, TW>::value || PackIntersects<CW, TR>::value;
|
|
};
|
|
|
|
template<typename E0, typename E1>
|
|
constexpr bool expressionDepends = ExpressionDepends<E0, E1>::value;
|
|
|
|
/**
|
|
* @brief testing Bernstein's conditions between each expression of a pack with one expression
|
|
*
|
|
* @param C a cluster of expressions' information
|
|
* @param T an expression's information
|
|
*
|
|
* @return true if any of the expressions from the cluster depends on the expression T
|
|
*/
|
|
template<typename, typename> struct ClusterDepends;
|
|
|
|
template<typename C, typename... Cs, typename T>
|
|
struct ClusterDepends<Pack<C, Cs...>, T> {
|
|
using next = ClusterDepends<Pack<Cs...>, T>;
|
|
static constexpr bool value = ExpressionDepends<C, T>::value || next::value;
|
|
};
|
|
|
|
template<typename T>
|
|
struct ClusterDepends<Pack<>, T> {
|
|
static constexpr bool value = false;
|
|
};
|
|
|
|
template<typename C, typename T>
|
|
constexpr bool clusterDepends = ClusterDepends<C, T>::value;
|
|
|
|
}
|
|
|
|
#endif
|