@@ -77,7 +77,6 @@ void ParallelOp::build(OpBuilder &builder, OperationState &state,
77
77
78
78
// / Parse an allocate clause with allocators and a list of operands with types.
79
79
// /
80
- // / allocate ::= `allocate` `(` allocate-operand-list `)`
81
80
// / allocate-operand-list :: = allocate-operand |
82
81
// / allocator-operand `,` allocate-operand-list
83
82
// / allocate-operand :: = ssa-id-and-type -> ssa-id-and-type
@@ -300,39 +299,35 @@ static void printScheduleClause(OpAsmPrinter &p, ClauseScheduleKind sched,
300
299
// Parser, printer and verifier for ReductionVarList
301
300
// ===----------------------------------------------------------------------===//
302
301
303
- // / reduction ::= `reduction` `(` reduction-entry-list `)`
304
302
// / reduction-entry-list ::= reduction-entry
305
303
// / | reduction-entry-list `,` reduction-entry
306
304
// / reduction-entry ::= symbol-ref `->` ssa-id `:` type
307
- static ParseResult
308
- parseReductionVarList (OpAsmParser &parser,
309
- SmallVectorImpl<SymbolRefAttr> &symbols,
310
- SmallVectorImpl<OpAsmParser::OperandType> &operands,
311
- SmallVectorImpl<Type> &types) {
312
- if (failed (parser.parseLParen ()))
313
- return failure ();
314
-
305
+ static ParseResult parseReductionVarList (
306
+ OpAsmParser &parser, SmallVectorImpl<OpAsmParser::OperandType> &operands,
307
+ SmallVectorImpl<Type> &types, ArrayAttr &redcuctionSymbols) {
308
+ SmallVector<SymbolRefAttr> reductionVec;
315
309
do {
316
- if (parser.parseAttribute (symbols .emplace_back ()) || parser. parseArrow ( ) ||
317
- parser.parseOperand (operands.emplace_back ()) ||
310
+ if (parser.parseAttribute (reductionVec .emplace_back ()) ||
311
+ parser.parseArrow () || parser. parseOperand (operands.emplace_back ()) ||
318
312
parser.parseColonType (types.emplace_back ()))
319
313
return failure ();
320
314
} while (succeeded (parser.parseOptionalComma ()));
321
- return parser.parseRParen ();
315
+ SmallVector<Attribute> reductions (reductionVec.begin (), reductionVec.end ());
316
+ redcuctionSymbols = ArrayAttr::get (parser.getContext (), reductions);
317
+ return success ();
322
318
}
323
319
324
320
// / Print Reduction clause
325
- static void printReductionVarList (OpAsmPrinter &p,
326
- Optional<ArrayAttr> reductions ,
327
- OperandRange reductionVars) {
328
- p << " reduction( " ;
321
+ static void printReductionVarList (OpAsmPrinter &p, Operation *op,
322
+ OperandRange reductionVars ,
323
+ TypeRange reductionTypes,
324
+ Optional<ArrayAttr> reductions) {
329
325
for (unsigned i = 0 , e = reductions->size (); i < e; ++i) {
330
326
if (i != 0 )
331
327
p << " , " ;
332
328
p << (*reductions)[i] << " -> " << reductionVars[i] << " : "
333
329
<< reductionVars[i].getType ();
334
330
}
335
- p << " ) " ;
336
331
}
337
332
338
333
// / Verifies Reduction Clause
@@ -552,7 +547,7 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
552
547
SmallVector<OpAsmParser::OperandType> allocates, allocators;
553
548
SmallVector<Type> allocateTypes, allocatorTypes;
554
549
555
- SmallVector<SymbolRefAttr> reductionSymbols ;
550
+ ArrayAttr reductions ;
556
551
SmallVector<OpAsmParser::OperandType> reductionVars;
557
552
SmallVector<Type> reductionVarTypes;
558
553
@@ -639,9 +634,10 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
639
634
" proc_bind_val" , " proc bind" ))
640
635
return failure ();
641
636
} else if (clauseKeyword == " reduction" ) {
642
- if (checkAllowed (reductionClause) ||
643
- parseReductionVarList (parser, reductionSymbols, reductionVars,
644
- reductionVarTypes))
637
+ if (checkAllowed (reductionClause) || parser.parseLParen () ||
638
+ parseReductionVarList (parser, reductionVars, reductionVarTypes,
639
+ reductions) ||
640
+ parser.parseRParen ())
645
641
return failure ();
646
642
clauseSegments[pos[reductionClause]] = reductionVars.size ();
647
643
} else if (clauseKeyword == " nowait" ) {
@@ -746,11 +742,7 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
746
742
if (failed (parser.resolveOperands (reductionVars, reductionVarTypes,
747
743
parser.getNameLoc (), result.operands )))
748
744
return failure ();
749
-
750
- SmallVector<Attribute> reductions (reductionSymbols.begin (),
751
- reductionSymbols.end ());
752
- result.addAttribute (" reductions" ,
753
- parser.getBuilder ().getArrayAttr (reductions));
745
+ result.addAttribute (" reductions" , reductions);
754
746
}
755
747
756
748
// Add linear parameters
@@ -805,53 +797,9 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
805
797
}
806
798
807
799
// ===----------------------------------------------------------------------===//
808
- // Parser, printer and verifier for SectionsOp
800
+ // Verifier for SectionsOp
809
801
// ===----------------------------------------------------------------------===//
810
802
811
- // / Parses an OpenMP Sections operation
812
- // /
813
- // / sections ::= `omp.sections` clause-list
814
- // / clause-list ::= clause clause-list | empty
815
- // / clause ::= reduction | allocate | nowait
816
- ParseResult SectionsOp::parse (OpAsmParser &parser, OperationState &result) {
817
- SmallVector<ClauseType> clauses = {reductionClause, allocateClause,
818
- nowaitClause};
819
-
820
- SmallVector<int > segments;
821
-
822
- if (failed (parseClauses (parser, result, clauses, segments)))
823
- return failure ();
824
-
825
- result.addAttribute (" operand_segment_sizes" ,
826
- parser.getBuilder ().getI32VectorAttr (segments));
827
-
828
- // Now parse the body.
829
- Region *body = result.addRegion ();
830
- if (parser.parseRegion (*body))
831
- return failure ();
832
- return success ();
833
- }
834
-
835
- void SectionsOp::print (OpAsmPrinter &p) {
836
- p << " " ;
837
-
838
- if (!reduction_vars ().empty ())
839
- printReductionVarList (p, reductions (), reduction_vars ());
840
-
841
- if (!allocate_vars ().empty ()) {
842
- printAllocateAndAllocator (p << " allocate(" , *this , allocate_vars (),
843
- allocate_vars ().getTypes (), allocators_vars (),
844
- allocators_vars ().getTypes ());
845
- p << " )" ;
846
- }
847
-
848
- if (nowait ())
849
- p << " nowait" ;
850
-
851
- p << ' ' ;
852
- p.printRegion (region ());
853
- }
854
-
855
803
LogicalResult SectionsOp::verify () {
856
804
if (allocate_vars ().size () != allocators_vars ().size ())
857
805
return emitError (
@@ -960,8 +908,11 @@ void WsLoopOp::print(OpAsmPrinter &p) {
960
908
if (auto order = order_val ())
961
909
p << " order(" << stringifyClauseOrderKind (*order) << " ) " ;
962
910
963
- if (!reduction_vars ().empty ())
964
- printReductionVarList (p, reductions (), reduction_vars ());
911
+ if (!reduction_vars ().empty ()) {
912
+ printReductionVarList (p << " reduction(" , *this , reduction_vars (),
913
+ reduction_vars ().getTypes (), reductions ());
914
+ p << " )" ;
915
+ }
965
916
966
917
p << ' ' ;
967
918
p.printRegion (region (), /* printEntryBlockArgs=*/ false );
0 commit comments