@@ -78,7 +78,15 @@ class LLVMLoweringInfo {
78
78
}
79
79
80
80
class CIR_Op<string mnemonic, list<Trait> traits = []> :
81
- Op<CIR_Dialect, mnemonic, traits>, LLVMLoweringInfo;
81
+ Op<CIR_Dialect, mnemonic, traits>, LLVMLoweringInfo {
82
+ // Should we generate an LLVM lowering pattern for this op?
83
+ bit hasLLVMLowering = true;
84
+ // Is the LLVM lowering pattern for this operation recursive?
85
+ bit isLLVMLoweringRecursive = false;
86
+ // Extra class declarations to be included in the generated LLVM lowering
87
+ // pattern.
88
+ code extraLLVMLoweringPatternDecl = "";
89
+ }
82
90
83
91
//===----------------------------------------------------------------------===//
84
92
// CastOp
@@ -218,6 +226,10 @@ def CIR_CastOp : CIR_Op<"cast", [
218
226
// The input and output types should match the cast kind.
219
227
let hasVerifier = 1;
220
228
let hasFolder = 1;
229
+
230
+ let extraLLVMLoweringPatternDecl = [{
231
+ mlir::Type convertTy(mlir::Type ty) const;
232
+ }];
221
233
}
222
234
223
235
@@ -297,6 +309,8 @@ def CIR_ConstantOp : CIR_Op<"const", [
297
309
}];
298
310
299
311
let hasFolder = 1;
312
+
313
+ let isLLVMLoweringRecursive = true;
300
314
}
301
315
302
316
//===----------------------------------------------------------------------===//
@@ -613,6 +627,8 @@ def CIR_IfOp : CIR_Op<"if", [
613
627
CArg<"BuilderCallbackRef", "buildTerminatedBody">:$thenBuilder,
614
628
CArg<"BuilderCallbackRef", "nullptr">:$elseBuilder)>
615
629
];
630
+
631
+ let hasLLVMLowering = false;
616
632
}
617
633
618
634
//===----------------------------------------------------------------------===//
@@ -659,6 +675,7 @@ def CIR_ConditionOp : CIR_Op<"condition", [
659
675
let arguments = (ins CIR_BoolType:$condition);
660
676
let assemblyFormat = " `(` $condition `)` attr-dict ";
661
677
let hasVerifier = 1;
678
+ let hasLLVMLowering = false;
662
679
}
663
680
664
681
//===----------------------------------------------------------------------===//
@@ -726,6 +743,8 @@ def CIR_YieldOp : CIR_Op<"yield", [
726
743
let builders = [
727
744
OpBuilder<(ins), [{ /* nothing to do */ }]>,
728
745
];
746
+
747
+ let hasLLVMLowering = false;
729
748
}
730
749
731
750
//===----------------------------------------------------------------------===//
@@ -741,6 +760,7 @@ def CIR_BreakOp : CIR_Op<"break", [Terminator]> {
741
760
}];
742
761
let assemblyFormat = "attr-dict";
743
762
let hasVerifier = 1;
763
+ let hasLLVMLowering = false;
744
764
}
745
765
746
766
//===----------------------------------------------------------------------===//
@@ -756,6 +776,7 @@ def CIR_ContinueOp : CIR_Op<"continue", [Terminator]> {
756
776
}];
757
777
let assemblyFormat = "attr-dict";
758
778
let hasVerifier = 1;
779
+ let hasLLVMLowering = false;
759
780
}
760
781
761
782
//===----------------------------------------------------------------------===//
@@ -814,6 +835,8 @@ def CIR_ScopeOp : CIR_Op<"scope", [
814
835
// Scopes without yielding values.
815
836
OpBuilder<(ins "llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>":$scopeBuilder)>
816
837
];
838
+
839
+ let hasLLVMLowering = false;
817
840
}
818
841
819
842
//===----------------------------------------------------------------------===//
@@ -860,6 +883,8 @@ def CIR_CaseOp : CIR_Op<"case", [
860
883
"CaseOpKind":$kind,
861
884
"mlir::OpBuilder::InsertPoint &":$insertPoint)>
862
885
];
886
+
887
+ let hasLLVMLowering = false;
863
888
}
864
889
865
890
def CIR_SwitchOp : CIR_Op<"switch", [
@@ -1025,6 +1050,8 @@ def CIR_SwitchOp : CIR_Op<"switch", [
1025
1050
// This is an expensive and need to be used with caution.
1026
1051
bool isSimpleForm(llvm::SmallVectorImpl<CaseOp> &cases);
1027
1052
}];
1053
+
1054
+ let hasLLVMLowering = false;
1028
1055
}
1029
1056
1030
1057
//===----------------------------------------------------------------------===//
@@ -1170,6 +1197,8 @@ def CIR_GotoOp : CIR_Op<"goto", [Terminator]> {
1170
1197
}];
1171
1198
let arguments = (ins StrAttr:$label);
1172
1199
let assemblyFormat = [{ $label attr-dict }];
1200
+
1201
+ let hasLLVMLowering = false;
1173
1202
}
1174
1203
1175
1204
//===----------------------------------------------------------------------===//
@@ -1185,6 +1214,8 @@ def CIR_LabelOp : CIR_Op<"label", [AlwaysSpeculatable]> {
1185
1214
let arguments = (ins StrAttr:$label);
1186
1215
let assemblyFormat = [{ $label attr-dict }];
1187
1216
let hasVerifier = 1;
1217
+
1218
+ let hasLLVMLowering = false;
1188
1219
}
1189
1220
1190
1221
//===----------------------------------------------------------------------===//
@@ -1349,6 +1380,8 @@ def CIR_WhileOp : CIR_WhileOpBase<"while"> {
1349
1380
}
1350
1381
```
1351
1382
}];
1383
+
1384
+ let hasLLVMLowering = false;
1352
1385
}
1353
1386
1354
1387
def CIR_DoWhileOp : CIR_WhileOpBase<"do"> {
@@ -1375,6 +1408,8 @@ def CIR_DoWhileOp : CIR_WhileOpBase<"do"> {
1375
1408
}
1376
1409
```
1377
1410
}];
1411
+
1412
+ let hasLLVMLowering = false;
1378
1413
}
1379
1414
1380
1415
//===----------------------------------------------------------------------===//
@@ -1442,6 +1477,8 @@ def CIR_ForOp : CIR_LoopOpBase<"for"> {
1442
1477
return llvm::SmallVector<mlir::Region *, 3>{&getCond(), &getBody(), &getStep()};
1443
1478
}
1444
1479
}];
1480
+
1481
+ let hasLLVMLowering = false;
1445
1482
}
1446
1483
1447
1484
//===----------------------------------------------------------------------===//
@@ -1480,6 +1517,8 @@ def CIR_CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
1480
1517
let assemblyFormat = [{
1481
1518
`(` $kind `,` $lhs `,` $rhs `)` `:` type($lhs) `,` type($result) attr-dict
1482
1519
}];
1520
+
1521
+ let isLLVMLoweringRecursive = true;
1483
1522
}
1484
1523
1485
1524
//===----------------------------------------------------------------------===//
@@ -1550,6 +1589,10 @@ def CIR_BinOp : CIR_Op<"binop", [
1550
1589
}];
1551
1590
1552
1591
let hasVerifier = 1;
1592
+
1593
+ let extraLLVMLoweringPatternDecl = [{
1594
+ mlir::LLVM::IntegerOverflowFlags getIntOverflowFlag(cir::BinOp op) const;
1595
+ }];
1553
1596
}
1554
1597
1555
1598
//===----------------------------------------------------------------------===//
@@ -1687,6 +1730,8 @@ def CIR_TernaryOp : CIR_Op<"ternary", [
1687
1730
`false` $falseRegion
1688
1731
`)` `:` functional-type(operands, results) attr-dict
1689
1732
}];
1733
+
1734
+ let hasLLVMLowering = false;
1690
1735
}
1691
1736
1692
1737
//===----------------------------------------------------------------------===//
@@ -1790,6 +1835,20 @@ def CIR_GlobalOp : CIR_Op<"global", [
1790
1835
"cir::GlobalLinkageKind::ExternalLinkage">:$linkage)>];
1791
1836
1792
1837
let hasVerifier = 1;
1838
+
1839
+ let isLLVMLoweringRecursive = true;
1840
+ let extraLLVMLoweringPatternDecl = [{
1841
+ mlir::LogicalResult matchAndRewriteRegionInitializedGlobal(
1842
+ cir::GlobalOp op, mlir::Attribute init,
1843
+ mlir::ConversionPatternRewriter &rewriter) const;
1844
+
1845
+ void setupRegionInitializedLLVMGlobalOp(
1846
+ cir::GlobalOp op, mlir::ConversionPatternRewriter &rewriter) const;
1847
+
1848
+ mutable mlir::LLVM::ComdatOp comdatOp = nullptr;
1849
+ mlir::SymbolRefAttr getComdatAttr(cir::GlobalOp &op,
1850
+ mlir::OpBuilder &builder) const;
1851
+ }];
1793
1852
}
1794
1853
1795
1854
//===----------------------------------------------------------------------===//
@@ -2340,6 +2399,19 @@ def CIR_FuncOp : CIR_Op<"func", [
2340
2399
2341
2400
let hasCustomAssemblyFormat = 1;
2342
2401
let hasVerifier = 1;
2402
+
2403
+ let extraLLVMLoweringPatternDecl = [{
2404
+ static mlir::StringRef getLinkageAttrNameString() { return "linkage"; }
2405
+
2406
+ void lowerFuncAttributes(
2407
+ cir::FuncOp func, bool filterArgAndResAttrs,
2408
+ mlir::SmallVectorImpl<mlir::NamedAttribute> &result) const;
2409
+
2410
+ mlir::LogicalResult
2411
+ matchAndRewriteAlias(cir::FuncOp op, llvm::StringRef aliasee, mlir::Type ty,
2412
+ OpAdaptor adaptor,
2413
+ mlir::ConversionPatternRewriter &rewriter) const;
2414
+ }];
2343
2415
}
2344
2416
2345
2417
//===----------------------------------------------------------------------===//
@@ -2761,6 +2833,8 @@ class CIR_ArrayInitDestroy<string mnemonic> : CIR_Op<mnemonic> {
2761
2833
regionBuilder($_builder, $_state.location);
2762
2834
}]>
2763
2835
];
2836
+
2837
+ let hasLLVMLowering = false;
2764
2838
}
2765
2839
2766
2840
def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
@@ -3380,6 +3454,8 @@ def CIR_ComplexMulOp : CIR_Op<"complex.mul", [
3380
3454
let assemblyFormat = [{
3381
3455
$lhs `,` $rhs `range` `(` $range `)` `:` qualified(type($result)) attr-dict
3382
3456
}];
3457
+
3458
+ let hasLLVMLowering = false;
3383
3459
}
3384
3460
3385
3461
def CIR_ComplexDivOp : CIR_Op<"complex.div", [
@@ -3422,6 +3498,8 @@ def CIR_ComplexDivOp : CIR_Op<"complex.div", [
3422
3498
let assemblyFormat = [{
3423
3499
$lhs `,` $rhs `range` `(` $range `)` `:` qualified(type($result)) attr-dict
3424
3500
}];
3501
+
3502
+ let hasLLVMLowering = false;
3425
3503
}
3426
3504
3427
3505
//===----------------------------------------------------------------------===//
0 commit comments