@@ -78,7 +78,15 @@ class LLVMLoweringInfo {
7878}
7979
8080class 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+ }
8290
8391//===----------------------------------------------------------------------===//
8492// CastOp
@@ -218,6 +226,10 @@ def CIR_CastOp : CIR_Op<"cast", [
218226 // The input and output types should match the cast kind.
219227 let hasVerifier = 1;
220228 let hasFolder = 1;
229+
230+ let extraLLVMLoweringPatternDecl = [{
231+ mlir::Type convertTy(mlir::Type ty) const;
232+ }];
221233}
222234
223235
@@ -297,6 +309,8 @@ def CIR_ConstantOp : CIR_Op<"const", [
297309 }];
298310
299311 let hasFolder = 1;
312+
313+ let isLLVMLoweringRecursive = true;
300314}
301315
302316//===----------------------------------------------------------------------===//
@@ -613,6 +627,8 @@ def CIR_IfOp : CIR_Op<"if", [
613627 CArg<"BuilderCallbackRef", "buildTerminatedBody">:$thenBuilder,
614628 CArg<"BuilderCallbackRef", "nullptr">:$elseBuilder)>
615629 ];
630+
631+ let hasLLVMLowering = false;
616632}
617633
618634//===----------------------------------------------------------------------===//
@@ -659,6 +675,7 @@ def CIR_ConditionOp : CIR_Op<"condition", [
659675 let arguments = (ins CIR_BoolType:$condition);
660676 let assemblyFormat = " `(` $condition `)` attr-dict ";
661677 let hasVerifier = 1;
678+ let hasLLVMLowering = false;
662679}
663680
664681//===----------------------------------------------------------------------===//
@@ -726,6 +743,8 @@ def CIR_YieldOp : CIR_Op<"yield", [
726743 let builders = [
727744 OpBuilder<(ins), [{ /* nothing to do */ }]>,
728745 ];
746+
747+ let hasLLVMLowering = false;
729748}
730749
731750//===----------------------------------------------------------------------===//
@@ -741,6 +760,7 @@ def CIR_BreakOp : CIR_Op<"break", [Terminator]> {
741760 }];
742761 let assemblyFormat = "attr-dict";
743762 let hasVerifier = 1;
763+ let hasLLVMLowering = false;
744764}
745765
746766//===----------------------------------------------------------------------===//
@@ -756,6 +776,7 @@ def CIR_ContinueOp : CIR_Op<"continue", [Terminator]> {
756776 }];
757777 let assemblyFormat = "attr-dict";
758778 let hasVerifier = 1;
779+ let hasLLVMLowering = false;
759780}
760781
761782//===----------------------------------------------------------------------===//
@@ -814,6 +835,8 @@ def CIR_ScopeOp : CIR_Op<"scope", [
814835 // Scopes without yielding values.
815836 OpBuilder<(ins "llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>":$scopeBuilder)>
816837 ];
838+
839+ let hasLLVMLowering = false;
817840}
818841
819842//===----------------------------------------------------------------------===//
@@ -860,6 +883,8 @@ def CIR_CaseOp : CIR_Op<"case", [
860883 "CaseOpKind":$kind,
861884 "mlir::OpBuilder::InsertPoint &":$insertPoint)>
862885 ];
886+
887+ let hasLLVMLowering = false;
863888}
864889
865890def CIR_SwitchOp : CIR_Op<"switch", [
@@ -1025,6 +1050,8 @@ def CIR_SwitchOp : CIR_Op<"switch", [
10251050 // This is an expensive and need to be used with caution.
10261051 bool isSimpleForm(llvm::SmallVectorImpl<CaseOp> &cases);
10271052 }];
1053+
1054+ let hasLLVMLowering = false;
10281055}
10291056
10301057//===----------------------------------------------------------------------===//
@@ -1170,6 +1197,8 @@ def CIR_GotoOp : CIR_Op<"goto", [Terminator]> {
11701197 }];
11711198 let arguments = (ins StrAttr:$label);
11721199 let assemblyFormat = [{ $label attr-dict }];
1200+
1201+ let hasLLVMLowering = false;
11731202}
11741203
11751204//===----------------------------------------------------------------------===//
@@ -1185,6 +1214,8 @@ def CIR_LabelOp : CIR_Op<"label", [AlwaysSpeculatable]> {
11851214 let arguments = (ins StrAttr:$label);
11861215 let assemblyFormat = [{ $label attr-dict }];
11871216 let hasVerifier = 1;
1217+
1218+ let hasLLVMLowering = false;
11881219}
11891220
11901221//===----------------------------------------------------------------------===//
@@ -1349,6 +1380,8 @@ def CIR_WhileOp : CIR_WhileOpBase<"while"> {
13491380 }
13501381 ```
13511382 }];
1383+
1384+ let hasLLVMLowering = false;
13521385}
13531386
13541387def CIR_DoWhileOp : CIR_WhileOpBase<"do"> {
@@ -1375,6 +1408,8 @@ def CIR_DoWhileOp : CIR_WhileOpBase<"do"> {
13751408 }
13761409 ```
13771410 }];
1411+
1412+ let hasLLVMLowering = false;
13781413}
13791414
13801415//===----------------------------------------------------------------------===//
@@ -1442,6 +1477,8 @@ def CIR_ForOp : CIR_LoopOpBase<"for"> {
14421477 return llvm::SmallVector<mlir::Region *, 3>{&getCond(), &getBody(), &getStep()};
14431478 }
14441479 }];
1480+
1481+ let hasLLVMLowering = false;
14451482}
14461483
14471484//===----------------------------------------------------------------------===//
@@ -1480,6 +1517,8 @@ def CIR_CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
14801517 let assemblyFormat = [{
14811518 `(` $kind `,` $lhs `,` $rhs `)` `:` type($lhs) `,` type($result) attr-dict
14821519 }];
1520+
1521+ let isLLVMLoweringRecursive = true;
14831522}
14841523
14851524//===----------------------------------------------------------------------===//
@@ -1550,6 +1589,10 @@ def CIR_BinOp : CIR_Op<"binop", [
15501589 }];
15511590
15521591 let hasVerifier = 1;
1592+
1593+ let extraLLVMLoweringPatternDecl = [{
1594+ mlir::LLVM::IntegerOverflowFlags getIntOverflowFlag(cir::BinOp op) const;
1595+ }];
15531596}
15541597
15551598//===----------------------------------------------------------------------===//
@@ -1687,6 +1730,8 @@ def CIR_TernaryOp : CIR_Op<"ternary", [
16871730 `false` $falseRegion
16881731 `)` `:` functional-type(operands, results) attr-dict
16891732 }];
1733+
1734+ let hasLLVMLowering = false;
16901735}
16911736
16921737//===----------------------------------------------------------------------===//
@@ -1790,6 +1835,20 @@ def CIR_GlobalOp : CIR_Op<"global", [
17901835 "cir::GlobalLinkageKind::ExternalLinkage">:$linkage)>];
17911836
17921837 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+ }];
17931852}
17941853
17951854//===----------------------------------------------------------------------===//
@@ -2340,6 +2399,19 @@ def CIR_FuncOp : CIR_Op<"func", [
23402399
23412400 let hasCustomAssemblyFormat = 1;
23422401 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+ }];
23432415}
23442416
23452417//===----------------------------------------------------------------------===//
@@ -2761,6 +2833,8 @@ class CIR_ArrayInitDestroy<string mnemonic> : CIR_Op<mnemonic> {
27612833 regionBuilder($_builder, $_state.location);
27622834 }]>
27632835 ];
2836+
2837+ let hasLLVMLowering = false;
27642838}
27652839
27662840def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
@@ -3380,6 +3454,8 @@ def CIR_ComplexMulOp : CIR_Op<"complex.mul", [
33803454 let assemblyFormat = [{
33813455 $lhs `,` $rhs `range` `(` $range `)` `:` qualified(type($result)) attr-dict
33823456 }];
3457+
3458+ let hasLLVMLowering = false;
33833459}
33843460
33853461def CIR_ComplexDivOp : CIR_Op<"complex.div", [
@@ -3422,6 +3498,8 @@ def CIR_ComplexDivOp : CIR_Op<"complex.div", [
34223498 let assemblyFormat = [{
34233499 $lhs `,` $rhs `range` `(` $range `)` `:` qualified(type($result)) attr-dict
34243500 }];
3501+
3502+ let hasLLVMLowering = false;
34253503}
34263504
34273505//===----------------------------------------------------------------------===//
0 commit comments