Motivation
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.
The LLVM dialect seems like the clear place for this attribute, as it models the LLVM feature flags, and can directly map to the target-features
attribue.
Intended usage:
The target_features
attribute is populated manually or by a pass:
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.
// Finds the "target_features" attribute on the parent
// FunctionOpInterface via a static helper on TargetFeaturesAttr.
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 could be rather simple and just check if the exact feature is in the list, though it could be possible to extend with implied features using information from LLVM.