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 missing stdlib high-level attributes. #431

Merged
merged 10 commits into from
Nov 1, 2023
Merged
28 changes: 28 additions & 0 deletions include/vast/CodeGen/CodeGenAttrVisitor.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/CodeGen/CodeGenAttrVisitor.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on include/vast/CodeGen/CodeGenAttrVisitor.hpp

File include/vast/CodeGen/CodeGenAttrVisitor.hpp does not conform to Custom style guidelines. (lines 71, 72)

#pragma once

Expand Down Expand Up @@ -40,10 +40,18 @@
);
}

mlir_attr VisitConstAttr(const clang::ConstAttr *attr) {
return make< hl::ConstAttr >();
}

mlir_attr VisitSectionAttr(const clang::SectionAttr *attr) {
return make< hl::SectionAttr >(attr->getName());
}

mlir_attr VisitFormatAttr(const clang::FormatAttr *attr) {
return make< hl::FormatAttr >(attr->getType()->getName());
}

mlir_attr VisitAnnotateAttr(const clang::AnnotateAttr *attr) {
return make< hl::AnnotationAttr >(attr->getAnnotation());
}
Expand All @@ -60,6 +68,10 @@
return make< hl::PackedAttr >();
}

mlir_attr VisitPureAttr(const clang::PureAttr *attr) {
return make< hl::PureAttr >();
}

mlir_attr VisitWarnUnusedResultAttr(const clang::WarnUnusedResultAttr *attr) {
return make< hl::WarnUnusedResultAttr >();
}
Expand All @@ -72,10 +84,26 @@
return make< hl::NoThrowAttr >();
}

mlir_attr VisitNonNullAttr(const clang::NonNullAttr *attr) {
return make< hl::NonNullAttr >();
}

mlir_attr VisitModeAttr(const clang::ModeAttr *attr) {
return make< hl::ModeAttr >(attr->getMode()->getName());
}

mlir_attr VisitBuiltinAttr(const clang::BuiltinAttr *attr) {
return make< hl::BuiltinAttr >(attr->getID());
}

mlir_attr VisitAsmLabelAttr(const clang::AsmLabelAttr *attr) {
return make< hl::AsmLabelAttr >(attr->getLabel(), attr->getIsLiteralLabel());
}

mlir_attr VisitAllocAlignAttr(const clang::AllocAlignAttr *attr) {
return make< hl::AllocAlignAttr >(attr->getParamIndex().getSourceIndex());
}

mlir_attr VisitAllocSizeAttr(const clang::AllocSizeAttr *attr) {
auto num = attr->getNumElemsParam().isValid() ? attr->getNumElemsParam().getSourceIndex() : int();
return make< hl::AllocSizeAttr >(attr->getElemSizeParam().getSourceIndex(), num);
Expand Down
42 changes: 40 additions & 2 deletions include/vast/Dialect/HighLevel/HighLevelAttributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,61 @@ class NameAttr<string name, string attr_mnemonic>
}]>,
];

let assemblyFormat = "$name";
let assemblyFormat = "`<` $name `>`";
}

def AnnotationAttr : NameAttr< "Annotation", "annotation" >;
def FormatAttr : NameAttr< "Format", "format" >;
def SectionAttr : NameAttr< "Section", "section" >;
def ConstAttr : HighLevel_Attr< "Const", "const" >;
def LoaderUninitAttr : HighLevel_Attr< "LoaderUninitialized", "loader_uninitialized" >;
def NoInstrumentAttr : HighLevel_Attr< "NoInstrumentFunction", "no_instrument_function" >;
def PackedAttr : HighLevel_Attr< "Packed", "packed" >;
def PureAttr : HighLevel_Attr< "Pure", "pure" >;
def WarnUnusedResAttr : HighLevel_Attr< "WarnUnusedResult", "warn_unused_result" >;
def RestrictAttr : HighLevel_Attr< "Restrict", "restrict" >;
def NoThrowAttr : HighLevel_Attr< "NoThrow", "nothrow" >;
def NoThrowAttr : HighLevel_Attr< "NoThrow", "nothrow" >;
def NonNullAttr : HighLevel_Attr< "NonNull", "nonnull" >;

def AsmLabelAttr : HighLevel_Attr< "AsmLabel", "asm" > {
let parameters = (ins "::mlir::StringAttr":$label, "bool":$isLiteral);
let builders = [
AttrBuilderWithInferredContext<(ins "::mlir::StringAttr":$label, "bool":$literal), [{
return get(label.getContext(), label, literal);
}]>,
AttrBuilder<(ins "::mlir::StringRef":$label, "bool":$literal), [{
return get(mlir::StringAttr::get($_ctxt, label), literal);
}]>,
];

let assemblyFormat = "`<` $label `,` $isLiteral `>`";
}

def ModeAttr : HighLevel_Attr< "Mode", "mode" > {
let parameters = (ins "::mlir::StringAttr":$mode);
let builders = [
AttrBuilderWithInferredContext<(ins "::mlir::StringAttr":$mode), [{
return get(mode.getContext(), mode);
}]>,
AttrBuilder<(ins "::mlir::StringRef":$mode), [{
return get(mlir::StringAttr::get($_ctxt, mode));
}]>,
];

let assemblyFormat = "`<` $mode `>`";
}

def BuiltinAttr : HighLevel_Attr< "Builtin", "builtin" > {
let parameters = (ins "unsigned":$ID);
let assemblyFormat = "`<` $ID `>`";
}

def AllocAlignAttr : HighLevel_Attr< "AllocAlign", "alloc_align" >{
let parameters = (ins "int":$alignment);

let assemblyFormat = "`<` $alignment `>`";
}

def AllocSizeAttr : HighLevel_Attr< "AllocSize", "alloc_size" >{
let parameters = (ins "int":$size_arg_pos, OptionalParameter< "int" >:$num_arg_pos);

Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/HighLevel/HighLevelTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def TypedefType : CVRQualifiedType<
}

def ElaboratedType : CVRQualifiedType<
"Elaborated", "elaborated", (ins "Type":$elementType), [ElementTypeInterface]
"Elaborated", "elaborated", (ins "Type":$elementType), [ElementTypeInterface, MemRefElementTypeInterface]
> {
let builders = [
TypeBuilder<(ins "Type":$element), [{
Expand Down
7 changes: 7 additions & 0 deletions test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@

tools = [
ToolSubst('%vast-opt', command = 'vast-opt'),
ToolSubst('%vast-opt-simplify', command = 'vast-opt',
extra_args=[
"--vast-hl-lower-types",
"--vast-hl-dce",
"--vast-hl-lower-typedefs"
]
),
ToolSubst('%vast-cc', command = 'vast-cc'),
ToolSubst('%vast-query', command = 'vast-query'),
ToolSubst('%vast-front', command = 'vast-front'),
Expand Down
2 changes: 1 addition & 1 deletion test/vast/Dialect/HighLevel/attr-a.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ typedef unsigned long long u64;

# define __nocast __attribute__((annotate("nocast")))

// CHECK: hl.typedef "cputime_t" {annotate = #hl<annotation "nocast">} : !hl.elaborated<!hl.typedef<"u64">>
// CHECK: hl.typedef "cputime_t" {annotate = #hl.annotation<"nocast">} : !hl.elaborated<!hl.typedef<"u64">>
typedef u64 __nocast cputime_t;