|
15 | 15 | #include "flang/Lower/FIRBuilder.h"
|
16 | 16 | #include "flang/Lower/PFTBuilder.h"
|
17 | 17 | #include "flang/Parser/parse-tree.h"
|
| 18 | +#include "flang/Semantics/tools.h" |
18 | 19 | #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
|
19 | 20 | #include "llvm/Frontend/OpenMP/OMPConstants.h"
|
20 | 21 |
|
@@ -87,19 +88,34 @@ genOMP(Fortran::lower::AbstractConverter &absConv,
|
87 | 88 | auto &firOpBuilder = absConv.getFirOpBuilder();
|
88 | 89 | auto currentLocation = absConv.getCurrentLocation();
|
89 | 90 | auto insertPt = firOpBuilder.saveInsertionPoint();
|
| 91 | + |
| 92 | + // Clauses. |
| 93 | + // FIXME: Add support for other clauses. |
| 94 | + mlir::Value numThreads; |
| 95 | + |
| 96 | + const auto ¶llelOpClauseList = |
| 97 | + std::get<Fortran::parser::OmpClauseList>(blockDirective.t); |
| 98 | + for (const auto &clause : parallelOpClauseList.v) { |
| 99 | + if (const auto &numThreadsClause = |
| 100 | + std::get_if<Fortran::parser::OmpClause::NumThreads>(&clause.u)) { |
| 101 | + // OMPIRBuilder expects `NUM_THREAD` clause as a `Value`. |
| 102 | + numThreads = absConv.genExprValue( |
| 103 | + *Fortran::semantics::GetExpr(numThreadsClause->v)); |
| 104 | + } |
| 105 | + } |
90 | 106 | llvm::ArrayRef<mlir::Type> argTy;
|
91 |
| - mlir::ValueRange range; |
92 |
| - llvm::SmallVector<int32_t, 6> operandSegmentSizes(6 /*Size=*/, |
93 |
| - 0 /*Value=*/); |
94 |
| - // create and insert the operation. |
| 107 | + Attribute defaultValue, procBindValue; |
| 108 | + // Create and insert the operation. |
| 109 | + // Create the Op with empty ranges for clauses that are yet to be lowered. |
95 | 110 | auto parallelOp = firOpBuilder.create<mlir::omp::ParallelOp>(
|
96 |
| - currentLocation, argTy, range); |
97 |
| - parallelOp.setAttr(mlir::omp::ParallelOp::getOperandSegmentSizeAttr(), |
98 |
| - firOpBuilder.getI32VectorAttr(operandSegmentSizes)); |
99 |
| - parallelOp.getRegion().push_back(new Block{}); |
| 111 | + currentLocation, argTy, Value(), numThreads, |
| 112 | + defaultValue.dyn_cast_or_null<StringAttr>(), ValueRange(), ValueRange(), |
| 113 | + ValueRange(), ValueRange(), |
| 114 | + procBindValue.dyn_cast_or_null<StringAttr>()); |
| 115 | + firOpBuilder.createBlock(¶llelOp.getRegion()); |
100 | 116 | auto &block = parallelOp.getRegion().back();
|
101 | 117 | firOpBuilder.setInsertionPointToStart(&block);
|
102 |
| - // ensure the block is well-formed. |
| 118 | + // Ensure the block is well-formed. |
103 | 119 | firOpBuilder.create<mlir::omp::TerminatorOp>(currentLocation);
|
104 | 120 | firOpBuilder.restoreInsertionPoint(insertPt);
|
105 | 121 | }
|
|
0 commit comments