46#include "llvm/Support/Alignment.h"
56constexpr uint64_t IndirectCutoffBytes = 16;
61constexpr unsigned ExtendBelowBits = 32;
64 if (isa<NoneType>(type))
67 if (
auto intTy = dyn_cast<IntegerType>(type)) {
68 if (intTy.getWidth() < ExtendBelowBits) {
75 if (
auto indexTy = dyn_cast<IndexType>(type)) {
77 if (sizeInBits.getFixedValue() < ExtendBelowBits) {
84 if (isa<FloatType, VectorType, MemRefType>(type))
93 if (!isa<DataLayoutTypeInterface>(type))
97 if (sizeInBits.isZero())
100 uint64_t sizeInBytes = (sizeInBits.getFixedValue() + 7) / 8;
101 if (sizeInBytes <= IndirectCutoffBytes)
116 fc.
argInfos.reserve(argTypes.size());
117 for (
Type t : argTypes)
118 fc.
argInfos.push_back(classifyOne(t, dl));
127constexpr StringRef knownArgKeys[] = {
128 "kind",
"coerced_type",
"sign_extend",
"can_flatten",
129 "direct_align",
"indirect_align",
"byval",
"indirect_addr_space",
132bool isKnownArgKey(StringRef key) {
133 for (StringRef k : knownArgKeys)
141FailureOr<ArgClassification>
143 StringAttr kindAttr = argDict.getAs<StringAttr>(
"kind");
145 emitError() <<
"missing required 'kind' StringAttr";
150 if (!isKnownArgKey(na.getName().getValue())) {
151 emitError() <<
"unknown key '" << na.getName().getValue()
152 <<
"' in classification dictionary; allowed keys are "
153 <<
"kind, coerced_type, sign_extend, can_flatten, "
154 <<
"direct_align, indirect_align, byval, "
155 <<
"indirect_addr_space";
159 StringRef kind = kindAttr.getValue();
161 if (kind ==
"direct") {
163 if (
auto t = argDict.getAs<TypeAttr>(
"coerced_type"))
164 coerced = t.getValue();
165 llvm::MaybeAlign align;
166 if (
auto da = argDict.getAs<IntegerAttr>(
"direct_align")) {
167 if (da.getInt() <= 0 || !llvm::isPowerOf2_64(da.getInt())) {
168 emitError() <<
"'direct_align' must be a positive power of 2; got "
172 align = llvm::Align(da.getInt());
175 if (
auto cf = argDict.getAs<
BoolAttr>(
"can_flatten"))
176 c.canFlatten =
cf.getValue();
180 if (kind ==
"extend") {
181 auto coerced = argDict.getAs<TypeAttr>(
"coerced_type");
183 emitError() <<
"kind='extend' requires 'coerced_type' TypeAttr";
186 bool signExt =
false;
187 if (
auto se = argDict.getAs<
BoolAttr>(
"sign_extend"))
188 signExt = se.getValue();
192 if (kind ==
"indirect" || kind ==
"indirect_aliased") {
193 auto align = argDict.getAs<IntegerAttr>(
"indirect_align");
196 <<
"' requires 'indirect_align' IntegerAttr";
199 if (align.getInt() <= 0 || !llvm::isPowerOf2_64(align.getInt())) {
200 emitError() <<
"'indirect_align' must be a positive power of 2; got "
204 unsigned addrSpace = 0;
205 if (
auto as = argDict.getAs<IntegerAttr>(
"indirect_addr_space")) {
206 if (as.getInt() < 0) {
207 emitError() <<
"'indirect_addr_space' must be non-negative; got "
211 addrSpace = as.getInt();
213 if (kind ==
"indirect_aliased") {
214 if (argDict.get(
"byval")) {
215 emitError() <<
"kind='indirect_aliased' does not take 'byval'";
222 if (
auto bv = argDict.getAs<
BoolAttr>(
"byval"))
223 byVal = bv.getValue();
228 if (kind ==
"ignore") {
232 if (kind ==
"expand") {
239 <<
"'; expected one of direct, extend, indirect, "
240 "indirect_aliased, ignore, expand";
247 auto returnDict = attr.getAs<DictionaryAttr>(
"return");
249 emitError() <<
"missing required 'return' DictionaryAttr";
253 auto argsArr = attr.getAs<ArrayAttr>(
"args");
255 emitError() <<
"missing required 'args' ArrayAttr";
260 StringRef k = na.getName().getValue();
261 if (k !=
"return" && k !=
"args") {
262 emitError() <<
"unknown top-level key '" << k
263 <<
"'; only 'return' and 'args' are allowed";
270 FailureOr<ArgClassification> ret = parseOne(returnDict,
emitError);
275 fc.
argInfos.reserve(argsArr.size());
277 auto d = dyn_cast<DictionaryAttr>(a);
279 emitError() <<
"'args' entries must be DictionaryAttrs";
282 FailureOr<ArgClassification> ac = parseOne(d,
emitError);
Attributes are known-constant values of operations.
Special case of IntegerAttr to represent boolean integers, i.e., signless i1 integers.
The main mechanism for performing data layout queries.
uint64_t getTypeABIAlignment(Type t) const
Returns the required alignment of the given type in the current scope.
llvm::TypeSize getTypeSizeInBits(Type t) const
Returns the size in bits of the given type in the current scope.
This class represents a diagnostic that is inflight and set to be reported.
NamedAttribute represents a combination of a name and an Attribute value.
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
FailureOr< FunctionClassification > parseClassificationAttr(DictionaryAttr attr, function_ref< InFlightDiagnostic()> emitError)
Parse a FunctionClassification from a plain MLIR DictionaryAttr.
FunctionClassification classify(TypeRange argTypes, Type returnType, const DataLayout &dl)
Classify a function signature using the test target's predictable rules.
@ Expand
Expand an aggregate into its constituent scalar fields.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::function_ref< Fn > function_ref
Describes how a single argument or return value is passed after ABI lowering.
static ArgClassification getIgnore()
static ArgClassification getDirect()
static ArgClassification getIndirect(llvm::Align align, bool byVal, unsigned addrSpace)
static ArgClassification getIndirectAliased(llvm::Align align, unsigned addrSpace)
static ArgClassification getExtend(Type coerced, bool signExt)
Holds the full ABI classification for a function: return type and all arguments.
ArgClassification returnInfo
SmallVector< ArgClassification > argInfos