@@ -18,8 +18,7 @@ VAST_UNRELAX_WARNINGS
18
18
19
19
#include < type_traits>
20
20
21
- namespace vast ::dl
22
- {
21
+ namespace vast ::dl {
23
22
// We are currently using `DLTI` dialect to help encoding data layout information,
24
23
// however in the future custom attributes will be probably preferable.
25
24
// Each entry is mapping `hl::Type -> uint32_t` and in the IR it is encoded as
@@ -30,35 +29,33 @@ namespace vast::dl
30
29
using bitwidth_t = uint32_t ;
31
30
32
31
mlir_type type;
33
- bitwidth_t bw = 0 ;
32
+ bitwidth_t bw = 0 ;
34
33
bitwidth_t abi_align = 0 ;
35
34
36
- DLEntry (mlir_type type, bitwidth_t bw, bitwidth_t abi_align )
37
- : type(type), bw(bw),
38
- abi_align (abi_align)
39
- {}
35
+ DLEntry (mlir_type type, bitwidth_t bw, bitwidth_t abi_align)
36
+ : type(type), bw(bw), abi_align(abi_align) {}
40
37
41
38
DLEntry (mlir_type type, mlir::DictionaryAttr dict_attr)
42
- : type(type),
43
- bw(extract(dict_attr, bw_key())),
44
- abi_align(extract(dict_attr, abi_align_key()))
45
- {}
39
+ : type(type)
40
+ , bw(extract(dict_attr, bw_key()))
41
+ , abi_align(extract(dict_attr, abi_align_key())) {}
46
42
47
43
DLEntry (const mlir::DataLayoutEntryInterface &attr)
48
- : DLEntry(mlir::dyn_cast< mlir_type >(attr.getKey()),
49
- mlir::dyn_cast< mlir::DictionaryAttr >(attr.getValue()))
50
- {
44
+ : DLEntry(
45
+ mlir::dyn_cast< mlir_type >(attr.getKey()),
46
+ mlir::dyn_cast< mlir::DictionaryAttr >(attr.getValue())
47
+ ) {
51
48
VAST_ASSERT (type);
52
49
}
53
50
54
- private:
51
+ private:
55
52
static mlir_type bw_type (mcontext_t &mctx) { return mlir::IntegerType::get (&mctx, 32 ); }
56
53
57
54
static llvm::StringRef bw_key () { return " vast.dl.bw" ; }
55
+
58
56
static llvm::StringRef abi_align_key () { return " vast.abi_align.key" ; }
59
57
60
- static bitwidth_t extract (mlir::DictionaryAttr dict_attr, llvm::StringRef key)
61
- {
58
+ static bitwidth_t extract (mlir::DictionaryAttr dict_attr, llvm::StringRef key) {
62
59
// Defensive check as there is path in ctors that does not guarantee this.
63
60
VAST_ASSERT (dict_attr);
64
61
@@ -69,43 +66,38 @@ namespace vast::dl
69
66
return static_cast < bitwidth_t >(int_attr.getInt ());
70
67
}
71
68
72
- mlir::StringAttr wrap_str (mcontext_t &mctx, llvm::StringRef str_value) const
73
- {
69
+ mlir::StringAttr wrap_str (mcontext_t &mctx, llvm::StringRef str_value) const {
74
70
return mlir::StringAttr::get (&mctx, str_value);
75
71
}
76
72
77
- public:
78
-
79
- mlir::Attribute create_raw_attr (mcontext_t &mctx) const
80
- {
73
+ public:
74
+ mlir::Attribute create_raw_attr (mcontext_t &mctx) const {
81
75
// TODO(lukas): There is `UI64Attr` in `IR/OpBase.td` not sure how to include it
82
76
// though.
83
- auto to_attr = [&](auto what)
84
- {
77
+ auto to_attr = [&](auto what) {
85
78
return mlir::IntegerAttr::get (bw_type (mctx), llvm::APInt (32 , what));
86
79
};
87
80
88
- std::array< mlir::NamedAttribute, 2 > all =
89
- {
90
- mlir::NamedAttribute ( wrap_str ( mctx, bw_key () ), to_attr ( bw ) ),
91
- mlir::NamedAttribute ( wrap_str ( mctx, abi_align_key () ), to_attr ( abi_align ) )
81
+ std::array< mlir::NamedAttribute, 2 > all = {
82
+ mlir::NamedAttribute (wrap_str (mctx, bw_key ()), to_attr (bw)),
83
+ mlir::NamedAttribute (wrap_str (mctx, abi_align_key ()), to_attr (abi_align))
92
84
};
93
85
94
86
return mlir::DictionaryAttr::get (&mctx, all);
95
87
}
96
88
97
89
// Wrap information in this object as `mlir::Attribute`, which is not attached yet
98
90
// to anything.
99
- mlir::DataLayoutEntryInterface wrap (mcontext_t &mctx) const
100
- {
91
+ mlir::DataLayoutEntryInterface wrap (mcontext_t &mctx) const {
101
92
return mlir::DataLayoutEntryAttr::get (type, create_raw_attr (mctx));
102
93
}
103
94
104
95
bool operator ==(const DLEntry &o) const = default ;
105
96
};
106
97
107
98
// For each type remember its data layout information.
108
- struct DataLayoutBlueprint {
99
+ struct DataLayoutBlueprint
100
+ {
109
101
bool try_emplace (mlir_type mty, const clang::Type *aty, const acontext_t &actx) {
110
102
// For other types this should be good-enough for now
111
103
auto info = actx.getTypeInfo (aty);
@@ -114,22 +106,22 @@ namespace vast::dl
114
106
return std::get< 1 >(entries.try_emplace (mty, dl::DLEntry{ mty, bw, abi_align }));
115
107
}
116
108
117
- void add (mlir_type type, dl::DLEntry entry)
118
- {
109
+ void add (mlir_type type, dl::DLEntry entry) {
119
110
auto it = entries.find (type);
120
- if (it != entries.end ())
121
- {
122
- VAST_CHECK (entry == it->second ,
123
- " Insertion of dl::DLEntry would make DLBlueprint inconsistent." );
111
+ if (it != entries.end ()) {
112
+ VAST_CHECK (
113
+ entry == it->second ,
114
+ " Insertion of dl::DLEntry would make DLBlueprint inconsistent."
115
+ );
124
116
}
125
117
entries.try_emplace (type, entry);
126
118
}
127
119
128
- auto wrap (mcontext_t &mctx) const
129
- {
120
+ auto wrap (mcontext_t &mctx) const {
130
121
std::vector< mlir::DataLayoutEntryInterface > flattened;
131
- for (const auto &[_, e] : entries)
122
+ for (const auto &[_, e] : entries) {
132
123
flattened.push_back (e.wrap (mctx));
124
+ }
133
125
return mlir::DataLayoutSpecAttr::get (&mctx, flattened);
134
126
}
135
127
0 commit comments