9#ifndef LLVM_CODEGEN_PBQP_MATH_H
10#define LLVM_CODEGEN_PBQP_MATH_H
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);
108template <
typename OStream>
110 assert((V.getLength() != 0) &&
"Zero-length vector badness.");
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),
135 Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
136 std::fill(Data.get(), Data.get() + (Rows * Cols), InitVal);
141 : Rows(M.Rows), Cols(M.Cols),
142 Data(
std::make_unique<
PBQPNum []>(Rows * 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)
157 return std::equal(Data.get(), Data.get() + (Rows * Cols), M.Data.get());
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.");
219 std::transform(Data.get(), Data.get() + (Rows * Cols), M.Data.get(),
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));
246template <
typename OStream>
248 assert((M.getRows() != 0) &&
"Zero-row matrix badness.");
249 for (
unsigned i = 0; i < M.getRows(); ++i)
250 OS << M.getRowAsVector(i) <<
"\n";
254template <
typename Metadata>
266template <
typename Metadata>
271template <
typename Metadata>
283template <
typename Metadata>
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MDMatrix(const Matrix &m)
const Metadata & getMetadata() const
const Metadata & getMetadata() const
MDVector(const Vector &v)
Matrix operator+(const Matrix &M)
PBQPNum * operator[](unsigned R)
Matrix element access.
Matrix & operator+=(const Matrix &M)
Add the given matrix to this one.
unsigned getRows() const
Return the number of rows in this matrix.
const PBQPNum * operator[](unsigned R) const
Matrix element access.
Vector getColAsVector(unsigned C) const
Returns the given column as a vector.
bool operator==(const Matrix &M) const
Comparison operator.
unsigned getCols() const
Return the number of cols in this matrix.
friend hash_code hash_value(const Matrix &)
Return a hash_code for the given matrix.
Matrix(Matrix &&M)
Move construct a PBQP matrix.
Vector getRowAsVector(unsigned R) const
Returns the given row as a vector.
Matrix(const Matrix &M)
Copy construct a PBQP matrix.
Matrix(unsigned Rows, unsigned Cols, PBQPNum InitVal)
Construct a PBQP Matrix with the given dimensions and initial value.
Matrix transpose() const
Matrix transpose.
Matrix(unsigned Rows, unsigned Cols)
Construct a PBQP Matrix with the given dimensions.
unsigned getLength() const
Return the length of the vector.
PBQPNum & operator[](unsigned Index)
Element access.
unsigned minIndex() const
Returns the index of the minimum value in this vector.
Vector(unsigned Length, PBQPNum InitVal)
Construct a PBQP vector with initializer.
Vector & operator+=(const Vector &V)
Add another vector to this one.
Vector(Vector &&V)
Move construct a PBQP vector.
friend hash_code hash_value(const Vector &)
Return a hash_value for the given vector.
Vector(const Vector &V)
Copy construct a PBQP vector.
const PBQPNum & operator[](unsigned Index) const
Const element access.
bool operator==(const Vector &V) const
Comparison operator.
Vector(unsigned Length)
Construct a PBQP vector of the given size.
An opaque object representing a hash code.
@ C
The default llvm calling convention, compatible with C.
OStream & operator<<(OStream &OS, const Vector &V)
Output a textual representation of the given vector on the given output stream.
hash_code hash_value(const Vector &V)
Return a hash_value for the given vector.
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Implement std::hash so that hash_code can be used in STL containers.