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

Kiran Chandramohan llvmlistbot at llvm.org
Wed Jan 17 07:59:23 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:

Some functions are outlined in MLIR math/complex conversions or runtime functions called. The simplifyIntrinsics pass also outlines functions (that are almost always inlined by LLVM but can potentially be not inlined). These can lead to this information being missed on these new functions or function declarations (for runtime calls).

Duplicating the same info (target_cpu, target_features) in all functions is probably a lot of noise.

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


More information about the Mlir-commits mailing list