[flang-commits] [flang] [flang][OpenMP][NFC] Outline `genOpWithBody` & `createBodyOfOp` args (PR #80817)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Tue Feb 6 04:58:31 PST 2024


================
@@ -2250,6 +2250,17 @@ createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
   return storeOp;
 }
 
+struct CreateBodyOfOpInfo {
+  Fortran::lower::AbstractConverter &converter;
+  mlir::Location &loc;
+  Fortran::lower::pft::Evaluation &eval;
+  bool genNested = true;
+  const Fortran::parser::OmpClauseList *clauses = nullptr;
+  const llvm::SmallVector<const Fortran::semantics::Symbol *> &args = {};
+  bool outerCombined = false;
+  DataSharingProcessor *dsp = nullptr;
----------------
luporl wrote:

While we can't use member designators, what about creating setters for the fields that have a default value?

```c++
  CreateBodyOfOpInfo &setGenNested(bool val) { genNested = val; }
  CreateBodyOfOpInfo &setClauses(const Fortran::parser::OmpClauseList *clauses) { clauses = clauses; }
  ...
```

By returning a reference to the object, it should be possible to chain calls to setters, like below:
`{ converter, loc, eval }.setClauses(clauses).setDsp(dsp)`

The advantage of this is that only fields with non-default values need to be explicitly set.
So, for instance, if a given function just needs to set `dsp`, it doesn't need to specify all other fields before it.
This makes it easier to add a new field or change default values.

Another option would be to add constructors that handle the most commonly set fields.
Example:
```c++
CreateBodyOfOpInfo(Fortran::lower::AbstractConverter &converter,
  mlir::Location &loc,
  Fortran::lower::pft::Evaluation &eval,
  bool genNested = true,
  const Fortran::parser::OmpClauseList *clauses = nullptr,
  const llvm::SmallVector<const Fortran::semantics::Symbol *> &args = {},
  bool outerCombined = false,
  DataSharingProcessor *dsp = nullptr)
  : loc(loc), eval(eval), genNested(genNested), ... {}

CreateBodyOfOpInfo(Fortran::lower::AbstractConverter &converter,
  mlir::Location &loc,
  Fortran::lower::pft::Evaluation &eval,
  bool genNested,
  bool outerCombined)
  : CreateBodyOfOpInfo(converter, loc, eval, genNested, nullptr, {}, outerCombined) {}

CreateBodyOfOpInfo(Fortran::lower::AbstractConverter &converter,
  mlir::Location &loc,
  Fortran::lower::pft::Evaluation &eval,
  DataSharingProcessor *dsp)
  : CreateBodyOfOpInfo(converter, loc, eval, true, nullptr, {}, false, dsp) {}
```

https://github.com/llvm/llvm-project/pull/80817


More information about the flang-commits mailing list