/usr/include/scilab/gvn/GVN.hxx is in scilab-include 6.0.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | /*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2015 - Scilab Enterprises - Calixte DENIZET
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally licensed under the terms of the CeCILL v2.1,
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
*
*/
#ifndef __GVN_HXX__
#define __GVN_HXX__
#include <string>
#include <list>
#include <map>
#include <unordered_map>
#include "MultivariatePolynomial.hxx"
#include "OpValue.hxx"
#include "symbol.hxx"
#include "dynlib_ast.h"
namespace analysis
{
/**
* \class GVN
* \brief GVN stands for Global Value Numbering
*
* This class implements a GVN but it is extended to track common expressions represented
* by multivariate polynomials.
* Symbolic calculus is allowed with integer values (such as matrix dimensions)
*
* All the pointers GVN::Value* returned by the GVN have the same lifetime than the GVN itself.
* For information, the GVN::Value are stored in unordered_map (or multimap) or list.
*
*/
class EXTERN_AST GVN
{
public:
/**
* \struct Value
* \brief Represents a value and polynomial
*/
struct Value
{
uint64_t value;
const MultivariatePolynomial * poly;
Value(const uint64_t _value) : value(_value), poly(nullptr) { }
friend inline std::wostream & operator<<(std::wostream & out, const Value & v)
{
out << L"Value: " << v.value
<< L", Poly: ";
if (v.poly)
{
out << *v.poly;
}
else
{
out << L"null";
}
return out;
}
inline bool operator==(const Value & R) const
{
return value == R.value;
}
inline bool operator!=(const Value & R) const
{
return value != R.value;
}
};
private:
typedef std::unordered_map<OpValue, Value, OpValue::Hash, OpValue::Eq> MapValues;
typedef std::unordered_map<int64_t, Value> MapInt64;
typedef std::multimap<symbol::Symbol, Value> MapSymbols;
typedef std::unordered_map<MultivariatePolynomial, Value *, MultivariatePolynomial::Hash, MultivariatePolynomial::Eq> MapPolys;
typedef std::list<Value> ListValues;
MapValues mapv;
MapInt64 mapi64;
MapSymbols maps;
MapPolys mapp;
ListValues list;
uint64_t current;
public:
// WARNING: current MUST be initialized with 0 and nothing else !
// (because when mpoly are evaluated with a std::vector<MP> the index begins to 0)
/**
* \brief constructor
*/
GVN() : current(0)
{
}
/**
* \brief Clear all the maps used in the GVN
*/
void clear();
/**
* \brief Get current value
*/
uint64_t getCurrentValue() const;
/**
* \brief Inserts a value associated with a polynomial
* \param mp a polynomial
* \param value a value
*/
void insertValue(const MultivariatePolynomial & mp, Value & value);
/**
* \brief Associated a symbol with a polynomial
* \param sym a symbol
* \param mp a polynomial
*/
void setValue(const symbol::Symbol & sym, const MultivariatePolynomial & mp);
/**
* \brief Associated a symbol with a Value
* \param sym a symbol
* \param LV a value
*/
void setValue(const symbol::Symbol & sym, const Value & LV);
/**
* \brief Get a value
* \return a Value
*/
Value * getValue();
/**
* \brief Get a value associated with a polynomial
* \param mp a polynomial
* \return a Value
*/
Value * getValue(const MultivariatePolynomial & mp);
/**
* \brief Get a value associated with a symbol
* \param sym a symbol
* \return a Value
*/
Value * getValue(const symbol::Symbol & sym);
/**
* \brief Get a value associated with a symbol
* \param sym a symbol
* \return a Value
*/
Value * getExistingValue(const symbol::Symbol & sym);
/**
* \brief Get a value associated with an integer
* \param x an integer
* \return a Value
*/
Value * getValue(const int64_t x);
/**
* \brief Get a value associated with a double
* \param x a double
* \return a Value
*/
Value * getValue(const double x);
/**
* \brief Get a value associated with an unary operation applyed to a value
* \param kind the kind of the operation
* \param LV a Value
* \return a Value
*/
Value * getValue(const OpValue::Kind kind, const Value & LV);
/**
* \brief Get a value associated with a binary operation applyed to two values
* \param kind the kind of the operation
* \param LV a Value (Left)
* \param RV a Value (Right)
* \return a Value
*/
Value * getValue(const OpValue::Kind kind, const Value & LV, const Value & RV);
/**
* \brief Get a map containing association between symbol names and value (as ULL)
* \return a map
*/
std::map<std::wstring, uint64_t> getSymMap() const;
/**
* \brief Overload of the operator << for GVN
*/
EXTERN_AST friend std::wostream & operator<<(std::wostream & out, const GVN & gvn);
private:
/**
* \brief Get a value associated with a polynomial which is the result of an operation
* \param mp a polynomial
* \param ov an operation
* \return a Value
*/
Value * getValue(const MultivariatePolynomial & mp, const OpValue & ov);
/**
* \brief Helper function to get the result of an unary operation applyed to the polynomial associated with a value
* \param OPER the operation
* \param LV a value
* \param ov the operation kind
* \return a Value
*/
Value * getValue(MultivariatePolynomial(OPER)(const MultivariatePolynomial & mp), const Value & LV, const OpValue & ov);
/**
* \brief Helper function to get the result of a binary operation applyed to the polynomials associated with two values
* \param OPER the operation
* \param LV a value (Left)
* \param RV a value (Right)
* \param ov the operation kind
* \return a Value
*/
Value * getValue(MultivariatePolynomial(OPER)(const MultivariatePolynomial & LMP, const MultivariatePolynomial & RMP), const Value & LV, const Value & RV, const OpValue & ov);
};
} // namespace analysis
#endif // __GVN_HXX__
|