[flang-commits] [flang] [flang][OpenMP][MLIR] Basic support for delayed privatization code-gen (PR #81833)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Sun Feb 18 03:04:46 PST 2024


================
@@ -522,11 +549,96 @@ void DataSharingProcessor::defaultPrivatize() {
         !sym->GetUltimate().has<Fortran::semantics::NamelistDetails>() &&
         !symbolsInNestedRegions.contains(sym) &&
         !symbolsInParentRegions.contains(sym) &&
-        !privatizedSymbols.contains(sym)) {
+        !privatizedSymbols.contains(sym))
+      doPrivatize(sym);
+  }
+}
+
+void DataSharingProcessor::doPrivatize(const Fortran::semantics::Symbol *sym) {
+  if (!useDelayedPrivatization) {
+    cloneSymbol(sym);
+    copyFirstPrivateSymbol(sym);
+    return;
+  }
+
+  Fortran::lower::SymbolBox hsb = converter.lookupOneLevelUpSymbol(*sym);
+  assert(hsb && "Host symbol box not found");
+
+  mlir::Type symType = hsb.getAddr().getType();
+  mlir::Location symLoc = hsb.getAddr().getLoc();
+  std::string privatizerName = sym->name().ToString() + ".privatizer";
+  bool isFirstPrivate =
+      sym->test(Fortran::semantics::Symbol::Flag::OmpFirstPrivate);
+
+  mlir::omp::PrivateClauseOp privatizerOp = [&]() {
+    auto moduleOp = firOpBuilder.getModule();
+
+    auto uniquePrivatizerName = fir::getTypeAsString(
+        symType, converter.getKindMap(),
+        sym->name().ToString() +
----------------
ergawy wrote:

> Would it make sense to make the privatizer name only depend on the variable type and the data sharing type (private, firstprivate, ...)?

I did this initially as suggested by @clementval & @luporl and it works fine. However, in the `alloc` region of the privatizer, we have `binc_name` attributes that have the name of the first symbol with that type and data-sharing type. So if you `var1` and `var2` sharing the same type and data-sharing type, you get something like this for their shared privatizer:
```
fir.alloca i32 {bindc_name = "var1", pinned, uniq_name = "_QFdelayed_privatization_privateEvar1"}
```

So if this is fine, I can go back to not using the variable name. I am just not very familiar with the semantics of these name-related attributes so I went the safer way.

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


More information about the flang-commits mailing list