10#include "llvm/Support/FormatVariadic.h"
21 case Profile::pro_int:
27 llvm_unreachable(
"Unknown TOSA profile");
32 case Extension::int16:
35 case Extension::fp8e4m3:
36 case Extension::fp8e5m2:
38 case Extension::variable:
39 case Extension::controlflow:
40 case Extension::doubleround:
41 case Extension::inexactround:
42 case Extension::dynamic:
45 case Extension::int64:
46 case Extension::mxfp_conv:
47 case Extension::shape:
52 llvm_unreachable(
"Unknown TOSA extension");
57 case Extension::int16:
59 case Extension::doubleround:
60 case Extension::inexactround:
61 return {Profile::pro_int};
63 case Extension::fp8e4m3:
64 case Extension::fp8e5m2:
67 case Extension::mxfp_conv:
68 return {Profile::pro_fp};
69 case Extension::variable:
70 case Extension::controlflow:
71 case Extension::dynamic:
72 case Extension::int64:
73 case Extension::shape:
74 return {Profile::pro_fp, Profile::pro_int};
78 llvm_unreachable(
"bad Extension type");
87 llvm_unreachable(
"Unknown TOSA level");
96 return TargetEnv(targetAttr.getSpecificationVersion(), targetAttr.getLevel(),
97 targetAttr.getProfiles(), targetAttr.getExtensions());
104 const auto isCompatibleWithTargetVersion =
105 [&](
const auto &targetEnum,
Location targetAttrLoc,
106 StringRef enumName) -> LogicalResult {
110 return emitError(targetAttrLoc, enumName)
111 <<
" '" << stringifyEnum(targetEnum)
112 <<
"' is not compatible with the target version "
114 <<
", minimum required version is "
119 const auto isExtensionCooperativeWithProfile =
120 [&](Extension ext) -> LogicalResult {
124 if (!llvm::any_of(cooperativeProfiles,
125 [&targetProfiles](
const auto &profile) {
126 return llvm::is_contained(targetProfiles, profile);
129 <<
"use of extension '" << stringifyEnum(ext)
130 <<
"' requires any of profiles: [" << cooperativeProfiles
131 <<
"] to be enabled in the target";
136 for (
const auto &profile : targetAttr.getProfiles())
138 isCompatibleWithTargetVersion(profile, targetAttrLoc,
"profile")))
140 for (
const auto &extension : targetAttr.getExtensions()) {
141 if (failed(isCompatibleWithTargetVersion(extension, targetAttrLoc,
144 if (failed(isExtensionCooperativeWithProfile(extension)))
147 if (failed(isCompatibleWithTargetVersion(targetAttr.getLevel(), targetAttrLoc,
160 if (
auto attr = op->
getAttrOfType<TargetEnvAttr>(TargetEnvAttr::name))
170 return TargetEnvAttr::get(context, SpecificationVersion::V_1_0, Level::eightK,
171 {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.