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

Kiran Chandramohan via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 16 07:20:14 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));
----------------
kiranchandramohan wrote:

The default question here would be whether we are going to use this information in HLFIR/FIR transformations and if not whether it is better to delay adding this information closer to conversion to LLVM dialect or potentially later.

If it is closer to conversion to LLVM dialect then you might be able to reuse the pass that added `frame-pointer` attribute. https://github.com/llvm/llvm-project/pull/74598

Please wait for opinion from others as well.

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


More information about the llvm-branch-commits mailing list