From 1acc005a262cac3f859fbfaf9c08fbf64587ed9d Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 10:45:12 +0100 Subject: [PATCH 01/10] hl: Add nonnull attribute. --- include/vast/CodeGen/CodeGenAttrVisitor.hpp | 4 ++++ include/vast/Dialect/HighLevel/HighLevelAttributes.td | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/vast/CodeGen/CodeGenAttrVisitor.hpp b/include/vast/CodeGen/CodeGenAttrVisitor.hpp index 316ccc52cf..43bd73c83d 100644 --- a/include/vast/CodeGen/CodeGenAttrVisitor.hpp +++ b/include/vast/CodeGen/CodeGenAttrVisitor.hpp @@ -72,6 +72,10 @@ namespace vast::cg { return make< hl::NoThrowAttr >(); } + mlir_attr VisitNonNullAttr(const clang::NonNullAttr *attr) { + return make< hl::NonNullAttr >(); + } + mlir_attr VisitBuiltinAttr(const clang::BuiltinAttr *attr) { return make< hl::BuiltinAttr >(attr->getID()); } diff --git a/include/vast/Dialect/HighLevel/HighLevelAttributes.td b/include/vast/Dialect/HighLevel/HighLevelAttributes.td index 8b34c4f1d0..f030ee1296 100644 --- a/include/vast/Dialect/HighLevel/HighLevelAttributes.td +++ b/include/vast/Dialect/HighLevel/HighLevelAttributes.td @@ -37,7 +37,8 @@ def NoInstrumentAttr : HighLevel_Attr< "NoInstrumentFunction", "no_instrument_f def PackedAttr : HighLevel_Attr< "Packed", "packed" >; 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 BuiltinAttr : HighLevel_Attr< "Builtin", "builtin" > { let parameters = (ins "unsigned":$ID); From 4826388c96e41c7f3fa06913dcd85c4cafba205e Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 10:52:41 +0100 Subject: [PATCH 02/10] hl: Add const attribute. --- include/vast/CodeGen/CodeGenAttrVisitor.hpp | 4 ++++ include/vast/Dialect/HighLevel/HighLevelAttributes.td | 1 + 2 files changed, 5 insertions(+) diff --git a/include/vast/CodeGen/CodeGenAttrVisitor.hpp b/include/vast/CodeGen/CodeGenAttrVisitor.hpp index 43bd73c83d..a97610c84d 100644 --- a/include/vast/CodeGen/CodeGenAttrVisitor.hpp +++ b/include/vast/CodeGen/CodeGenAttrVisitor.hpp @@ -40,6 +40,10 @@ namespace vast::cg { ); } + mlir_attr VisitConstAttr(const clang::ConstAttr *attr) { + return make< hl::ConstAttr >(); + } + mlir_attr VisitSectionAttr(const clang::SectionAttr *attr) { return make< hl::SectionAttr >(attr->getName()); } diff --git a/include/vast/Dialect/HighLevel/HighLevelAttributes.td b/include/vast/Dialect/HighLevel/HighLevelAttributes.td index f030ee1296..1875a0e667 100644 --- a/include/vast/Dialect/HighLevel/HighLevelAttributes.td +++ b/include/vast/Dialect/HighLevel/HighLevelAttributes.td @@ -32,6 +32,7 @@ class NameAttr def AnnotationAttr : NameAttr< "Annotation", "annotation" >; 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" >; From d75f28106ae8e8a28861c4aea86c0c5c7dec10c5 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 11:02:53 +0100 Subject: [PATCH 03/10] hl: Add alloc align attribute. --- include/vast/CodeGen/CodeGenAttrVisitor.hpp | 4 ++++ include/vast/Dialect/HighLevel/HighLevelAttributes.td | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/include/vast/CodeGen/CodeGenAttrVisitor.hpp b/include/vast/CodeGen/CodeGenAttrVisitor.hpp index a97610c84d..603713e387 100644 --- a/include/vast/CodeGen/CodeGenAttrVisitor.hpp +++ b/include/vast/CodeGen/CodeGenAttrVisitor.hpp @@ -84,6 +84,10 @@ namespace vast::cg { return make< hl::BuiltinAttr >(attr->getID()); } + 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); diff --git a/include/vast/Dialect/HighLevel/HighLevelAttributes.td b/include/vast/Dialect/HighLevel/HighLevelAttributes.td index 1875a0e667..de79a09408 100644 --- a/include/vast/Dialect/HighLevel/HighLevelAttributes.td +++ b/include/vast/Dialect/HighLevel/HighLevelAttributes.td @@ -46,6 +46,12 @@ def BuiltinAttr : HighLevel_Attr< "Builtin", "builtin" > { 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); From 6c7a459b5f08f1492365d73b58066bbea70a1d38 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 11:14:42 +0100 Subject: [PATCH 04/10] hl: Add mode attribute. --- include/vast/CodeGen/CodeGenAttrVisitor.hpp | 4 ++++ .../vast/Dialect/HighLevel/HighLevelAttributes.td | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/vast/CodeGen/CodeGenAttrVisitor.hpp b/include/vast/CodeGen/CodeGenAttrVisitor.hpp index 603713e387..697b7c5ba9 100644 --- a/include/vast/CodeGen/CodeGenAttrVisitor.hpp +++ b/include/vast/CodeGen/CodeGenAttrVisitor.hpp @@ -80,6 +80,10 @@ namespace vast::cg { 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()); } diff --git a/include/vast/Dialect/HighLevel/HighLevelAttributes.td b/include/vast/Dialect/HighLevel/HighLevelAttributes.td index de79a09408..e404665744 100644 --- a/include/vast/Dialect/HighLevel/HighLevelAttributes.td +++ b/include/vast/Dialect/HighLevel/HighLevelAttributes.td @@ -41,6 +41,20 @@ def RestrictAttr : HighLevel_Attr< "Restrict", "restrict" >; def NoThrowAttr : HighLevel_Attr< "NoThrow", "nothrow" >; def NonNullAttr : HighLevel_Attr< "NonNull", "nonnull" >; +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 `>`"; From 668f993f22ce445b294f9c54c2443a1706c4a95f Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 11:17:21 +0100 Subject: [PATCH 05/10] hl: Add pure attribute. --- include/vast/CodeGen/CodeGenAttrVisitor.hpp | 4 ++++ include/vast/Dialect/HighLevel/HighLevelAttributes.td | 1 + 2 files changed, 5 insertions(+) diff --git a/include/vast/CodeGen/CodeGenAttrVisitor.hpp b/include/vast/CodeGen/CodeGenAttrVisitor.hpp index 697b7c5ba9..a9f36df8b8 100644 --- a/include/vast/CodeGen/CodeGenAttrVisitor.hpp +++ b/include/vast/CodeGen/CodeGenAttrVisitor.hpp @@ -64,6 +64,10 @@ namespace vast::cg { 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 >(); } diff --git a/include/vast/Dialect/HighLevel/HighLevelAttributes.td b/include/vast/Dialect/HighLevel/HighLevelAttributes.td index e404665744..5917e21f8a 100644 --- a/include/vast/Dialect/HighLevel/HighLevelAttributes.td +++ b/include/vast/Dialect/HighLevel/HighLevelAttributes.td @@ -36,6 +36,7 @@ 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" >; From 614604b2bd27b16089f283617f5f8f17b4bf2f94 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 11:27:25 +0100 Subject: [PATCH 06/10] hl: Add format attribute. --- include/vast/CodeGen/CodeGenAttrVisitor.hpp | 4 ++++ include/vast/Dialect/HighLevel/HighLevelAttributes.td | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/vast/CodeGen/CodeGenAttrVisitor.hpp b/include/vast/CodeGen/CodeGenAttrVisitor.hpp index a9f36df8b8..0bb5a91b1b 100644 --- a/include/vast/CodeGen/CodeGenAttrVisitor.hpp +++ b/include/vast/CodeGen/CodeGenAttrVisitor.hpp @@ -48,6 +48,10 @@ namespace vast::cg { 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()); } diff --git a/include/vast/Dialect/HighLevel/HighLevelAttributes.td b/include/vast/Dialect/HighLevel/HighLevelAttributes.td index 5917e21f8a..0fb5afbd90 100644 --- a/include/vast/Dialect/HighLevel/HighLevelAttributes.td +++ b/include/vast/Dialect/HighLevel/HighLevelAttributes.td @@ -27,10 +27,11 @@ class NameAttr }]>, ]; - 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" >; From a6c8c2613fe7ee60a796d456174bcd6ddb8510c9 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 11:46:23 +0100 Subject: [PATCH 07/10] hl: Add asm label attribute. --- include/vast/CodeGen/CodeGenAttrVisitor.hpp | 4 ++++ .../vast/Dialect/HighLevel/HighLevelAttributes.td | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/vast/CodeGen/CodeGenAttrVisitor.hpp b/include/vast/CodeGen/CodeGenAttrVisitor.hpp index 0bb5a91b1b..52f739fa5c 100644 --- a/include/vast/CodeGen/CodeGenAttrVisitor.hpp +++ b/include/vast/CodeGen/CodeGenAttrVisitor.hpp @@ -96,6 +96,10 @@ namespace vast::cg { 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()); } diff --git a/include/vast/Dialect/HighLevel/HighLevelAttributes.td b/include/vast/Dialect/HighLevel/HighLevelAttributes.td index 0fb5afbd90..3c0d350845 100644 --- a/include/vast/Dialect/HighLevel/HighLevelAttributes.td +++ b/include/vast/Dialect/HighLevel/HighLevelAttributes.td @@ -43,6 +43,20 @@ def RestrictAttr : HighLevel_Attr< "Restrict", "restrict" >; 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 = [ From 5b45da438da1d133636e4ec8527bb927b4e3292d Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 11:50:33 +0100 Subject: [PATCH 08/10] test: Fix annotation attr syntax. --- test/vast/Dialect/HighLevel/attr-a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/vast/Dialect/HighLevel/attr-a.c b/test/vast/Dialect/HighLevel/attr-a.c index 995e8675e2..5a55521009 100644 --- a/test/vast/Dialect/HighLevel/attr-a.c +++ b/test/vast/Dialect/HighLevel/attr-a.c @@ -6,5 +6,5 @@ typedef unsigned long long u64; # define __nocast __attribute__((annotate("nocast"))) -// CHECK: hl.typedef "cputime_t" {annotate = #hl} : !hl.elaborated> +// CHECK: hl.typedef "cputime_t" {annotate = #hl.annotation<"nocast">} : !hl.elaborated> typedef u64 __nocast cputime_t; From 5bd1884449efdb02bb1abbc5dd79c571c9aaae91 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 13:51:54 +0100 Subject: [PATCH 09/10] test: Add shothand to call vast-opt with high-level simplification passes. --- test/lit.cfg.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/lit.cfg.py b/test/lit.cfg.py index c1ca352bed..f82a2cd7aa 100644 --- a/test/lit.cfg.py +++ b/test/lit.cfg.py @@ -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'), From d89268529d1a0f94f69fb56506a2117f0a8fcb5b Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 1 Nov 2023 13:56:03 +0100 Subject: [PATCH 10/10] hl: Make elaborated type to support MemRefElementTypeInterface. --- include/vast/Dialect/HighLevel/HighLevelTypes.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vast/Dialect/HighLevel/HighLevelTypes.td b/include/vast/Dialect/HighLevel/HighLevelTypes.td index 6226945596..ae2b82a9ef 100644 --- a/include/vast/Dialect/HighLevel/HighLevelTypes.td +++ b/include/vast/Dialect/HighLevel/HighLevelTypes.td @@ -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), [{