MLIR 24.0.0git
TestTarget.h
Go to the documentation of this file.
1//===- TestTarget.h - Predictable test ABI target --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the test ABI target, a predictable, dialect-agnostic
10// classifier used to exercise the MLIR ABIRewriteContext infrastructure
11// without depending on any real ABI. See TestTarget.cpp for the rules
12// and the rationale.
13//
14// It also declares parseClassificationAttr, the helper used by the
15// classification-injection driver: tests can attach an arbitrary
16// FunctionClassification to a function via a plain mlir::DictionaryAttr,
17// and the rewriter pass reads it back through this parser. This lets
18// tests verify rewriter output against any classification (including
19// shapes the test target itself doesn't produce) without needing a real
20// ABIInfo.
21//
22//===----------------------------------------------------------------------===//
23
24#ifndef MLIR_ABI_TARGETS_TEST_TESTTARGET_H
25#define MLIR_ABI_TARGETS_TEST_TESTTARGET_H
26
29#include "mlir/IR/Diagnostics.h"
30#include "mlir/IR/TypeRange.h"
33#include "llvm/Support/Error.h"
34
35namespace mlir {
36namespace abi {
37namespace test {
38
39/// Classify a function signature using the test target's predictable rules.
40///
41/// The rules approximate x86_64 SysV thresholds for reviewer familiarity
42/// (see TestTarget.cpp for the full list) but are not a substitute for
43/// testing against a real ABIInfo. Real-ABI-shaped tests should use the
44/// classification-injection driver via `parseClassificationAttr` below.
45///
46/// \param argTypes Argument types of the function.
47/// \param returnType Return type of the function.
48/// \param dl DataLayout used for size and alignment queries.
50 const DataLayout &dl);
51
52/// Parse a `FunctionClassification` from a plain MLIR DictionaryAttr.
53///
54/// Schema (all keys are required unless marked optional):
55///
56/// {
57/// return = { kind = "<kind>", ...per-kind keys... },
58/// args = [ { kind = "<kind>", ...per-kind keys... }, ... ]
59/// }
60///
61/// Per-arg/return dictionary keys:
62/// kind: StringAttr. One of "direct", "extend", "indirect",
63/// "indirect_aliased", "ignore", "expand".
64///
65/// For kind = "direct" (all optional):
66/// coerced_type: TypeAttr. ABI-coerced type, if different from the
67/// original.
68/// can_flatten: BoolAttr. Defaults to true.
69/// direct_align: IntegerAttr. Stack-slot alignment in bytes when the
70/// ABI sets one apart from the type's. When set, the
71/// rewriter emits llvm.alignstack.
72///
73/// For kind = "extend" (coerced_type required, sign_extend optional):
74/// coerced_type: TypeAttr. Required; the extended integer type.
75/// sign_extend: BoolAttr. Defaults to false (zero-extend).
76///
77/// For kind = "indirect" (indirect_align required, byval and
78/// indirect_addr_space optional):
79/// indirect_align: IntegerAttr. Required; alignment of the
80/// pointed-to object in bytes.
81/// byval: BoolAttr. Defaults to true.
82/// indirect_addr_space: IntegerAttr. Target address space of the
83/// pointer. Defaults to 0.
84///
85/// For kind = "indirect_aliased": the same keys as "indirect" except byval,
86/// which it rejects.
87///
88/// For kind = "ignore" / "expand": no extra keys.
89///
90/// Future schema additions tracked in projects/daily_log.md (Step 0c
91/// field-mapping table). When we add new fields to ArgClassification
92/// (e.g. direct_offset, extend_kind tristate, indirect_realign), the
93/// corresponding optional keys go here.
94///
95/// Unknown keys cause a parse error (no silent ignore — keeps schema
96/// honest as it grows).
97///
98/// \param attr The dictionary attribute to parse.
99/// \param emitError Diagnostic sink for parse errors.
100/// \returns The parsed classification, or failure on error.
101FailureOr<FunctionClassification>
102parseClassificationAttr(DictionaryAttr attr,
104} // namespace test
105} // namespace abi
106} // namespace mlir
107
108#endif // MLIR_ABI_TARGETS_TEST_TESTTARGET_H
The main mechanism for performing data layout queries.
This class represents a diagnostic that is inflight and set to be reported.
This class provides an abstraction over the various different ranges of value types.
Definition TypeRange.h:40
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
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.
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
Definition LLVM.h:155
Holds the full ABI classification for a function: return type and all arguments.