[flang-commits] [mlir] [flang] [Flang][Lower] Attach target_cpu and target_features attributes to MLIR functions (PR #78289)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Thu Jan 18 06:04:13 PST 2024


================
@@ -4290,6 +4291,18 @@ class FirConverter : public Fortran::lower::AbstractConverter {
     assert(blockId == 0 && "invalid blockId");
     assert(activeConstructStack.empty() && "invalid construct stack state");
 
+    // Set target_cpu and target_features attributes to be passed through to the
+    // llvm.func operation during lowering.
+    const llvm::TargetMachine &targetMachine = bridge.getTargetMachine();
+    if (auto targetCPU = targetMachine.getTargetCPU(); !targetCPU.empty())
+      func->setAttr("target_cpu",
+                    mlir::StringAttr::get(func.getContext(), targetCPU));
+
+    if (auto targetFeatures = targetMachine.getTargetFeatureString();
+        !targetFeatures.empty())
+      func->setAttr("target_features", mlir::LLVM::TargetFeaturesAttr::get(
+                                           func.getContext(), targetFeatures));
----------------
kparzysz wrote:

The intent in adding all relevant information from target machine early on is to become independent of it, or in other words, the generated module is more self-contained.  We already get the target machine at this point, so we may extract all that we're going to need from it, until having it again becomes necessary (generation of LLVM IR?).

This isn't to say that we have to do it, it just explains my motive for suggesting it.

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


More information about the flang-commits mailing list