9 #ifndef LLVM_CODEGEN_PBQP_MATH_H 10 #define LLVM_CODEGEN_PBQP_MATH_H 31 : Length(Length), Data(
std::make_unique<
PBQPNum []>(Length)) {}
35 : Length(Length), Data(
std::make_unique<
PBQPNum []>(Length)) {
36 std::fill(Data.get(), Data.get() + Length, InitVal);
41 : Length(V.Length), Data(
std::make_unique<
PBQPNum []>(Length)) {
42 std::copy(V.Data.get(), V.Data.get() + Length, Data.get());
47 : Length(V.Length), Data(
std::move(V.Data)) {
53 assert(Length != 0 && Data &&
"Invalid vector");
54 if (Length != V.Length)
56 return std::equal(Data.get(), Data.get() + Length, V.Data.get());
61 assert(Length != 0 && Data &&
"Invalid vector");
67 assert(Length != 0 && Data &&
"Invalid vector");
68 assert(Index < Length &&
"Vector element access out of bounds.");
74 assert(Length != 0 && Data &&
"Invalid vector");
75 assert(Index < Length &&
"Vector element access out of bounds.");
81 assert(Length != 0 && Data &&
"Invalid vector");
82 assert(Length == V.Length &&
"Vector length mismatch.");
83 std::transform(Data.get(), Data.get() + Length, V.Data.get(), Data.get(),
84 std::plus<PBQPNum>());
90 assert(Length != 0 && Data &&
"Invalid vector");
91 return std::min_element(Data.get(), Data.get() + Length) - Data.get();
96 std::unique_ptr<PBQPNum []> Data;
101 unsigned *VBegin =
reinterpret_cast<unsigned*
>(V.Data.get());
102 unsigned *VEnd =
reinterpret_cast<unsigned*
>(V.Data.get() + V.Length);
108 template <
typename OStream>
113 for (
unsigned i = 1; i < V.getLength(); ++i)
128 Rows(Rows), Cols(Cols),
Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
134 : Rows(Rows), Cols(Cols),
136 std::fill(
Data.get(),
Data.get() + (Rows * Cols), InitVal);
141 : Rows(M.Rows), Cols(M.Cols),
143 std::copy(M.Data.get(), M.Data.get() + (Rows * Cols),
Data.get());
148 : Rows(M.Rows), Cols(M.Cols),
Data(
std::move(M.
Data)) {
154 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
155 if (Rows != M.Rows || Cols != M.Cols)
162 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
168 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
174 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
175 assert(R < Rows &&
"Row out of bounds.");
176 return Data.get() + (R * Cols);
181 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
182 assert(R < Rows &&
"Row out of bounds.");
183 return Data.get() + (R * Cols);
188 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
190 for (
unsigned C = 0;
C < Cols; ++
C)
191 V[
C] = (*
this)[R][
C];
197 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
199 for (
unsigned R = 0; R < Rows; ++R)
200 V[R] = (*
this)[R][
C];
206 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
208 for (
unsigned r = 0; r < Rows; ++r)
209 for (
unsigned c = 0; c < Cols; ++c)
210 M[c][r] = (*
this)[r][c];
216 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
217 assert(Rows == M.Rows && Cols == M.Cols &&
218 "Matrix dimensions mismatch.");
220 Data.get(), std::plus<PBQPNum>());
225 assert(Rows != 0 && Cols != 0 &&
Data &&
"Invalid matrix");
233 std::unique_ptr<PBQPNum []>
Data;
238 unsigned *MBegin =
reinterpret_cast<unsigned*
>(M.Data.get());
240 reinterpret_cast<unsigned*
>(M.Data.get() + (M.Rows * M.Cols));
246 template <
typename OStream>
249 for (
unsigned i = 0; i < M.
getRows(); ++i)
254 template <
typename Metadata>
266 template <
typename Metadata>
268 return hash_value(static_cast<const Vector&>(V));
271 template <
typename Metadata>
283 template <
typename Metadata>
285 return hash_value(static_cast<const Matrix&>(M));
291 #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.
This class represents lattice values for constants.
PBQPNum * operator[](unsigned R)
Matrix element access.
unsigned getLength() const
Return the length of the vector.
PBQPNum & operator[](unsigned Index)
Element access.
Vector getRowAsVector(unsigned R) const
Returns the given row as a vector.
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.
Vector getColAsVector(unsigned C) const
Returns the given column as a vector.
const PBQPNum & operator[](unsigned Index) const
Const element access.
unsigned getRows() const
Return the number of rows in this matrix.
unsigned minIndex() const
Returns the index of the minimum value in this vector.
Vector(unsigned Length)
Construct a PBQP vector of the given size.
unsigned getCols() const
Return the number of cols in this matrix.
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.
Matrix(Matrix &&M)
Move construct a PBQP matrix.
Vector(const Vector &V)
Copy construct a PBQP vector.
const PBQPNum * operator[](unsigned R) const
Matrix element access.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Matrix operator+(const Matrix &M)
bool operator==(const Vector &V) const
Comparison operator.
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
bool operator==(const Matrix &M) const
Comparison operator.
const Metadata & getMetadata() const
Vector(Vector &&V)
Move construct a PBQP vector.
Vector & operator+=(const Vector &V)
Add another vector to this one.
Matrix transpose() const
Matrix transpose.
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.
OutputIt copy(R &&Range, OutputIt Out)
Vector(unsigned Length, PBQPNum InitVal)
Construct a PBQP vector with initializer.
MDVector(const Vector &v)