|
| 1 | +//===----------------------------------------------------------------------===// |
| 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 CIR dialect type constraints. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD |
| 14 | +#define CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD |
| 15 | + |
| 16 | +include "mlir/IR/Constraints.td" |
| 17 | +include "mlir/IR/CommonTypeConstraints.td" |
| 18 | + |
| 19 | +class CIR_IsTypePred<code type> : CPred<"::mlir::isa<" # type # ">($_self)">; |
| 20 | + |
| 21 | +class CIR_TypeBase<code type, string summary = ""> |
| 22 | + : Type<CIR_IsTypePred<type>, summary, type>; |
| 23 | + |
| 24 | +class CIR_CastSelfToType<code type, Pred pred> |
| 25 | + : SubstLeaves<"$_self", "::mlir::cast<" # type # ">($_self)", pred>; |
| 26 | + |
| 27 | +class CIR_CastedSelfsToType<code type, list<Pred> preds> |
| 28 | + : And<!foreach(pred, preds, CIR_CastSelfToType<type, pred>)>; |
| 29 | + |
| 30 | +class CIR_ConfinedType<Type type, list<Pred> preds, string summary = ""> |
| 31 | + : Type<And<[type.predicate, CIR_CastedSelfsToType<type.cppType, preds>]>, |
| 32 | + summary, type.cppType>; |
| 33 | + |
| 34 | +//===----------------------------------------------------------------------===// |
| 35 | +// IntType predicates |
| 36 | +//===----------------------------------------------------------------------===// |
| 37 | + |
| 38 | +def CIR_AnyIntType : CIR_TypeBase<"::cir::IntType", "integer type">; |
| 39 | + |
| 40 | +def CIR_AnyUIntType : CIR_ConfinedType<CIR_AnyIntType, [ |
| 41 | + CPred<"$_self.isUnsigned()">], "unsigned integer type">; |
| 42 | + |
| 43 | +def CIR_AnySIntType : CIR_ConfinedType<CIR_AnyIntType, [ |
| 44 | + CPred<"$_self.isSigned()">], "signed integer type">; |
| 45 | + |
| 46 | +class CIR_HasWidthPred<int width> : CPred<"$_self.getWidth() == " # width>; |
| 47 | + |
| 48 | +def CIR_HasFundamentalIntWidthPred |
| 49 | + : CPred<"::cir::isValidFundamentalIntWidth($_self.getWidth())">; |
| 50 | + |
| 51 | +class CIR_IntOfWidthsPred<list<int> widths> |
| 52 | + : Or<!foreach(width, widths, CIR_HasWidthPred<width>)>; |
| 53 | + |
| 54 | +class CIR_IntOfWidths<list<int> widths> |
| 55 | + : CIR_ConfinedType<CIR_AnyIntType, [CIR_IntOfWidthsPred<widths>], |
| 56 | + "integer type of widths " # !interleave(widths, "/")>; |
| 57 | + |
| 58 | +class CIR_SIntOfWidths<list<int> widths> |
| 59 | + : CIR_ConfinedType<CIR_AnySIntType, [CIR_IntOfWidthsPred<widths>], |
| 60 | + "signed integer type of widths " # !interleave(widths, "/")>; |
| 61 | + |
| 62 | +class CIR_UIntOfWidths<list<int> widths> |
| 63 | + : CIR_ConfinedType<CIR_AnyUIntType, [CIR_IntOfWidthsPred<widths>], |
| 64 | + "unsigned integer type of widths " # !interleave(widths, "/")>; |
| 65 | + |
| 66 | +class CIR_UInt<int width> |
| 67 | + : CIR_ConfinedType<CIR_AnyUIntType, [CIR_HasWidthPred<width>], |
| 68 | + width # "-bit unsigned integer">, |
| 69 | + BuildableType<"$_builder.getType<" # cppType # ">(" # |
| 70 | + width # ", /*isSigned=*/false)">; |
| 71 | + |
| 72 | +def CIR_UInt1 : CIR_UInt<1>; |
| 73 | +def CIR_UInt8 : CIR_UInt<8>; |
| 74 | +def CIR_UInt16 : CIR_UInt<16>; |
| 75 | +def CIR_UInt32 : CIR_UInt<32>; |
| 76 | +def CIR_UInt64 : CIR_UInt<64>; |
| 77 | +def CIR_UInt128 : CIR_UInt<128>; |
| 78 | + |
| 79 | +class CIR_SInt<int width> |
| 80 | + : CIR_ConfinedType<CIR_AnySIntType, [CIR_HasWidthPred<width>], |
| 81 | + width # "-bit signed integer">, |
| 82 | + BuildableType<"$_builder.getType<" # cppType # ">(" # |
| 83 | + width # ", /*isSigned=*/true)">; |
| 84 | + |
| 85 | +def CIR_SInt1 : CIR_SInt<1>; |
| 86 | +def CIR_SInt8 : CIR_SInt<8>; |
| 87 | +def CIR_SInt16 : CIR_SInt<16>; |
| 88 | +def CIR_SInt32 : CIR_SInt<32>; |
| 89 | +def CIR_SInt64 : CIR_SInt<64>; |
| 90 | +def CIR_SInt128 : CIR_SInt<128>; |
| 91 | + |
| 92 | +// Fundamental integer types represent standard source-level integer types that |
| 93 | +// have a specified set of admissible bitwidths (8, 16, 32, 64). |
| 94 | + |
| 95 | +def CIR_AnyFundamentalIntType |
| 96 | + : CIR_ConfinedType<CIR_AnyIntType, [CIR_HasFundamentalIntWidthPred], |
| 97 | + "fundamental integer type"> { |
| 98 | + let cppFunctionName = "isFundamentalIntType"; |
| 99 | +} |
| 100 | + |
| 101 | +def CIR_AnyFundamentalUIntType |
| 102 | + : CIR_ConfinedType<CIR_AnyUIntType, [CIR_HasFundamentalIntWidthPred], |
| 103 | + "fundamental unsigned integer type"> { |
| 104 | + let cppFunctionName = "isFundamentalUIntType"; |
| 105 | +} |
| 106 | + |
| 107 | +def CIR_AnyFundamentalSIntType |
| 108 | + : CIR_ConfinedType<CIR_AnySIntType, [CIR_HasFundamentalIntWidthPred], |
| 109 | + "fundamental signed integer type"> { |
| 110 | + let cppFunctionName = "isFundamentalSIntType"; |
| 111 | +} |
| 112 | + |
| 113 | +#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD |
0 commit comments