clang 22.0.0git
ABIArgInfo.h
Go to the documentation of this file.
1//==-- ABIArgInfo.h - Abstract info regarding ABI-specific arguments -------==//
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// Defines ABIArgInfo and associated types used by CIR to track information
10// regarding ABI-coerced types for function arguments and return values. This
11// was moved to the common library as it might be used by both CIRGen and
12// passes.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef CLANG_CIR_ABIARGINFO_H
17#define CLANG_CIR_ABIARGINFO_H
18
19#include "mlir/IR/Types.h"
21
22namespace cir {
23
25public:
26 enum Kind : uint8_t {
27 /// Pass the argument directly using the normal converted CIR type,
28 /// or by coercing to another specified type stored in 'CoerceToType'). If
29 /// an offset is specified (in UIntData), then the argument passed is offset
30 /// by some number of bytes in the memory representation. A dummy argument
31 /// is emitted before the real argument if the specified type stored in
32 /// "PaddingType" is not zero.
34
35 /// Ignore the argument (treat as void). Useful for void and empty
36 /// structs.
38
39 // TODO: more argument kinds will be added as the upstreaming proceeds.
40 };
41
42private:
43 mlir::Type typeData;
44 struct DirectAttrInfo {
45 unsigned offset;
46 unsigned align;
47 };
48 union {
49 DirectAttrInfo directAttr;
50 };
51 Kind theKind;
52
53public:
54 ABIArgInfo(Kind k = Direct) : directAttr{0, 0}, theKind(k) {}
55
56 static ABIArgInfo getDirect(mlir::Type ty = nullptr) {
57 ABIArgInfo info(Direct);
58 info.setCoerceToType(ty);
60 return info;
61 }
62
63 static ABIArgInfo getIgnore() { return ABIArgInfo(Ignore); }
64
65 Kind getKind() const { return theKind; }
66 bool isDirect() const { return theKind == Direct; }
67 bool isIgnore() const { return theKind == Ignore; }
68
69 bool canHaveCoerceToType() const {
71 return isDirect();
72 }
73
74 unsigned getDirectOffset() const {
76 return directAttr.offset;
77 }
78
79 mlir::Type getCoerceToType() const {
80 assert(canHaveCoerceToType() && "invalid kind!");
81 return typeData;
82 }
83
84 void setCoerceToType(mlir::Type ty) {
85 assert(canHaveCoerceToType() && "invalid kind!");
86 typeData = ty;
87 }
88};
89
90} // namespace cir
91
92#endif // CLANG_CIR_ABIARGINFO_H
ABIArgInfo(Kind k=Direct)
Definition: ABIArgInfo.h:54
DirectAttrInfo directAttr
Definition: ABIArgInfo.h:49
Kind getKind() const
Definition: ABIArgInfo.h:65
@ Direct
Pass the argument directly using the normal converted CIR type, or by coercing to another specified t...
Definition: ABIArgInfo.h:33
@ Ignore
Ignore the argument (treat as void).
Definition: ABIArgInfo.h:37
mlir::Type getCoerceToType() const
Definition: ABIArgInfo.h:79
bool isIgnore() const
Definition: ABIArgInfo.h:67
bool isDirect() const
Definition: ABIArgInfo.h:66
void setCoerceToType(mlir::Type ty)
Definition: ABIArgInfo.h:84
static ABIArgInfo getIgnore()
Definition: ABIArgInfo.h:63
bool canHaveCoerceToType() const
Definition: ABIArgInfo.h:69
static ABIArgInfo getDirect(mlir::Type ty=nullptr)
Definition: ABIArgInfo.h:56
unsigned getDirectOffset() const
Definition: ABIArgInfo.h:74
Definition: ABIArgInfo.h:22
static bool abiArgInfo()