LLVM: include/llvm/CodeGen/PBQP/Math.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_CODEGEN_PBQP_MATH_H

10#define LLVM_CODEGEN_PBQP_MATH_H

11

16#include

17#include

18#include

19#include

20

21namespace llvm {

22namespace PBQP {

23

25

26

28public:

29

31

32

34 std::fill(begin(), end(), InitVal);

35 }

36

37

39

40

42

43

45 const PBQPNum *end() const { return Data.end(); }

48

49

51 assert(!Data.empty() && "Invalid vector");

53 }

54

55

57 assert(!Data.empty() && "Invalid vector");

58 return Data.size();

59 }

60

61

63 assert(!Data.empty() && "Invalid vector");

64 assert(Index < Data.size() && "Vector element access out of bounds.");

65 return Data[Index];

66 }

67

68

70 assert(!Data.empty() && "Invalid vector");

71 assert(Index < Data.size() && "Vector element access out of bounds.");

72 return Data[Index];

73 }

74

75

77 assert(!Data.empty() && "Invalid vector");

78 assert(Data.size() == V.Data.size() && "Vector length mismatch.");

79 std::transform(begin(), end(), V.begin(), begin(), std::plus());

80 return *this;

81 }

82

83

85 assert(!Data.empty() && "Invalid vector");

87 }

88

89private:

91};

92

93

95 const unsigned *VBegin = reinterpret_cast<const unsigned *>(V.begin());

96 const unsigned *VEnd = reinterpret_cast<const unsigned *>(V.end());

98}

99

100

101

102template

104 assert((V.getLength() != 0) && "Zero-length vector badness.");

106 return OS;

107}

108

109

111private:

113

114public:

115

116 Matrix(unsigned Rows, unsigned Cols) :

117 Rows(Rows), Cols(Cols), Data(std::make_unique<PBQPNum []>(Rows * Cols)) {

118 }

119

120

121

123 : Rows(Rows), Cols(Cols),

124 Data(std::make_unique<PBQPNum []>(Rows * Cols)) {

125 std::fill(Data.get(), Data.get() + (Rows * Cols), InitVal);

126 }

127

128

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());

133 }

134

135

137 : Rows(M.Rows), Cols(M.Cols), Data(std::move(M.Data)) {

138 M.Rows = M.Cols = 0;

139 }

140

141

143 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

144 if (Rows != M.Rows || Cols != M.Cols)

145 return false;

146 return std::equal(Data.get(), Data.get() + (Rows * Cols), M.Data.get());

147 }

148

149

151 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

152 return Rows;

153 }

154

155

157 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

158 return Cols;

159 }

160

161

163 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

164 assert(R < Rows && "Row out of bounds.");

165 return Data.get() + (R * Cols);

166 }

167

168

170 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

171 assert(R < Rows && "Row out of bounds.");

172 return Data.get() + (R * Cols);

173 }

174

175

177 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

179 for (unsigned C = 0; C < Cols; ++C)

180 V[C] = (*this)[R][C];

181 return V;

182 }

183

184

186 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

188 for (unsigned R = 0; R < Rows; ++R)

189 V[R] = (*this)[R][C];

190 return V;

191 }

192

193

195 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

196 Matrix M(Cols, Rows);

197 for (unsigned r = 0; r < Rows; ++r)

198 for (unsigned c = 0; c < Cols; ++c)

199 M[c][r] = (*this)[r][c];

200 return M;

201 }

202

203

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());

210 return *this;

211 }

212

214 assert(Rows != 0 && Cols != 0 && Data && "Invalid matrix");

216 Tmp += M;

217 return Tmp;

218 }

219

220private:

221 unsigned Rows, Cols;

222 std::unique_ptr<PBQPNum []> Data;

223};

224

225

227 unsigned *MBegin = reinterpret_cast<unsigned*>(M.Data.get());

228 unsigned *MEnd =

229 reinterpret_cast<unsigned*>(M.Data.get() + (M.Rows * M.Cols));

231}

232

233

234

235template

237 assert((M.getRows() != 0) && "Zero-row matrix badness.");

238 for (unsigned i = 0; i < M.getRows(); ++i)

239 OS << M.getRowAsVector(i) << "\n";

240 return OS;

241}

242

243template

245public:

248

250

251private:

253};

254

255template

259

260template

262public:

265

267

268private:

270};

271

272template

276

277}

278}

279

280#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

This is a MutableArrayRef that owns its array.

MDMatrix(const Matrix &m)

Definition Math.h:263

MDMatrix(Matrix &&m)

Definition Math.h:264

const Metadata & getMetadata() const

Definition Math.h:266

const Metadata & getMetadata() const

Definition Math.h:249

MDVector(const Vector &v)

Definition Math.h:246

MDVector(Vector &&v)

Definition Math.h:247

PBQP Matrix class.

Definition Math.h:110

Matrix operator+(const Matrix &M)

Definition Math.h:213

PBQPNum * operator[](unsigned R)

Matrix element access.

Definition Math.h:162

Matrix & operator+=(const Matrix &M)

Add the given matrix to this one.

Definition Math.h:204

friend hash_code hash_value(const Matrix &)

Return a hash_code for the given matrix.

Definition Math.h:226

unsigned getRows() const

Return the number of rows in this matrix.

Definition Math.h:150

const PBQPNum * operator[](unsigned R) const

Matrix element access.

Definition Math.h:169

Vector getColAsVector(unsigned C) const

Returns the given column as a vector.

Definition Math.h:185

bool operator==(const Matrix &M) const

Comparison operator.

Definition Math.h:142

unsigned getCols() const

Return the number of cols in this matrix.

Definition Math.h:156

Matrix(Matrix &&M)

Move construct a PBQP matrix.

Definition Math.h:136

Vector getRowAsVector(unsigned R) const

Returns the given row as a vector.

Definition Math.h:176

Matrix(const Matrix &M)

Copy construct a PBQP matrix.

Definition Math.h:129

Matrix(unsigned Rows, unsigned Cols, PBQPNum InitVal)

Construct a PBQP Matrix with the given dimensions and initial value.

Definition Math.h:122

Matrix transpose() const

Matrix transpose.

Definition Math.h:194

Matrix(unsigned Rows, unsigned Cols)

Construct a PBQP Matrix with the given dimensions.

Definition Math.h:116

PBQP Vector class.

Definition Math.h:27

unsigned getLength() const

Return the length of the vector.

Definition Math.h:56

PBQPNum & operator[](unsigned Index)

Element access.

Definition Math.h:62

PBQPNum * begin()

Definition Math.h:46

unsigned minIndex() const

Returns the index of the minimum value in this vector.

Definition Math.h:84

const PBQPNum * begin() const

Definition Math.h:44

Vector(unsigned Length, PBQPNum InitVal)

Construct a PBQP vector with initializer.

Definition Math.h:33

Vector & operator+=(const Vector &V)

Add another vector to this one.

Definition Math.h:76

Vector(Vector &&V)

Move construct a PBQP vector.

Definition Math.h:41

Vector(const Vector &V)

Copy construct a PBQP vector.

Definition Math.h:38

PBQPNum * end()

Definition Math.h:47

const PBQPNum & operator[](unsigned Index) const

Const element access.

Definition Math.h:69

const PBQPNum * end() const

Definition Math.h:45

bool operator==(const Vector &V) const

Comparison operator.

Definition Math.h:50

Vector(unsigned Length)

Construct a PBQP vector of the given size.

Definition Math.h:30

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.

Definition Math.h:103

hash_code hash_value(const Vector &V)

Return a hash_value for the given vector.

Definition Math.h:94

float PBQPNum

Definition Math.h:24

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.