9#ifndef LLVM_CODEGEN_PBQP_MATH_H
10#define LLVM_CODEGEN_PBQP_MATH_H
46 const PBQPNum *
end()
const {
return Data.data() + Data.size(); }
52 assert(!Data.empty() &&
"Invalid vector");
58 assert(!Data.empty() &&
"Invalid vector");
64 assert(!Data.empty() &&
"Invalid vector");
65 assert(Index < Data.size() &&
"Vector element access out of bounds.");
71 assert(!Data.empty() &&
"Invalid vector");
72 assert(Index < Data.size() &&
"Vector element access out of bounds.");
78 assert(!Data.empty() &&
"Invalid vector");
79 assert(Data.size() == V.Data.size() &&
"Vector length mismatch.");
80 std::transform(
begin(),
end(), V.begin(),
begin(), std::plus<PBQPNum>());
86 assert(!Data.empty() &&
"Invalid vector");
96 const unsigned *VBegin =
reinterpret_cast<const unsigned *
>(V.begin());
97 const unsigned *VEnd =
reinterpret_cast<const unsigned *
>(V.end());
103template <
typename OStream>
105 assert((V.getLength() != 0) &&
"Zero-length vector badness.");
118 Rows(Rows), Cols(Cols), Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
124 : Rows(Rows), Cols(Cols),
125 Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
126 std::fill(Data.get(), Data.get() + (Rows * Cols), InitVal);
131 : Rows(M.Rows), Cols(M.Cols),
132 Data(
std::make_unique<
PBQPNum []>(Rows * Cols)) {
133 std::copy(M.Data.get(), M.Data.get() + (Rows * Cols), Data.get());
138 : Rows(M.Rows), Cols(M.Cols), Data(
std::
move(M.Data)) {
144 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
145 if (Rows != M.Rows || Cols != M.Cols)
147 return std::equal(Data.get(), Data.get() + (Rows * Cols), M.Data.get());
152 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
158 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
164 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
165 assert(R < Rows &&
"Row out of bounds.");
166 return Data.get() + (R * Cols);
171 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
172 assert(R < Rows &&
"Row out of bounds.");
173 return Data.get() + (R * Cols);
178 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
180 for (
unsigned C = 0;
C < Cols; ++
C)
181 V[
C] = (*
this)[R][
C];
187 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
189 for (
unsigned R = 0; R < Rows; ++R)
190 V[R] = (*
this)[R][
C];
196 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
198 for (
unsigned r = 0; r < Rows; ++r)
199 for (
unsigned c = 0; c < Cols; ++c)
200 M[c][r] = (*
this)[r][c];
206 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
207 assert(Rows == M.Rows && Cols == M.Cols &&
208 "Matrix dimensions mismatch.");
209 std::transform(Data.get(), Data.get() + (Rows * Cols), M.Data.get(),
210 Data.get(), std::plus<PBQPNum>());
215 assert(Rows != 0 && Cols != 0 && Data &&
"Invalid matrix");
223 std::unique_ptr<PBQPNum []>
Data;
228 unsigned *MBegin =
reinterpret_cast<unsigned*
>(M.Data.get());
230 reinterpret_cast<unsigned*
>(M.Data.get() + (M.Rows * M.Cols));
236template <
typename OStream>
238 assert((M.getRows() != 0) &&
"Zero-row matrix badness.");
239 for (
unsigned i = 0; i < M.getRows(); ++i)
240 OS << M.getRowAsVector(i) <<
"\n";
244template <
typename Metadata>
256template <
typename Metadata>
261template <
typename Metadata>
273template <
typename Metadata>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
friend hash_code hash_value(const Matrix &)
Return a hash_code for the given matrix.
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.
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
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.