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

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Fri Jan 19 03:14:03 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));
----------------
skatrak wrote:

> I understand your point about self-contained module, and I am not opposed adding these attributes to the module op until we are ready to add them on the func.func (that is, before codegen when we should not emit new func.func), and to retrieve them from here instead of the driver.

I think this is a good compromise. Since these attributes will have the same values for all functions, we can attach this information to the module, making it available as early as possible, but without having to deal with explicitly adding them to each function that is created. Then, the target rewrite pass only has to forward these module attributes to each function.

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


More information about the flang-commits mailing list