LLVM: include/llvm/Support/Alignment.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21#ifndef LLVM_SUPPORT_ALIGNMENT_H_

22#define LLVM_SUPPORT_ALIGNMENT_H_

23

25#include

26#include

27#ifndef NDEBUG

28#include

29#endif

30

31namespace llvm {

32

33#define ALIGN_CHECK_ISPOSITIVE(decl) \

34 assert(decl > 0 && (#decl " should be defined"))

35

36

37

38

40private:

41 uint8_t ShiftValue = 0;

42

43

54

55

56

57

58

59

60

61

62 struct LogValue {

64 };

65

66public:

67

68 constexpr Align() = default;

69

70

75

77 assert(Value > 0 && "Value must not be 0");

80 assert(ShiftValue < 64 && "Broken invariant");

81 }

82

83

84

86

87

89 assert(ShiftValue != 0 && "Undefined operation");

91 Out.ShiftValue = ShiftValue - 1;

92 return Out;

93 }

94

95

96 template <size_t kValue> constexpr static Align Constant() {

97 return LogValue{static_cast<uint8_t>(CTLog2())};

98 }

99

100

101

102 template constexpr static Align Of() {

104 }

105

106

107 constexpr Align(LogValue CA) : ShiftValue(CA.Log) {}

108};

109

110

113}

114

115

116

118private:

119 using UP = std::optional;

120

121public:

122

124

125

130

135 "Alignment is neither 0 nor a power of 2");

138 }

139

140

142};

143

144

146 return SizeInBytes % Lhs.value() == 0;

147}

148

149

151 return isAligned(Lhs, reinterpret_cast<uintptr_t>(Addr));

152}

153

154

157

158

159

160

161

162

163

164

165

167}

168

169

170

171

172

173

174

175

176

177

178

179

184}

185

186

188 uintptr_t ArithAddr = reinterpret_cast<uintptr_t>(Addr);

189 assert(static_cast<uintptr_t>(ArithAddr + Alignment.value() - 1) >=

190 ArithAddr &&

191 "Overflow");

192 return alignTo(ArithAddr, Alignment);

193}

194

195

196

199}

200

201

202

205}

206

207

208inline unsigned Log2(Align A) { return A.ShiftValue; }

209

210

211

214}

215

216

218

219

224 Out.ShiftValue = Value - 1;

225 return Out;

226}

227

228

229

231

232

235 return Lhs.value() == Rhs;

236}

239 return Lhs.value() != Rhs;

240}

243 return Lhs.value() <= Rhs;

244}

247 return Lhs.value() >= Rhs;

248}

251 return Lhs.value() < Rhs;

252}

255 return Lhs.value() > Rhs;

256}

257

258

260 return Lhs.ShiftValue == Rhs.ShiftValue;

261}

263 return Lhs.ShiftValue != Rhs.ShiftValue;

264}

266 return Lhs.ShiftValue <= Rhs.ShiftValue;

267}

269 return Lhs.ShiftValue >= Rhs.ShiftValue;

270}

272 return Lhs.ShiftValue < Rhs.ShiftValue;

273}

275 return Lhs.ShiftValue > Rhs.ShiftValue;

276}

277

278

283

288

293

294

299

301 return (Lhs && Rhs && (*Lhs == *Rhs)) || (!Lhs && !Rhs);

302}

304

309

310#ifndef NDEBUG

311

313 return std::to_string(A.value());

314}

315

317 if (MA)

318 return std::to_string(MA->value());

319 return "None";

320}

321#endif

322

323#undef ALIGN_CHECK_ISPOSITIVE

324

325}

326

327#endif

#define ALIGN_CHECK_ISPOSITIVE(decl)

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static TripleVec::iterator emplace(TripleVec &Container, Triple &&T)

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This is an important base class in LLVM.

LLVM Value Representation.

This is an optimization pass for GlobalISel generic memory operations.

bool operator<(int64_t V1, const APSInt &V2)

unsigned encode(MaybeAlign A)

Returns a representation of the alignment that encodes undefined as 0.

bool isAligned(Align Lhs, uint64_t SizeInBytes)

Checks that SizeInBytes is a multiple of the alignment.

bool operator!=(uint64_t V1, const APInt &V2)

bool operator>=(int64_t V1, const APSInt &V2)

uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment)

Returns the necessary adjustment for aligning Addr to Alignment bytes, rounding up.

constexpr bool isPowerOf2_64(uint64_t Value)

Return true if the argument is a power of two > 0 (64 bit edition.)

bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)

unsigned Log2_64(uint64_t Value)

Return the floor log base 2 of the specified value, -1 if the value is zero.

constexpr T MinAlign(U A, V B)

A and B are either alignments or offsets.

bool operator>(int64_t V1, const APSInt &V2)

uint64_t offsetToAlignment(uint64_t Value, Align Alignment)

Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...

MaybeAlign decodeMaybeAlign(unsigned Value)

Dual operation of the encode function above.

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

Align commonAlignment(Align A, uint64_t Offset)

Returns the alignment that satisfies both alignments.

Align assumeAligned(uint64_t Value)

Treats the value 0 as a 1, so Align is always at least 1.

unsigned Log2(Align A)

Returns the log2 of the alignment.

bool operator<=(int64_t V1, const APSInt &V2)

bool isAddrAligned(Align Lhs, const void *Addr)

Checks that Addr is a multiple of the alignment.

uintptr_t alignAddr(const void *Addr, Align Alignment)

Aligns Addr to Alignment bytes, rounding up.

This struct is a compact representation of a valid (non-zero power of two) alignment.

friend unsigned encode(struct MaybeAlign A)

Returns a representation of the alignment that encodes undefined as 0.

friend bool operator>=(Align Lhs, Align Rhs)

constexpr Align(LogValue CA)

Constexpr constructor from LogValue type.

static constexpr Align Of()

Allow constructions of constexpr Align from types.

friend struct MaybeAlign decodeMaybeAlign(unsigned Value)

Dual operation of the encode function above.

Align & operator=(Align &&Other)=default

uint64_t value() const

This is a hole in the type system and should not be abused.

constexpr Align(Align &&Other)=default

friend bool operator<(Align Lhs, Align Rhs)

static constexpr Align Constant()

Allow constructions of constexpr Align.

Align & operator=(const Align &Other)=default

friend bool operator==(Align Lhs, Align Rhs)

Comparisons operators between Align.

friend bool operator<=(Align Lhs, Align Rhs)

constexpr Align()=default

Default is byte-aligned.

friend bool operator!=(Align Lhs, Align Rhs)

friend unsigned Log2(Align)

Returns the log2 of the alignment.

constexpr Align(const Align &Other)=default

Do not perform checks in case of copy/move construct/assign, because the checks have been performed w...

friend bool operator>(Align Lhs, Align Rhs)

This struct is a compact representation of a valid (power of two) or undefined (0) alignment.

Align valueOrOne() const

For convenience, returns a valid alignment or 1 if undefined.

MaybeAlign(MaybeAlign &&Other)=default

constexpr MaybeAlign(Align Value)

constexpr MaybeAlign(std::nullopt_t None)

MaybeAlign(const MaybeAlign &Other)=default

Do not perform checks in case of copy/move construct/assign, because the checks have been performed w...

MaybeAlign(uint64_t Value)

MaybeAlign()=default

Default is undefined.

MaybeAlign & operator=(MaybeAlign &&Other)=default

MaybeAlign & operator=(const MaybeAlign &Other)=default