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