9#ifndef LLVM_CODEGEN_PBQP_MATH_H
10#define LLVM_CODEGEN_PBQP_MATH_H
78 assert(Data.
size() == V.Data.size() &&
"Vector length mismatch.");
79 std::transform(
begin(),
end(), V.begin(),
begin(), std::plus<PBQPNum>());
95 const unsigned *VBegin =
reinterpret_cast<const unsigned *
>(V.begin());
96 const unsigned *VEnd =
reinterpret_cast<const unsigned *
>(V.end());
102template <
typename OStream>
104 assert((V.getLength() != 0) &&
"Zero-length vector badness.");
117 Rows(Rows), Cols(Cols), Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
123 : Rows(Rows), Cols(Cols),
124 Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
125 std::fill(Data.get(), Data.get() + (Rows * Cols), InitVal);
130 : Rows(M.Rows), Cols(M.Cols),
131 Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
132 std::copy(M.Data.get(), M.Data.get() + (Rows * Cols), Data.get());
137 : Rows(M.Rows), Cols(M.Cols), Data(
std::
move(M.Data)) {
143 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
144 if (Rows != M.Rows || Cols != M.Cols)
146 return std::equal(Data.get(), Data.get() + (Rows * Cols), M.Data.get());
151 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
157 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
163 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
164 assert(R < Rows &&
"Row out of bounds.");
165 return Data.get() + (R * Cols);
170 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
171 assert(R < Rows &&
"Row out of bounds.");
172 return Data.get() + (R * Cols);
177 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
179 for (
unsigned C = 0;
C < Cols; ++
C)
180 V[
C] = (*
this)[R][
C];
186 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
188 for (
unsigned R = 0; R < Rows; ++R)
189 V[R] = (*
this)[R][
C];
195 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
197 for (
unsigned r = 0; r < Rows; ++r)
198 for (
unsigned c = 0; c < Cols; ++c)
199 M[c][r] = (*
this)[r][c];
205 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
206 assert(Rows == M.Rows && Cols == M.Cols &&
207 "Matrix dimensions mismatch.");
208 std::transform(Data.get(), Data.get() + (Rows * Cols), M.Data.get(),
209 Data.get(), std::plus<PBQPNum>());
214 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
222 std::unique_ptr<PBQPNum []> Data;
227 unsigned *MBegin =
reinterpret_cast<unsigned*
>(M.Data.get());
229 reinterpret_cast<unsigned*
>(M.Data.get() + (M.Rows * M.Cols));
235template <
typename OStream>
237 assert((M.getRows() != 0) &&
"Zero-row matrix badness.");
238 for (
unsigned i = 0; i < M.getRows(); ++i)
239 OS << M.getRowAsVector(i) <<
"\n";
243template <
typename Metadata>
255template <
typename Metadata>
260template <
typename Metadata>
272template <
typename Metadata>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
This is a MutableArrayRef that owns its array.
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.
const PBQPNum * begin() const
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.
Vector(const Vector &V)
Copy construct a PBQP vector.
const PBQPNum & operator[](unsigned Index) const
Const element access.
const PBQPNum * end() const
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.
auto min_element(R &&Range)
Provide wrappers to std::min_element which take ranges instead of having to pass begin/end explicitly...
InterleavedRange< Range > interleaved(const Range &R, StringRef Separator=", ", StringRef Prefix="", StringRef Suffix="")
Output range R as a sequence of interleaved elements.
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.
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
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.