@@ -89,35 +89,53 @@ static ParseResult parseAllocateAndAllocator(
8989 SmallVectorImpl<OpAsmParser::OperandType> &operandsAllocator,
9090 SmallVectorImpl<Type> &typesAllocator) {
9191
92- return parser.parseCommaSeparatedList (
93- OpAsmParser::Delimiter::Paren, [&]() -> ParseResult {
94- OpAsmParser::OperandType operand;
95- Type type;
96- if (parser.parseOperand (operand) || parser.parseColonType (type))
97- return failure ();
98- operandsAllocator.push_back (operand);
99- typesAllocator.push_back (type);
100- if (parser.parseArrow ())
101- return failure ();
102- if (parser.parseOperand (operand) || parser.parseColonType (type))
103- return failure ();
92+ return parser.parseCommaSeparatedList ([&]() -> ParseResult {
93+ OpAsmParser::OperandType operand;
94+ Type type;
95+ if (parser.parseOperand (operand) || parser.parseColonType (type))
96+ return failure ();
97+ operandsAllocator.push_back (operand);
98+ typesAllocator.push_back (type);
99+ if (parser.parseArrow ())
100+ return failure ();
101+ if (parser.parseOperand (operand) || parser.parseColonType (type))
102+ return failure ();
104103
105- operandsAllocate.push_back (operand);
106- typesAllocate.push_back (type);
107- return success ();
108- });
104+ operandsAllocate.push_back (operand);
105+ typesAllocate.push_back (type);
106+ return success ();
107+ });
109108}
110109
111110// / Print allocate clause
112- static void printAllocateAndAllocator (OpAsmPrinter &p,
111+ static void printAllocateAndAllocator (OpAsmPrinter &p, Operation *op,
113112 OperandRange varsAllocate,
114- OperandRange varsAllocator) {
115- p << " allocate(" ;
113+ TypeRange typesAllocate,
114+ OperandRange varsAllocator,
115+ TypeRange typesAllocator) {
116116 for (unsigned i = 0 ; i < varsAllocate.size (); ++i) {
117- std::string separator = i == varsAllocate.size () - 1 ? " ) " : " , " ;
118- p << varsAllocator[i] << " : " << varsAllocator[i].getType () << " -> " ;
119- p << varsAllocate[i] << " : " << varsAllocate[i].getType () << separator;
117+ std::string separator = i == varsAllocate.size () - 1 ? " " : " , " ;
118+ p << varsAllocator[i] << " : " << typesAllocator[i] << " -> " ;
119+ p << varsAllocate[i] << " : " << typesAllocate[i] << separator;
120+ }
121+ }
122+
123+ ParseResult parseProcBindKind (OpAsmParser &parser,
124+ omp::ClauseProcBindKindAttr &procBindAttr) {
125+ StringRef procBindStr;
126+ if (parser.parseKeyword (&procBindStr))
127+ return failure ();
128+ if (auto procBindVal = symbolizeClauseProcBindKind (procBindStr)) {
129+ procBindAttr =
130+ ClauseProcBindKindAttr::get (parser.getContext (), *procBindVal);
131+ return success ();
120132 }
133+ return failure ();
134+ }
135+
136+ void printProcBindKind (OpAsmPrinter &p, Operation *op,
137+ omp::ClauseProcBindKindAttr procBindAttr) {
138+ p << stringifyClauseProcBindKind (procBindAttr.getValue ());
121139}
122140
123141LogicalResult ParallelOp::verify () {
@@ -127,24 +145,6 @@ LogicalResult ParallelOp::verify() {
127145 return success ();
128146}
129147
130- void ParallelOp::print (OpAsmPrinter &p) {
131- p << " " ;
132- if (auto ifCond = if_expr_var ())
133- p << " if(" << ifCond << " : " << ifCond.getType () << " ) " ;
134-
135- if (auto threads = num_threads_var ())
136- p << " num_threads(" << threads << " : " << threads.getType () << " ) " ;
137-
138- if (!allocate_vars ().empty ())
139- printAllocateAndAllocator (p, allocate_vars (), allocators_vars ());
140-
141- if (auto bind = proc_bind_val ())
142- p << " proc_bind(" << stringifyClauseProcBindKind (*bind) << " ) " ;
143-
144- p << ' ' ;
145- p.printRegion (getRegion ());
146- }
147-
148148// ===----------------------------------------------------------------------===//
149149// Parser and printer for Linear Clause
150150// ===----------------------------------------------------------------------===//
@@ -626,9 +626,10 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
626626 return failure ();
627627 clauseSegments[pos[threadLimitClause]] = 1 ;
628628 } else if (clauseKeyword == " allocate" ) {
629- if (checkAllowed (allocateClause) ||
629+ if (checkAllowed (allocateClause) || parser. parseLParen () ||
630630 parseAllocateAndAllocator (parser, allocates, allocateTypes,
631- allocators, allocatorTypes))
631+ allocators, allocatorTypes) ||
632+ parser.parseRParen ())
632633 return failure ();
633634 clauseSegments[pos[allocateClause]] = allocates.size ();
634635 clauseSegments[pos[allocateClause] + 1 ] = allocators.size ();
@@ -803,32 +804,6 @@ static ParseResult parseClauses(OpAsmParser &parser, OperationState &result,
803804 return success ();
804805}
805806
806- // / Parses a parallel operation.
807- // /
808- // / operation ::= `omp.parallel` clause-list
809- // / clause-list ::= clause | clause clause-list
810- // / clause ::= if | num-threads | allocate | proc-bind
811- // /
812- ParseResult ParallelOp::parse (OpAsmParser &parser, OperationState &result) {
813- SmallVector<ClauseType> clauses = {ifClause, numThreadsClause, allocateClause,
814- procBindClause};
815-
816- SmallVector<int > segments;
817-
818- if (failed (parseClauses (parser, result, clauses, segments)))
819- return failure ();
820-
821- result.addAttribute (" operand_segment_sizes" ,
822- parser.getBuilder ().getI32VectorAttr (segments));
823-
824- Region *body = result.addRegion ();
825- SmallVector<OpAsmParser::OperandType> regionArgs;
826- SmallVector<Type> regionArgTypes;
827- if (parser.parseRegion (*body, regionArgs, regionArgTypes))
828- return failure ();
829- return success ();
830- }
831-
832807// ===----------------------------------------------------------------------===//
833808// Parser, printer and verifier for SectionsOp
834809// ===----------------------------------------------------------------------===//
@@ -863,8 +838,12 @@ void SectionsOp::print(OpAsmPrinter &p) {
863838 if (!reduction_vars ().empty ())
864839 printReductionVarList (p, reductions (), reduction_vars ());
865840
866- if (!allocate_vars ().empty ())
867- printAllocateAndAllocator (p, allocate_vars (), allocators_vars ());
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+ }
868847
869848 if (nowait ())
870849 p << " nowait" ;
0 commit comments