[all-commits] [llvm/llvm-project] 17de46: [mlir][llvm] Add llvm.target_features features att...

Benjamin Maxwell via All-commits all-commits at lists.llvm.org
Tue Dec 5 03:29:44 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 17de468df1af6479f31bb8c02973e01702f7b240
      https://github.com/llvm/llvm-project/commit/17de468df1af6479f31bb8c02973e01702f7b240
  Author: Benjamin Maxwell <benjamin.maxwell at arm.com>
  Date:   2023-12-05 (Tue, 05 Dec 2023)

  Changed paths:
    M mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    M mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
    M mlir/lib/Target/LLVMIR/ModuleImport.cpp
    M mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
    A mlir/test/Target/LLVMIR/Import/target-features.ll
    M mlir/test/Target/LLVMIR/llvmir-invalid.mlir
    A mlir/test/Target/LLVMIR/target-features.mlir

  Log Message:
  -----------
  [mlir][llvm] Add llvm.target_features features attribute (#71510)

This patch adds a target_features (TargetFeaturesAttr) to the LLVM
dialect to allow setting and querying the features in use on a function.

The motivation for this comes from the Arm SME dialect where we would
like a convenient way to check what variants of an operation are
available based on the CPU features.

Intended usage:

The target_features attribute is populated manually or by a pass:

```mlir
func.func @example() attributes {
   target_features = #llvm.target_features<["+sme", "+sve", "+sme-f64f64"]>
} {
 // ...
}
```

Then within a later rewrite the attribute can be checked, and used to
make lowering decisions.

```c++
// Finds the "target_features" attribute on the parent
// FunctionOpInterface.
auto targetFeatures = LLVM::TargetFeaturesAttr::featuresAt(op);

// Check a feature.
// Returns false if targetFeatures is null or the feature is not in
// the list.
if (!targetFeatures.contains("+sme-f64f64"))
    return failure();
```

For now, this is rather simple just checks if the exact feature is in
the list, though it could be possible to extend with implied features
using information from LLVM.




More information about the All-commits mailing list