@@ -566,6 +566,22 @@ static mlir::ParseResult parseCallOp(mlir::OpAsmParser &parser,
566
566
return mlir::success ();
567
567
}
568
568
569
+ void fir::CallOp::build (mlir::OpBuilder &builder, mlir::OperationState &result,
570
+ mlir::FuncOp callee, mlir::ValueRange operands) {
571
+ result.addOperands (operands);
572
+ result.addAttribute (calleeAttrName (), builder.getSymbolRefAttr (callee));
573
+ result.addTypes (callee.getType ().getResults ());
574
+ }
575
+
576
+ void fir::CallOp::build (mlir::OpBuilder &builder, mlir::OperationState &result,
577
+ mlir::SymbolRefAttr callee,
578
+ llvm::ArrayRef<mlir::Type> results,
579
+ mlir::ValueRange operands) {
580
+ result.addOperands (operands);
581
+ result.addAttribute (calleeAttrName (), callee);
582
+ result.addTypes (results);
583
+ }
584
+
569
585
// ===----------------------------------------------------------------------===//
570
586
// CharConvertOp
571
587
// ===----------------------------------------------------------------------===//
@@ -681,11 +697,15 @@ static mlir::ParseResult parseConstcOp(mlir::OpAsmParser &parser,
681
697
682
698
static void print (mlir::OpAsmPrinter &p, fir::ConstcOp &op) {
683
699
p << op.getOperationName () << " (0x" ;
684
- auto f1 = op.getOperation ()->getAttr (fir::ConstcOp::realAttrName ()).cast <mlir::FloatAttr>();
700
+ auto f1 = op.getOperation ()
701
+ ->getAttr (fir::ConstcOp::realAttrName ())
702
+ .cast <mlir::FloatAttr>();
685
703
auto i1 = f1.getValue ().bitcastToAPInt ();
686
704
p.getStream ().write_hex (i1.getZExtValue ());
687
705
p << " , 0x" ;
688
- auto f2 = op.getOperation ()->getAttr (fir::ConstcOp::imagAttrName ()).cast <mlir::FloatAttr>();
706
+ auto f2 = op.getOperation ()
707
+ ->getAttr (fir::ConstcOp::imagAttrName ())
708
+ .cast <mlir::FloatAttr>();
689
709
auto i2 = f2.getValue ().bitcastToAPInt ();
690
710
p.getStream ().write_hex (i2.getZExtValue ());
691
711
p << " ) : " ;
@@ -905,14 +925,16 @@ static mlir::ParseResult parseDispatchTableOp(mlir::OpAsmParser &parser,
905
925
}
906
926
907
927
static void print (mlir::OpAsmPrinter &p, fir::DispatchTableOp &op) {
908
- auto tableName = op.getOperation ()->getAttrOfType <StringAttr>(
909
- mlir::SymbolTable::getSymbolAttrName ()).getValue ();
928
+ auto tableName =
929
+ op.getOperation ()
930
+ ->getAttrOfType <StringAttr>(mlir::SymbolTable::getSymbolAttrName ())
931
+ .getValue ();
910
932
p << op.getOperationName () << " @" << tableName;
911
933
912
934
Region &body = op.getOperation ()->getRegion (0 );
913
935
if (!body.empty ())
914
936
p.printRegion (body, /* printEntryBlockArgs=*/ false ,
915
- /* printBlockTerminators=*/ false );
937
+ /* printBlockTerminators=*/ false );
916
938
}
917
939
918
940
static mlir::LogicalResult verify (fir::DispatchTableOp &op) {
@@ -1132,16 +1154,17 @@ static void print(mlir::OpAsmPrinter &p, fir::GlobalOp &op) {
1132
1154
if (op.linkName ().hasValue ())
1133
1155
p << ' ' << op.linkName ().getValue ();
1134
1156
p << ' ' ;
1135
- p.printAttributeWithoutType (op.getOperation ()->getAttr (fir::GlobalOp::symbolAttrName ()));
1157
+ p.printAttributeWithoutType (
1158
+ op.getOperation ()->getAttr (fir::GlobalOp::symbolAttrName ()));
1136
1159
if (auto val = op.getValueOrNull ())
1137
1160
p << ' (' << val << ' )' ;
1138
1161
if (op.getOperation ()->getAttr (fir::GlobalOp::constantAttrName ()))
1139
1162
p << " constant" ;
1140
1163
p << " : " ;
1141
1164
p.printType (op.getType ());
1142
1165
if (op.hasInitializationBody ())
1143
- p.printRegion (op.getOperation ()->getRegion (0 ),
1144
- /* printEntryBlockArgs=*/ false ,
1166
+ p.printRegion (op.getOperation ()->getRegion (0 ),
1167
+ /* printEntryBlockArgs=*/ false ,
1145
1168
/* printBlockTerminators=*/ true );
1146
1169
}
1147
1170
@@ -1332,6 +1355,15 @@ static void print(mlir::OpAsmPrinter &p, fir::FieldIndexOp &op) {
1332
1355
}
1333
1356
}
1334
1357
1358
+ void fir::FieldIndexOp::build (mlir::OpBuilder &builder,
1359
+ mlir::OperationState &result,
1360
+ llvm::StringRef fieldName, mlir::Type recTy,
1361
+ mlir::ValueRange operands) {
1362
+ result.addAttribute (fieldAttrName (), builder.getStringAttr (fieldName));
1363
+ result.addAttribute (typeAttrName (), TypeAttr::get (recTy));
1364
+ result.addOperands (operands);
1365
+ }
1366
+
1335
1367
// ===----------------------------------------------------------------------===//
1336
1368
// InsertOnRangeOp
1337
1369
// ===----------------------------------------------------------------------===//
@@ -1987,17 +2019,18 @@ static mlir::ParseResult parseDTEntryOp(mlir::OpAsmParser &parser,
1987
2019
return mlir::failure ();
1988
2020
} else {
1989
2021
result.addAttribute (fir::DTEntryOp::methodAttrName (),
1990
- parser.getBuilder ().getStringAttr (methodName));
2022
+ parser.getBuilder ().getStringAttr (methodName));
1991
2023
}
1992
2024
mlir::SymbolRefAttr calleeAttr;
1993
2025
if (parser.parseComma () ||
1994
- parser.parseAttribute (calleeAttr, fir::DTEntryOp::procAttrName (), result.attributes ))
2026
+ parser.parseAttribute (calleeAttr, fir::DTEntryOp::procAttrName (),
2027
+ result.attributes ))
1995
2028
return mlir::failure ();
1996
2029
return mlir::success ();
1997
2030
}
1998
2031
1999
2032
static void print (mlir::OpAsmPrinter &p, fir::DTEntryOp &op) {
2000
- p << op.getOperationName () << ' '
2033
+ p << op.getOperationName () << ' '
2001
2034
<< op.getOperation ()->getAttr (fir::DTEntryOp::methodAttrName ()) << " , "
2002
2035
<< op.getOperation ()->getAttr (fir::DTEntryOp::procAttrName ());
2003
2036
}
@@ -2347,7 +2380,9 @@ static void print(mlir::OpAsmPrinter &p, fir::SelectCaseOp &op) {
2347
2380
p << op.getOperationName () << ' ' ;
2348
2381
p.printOperand (op.getSelector ());
2349
2382
p << " : " << op.getSelector ().getType () << " [" ;
2350
- auto cases = op.getOperation ()->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ()).getValue ();
2383
+ auto cases = op.getOperation ()
2384
+ ->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ())
2385
+ .getValue ();
2351
2386
auto count = op.getNumConditions ();
2352
2387
for (decltype (count) i = 0 ; i != count; ++i) {
2353
2388
if (i)
@@ -2365,8 +2400,10 @@ static void print(mlir::OpAsmPrinter &p, fir::SelectCaseOp &op) {
2365
2400
op.printSuccessorAtIndex (p, i);
2366
2401
}
2367
2402
p << ' ]' ;
2368
- p.printOptionalAttrDict (op.getOperation ()->getAttrs (), {op.getCasesAttr (), getCompareOffsetAttr (),
2369
- getTargetOffsetAttr (), op.getOperandSegmentSizeAttr ()});
2403
+ p.printOptionalAttrDict (op.getOperation ()->getAttrs (),
2404
+ {op.getCasesAttr (), getCompareOffsetAttr (),
2405
+ getTargetOffsetAttr (),
2406
+ op.getOperandSegmentSizeAttr ()});
2370
2407
}
2371
2408
2372
2409
unsigned fir::SelectCaseOp::compareOffsetSize () {
@@ -2464,7 +2501,9 @@ static mlir::LogicalResult verify(fir::SelectCaseOp &op) {
2464
2501
op.getSelector ().getType ().isa <fir::LogicalType>() ||
2465
2502
op.getSelector ().getType ().isa <fir::CharacterType>()))
2466
2503
return op.emitOpError (" must be an integer, character, or logical" );
2467
- auto cases = op.getOperation ()->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ()).getValue ();
2504
+ auto cases = op.getOperation ()
2505
+ ->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ())
2506
+ .getValue ();
2468
2507
auto count = op.getNumDest ();
2469
2508
if (count == 0 )
2470
2509
return op.emitOpError (" must have at least one successor" );
@@ -2477,10 +2516,8 @@ static mlir::LogicalResult verify(fir::SelectCaseOp &op) {
2477
2516
for (decltype (count) i = 0 ; i != count; ++i) {
2478
2517
auto &attr = cases[i];
2479
2518
if (!(attr.isa <fir::PointIntervalAttr>() ||
2480
- attr.isa <fir::LowerBoundAttr>() ||
2481
- attr.isa <fir::UpperBoundAttr>() ||
2482
- attr.isa <fir::ClosedIntervalAttr>() ||
2483
- attr.isa <mlir::UnitAttr>()))
2519
+ attr.isa <fir::LowerBoundAttr>() || attr.isa <fir::UpperBoundAttr>() ||
2520
+ attr.isa <fir::ClosedIntervalAttr>() || attr.isa <mlir::UnitAttr>()))
2484
2521
return op.emitOpError (" incorrect select case attribute type" );
2485
2522
}
2486
2523
return mlir::success ();
@@ -2605,7 +2642,9 @@ static void print(mlir::OpAsmPrinter &p, fir::SelectTypeOp &op) {
2605
2642
p << op.getOperationName () << ' ' ;
2606
2643
p.printOperand (op.getSelector ());
2607
2644
p << " : " << op.getSelector ().getType () << " [" ;
2608
- auto cases = op.getOperation ()->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ()).getValue ();
2645
+ auto cases = op.getOperation ()
2646
+ ->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ())
2647
+ .getValue ();
2609
2648
auto count = op.getNumConditions ();
2610
2649
for (decltype (count) i = 0 ; i != count; ++i) {
2611
2650
if (i)
@@ -2614,14 +2653,18 @@ static void print(mlir::OpAsmPrinter &p, fir::SelectTypeOp &op) {
2614
2653
op.printSuccessorAtIndex (p, i);
2615
2654
}
2616
2655
p << ' ]' ;
2617
- p.printOptionalAttrDict (op.getOperation ()->getAttrs (), {op.getCasesAttr (), getCompareOffsetAttr (),
2618
- getTargetOffsetAttr (), fir::SelectTypeOp::getOperandSegmentSizeAttr ()});
2656
+ p.printOptionalAttrDict (op.getOperation ()->getAttrs (),
2657
+ {op.getCasesAttr (), getCompareOffsetAttr (),
2658
+ getTargetOffsetAttr (),
2659
+ fir::SelectTypeOp::getOperandSegmentSizeAttr ()});
2619
2660
}
2620
2661
2621
2662
static mlir::LogicalResult verify (fir::SelectTypeOp &op) {
2622
2663
if (!(op.getSelector ().getType ().isa <fir::BoxType>()))
2623
2664
return op.emitOpError (" must be a boxed type" );
2624
- auto cases = op.getOperation ()->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ()).getValue ();
2665
+ auto cases = op.getOperation ()
2666
+ ->getAttrOfType <mlir::ArrayAttr>(op.getCasesAttr ())
2667
+ .getValue ();
2625
2668
auto count = op.getNumDest ();
2626
2669
if (count == 0 )
2627
2670
return op.emitOpError (" must have at least one successor" );
@@ -2638,6 +2681,37 @@ static mlir::LogicalResult verify(fir::SelectTypeOp &op) {
2638
2681
return mlir::success ();
2639
2682
}
2640
2683
2684
+ void fir::SelectTypeOp::build (mlir::OpBuilder &builder,
2685
+ mlir::OperationState &result,
2686
+ mlir::Value selector,
2687
+ llvm::ArrayRef<mlir::Attribute> typeOperands,
2688
+ llvm::ArrayRef<mlir::Block *> destinations,
2689
+ llvm::ArrayRef<mlir::ValueRange> destOperands,
2690
+ llvm::ArrayRef<mlir::NamedAttribute> attributes) {
2691
+ result.addOperands (selector);
2692
+ result.addAttribute (getCasesAttr (), builder.getArrayAttr (typeOperands));
2693
+ const auto count = destinations.size ();
2694
+ for (auto d : destinations)
2695
+ result.addSuccessors (d);
2696
+ const auto opCount = destOperands.size ();
2697
+ llvm::SmallVector<int32_t > argOffs;
2698
+ int32_t sumArgs = 0 ;
2699
+ for (std::remove_const_t <decltype (count)> i = 0 ; i != count; ++i) {
2700
+ if (i < opCount) {
2701
+ result.addOperands (destOperands[i]);
2702
+ const auto argSz = destOperands[i].size ();
2703
+ argOffs.push_back (argSz);
2704
+ sumArgs += argSz;
2705
+ } else {
2706
+ argOffs.push_back (0 );
2707
+ }
2708
+ }
2709
+ result.addAttribute (getOperandSegmentSizeAttr (),
2710
+ builder.getI32VectorAttr ({1 , 0 , sumArgs}));
2711
+ result.addAttribute (getTargetOffsetAttr (), builder.getI32VectorAttr (argOffs));
2712
+ result.addAttributes (attributes);
2713
+ }
2714
+
2641
2715
// ===----------------------------------------------------------------------===//
2642
2716
// ShapeOp
2643
2717
// ===----------------------------------------------------------------------===//
0 commit comments