MLIR: include/mlir/Support/TypeID.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef MLIR_SUPPORT_TYPEID_H

15#define MLIR_SUPPORT_TYPEID_H

16

18#include "llvm/ADT/DenseMapInfo.h"

19#include "llvm/ADT/Hashing.h"

20#include "llvm/ADT/STLExtras.h"

21#include "llvm/Support/Allocator.h"

22#include "llvm/Support/Compiler.h"

23#include "llvm/Support/PointerLikeTypeTraits.h"

24#include "llvm/Support/TypeName.h"

25

26namespace mlir {

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

108

109

110

111

112 struct alignas(8) Storage {};

113

114public:

116

117

119 return storage == other.storage;

120 }

122 return !(*this == other);

123 }

124

125

126 template

128 template <template <typename> class Trait>

130

131

133 return static_cast<const void *>(storage);

134 }

136 return TypeID(reinterpret_cast<const Storage *>(pointer));

137 }

138

139

141

142private:

143 TypeID(const Storage *storage) : storage(storage) {}

144

145

146 const Storage *storage;

147

149};

150

151

155

156

157

158

159

160namespace detail {

161

162

163

169

170template

172

173

174

175

176

177

178 template

180 template

183};

184

185template

190

191

192

193

194

195

196

197

198

199

200

201

202template <typename T, typename Enable = void>

204public:

207 "TypeID::get<> requires the complete definition of `T`");

209 return id;

210 }

211};

212

213

214

215

216

217

218

220

221 template

223 template

225

226 template

228 return T::resolveTypeID();

229 }

230};

231

232

233

234template

236 T, std::enable_if_t<InlineTypeIDResolver::has_resolve_typeid::value>> {

237public:

241};

242}

243

244template

248template <template <typename> class Trait>

250

251 struct Empty {};

253}

254

255

256

257

258

259

260

261

262#define MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME) \

263 namespace mlir { \

264 namespace detail { \

265 template <> \

266 class TypeIDResolver<CLASS_NAME> { \

267 public: \

268 static TypeID resolveTypeID() { return id; } \

269 \

270 private: \

271 static SelfOwningTypeID id; \

272 }; \

273 } \

274 }

275

276#define MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME) \

277 namespace mlir { \

278 namespace detail { \

279 SelfOwningTypeID TypeIDResolver<CLASS_NAME>::id = {}; \

280 } \

281 }

282

283

284

285

286

287

288

289

290

291#define MLIR_DECLARE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME) \

292 namespace mlir { \

293 namespace detail { \

294 template <> \

295 class TypeIDResolver<CLASS_NAME> : public FallbackTypeIDResolver { \

296 public: \

297 static TypeID resolveTypeID() { \

298 static_assert(is_fully_resolved<CLASS_NAME>(), \

299 "TypeID::get<> requires the complete definition of `T`"); \

300 static TypeID id = \

301 registerImplicitTypeID(llvm::getTypeName<CLASS_NAME>()); \

302 return id; \

303 } \

304 }; \

305 } \

306 }

307

308#define MLIR_DEFINE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)

309

310

311#ifndef MLIR_USE_FALLBACK_TYPE_IDS

312#define MLIR_USE_FALLBACK_TYPE_IDS false

313#endif

314

315#if MLIR_USE_FALLBACK_TYPE_IDS

316#define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME) \

317 MLIR_DECLARE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)

318#define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME) \

319 MLIR_DEFINE_EXPLICIT_FALLBACK_TYPE_ID(CLASS_NAME)

320#else

321#define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME) \

322 MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)

323#define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME) \

324 MLIR_DEFINE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)

325#endif

326

327

328

329

330

331#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME) \

332 static ::mlir::TypeID resolveTypeID() { \

333 static ::mlir::SelfOwningTypeID id; \

334 return id; \

335 } \

336 static_assert( \

337 ::mlir::detail::InlineTypeIDResolver::has_resolve_typeid< \

338 CLASS_NAME>::value, \

339 "`MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` must be placed in a " \

340 "public section of `" #CLASS_NAME "`");

341

342

343

344

345

346

347

348

350public:

351

352

354

355private:

356

357

358 llvm::SpecificBumpPtrAllocatorTypeID::Storage ids;

359};

360

361

362

363

364

365

366

367

368

370public:

376

377

379

380

382};

383

384}

385

386

387

388

389

390

391

393

394namespace llvm {

395template <>

410

411

412template <>

413struct PointerLikeTypeTraits<mlir::TypeID> {

421};

422

423}

424

425#endif

#define MLIR_DECLARE_EXPLICIT_SELF_OWNING_TYPE_ID(CLASS_NAME)

Definition TypeID.h:262

SelfOwningTypeID(SelfOwningTypeID &&)=delete

TypeID getTypeID() const

Return the TypeID owned by this object.

Definition TypeID.h:381

SelfOwningTypeID & operator=(const SelfOwningTypeID &)=delete

SelfOwningTypeID & operator=(SelfOwningTypeID &&)=delete

SelfOwningTypeID(const SelfOwningTypeID &)=delete

SelfOwningTypeID()=default

This class provides a way to define new TypeIDs at runtime.

Definition TypeID.h:349

TypeID allocate()

Allocate a new TypeID, that is ensured to be unique for the lifetime of the TypeIDAllocator.

Definition TypeID.h:353

This class provides an efficient unique identifier for a specific C++ type.

Definition TypeID.h:107

TypeID()

Definition TypeID.h:115

bool operator==(const TypeID &other) const

Comparison operations.

Definition TypeID.h:118

static TypeID get()

Construct a type info object for the given type T.

Definition TypeID.h:245

static TypeID getFromOpaquePointer(const void *pointer)

Definition TypeID.h:135

friend::llvm::hash_code hash_value(TypeID id)

Enable hashing TypeID.

friend class TypeIDAllocator

Definition TypeID.h:148

bool operator!=(const TypeID &other) const

Definition TypeID.h:121

const void * getAsOpaquePointer() const

Methods for supporting PointerLikeTypeTraits.

Definition TypeID.h:132

This class provides a fallback for resolving TypeIDs.

Definition TypeID.h:164

static LLVM_ALWAYS_EXPORT TypeID registerImplicitTypeID(StringRef name)

Register an implicit type ID for the given type name.

static TypeID resolveTypeID()

Definition TypeID.h:238

This class provides a resolver for getting the ID for a given class T.

Definition TypeID.h:203

static TypeID resolveTypeID()

Definition TypeID.h:205

The OpAsmOpInterface, see OpAsmInterface.td for more details.

constexpr bool is_fully_resolved()

Definition TypeID.h:186

Include the generated interface declarations.

llvm::DenseMapInfo< T, Enable > DenseMapInfo

inline ::llvm::hash_code hash_value(AffineExpr arg)

Make AffineExpr hashable.

static unsigned getHashValue(mlir::TypeID val)

Definition TypeID.h:405

static bool isEqual(mlir::TypeID lhs, mlir::TypeID rhs)

Definition TypeID.h:408

static mlir::TypeID getEmptyKey()

Definition TypeID.h:397

static mlir::TypeID getTombstoneKey()

Definition TypeID.h:401

static void * getAsVoidPointer(mlir::TypeID info)

Definition TypeID.h:414

static mlir::TypeID getFromVoidPointer(void *ptr)

Definition TypeID.h:417

static constexpr int NumLowBitsAvailable

Definition TypeID.h:420

This class provides utilities for resolving the TypeID of a class that provides a static TypeID resol...

Definition TypeID.h:219

decltype(T::resolveTypeID()) has_resolve_typeid_trait

Trait to check if T provides a static resolveTypeID method.

Definition TypeID.h:222

static TypeID resolveTypeID()

Definition TypeID.h:227

llvm::is_detected< has_resolve_typeid_trait, T > has_resolve_typeid

Definition TypeID.h:224

decltype(sizeof(U)) is_fully_resolved_trait

Trait to check if U is fully resolved.

Definition TypeID.h:179

llvm::is_detected< is_fully_resolved_trait, U > is_fully_resolved

Definition TypeID.h:181

static constexpr bool value

Definition TypeID.h:182