10 #ifndef LLVM_CODEGEN_PBQP_MATH_H
11 #define LLVM_CODEGEN_PBQP_MATH_H
35 std::fill(Data.get(), Data.get() + Length, InitVal);
41 std::copy(V.Data.get(), V.Data.get() + Length, Data.get());
46 : Length(V.Length), Data(std::move(V.Data)) {
52 assert(Length != 0 && Data &&
"Invalid vector");
53 if (Length != V.Length)
55 return std::equal(Data.get(), Data.get() + Length, V.Data.get());
60 assert(Length != 0 && Data &&
"Invalid vector");
66 assert(Length != 0 && Data &&
"Invalid vector");
67 assert(Index < Length &&
"Vector element access out of bounds.");
73 assert(Length != 0 && Data &&
"Invalid vector");
74 assert(Index < Length &&
"Vector element access out of bounds.");
80 assert(Length != 0 && Data &&
"Invalid vector");
81 assert(Length == V.Length &&
"Vector length mismatch.");
82 std::transform(Data.get(), Data.get() + Length, V.Data.get(), Data.get(),
83 std::plus<PBQPNum>());
89 assert(Length != 0 && Data &&
"Invalid vector");
90 return std::min_element(Data.get(), Data.get() + Length) - Data.get();
95 std::unique_ptr<PBQPNum []> Data;
100 unsigned *VBegin =
reinterpret_cast<unsigned*
>(V.Data.get());
101 unsigned *VEnd =
reinterpret_cast<unsigned*
>(V.Data.get() + V.Length);
107 template <
typename OStream>
112 for (
unsigned i = 1;
i < V.getLength(); ++
i)
133 : Rows(Rows), Cols(Cols),
135 std::fill(Data.get(), Data.get() + (Rows * Cols), InitVal);
140 : Rows(M.Rows), Cols(M.Cols),
142 std::copy(M.Data.get(), M.Data.get() + (Rows * Cols), Data.get());
147 : Rows(M.Rows), Cols(M.Cols), Data(std::move(M.Data)) {
153 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
154 if (Rows != M.Rows || Cols != M.Cols)
156 return std::equal(Data.get(), Data.get() + (Rows * Cols), M.Data.get());
161 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
167 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
173 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
174 assert(R < Rows &&
"Row out of bounds.");
175 return Data.get() + (R * Cols);
180 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
181 assert(R < Rows &&
"Row out of bounds.");
182 return Data.get() + (R * Cols);
187 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
189 for (
unsigned C = 0;
C < Cols; ++
C)
190 V[
C] = (*
this)[R][
C];
196 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
198 for (
unsigned R = 0; R < Rows; ++R)
199 V[R] = (*
this)[R][
C];
205 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
207 for (
unsigned r = 0; r < Rows; ++r)
208 for (
unsigned c = 0; c < Cols; ++c)
209 M[c][r] = (*
this)[r][c];
215 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
216 assert(Rows == M.Rows && Cols == M.Cols &&
217 "Matrix dimensions mismatch.");
218 std::transform(Data.get(), Data.get() + (Rows * Cols), M.Data.get(),
219 Data.get(), std::plus<PBQPNum>());
224 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
232 std::unique_ptr<PBQPNum []> Data;
237 unsigned *MBegin =
reinterpret_cast<unsigned*
>(M.Data.get());
239 reinterpret_cast<unsigned*
>(M.Data.get() + (M.Rows * M.Cols));
245 template <
typename OStream>
253 template <
typename Metadata>
263 template <
typename Metadata>
265 return hash_value(static_cast<const Vector&>(V));
268 template <
typename Metadata>
278 template <
typename Metadata>
280 return hash_value(static_cast<const Matrix&>(M));
286 #endif // LLVM_CODEGEN_PBQP_MATH_H
OStream & operator<<(OStream &OS, const Vector &V)
Output a textual representation of the given vector on the given output stream.
unsigned getCols() const
Return the number of cols in this matrix.
unsigned minIndex() const
Returns the index of the minimum value in this vector.
friend hash_code hash_value(const Matrix &)
Return a hash_code for the given matrix.
PBQPNum * operator[](unsigned R)
Matrix element access.
PBQPNum & operator[](unsigned Index)
Element access.
MDMatrix(const Matrix &m)
Matrix(unsigned Rows, unsigned Cols, PBQPNum InitVal)
Construct a PBQP Matrix with the given dimensions and initial value.
Matrix(unsigned Rows, unsigned Cols)
Construct a PBQP Matrix with the given dimensions.
bool operator==(const Matrix &M) const
Comparison operator.
Vector getRowAsVector(unsigned R) const
Returns the given row as a vector.
Vector getColAsVector(unsigned C) const
Returns the given column as a vector.
const PBQPNum & operator[](unsigned Index) const
Const element access.
Vector(unsigned Length)
Construct a PBQP vector of the given size.
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Matrix & operator+=(const Matrix &M)
Add the given matrix to this one.
friend hash_code hash_value(const Vector &)
Return a hash_value for the given vector.
unsigned getLength() const
Return the length of the vector.
Matrix(Matrix &&M)
Move construct a PBQP matrix.
const Metadata & getMetadata() const
Vector(const Vector &V)
Copy construct a PBQP vector.
hash_code hash_value(const Vector &V)
Return a hash_value for the given vector.
bool operator==(const Vector &V) const
Comparison operator.
const PBQPNum * operator[](unsigned R) const
Matrix element access.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Matrix operator+(const Matrix &M)
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
const Metadata & getMetadata() const
unsigned getRows() const
Return the number of rows in this matrix.
Vector(Vector &&V)
Move construct a PBQP vector.
Vector & operator+=(const Vector &V)
Add another vector to this one.
OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Matrix(const Matrix &M)
Copy construct a PBQP matrix.
Matrix transpose() const
Matrix transpose.
Vector(unsigned Length, PBQPNum InitVal)
Construct a PBQP vector with initializer.
MDVector(const Vector &v)