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

Mats Petersson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 17 06:28: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));
----------------
Leporacanthicus wrote:

I _think_ this doesn't set the target info for function declarations (interfaces that are in a different source), which I  need. I'm happy to add that as an addition on top. l

Are we getting the target CPU and target features for every function? Or just the once? I'm sure it's not a "heavy" operaiton, but seems a bit unnecessary to do repeatedly. Should be the same for ALL functions in a module... 

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


More information about the llvm-branch-commits mailing list