10#include "llvm/Support/FormatVariadic.h"
17 version.
isDraft() ?
".draft" :
"");
22 case Profile::pro_int:
28 llvm_unreachable(
"Unknown TOSA profile");
33 case Extension::int16:
36 case Extension::fp8e4m3:
37 case Extension::fp8e5m2:
39 case Extension::variable:
40 case Extension::controlflow:
41 case Extension::doubleround:
42 case Extension::inexactround:
43 case Extension::dynamic:
46 case Extension::int64:
47 case Extension::mxfp_conv:
48 case Extension::shape:
53 llvm_unreachable(
"Unknown TOSA extension");
58 case Extension::int16:
60 case Extension::doubleround:
61 case Extension::inexactround:
62 return {Profile::pro_int};
64 case Extension::fp8e4m3:
65 case Extension::fp8e5m2:
68 case Extension::mxfp_conv:
69 return {Profile::pro_fp};
70 case Extension::variable:
71 case Extension::controlflow:
72 case Extension::dynamic:
73 case Extension::int64:
74 case Extension::shape:
75 return {Profile::pro_fp, Profile::pro_int};
79 llvm_unreachable(
"bad Extension type");
88 llvm_unreachable(
"Unknown TOSA level");
97 return TargetEnv(targetAttr.getSpecificationVersion(), targetAttr.getLevel(),
98 targetAttr.getProfiles(), targetAttr.getExtensions());
105 const auto isCompatibleWithTargetVersion =
106 [&](
const auto &targetEnum,
Location targetAttrLoc,
107 StringRef enumName) -> LogicalResult {
111 return emitError(targetAttrLoc, enumName)
112 <<
" '" << stringifyEnum(targetEnum)
113 <<
"' is not compatible with the target version "
115 <<
", minimum required version is "
120 const auto isExtensionCooperativeWithProfile =
121 [&](Extension ext) -> LogicalResult {
125 if (!llvm::any_of(cooperativeProfiles,
126 [&targetProfiles](
const auto &profile) {
127 return llvm::is_contained(targetProfiles, profile);
130 <<
"use of extension '" << stringifyEnum(ext)
131 <<
"' requires any of profiles: [" << cooperativeProfiles
132 <<
"] to be enabled in the target";
137 for (
const auto &profile : targetAttr.getProfiles())
139 isCompatibleWithTargetVersion(profile, targetAttrLoc,
"profile")))
141 for (
const auto &extension : targetAttr.getExtensions()) {
142 if (failed(isCompatibleWithTargetVersion(extension, targetAttrLoc,
145 if (failed(isExtensionCooperativeWithProfile(extension)))
148 if (failed(isCompatibleWithTargetVersion(targetAttr.getLevel(), targetAttrLoc,
161 if (
auto attr = op->
getAttrOfType<TargetEnvAttr>(TargetEnvAttr::name))
171 return TargetEnvAttr::get(context, SpecificationVersion::V_1_0, Level::eightK,
172 {Profile::pro_int, Profile::pro_fp}, {});
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
AttrClass getAttrOfType(StringAttr name)
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
MLIRContext * getContext()
Return the context this operation is associated with.
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
static FailureOr< TargetEnv > createTargetEnvFromAttr(TargetEnvAttr targetAttr, Location targetEnvAttrLoc)
static LogicalResult verifyTargetInformation(TargetEnvAttr targetAttr, Location targetAttrLoc)
A thin wrapper around the SpecificationVersion enum to represent and provide utilities around the TOS...
bool isBackwardsCompatibleWith(TosaSpecificationVersion baseVersion) const
uint32_t getMinor() const
uint32_t getMajor() const
llvm::SmallString< 4 > stringifyVersion(TosaSpecificationVersion version)
SmallVector< Profile, 2 > getCooperativeProfiles(Extension ext)
TargetEnvAttr getDefaultTargetEnv(MLIRContext *context)
TosaSpecificationVersion getMinVersion(const Profile &profile)
TargetEnvAttr lookupTargetEnv(Operation *op)
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.