Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AtomicExpr stub #746

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/vast/CodeGen/DefaultStmtVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace vast::cg {
operation VisitArraySubscriptExpr(const clang::ArraySubscriptExpr *expr);
// operation VisitArrayTypeTraitExpr(const clang::ArrayTypeTraitExpr *expr)
// operation VisitAsTypeExpr(const clang::AsTypeExpr *expr)
// operation VisitAtomicExpr(const clang::AtomicExpr *expr)
operation VisitAtomicExpr(const clang::AtomicExpr *expr);
// operation VisitBlockExpr(const clang::BlockExpr *expr)

// operation VisitCXXBindTemporaryExpr(const clang::CXXBindTemporaryExpr *expr);
Expand Down
22 changes: 22 additions & 0 deletions include/vast/Dialect/HighLevel/HighLevelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1759,4 +1759,26 @@ def HighLevel_GenericSelectionExpr
let assemblyFormat = [{ attr-dict `match` (`region` `:` $control^)? (`type` `:` $controlType^)? $body `->` type($result)}];
}

def HighLevel_AtomicExpr
: HighLevel_Op< "atomic_expr", [NoTerminator] >
, Arguments<(ins StrAttr:$name)>
, Results<(outs Optional< AnyType >:$result)>
{
let summary = "VAST atomic expr";
let description = [{ VAST atomic expr stub}];

let regions = (region VariadicRegion< AnyRegion >:$subexprs);

let skipDefaultBuilders = 1;
let builders = [
OpBuilder<(ins
"llvm::StringRef":$name,
"Type":$rty,
"const std::vector< builder_callback > &":$builders
)>
];

let assemblyFormat = [{ $name attr-dict `:` type($result) $subexprs}];
}

#endif // VAST_DIALECT_HIGHLEVEL_IR_HIGHLEVELOPS
14 changes: 13 additions & 1 deletion lib/vast/CodeGen/DefaultStmtVisitor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/CodeGen/DefaultStmtVisitor.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on lib/vast/CodeGen/DefaultStmtVisitor.cpp

File lib/vast/CodeGen/DefaultStmtVisitor.cpp does not conform to Custom style guidelines. (lines 943, 945)

#include "vast/Util/Warnings.hpp"

Expand Down Expand Up @@ -930,7 +930,19 @@

// operation default_stmt_visitor::VisitArrayTypeTraitExpr(const clang::ArrayTypeTraitExpr *expr)
// operation default_stmt_visitor::VisitAsTypeExpr(const clang::AsTypeExpr *expr)
// operation default_stmt_visitor::VisitAtomicExpr(const clang::AtomicExpr *expr)
operation default_stmt_visitor::VisitAtomicExpr(const clang::AtomicExpr *expr) {
std::vector< builder_callback > subexprs;
for (auto subexpr : expr->children()) {
subexprs.push_back(mk_region_builder(subexpr));
}
return bld.compose< hl::AtomicExpr >()
.bind(self.location(expr))
.bind(expr->getOpAsString())
.bind(visit_maybe_lvalue_result_type(expr))
.bind(subexprs)
.freeze();

}
// operation default_stmt_visitor::VisitBlockExpr(const clang::BlockExpr *expr)

// operation default_stmt_visitor::VisitCXXBindTemporaryExpr(const clang::CXXBindTemporaryExpr *expr) { return {}; }
Expand Down
18 changes: 18 additions & 0 deletions lib/vast/Dialect/HighLevel/HighLevelOps.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Dialect/HighLevel/HighLevelOps.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on lib/vast/Dialect/HighLevel/HighLevelOps.cpp

File lib/vast/Dialect/HighLevel/HighLevelOps.cpp does not conform to Custom style guidelines. (lines 895, 896, 897, 904, 905)

#include "vast/Util/Warnings.hpp"

Expand Down Expand Up @@ -886,6 +886,24 @@
bool GenericSelectionExpr::isTypePredicate() {
return (*this)->hasAttr("matchType");
}

//
// AtomicExpr
//

void AtomicExpr::build(
Builder &bld,
State &st,
llvm::StringRef name,
mlir_type type,
const std::vector< builder_callback > &builders
) {
InsertionGuard guard(bld);
st.addAttribute(getNameAttrName(st.name), bld.getStringAttr(name));
st.addTypes(type);
for (builder_callback_ref builder : builders)
build_region(bld, st, builder);
}
}

//===----------------------------------------------------------------------===//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %vast-front %s -vast-emit-mlir=hl -o - > %t && %vast-opt %t | diff -B %t -

int load(int* p) {
// CHECK: unsup.stmt "AtomicExpr"
// CHECK: hl.atomic_expr "__atomic_load_n" : !hl.int
// CHECK: hl.ref @p
// CHECK: hl.const #core.integer<5>
int q = __atomic_load_n (p, __ATOMIC_SEQ_CST);
Expand Down