clang 24.0.0git
CIRAttrs.cpp
Go to the documentation of this file.
1//===- CIRAttrs.cpp - MLIR CIR Attributes ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the attributes in the CIR dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
15
16#include "mlir/IR/Attributes.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "llvm/Support/MathExtras.h"
19
20//===-----------------------------------------------------------------===//
21// RecordMembers
22//===-----------------------------------------------------------------===//
23
24static void printRecordMembers(mlir::AsmPrinter &p, mlir::ArrayAttr members);
25static mlir::ParseResult parseRecordMembers(mlir::AsmParser &parser,
26 mlir::ArrayAttr &members);
27
28//===-----------------------------------------------------------------===//
29// IntLiteral
30//===-----------------------------------------------------------------===//
31
32static void printIntLiteral(mlir::AsmPrinter &p, llvm::APInt value,
33 cir::IntTypeInterface ty);
34static mlir::ParseResult parseIntLiteral(mlir::AsmParser &parser,
35 llvm::APInt &value,
36 cir::IntTypeInterface ty);
37//===-----------------------------------------------------------------===//
38// FloatLiteral
39//===-----------------------------------------------------------------===//
40
41static void printFloatLiteral(mlir::AsmPrinter &p, llvm::APFloat value,
42 mlir::Type ty);
43static mlir::ParseResult
44parseFloatLiteral(mlir::AsmParser &parser,
45 mlir::FailureOr<llvm::APFloat> &value,
46 cir::FPTypeInterface fpType);
47
48static mlir::ParseResult parseConstPtr(mlir::AsmParser &parser,
49 mlir::IntegerAttr &value);
50
51static void printConstPtr(mlir::AsmPrinter &p, mlir::IntegerAttr value);
52
53static mlir::ParseResult
54parseDataMemberPath(mlir::AsmParser &parser,
55 mlir::DenseI32ArrayAttr &memberPath);
56
57static void printDataMemberPath(mlir::AsmPrinter &p,
58 mlir::DenseI32ArrayAttr memberPath);
59
60#define GET_ATTRDEF_CLASSES
61#include "clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc"
62
63using namespace mlir;
64using namespace cir;
65
66//===----------------------------------------------------------------------===//
67// MemorySpaceAttrInterface implementations for Lang and Target address space
68// attributes
69//===----------------------------------------------------------------------===//
70
71bool LangAddressSpaceAttr::isValidLoad(
72 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
73 std::optional<int64_t> alignment, const mlir::DataLayout *dataLayout,
74 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
75 llvm_unreachable("isValidLoad for LangAddressSpaceAttr NYI");
76}
77
78bool LangAddressSpaceAttr::isValidStore(
79 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
80 std::optional<int64_t> alignment, const mlir::DataLayout *dataLayout,
81 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
82 llvm_unreachable("isValidStore for LangAddressSpaceAttr NYI");
83}
84
85bool LangAddressSpaceAttr::isValidAtomicOp(
86 mlir::ptr::AtomicBinOp op, mlir::Type type,
87 mlir::ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
88 const mlir::DataLayout *dataLayout,
89 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
90 llvm_unreachable("isValidAtomicOp for LangAddressSpaceAttr NYI");
91}
92
93bool LangAddressSpaceAttr::isValidAtomicXchg(
94 mlir::Type type, mlir::ptr::AtomicOrdering successOrdering,
95 mlir::ptr::AtomicOrdering failureOrdering, std::optional<int64_t> alignment,
96 const mlir::DataLayout *dataLayout,
97 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
98 llvm_unreachable("isValidAtomicXchg for LangAddressSpaceAttr NYI");
99}
100
101bool LangAddressSpaceAttr::isValidAddrSpaceCast(
102 mlir::Type tgt, mlir::Type src,
103 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
104 llvm_unreachable("isValidAddrSpaceCast for LangAddressSpaceAttr NYI");
105}
106
107bool LangAddressSpaceAttr::isValidPtrIntCast(
108 mlir::Type intLikeTy, mlir::Type ptrLikeTy,
109 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
110 llvm_unreachable("isValidPtrIntCast for LangAddressSpaceAttr NYI");
111}
112
113bool TargetAddressSpaceAttr::isValidLoad(
114 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
115 std::optional<int64_t> alignment, const mlir::DataLayout *dataLayout,
116 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
117 llvm_unreachable("isValidLoad for TargetAddressSpaceAttr NYI");
118}
119
120bool TargetAddressSpaceAttr::isValidStore(
121 mlir::Type type, mlir::ptr::AtomicOrdering ordering,
122 std::optional<int64_t> alignment, const mlir::DataLayout *dataLayout,
123 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
124 llvm_unreachable("isValidStore for TargetAddressSpaceAttr NYI");
125}
126
127bool TargetAddressSpaceAttr::isValidAtomicOp(
128 mlir::ptr::AtomicBinOp op, mlir::Type type,
129 mlir::ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
130 const mlir::DataLayout *dataLayout,
131 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
132 llvm_unreachable("isValidAtomicOp for TargetAddressSpaceAttr NYI");
133}
134
135bool TargetAddressSpaceAttr::isValidAtomicXchg(
136 mlir::Type type, mlir::ptr::AtomicOrdering successOrdering,
137 mlir::ptr::AtomicOrdering failureOrdering, std::optional<int64_t> alignment,
138 const mlir::DataLayout *dataLayout,
139 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
140 llvm_unreachable("isValidAtomicXchg for TargetAddressSpaceAttr NYI");
141}
142
143bool TargetAddressSpaceAttr::isValidAddrSpaceCast(
144 mlir::Type tgt, mlir::Type src,
145 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
146 llvm_unreachable("isValidAddrSpaceCast for TargetAddressSpaceAttr NYI");
147}
148
149bool TargetAddressSpaceAttr::isValidPtrIntCast(
150 mlir::Type intLikeTy, mlir::Type ptrLikeTy,
151 llvm::function_ref<mlir::InFlightDiagnostic()> emitError) const {
152 llvm_unreachable("isValidPtrIntCast for TargetAddressSpaceAttr NYI");
153}
154
155//===----------------------------------------------------------------------===//
156// PtrSpecAttr definitions
157//===----------------------------------------------------------------------===//
158
159LogicalResult PtrSpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,
160 uint32_t size, uint32_t abi,
161 uint32_t preferred, uint32_t index) {
162 constexpr unsigned kBitsInByte = 8;
163 if (size % kBitsInByte != 0)
164 return emitError() << "size entry must be divisible by 8";
165 if (abi % kBitsInByte != 0)
166 return emitError() << "abi entry must be divisible by 8";
167 if (preferred % kBitsInByte != 0)
168 return emitError() << "preferred entry must be divisible by 8";
169 if (index != kOptionalSpecValue && index % kBitsInByte != 0)
170 return emitError() << "index entry must be divisible by 8";
171 if (abi > preferred)
172 return emitError() << "preferred alignment is expected to be at least "
173 "as large as ABI alignment";
174 return success();
175}
176
177//===----------------------------------------------------------------------===//
178// BitIntSpecAttr definitions
179//===----------------------------------------------------------------------===//
180
181LogicalResult
182BitIntSpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,
183 uint32_t maxAlign) {
184 // TargetInfo::getBitIntMaxAlign() is a power of two, at least the char
185 // width. Char width is 8 bits.
186 if (maxAlign < 8 || !llvm::isPowerOf2_32(maxAlign))
187 return emitError() << "max_align must be a power of two of at least 8";
188 return success();
189}
190
191//===----------------------------------------------------------------------===//
192// BitFieldDeclAttr definitions
193//===----------------------------------------------------------------------===//
194
195LogicalResult
196BitFieldDeclAttr::verify(function_ref<InFlightDiagnostic()> emitError,
197 mlir::Type declaredType, uint64_t width,
198 bool isUnnamed) {
199 if (width == 0 && !isUnnamed)
200 return emitError() << "zero-width bit-field cannot be named";
201 return success();
202}
203
204//===----------------------------------------------------------------------===//
205// General CIR parsing / printing
206//===----------------------------------------------------------------------===//
207
208static void printRecordMembers(mlir::AsmPrinter &printer,
209 mlir::ArrayAttr members) {
210 printer << '{';
211 llvm::interleaveComma(members, printer);
212 printer << '}';
213}
214
215static ParseResult parseRecordMembers(mlir::AsmParser &parser,
216 mlir::ArrayAttr &members) {
218
219 auto delimiter = AsmParser::Delimiter::Braces;
220 auto result = parser.parseCommaSeparatedList(delimiter, [&]() {
221 mlir::TypedAttr attr;
222 if (parser.parseAttribute(attr).failed())
223 return mlir::failure();
224 elts.push_back(attr);
225 return mlir::success();
226 });
227
228 if (result.failed())
229 return mlir::failure();
230
231 members = mlir::ArrayAttr::get(parser.getContext(), elts);
232 return mlir::success();
233}
234
235//===----------------------------------------------------------------------===//
236// ConstRecordAttr definitions
237//===----------------------------------------------------------------------===//
238
239static bool isValidFlexibleArrayInit(mlir::Type memberType,
240 mlir::Type initType) {
241 auto memberArrayType = mlir::dyn_cast<cir::ArrayType>(memberType);
242 auto initArrayType = mlir::dyn_cast<cir::ArrayType>(initType);
243 return memberArrayType && memberArrayType.getSize() == 0 && initArrayType &&
244 memberArrayType.getElementType() == initArrayType.getElementType();
245}
246
247LogicalResult
248ConstRecordAttr::verify(function_ref<InFlightDiagnostic()> emitError,
249 mlir::Type type, ArrayAttr members) {
250 auto sTy = mlir::dyn_cast_if_present<cir::RecordType>(type);
251 if (!sTy)
252 return emitError() << "expected !cir.struct or !cir.union type";
253
254 // union record initializer is just a single element that has to match one of
255 // the fields in the union (the new active member).
256 if (sTy.isUnion()) {
257 if (members.size() != 1)
258 return emitError() << "union constant must have exactly one element, got "
259 << members.size();
260 auto m = mlir::cast<mlir::TypedAttr>(members[0]);
261 // A bit-field variant is initialized as the access unit it owns.
262 if (!llvm::any_of(sTy.getMembers(), [&](mlir::Type memberTy) {
263 mlir::Type storageType = cir::memberStorageType(memberTy);
264 return storageType == m.getType() ||
265 isValidFlexibleArrayInit(storageType, m.getType());
266 }))
267 return emitError() << "union element type " << m.getType()
268 << " is not a member of " << sTy;
269 return success();
270 }
271
272 // A member that owns no bytes is not stored, so it takes no element. A
273 // bit-field's bits are packed into the element of the member that owns its
274 // access unit, and a zero-width bit-field has no bits to store at all.
275 llvm::SmallVector<mlir::Type> storedMembers;
276 for (mlir::Type memberTy : sTy.getMembers())
277 if (cir::memberOwnsBytes(memberTy))
278 storedMembers.push_back(cir::memberStorageType(memberTy));
279
280 if (storedMembers.size() != members.size())
281 return emitError() << "number of elements must match";
282
283 for (const auto &[attrIdx, member] : llvm::enumerate(storedMembers)) {
284 auto m = mlir::cast<mlir::TypedAttr>(members[attrIdx]);
285
286 // As a special case, we allow a flexible array member. This can only be the
287 // last element, the rest of the array type has to match (that is, the
288 // element type has to match), and the array member must be size zero.
289 if (attrIdx == storedMembers.size() - 1) {
290 auto memArrayTy = dyn_cast<cir::ArrayType>(member);
291 if (memArrayTy && memArrayTy.getSize() == 0) {
292
293 // The FAM must only match another array type initializer.
294 if (!isa<cir::ArrayType>(m.getType()))
295 return emitError()
296 << "element at index " << attrIdx << " has type "
297 << m.getType() << " but the expected type for this element is "
298 << member;
299
300 cir::ArrayType initArrayTy = cast<cir::ArrayType>(m.getType());
301 // The FAM only matches an equivalent array type.
302 if (initArrayTy.getElementType() != memArrayTy.getElementType())
303 return emitError()
304 << "flexible array member at index " << attrIdx << " has type "
305 << m.getType()
306 << " which doesn't match the expected element type of member "
307 << member;
308 continue;
309 }
310 }
311
312 if (member != m.getType())
313 return emitError() << "element at index " << attrIdx << " has type "
314 << m.getType()
315 << " but the expected type for this element is "
316 << member;
317 }
318
319 return success();
320}
321
322//===----------------------------------------------------------------------===//
323// OptInfoAttr definitions
324//===----------------------------------------------------------------------===//
325
326LogicalResult OptInfoAttr::verify(function_ref<InFlightDiagnostic()> emitError,
327 unsigned level, unsigned size) {
328 if (level > 3)
329 return emitError()
330 << "optimization level must be between 0 and 3 inclusive";
331 if (size > 2)
332 return emitError()
333 << "size optimization level must be between 0 and 2 inclusive";
334 return success();
335}
336
337//===----------------------------------------------------------------------===//
338// ConstPtrAttr definitions
339//===----------------------------------------------------------------------===//
340
341// TODO(CIR): Consider encoding the null value differently and use conditional
342// assembly format instead of custom parsing/printing.
343static ParseResult parseConstPtr(AsmParser &parser, mlir::IntegerAttr &value) {
344
345 if (parser.parseOptionalKeyword("null").succeeded()) {
346 value = parser.getBuilder().getI64IntegerAttr(0);
347 return success();
348 }
349
350 return parser.parseAttribute(value);
351}
352
353static void printConstPtr(AsmPrinter &p, mlir::IntegerAttr value) {
354 if (!value.getInt())
355 p << "null";
356 else
357 p << value;
358}
359
360static ParseResult parseDataMemberPath(AsmParser &parser,
361 mlir::DenseI32ArrayAttr &memberPath) {
362 if (parser.parseOptionalKeyword("null").succeeded())
363 return success();
364
365 auto parsed = mlir::FieldParser<mlir::DenseI32ArrayAttr>::parse(parser);
366 if (mlir::failed(parsed))
367 return failure();
368 memberPath = *parsed;
369 return success();
370}
371
372static void printDataMemberPath(AsmPrinter &p,
373 mlir::DenseI32ArrayAttr memberPath) {
374 if (!memberPath)
375 p << "null";
376 else
377 p.printStrippedAttrOrType(memberPath);
378}
379
380//===----------------------------------------------------------------------===//
381// IntAttr definitions
382//===----------------------------------------------------------------------===//
383
384mlir::ParseResult parseIntLiteral(mlir::AsmParser &parser, llvm::APInt &value,
385 cir::IntTypeInterface ty) {
386 llvm::SMLoc loc = parser.getCurrentLocation();
387 llvm::APInt parsed;
388 mlir::OptionalParseResult result = parser.parseOptionalInteger(parsed);
389 if (!result.has_value() || failed(*result))
390 return parser.emitError(loc, "expected integer value");
391
392 const unsigned width = ty.getWidth();
393 const bool fits =
394 ty.isSigned() ? parsed.getSignificantBits() <= width
395 : !parsed.isNegative() && parsed.getActiveBits() <= width;
396 if (!fits)
397 return parser.emitError(loc, "integer value too large for the given type");
398
399 value = ty.isSigned() ? parsed.sextOrTrunc(width) : parsed.zextOrTrunc(width);
400 return success();
401}
402
403void printIntLiteral(mlir::AsmPrinter &p, llvm::APInt value,
404 cir::IntTypeInterface ty) {
406 value.toString(str, /*radix=*/10, /*isSigned=*/ty.isSigned());
407 p << str;
408}
409
410LogicalResult IntAttr::verify(function_ref<InFlightDiagnostic()> emitError,
411 cir::IntTypeInterface type, llvm::APInt value) {
412 if (value.getBitWidth() != type.getWidth())
413 return emitError() << "type and value bitwidth mismatch: "
414 << type.getWidth() << " != " << value.getBitWidth();
415 return success();
416}
417
418//===----------------------------------------------------------------------===//
419// FPAttr definitions
420//===----------------------------------------------------------------------===//
421
422static void printFloatLiteral(AsmPrinter &p, APFloat value, Type ty) {
423 p << value;
424}
425
426static ParseResult parseFloatLiteral(AsmParser &parser,
427 FailureOr<APFloat> &value,
428 cir::FPTypeInterface fpType) {
429
430 APFloat parsedValue(0.0);
431 if (parser.parseFloat(fpType.getFloatSemantics(), parsedValue))
432 return failure();
433
434 value.emplace(parsedValue);
435 return success();
436}
437
438//===----------------------------------------------------------------------===//
439// MemoryEffectsAttr definitions
440//===----------------------------------------------------------------------===//
441
442MemoryEffectsAttr MemoryEffectsAttr::none(MLIRContext *ctx) {
443 return get(ctx, ModRefInfo::NoModRef);
444}
445
446MemoryEffectsAttr MemoryEffectsAttr::readOnly(MLIRContext *ctx) {
447 return get(ctx, ModRefInfo::Ref);
448}
449
450MemoryEffectsAttr MemoryEffectsAttr::writeOnly(MLIRContext *ctx) {
451 return get(ctx, ModRefInfo::Mod);
452}
453
454MemoryEffectsAttr MemoryEffectsAttr::argMemOnly(MLIRContext *ctx,
455 ModRefInfo mr) {
456 return get(ctx, /*other=*/ModRefInfo::NoModRef, /*arg_mem=*/mr,
457 /*inaccessible_mem=*/ModRefInfo::NoModRef,
458 /*errno_mem=*/ModRefInfo::NoModRef,
459 /*target_mem0=*/ModRefInfo::NoModRef,
460 /*target_mem1=*/ModRefInfo::NoModRef);
461}
462
463MemoryEffectsAttr MemoryEffectsAttr::inaccessibleMemOnly(MLIRContext *ctx,
464 ModRefInfo mr) {
465 return get(ctx, /*other=*/ModRefInfo::NoModRef,
466 /*arg_mem=*/ModRefInfo::NoModRef, /*inaccessible_mem=*/mr,
467 /*errno_mem=*/ModRefInfo::NoModRef,
468 /*target_mem0=*/ModRefInfo::NoModRef,
469 /*target_mem1=*/ModRefInfo::NoModRef);
470}
471
472MemoryEffectsAttr MemoryEffectsAttr::errnoMemOnly(MLIRContext *ctx,
473 ModRefInfo mr) {
474 return get(ctx, /*other=*/ModRefInfo::NoModRef,
475 /*arg_mem=*/ModRefInfo::NoModRef,
476 /*inaccessible_mem=*/ModRefInfo::NoModRef, /*errno_mem=*/mr,
477 /*target_mem0=*/ModRefInfo::NoModRef,
478 /*target_mem1=*/ModRefInfo::NoModRef);
479}
480
481MemoryEffectsAttr MemoryEffectsAttr::otherMemOnly(MLIRContext *ctx,
482 ModRefInfo mr) {
483 return get(ctx, /*other=*/mr, /*arg_mem=*/ModRefInfo::NoModRef,
484 /*inaccessible_mem=*/ModRefInfo::NoModRef,
485 /*errno_mem=*/ModRefInfo::NoModRef,
486 /*target_mem0=*/ModRefInfo::NoModRef,
487 /*target_mem1=*/ModRefInfo::NoModRef);
488}
489
490MemoryEffectsAttr MemoryEffectsAttr::inaccessibleOrArgMemOnly(MLIRContext *ctx,
491 ModRefInfo mr) {
492 return get(ctx, /*other=*/ModRefInfo::NoModRef, /*arg_mem=*/mr,
493 /*inaccessible_mem=*/mr, /*errno_mem=*/ModRefInfo::NoModRef,
494 /*target_mem0=*/ModRefInfo::NoModRef,
495 /*target_mem1=*/ModRefInfo::NoModRef);
496}
497
498MemoryEffectsAttr MemoryEffectsAttr::inaccessibleOrErrnoMemOnly(
499 MLIRContext *ctx, ModRefInfo inaccessibleMr, ModRefInfo errnoMr) {
500 return get(ctx, /*other=*/ModRefInfo::NoModRef,
501 /*arg_mem=*/ModRefInfo::NoModRef,
502 /*inaccessible_mem=*/inaccessibleMr, /*errno_mem=*/errnoMr,
503 /*target_mem0=*/ModRefInfo::NoModRef,
504 /*target_mem1=*/ModRefInfo::NoModRef);
505}
506
507MemoryEffectsAttr MemoryEffectsAttr::inaccessibleOrArgOrErrnoMemOnly(
508 MLIRContext *ctx, ModRefInfo inaccessibleOrArgMr, ModRefInfo errnoMr) {
509 return get(ctx, /*other=*/ModRefInfo::NoModRef,
510 /*arg_mem=*/inaccessibleOrArgMr,
511 /*inaccessible_mem=*/inaccessibleOrArgMr, /*errno_mem=*/errnoMr,
512 /*target_mem0=*/ModRefInfo::NoModRef,
513 /*target_mem1=*/ModRefInfo::NoModRef);
514}
515
516MemoryEffectsAttr
517MemoryEffectsAttr::argumentOrErrnoMemOnly(MLIRContext *ctx, ModRefInfo argMr,
518 ModRefInfo errnoMr) {
519 return get(ctx, /*other=*/ModRefInfo::NoModRef, /*arg_mem=*/argMr,
520 /*inaccessible_mem=*/ModRefInfo::NoModRef, /*errno_mem=*/errnoMr,
521 /*target_mem0=*/ModRefInfo::NoModRef,
522 /*target_mem1=*/ModRefInfo::NoModRef);
523}
524
525FPAttr FPAttr::getZero(Type type) {
526 return get(type,
527 APFloat::getZero(
528 mlir::cast<cir::FPTypeInterface>(type).getFloatSemantics()));
529}
530
531LogicalResult FPAttr::verify(function_ref<InFlightDiagnostic()> emitError,
532 cir::FPTypeInterface fpType, APFloat value) {
533 if (APFloat::SemanticsToEnum(fpType.getFloatSemantics()) !=
534 APFloat::SemanticsToEnum(value.getSemantics()))
535 return emitError() << "floating-point semantics mismatch";
536
537 return success();
538}
539
540//===----------------------------------------------------------------------===//
541// CmpThreeWayInfoAttr definitions
542//===----------------------------------------------------------------------===//
543
544std::string CmpThreeWayInfoAttr::getAlias() const {
545 std::string alias = "cmpinfo";
546
547 switch (getOrdering()) {
548 case CmpOrdering::Strong:
549 alias.append("_strong_");
550 break;
551 case CmpOrdering::Weak:
552 alias.append("_weak_");
553 break;
554 case CmpOrdering::Partial:
555 alias.append("_partial_");
556 break;
557 }
558
559 auto appendInt = [&](int64_t value) {
560 if (value < 0) {
561 alias.push_back('n');
562 value = -value;
563 }
564 alias.append(std::to_string(value));
565 };
566
567 alias.append("lt");
568 appendInt(getLt());
569 alias.append("eq");
570 appendInt(getEq());
571 alias.append("gt");
572 appendInt(getGt());
573
574 if (std::optional<int> unordered = getUnordered()) {
575 alias.append("un");
576 appendInt(unordered.value());
577 }
578
579 return alias;
580}
581
582LogicalResult
583CmpThreeWayInfoAttr::verify(function_ref<InFlightDiagnostic()> emitError,
584 CmpOrdering ordering, int64_t lt, int64_t eq,
585 int64_t gt, std::optional<int64_t> unordered) {
586 // The presence of unordered must match the value of ordering.
587 if ((ordering == CmpOrdering::Strong || ordering == CmpOrdering::Weak) &&
588 unordered) {
589 emitError() << "strong and weak ordering do not include unordered";
590 return failure();
591 }
592 if (ordering == CmpOrdering::Partial && !unordered) {
593 emitError() << "partial ordering requires unordered value";
594 return failure();
595 }
596
597 return success();
598}
599
600//===----------------------------------------------------------------------===//
601// ConstComplexAttr definitions
602//===----------------------------------------------------------------------===//
603
604LogicalResult
605ConstComplexAttr::verify(function_ref<InFlightDiagnostic()> emitError,
606 cir::ComplexType type, mlir::TypedAttr real,
607 mlir::TypedAttr imag) {
608 mlir::Type elemType = type.getElementType();
609 if (real.getType() != elemType)
610 return emitError()
611 << "type of the real part does not match the complex type";
612
613 if (imag.getType() != elemType)
614 return emitError()
615 << "type of the imaginary part does not match the complex type";
616
617 return success();
618}
619
620//===----------------------------------------------------------------------===//
621// CIR_CUDAVarRegistrationInfoAttr definitions
622//===----------------------------------------------------------------------===//
623
624void CUDAVarRegistrationInfoAttr::print(AsmPrinter &p) const {
625 p << "<" << getDeviceSideName();
626 p << ", " << stringifyEnum(getKind());
627 if (getIsExtern())
628 p << ", extern";
629 if (getIsConstant())
630 p << ", constant";
631 if (getIsManaged())
632 p << ", managed";
633 if (getKind() == CUDADeviceVarKind::Surface)
634 p << ", surface_type = " << getSurfTexType();
635 else if (getKind() == CUDADeviceVarKind::Texture) {
636 p << ", texture_type = " << getSurfTexType();
637 if (getNormalized())
638 p << ", normalized";
639 }
640 p << ">";
641}
642
643Attribute CUDAVarRegistrationInfoAttr::parse(AsmParser &parser, Type odsType) {
644 if (parser.parseLess())
645 return {};
646
647 std::string deviceSideName;
648 if (parser.parseKeywordOrString(&deviceSideName)) {
649 parser.emitError(parser.getCurrentLocation(),
650 "expected device variable name");
651 return {};
652 }
653
654 if (parser.parseComma())
655 return {};
656
657 // Parse the device variable kind (Variable, Surface, Texture)
658 StringRef kindStr;
659 if (parser.parseKeyword(&kindStr))
660 return {};
661
662 std::optional<CUDADeviceVarKind> kind = symbolizeCUDADeviceVarKind(kindStr);
663 if (!kind) {
664 parser.emitError(parser.getCurrentLocation(),
665 "unknown device variable kind: ")
666 << kindStr;
667 return {};
668 }
669
670 // Parse optional flags: extern, constant, managed
671 bool isExtern = false;
672 bool isConstant = false;
673 bool isManaged = false;
674 int32_t surfTexType = 0;
675 bool normalized = false;
676
677 while (parser.parseOptionalGreater().failed()) {
678 if (parser.parseComma())
679 return {};
680
681 StringRef flag;
682 if (parser.parseKeyword(&flag))
683 return {};
684
685 if (flag == "extern")
686 isExtern = true;
687 else if (flag == "constant")
688 isConstant = true;
689 else if (flag == "managed")
690 isManaged = true;
691 else if (flag == "normalized") {
692 if (*kind != CUDADeviceVarKind::Texture) {
693 parser.emitError(parser.getCurrentLocation(),
694 "'normalized' is only valid for Texture");
695 return {};
696 }
697 normalized = true;
698 } else if (flag == "surface_type") {
699 if (*kind != CUDADeviceVarKind::Surface) {
700 parser.emitError(parser.getCurrentLocation(),
701 "'surface_type' is only valid for Surface");
702 return {};
703 }
704 if (parser.parseEqual() || parser.parseInteger(surfTexType))
705 return {};
706 } else if (flag == "texture_type") {
707 if (*kind != CUDADeviceVarKind::Texture) {
708 parser.emitError(parser.getCurrentLocation(),
709 "'texture_type' is only valid for Texture");
710 return {};
711 }
712 if (parser.parseEqual() || parser.parseInteger(surfTexType))
713 return {};
714 } else {
715 parser.emitError(parser.getCurrentLocation(), "unknown flag: ") << flag;
716 return {};
717 }
718 }
719
720 return get(parser.getContext(), deviceSideName, *kind, isExtern, isConstant,
721 isManaged, surfTexType, normalized);
722}
723
724//===----------------------------------------------------------------------===//
725// DataMemberAttr definitions
726//===----------------------------------------------------------------------===//
727
728LogicalResult
729DataMemberAttr::verify(function_ref<InFlightDiagnostic()> emitError,
730 cir::DataMemberType ty,
731 mlir::DenseI32ArrayAttr memberPath) {
732 if (!memberPath)
733 return success(); // null pointer — always valid
734
735 if (memberPath.empty())
736 return emitError() << "#cir.data_member path must not be empty";
737
738 mlir::Type currentTy = ty.getClassTy();
739 for (auto [step, idx] : llvm::enumerate(memberPath.asArrayRef())) {
740 auto recTy = mlir::dyn_cast<cir::RecordType>(currentTy);
741 if (!recTy)
742 return emitError() << "#cir.data_member path step " << step
743 << " reaches a non-record type";
744
745 if (recTy.isIncomplete())
746 return success(); // cannot validate further; trust the builder
747
748 if (idx < 0 || static_cast<unsigned>(idx) >= recTy.getNumElements())
749 return emitError() << "#cir.data_member path index " << idx << " at step "
750 << step << " is out of range";
751
752 currentTy = recTy.getMembers()[idx];
753 }
754
755 if (currentTy != ty.getMemberTy())
756 return emitError()
757 << "member type of a #cir.data_member attribute must match "
758 "the attribute type";
759
760 return success();
761}
762
763//===----------------------------------------------------------------------===//
764// MethodAttr definitions
765//===----------------------------------------------------------------------===//
766
767LogicalResult MethodAttr::verify(function_ref<InFlightDiagnostic()> emitError,
768 cir::MethodType type,
769 std::optional<FlatSymbolRefAttr> symbol,
770 std::optional<uint64_t> vtable_offset) {
771 if (symbol.has_value() && vtable_offset.has_value())
772 return emitError()
773 << "at most one of symbol and vtable_offset can be present "
774 "in #cir.method";
775
776 return success();
777}
778
779Attribute MethodAttr::parse(AsmParser &parser, Type odsType) {
780 auto ty = mlir::cast<cir::MethodType>(odsType);
781
782 if (parser.parseLess().failed())
783 return {};
784
785 // Try to parse the null pointer constant.
786 if (parser.parseOptionalKeyword("null").succeeded()) {
787 if (parser.parseGreater().failed())
788 return {};
789 return get(ty);
790 }
791
792 // Try to parse a flat symbol ref for a pointer to non-virtual member
793 // function.
794 FlatSymbolRefAttr symbol;
795 mlir::OptionalParseResult parseSymbolRefResult =
796 parser.parseOptionalAttribute(symbol);
797 if (parseSymbolRefResult.has_value()) {
798 if (parseSymbolRefResult.value().failed())
799 return {};
800 if (parser.parseGreater().failed())
801 return {};
802 return get(ty, symbol);
803 }
804
805 // Parse a uint64 that represents the vtable offset.
806 std::uint64_t vtableOffset = 0;
807 if (parser.parseKeyword("vtable_offset"))
808 return {};
809 if (parser.parseEqual())
810 return {};
811 if (parser.parseInteger(vtableOffset))
812 return {};
813
814 if (parser.parseGreater())
815 return {};
816
817 return get(ty, vtableOffset);
818}
819
820void MethodAttr::print(AsmPrinter &printer) const {
821 auto symbol = getSymbol();
822 auto vtableOffset = getVtableOffset();
823
824 printer << '<';
825 if (symbol.has_value()) {
826 printer << *symbol;
827 } else if (vtableOffset.has_value()) {
828 printer << "vtable_offset = " << *vtableOffset;
829 } else {
830 printer << "null";
831 }
832 printer << '>';
833}
834
835//===----------------------------------------------------------------------===//
836// CIR ConstArrayAttr
837//===----------------------------------------------------------------------===//
838
839LogicalResult
840ConstArrayAttr::verify(function_ref<InFlightDiagnostic()> emitError, Type type,
841 Attribute elts, int trailingZerosNum) {
842
843 if (!(mlir::isa<ArrayAttr, StringAttr>(elts)))
844 return emitError() << "constant array expects ArrayAttr or StringAttr";
845
846 if (auto strAttr = mlir::dyn_cast<StringAttr>(elts)) {
847 const auto arrayTy = mlir::cast<ArrayType>(type);
848 const auto intTy = mlir::dyn_cast<IntType>(arrayTy.getElementType());
849
850 // TODO: add CIR type for char.
851 if (!intTy || intTy.getWidth() != 8)
852 return emitError()
853 << "constant array element for string literals expects "
854 "!cir.int<u, 8> element type";
855 return success();
856 }
857
858 assert(mlir::isa<ArrayAttr>(elts));
859 const auto arrayAttr = mlir::cast<mlir::ArrayAttr>(elts);
860 const auto arrayTy = mlir::cast<ArrayType>(type);
861
862 // Make sure both number of elements and subelement types match type.
863 if (arrayAttr.size() > arrayTy.getSize())
864 return emitError() << "constant array has " << arrayAttr.size()
865 << " values but array type has size "
866 << arrayTy.getSize();
867 if (arrayTy.getSize() != arrayAttr.size() + trailingZerosNum)
868 return emitError() << "constant array size should match type size";
869 return success();
870}
871
872Attribute ConstArrayAttr::parse(AsmParser &parser, Type type) {
873 mlir::FailureOr<Type> resultTy;
874 mlir::FailureOr<Attribute> resultVal;
875
876 // Parse literal '<'
877 if (parser.parseLess())
878 return {};
879
880 // Parse variable 'value'
881 resultVal = FieldParser<Attribute>::parse(parser);
882 if (failed(resultVal)) {
883 parser.emitError(
884 parser.getCurrentLocation(),
885 "failed to parse ConstArrayAttr parameter 'value' which is "
886 "to be a `Attribute`");
887 return {};
888 }
889
890 // ArrayAttrrs have per-element type, not the type of the array...
891 if (mlir::isa<ArrayAttr>(*resultVal)) {
892 // Array has implicit type: infer from const array type.
893 if (parser.parseOptionalColon().failed()) {
894 resultTy = type;
895 } else { // Array has explicit type: parse it.
896 resultTy = FieldParser<Type>::parse(parser);
897 if (failed(resultTy)) {
898 parser.emitError(
899 parser.getCurrentLocation(),
900 "failed to parse ConstArrayAttr parameter 'type' which is "
901 "to be a `::mlir::Type`");
902 return {};
903 }
904 }
905 } else {
906 auto ta = mlir::cast<TypedAttr>(*resultVal);
907 resultTy = ta.getType();
908 if (mlir::isa<mlir::NoneType>(*resultTy)) {
909 parser.emitError(parser.getCurrentLocation(),
910 "expected type declaration for string literal");
911 return {};
912 }
913 }
914
915 unsigned zeros = 0;
916 if (parser.parseOptionalComma().succeeded()) {
917 if (parser.parseOptionalKeyword("trailing_zeros").succeeded()) {
918 unsigned totalSize = mlir::cast<cir::ArrayType>(type).getSize();
919 mlir::Attribute elts = resultVal.value();
920 if (auto str = mlir::dyn_cast<mlir::StringAttr>(elts))
921 zeros = totalSize - str.size();
922 else
923 zeros = totalSize - mlir::cast<mlir::ArrayAttr>(elts).size();
924 } else {
925 return {};
926 }
927 }
928
929 // Parse literal '>'
930 if (parser.parseGreater())
931 return {};
932
933 return parser.getChecked<ConstArrayAttr>(parser.getCurrentLocation(),
934 parser.getContext(), type,
935 resultVal.value(), zeros);
936}
937
938void ConstArrayAttr::print(AsmPrinter &printer) const {
939 printer << "<";
940 printer.printStrippedAttrOrType(getElts());
941 if (getTrailingZerosNum())
942 printer << ", trailing_zeros";
943 printer << ">";
944}
945
946//===----------------------------------------------------------------------===//
947// CIR ConstVectorAttr
948//===----------------------------------------------------------------------===//
949
950LogicalResult
951cir::ConstVectorAttr::verify(function_ref<InFlightDiagnostic()> emitError,
952 Type type, ArrayAttr elts) {
953
954 if (!mlir::isa<cir::VectorType>(type))
955 return emitError() << "type of cir::ConstVectorAttr is not a "
956 "cir::VectorType: "
957 << type;
958
959 const auto vecType = mlir::cast<cir::VectorType>(type);
960
961 if (vecType.isScalable())
962 return emitError() << "scalable vector constants are not supported";
963
964 if (vecType.getFixedSize() != elts.size())
965 return emitError()
966 << "number of constant elements should match vector size";
967
968 // Check if the types of the elements match
969 LogicalResult elementTypeCheck = success();
970 elts.walkImmediateSubElements(
971 [&](Attribute element) {
972 if (elementTypeCheck.failed()) {
973 // An earlier element didn't match
974 return;
975 }
976 auto typedElement = mlir::dyn_cast<TypedAttr>(element);
977 if (!typedElement ||
978 typedElement.getType() != vecType.getElementType()) {
979 elementTypeCheck = failure();
980 emitError() << "constant type should match vector element type";
981 }
982 },
983 [&](Type) {});
984
985 return elementTypeCheck;
986}
987
988//===----------------------------------------------------------------------===//
989// CIR VTableAttr
990//===----------------------------------------------------------------------===//
991
992LogicalResult cir::VTableAttr::verify(
993 llvm::function_ref<mlir::InFlightDiagnostic()> emitError, mlir::Type type,
994 mlir::ArrayAttr data) {
995 auto sTy = mlir::dyn_cast_if_present<cir::RecordType>(type);
996 if (!sTy)
997 return emitError() << "expected !cir.struct or !cir.union type result";
998 if (sTy.getMembers().empty() || data.empty())
999 return emitError() << "expected record type with one or more subtype";
1000
1001 if (cir::ConstRecordAttr::verify(emitError, type, data).failed())
1002 return failure();
1003
1004 for (const auto &element : data.getAsRange<mlir::Attribute>()) {
1005 const auto &constArrayAttr = mlir::dyn_cast<cir::ConstArrayAttr>(element);
1006 if (!constArrayAttr)
1007 return emitError() << "expected constant array subtype";
1008
1009 LogicalResult eltTypeCheck = success();
1010 auto arrayElts = mlir::cast<ArrayAttr>(constArrayAttr.getElts());
1011 arrayElts.walkImmediateSubElements(
1012 [&](mlir::Attribute attr) {
1013 if (mlir::isa<ConstPtrAttr, GlobalViewAttr>(attr))
1014 return;
1015
1016 eltTypeCheck = emitError()
1017 << "expected GlobalViewAttr or ConstPtrAttr";
1018 },
1019 [&](mlir::Type type) {});
1020 if (eltTypeCheck.failed())
1021 return eltTypeCheck;
1022 }
1023 return success();
1024}
1025
1026//===----------------------------------------------------------------------===//
1027// DynamicCastInfoAtttr definitions
1028//===----------------------------------------------------------------------===//
1029
1030std::string DynamicCastInfoAttr::getAlias() const {
1031 // The alias looks like: `dyn_cast_info_<src>_<dest>`
1032
1033 std::string alias = "dyn_cast_info_";
1034
1035 alias.append(getSrcRtti().getSymbol().getValue());
1036 alias.push_back('_');
1037 alias.append(getDestRtti().getSymbol().getValue());
1038
1039 return alias;
1040}
1041
1042// TODO: Give type_info a distinct CIR type so we can verify that a
1043// FlatSymbolRefAttr actually names a type_info global.
1044static bool isRttiPtr(mlir::Type ty) {
1045 auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty);
1046 if (!ptrTy)
1047 return false;
1048
1049 auto pointeeIntTy = mlir::dyn_cast<cir::IntType>(ptrTy.getPointee());
1050 if (!pointeeIntTy)
1051 return false;
1052
1053 return pointeeIntTy.isUnsigned() && pointeeIntTy.getWidth() == 8;
1054}
1055
1056LogicalResult DynamicCastInfoAttr::verify(
1057 function_ref<InFlightDiagnostic()> emitError, cir::GlobalViewAttr srcRtti,
1058 cir::GlobalViewAttr destRtti, mlir::FlatSymbolRefAttr runtimeFunc,
1059 mlir::FlatSymbolRefAttr badCastFunc, cir::IntAttr offsetHint) {
1060 if (!isRttiPtr(srcRtti.getType()))
1061 return emitError() << "srcRtti must be an RTTI pointer";
1062
1063 if (!isRttiPtr(destRtti.getType()))
1064 return emitError() << "destRtti must be an RTTI pointer";
1065
1066 return success();
1067}
1068
1069//===----------------------------------------------------------------------===//
1070// EhFilterAttr definitions
1071//===----------------------------------------------------------------------===//
1072
1073LogicalResult EhFilterAttr::verify(function_ref<InFlightDiagnostic()> emitError,
1074 mlir::ArrayAttr permittedTypes) {
1075 for (mlir::Attribute typeAttr : permittedTypes) {
1076 auto rtti = mlir::dyn_cast<cir::GlobalViewAttr>(typeAttr);
1077 if (!rtti || !isRttiPtr(rtti.getType()))
1078 return emitError() << "permitted type list must contain only type info "
1079 "symbols";
1080 }
1081
1082 return success();
1083}
1084
1085//===----------------------------------------------------------------------===//
1086// RecordLayoutAttr
1087//===----------------------------------------------------------------------===//
1088
1089Attribute RecordLayoutAttr::parse(AsmParser &parser, Type odsType) {
1090 (void)odsType;
1091 SMLoc loc = parser.getCurrentLocation();
1092 if (parser.parseLess() || parser.parseKeyword("arg_passing_kind") ||
1093 parser.parseEqual())
1094 return {};
1095
1096 FailureOr<ArgPassingKind> kind = FieldParser<ArgPassingKind>::parse(parser);
1097 if (failed(kind))
1098 return {};
1099
1100 if (parser.parseComma() || parser.parseKeyword("has_trivial_dtor") ||
1101 parser.parseEqual())
1102 return {};
1103 FailureOr<bool> hasTrivialDtor = FieldParser<bool>::parse(parser);
1104 if (failed(hasTrivialDtor))
1105 return {};
1106
1107 if (parser.parseComma() || parser.parseKeyword("record_align") ||
1108 parser.parseEqual())
1109 return {};
1110 FailureOr<uint64_t> recordAlign = FieldParser<uint64_t>::parse(parser);
1111 if (failed(recordAlign))
1112 return {};
1113
1114 // An omitted unadjusted_align stores the record alignment. The optional
1115 // fields may follow record_align in any order.
1116 uint64_t unadjustedAlign = *recordAlign;
1117 bool transparentUnion = false;
1118 bool flexibleArrayMember = false;
1119 while (succeeded(parser.parseOptionalComma())) {
1120 if (succeeded(parser.parseOptionalKeyword("unadjusted_align"))) {
1121 if (parser.parseEqual())
1122 return {};
1123 FailureOr<uint64_t> parsed = FieldParser<uint64_t>::parse(parser);
1124 if (failed(parsed))
1125 return {};
1126 unadjustedAlign = *parsed;
1127 continue;
1128 }
1129 if (succeeded(parser.parseOptionalKeyword("transparent_union"))) {
1130 if (parser.parseEqual())
1131 return {};
1132 FailureOr<bool> parsed = FieldParser<bool>::parse(parser);
1133 if (failed(parsed))
1134 return {};
1135 transparentUnion = *parsed;
1136 continue;
1137 }
1138 if (succeeded(parser.parseOptionalKeyword("flexible_array_member"))) {
1139 if (parser.parseEqual())
1140 return {};
1141 FailureOr<bool> parsed = FieldParser<bool>::parse(parser);
1142 if (failed(parsed))
1143 return {};
1144 flexibleArrayMember = *parsed;
1145 continue;
1146 }
1147 parser.emitError(parser.getCurrentLocation(),
1148 "expected unadjusted_align, transparent_union or "
1149 "flexible_array_member");
1150 return {};
1151 }
1152
1153 if (parser.parseGreater())
1154 return {};
1155 return parser.getChecked<RecordLayoutAttr>(
1156 loc, parser.getContext(), *kind, *hasTrivialDtor, *recordAlign,
1157 unadjustedAlign, transparentUnion, flexibleArrayMember);
1158}
1159
1160void RecordLayoutAttr::print(AsmPrinter &printer) const {
1161 printer << "<arg_passing_kind = ";
1162 printer.printStrippedAttrOrType(getArgPassingKind());
1163 printer << ", has_trivial_dtor = ";
1164 printer.printStrippedAttrOrType(getHasTrivialDtor());
1165 printer << ", record_align = ";
1166 printer.printStrippedAttrOrType(getRecordAlign());
1167 // Print unadjusted_align only when it differs from record_align.
1168 if (getUnadjustedAlign() != getRecordAlign()) {
1169 printer << ", unadjusted_align = ";
1170 printer.printStrippedAttrOrType(getUnadjustedAlign());
1171 }
1172 if (getTransparentUnion()) {
1173 printer << ", transparent_union = ";
1174 printer.printStrippedAttrOrType(getTransparentUnion());
1175 }
1176 if (getFlexibleArrayMember()) {
1177 printer << ", flexible_array_member = ";
1178 printer.printStrippedAttrOrType(getFlexibleArrayMember());
1179 }
1180 printer << '>';
1181}
1182
1183//===----------------------------------------------------------------------===//
1184// RecordLayout lookup
1185//===----------------------------------------------------------------------===//
1186
1187RecordLayoutAttr cir::tryGetRecordLayout(mlir::ModuleOp mod,
1188 mlir::StringAttr name) {
1189 if (!name)
1190 return {};
1191 auto dict = mod->getAttrOfType<mlir::DictionaryAttr>(
1192 CIRDialect::getRecordLayoutsAttrName());
1193 if (!dict)
1194 return {};
1195 return dict.getAs<RecordLayoutAttr>(name);
1196}
1197
1198RecordLayoutAttr cir::getRecordLayout(mlir::ModuleOp mod,
1199 mlir::StringAttr name) {
1200 RecordLayoutAttr attr = tryGetRecordLayout(mod, name);
1201 assert(attr && "record layout entry missing for named record");
1202 return attr;
1203}
1204
1205//===----------------------------------------------------------------------===//
1206// CIR Dialect
1207//===----------------------------------------------------------------------===//
1208
1209void CIRDialect::registerAttributes() {
1210 addAttributes<
1211#define GET_ATTRDEF_LIST
1212#include "clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc"
1213 >();
1214}
static mlir::ParseResult parseFloatLiteral(mlir::AsmParser &parser, mlir::FailureOr< llvm::APFloat > &value, cir::FPTypeInterface fpType)
static void printConstPtr(mlir::AsmPrinter &p, mlir::IntegerAttr value)
static void printRecordMembers(mlir::AsmPrinter &p, mlir::ArrayAttr members)
Definition CIRAttrs.cpp:208
static mlir::ParseResult parseIntLiteral(mlir::AsmParser &parser, llvm::APInt &value, cir::IntTypeInterface ty)
Definition CIRAttrs.cpp:384
static void printIntLiteral(mlir::AsmPrinter &p, llvm::APInt value, cir::IntTypeInterface ty)
Definition CIRAttrs.cpp:403
static mlir::ParseResult parseConstPtr(mlir::AsmParser &parser, mlir::IntegerAttr &value)
static void printFloatLiteral(mlir::AsmPrinter &p, llvm::APFloat value, mlir::Type ty)
static mlir::ParseResult parseDataMemberPath(mlir::AsmParser &parser, mlir::DenseI32ArrayAttr &memberPath)
static bool isRttiPtr(mlir::Type ty)
static void printDataMemberPath(mlir::AsmPrinter &p, mlir::DenseI32ArrayAttr memberPath)
static mlir::ParseResult parseRecordMembers(mlir::AsmParser &parser, mlir::ArrayAttr &members)
Definition CIRAttrs.cpp:215
static bool isValidFlexibleArrayInit(mlir::Type memberType, mlir::Type initType)
Definition CIRAttrs.cpp:239
static Decl::Kind getKind(const Decl *D)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Same lookup as getRecordLayout, but returns a null attribute instead of asserting when the record has...
RecordLayoutAttr getRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Look up the RecordLayoutAttr for a named record in the module's cir.record_layouts dictionary.
mlir::Type memberStorageType(mlir::Type memberTy)
The storage a member is stored as: the access unit for a bit-field member, and the member type itself...
Definition CIRTypes.h:135
bool memberOwnsBytes(mlir::Type memberTy)
Whether a record member occupies bytes of its record.
Definition CIRTypes.h:126
RangeSelector member(std::string ID)
Given a MemberExpr, selects the member token. ID is the node's binding in the match result.
float __ovld __cnfn step(float, float)
Returns 0.0 if x < edge, otherwise it returns 1.0.
__builtin_bitreverse32 uint32_t __builtin_riscv_aaddu_u32 __builtin_riscv_asubu_u32 int32_t
int32_t uint32_t uint32_t __builtin_riscv_mhracc_i32 __builtin_riscv_mhraccu_u32 __builtin_riscv_mhraccsu_i32 __builtin_riscv_mulqr_i32 int64_t