MLIR 23.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"
31#include "llvm/Support/Error.h"
32
33namespace mlir {
34namespace abi {
35namespace test {
36
37/// Classify a function signature using the test target's predictable rules.
38///
39/// The rules approximate x86_64 SysV thresholds for reviewer familiarity
40/// (see TestTarget.cpp for the full list) but are not a substitute for
41/// testing against a real ABIInfo. Real-ABI-shaped tests should use the
42/// classification-injection driver via `parseClassificationAttr` below.
43///
44/// \param argTypes Argument types of the function.
45/// \param returnType Return type of the function.
46/// \param dl DataLayout used for size and alignment queries.
48 const DataLayout &dl);
49
50/// Parse a `FunctionClassification` from a plain MLIR DictionaryAttr.
51///
52/// Schema (all keys are required unless marked optional):
53///
54/// {
55/// return = { kind = "<kind>", ...per-kind keys... },
56/// args = [ { kind = "<kind>", ...per-kind keys... }, ... ]
57/// }
58///
59/// Per-arg/return dictionary keys:
60/// kind: StringAttr. One of "direct", "extend", "indirect",
61/// "ignore", "expand".
62///
63/// For kind = "direct" (all optional):
64/// coerced_type: TypeAttr. ABI-coerced type, if different from the
65/// original.
66/// can_flatten: BoolAttr. Defaults to true.
67///
68/// For kind = "extend" (coerced_type required, sign_extend optional):
69/// coerced_type: TypeAttr. Required; the extended integer type.
70/// sign_extend: BoolAttr. Defaults to false (zero-extend).
71///
72/// For kind = "indirect" (indirect_align required, byval optional):
73/// indirect_align: IntegerAttr. Required; alignment of the pointed-to
74/// object in bytes.
75/// byval: BoolAttr. Defaults to true.
76///
77/// For kind = "ignore" / "expand": no extra keys.
78///
79/// Future schema additions tracked in projects/daily_log.md (Step 0c
80/// field-mapping table). When we add new fields to ArgClassification
81/// (e.g. direct_offset, extend_kind tristate, indirect_addr_space,
82/// indirect_realign), the corresponding optional keys go here.
83///
84/// Unknown keys cause a parse error (no silent ignore — keeps schema
85/// honest as it grows).
86///
87/// \param attr The dictionary attribute to parse.
88/// \param emitError Diagnostic sink for parse errors.
89/// \returns The parsed classification, or std::nullopt on error.
90std::optional<FunctionClassification>
91parseClassificationAttr(DictionaryAttr attr,
93
94} // namespace test
95} // namespace abi
96} // namespace mlir
97
98#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.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
std::optional< FunctionClassification > parseClassificationAttr(DictionaryAttr attr, function_ref< InFlightDiagnostic()> emitError)
Parse a FunctionClassification from a plain MLIR DictionaryAttr.
FunctionClassification classify(ArrayRef< Type > 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:147
Holds the full ABI classification for a function: return type and all arguments.