Skip to content

Commit a627451

Browse files
committed
util: Format DataLayout.hpp using project config.
1 parent 8ee25ed commit a627451

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed

include/vast/Util/DataLayout.hpp

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ VAST_UNRELAX_WARNINGS
1818

1919
#include <type_traits>
2020

21-
namespace vast::dl
22-
{
21+
namespace vast::dl {
2322
// We are currently using `DLTI` dialect to help encoding data layout information,
2423
// however in the future custom attributes will be probably preferable.
2524
// Each entry is mapping `hl::Type -> uint32_t` and in the IR it is encoded as
@@ -30,35 +29,33 @@ namespace vast::dl
3029
using bitwidth_t = uint32_t;
3130

3231
mlir_type type;
33-
bitwidth_t bw = 0;
32+
bitwidth_t bw = 0;
3433
bitwidth_t abi_align = 0;
3534

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) {}
4037

4138
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())) {}
4642

4743
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+
) {
5148
VAST_ASSERT(type);
5249
}
5350

54-
private:
51+
private:
5552
static mlir_type bw_type(mcontext_t &mctx) { return mlir::IntegerType::get(&mctx, 32); }
5653

5754
static llvm::StringRef bw_key() { return "vast.dl.bw"; }
55+
5856
static llvm::StringRef abi_align_key() { return "vast.abi_align.key"; }
5957

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) {
6259
// Defensive check as there is path in ctors that does not guarantee this.
6360
VAST_ASSERT(dict_attr);
6461

@@ -69,43 +66,38 @@ namespace vast::dl
6966
return static_cast< bitwidth_t >(int_attr.getInt());
7067
}
7168

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 {
7470
return mlir::StringAttr::get(&mctx, str_value);
7571
}
7672

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 {
8175
// TODO(lukas): There is `UI64Attr` in `IR/OpBase.td` not sure how to include it
8276
// though.
83-
auto to_attr = [&](auto what)
84-
{
77+
auto to_attr = [&](auto what) {
8578
return mlir::IntegerAttr::get(bw_type(mctx), llvm::APInt(32, what));
8679
};
8780

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))
9284
};
9385

9486
return mlir::DictionaryAttr::get(&mctx, all);
9587
}
9688

9789
// Wrap information in this object as `mlir::Attribute`, which is not attached yet
9890
// to anything.
99-
mlir::DataLayoutEntryInterface wrap(mcontext_t &mctx) const
100-
{
91+
mlir::DataLayoutEntryInterface wrap(mcontext_t &mctx) const {
10192
return mlir::DataLayoutEntryAttr::get(type, create_raw_attr(mctx));
10293
}
10394

10495
bool operator==(const DLEntry &o) const = default;
10596
};
10697

10798
// For each type remember its data layout information.
108-
struct DataLayoutBlueprint {
99+
struct DataLayoutBlueprint
100+
{
109101
bool try_emplace(mlir_type mty, const clang::Type *aty, const acontext_t &actx) {
110102
// For other types this should be good-enough for now
111103
auto info = actx.getTypeInfo(aty);
@@ -114,22 +106,22 @@ namespace vast::dl
114106
return std::get< 1 >(entries.try_emplace(mty, dl::DLEntry{ mty, bw, abi_align }));
115107
}
116108

117-
void add(mlir_type type, dl::DLEntry entry)
118-
{
109+
void add(mlir_type type, dl::DLEntry entry) {
119110
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+
);
124116
}
125117
entries.try_emplace(type, entry);
126118
}
127119

128-
auto wrap(mcontext_t &mctx) const
129-
{
120+
auto wrap(mcontext_t &mctx) const {
130121
std::vector< mlir::DataLayoutEntryInterface > flattened;
131-
for (const auto &[_, e] : entries)
122+
for (const auto &[_, e] : entries) {
132123
flattened.push_back(e.wrap(mctx));
124+
}
133125
return mlir::DataLayoutSpecAttr::get(&mctx, flattened);
134126
}
135127

0 commit comments

Comments
 (0)