From e89fd8d7cf87e41bcec2e27b38df41e4199505a8 Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 11 Sep 2024 17:14:29 +0200 Subject: [PATCH 01/50] hl: Obliterate SSA value frm VarDecl. --- include/vast/CodeGen/ScopeContext.hpp | 15 +++++---------- include/vast/Dialect/HighLevel/HighLevelVar.td | 5 +++-- lib/vast/Dialect/HighLevel/HighLevelOps.cpp | 3 +-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/vast/CodeGen/ScopeContext.hpp b/include/vast/CodeGen/ScopeContext.hpp index cc48f7a69d..e046f519b4 100644 --- a/include/vast/CodeGen/ScopeContext.hpp +++ b/include/vast/CodeGen/ScopeContext.hpp @@ -32,7 +32,7 @@ namespace vast::cg }; using funs_scope_table = scoped_table< string_ref, operation >; - using vars_scope_table = scoped_table< string_ref, mlir_value >; + using vars_scope_table = scoped_table< string_ref, operation >; using types_scope_table = scoped_table< string_ref, operation >; using members_scope_table = scoped_table< string_ref, operation >; using labels_scope_table = scoped_table< string_ref, operation >; @@ -57,7 +57,7 @@ namespace vast::cg operation declare(operation op) { llvm::TypeSwitch< operation >(op) .Case< core::VarSymbolOpInterface >([&] (auto &op) { - symbols.vars.insert(op.getSymbolName(), op->getResult(0)); + symbols.vars.insert(op.getSymbolName(), op); }) .Case< core::TypeSymbolOpInterface >([&] (auto &op) { symbols.types.insert(op.getSymbolName(), op); @@ -90,11 +90,7 @@ namespace vast::cg } } - auto declare_function_param(string_ref name, mlir_value value) { - return symbols.vars.insert(name, value), value; - } - - mlir_value lookup_var(string_ref name) const { + operation lookup_var(string_ref name) const { return symbols.vars.lookup(name); } @@ -190,8 +186,7 @@ namespace vast::cg virtual ~block_scope() = default; - symbol_table_scope< string_ref, mlir_value > vars; - + symbol_table_scope< string_ref, operation > vars; symbol_table_scope< string_ref, operation > types; symbol_table_scope< string_ref, operation > enum_constants; }; @@ -239,7 +234,7 @@ namespace vast::cg symbol_table_scope< string_ref, operation > functions; symbol_table_scope< string_ref, operation > types; - symbol_table_scope< string_ref, mlir_value > globals; + symbol_table_scope< string_ref, operation > globals; symbol_table_scope< string_ref, operation > enum_constants; }; diff --git a/include/vast/Dialect/HighLevel/HighLevelVar.td b/include/vast/Dialect/HighLevel/HighLevelVar.td index 4d6817b51c..402f0967e3 100644 --- a/include/vast/Dialect/HighLevel/HighLevelVar.td +++ b/include/vast/Dialect/HighLevel/HighLevelVar.td @@ -182,11 +182,11 @@ def HighLevel_VarDeclOp let arguments = (ins SymbolNameAttr:$sym_name, + TypeAttr:$type, OptionalAttr:$storageClass, OptionalAttr:$threadStorageClass ); - let results = (outs AnyType:$result); let regions = (region AnyRegion:$initializer, AnyRegion:$allocation_size @@ -203,7 +203,8 @@ def HighLevel_VarDeclOp ]; let assemblyFormat = [{ - $sym_name attr-dict ($storageClass^)? ($threadStorageClass^)? `:` type($result) + $sym_name attr-dict ($storageClass^)? ($threadStorageClass^)? + `:` $type (`=` $initializer^)? (`allocation_size` $allocation_size^)? }]; diff --git a/lib/vast/Dialect/HighLevel/HighLevelOps.cpp b/lib/vast/Dialect/HighLevel/HighLevelOps.cpp index 2cc99c1333..79f9e15abe 100644 --- a/lib/vast/Dialect/HighLevel/HighLevelOps.cpp +++ b/lib/vast/Dialect/HighLevel/HighLevelOps.cpp @@ -345,12 +345,11 @@ namespace vast::hl maybe_builder_callback_ref alloc ) { st.addAttribute(core::symbol_attr_name(), bld.getStringAttr(name)); + st.addAttribute("type", mlir::TypeAttr::get(type)); InsertionGuard guard(bld); build_region(bld, st, init); build_region(bld, st, alloc); - - st.addTypes(type); } void EnumDeclOp::build( From 00247219a4be530abcf01a0feb84864dd654e1f4 Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 11 Sep 2024 17:15:50 +0200 Subject: [PATCH 02/50] hl: Let DeclRef take symbol name instead of SSA value. --- include/vast/Dialect/HighLevel/HighLevelOps.td | 17 ++++++++++++++--- lib/vast/CodeGen/DefaultStmtVisitor.cpp | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/vast/Dialect/HighLevel/HighLevelOps.td b/include/vast/Dialect/HighLevel/HighLevelOps.td index f51a624ce6..88d5849554 100644 --- a/include/vast/Dialect/HighLevel/HighLevelOps.td +++ b/include/vast/Dialect/HighLevel/HighLevelOps.td @@ -449,16 +449,15 @@ def HighLevel_ReturnOp ]; } -// use InferTypeOpInterface def HighLevel_DeclRefOp : HighLevel_Op< "ref" > - , Arguments<(ins AnyType:$decl)> + , Arguments<(ins FlatSymbolRefAttr:$decl)> , Results<(outs HighLevel_LValueOf:$result)> { let summary = "VAST variable reference declaration"; let description = [{ VAST variable reference declaration }]; - let assemblyFormat = "$decl attr-dict `:` functional-type(operands, results)"; + let assemblyFormat = "$decl attr-dict `:` type($result)"; } def HighLevel_FuncRefOp @@ -1548,6 +1547,18 @@ def HighLevel_EmptyDeclOp let assemblyFormat = [{ attr-dict }]; } + +def HighLevel_ParmVarDeclOp + : HighLevel_Op< "param", [Core_VarSymbol] > + , Arguments<(ins SymbolNameAttr:$sym_name, AnyType:$param)> +{ + let summary = "VAST parameter declaration"; + let description = [{ VAST parameter declaration }]; + + let assemblyFormat = "$sym_name `=` $param `:` type($param) attr-dict"; +} + + def HighLevel_AsmOp : HighLevel_Op< "asm", [AttrSizedOperandSegments] > , Arguments<(ins diff --git a/lib/vast/CodeGen/DefaultStmtVisitor.cpp b/lib/vast/CodeGen/DefaultStmtVisitor.cpp index 92ab936de2..fce66f0fc3 100644 --- a/lib/vast/CodeGen/DefaultStmtVisitor.cpp +++ b/lib/vast/CodeGen/DefaultStmtVisitor.cpp @@ -660,7 +660,7 @@ namespace vast::cg return bld.compose< hl::DeclRefOp >() .bind(self.location(expr)) .bind(visit_as_lvalue_type(self, mctx, expr->getType())) - .bind(self.scope.lookup_var(name.value())) + .bind(self.symbol(expr)) .freeze(); } From 089ae647fd5cf74fb98fe8f5fdf77714d4e65617 Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 11 Sep 2024 17:16:47 +0200 Subject: [PATCH 03/50] cg: Declare function param names using ParmVarDeclOp. --- lib/vast/CodeGen/CodeGenFunction.cpp | 4 ++-- lib/vast/CodeGen/DefaultDeclVisitor.cpp | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/vast/CodeGen/CodeGenFunction.cpp b/lib/vast/CodeGen/CodeGenFunction.cpp index 34afef430d..88431c9333 100644 --- a/lib/vast/CodeGen/CodeGenFunction.cpp +++ b/lib/vast/CodeGen/CodeGenFunction.cpp @@ -146,13 +146,13 @@ namespace vast::cg void function_generator::declare_function_params(const clang_function *decl, vast_function fn) { auto *entry_block = fn.addEntryBlock(); auto params = llvm::zip(decl->parameters(), entry_block->getArguments()); + auto _ = bld.scoped_insertion_at_start(entry_block); for (const auto &[param, earg] : params) { // TODO set alignment earg.setLoc(visitor.location(param).value()); if (auto name = visitor.symbol(param)) { - // TODO set name - scope().declare_function_param(name.value(), earg); + visitor.visit(param); } } } diff --git a/lib/vast/CodeGen/DefaultDeclVisitor.cpp b/lib/vast/CodeGen/DefaultDeclVisitor.cpp index 3511be3b58..ca5b85d9d4 100644 --- a/lib/vast/CodeGen/DefaultDeclVisitor.cpp +++ b/lib/vast/CodeGen/DefaultDeclVisitor.cpp @@ -257,22 +257,28 @@ namespace vast::cg { } operation default_decl_visitor::VisitParmVarDecl(const clang::ParmVarDecl *decl) { - if (auto name = self.symbol(decl)) { - if (auto var = self.scope.lookup_var(name.value())) { - return var.getDefiningOp(); - } + auto blk = bld.getInsertionBlock(); + if (auto fn = mlir::dyn_cast< mlir::FunctionOpInterface >(blk->getParentOp())) { + auto param_index = decl->getFunctionScopeIndex(); + return bld.compose< hl::ParmVarDeclOp >() + .bind(self.location(decl)) + .bind(self.symbol(decl)) + .bind(fn.getArgument(param_index)) + .freeze(); } return {}; } - operation - default_decl_visitor::VisitImplicitParamDecl(const clang::ImplicitParamDecl * /* decl */) { + operation default_decl_visitor::VisitImplicitParamDecl( + const clang::ImplicitParamDecl * /* decl */ + ) { return {}; } - operation - default_decl_visitor::VisitLinkageSpecDecl(const clang::LinkageSpecDecl * /* decl */) { + operation default_decl_visitor::VisitLinkageSpecDecl( + const clang::LinkageSpecDecl * /* decl */ + ) { return {}; } From ce91cc1c23d3bccbb4e0f386d823fce60923ee9b Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 10:08:19 +0200 Subject: [PATCH 04/50] test: Update references of ssa values to symbols. --- test/query/users.c | 6 +- test/vast/Conversion/do-while-a.c | 4 +- test/vast/Conversion/do-while-b.c | 4 +- test/vast/Conversion/enum-a.c | 10 +- test/vast/Conversion/enum-b.c | 8 +- test/vast/Conversion/enum-global.c | 4 +- test/vast/Conversion/subscript-b.c | 4 +- test/vast/Dialect/HighLevel/alignof-b.cpp | 4 +- test/vast/Dialect/HighLevel/alignof-d.cpp | 4 +- test/vast/Dialect/HighLevel/array-d.c | 10 +- test/vast/Dialect/HighLevel/array-e.c | 6 +- test/vast/Dialect/HighLevel/asm-b.c | 8 +- test/vast/Dialect/HighLevel/bits-a.c | 6 +- test/vast/Dialect/HighLevel/bits-b.c | 4 +- test/vast/Dialect/HighLevel/cast-a.cpp | 4 +- test/vast/Dialect/HighLevel/class-a.cpp | 2 +- test/vast/Dialect/HighLevel/dowhile-a.cpp | 4 +- test/vast/Dialect/HighLevel/enum-b.c | 4 +- .../Dialect/HighLevel/func-not-prototype-a.c | 2 +- test/vast/Dialect/HighLevel/goto-b.c | 4 +- test/vast/Dialect/HighLevel/ops-a.c | 12 +- test/vast/Dialect/HighLevel/ops-b.c | 60 ++--- test/vast/Dialect/HighLevel/ops-c.c | 50 ++-- test/vast/Dialect/HighLevel/ops-d.c | 4 +- test/vast/Dialect/HighLevel/ops-e.c | 12 +- test/vast/Dialect/HighLevel/ops-h.c | 226 +++++++++--------- test/vast/Dialect/HighLevel/pointers-e.c | 4 +- test/vast/Dialect/HighLevel/pointers-g.c | 4 +- test/vast/Dialect/HighLevel/quirks-j.c | 16 +- test/vast/Dialect/HighLevel/quirks-o.c | 8 +- test/vast/Dialect/HighLevel/ref-a.c | 6 +- test/vast/Dialect/HighLevel/ref-b.c | 10 +- test/vast/Dialect/HighLevel/sizeof-a.c | 6 +- test/vast/Dialect/HighLevel/struct-e.c | 6 +- test/vast/Dialect/HighLevel/switch-a.c | 18 +- test/vast/Dialect/HighLevel/switch-b.cpp | 2 +- test/vast/Dialect/HighLevel/typedef-a.c | 88 +++---- test/vast/Dialect/HighLevel/typedef-b.c | 8 +- test/vast/Dialect/HighLevel/unary-b.c | 6 +- test/vast/Dialect/HighLevel/vars-b.c | 4 +- test/vast/Dialect/HighLevel/vars-c.c | 20 +- test/vast/Dialect/Unsupported/atomicexpr.cpp | 3 +- test/vast/Transform/HL/DCE/for-a.c | 2 +- test/vast/Transform/HL/LowerTypedefs/func-b.c | 2 +- test/vast/Transform/HL/LowerTypedefs/var-a.c | 6 +- test/vast/Transform/HL/LowerTypes/fn-arg-a.c | 9 +- test/vast/Transform/HL/LowerTypes/fn-ptr-a.c | 6 +- test/vast/Transform/HL/LowerTypes/loop.c | 4 +- .../Transform/HL/LowerTypes/struct-access-a.c | 6 +- 49 files changed, 354 insertions(+), 356 deletions(-) diff --git a/test/query/users.c b/test/query/users.c index 12bb830439..727e5d6b6c 100644 --- a/test/query/users.c +++ b/test/query/users.c @@ -12,14 +12,14 @@ // REQUIRES: vast-query -// FOO: hl.ref %0 +// FOO: hl.ref @a int foo() { int a; return a; } -// MAIN: hl.ref %0 -// MAIN: hl.ref %0 +// MAIN: hl.ref @a +// MAIN: hl.ref @b int main() { int a = 1, b = 1; diff --git a/test/vast/Conversion/do-while-a.c b/test/vast/Conversion/do-while-a.c index b8dbd149ab..ecaffae1df 100644 --- a/test/vast/Conversion/do-while-a.c +++ b/test/vast/Conversion/do-while-a.c @@ -7,13 +7,13 @@ // LL_CF: ll.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb2 -// LL_CF: [[V8:%[0-9]+]] = hl.ref [[ARG0]] : (!hl.lvalue) -> !hl.lvalue +// LL_CF: [[V8:%[0-9]+]] = hl.ref [[ARG0]] : !hl.lvalue // LL_CF: [[V9:%[0-9]+]] = hl.implicit_cast [[V8]] LValueToRValue : !hl.lvalue -> si32 // LL_CF: [[V11:%[0-9]+]] = hl.cmp sgt [[V9]], {{.*}} : si32, si32 -> si32 // LL_CF: [[V12:%[0-9]+]] = hl.implicit_cast [[V11]] IntegralCast : si32 -> i1 // LL_CF: ll.cond_scope_ret [[V12]] : i1, ^bb2 // LL_CF: ^bb2: // 2 preds: ^bb0, ^bb1 -// LL_CF: [[V6:%[0-9]+]] = hl.ref [[ARG0]] : (!hl.lvalue) -> !hl.lvalue +// LL_CF: [[V6:%[0-9]+]] = hl.ref [[ARG0]] : !hl.lvalue // LL_CF: {{,*}} = hl.pre.dec [[V6]] : !hl.lvalue -> si32 // LL_CF: ll.br ^bb1 // LL_CF: } diff --git a/test/vast/Conversion/do-while-b.c b/test/vast/Conversion/do-while-b.c index 58db08d01c..38f04d1886 100644 --- a/test/vast/Conversion/do-while-b.c +++ b/test/vast/Conversion/do-while-b.c @@ -12,7 +12,7 @@ // LL_CF: [[B1V8:%[0-9]+]] = hl.implicit_cast [[B1V7]] IntegralCast : si32 -> i1 // LL_CF: ll.cond_scope_ret [[B1V8]] : i1, ^bb2 // LL_CF: ^bb2: // 2 preds: ^bb0, ^bb1 -// LL_CF: [[V4:%[0-9]+]] = hl.ref [[ARG0]] : (!hl.lvalue) -> !hl.lvalue +// LL_CF: [[V4:%[0-9]+]] = hl.ref [[ARG0]] : !hl.lvalue // LL_CF: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> si32 // LL_CF: [[V6:%[0-9]+]] = hl.const #core.integer<42> : si32 // LL_CF: [[V7:%[0-9]+]] = hl.cmp eq [[V5]], [[V6]] : si32, si32 -> si32 @@ -21,7 +21,7 @@ // LL_CF: ^bb3: // pred: ^bb2 // LL_CF: ll.scope_ret // LL_CF: ^bb4: // pred: ^bb2 -// LL_CF: [[V9:%[0-9]+]] = hl.ref [[V3]] : (!hl.lvalue) -> !hl.lvalue +// LL_CF: [[V9:%[0-9]+]] = hl.ref [[V3]] : !hl.lvalue // LL_CF: [[V10:%[0-9]+]] = hl.post.inc [[V9]] : !hl.lvalue -> si32 // LL_CF: ll.br ^bb1 // LL_CF: } diff --git a/test/vast/Conversion/enum-a.c b/test/vast/Conversion/enum-a.c index 926e3b3e14..2c693e1801 100644 --- a/test/vast/Conversion/enum-a.c +++ b/test/vast/Conversion/enum-a.c @@ -11,26 +11,26 @@ enum E : int { // ENUM: hl.func{{.*}} int main() { - // ENUM: {{.*}} = hl.var @a : !hl.lvalue = { + // ENUM: hl.var @a : !hl.lvalue = { // ENUM: {{.*}} = hl.const #core.integer<0> : !hl.int // ENUM: hl.value.yield {{.*}} : !hl.int // ENUM: } int a = E_a; - // ENUM: {{.*}} = hl.var @b : !hl.lvalue = { + // ENUM: hl.var @b : !hl.lvalue = { // ENUM: {{.*}} = hl.const #core.integer<0> : !hl.int // ENUM: hl.value.yield {{.*}} : !hl.int // ENUM: } enum E b = E_a; - // ENUM: {{.*}} = hl.var @c : !hl.lvalue = { + // ENUM: hl.var @c : !hl.lvalue = { // ENUM: {{.*}} = hl.const #core.integer<0> : !hl.int // ENUM: hl.value.yield {{.*}} : !hl.int // ENUM: } enum E c = 0; - // ENUM: {{.*}} = hl.var @d : !hl.lvalue = { - // ENUM: {{.*}} = hl.ref {{.*}} : (!hl.lvalue) -> !hl.lvalue + // ENUM: hl.var @d : !hl.lvalue = { + // ENUM: {{.*}} = hl.ref @a : !hl.lvalue // ENUM: hl.value.yield {{.*}} : !hl.int // ENUM: } enum E d = a; diff --git a/test/vast/Conversion/enum-b.c b/test/vast/Conversion/enum-b.c index 92deae8e1f..c189e8cdb2 100644 --- a/test/vast/Conversion/enum-b.c +++ b/test/vast/Conversion/enum-b.c @@ -14,26 +14,26 @@ enum E id(enum E e) { } int main() { - // ENUM: {{.*}} = hl.var @a : !hl.lvalue = { + // ENUM: hl.var @a : !hl.lvalue = { // ENUM: [[A7:%[0-9]+]] = hl.call @id({{.*}}) : (!hl.char) -> !hl.char // ENUM: hl.value.yield [[A7]] : !hl.char // ENUM: } enum E a = id(E_b); - // ENUM: {{.*}} = hl.var @b : !hl.lvalue = { + // ENUM: hl.var @b : !hl.lvalue = { // ENUM: [[B6:%[0-9]+]] = hl.implicit_cast {{.*}} IntegralCast : !hl.int -> !hl.char // ENUM: [[B7:%[0-9]+]] = hl.call @id([[B6]]) : (!hl.char) -> !hl.char // ENUM: hl.value.yield [[B7]] : !hl.char // ENUM: } enum E b = id(0); - // ENUM: {{.*}} = hl.var @c : !hl.lvalue = { + // ENUM: hl.var @c : !hl.lvalue = { // ENUM: [[C7:%[0-9]+]] = hl.call @id({{.*}}) : (!hl.char) -> !hl.char // ENUM: [[C8:%[0-9]+]] = hl.implicit_cast [[C7]] IntegralCast : !hl.char -> !hl.int // ENUM: hl.value.yield [[C8]] : !hl.int // ENUM: } int c = id(E_b); - // ENUM: {{.*}} = hl.var @d : !hl.lvalue = { + // ENUM: hl.var @d : !hl.lvalue = { // ENUM: [[D6:%[0-9]+]] = hl.implicit_cast {{.*}} IntegralCast : !hl.int -> !hl.char // ENUM: [[D7:%[0-9]+]] = hl.call @id([[D6]]) : (!hl.char) -> !hl.char // ENUM: [[D8:%[0-9]+]] = hl.implicit_cast [[D7]] IntegralCast : !hl.char -> !hl.int diff --git a/test/vast/Conversion/enum-global.c b/test/vast/Conversion/enum-global.c index 8c1a88317b..3a9abeed8b 100644 --- a/test/vast/Conversion/enum-global.c +++ b/test/vast/Conversion/enum-global.c @@ -12,7 +12,7 @@ enum E : char { E_a = 0 }; -// ENUM: {{.*}} = hl.var @a : !hl.lvalue = { +// ENUM: hl.var @a : !hl.lvalue = { // ENUM: [[A2:%[0-9]+]] = hl.const #core.integer<0> : !hl.int // ENUM: [[A3:%[0-9]+]] = hl.implicit_cast [[A2]] IntegralCast : !hl.int -> !hl.char // ENUM: hl.value.yield [[A3]] : !hl.char @@ -26,7 +26,7 @@ enum E a = 0; typedef enum E(*fn_ptr)(enum E); -// ENUM: {{.*}} = hl.var @p : !hl.lvalue) -> (!hl.char)>>>> = { +// ENUM: hl.var @p : !hl.lvalue) -> (!hl.char)>>>> = { // LLVM: llvm.mlir.global internal constant @p() {{.*}} : !llvm.ptr { // LLVM: [[P1:%[0-9]+]] = llvm.mlir.zero : !llvm.ptr diff --git a/test/vast/Conversion/subscript-b.c b/test/vast/Conversion/subscript-b.c index 9a863e29aa..2d7a6cc08a 100644 --- a/test/vast/Conversion/subscript-b.c +++ b/test/vast/Conversion/subscript-b.c @@ -2,10 +2,10 @@ // RUN: %check-lower-value-categories %s | %file-check %s -check-prefix=VAL_CAT // RUN: %check-core-to-llvm %s | %file-check %s -check-prefix=C_LLVM -// STD_TYPES: {{.*}} = hl.var @arr1 : !hl.lvalue> = { +// STD_TYPES: hl.var @arr1 : !hl.lvalue> = { -// VAL_CAT: {{.*}} = hl.var @arr1 : !hl.ptr> = { +// VAL_CAT: hl.var @arr1 : !hl.ptr> = { // VAL_CAT: hl.value.yield {{.*}} : !hl.array<3, si32> diff --git a/test/vast/Dialect/HighLevel/alignof-b.cpp b/test/vast/Dialect/HighLevel/alignof-b.cpp index f799f7d9fe..e6f28ba598 100644 --- a/test/vast/Dialect/HighLevel/alignof-b.cpp +++ b/test/vast/Dialect/HighLevel/alignof-b.cpp @@ -5,11 +5,11 @@ int main() { // CHECK: hl.alignof.type !hl.int -> !hl.long< unsigned > unsigned long si = alignof(int); - // CHECK: [[V1:%[0-9]+]] = hl.var @v : !hl.lvalue + // CHECK: hl.var @v : !hl.lvalue int v; // CHECK: hl.var @sv : !hl.lvalue> // CHECK: hl.alignof.expr -> !hl.long< unsigned > - // CHECK: hl.ref [[V1]] + // CHECK: hl.ref @v unsigned long sv = alignof v; } diff --git a/test/vast/Dialect/HighLevel/alignof-d.cpp b/test/vast/Dialect/HighLevel/alignof-d.cpp index 82edc46c44..91708f5a7c 100644 --- a/test/vast/Dialect/HighLevel/alignof-d.cpp +++ b/test/vast/Dialect/HighLevel/alignof-d.cpp @@ -5,11 +5,11 @@ int main() { // CHECK: hl.preferred_alignof.type !hl.int -> !hl.long< unsigned > unsigned long si = __alignof__(int); - // CHECK: [[V1:%[0-9]+]] = hl.var @v : !hl.lvalue + // CHECK: hl.var @v : !hl.lvalue int v; // CHECK: hl.var @sv : !hl.lvalue> // CHECK: hl.preferred_alignof.expr -> !hl.long< unsigned > - // CHECK: hl.ref [[V1]] + // CHECK: hl.ref @v unsigned long sv = __alignof__ v; } diff --git a/test/vast/Dialect/HighLevel/array-d.c b/test/vast/Dialect/HighLevel/array-d.c index a295064eb7..d39c573346 100644 --- a/test/vast/Dialect/HighLevel/array-d.c +++ b/test/vast/Dialect/HighLevel/array-d.c @@ -4,22 +4,22 @@ // TODO decl.ref registers int main() { - // CHECK: [[ARR:%[0-9]+]] = hl.var @arr : !hl.lvalue> + // CHECK: hl.var @arr : !hl.lvalue> int arr[3]; // CHECK: hl.var @v0 : !hl.lvalue = { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[ARR]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @arr // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] ArrayToPointerDecay : !hl.lvalue> -> !hl.ptr // CHECK: [[V3:%[0-9]+]] = hl.const #core.integer<0> : !hl.int // CHECK: hl.subscript [[V2]] at {{.*}}[[V3]] : !hl.int] : !hl.ptr -> !hl.lvalue // CHECK: } int v0 = arr[0]; - // CHECK: [[IDX:%[0-9]+]] = hl.var @idx : !hl.lvalue + // CHECK: hl.var @idx : !hl.lvalue int idx = 2; // CHECK: hl.var @v2 : !hl.lvalue = { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[ARR]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @arr // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] ArrayToPointerDecay : !hl.lvalue> -> !hl.ptr - // CHECK: [[V3:%[0-9]+]] = hl.ref [[IDX]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @idx // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.subscript [[V2]] at {{.*}}[[V4]] : !hl.int] : !hl.ptr -> !hl.lvalue // CHECK: } diff --git a/test/vast/Dialect/HighLevel/array-e.c b/test/vast/Dialect/HighLevel/array-e.c index 9d14be185b..7cc09fc402 100644 --- a/test/vast/Dialect/HighLevel/array-e.c +++ b/test/vast/Dialect/HighLevel/array-e.c @@ -3,7 +3,7 @@ void foo(int size) { // CHECK: hl.var @arr : !hl.lvalue> allocation_size { - // CHECK: hl.ref %arg0 + // CHECK: hl.ref @size int arr[size]; } @@ -17,10 +17,10 @@ void bar() { void baz(int x) { // CHECK: hl.var @Y : !hl.lvalue> allocation_size - // CHECK: hl.ref %arg0 + // CHECK: hl.ref @x int Y[x]; ++x; // CHECK: hl.var @Z : !hl.lvalue> allocation_size - // CHECK: hl.ref %arg0 + // CHECK: hl.ref @x int Z[x]; } diff --git a/test/vast/Dialect/HighLevel/asm-b.c b/test/vast/Dialect/HighLevel/asm-b.c index c38e20fc86..d35d058b13 100644 --- a/test/vast/Dialect/HighLevel/asm-b.c +++ b/test/vast/Dialect/HighLevel/asm-b.c @@ -3,11 +3,11 @@ void f() { int src = 1; -// CHECK: [[SRC:%[0-9]+]] = hl.var @src +// CHECK: hl.var @src int dst; -// CHECK: [[DST:%[0-9]+]] = hl.var @dst -// CHECK: [[DST_REF:%[0-9]+]] = hl.ref [[DST]] -// CHECK: [[SRC_REF:%[0-9]+]] = hl.ref [[SRC]] +// CHECK: hl.var @dst +// CHECK: [[DST_REF:%[0-9]+]] = hl.ref @dst +// CHECK: [[SRC_REF:%[0-9]+]] = hl.ref @src // CHECK: [[CAST_SRC:%[0-9]+]] = hl.implicit_cast [[SRC_REF]] // CHECK: hl.asm {is_volatile} "mov %w1, %w0\0A\09add $1, %w0"([0] [[DST_REF]] : ["=r"]) (ins : [1] [[CAST_SRC]] : ["r"]) () () : (!hl.lvalue, !hl.int) -> () asm inline volatile ("mov %w1, %w0\n\t" diff --git a/test/vast/Dialect/HighLevel/bits-a.c b/test/vast/Dialect/HighLevel/bits-a.c index 89d93918d2..2db7f51abc 100644 --- a/test/vast/Dialect/HighLevel/bits-a.c +++ b/test/vast/Dialect/HighLevel/bits-a.c @@ -6,7 +6,7 @@ // CHECK: @sign1 {{.*}} ([[A1:%arg[0-9]+]]: !hl.lvalue) -> !hl.int int sign1(int v) { // CHECK: [[V0:%[0-9]+]] = hl.expr : !hl.int - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @v // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V3:%[0-9]+]] = hl.const #core.integer<0> : !hl.int // CHECK: [[V4:%[0-9]+]] = hl.cmp slt [[V2]], [[V3]] : !hl.int, !hl.int -> !hl.int @@ -18,7 +18,7 @@ int sign1(int v) { int sign2(int v) { // CHECK: hl.expr : !hl.int< unsigned > // CHECK: hl.expr : !hl.int - // CHECK: hl.ref [[A1]] + // CHECK: hl.ref @v // CHECK: hl.cstyle_cast [[X:%[0-9]+]] NoOp : !hl.int -> !hl.int // CHECK: hl.cstyle_cast [[Y:%[0-9]+]] IntegralCast : !hl.int -> !hl.int< unsigned > // CHECK: hl.expr : !hl.long< unsigned > @@ -34,7 +34,7 @@ int sign2(int v) { // CHECK: @sign3 {{.*}} ([[A1:%arg[0-9]+]]: !hl.lvalue>) -> !hl.int int sign3(unsigned long v) { - // CHECK: [[V0:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V0:%[0-9]+]] = hl.ref @v // CHECK: [[V1:%[0-9]+]] = hl.implicit_cast [[V0]] // CHECK: [[V2:%[0-9]+]] = hl.expr : !hl.long< unsigned > // CHECK: hl.sizeof.type !hl.int -> !hl.long< unsigned > diff --git a/test/vast/Dialect/HighLevel/bits-b.c b/test/vast/Dialect/HighLevel/bits-b.c index 3c8d8985cd..174cca07c2 100644 --- a/test/vast/Dialect/HighLevel/bits-b.c +++ b/test/vast/Dialect/HighLevel/bits-b.c @@ -5,8 +5,8 @@ _Bool oposite_signs(int x, int y) { // CHECK: hl.expr : !hl.int // CHECK: hl.expr : !hl.int - // CHECK: hl.ref [[A1]] - // CHECK: hl.ref [[A2]] + // CHECK: hl.ref @x + // CHECK: hl.ref @y // CHECK: hl.bin.xor // CHECK: hl.const #core.integer<0> : !hl.int // CHECK: hl.cmp slt diff --git a/test/vast/Dialect/HighLevel/cast-a.cpp b/test/vast/Dialect/HighLevel/cast-a.cpp index 8096229703..5e3d467af3 100644 --- a/test/vast/Dialect/HighLevel/cast-a.cpp +++ b/test/vast/Dialect/HighLevel/cast-a.cpp @@ -5,10 +5,10 @@ void cast_cstyle() { int i = 0; - // CHECK: [[I:%[0-9]+]] = hl.var @i : !hl.lvalue + // CHECK: hl.var @i : !hl.lvalue short s = (short)i; // CHECK: hl.var @s : !hl.lvalue - // CHECK: [[V1:%[0-9]+]] = hl.ref [[I]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @i // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.int -> !hl.short // CHECK: [[V4:%[0-9]+]] = hl.cstyle_cast [[V3]] NoOp : !hl.short -> !hl.short diff --git a/test/vast/Dialect/HighLevel/class-a.cpp b/test/vast/Dialect/HighLevel/class-a.cpp index 34fa265120..c4db5c1307 100644 --- a/test/vast/Dialect/HighLevel/class-a.cpp +++ b/test/vast/Dialect/HighLevel/class-a.cpp @@ -19,6 +19,6 @@ class C : public A, protected virtual B { // CHECK: hl.field @x : !hl.int int x; - // CHECK: %0 = hl.var @C::y sc_static : !hl.lvalue + // CHECK: hl.var @C::y sc_static : !hl.lvalue static int y; }; diff --git a/test/vast/Dialect/HighLevel/dowhile-a.cpp b/test/vast/Dialect/HighLevel/dowhile-a.cpp index 2a392a693f..9691c34ee9 100644 --- a/test/vast/Dialect/HighLevel/dowhile-a.cpp +++ b/test/vast/Dialect/HighLevel/dowhile-a.cpp @@ -14,10 +14,10 @@ void basic() { // CHECK-LABEL: hl.func @_Z10inner_condv void inner_cond() { - // CHECK: [[I:%[0-9]+]] = hl.var @i : !hl.lvalue + // CHECK: hl.var @i : !hl.lvalue int i = 0; // CHECK: hl.do { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[I]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @i // CHECK: hl.post.inc [[V1]] do { i++; diff --git a/test/vast/Dialect/HighLevel/enum-b.c b/test/vast/Dialect/HighLevel/enum-b.c index 77abfbef8f..ba71b985d0 100644 --- a/test/vast/Dialect/HighLevel/enum-b.c +++ b/test/vast/Dialect/HighLevel/enum-b.c @@ -10,7 +10,7 @@ int main() { // CHECK: hl.enum.const @BLUE = #core.integer<2> : !hl.int // CHECK: } - // CHECK: [[VAR:%[0-9]+]] = hl.var @r : !hl.lvalue>> = { + // CHECK: hl.var @r : !hl.lvalue>> = { // CHECK: [[V1:%[0-9]+]] = hl.enumref @RED : !hl.int // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] IntegralCast : !hl.int -> !hl.elaborated> // CHECK: hl.value.yield [[V2]] : !hl.elaborated> @@ -18,7 +18,7 @@ int main() { enum color { RED, GREEN, BLUE } r = RED; // CHECK: hl.switch - // CHECK: hl.ref [[VAR]] + // CHECK: hl.ref @r switch(r) { // CHECK: hl.case // CHECK: hl.enumref @RED : !hl.int diff --git a/test/vast/Dialect/HighLevel/func-not-prototype-a.c b/test/vast/Dialect/HighLevel/func-not-prototype-a.c index 2b5d619a6e..7851e22515 100644 --- a/test/vast/Dialect/HighLevel/func-not-prototype-a.c +++ b/test/vast/Dialect/HighLevel/func-not-prototype-a.c @@ -4,7 +4,7 @@ // CHECK: hl.func @foo external ([[ARG1:%[a-z0-9]+]]: !hl.lvalue) int foo(); int foo(int x) { -// CHECK: hl.ref [[ARG1]] +// CHECK: hl.ref @x if (x != 0) { return 1; } diff --git a/test/vast/Dialect/HighLevel/goto-b.c b/test/vast/Dialect/HighLevel/goto-b.c index 0d5f527d4d..b7d4079773 100644 --- a/test/vast/Dialect/HighLevel/goto-b.c +++ b/test/vast/Dialect/HighLevel/goto-b.c @@ -3,7 +3,7 @@ void foo(int test) { - // CHECK: [[PTR:%[0-9]+]] = hl.var + // CHECK: hl.var void *ptr; if (test) @@ -14,7 +14,7 @@ void foo(int test) { ptr = &&bar; // CHECK: hl.indirect_goto : { - // CHECK: hl.ref [[PTR]] + // CHECK: hl.ref @ptr // CHECK: } goto *ptr; diff --git a/test/vast/Dialect/HighLevel/ops-a.c b/test/vast/Dialect/HighLevel/ops-a.c index e3b988a584..9471ab565b 100644 --- a/test/vast/Dialect/HighLevel/ops-a.c +++ b/test/vast/Dialect/HighLevel/ops-a.c @@ -4,9 +4,9 @@ // CHECK: hl.func @add1 {{.*}} ([[A1:%arg[0-9]+]]: !hl.lvalue, [[A2:%arg[0-9]+]]: !hl.lvalue) -> !hl.int int add1(int a, int b) { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.add [[V2]], [[V4]] : (!hl.int, !hl.int) -> !hl.int return a + b; @@ -15,16 +15,16 @@ int add1(int a, int b) // CHECK: hl.func @add2 {{.*}} ([[A1:%arg[0-9]+]]: !hl.lvalue, [[A2:%arg[0-9]+]]: !hl.lvalue) -> !hl.int int add2(int a, int b) { - // CHECK: [[R:%[0-9]+]] = hl.var @r : !hl.lvalue = { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @r : !hl.lvalue = { + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.add [[V2]], [[V4]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.value.yield [[V5]] int r = a + b; - // CHECK: [[V7:%[0-9]+]] = hl.ref [[R]] + // CHECK: [[V7:%[0-9]+]] = hl.ref @r // CHECK: [[V8:%[0-9]+]] = hl.implicit_cast [[V7]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: return [[V8]] : !hl.int return r; diff --git a/test/vast/Dialect/HighLevel/ops-b.c b/test/vast/Dialect/HighLevel/ops-b.c index 0b5bedc8df..4e57ab45a7 100644 --- a/test/vast/Dialect/HighLevel/ops-b.c +++ b/test/vast/Dialect/HighLevel/ops-b.c @@ -5,43 +5,43 @@ void arithemtic_signed(int a, int b) { int c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.add [[V2]], [[V4]] // CHECK: hl.assign [[V5]] to [[CR]] : !hl.int c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.sub [[V2]], [[V4]] // CHECK: hl.assign [[V5]] to [[CR]] : !hl.int c = a - b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.mul [[V2]], [[V4]] // CHECK: hl.assign [[V5]] to [[CR]] : !hl.int c = a * b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.sdiv [[V2]], [[V4]] // CHECK: hl.assign [[V5]] to [[CR]] : !hl.int c = a / b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.srem [[V2]], [[V4]] // CHECK: hl.assign [[V5]] to [[CR]] : !hl.int @@ -60,28 +60,28 @@ void arithemtic_unsigned(unsigned a, unsigned b) // CHECK: hl.func @assign_signed {{.*}} ([[A1:%arg[0-9]+]]: !hl.lvalue, [[A2:%arg[0-9]+]]: !hl.lvalue) void assign_signed(int a, int b) { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] - // CHECK: [[V2:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.assign.add [[V3]] to [[V1]] : !hl.int a += b; - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] - // CHECK: [[V2:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.assign.sub [[V3]] to [[V1]] : !hl.int a -= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] - // CHECK: [[V2:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.assign.mul [[V3]] to [[V1]] : !hl.int a *= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] - // CHECK: [[V2:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.assign.sdiv [[V3]] to [[V1]] : !hl.int a /= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] - // CHECK: [[V2:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.assign.srem [[V3]] to [[V1]] : !hl.int a %= b; @@ -90,13 +90,13 @@ void assign_signed(int a, int b) // CHECK: hl.func @assign_unsigned {{.*}} ([[A1:%arg[0-9]+]]: !hl.lvalue>, [[A2:%arg[0-9]+]]: !hl.lvalue>) void assign_unsigned(unsigned a, unsigned b) { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] - // CHECK: [[V2:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue> -> !hl.int< unsigned > // CHECK: hl.assign.udiv [[V3]] to [[V1]] : !hl.int< unsigned > a /= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] - // CHECK: [[V2:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue> -> !hl.int< unsigned > // CHECK: hl.assign.urem [[V3]] to [[V1]] : !hl.int< unsigned > a %= b; diff --git a/test/vast/Dialect/HighLevel/ops-c.c b/test/vast/Dialect/HighLevel/ops-c.c index 94a8b359fb..d6c59a60b4 100644 --- a/test/vast/Dialect/HighLevel/ops-c.c +++ b/test/vast/Dialect/HighLevel/ops-c.c @@ -2,95 +2,95 @@ // RUN: %vast-cc1 -vast-emit-mlir=hl %s -o %t && %vast-opt %t | diff -B %t - void bit_ops(int a, int b) { - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] - // CHECK: [[V3:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] // CHECK: hl.bin.shl [[V2]], [[V4]] int shl = a << b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] - // CHECK: [[V3:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] // CHECK: hl.bin.ashr [[V2]], [[V4]] int shr = a >> b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] - // CHECK: [[V3:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] // CHECK: hl.bin.xor [[V2]], [[V4]] int xor = a ^ b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] - // CHECK: [[V3:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] // CHECK: hl.bin.or [[V2]], [[V4]] int or = a | b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] - // CHECK: [[V3:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] // CHECK: hl.bin.and [[V2]], [[V4]] int and = a & b; // CHECK: hl.bin.land { - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[A:%[0-9]+]] : !hl.int // CHECK: }, { - // CHECK: [[V3:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] // CHECK: hl.value.yield [[B:%[0-9]+]] : !hl.int // CHECK: } : !hl.int int land = a && b; // CHECK: hl.bin.lor { - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[A:%[0-9]+]] : !hl.int // CHECK: }, { - // CHECK: [[V3:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] // CHECK: hl.value.yield [[B:%[0-9]+]] : !hl.int // CHECK: } : !hl.int int lor = a || b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.not [[V2]] int not = ~a; } void bit_assign_ops(int a, int b) { - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 - // CHECK: [[V2:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V2]] // CHECK: hl.assign.bin.shl [[V4]] to [[V1]] a <<= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 - // CHECK: [[V2:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V2]] // CHECK: hl.assign.bin.ashr [[V4]] to [[V1]] a >>= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 - // CHECK: [[V2:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V2]] // CHECK: hl.assign.bin.xor [[V4]] to [[V1]] a ^= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 - // CHECK: [[V2:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V2]] // CHECK: hl.assign.bin.or [[V4]] to [[V1]] a |= b; - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 - // CHECK: [[V2:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a + // CHECK: [[V2:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V2]] // CHECK: hl.assign.bin.and [[V4]] to [[V1]] a &= b; diff --git a/test/vast/Dialect/HighLevel/ops-d.c b/test/vast/Dialect/HighLevel/ops-d.c index 4779c2e752..ef35dd0147 100644 --- a/test/vast/Dialect/HighLevel/ops-d.c +++ b/test/vast/Dialect/HighLevel/ops-d.c @@ -3,13 +3,13 @@ void unary_inplace(int a) { // CHECK: hl.var @pre : !hl.lvalue - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.pre.inc [[V1]] : !hl.lvalue -> !hl.int // CHECK: hl.value.yield [[V2]] : !hl.int int pre = ++a; // CHECK: hl.var @post : !hl.lvalue - // CHECK: [[V1:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.post.inc [[V1]] : !hl.lvalue -> !hl.int // CHECK: hl.value.yield [[V2]] : !hl.int int post = a++; diff --git a/test/vast/Dialect/HighLevel/ops-e.c b/test/vast/Dialect/HighLevel/ops-e.c index d8dc8a5759..4403dcb4cd 100644 --- a/test/vast/Dialect/HighLevel/ops-e.c +++ b/test/vast/Dialect/HighLevel/ops-e.c @@ -3,14 +3,14 @@ void assign_assign() { int a, b, c; - // CHECK: [[A:%[0-9]+]] = hl.var @a : !hl.lvalue - // CHECK: [[B:%[0-9]+]] = hl.var @b : !hl.lvalue - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue + // CHECK: hl.var @a : !hl.lvalue + // CHECK: hl.var @b : !hl.lvalue + // CHECK: hl.var @c : !hl.lvalue - // CHECK: [[RA:%[0-9]+]] = hl.ref [[A]] + // CHECK: [[RA:%[0-9]+]] = hl.ref @a // CHECK: [[V1:%[0-9]+]] = hl.expr - // CHECK: [[RB:%[0-9]+]] = hl.ref [[B]] - // CHECK: [[RC:%[0-9]+]] = hl.ref [[C]] + // CHECK: [[RB:%[0-9]+]] = hl.ref @b + // CHECK: [[RC:%[0-9]+]] = hl.ref @c // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[RC]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[VA:%[0-9]+]] = hl.assign [[V2]] to [[RB]] : !hl.int // CHECK: [[VA:%[0-9]+]] = hl.assign [[V1]] to [[RA]] : !hl.int diff --git a/test/vast/Dialect/HighLevel/ops-h.c b/test/vast/Dialect/HighLevel/ops-h.c index 7667410ff1..de94e09579 100644 --- a/test/vast/Dialect/HighLevel/ops-h.c +++ b/test/vast/Dialect/HighLevel/ops-h.c @@ -5,93 +5,93 @@ void arithemtic_int_short(int a, short b) { int c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.add [[V2]], [[V5]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.add [[V5]], [[V4]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = b + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.sub [[V2]], [[V5]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = a - b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.sub [[V5]], [[V4]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = b - a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.mul [[V2]], [[V5]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = a * b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.mul [[V5]], [[V4]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = b * a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V2]], [[V5]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = a / b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V5]], [[V4]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = b / a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.srem [[V2]], [[V5]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int c = a % b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.srem [[V5]], [[V4]] : (!hl.int, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int @@ -101,92 +101,92 @@ void arithemtic_int_short(int a, short b) void arithemtic_int_long(int a, long b) { long c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.int -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.add [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.int -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.add [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.int -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sub [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a - b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.int -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sub [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b - a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.int -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.mul [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a * b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.int -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.mul [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b * a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.int -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a / b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.int -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b / a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.int -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.srem [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a % b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.int -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.srem [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long @@ -197,92 +197,92 @@ void arithemtic_int_long(int a, long b) void arithemtic_short_long(short a, long b) { long c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.add [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.add [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sub [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a - b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sub [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b - a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.mul [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a * b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.mul [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b * a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a / b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = b / a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.long - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @b // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.srem [[V3]], [[V5]] : (!hl.long, !hl.long) -> !hl.long // CHECK: hl.assign [[V6]] to [[CR]] : !hl.long c = a % b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.long // CHECK: [[V6:%[0-9]+]] = hl.srem [[V2]], [[V5]] : (!hl.long, !hl.long) -> !hl.long @@ -293,29 +293,29 @@ void arithemtic_short_long(short a, long b) void arithemtic_pointer_short(int* a, short b) { int* c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue> - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue> + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue> -> !hl.ptr - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.add [[V2]], [[V5]] : (!hl.ptr, !hl.int) -> !hl.ptr // CHECK: hl.assign [[V6]] to [[CR]] : !hl.ptr c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.short -> !hl.int - // CHECK: [[V4:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V4:%[0-9]+]] = hl.ref @a // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue> -> !hl.ptr // CHECK: [[V6:%[0-9]+]] = hl.add [[V3]], [[V5]] : (!hl.int, !hl.ptr) -> !hl.ptr // CHECK: hl.assign [[V6]] to [[CR]] : !hl.ptr c = b + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue> -> !hl.ptr - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.short // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.short -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.sub [[V2]], [[V5]] : (!hl.ptr, !hl.int) -> !hl.ptr @@ -326,27 +326,27 @@ void arithemtic_pointer_short(int* a, short b) void arithemtic_pointer_long(int* a, long b) { int* c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue> - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue> + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue> -> !hl.ptr - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V5:%[0-9]+]] = hl.add [[V2]], [[V4]] : (!hl.ptr, !hl.long) -> !hl.ptr // CHECK: hl.assign [[V5]] to [[CR]] : !hl.ptr c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue> -> !hl.ptr // CHECK: [[V5:%[0-9]+]] = hl.add [[V2]], [[V4]] : (!hl.long, !hl.ptr) -> !hl.ptr // CHECK: hl.assign [[V5]] to [[CR]] : !hl.ptr c = b + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue> -> !hl.ptr - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V5:%[0-9]+]] = hl.sub [[V2]], [[V4]] : (!hl.ptr, !hl.long) -> !hl.ptr // CHECK: hl.assign [[V5]] to [[CR]] : !hl.ptr diff --git a/test/vast/Dialect/HighLevel/pointers-e.c b/test/vast/Dialect/HighLevel/pointers-e.c index fb1c56a0c5..387d28aac3 100644 --- a/test/vast/Dialect/HighLevel/pointers-e.c +++ b/test/vast/Dialect/HighLevel/pointers-e.c @@ -4,7 +4,7 @@ int f(); int main() { - // CHECK: [[FP:%[0-9]+]] = hl.var @p : !hl.lvalue (!hl.int)>>>> + // CHECK: hl.var @p : !hl.lvalue (!hl.int)>>>> // CHECK: hl.funcref @f : !core.fn<() -> (!hl.int)> // CHECK: FunctionToPointerDecay : !core.fn<() -> (!hl.int)> -> !hl.ptr (!hl.int)>> int (*p)() = f; // pointer p is pointing to f @@ -14,7 +14,7 @@ int main() { // CHECK: hl.indirect_call [[P]] : !hl.ptr (!hl.int)>>>() : () -> !hl.int (*p)(); // function f invoked through the function designator - // CHECK: [[R:%[0-9]+]] = hl.ref [[FP]] + // CHECK: [[R:%[0-9]+]] = hl.ref @p // CHECK: [[F:%[0-9]+]] = hl.implicit_cast [[R]] LValueToRValue // CHECK: hl.indirect_call [[F]] : !hl.ptr (!hl.int)>>>() : () -> !hl.int p(); // function f invoked directly through the pointer diff --git a/test/vast/Dialect/HighLevel/pointers-g.c b/test/vast/Dialect/HighLevel/pointers-g.c index e7d3477d47..913564c21e 100644 --- a/test/vast/Dialect/HighLevel/pointers-g.c +++ b/test/vast/Dialect/HighLevel/pointers-g.c @@ -2,9 +2,9 @@ // RUN: %vast-cc1 -vast-emit-mlir=hl %s -o %t && %vast-opt %t | diff -B %t - int main() { - // CHECK: [[N:%[0-9]+]] = hl.var @n : !hl.lvalue + // CHECK: hl.var @n : !hl.lvalue // CHECK: hl.var @p : !hl.lvalue> - // CHECK: [[R:%[0-9]+]] = hl.ref [[N]] + // CHECK: [[R:%[0-9]+]] = hl.ref @n // CHECK: hl.addressof [[R]] : !hl.lvalue -> !hl.ptr int n = 1, *p = &n; // CHECK: hl.var @pv : !hl.lvalue> diff --git a/test/vast/Dialect/HighLevel/quirks-j.c b/test/vast/Dialect/HighLevel/quirks-j.c index 4de63d73e7..6fad365314 100644 --- a/test/vast/Dialect/HighLevel/quirks-j.c +++ b/test/vast/Dialect/HighLevel/quirks-j.c @@ -10,23 +10,23 @@ struct bitfield { }; void foo() { - // CHECK: [[A:%[0-9]+]] = hl.var @a : !hl.lvalue> + // CHECK: hl.var @a : !hl.lvalue> int a[2]; - // CHECK: [[I:%[0-9]+]] = hl.var @i : !hl.lvalue + // CHECK: hl.var @i : !hl.lvalue int i; - // CHECK: [[J:%[0-9]+]] = hl.var @j : !hl.lvalue> + // CHECK: hl.var @j : !hl.lvalue> const int j; - //CHECK: [[BF:%[0-9]+]] = hl.var @bf : !hl.lvalue>> + // CHECK: hl.var @bf : !hl.lvalue>> struct bitfield bf; // these are all lvalues - // CHECK: hl.ref [[A]] + // CHECK: hl.ref @a a; - // CHECK: hl.ref [[I]] + // CHECK: hl.ref @i i; - // CHECK: hl.ref [[J]] + // CHECK: hl.ref @j j; - // CHECK: [[R:%[0-9]+]] = hl.ref [[BF]] + // CHECK: [[R:%[0-9]+]] = hl.ref @bf // CHECK: hl.member [[R]] at @x : !hl.lvalue>> -> !hl.lvalue> bf.x; diff --git a/test/vast/Dialect/HighLevel/quirks-o.c b/test/vast/Dialect/HighLevel/quirks-o.c index 0da4775d39..5528ad86f7 100644 --- a/test/vast/Dialect/HighLevel/quirks-o.c +++ b/test/vast/Dialect/HighLevel/quirks-o.c @@ -7,16 +7,16 @@ int foo(int* ptr, int index) { // When indexing, the pointer and integer parts // of the subscript expression are interchangeable. - // CHECK: [[P:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[P:%[0-9]+]] = hl.ref @ptr // CHECK: [[PC:%[0-9]+]] = hl.implicit_cast [[P]] LValueToRValue : !hl.lvalue> -> !hl.ptr - // CHECK: [[I:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[I:%[0-9]+]] = hl.ref @index // CHECK: [[IC:%[0-9]+]] = hl.implicit_cast [[I]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.subscript [[PC]] at [{{%.*}} : !hl.int] : !hl.ptr -> !hl.lvalue - // CHECK: [[P:%[0-9]+]] = hl.ref %arg0 + // CHECK: [[P:%[0-9]+]] = hl.ref @ptr // CHECK: [[PC:%[0-9]+]] = hl.implicit_cast [[P]] LValueToRValue : !hl.lvalue> -> !hl.ptr - // CHECK: [[I:%[0-9]+]] = hl.ref %arg1 + // CHECK: [[I:%[0-9]+]] = hl.ref @index // CHECK: [[IC:%[0-9]+]] = hl.implicit_cast [[I]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.subscript [[PC]] at [{{%.*}} : !hl.int] : !hl.ptr -> !hl.lvalue return ptr[index] + index[ptr]; diff --git a/test/vast/Dialect/HighLevel/ref-a.c b/test/vast/Dialect/HighLevel/ref-a.c index 4d45a6bdfa..e6510d9acf 100644 --- a/test/vast/Dialect/HighLevel/ref-a.c +++ b/test/vast/Dialect/HighLevel/ref-a.c @@ -3,10 +3,10 @@ int main() { - // CHECK: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue = { + // CHECK: hl.var @x : !hl.lvalue = { // CHECK: [[V1:%[0-9]+]] = hl.const #core.integer<0> : !hl.int int x = 0; - // CHECK: [[Y:%[0-9]+]] = hl.var @y : !hl.lvalue = { - // CHECK: [[V2:%[0-9]+]] = hl.ref [[X]] + // CHECK: hl.var @y : !hl.lvalue = { + // CHECK: [[V2:%[0-9]+]] = hl.ref @x int y = x; } diff --git a/test/vast/Dialect/HighLevel/ref-b.c b/test/vast/Dialect/HighLevel/ref-b.c index ba261d071f..57aeae9d29 100644 --- a/test/vast/Dialect/HighLevel/ref-b.c +++ b/test/vast/Dialect/HighLevel/ref-b.c @@ -3,16 +3,16 @@ int main() { - // CHECK: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue + // CHECK: hl.var @x : !hl.lvalue int x = 0; - // CHECK: [[Y:%[0-9]+]] = hl.var @y : !hl.lvalue> - // CHECK: [[V1:%[0-9]+]] = hl.ref [[X]] + // CHECK: hl.var @y : !hl.lvalue> + // CHECK: [[V1:%[0-9]+]] = hl.ref @x // CHECK: [[V2:%[0-9]+]] = hl.addressof [[V1]] : !hl.lvalue -> !hl.ptr int *y = &x; - // CHECK: [[Z:%[0-9]+]] = hl.var @z : !hl.lvalue - // CHECK: [[V3:%[0-9]+]] = hl.ref [[Y]] + // CHECK: hl.var @z : !hl.lvalue + // CHECK: [[V3:%[0-9]+]] = hl.ref @y // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue> -> !hl.ptr // CHECK: [[V5:%[0-9]+]] = hl.deref [[V4]] : !hl.ptr -> !hl.lvalue // CHECK: [[V6:%[0-9]+]] = hl.implicit_cast [[V5]] LValueToRValue : !hl.lvalue -> !hl.int diff --git a/test/vast/Dialect/HighLevel/sizeof-a.c b/test/vast/Dialect/HighLevel/sizeof-a.c index ce1d454c2d..70dd940cd8 100644 --- a/test/vast/Dialect/HighLevel/sizeof-a.c +++ b/test/vast/Dialect/HighLevel/sizeof-a.c @@ -7,9 +7,9 @@ int main() { int v; - // CHECK: [[V:%[0-9]+]] = hl.var @v : !hl.lvalue - // CHECK: [[SV:%[0-9]+]] = hl.var @sv : !hl.lvalue> + // CHECK: hl.var @v : !hl.lvalue + // CHECK: hl.var @sv : !hl.lvalue> // CHECK: hl.sizeof.expr -> !hl.long< unsigned > - // CHECK: hl.ref [[V]] + // CHECK: hl.ref @v unsigned long sv = sizeof v; } diff --git a/test/vast/Dialect/HighLevel/struct-e.c b/test/vast/Dialect/HighLevel/struct-e.c index 7bc18f8580..10ad65bce9 100644 --- a/test/vast/Dialect/HighLevel/struct-e.c +++ b/test/vast/Dialect/HighLevel/struct-e.c @@ -12,15 +12,15 @@ struct s { // CHECK: hl.func @f void f() { - // CHECK: [[V:%[0-9]+]] = hl.var @v : !hl.lvalue>> + // CHECK: hl.var @v : !hl.lvalue>> struct s v; // CHECK: hl.var @x : !hl.lvalue - // CHECK: [[V1:%[0-9]+]] = hl.ref [[V]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @v // CHECK: [[V2:%[0-9]+]] = hl.member [[V1]] at @a : !hl.lvalue>> -> !hl.lvalue // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] LValueToRValue : !hl.lvalue -> !hl.int // CHECK: hl.value.yield [[V3]] : !hl.int int x = v.a; - // CHECK: [[V1:%[0-9]+]] = hl.ref [[V]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @v // CHECK: [[V2:%[0-9]+]] = hl.member [[V1]] at @b : !hl.lvalue>> -> !hl.lvalue // CHECK: [[V3:%[0-9]+]] = hl.const #core.integer<1> : !hl.int // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] IntegralCast : !hl.int -> !hl.short diff --git a/test/vast/Dialect/HighLevel/switch-a.c b/test/vast/Dialect/HighLevel/switch-a.c index c143eeca7d..a4c8a8c75f 100644 --- a/test/vast/Dialect/HighLevel/switch-a.c +++ b/test/vast/Dialect/HighLevel/switch-a.c @@ -5,7 +5,7 @@ int switch_simple(int num) { // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) { @@ -40,7 +40,7 @@ int switch_simple(int num) int switch_fallthorugh_1(int num) { // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) { @@ -63,7 +63,7 @@ int switch_fallthorugh_1(int num) int switch_fallthorugh_2(int num) { // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) { @@ -86,7 +86,7 @@ int switch_fallthorugh_2(int num) int switch_nodefault(int num) { // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) { @@ -107,7 +107,7 @@ int switch_nodefault(int num) int switch_break(int num) { // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) { @@ -129,7 +129,7 @@ int switch_break(int num) int switch_block(int num) { // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) { @@ -155,7 +155,7 @@ void switch_single(int num) { int v = 0; // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) @@ -171,14 +171,14 @@ void switch_no_compound(int num) { int v = 0; // CHECK: hl.switch { - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V1:%[0-9]+]] = hl.ref @num // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] // CHECK: hl.value.yield [[V2]] switch (num) // CHECK: } cases { // CHECK: hl.case { // CHECK: hl.case { - // CHECK: hl.ref + // CHECK: hl.ref @v // CHECK: hl.post.inc case 0: case 1: v++; diff --git a/test/vast/Dialect/HighLevel/switch-b.cpp b/test/vast/Dialect/HighLevel/switch-b.cpp index b55d00b387..26f71dd80a 100644 --- a/test/vast/Dialect/HighLevel/switch-b.cpp +++ b/test/vast/Dialect/HighLevel/switch-b.cpp @@ -6,7 +6,7 @@ int switch_init(int num) { // CHECK: core.scope { - // CHECK: [[V:%[0-9]+]] = hl.var @v : !hl.lvalue + // CHECK: hl.var @v : !hl.lvalue // CHECK: hl.switch { // CHECK: [[V2:%[0-9]+]] = hl.ref [[V]] // CHECK: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] diff --git a/test/vast/Dialect/HighLevel/typedef-a.c b/test/vast/Dialect/HighLevel/typedef-a.c index 5151474621..d2edfca53b 100644 --- a/test/vast/Dialect/HighLevel/typedef-a.c +++ b/test/vast/Dialect/HighLevel/typedef-a.c @@ -9,101 +9,101 @@ typedef short SHORT; void arithemtic_int_short(INT a, SHORT b) { INT c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue>> - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue>> + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.add [[V2]], [[V4]] : (!hl.elaborated>, !hl.elaborated>) -> !hl.elaborated> // CHECK: hl.assign [[V5]] to [[CR]] : !hl.elaborated>, !hl.lvalue>> -> !hl.elaborated> c = a + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.elaborated> -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.add [[V2]], [[V5]] : (!hl.elaborated>, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.elaborated> -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V6:%[0-9]+]] = hl.add [[V5]], [[V4]] : (!hl.int, !hl.elaborated>) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = b + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.elaborated> -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.sub [[V2]], [[V5]] : (!hl.elaborated>, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = a - b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.elaborated> -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V6:%[0-9]+]] = hl.sub [[V5]], [[V4]] : (!hl.int, !hl.elaborated>) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = b - a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.elaborated> -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.mul [[V2]], [[V5]] : (!hl.elaborated>, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = a * b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.elaborated> -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V6:%[0-9]+]] = hl.mul [[V5]], [[V4]] : (!hl.int, !hl.elaborated>) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = b * a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.elaborated> -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V2]], [[V5]] : (!hl.elaborated>, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = a / b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.elaborated> -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V6:%[0-9]+]] = hl.sdiv [[V5]], [[V4]] : (!hl.int, !hl.elaborated>) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = b / a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] IntegralCast : !hl.elaborated> -> !hl.int // CHECK: [[V6:%[0-9]+]] = hl.srem [[V2]], [[V5]] : (!hl.elaborated>, !hl.int) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> c = a % b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V5:%[0-9]+]] = hl.implicit_cast [[V2]] IntegralCast : !hl.elaborated> -> !hl.int - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>> -> !hl.elaborated> // CHECK: [[V6:%[0-9]+]] = hl.srem [[V5]], [[V4]] : (!hl.int, !hl.elaborated>) -> !hl.int // CHECK: hl.assign [[V6]] to [[CR]] : !hl.int, !hl.lvalue>> -> !hl.elaborated> @@ -113,27 +113,27 @@ void arithemtic_int_short(INT a, SHORT b) void arithemtic_pointer_long(INT* a, long b) { INT* c; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue>>> - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: hl.var @c : !hl.lvalue>>> + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>>> -> !hl.ptr>> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V5:%[0-9]+]] = hl.add [[V2]], [[V4]] : (!hl.ptr>>, !hl.long) -> !hl.ptr>> // CHECK: hl.assign [[V5]] to [[CR]] : !hl.ptr>> c = a + b; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @b // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue -> !hl.long - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @a // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue>>> -> !hl.ptr>> // CHECK: [[V5:%[0-9]+]] = hl.add [[V2]], [[V4]] : (!hl.long, !hl.ptr>>) -> !hl.ptr>> // CHECK: hl.assign [[V5]] to [[CR]] : !hl.ptr>> c = b + a; - // CHECK: [[CR:%[0-9]+]] = hl.ref [[C]] - // CHECK: [[V1:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[CR:%[0-9]+]] = hl.ref @c + // CHECK: [[V1:%[0-9]+]] = hl.ref @a // CHECK: [[V2:%[0-9]+]] = hl.implicit_cast [[V1]] LValueToRValue : !hl.lvalue>>> -> !hl.ptr>> - // CHECK: [[V3:%[0-9]+]] = hl.ref [[A2]] + // CHECK: [[V3:%[0-9]+]] = hl.ref @b // CHECK: [[V4:%[0-9]+]] = hl.implicit_cast [[V3]] LValueToRValue : !hl.lvalue -> !hl.long // CHECK: [[V5:%[0-9]+]] = hl.sub [[V2]], [[V4]] : (!hl.ptr>>, !hl.long) -> !hl.ptr>> // CHECK: hl.assign [[V5]] to [[CR]] : !hl.ptr>> diff --git a/test/vast/Dialect/HighLevel/typedef-b.c b/test/vast/Dialect/HighLevel/typedef-b.c index 45c4f60876..3c68c0e772 100644 --- a/test/vast/Dialect/HighLevel/typedef-b.c +++ b/test/vast/Dialect/HighLevel/typedef-b.c @@ -7,7 +7,7 @@ typedef int INT; typedef long INT2; // CHECK: hl.func @fun {{.*}} ([[A0:%arg[0-9]+]]: !hl.lvalue>>, [[A1:%arg[0-9]+]]: !hl.lvalue>>) -> !hl.elaborated> INT fun(INT a, INT2 b) { - // CHECK: [[V0:%[0-9]+]] = hl.ref [[A0]] + // CHECK: [[V0:%[0-9]+]] = hl.ref @a // CHECK: [[V1:%[0-9]+]] = hl.post.inc [[V0]] : !hl.lvalue>> -> !hl.elaborated> a++; // CHECK: [[LOR:%[0-9]+]] = hl.bin.lor { @@ -19,16 +19,16 @@ INT fun(INT a, INT2 b) { // CHECK: } : !hl.int // CHECK! hl.cond.yield [[LOR]] : hl.int if(a == b || !b) - // CHECK: [[V0:%[0-9]+]] = hl.ref [[A1]] + // CHECK: [[V0:%[0-9]+]] = hl.ref @b // CHECK: [[V1:%[0-9]+]] = hl.post.inc [[V0]] : !hl.lvalue>> -> !hl.elaborated> b++; - // CHECK: [[C:%[0-9]+]] = hl.var @c : !hl.lvalue = { + // CHECK: hl.var @c : !hl.lvalue = { // CHECK: [[SHL:%[0-9]+]] = hl.bin.shl [[X:%[0-9]+]], [[Y:%[0-9]+]] : (!hl.elaborated>, !hl.int) -> !hl.elaborated> // CHECK: } int c = b<<1; // CHECK: [[SHR:%[0-9]+]] = hl.bin.ashr [[X:%[0-9]+]], [[Y:%[0-9]+]] : (!hl.elaborated>, !hl.int) -> !hl.elaborated> c = a>>1; - // CHECK: [[PTR:%[0-9]+]] = hl.var @ptr : !hl.lvalue>>> = { + // CHECK: hl.var @ptr : !hl.lvalue>>> = { // CHECK: hl.addressof [[X:%[0-9]+]] : !hl.lvalue>> -> !hl.ptr>> // CHECK: } INT *ptr = &a; diff --git a/test/vast/Dialect/HighLevel/unary-b.c b/test/vast/Dialect/HighLevel/unary-b.c index b766d199b5..edec54f83c 100644 --- a/test/vast/Dialect/HighLevel/unary-b.c +++ b/test/vast/Dialect/HighLevel/unary-b.c @@ -2,10 +2,10 @@ // RUN: %vast-cc1 -vast-emit-mlir=hl %s -o %t && %vast-opt %t | diff -B %t - int main() { - // CHECK: [[A:%[0-9]+]] = hl.var @a : !hl.lvalue + // CHECK: hl.var @a : !hl.lvalue int a = 1; - // CHECK: [[B:%[0-9]+]] = hl.var @b : !hl.lvalue - // CHECK: [[AR:%[0-9]+]] = hl.ref [[A]] + // CHECK: hl.var @b : !hl.lvalue + // CHECK: [[AR:%[0-9]+]] = hl.ref @a // CHECK: hl.pre.dec [[AR]] : !hl.lvalue -> !hl.int int b = --a; } diff --git a/test/vast/Dialect/HighLevel/vars-b.c b/test/vast/Dialect/HighLevel/vars-b.c index 8a5e1d66e5..6aec2295c6 100644 --- a/test/vast/Dialect/HighLevel/vars-b.c +++ b/test/vast/Dialect/HighLevel/vars-b.c @@ -3,9 +3,9 @@ #include int main() { - // CHECK: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue> + // CHECK: hl.var @x : !hl.lvalue> // CHECK: hl.sizeof.expr - // CHECK: hl.ref [[X]] + // CHECK: hl.ref @x int *x = malloc(sizeof(*x)); return 0; } diff --git a/test/vast/Dialect/HighLevel/vars-c.c b/test/vast/Dialect/HighLevel/vars-c.c index e8fc34890d..313e065ce8 100644 --- a/test/vast/Dialect/HighLevel/vars-c.c +++ b/test/vast/Dialect/HighLevel/vars-c.c @@ -4,35 +4,35 @@ #include int main() { - // CHECK: [[Y:%[0-9]+]] = hl.var @y : !hl.lvalue> + // CHECK: hl.var @y : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[Y]] int *y = malloc(sizeof(*y)); if(1) { - // CHECK: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue> + // CHECK: hl.var @x : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[X]] int *x = malloc(sizeof(*x)); } while(1) { - // CHECK: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue> + // CHECK: hl.var @x : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[X]] int *x = malloc(sizeof(*x)); } do{ - // CHECK: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue> + // CHECK: hl.var @x : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[X]] int *x = malloc(sizeof(*x)); }while(0); // CHECK: core.scope - // CHECK-NEXT: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue> + // CHECK-NEXT: hl.var @x : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[X]] for(int *x = malloc(sizeof(*x)); *x<100; *x++) { // CHECK: do - // CHECK-NEXT: [[F:%[0-9]+]] = hl.var @f : !hl.lvalue> + // CHECK-NEXT: hl.var @f : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[F]] int *f = malloc(sizeof(*f)); @@ -43,7 +43,7 @@ int main() { if (*y) { case 2: case 3: case 5: case 7: { // CHECK: hl.case - // CHECK: [[X:%[0-9]+]] = hl.var @x : !hl.lvalue> + // CHECK: hl.var @x : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[X]] int *x = malloc(sizeof(*x)); @@ -57,13 +57,13 @@ int main() { case 1: default: { // CHECK: hl.default - // CHECK: [[Z:%[0-9]+]] = hl.var @z : !hl.lvalue> + // CHECK: hl.var @z : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[Z]] int *z = malloc(sizeof(*z)); } } - // CHECK: [[G:%[0-9]+]] = hl.var @g : !hl.lvalue> + // CHECK: hl.var @g : !hl.lvalue> // CHECK: hl.cond // CHECK: ? // CHECK: hl.sizeof.expr @@ -73,7 +73,7 @@ int main() { int *g = y ? malloc(sizeof(*g)) : y ; ({ // CHECK: hl.stmt.expr - // CHECK: [[Z:%[0-9]+]] = hl.var @z : !hl.lvalue> + // CHECK: hl.var @z : !hl.lvalue> // CHECK: hl.sizeof.expr // CHECK: hl.ref [[Z]] int *z = malloc(sizeof(*z)); diff --git a/test/vast/Dialect/Unsupported/atomicexpr.cpp b/test/vast/Dialect/Unsupported/atomicexpr.cpp index 431a6f4211..11901baf0e 100644 --- a/test/vast/Dialect/Unsupported/atomicexpr.cpp +++ b/test/vast/Dialect/Unsupported/atomicexpr.cpp @@ -3,9 +3,8 @@ int load(int* p) { // CHECK: unsup.stmt "AtomicExpr" - // CHECK: hl.ref %arg0 + // CHECK: hl.ref @p // CHECK: hl.const #core.integer<5> int q = __atomic_load_n (p, __ATOMIC_SEQ_CST); return q; } - diff --git a/test/vast/Transform/HL/DCE/for-a.c b/test/vast/Transform/HL/DCE/for-a.c index 3099160631..0de5d29401 100644 --- a/test/vast/Transform/HL/DCE/for-a.c +++ b/test/vast/Transform/HL/DCE/for-a.c @@ -5,7 +5,7 @@ void fn() for (int i = 0; i < 15; ++i) { // CHECK: } do { - // CHECK-NEXT: [[V1:%[0-9]+]] = hl.ref [[V0:%[0-9]+]] + // CHECK-NEXT: [[V1:%[0-9]+]] = hl.ref @i // CHECK-NEXT: [[V2:%[0-9]+]] = hl.pre.inc [[V1]] : !hl.lvalue // CHECK-NEXT: hl.break // CHECK-NEXT: } diff --git a/test/vast/Transform/HL/LowerTypedefs/func-b.c b/test/vast/Transform/HL/LowerTypedefs/func-b.c index 05797e1684..2ede46b32e 100644 --- a/test/vast/Transform/HL/LowerTypedefs/func-b.c +++ b/test/vast/Transform/HL/LowerTypedefs/func-b.c @@ -3,6 +3,6 @@ typedef int INT; // CHECK: hl.func @fn {{.*}} ([[A1:%arg[0-9]+]]: !hl.lvalue) -> !hl.int int fn(INT x) { - // CHECK: hl.ref [[A1]] : (!hl.lvalue) -> !hl.lvalue + // CHECK: hl.ref @x : !hl.lvalue return x; } diff --git a/test/vast/Transform/HL/LowerTypedefs/var-a.c b/test/vast/Transform/HL/LowerTypedefs/var-a.c index 0d3d784090..a6bdab6dd6 100644 --- a/test/vast/Transform/HL/LowerTypedefs/var-a.c +++ b/test/vast/Transform/HL/LowerTypedefs/var-a.c @@ -2,15 +2,15 @@ typedef int INT; -// CHECK: {{.*}} = hl.var @a : !hl.lvalue +// CHECK: hl.var @a : !hl.lvalue INT a = 0; typedef INT IINT; -// CHECK: {{.*}} = hl.var @b : !hl.lvalue +// CHECK: hl.var @b : !hl.lvalue IINT b = 0; typedef IINT IIINT; -// CHECK: {{.*}} = hl.var @c : !hl.lvalue +// CHECK: hl.var @c : !hl.lvalue IIINT c = 0; diff --git a/test/vast/Transform/HL/LowerTypes/fn-arg-a.c b/test/vast/Transform/HL/LowerTypes/fn-arg-a.c index 276f9f8477..9967966b37 100644 --- a/test/vast/Transform/HL/LowerTypes/fn-arg-a.c +++ b/test/vast/Transform/HL/LowerTypes/fn-arg-a.c @@ -10,11 +10,10 @@ static const char base64encdec [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq CURLcode Curl_base64_encode (const char *inputbuff, unsigned long insize, char **outptr, unsigned long *outlen) { - // CHECK: {{.*}} = hl.ref %arg0 : (!hl.lvalue>) -> !hl.lvalue> - // CHECK: {{.*}} = hl.ref %arg1 : (!hl.lvalue) -> !hl.lvalue - // CHECK: {{.*}} = hl.ref %arg2 : (!hl.lvalue>>) -> !hl.lvalue>> - // CHECK: {{.*}} = hl.ref %arg3 : (!hl.lvalue>) -> !hl.lvalue> - + // CHECK: hl.param @inputbuff = %arg0 : !hl.lvalue> + // CHECK: hl.param @insize = %arg1 : !hl.lvalue + // CHECK: hl.param @outptr = %arg2 : !hl.lvalue>> + // CHECK: hl.param @outlen = %arg3 : !hl.lvalue> return base64_encode(base64encdec, inputbuff, insize, outptr, outlen) ; } diff --git a/test/vast/Transform/HL/LowerTypes/fn-ptr-a.c b/test/vast/Transform/HL/LowerTypes/fn-ptr-a.c index b2df0c37c5..4bb8712bec 100644 --- a/test/vast/Transform/HL/LowerTypes/fn-ptr-a.c +++ b/test/vast/Transform/HL/LowerTypes/fn-ptr-a.c @@ -10,7 +10,7 @@ void * malloc ( unsigned long __size ); curl_malloc_callback Curl_cmalloc = ( curl_malloc_callback ) malloc ; // LTYPES: hl.typedef @curl_malloc_callback : !hl.ptr) -> (!hl.ptr)>> -// LTYPES: {{.*}} = hl.var @Curl_cmalloc : !hl.lvalue>> = { +// LTYPES: hl.var @Curl_cmalloc : !hl.lvalue>> = { -// LTYPEDEFS: {{.*}} = hl.var @Curl_cmalloc sc_extern : !hl.lvalue) -> (!hl.ptr)>>> -// LTYPEDEFS: {{.*}} = hl.var @Curl_cmalloc : !hl.lvalue) -> (!hl.ptr)>>> = { +// LTYPEDEFS: hl.var @Curl_cmalloc sc_extern : !hl.lvalue) -> (!hl.ptr)>>> +// LTYPEDEFS: hl.var @Curl_cmalloc : !hl.lvalue) -> (!hl.ptr)>>> = { diff --git a/test/vast/Transform/HL/LowerTypes/loop.c b/test/vast/Transform/HL/LowerTypes/loop.c index 638d90b1d8..4192dea86f 100644 --- a/test/vast/Transform/HL/LowerTypes/loop.c +++ b/test/vast/Transform/HL/LowerTypes/loop.c @@ -2,9 +2,9 @@ void loop_simple() { - // CHECK: [[I:%[0-9]+]] = hl.var @i : !hl.lvalue + // CHECK: hl.var @i : !hl.lvalue // CHECK: hl.for - // CHECK: [[V0:%[0-9]+]] = hl.ref [[I]] + // CHECK: [[V0:%[0-9]+]] = hl.ref @i // CHECK: [[V1:%[0-9]+]] = hl.implicit_cast [[V0]] LValueToRValue : !hl.lvalue -> si32 // CHECK: [[V2:%[0-9]+]] = hl.const #core.integer<100> : si32 // CHECK: [[V3:%[0-9]+]] = hl.cmp slt [[V1]], [[V2]] : si32, si32 -> si32 diff --git a/test/vast/Transform/HL/LowerTypes/struct-access-a.c b/test/vast/Transform/HL/LowerTypes/struct-access-a.c index a698913dcf..1646be0474 100644 --- a/test/vast/Transform/HL/LowerTypes/struct-access-a.c +++ b/test/vast/Transform/HL/LowerTypes/struct-access-a.c @@ -13,12 +13,12 @@ struct X int main() { - // CHECK: [[V0:%[0-9]+]] = hl.var @var_a : !hl.lvalue>> - // CHECK: [[V1:%[0-9]+]] = hl.ref [[V0]] + // CHECK: hl.var @var_a : !hl.lvalue>> + // CHECK: [[V1:%[0-9]+]] = hl.ref @var_a // CHECK: [[V2:%[0-9]+]] = hl.member [[V1]] at @member_x : !hl.lvalue>> -> !hl.lvalue // CHECK: [[V3:%[0-9]+]] = hl.const #core.integer<1> : si32 // CHECK: [[V4:%[0-9]+]] = hl.assign [[V3]] to [[V2]] : si32, !hl.lvalue -> si32 - // CHECK: [[V5:%[0-9]+]] = hl.ref [[V0]] + // CHECK: [[V5:%[0-9]+]] = hl.ref @var_a // CHECK: [[V6:%[0-9]+]] = hl.member [[V5]] at @member_y : !hl.lvalue>> -> !hl.lvalue // CHECK: [[V7:%[0-9]+]] = hl.const #core.integer<2> : si32 // CHECK: [[V8:%[0-9]+]] = hl.assign [[V7]] to [[V6]] : si32, !hl.lvalue -> si32 From 7aa1c34c9c5aaeec27e91d24515e323faf727a79 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 12:26:07 +0200 Subject: [PATCH 05/50] conv:tollvars: Remove obsolete var initilization section fix. --- lib/vast/Conversion/FromHL/ToLLVars.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lib/vast/Conversion/FromHL/ToLLVars.cpp b/lib/vast/Conversion/FromHL/ToLLVars.cpp index 365288588d..e59b51d007 100644 --- a/lib/vast/Conversion/FromHL/ToLLVars.cpp +++ b/lib/vast/Conversion/FromHL/ToLLVars.cpp @@ -75,24 +75,6 @@ namespace vast return mlir::success(); } - // This deals with cases where the initializer references - // the variable itself - int *x = malloc(sizeof(*x)); - // We can't reference the initialized value so we use the - // initialized one - auto fix_init_refs = [&](){ - auto var = op.getResult(); - for (auto user : op->getUsers()) { - if (op->isAncestor(user)) { - for (op_operand& operand : user->getOpOperands()) { - if (operand.is(var)) { - user->setOperand(operand.getOperandNumber(), uninit_var); - } - } - } - } - }; - rewriter.modifyOpInPlace(op, fix_init_refs); - auto yield = inline_init_region< hl::ValueYieldOp >(op, rewriter); rewriter.setInsertionPointAfter(yield); auto initialize = rewriter.create< ll::InitializeVar >( From d49a4520185bfd189666582d6148b3f597c46797 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 21:31:06 +0200 Subject: [PATCH 06/50] conv: Introduce VarsToCells pass and ToMem pipeline step. --- include/vast/Conversion/Passes.hpp | 5 ++++ include/vast/Conversion/Passes.td | 11 +++++++ lib/vast/Conversion/CMakeLists.txt | 7 +++-- lib/vast/Conversion/FromHL/Passes.cpp | 15 +++++++++- lib/vast/Conversion/ToMem/CMakeLists.txt | 5 ++++ lib/vast/Conversion/ToMem/VarsToCells.cpp | 36 +++++++++++++++++++++++ 6 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 lib/vast/Conversion/ToMem/CMakeLists.txt create mode 100644 lib/vast/Conversion/ToMem/VarsToCells.cpp diff --git a/include/vast/Conversion/Passes.hpp b/include/vast/Conversion/Passes.hpp index 43677c1a9b..1bb7aa6922 100644 --- a/include/vast/Conversion/Passes.hpp +++ b/include/vast/Conversion/Passes.hpp @@ -63,6 +63,9 @@ namespace vast std::unique_ptr< mlir::Pass > createLowerValueCategoriesPass(); + // ToMem + std::unique_ptr< mlir::Pass > createVarsToCellsPass(); + // Generate the code for registering passes. #define GEN_PASS_REGISTRATION #include "vast/Conversion/Passes.h.inc" @@ -76,6 +79,8 @@ namespace vast pipeline_step_ptr to_ll(); + pipeline_step_ptr to_mem(); + pipeline_step_ptr to_llvm(); pipeline_step_ptr canonicalize(); diff --git a/include/vast/Conversion/Passes.td b/include/vast/Conversion/Passes.td index cdfb1e118f..15c9900b6e 100644 --- a/include/vast/Conversion/Passes.td +++ b/include/vast/Conversion/Passes.td @@ -79,6 +79,17 @@ def FnArgsToAlloca : Pass<"vast-fn-args-to-alloca", "core::ModuleOp"> { ]; } +def VarsToCells : Pass<"vast-vars-to-cells", "core::ModuleOp"> { + let summary = "Lower `hl.var` into ssa-based `ll.cell`."; + let description = [{ TBD }]; + + let constructor = "vast::createVarsToCellsPass()"; + let dependentDialects = [ + "vast::ll::LowLevelDialect", + "vast::hl::HighLevelDialect", + ]; +} + def LowerValueCategories : Pass<"vast-lower-value-categories", "core::ModuleOp"> { let summary = "Lower `hl.lvalue` into explicit pointers and loads."; let description = [{ diff --git a/lib/vast/Conversion/CMakeLists.txt b/lib/vast/Conversion/CMakeLists.txt index 7db0b1f88a..5121bfcca5 100644 --- a/lib/vast/Conversion/CMakeLists.txt +++ b/lib/vast/Conversion/CMakeLists.txt @@ -1,7 +1,8 @@ add_subdirectory(ABI) +add_subdirectory(Core) +add_subdirectory(FromHL) +add_subdirectory(Generic) add_subdirectory(PDLL) +add_subdirectory(ToMem) add_subdirectory(ToLLVM) -add_subdirectory(FromHL) add_subdirectory(TypeConverters) -add_subdirectory(Core) -add_subdirectory(Generic) diff --git a/lib/vast/Conversion/FromHL/Passes.cpp b/lib/vast/Conversion/FromHL/Passes.cpp index e21db0c6ef..9dd75903f3 100644 --- a/lib/vast/Conversion/FromHL/Passes.cpp +++ b/lib/vast/Conversion/FromHL/Passes.cpp @@ -44,8 +44,21 @@ namespace vast::conv::pipeline { return pass(createFnArgsToAllocaPass); } + // FIXME: move to ToMem/Passes.cpp eventually + pipeline_step_ptr vars_to_cells() { + return pass(createVarsToCellsPass); + } + + pipeline_step_ptr to_mem() { + return compose("to-mem", + vars_to_cells + ); + } + + pipeline_step_ptr lower_value_categories() { - return pass(createLowerValueCategoriesPass); + return pass(createLowerValueCategoriesPass) + .depends_on(to_mem); } pipeline_step_ptr to_ll() { diff --git a/lib/vast/Conversion/ToMem/CMakeLists.txt b/lib/vast/Conversion/ToMem/CMakeLists.txt new file mode 100644 index 0000000000..acd350c8f9 --- /dev/null +++ b/lib/vast/Conversion/ToMem/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2024-present, Trail of Bits, Inc. + +add_vast_conversion_library(ToMemConversionPasses + VarsToCells.cpp +) diff --git a/lib/vast/Conversion/ToMem/VarsToCells.cpp b/lib/vast/Conversion/ToMem/VarsToCells.cpp new file mode 100644 index 0000000000..e6ce1a8645 --- /dev/null +++ b/lib/vast/Conversion/ToMem/VarsToCells.cpp @@ -0,0 +1,36 @@ +// Copyright (c) 2024-present, Trail of Bits, Inc. + +#include "vast/Conversion/Passes.hpp" + +VAST_RELAX_WARNINGS +#include +#include +#include +VAST_UNRELAX_WARNINGS + +#include "../PassesDetails.hpp" + +#include "vast/Dialect/HighLevel/HighLevelTypes.hpp" +#include "vast/Dialect/LowLevel/LowLevelOps.hpp" + +#include "vast/Util/Common.hpp" +#include "vast/Conversion/Common/Mixins.hpp" +#include "vast/Conversion/Common/Patterns.hpp" + +namespace vast::conv { + + struct VarsToCellsPass : ModuleConversionPassMixin< VarsToCellsPass, VarsToCellsBase > + { + using base = ModuleConversionPassMixin< VarsToCellsPass, VarsToCellsBase >; + + static conversion_target create_conversion_target(mcontext_t &mctx) { + conversion_target target(mctx); + return target; + } + }; + +} // namespace vast::conv + +std::unique_ptr< mlir::Pass > vast::createVarsToCellsPass() { + return std::make_unique< vast::conv::VarsToCellsPass >(); +} From f567a8154c03573f09df0c9374a63d670d02f07c Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 21:37:22 +0200 Subject: [PATCH 07/50] ll: Introduce memory cells to represent variables storage. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index 49bca038c1..c58a7e0c53 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -93,6 +93,32 @@ def Store }]; } +def Cell + : LowLevel_Op< "cell" > + , Arguments<(ins SymbolNameAttr:$sym_name)> + , Results<(outs AnyType:$result)> +{ + let summary = "Cell that holds the value and is accessible trhough SSA result."; + + let assemblyFormat = [{ + operands attr-dict `:` functional-type(operands, results) + }]; +} + +def CellInit + : LowLevel_Op< "cell_init" > + , Arguments<(ins AnyType:$var, Variadic:$elements)> + , Results<(outs AnyType:$result)> +{ + let summary = "Cell initialization."; + + let assemblyFormat = [{ + operands attr-dict `:` functional-type(operands, results) + }]; + +} + +// FIXME: This is to be removed once cells are properly implemented. def UninitializedVar : LowLevel_Op< "uninitialized_var", [Core_VarSymbol] > , Results<(outs AnyType:$result)> @@ -107,6 +133,7 @@ def UninitializedVar }]; } +// FIXME: This is to be removed once cells are properly implemented. def InitializeVar : LowLevel_Op< "initialize" > , Arguments<(ins AnyType:$var, Variadic:$elements)> From e1620b8ce89c7ca0b4f45e04a02b5f01fc9adf3c Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 22:15:19 +0200 Subject: [PATCH 08/50] conv:tomem: Implement VarsToCellsPass. --- lib/vast/Conversion/ToMem/VarsToCells.cpp | 57 ++++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/vast/Conversion/ToMem/VarsToCells.cpp b/lib/vast/Conversion/ToMem/VarsToCells.cpp index e6ce1a8645..9d1798b7ec 100644 --- a/lib/vast/Conversion/ToMem/VarsToCells.cpp +++ b/lib/vast/Conversion/ToMem/VarsToCells.cpp @@ -19,13 +19,66 @@ VAST_UNRELAX_WARNINGS namespace vast::conv { + namespace pattern { + + struct var_to_cell : operation_conversion_pattern< hl::VarDeclOp > + { + using base = operation_conversion_pattern< hl::VarDeclOp >; + using base::base; + + using adaptor_t = hl::VarDeclOp::Adaptor; + + // Inline the region that is responsible for initialization + // * `rewriter` insert point is invalidated (although documentation of called + // methods does not state it, experimentally it is corrupted) + // * terminator is returned to be used & erased by caller. + operation inline_init_region(auto src, auto &rewriter) const { + auto &init_region = src.getInitializer(); + auto &init_block = init_region.back(); + + auto terminator = init_block.getTerminator(); + rewriter.inlineRegionBefore(init_region, src->getBlock()); + rewriter.inlineBlockBefore(&init_block, src.getOperation()); + return terminator; + } + + logical_result matchAndRewrite( + hl::VarDeclOp op, adaptor_t adaptor, conversion_rewriter &rewriter + ) const override { + auto cell = rewriter.create< ll::Cell >(op.getLoc(), op.getType(), op.getSymName()); + + if (auto &init = op.getInitializer(); !init.empty()) { + auto yield = inline_init_region(op, rewriter); + rewriter.setInsertionPointAfter(yield); + rewriter.create< ll::CellInit >( + yield->getLoc(), op.getType(), cell, yield->getOperand(0) + ); + rewriter.eraseOp(yield); + } + + rewriter.replaceOp(op, cell); + return mlir::success(); + } + + static void legalize(conversion_target &trg) { + base::legalize(trg); + trg.addLegalOp< ll::Cell >(); + trg.addLegalOp< ll::CellInit >(); + } + }; + + } // namespace pattern + struct VarsToCellsPass : ModuleConversionPassMixin< VarsToCellsPass, VarsToCellsBase > { using base = ModuleConversionPassMixin< VarsToCellsPass, VarsToCellsBase >; static conversion_target create_conversion_target(mcontext_t &mctx) { - conversion_target target(mctx); - return target; + return conversion_target(mctx); + } + + static void populate_conversions(auto &cfg) { + base::populate_conversions< pattern::var_to_cell >(cfg); } }; From e2b8d5c78ba25cc4b8df9928e83321f2568358f4 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 22:15:57 +0200 Subject: [PATCH 09/50] ll: Clean up `Cell` assembly format. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index c58a7e0c53..9faf81c763 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -101,7 +101,7 @@ def Cell let summary = "Cell that holds the value and is accessible trhough SSA result."; let assemblyFormat = [{ - operands attr-dict `:` functional-type(operands, results) + $sym_name attr-dict `:` type($result) }]; } From 998635a090e98a69246e774353d7c87a38b52108 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 22:21:41 +0200 Subject: [PATCH 10/50] ll: Add prefix to LowLevel operations. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 38 ++++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index 9faf81c763..823d58a856 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -25,7 +25,7 @@ def LowLevel_StructGEPOp let description = [{ VAST struct gep operation }]; } -def Subscript +def LowLevel_Subscript : LowLevel_Op< "subscript" > , Arguments<(ins AnyType:$array, @@ -41,7 +41,7 @@ def Subscript }]; } -def ArgAlloca +def LowLevel_ArgAlloca : LowLevel_Op< "arg_alloca" > , Arguments<(ins AnyType:$fn_arg)> , Results<(outs AnyType:$result)> @@ -53,7 +53,7 @@ def ArgAlloca }]; } -def Alloca +def LowLevel_Alloca : LowLevel_Op< "alloca" >, Results<(outs AnyType:$result)> { @@ -70,7 +70,7 @@ class PointerPointeeTypeMatch< string ptr, string val > "? mlir::cast< ElementTypeInterface >($_self).getElementType()" ": mlir::Type{}" >; -def Load +def LowLevel_Load : LowLevel_Op< "load", [PointerPointeeTypeMatch<"ptr", "result"> ] > , Arguments<(ins ElementTypeInterface:$ptr)> , Results<(outs AnyType:$result)> @@ -82,7 +82,7 @@ def Load }]; } -def Store +def LowLevel_Store : LowLevel_Op< "store", [PointerPointeeTypeMatch<"ptr", "val">]> , Arguments<(ins AnyType:$val, ElementTypeInterface:$ptr)> { @@ -93,7 +93,7 @@ def Store }]; } -def Cell +def LowLevel_Cell : LowLevel_Op< "cell" > , Arguments<(ins SymbolNameAttr:$sym_name)> , Results<(outs AnyType:$result)> @@ -105,7 +105,7 @@ def Cell }]; } -def CellInit +def LowLevel_CellInit : LowLevel_Op< "cell_init" > , Arguments<(ins AnyType:$var, Variadic:$elements)> , Results<(outs AnyType:$result)> @@ -119,7 +119,7 @@ def CellInit } // FIXME: This is to be removed once cells are properly implemented. -def UninitializedVar +def LowLevel_UninitializedVar : LowLevel_Op< "uninitialized_var", [Core_VarSymbol] > , Results<(outs AnyType:$result)> { @@ -134,7 +134,7 @@ def UninitializedVar } // FIXME: This is to be removed once cells are properly implemented. -def InitializeVar +def LowLevel_InitializeVar : LowLevel_Op< "initialize" > , Arguments<(ins AnyType:$var, Variadic:$elements)> , Results<(outs AnyType:$result)> @@ -151,7 +151,7 @@ def InitializeVar }]; } -def Concat +def LowLevel_Concat : LowLevel_Op< "concat" > , Arguments<(ins Variadic:$args)> , Results<(outs AnyType:$result)> @@ -166,7 +166,7 @@ def Concat }]; } -def Extract +def LowLevel_Extract : LowLevel_Op< "extract" > , Arguments<(ins AnyType:$arg, TypedAttrInterface:$from, TypedAttrInterface:$to)> , Results<(outs AnyType:$result)> @@ -213,7 +213,7 @@ def Extract }]; } -def Br +def LowLevel_Br : LowLevel_Op< "br", [Terminator, DeclareOpInterfaceMethods] > @@ -242,7 +242,7 @@ def Br }]; } -def CondBr +def LowLevel_CondBr : LowLevel_Op< "cond_br", [Terminator, AttrSizedOperandSegments] > , Arguments<(ins AnyType:$cond, Variadic:$trueOperands, Variadic:$falseOperands )> { @@ -282,7 +282,7 @@ def CondBr }]; } -def ScopeRet +def LowLevel_ScopeRet : LowLevel_Op< "scope_ret", [Terminator] > { let summary = "Terminator of scope."; @@ -291,7 +291,7 @@ def ScopeRet let assemblyFormat = [{attr-dict}]; } -def ScopeRecurse +def LowLevel_ScopeRecurse : LowLevel_Op< "scope_recurse", [Terminator] > { let summary = "Jump to first block of scope."; @@ -300,7 +300,7 @@ def ScopeRecurse let assemblyFormat = [{attr-dict}]; } -def CondScopeRet +def LowLevel_CondScopeRet : LowLevel_Op< "cond_scope_ret", [Terminator] > { let summary = "Terminator of scope if condition is met, otherwise branch."; @@ -322,7 +322,7 @@ def CondScopeRet $dest (`(` $dest_operands^ `:` type($dest_operands) `)`)? attr-dict }];} -def ReturnOp +def LowLevel_ReturnOp : LowLevel_Op< "return", [Terminator, Core_ReturnLikeTrait] > , Arguments<(ins Variadic:$result)> { @@ -334,7 +334,7 @@ def ReturnOp let assemblyFormat = "($result^ `:` type($result))? attr-dict"; } -def Scope +def LowLevel_Scope : LowLevel_Op< "scope", [NoRegionArguments, NoTerminator] > { let summary = "Scope, holds one region."; @@ -358,7 +358,7 @@ def Scope }]; } -def InlineScope +def LowLevel_InlineScope : LowLevel_Op< "inline_scope", [NoRegionArguments] > { let summary = "Scope, that forwards (cond)scope return up."; From 9b2d7fc6bc65e8a7fbbe8a0d966da69549ac6736 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 22:49:55 +0200 Subject: [PATCH 11/50] ll: Make ll::scope a shadowing symbol table. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index 823d58a856..b975af0bc8 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -335,7 +335,13 @@ def LowLevel_ReturnOp } def LowLevel_Scope - : LowLevel_Op< "scope", [NoRegionArguments, NoTerminator] > + : LowLevel_Op< "scope", [ + NoRegionArguments, + NoTerminator, + Core_ShadowingSymbolTable< [ + [Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol] + ] > + ] > { let summary = "Scope, holds one region."; let description = [{ Scope that holds one region, each block should be terminated From c8e9788c98f321ee804ee79126fe0fc5c51cdb5a Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 22:50:17 +0200 Subject: [PATCH 12/50] ll: Make ll::Cell to define variable symbol. --- include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp | 3 +++ include/vast/Dialect/LowLevel/LowLevelOps.hpp | 2 ++ include/vast/Dialect/LowLevel/LowLevelOps.td | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp b/include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp index d50edc6bfc..2bad814b0a 100644 --- a/include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp +++ b/include/vast/Dialect/Core/Interfaces/SymbolInterface.hpp @@ -27,8 +27,11 @@ namespace vast::core { namespace vast::core { using symbol = SymbolOpInterface; + using func_symbol = FuncSymbolOpInterface; + using var_symbol = VarSymbolOpInterface; + template< typename interface > concept symbol_op_interface = requires (interface i) { static_cast< symbol >(i); diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.hpp b/include/vast/Dialect/LowLevel/LowLevelOps.hpp index d89d8e5f39..8535ee16ee 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.hpp +++ b/include/vast/Dialect/LowLevel/LowLevelOps.hpp @@ -18,6 +18,8 @@ VAST_RELAX_WARNINGS VAST_RELAX_WARNINGS #include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp" +#include "vast/Dialect/Core/Interfaces/SymbolTableInterface.hpp" + #include "vast/Interfaces/ElementTypeInterface.hpp" #include "vast/Dialect/Core/CoreTypes.hpp" diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index b975af0bc8..64dccd3999 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -12,6 +12,7 @@ include "vast/Dialect/Core/Interfaces/SymbolInterface.td" include "vast/Interfaces/ElementTypeInterface.td" include "vast/Dialect/Core/CoreTraits.td" +include "vast/Dialect/Core/Interfaces/SymbolTableInterface.td" include "vast/Dialect/Core/Func.td" @@ -94,7 +95,7 @@ def LowLevel_Store } def LowLevel_Cell - : LowLevel_Op< "cell" > + : LowLevel_Op< "cell", [Core_VarSymbol] > , Arguments<(ins SymbolNameAttr:$sym_name)> , Results<(outs AnyType:$result)> { From dc95487ce1375ae136027571c379ff25aea46352 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 22:52:14 +0200 Subject: [PATCH 13/50] conv:tomem: Create RefsToSSAPass. --- include/vast/Conversion/Passes.hpp | 2 + include/vast/Conversion/Passes.td | 11 ++++ lib/vast/Conversion/FromHL/Passes.cpp | 8 ++- lib/vast/Conversion/ToMem/CMakeLists.txt | 1 + lib/vast/Conversion/ToMem/RefsToSSA.cpp | 67 ++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 lib/vast/Conversion/ToMem/RefsToSSA.cpp diff --git a/include/vast/Conversion/Passes.hpp b/include/vast/Conversion/Passes.hpp index 1bb7aa6922..8f51f8944e 100644 --- a/include/vast/Conversion/Passes.hpp +++ b/include/vast/Conversion/Passes.hpp @@ -64,6 +64,8 @@ namespace vast std::unique_ptr< mlir::Pass > createLowerValueCategoriesPass(); // ToMem + std::unique_ptr< mlir::Pass > createRefsToSSAPass(); + std::unique_ptr< mlir::Pass > createVarsToCellsPass(); // Generate the code for registering passes. diff --git a/include/vast/Conversion/Passes.td b/include/vast/Conversion/Passes.td index 15c9900b6e..16fbef3ad3 100644 --- a/include/vast/Conversion/Passes.td +++ b/include/vast/Conversion/Passes.td @@ -90,6 +90,17 @@ def VarsToCells : Pass<"vast-vars-to-cells", "core::ModuleOp"> { ]; } +def RefsToSSA : Pass<"vast-refs-to-ssa", "core::ModuleOp"> { + let summary = "Lower `hl.ref` into ssa-based `ll.cell`."; + let description = [{ TBD }]; + + let constructor = "vast::createRefsToSSAPass()"; + let dependentDialects = [ + "vast::ll::LowLevelDialect", + "vast::hl::HighLevelDialect", + ]; +} + def LowerValueCategories : Pass<"vast-lower-value-categories", "core::ModuleOp"> { let summary = "Lower `hl.lvalue` into explicit pointers and loads."; let description = [{ diff --git a/lib/vast/Conversion/FromHL/Passes.cpp b/lib/vast/Conversion/FromHL/Passes.cpp index 9dd75903f3..3eabcd1a6e 100644 --- a/lib/vast/Conversion/FromHL/Passes.cpp +++ b/lib/vast/Conversion/FromHL/Passes.cpp @@ -49,9 +49,15 @@ namespace vast::conv::pipeline { return pass(createVarsToCellsPass); } + pipeline_step_ptr refs_to_ssa() { + return pass(createRefsToSSAPass) + .depends_on(vars_to_cells); + } + pipeline_step_ptr to_mem() { return compose("to-mem", - vars_to_cells + vars_to_cells, + refs_to_ssa ); } diff --git a/lib/vast/Conversion/ToMem/CMakeLists.txt b/lib/vast/Conversion/ToMem/CMakeLists.txt index acd350c8f9..fa23436af6 100644 --- a/lib/vast/Conversion/ToMem/CMakeLists.txt +++ b/lib/vast/Conversion/ToMem/CMakeLists.txt @@ -1,5 +1,6 @@ # Copyright (c) 2024-present, Trail of Bits, Inc. add_vast_conversion_library(ToMemConversionPasses + RefsToSSA.cpp VarsToCells.cpp ) diff --git a/lib/vast/Conversion/ToMem/RefsToSSA.cpp b/lib/vast/Conversion/ToMem/RefsToSSA.cpp new file mode 100644 index 0000000000..365217bbb8 --- /dev/null +++ b/lib/vast/Conversion/ToMem/RefsToSSA.cpp @@ -0,0 +1,67 @@ +// Copyright (c) 2024-present, Trail of Bits, Inc. + +#include "vast/Conversion/Passes.hpp" + +VAST_RELAX_WARNINGS +#include +#include +#include +VAST_UNRELAX_WARNINGS + +#include "../PassesDetails.hpp" + +#include "vast/Dialect/LowLevel/LowLevelOps.hpp" + +#include "vast/Util/Common.hpp" +#include "vast/Conversion/Common/Mixins.hpp" +#include "vast/Conversion/Common/Patterns.hpp" + +namespace vast::conv { + + namespace pattern { + + struct ref_to_ssa : operation_conversion_pattern< hl::DeclRefOp > + { + using base = operation_conversion_pattern< hl::DeclRefOp >; + using base::base; + + using adaptor_t = hl::DeclRefOp::Adaptor; + + logical_result matchAndRewrite( + hl::DeclRefOp op, adaptor_t adaptor, conversion_rewriter &rewriter + ) const override { + auto st = core::get_effective_symbol_table_for< core::var_symbol >(op); + VAST_CHECK(st, "No effective symbol table found for variable reference resolution."); + + auto var = st->lookup< core::var_symbol >(op.getName()); + VAST_CHECK(var, "Variable {} not present in the symbol table.", op.getName()); + VAST_CHECK(mlir::isa< ll::Cell >(var), "Variable {} is not a cell." + "Lower variable to cells before lowering of references.", + op.getName() + ); + + rewriter.replaceOp(op, var); + return mlir::success(); + } + }; + + } // namespace pattern + + struct RefsToSSAPass : ModuleConversionPassMixin< RefsToSSAPass, RefsToSSABase > + { + using base = ModuleConversionPassMixin< RefsToSSAPass, RefsToSSABase >; + + static conversion_target create_conversion_target(mcontext_t &mctx) { + return conversion_target(mctx); + } + + static void populate_conversions(auto &cfg) { + base::populate_conversions< pattern::ref_to_ssa >(cfg); + } + }; + +} // namespace vast::conv + +std::unique_ptr< mlir::Pass > vast::createRefsToSSAPass() { + return std::make_unique< vast::conv::RefsToSSAPass >(); +} From 05cf3521e6304021db4e55c24f7df31342fcf657 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 22:52:42 +0200 Subject: [PATCH 14/50] hl: Rename `DeclRefOp` parameter `decl` to `name`. --- include/vast/Dialect/HighLevel/HighLevelOps.td | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/vast/Dialect/HighLevel/HighLevelOps.td b/include/vast/Dialect/HighLevel/HighLevelOps.td index 88d5849554..995337970b 100644 --- a/include/vast/Dialect/HighLevel/HighLevelOps.td +++ b/include/vast/Dialect/HighLevel/HighLevelOps.td @@ -451,13 +451,13 @@ def HighLevel_ReturnOp def HighLevel_DeclRefOp : HighLevel_Op< "ref" > - , Arguments<(ins FlatSymbolRefAttr:$decl)> + , Arguments<(ins FlatSymbolRefAttr:$name)> , Results<(outs HighLevel_LValueOf:$result)> { let summary = "VAST variable reference declaration"; let description = [{ VAST variable reference declaration }]; - let assemblyFormat = "$decl attr-dict `:` type($result)"; + let assemblyFormat = "$name attr-dict `:` type($result)"; } def HighLevel_FuncRefOp From c11d123a49233083cec7f18aec8c03f52925af23 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 23:00:48 +0200 Subject: [PATCH 15/50] conv: Remove obsolete `hl-to-ll-vars` pass. --- include/vast/Conversion/Passes.hpp | 2 - include/vast/Conversion/Passes.td | 14 --- lib/vast/Conversion/FromHL/CMakeLists.txt | 1 - lib/vast/Conversion/FromHL/Passes.cpp | 6 - lib/vast/Conversion/FromHL/ToLLVars.cpp | 130 ---------------------- 5 files changed, 153 deletions(-) delete mode 100644 lib/vast/Conversion/FromHL/ToLLVars.cpp diff --git a/include/vast/Conversion/Passes.hpp b/include/vast/Conversion/Passes.hpp index 8f51f8944e..75ccef3cb3 100644 --- a/include/vast/Conversion/Passes.hpp +++ b/include/vast/Conversion/Passes.hpp @@ -51,8 +51,6 @@ namespace vast std::unique_ptr< mlir::Pass > createHLToLLGEPsPass(); - std::unique_ptr< mlir::Pass > createHLToLLVarsPass(); - std::unique_ptr< mlir::Pass > createHLEmitLazyRegionsPass(); std::unique_ptr< mlir::Pass > createHLToLLFuncPass(); diff --git a/include/vast/Conversion/Passes.td b/include/vast/Conversion/Passes.td index 16fbef3ad3..0500257319 100644 --- a/include/vast/Conversion/Passes.td +++ b/include/vast/Conversion/Passes.td @@ -168,20 +168,6 @@ def HLToLLGEPs : Pass<"vast-hl-to-ll-geps", "core::ModuleOp"> { ]; } -def HLToLLVars : Pass<"vast-hl-to-ll-vars", "core::ModuleOp"> { - let summary = "Convert hl variables into ll versions."; - let description = [{ - This pass is still a work in progress. - }]; - - let constructor = "vast::createHLToLLVarsPass()"; - let dependentDialects = [ - "mlir::LLVM::LLVMDialect", - "vast::ll::LowLevelDialect", - "vast::core::CoreDialect" - ]; -} - def HLToLLFunc : Pass<"vast-hl-to-ll-func", "core::ModuleOp"> { let summary = "Convert hl functions into ll versions."; let description = [{ diff --git a/lib/vast/Conversion/FromHL/CMakeLists.txt b/lib/vast/Conversion/FromHL/CMakeLists.txt index 3b554f7cdd..9785424393 100644 --- a/lib/vast/Conversion/FromHL/CMakeLists.txt +++ b/lib/vast/Conversion/FromHL/CMakeLists.txt @@ -7,5 +7,4 @@ add_vast_conversion_library(HighLevelConversionPasses ToLLCF.cpp ToLLFunc.cpp ToLLGEPs.cpp - ToLLVars.cpp ) diff --git a/lib/vast/Conversion/FromHL/Passes.cpp b/lib/vast/Conversion/FromHL/Passes.cpp index 3eabcd1a6e..271b28a2d4 100644 --- a/lib/vast/Conversion/FromHL/Passes.cpp +++ b/lib/vast/Conversion/FromHL/Passes.cpp @@ -25,11 +25,6 @@ namespace vast::conv::pipeline { return pass(createHLToLLGEPsPass); } - pipeline_step_ptr hl_to_ll_vars() { - // TODO add dependencies - return pass(createHLToLLVarsPass); - } - pipeline_step_ptr lazy_regions() { // TODO add dependencies return pass(createHLEmitLazyRegionsPass); @@ -70,7 +65,6 @@ namespace vast::conv::pipeline { pipeline_step_ptr to_ll() { return compose( "to-ll", hl_to_ll_func, - hl_to_ll_vars, hl_to_ll_cf, hl_to_ll_geps, fn_args_to_alloca, diff --git a/lib/vast/Conversion/FromHL/ToLLVars.cpp b/lib/vast/Conversion/FromHL/ToLLVars.cpp deleted file mode 100644 index e59b51d007..0000000000 --- a/lib/vast/Conversion/FromHL/ToLLVars.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2021-present, Trail of Bits, Inc. - -#include "vast/Dialect/HighLevel/Passes.hpp" - -VAST_RELAX_WARNINGS -#include -#include -#include -#include - -#include -VAST_UNRELAX_WARNINGS - -#include "PassesDetails.hpp" - -#include "vast/Dialect/Core/CoreOps.hpp" -#include "vast/Dialect/HighLevel/HighLevelOps.hpp" -#include "vast/Dialect/LowLevel/LowLevelOps.hpp" - -#include "vast/Util/Common.hpp" -#include "vast/Util/DialectConversion.hpp" -#include "vast/Conversion/TypeConverters/LLVMTypeConverter.hpp" -#include "vast/Util/Symbols.hpp" - -namespace vast -{ - namespace pattern - { - // Inline the region that is responsible for initialization - // * `rewriter` insert point is invalidated (although documentation of called - // methods does not state it, experimentally it is corrupted) - // * terminator is returned to be used & erased by caller. - template< typename T > - T inline_init_region(auto src, auto &rewriter) - { - auto &init_region = src.getInitializer(); - auto &init_block = init_region.back(); - - auto terminator = mlir::dyn_cast< T >(init_block.getTerminator()); - - rewriter.inlineRegionBefore(init_region, src->getBlock()); - rewriter.inlineBlockBefore(&init_block, src.getOperation()); - return terminator; - } - - template< typename O > - struct BasePattern : mlir::ConvertOpToLLVMPattern< O > - { - using Base = mlir::ConvertOpToLLVMPattern< O >; - - conv::tc::LLVMTypeConverter &tc; - - BasePattern(conv::tc::LLVMTypeConverter &tc_) : Base(tc_), tc(tc_) {} - conv::tc::LLVMTypeConverter &type_converter() const { return tc; } - }; - - struct vardecl_op : BasePattern< hl::VarDeclOp > - { - using op_t = hl::VarDeclOp; - using Base = BasePattern< op_t >; - using Base::Base; - - mlir::LogicalResult matchAndRewrite( - op_t op, typename op_t::Adaptor ops, - conversion_rewriter &rewriter) const override - { - auto trg_type = op.getType(); - - auto uninit_var = rewriter.create< ll::UninitializedVar >(op.getLoc(), - trg_type); - - if (op.getInitializer().empty()) - { - rewriter.replaceOp(op, uninit_var); - return mlir::success(); - } - - auto yield = inline_init_region< hl::ValueYieldOp >(op, rewriter); - rewriter.setInsertionPointAfter(yield); - auto initialize = rewriter.create< ll::InitializeVar >( - yield.getLoc(), - trg_type, - uninit_var, yield.getResult()); - - rewriter.replaceOp(op, initialize); - rewriter.eraseOp(yield); - - return mlir::success(); - } - }; - - } // namespace pattern - - struct HLToLLVarsPass : HLToLLVarsBase< HLToLLVarsPass > - { - void runOnOperation() override - { - auto op = this->getOperation(); - auto &mctx = this->getContext(); - - mlir::ConversionTarget trg(mctx); - trg.markUnknownOpDynamicallyLegal( [](auto) { return true; } ); - trg.addDynamicallyLegalOp< hl::VarDeclOp >([&](hl::VarDeclOp op) - { - // TODO(conv): `!ast_node->isLocalVarDeclOrParam()` should maybe be ported - // to the mlir op? - return mlir::isa< core::module >(op->getParentOp()); - }); - - const auto &dl_analysis = this->getAnalysis< mlir::DataLayoutAnalysis >(); - - mlir::LowerToLLVMOptions llvm_options(&mctx); - llvm_options.useBarePtrCallConv = true; - conv::tc::LLVMTypeConverter type_converter(&mctx, llvm_options, &dl_analysis); - - mlir::RewritePatternSet patterns(&mctx); - - patterns.add< pattern::vardecl_op >(type_converter); - - if (mlir::failed(mlir::applyPartialConversion(op, trg, std::move(patterns)))) - return signalPassFailure(); - } - }; -} // namespace vast - - -std::unique_ptr< mlir::Pass > vast::createHLToLLVarsPass() -{ - return std::make_unique< vast::HLToLLVarsPass >(); -} From 9d55d784085f002a6adfd7c31c248f23fc2f9737 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 23:21:12 +0200 Subject: [PATCH 16/50] ll: Remove obsolete ArgAlloca as it is replaced by Cell now. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index 64dccd3999..5fd2bd7a4d 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -42,18 +42,6 @@ def LowLevel_Subscript }]; } -def LowLevel_ArgAlloca - : LowLevel_Op< "arg_alloca" > - , Arguments<(ins AnyType:$fn_arg)> - , Results<(outs AnyType:$result)> -{ - let summary = "Alloca that holds the function argument."; - - let assemblyFormat = [{ - operands attr-dict `:` functional-type(operands, results) - }]; -} - def LowLevel_Alloca : LowLevel_Op< "alloca" >, Results<(outs AnyType:$result)> From c7c7a36740e8680166e3415f093d2c37044af5a0 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 23:22:08 +0200 Subject: [PATCH 17/50] conv: Remove obsolete FnArgsToAllocaPass. --- include/vast/Conversion/Passes.hpp | 2 - include/vast/Conversion/Passes.td | 14 -- lib/vast/Conversion/FromHL/Passes.cpp | 5 - lib/vast/Conversion/Generic/CMakeLists.txt | 1 - .../Conversion/Generic/FnArgsToAlloca.cpp | 139 ------------------ 5 files changed, 161 deletions(-) delete mode 100644 lib/vast/Conversion/Generic/FnArgsToAlloca.cpp diff --git a/include/vast/Conversion/Passes.hpp b/include/vast/Conversion/Passes.hpp index 75ccef3cb3..3f94e20c55 100644 --- a/include/vast/Conversion/Passes.hpp +++ b/include/vast/Conversion/Passes.hpp @@ -57,8 +57,6 @@ namespace vast std::unique_ptr< mlir::Pass > createHLToHLBI(); - std::unique_ptr< mlir::Pass > createFnArgsToAllocaPass(); - std::unique_ptr< mlir::Pass > createLowerValueCategoriesPass(); // ToMem diff --git a/include/vast/Conversion/Passes.td b/include/vast/Conversion/Passes.td index 0500257319..eb5905ec78 100644 --- a/include/vast/Conversion/Passes.td +++ b/include/vast/Conversion/Passes.td @@ -65,20 +65,6 @@ def IRsToLLVM : Pass<"vast-irs-to-llvm", "mlir::ModuleOp"> { ]; } -def FnArgsToAlloca : Pass<"vast-fn-args-to-alloca", "core::ModuleOp"> { - let summary = "VAST to LLVM Dialect conversion"; - let description = [{ - For each function emit its prologue - for each argument make an alloca - and store the corresponding argument in it. - }]; - - let constructor = "vast::createFnArgsToAllocaPass()"; - let dependentDialects = [ - "vast::ll::LowLevelDialect", - "vast::core::CoreDialect" - ]; -} - def VarsToCells : Pass<"vast-vars-to-cells", "core::ModuleOp"> { let summary = "Lower `hl.var` into ssa-based `ll.cell`."; let description = [{ TBD }]; diff --git a/lib/vast/Conversion/FromHL/Passes.cpp b/lib/vast/Conversion/FromHL/Passes.cpp index 271b28a2d4..a6fc8cf81e 100644 --- a/lib/vast/Conversion/FromHL/Passes.cpp +++ b/lib/vast/Conversion/FromHL/Passes.cpp @@ -35,10 +35,6 @@ namespace vast::conv::pipeline { return pass(createHLToLLFuncPass); } - pipeline_step_ptr fn_args_to_alloca() { - return pass(createFnArgsToAllocaPass); - } - // FIXME: move to ToMem/Passes.cpp eventually pipeline_step_ptr vars_to_cells() { return pass(createVarsToCellsPass); @@ -67,7 +63,6 @@ namespace vast::conv::pipeline { hl_to_ll_func, hl_to_ll_cf, hl_to_ll_geps, - fn_args_to_alloca, lower_value_categories, lazy_regions ); diff --git a/lib/vast/Conversion/Generic/CMakeLists.txt b/lib/vast/Conversion/Generic/CMakeLists.txt index 4dcdc48f3b..3319f4a481 100644 --- a/lib/vast/Conversion/Generic/CMakeLists.txt +++ b/lib/vast/Conversion/Generic/CMakeLists.txt @@ -1,6 +1,5 @@ # Copyright (c) 2024-present, Trail of Bits, Inc. add_vast_conversion_library(GenericConversionPasses - FnArgsToAlloca.cpp LowerValueCategories.cpp ) diff --git a/lib/vast/Conversion/Generic/FnArgsToAlloca.cpp b/lib/vast/Conversion/Generic/FnArgsToAlloca.cpp deleted file mode 100644 index a7cb1e509e..0000000000 --- a/lib/vast/Conversion/Generic/FnArgsToAlloca.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) 2021-present, Trail of Bits, Inc. - -#include "vast/Conversion/Passes.hpp" - -VAST_RELAX_WARNINGS -#include -#include -#include -VAST_UNRELAX_WARNINGS - -#include "../PassesDetails.hpp" - -#include "vast/Dialect/HighLevel/HighLevelTypes.hpp" - -#include "vast/Dialect/LowLevel/LowLevelOps.hpp" - -#include "vast/Util/Common.hpp" - -#include "vast/Conversion/Common/Mixins.hpp" -#include "vast/Conversion/TypeConverters/HLToStd.hpp" -#include "vast/Conversion/TypeConverters/TypeConvertingPattern.hpp" - -namespace vast::conv { - namespace { - struct strip_lvalue - : tc::base_type_converter - , tc::mixins< strip_lvalue > - , tc::CoreToStd< strip_lvalue > - { - mcontext_t &mctx; - - strip_lvalue(mcontext_t &mctx) : mctx(mctx) { init(); } - - auto convert_lvalue() { - return [&](hl::LValueType type) { - return Maybe(type.getElementType()) - .and_then(convert_type_to_type()) - .unwrap() - .template take_wrapped< maybe_type_t >(); - }; - } - - void init() { - addConversion([&](mlir_type t) { return t; }); - tc::CoreToStd< strip_lvalue >::init(); - addConversion(convert_lvalue()); - } - }; - - using strip_lvalue_pattern = tc::generic_type_converting_pattern< strip_lvalue >; - - } // namespace - - struct FnArgsToAllocaPass : FnArgsToAllocaBase< FnArgsToAllocaPass > - { - using base = FnArgsToAllocaBase< FnArgsToAllocaPass >; - - void runOnOperation() override { - auto root = getOperation(); - - // TODO(conv): It would be much better if this pass could run on - // `mlir::FunctionOpInterface` instead of module. - auto lower = [&](mlir::FunctionOpInterface fn) { lower_args_to_alloca(fn); }; - - root->walk(lower); - - // Now proceed to update function types by stripping lvalues - auto &mctx = getContext(); - - auto tc = strip_lvalue(mctx); - auto trg = mlir::ConversionTarget(mctx); - - auto is_fn = [&](operation op) { - auto as_fn = mlir::dyn_cast< mlir::FunctionOpInterface >(op); - if (!as_fn) { - return true; - } - - for (auto arg_type : as_fn.getArgumentTypes()) { - if (!tc.isLegal(arg_type)) { - return false; - } - } - return true; - }; - trg.markUnknownOpDynamicallyLegal(is_fn); - - mlir::RewritePatternSet patterns(&mctx); - patterns.add< strip_lvalue_pattern >(tc, mctx); - - if (mlir::failed(mlir::applyPartialConversion(root, trg, std::move(patterns)))) { - return signalPassFailure(); - } - } - - void arg_to_alloca(auto arg, auto &block, auto &bld) const { - if (!needs_lowering(arg)) { - return; - } - - auto lowered = - bld.template create< ll::ArgAlloca >(arg.getLoc(), arg.getType(), arg); - - arg.replaceAllUsesWith(lowered); - lowered->setOperand(0, arg); - } - - bool needs_lowering(auto arg) const { - for (auto user : arg.getUsers()) { - if (!mlir::isa< ll::ArgAlloca >(user)) { - return true; - } - } - return false; - } - - void lower_args_to_alloca(mlir::FunctionOpInterface fn) { - if (!fn || fn.empty()) { - return; - } - - auto &block = fn.front(); - if (!block.isEntryBlock()) { - return; - } - - // We don't care about guards - mlir::OpBuilder bld(&getContext()); - bld.setInsertionPointToStart(&block); - for (auto arg : block.getArguments()) { - arg_to_alloca(arg, block, bld); - } - } - }; -} // namespace vast::conv - -std::unique_ptr< mlir::Pass > vast::createFnArgsToAllocaPass() { - return std::make_unique< vast::conv::FnArgsToAllocaPass >(); -} From 8d2cb5ea7fdeed7ceb571927d2fef37ac838252d Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 23:22:45 +0200 Subject: [PATCH 18/50] conv:tomem: Add `hl::ParmVarDeclOp` to `ll::Cell` pattern. --- lib/vast/Conversion/ToMem/VarsToCells.cpp | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/vast/Conversion/ToMem/VarsToCells.cpp b/lib/vast/Conversion/ToMem/VarsToCells.cpp index 9d1798b7ec..e4d4ca6d8f 100644 --- a/lib/vast/Conversion/ToMem/VarsToCells.cpp +++ b/lib/vast/Conversion/ToMem/VarsToCells.cpp @@ -67,6 +67,32 @@ namespace vast::conv { } }; + struct param_to_cell : operation_conversion_pattern< hl::ParmVarDeclOp > + { + using base = operation_conversion_pattern< hl::ParmVarDeclOp >; + using base::base; + + using adaptor_t = hl::ParmVarDeclOp::Adaptor; + + logical_result matchAndRewrite( + hl::ParmVarDeclOp op, adaptor_t adaptor, conversion_rewriter &rewriter + ) const override { + auto param = op.getParam(); + auto type = param.getType(); + auto loc = op.getLoc(); + auto cell = rewriter.create< ll::Cell >(loc, type, op.getSymName()); + rewriter.create< ll::CellInit >(loc, type, cell, param); + rewriter.replaceOp(op, cell); + return mlir::success(); + } + + static void legalize(conversion_target &trg) { + base::legalize(trg); + trg.addLegalOp< ll::Cell >(); + trg.addLegalOp< ll::CellInit >(); + } + }; + } // namespace pattern struct VarsToCellsPass : ModuleConversionPassMixin< VarsToCellsPass, VarsToCellsBase > @@ -78,7 +104,9 @@ namespace vast::conv { } static void populate_conversions(auto &cfg) { + // TODO: Deal only with local variables base::populate_conversions< pattern::var_to_cell >(cfg); + base::populate_conversions< pattern::param_to_cell >(cfg); } }; From 0fa5c04d9a884f8e563cbb65ede9003c5a0ce680 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 23:24:11 +0200 Subject: [PATCH 19/50] conv: Remove obsolete Param to Alloca conversion. --- .../Conversion/Generic/LowerValueCategories.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/vast/Conversion/Generic/LowerValueCategories.cpp b/lib/vast/Conversion/Generic/LowerValueCategories.cpp index 685f37af69..d4cc16078c 100644 --- a/lib/vast/Conversion/Generic/LowerValueCategories.cpp +++ b/lib/vast/Conversion/Generic/LowerValueCategories.cpp @@ -193,20 +193,6 @@ namespace vast::conv { } }; - template< typename op_t > - struct with_store : memory_allocation< op_t > - { - using base = memory_allocation< op_t >; - - VAST_DEFINE_REWRITE { - auto allocation = this->allocate(op, rewriter); - this->initialize(allocation, ops.getOperands()[0], rewriter); - rewriter.replaceOp(op, allocation); - - return mlir::success(); - } - }; - template< typename op_t > struct as_load : base_pattern< op_t > { @@ -521,7 +507,6 @@ namespace vast::conv { auto trg = mlir::ConversionTarget(mctx); patterns.add< fallback >(tc, mctx); - patterns.add< with_store< ll::ArgAlloca > >(mctx, tc); patterns.add< store_and_forward_ptr< ll::InitializeVar > >(mctx, tc); patterns .add< ignore< hl::DeclRefOp >, ignore< hl::Deref >, ignore< hl::AddressOf > >( From 1f2ac1b24f7cb9e8c817aa1f2157de4a4e2aa419 Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 23:41:20 +0200 Subject: [PATCH 20/50] conv: Update ll::Var to ll::Cell patterns. --- .../Generic/LowerValueCategories.cpp | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/vast/Conversion/Generic/LowerValueCategories.cpp b/lib/vast/Conversion/Generic/LowerValueCategories.cpp index d4cc16078c..4b8c81d374 100644 --- a/lib/vast/Conversion/Generic/LowerValueCategories.cpp +++ b/lib/vast/Conversion/Generic/LowerValueCategories.cpp @@ -157,24 +157,6 @@ namespace vast::conv { auto type = this->tc.convert_type_to_type(op.getType()); return rewriter.template create< ll::Alloca >(op.getLoc(), *type); } - - auto initialize(auto allocation, mlir_value value, auto &rewriter) const { - return rewriter.template create< ll::Store >( - allocation.getLoc(), value, allocation - ); - } - }; - - template< typename op_t > - struct allocate_and_propagate : memory_allocation< op_t > - { - using base = memory_allocation< op_t >; - - VAST_DEFINE_REWRITE { - auto ptr = this->allocate(op, rewriter); - rewriter.replaceOp(op, ptr); - return mlir::success(); - } }; template< typename op_t > @@ -507,13 +489,13 @@ namespace vast::conv { auto trg = mlir::ConversionTarget(mctx); patterns.add< fallback >(tc, mctx); - patterns.add< store_and_forward_ptr< ll::InitializeVar > >(mctx, tc); + patterns.add< store_and_forward_ptr< ll::CellInit > >(mctx, tc); patterns .add< ignore< hl::DeclRefOp >, ignore< hl::Deref >, ignore< hl::AddressOf > >( mctx, tc ); - patterns.add< memory_allocation< ll::UninitializedVar > >(mctx, tc); + patterns.add< memory_allocation< ll::Cell > >(mctx, tc); patterns.add< subscript >(mctx, tc); // implicit casts @@ -541,8 +523,7 @@ namespace vast::conv { return op.getKind() != hl::CastKind::LValueToRValue && is_legal(op); }); - trg.addIllegalOp< - ll::InitializeVar, hl::PreIncOp, hl::PreDecOp, hl::PostIncOp, hl::PreIncOp >(); + trg.addIllegalOp< hl::PreIncOp, hl::PreDecOp, hl::PostIncOp, hl::PreIncOp >(); // This will never have correct types but we want to have it legal. trg.addLegalOp< mlir::UnrealizedConversionCastOp >(); From af152216a8d476442c6243d32eb6e15479cd3fbf Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 13 Sep 2024 23:44:37 +0200 Subject: [PATCH 21/50] conv:tollvm: Remove obsolete ll::Var conversions. --- lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp | 45 ------------------------ 1 file changed, 45 deletions(-) diff --git a/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp b/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp index b68170d460..eeb3468f0b 100644 --- a/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp +++ b/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp @@ -324,49 +324,6 @@ namespace vast::conv::irstollvm } }; - - struct uninit_var : base_pattern< ll::UninitializedVar > - { - using op_t = ll::UninitializedVar; - using base = base_pattern< op_t >; - using base::base; - - logical_result matchAndRewrite( - op_t op, typename op_t::Adaptor ops, - conversion_rewriter &rewriter) const override - { - auto et = converted_element_type(op.getType()); - auto alloca = mk_alloca(rewriter, convert(op.getType()), et, op.getLoc()); - rewriter.replaceOp(op, alloca); - - return logical_result::success(); - } - }; - - struct initialize_var : base_pattern< ll::InitializeVar >, - value_builder< initialize_var > - { - using op_t = ll::InitializeVar; - using base = base_pattern< op_t >; - using base::base; - - logical_result matchAndRewrite( - op_t op, typename op_t::Adaptor ops, - conversion_rewriter &rewriter) const override - { - auto element = this->construct_value(rewriter, ops.getElements()[0]); - auto ptr = ops.getVar(); - - rewriter.template create< LLVM::StoreOp >( - element.getLoc(), - element, - ptr); - rewriter.replaceOp(op, ptr); - - return logical_result::success(); - } - }; - struct init_list_expr : base_pattern< hl::InitListExpr >, value_builder< init_list_expr > { @@ -457,8 +414,6 @@ namespace vast::conv::irstollvm }; using init_conversions = util::type_list< - uninit_var, - initialize_var, init_list_expr, vardecl, global_ref From be1de8ce860189baa8160207c02c612f1dcc6ccc Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 10:29:15 +0200 Subject: [PATCH 22/50] treewide: Rename ModuleConversionPassMixin to more generic ConversionPassMixin. --- include/vast/Conversion/Common/Mixins.hpp | 16 ++++++++-------- lib/vast/Conversion/ABI/LowerABI.cpp | 4 ++-- lib/vast/Conversion/Core/ToLLVM.cpp | 4 ++-- lib/vast/Conversion/FromHL/EmitLazyRegions.cpp | 4 ++-- lib/vast/Conversion/FromHL/ToHLBI.cpp | 4 ++-- lib/vast/Conversion/FromHL/ToLLCF.cpp | 4 ++-- lib/vast/Conversion/FromHL/ToLLFunc.cpp | 4 ++-- lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp | 4 ++-- lib/vast/Conversion/ToMem/RefsToSSA.cpp | 4 ++-- lib/vast/Conversion/ToMem/VarsToCells.cpp | 4 ++-- .../Transforms/LowerElaboratedTypes.cpp | 2 +- .../HighLevel/Transforms/LowerTypeDefs.cpp | 2 +- 12 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/vast/Conversion/Common/Mixins.hpp b/include/vast/Conversion/Common/Mixins.hpp index 4cda960435..ffdbb7cff2 100644 --- a/include/vast/Conversion/Common/Mixins.hpp +++ b/include/vast/Conversion/Common/Mixins.hpp @@ -110,7 +110,7 @@ namespace vast { // base class for module conversion passes providing common functionality // template< typename derived, template< typename > typename base > - struct ModuleConversionPassMixinBase + struct ConversionPassMixinBase : base< derived > , populate_patterns< derived > { @@ -165,8 +165,8 @@ namespace vast { // // Example usage: // - // struct ExamplePass : ModuleConversionPassMixin { - // using base = ModuleConversionPassMixin; + // struct ExamplePass : ConversionPassMixin { + // using base = ConversionPassMixin; // // static conversion_target create_conversion_target(mcontext_t &context) { // conversion_target target(context); @@ -182,7 +182,7 @@ namespace vast { // } // template< typename derived, template< typename > typename base > - struct ModuleConversionPassMixin : ModuleConversionPassMixinBase< derived, base > + struct ConversionPassMixin : ConversionPassMixinBase< derived, base > { base_conversion_config make_config() { auto &ctx = this->getContext(); @@ -196,8 +196,8 @@ namespace vast { // // Example usage: // - // struct ExamplePass : ModuleLLVMConversionPassMixin { - // using base = ModuleLLVMConversionPassMixin; + // struct ExamplePass : LLVMConversionPassMixin { + // using base = LLVMConversionPassMixin; // // static conversion_target create_conversion_target(mcontest_t &context) { // conversion_target target(context); @@ -213,8 +213,8 @@ namespace vast { // } // template< typename derived, template< typename > typename base > - struct ModuleLLVMConversionPassMixin - : ModuleConversionPassMixinBase< derived, base > + struct LLVMConversionPassMixin + : ConversionPassMixinBase< derived, base > { std::shared_ptr< llvm_type_converter > tc; diff --git a/lib/vast/Conversion/ABI/LowerABI.cpp b/lib/vast/Conversion/ABI/LowerABI.cpp index e88a12c3e2..1bb33604e7 100644 --- a/lib/vast/Conversion/ABI/LowerABI.cpp +++ b/lib/vast/Conversion/ABI/LowerABI.cpp @@ -556,9 +556,9 @@ namespace vast } // namespace } // namespace pattern - struct LowerABI : ModuleConversionPassMixin< LowerABI, LowerABIBase > + struct LowerABI : ConversionPassMixin< LowerABI, LowerABIBase > { - using base = ModuleConversionPassMixin< LowerABI, LowerABIBase >; + using base = ConversionPassMixin< LowerABI, LowerABIBase >; static conversion_target create_conversion_target(mcontext_t &context) { conversion_target target(context); diff --git a/lib/vast/Conversion/Core/ToLLVM.cpp b/lib/vast/Conversion/Core/ToLLVM.cpp index 43cc2313f5..99ba239071 100644 --- a/lib/vast/Conversion/Core/ToLLVM.cpp +++ b/lib/vast/Conversion/Core/ToLLVM.cpp @@ -259,9 +259,9 @@ namespace vast } //namespace pattern - struct CoreToLLVMPass : ModuleConversionPassMixin< CoreToLLVMPass, CoreToLLVMBase > + struct CoreToLLVMPass : ConversionPassMixin< CoreToLLVMPass, CoreToLLVMBase > { - using base = ModuleConversionPassMixin< CoreToLLVMPass, CoreToLLVMBase >; + using base = ConversionPassMixin< CoreToLLVMPass, CoreToLLVMBase >; static conversion_target create_conversion_target(mcontext_t &context) { conversion_target target(context); diff --git a/lib/vast/Conversion/FromHL/EmitLazyRegions.cpp b/lib/vast/Conversion/FromHL/EmitLazyRegions.cpp index 2cfc2cc410..75e2c8f6d8 100644 --- a/lib/vast/Conversion/FromHL/EmitLazyRegions.cpp +++ b/lib/vast/Conversion/FromHL/EmitLazyRegions.cpp @@ -125,9 +125,9 @@ namespace vast >; struct HLEmitLazyRegionsPass - : ModuleConversionPassMixin< HLEmitLazyRegionsPass, HLEmitLazyRegionsBase > + : ConversionPassMixin< HLEmitLazyRegionsPass, HLEmitLazyRegionsBase > { - using base = ModuleConversionPassMixin< HLEmitLazyRegionsPass, HLEmitLazyRegionsBase >; + using base = ConversionPassMixin< HLEmitLazyRegionsPass, HLEmitLazyRegionsBase >; static conversion_target create_conversion_target(mcontext_t &context) { conversion_target target(context); diff --git a/lib/vast/Conversion/FromHL/ToHLBI.cpp b/lib/vast/Conversion/FromHL/ToHLBI.cpp index 30f7efca9a..1a314ea538 100644 --- a/lib/vast/Conversion/FromHL/ToHLBI.cpp +++ b/lib/vast/Conversion/FromHL/ToHLBI.cpp @@ -407,9 +407,9 @@ namespace vast::conv { } }; - struct HLToHLBIPass : ModuleConversionPassMixin< HLToHLBIPass, HLToHLBIBase > + struct HLToHLBIPass : ConversionPassMixin< HLToHLBIPass, HLToHLBIBase > { - using base = ModuleConversionPassMixin< HLToHLBIPass, HLToHLBIBase >; + using base = ConversionPassMixin< HLToHLBIPass, HLToHLBIBase >; static conversion_target create_conversion_target(mcontext_t &context) { conversion_target target(context); diff --git a/lib/vast/Conversion/FromHL/ToLLCF.cpp b/lib/vast/Conversion/FromHL/ToLLCF.cpp index a948262f65..4f609a9565 100644 --- a/lib/vast/Conversion/FromHL/ToLLCF.cpp +++ b/lib/vast/Conversion/FromHL/ToLLCF.cpp @@ -497,9 +497,9 @@ namespace vast::conv { } // namespace pattern - struct HLToLLCF : ModuleConversionPassMixin< HLToLLCF, HLToLLCFBase > + struct HLToLLCF : ConversionPassMixin< HLToLLCF, HLToLLCFBase > { - using base = ModuleConversionPassMixin< HLToLLCF, HLToLLCFBase >; + using base = ConversionPassMixin< HLToLLCF, HLToLLCFBase >; static auto create_conversion_target(mcontext_t &mctx) { mlir::ConversionTarget trg(mctx); diff --git a/lib/vast/Conversion/FromHL/ToLLFunc.cpp b/lib/vast/Conversion/FromHL/ToLLFunc.cpp index 6d15ba0b07..c5c3b6a34b 100644 --- a/lib/vast/Conversion/FromHL/ToLLFunc.cpp +++ b/lib/vast/Conversion/FromHL/ToLLFunc.cpp @@ -31,9 +31,9 @@ namespace vast::conv::hltollfunc }; } // namespace pattern - struct HLToLLFunc : ModuleConversionPassMixin< HLToLLFunc, HLToLLFuncBase > + struct HLToLLFunc : ConversionPassMixin< HLToLLFunc, HLToLLFuncBase > { - using base = ModuleConversionPassMixin< HLToLLFunc, HLToLLFuncBase >; + using base = ConversionPassMixin< HLToLLFunc, HLToLLFuncBase >; static conversion_target create_conversion_target(mcontext_t &context) { return { context }; diff --git a/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp b/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp index eeb3468f0b..99141c59b9 100644 --- a/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp +++ b/lib/vast/Conversion/ToLLVM/IRsToLLVM.cpp @@ -1502,9 +1502,9 @@ namespace vast::conv::irstollvm ll_alloca >; - struct IRsToLLVMPass : ModuleLLVMConversionPassMixin< IRsToLLVMPass, IRsToLLVMBase > + struct IRsToLLVMPass : LLVMConversionPassMixin< IRsToLLVMPass, IRsToLLVMBase > { - using base = ModuleLLVMConversionPassMixin< IRsToLLVMPass, IRsToLLVMBase >; + using base = LLVMConversionPassMixin< IRsToLLVMPass, IRsToLLVMBase >; static conversion_target create_conversion_target(mcontext_t &context, auto &tc) { conversion_target target(context); diff --git a/lib/vast/Conversion/ToMem/RefsToSSA.cpp b/lib/vast/Conversion/ToMem/RefsToSSA.cpp index 365217bbb8..ee5af34844 100644 --- a/lib/vast/Conversion/ToMem/RefsToSSA.cpp +++ b/lib/vast/Conversion/ToMem/RefsToSSA.cpp @@ -47,9 +47,9 @@ namespace vast::conv { } // namespace pattern - struct RefsToSSAPass : ModuleConversionPassMixin< RefsToSSAPass, RefsToSSABase > + struct RefsToSSAPass : ConversionPassMixin< RefsToSSAPass, RefsToSSABase > { - using base = ModuleConversionPassMixin< RefsToSSAPass, RefsToSSABase >; + using base = ConversionPassMixin< RefsToSSAPass, RefsToSSABase >; static conversion_target create_conversion_target(mcontext_t &mctx) { return conversion_target(mctx); diff --git a/lib/vast/Conversion/ToMem/VarsToCells.cpp b/lib/vast/Conversion/ToMem/VarsToCells.cpp index e4d4ca6d8f..627149b7b4 100644 --- a/lib/vast/Conversion/ToMem/VarsToCells.cpp +++ b/lib/vast/Conversion/ToMem/VarsToCells.cpp @@ -95,9 +95,9 @@ namespace vast::conv { } // namespace pattern - struct VarsToCellsPass : ModuleConversionPassMixin< VarsToCellsPass, VarsToCellsBase > + struct VarsToCellsPass : ConversionPassMixin< VarsToCellsPass, VarsToCellsBase > { - using base = ModuleConversionPassMixin< VarsToCellsPass, VarsToCellsBase >; + using base = ConversionPassMixin< VarsToCellsPass, VarsToCellsBase >; static conversion_target create_conversion_target(mcontext_t &mctx) { return conversion_target(mctx); diff --git a/lib/vast/Dialect/HighLevel/Transforms/LowerElaboratedTypes.cpp b/lib/vast/Dialect/HighLevel/Transforms/LowerElaboratedTypes.cpp index ecf3f0edd2..4e15e0bde3 100644 --- a/lib/vast/Dialect/HighLevel/Transforms/LowerElaboratedTypes.cpp +++ b/lib/vast/Dialect/HighLevel/Transforms/LowerElaboratedTypes.cpp @@ -69,7 +69,7 @@ namespace vast::hl { } // namespace pattern } // namespace - struct LowerElaboratedTypes : ModuleConversionPassMixin< LowerElaboratedTypes, LowerElaboratedTypesBase > + struct LowerElaboratedTypes : ConversionPassMixin< LowerElaboratedTypes, LowerElaboratedTypesBase > { static auto create_conversion_target(mcontext_t &mctx) { mlir::ConversionTarget trg(mctx); diff --git a/lib/vast/Dialect/HighLevel/Transforms/LowerTypeDefs.cpp b/lib/vast/Dialect/HighLevel/Transforms/LowerTypeDefs.cpp index 8961263509..94e48e2ddf 100644 --- a/lib/vast/Dialect/HighLevel/Transforms/LowerTypeDefs.cpp +++ b/lib/vast/Dialect/HighLevel/Transforms/LowerTypeDefs.cpp @@ -92,7 +92,7 @@ namespace vast::hl { } // namespace pattern } // namespace - struct LowerTypeDefs : ModuleConversionPassMixin< LowerTypeDefs, LowerTypeDefsBase > + struct LowerTypeDefs : ConversionPassMixin< LowerTypeDefs, LowerTypeDefsBase > { static auto create_conversion_target(mcontext_t &mctx) { mlir::ConversionTarget trg(mctx); From 6f4a69b933ab7fe682aaddf1252e11d95e5bb779 Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 13:31:41 +0200 Subject: [PATCH 23/50] conv: Refactor function conversion utilities. --- .../Conversion/TypeConverters/HLToStd.hpp | 71 ++++++++----------- .../TypeConverters/TypeConverter.hpp | 59 +++++++-------- .../TypeConverters/TypeConvertingPattern.hpp | 11 ++- .../Generic/LowerValueCategories.cpp | 59 +++++++-------- .../HighLevel/Transforms/HLLowerTypes.cpp | 2 +- 5 files changed, 89 insertions(+), 113 deletions(-) diff --git a/include/vast/Conversion/TypeConverters/HLToStd.hpp b/include/vast/Conversion/TypeConverters/HLToStd.hpp index ea08ebe329..5687ca97ab 100644 --- a/include/vast/Conversion/TypeConverters/HLToStd.hpp +++ b/include/vast/Conversion/TypeConverters/HLToStd.hpp @@ -28,27 +28,25 @@ namespace vast::conv::tc { // Requires of `self_t` // * inherits/implements `mixins` // * implements `int_type()` - template< typename self_t > - struct HLAggregates + template< typename derived > + struct aggregates_type_converter + : gap::core::crtp< derived, aggregates_type_converter > { - private: - const self_t &self() const { return static_cast< const self_t & >(*this); } - self_t &self() { return static_cast< self_t & >(*this); } - - public: + using base = gap::core::crtp< derived, aggregates_type_converter >; + using base::underlying; // This is not a ctor so that users can position it as they want // in their initialization. void init() { - self().addConversion(convert_decayed_type()); - self().addConversion(convert_lvalue_type()); - self().addConversion(convert_pointer_type()); - self().addConversion(convert_paren_type()); + underlying().addConversion(convert_decayed_type()); + underlying().addConversion(convert_lvalue_type()); + underlying().addConversion(convert_pointer_type()); + underlying().addConversion(convert_paren_type()); } auto convert_decayed_type() { return [&](hl::DecayedType type) { return Maybe(type.getElementType()) - .and_then(self().convert_type_to_type()) + .and_then(underlying().convert_type_to_type()) .unwrap() .template take_wrapped< maybe_type_t >(); }; @@ -57,9 +55,9 @@ namespace vast::conv::tc { auto convert_lvalue_type() { return [&](hl::LValueType type) { return Maybe(type.getElementType()) - .and_then(self().convert_type_to_type()) + .and_then(underlying().convert_type_to_type()) .unwrap() - .and_then(self().template make_aggregate_type< hl::LValueType >()) + .and_then(underlying().template make_aggregate_type< hl::LValueType >()) .template take_wrapped< maybe_type_t >(); }; } @@ -69,9 +67,9 @@ namespace vast::conv::tc { using raw = hl::PointerType; return Maybe(type.getElementType()) - .and_then(self().convert_pointer_element_type()) + .and_then(underlying().convert_pointer_element_type()) .unwrap() - .and_then(self().template make_aggregate_type< raw >(type.getQuals())) + .and_then(underlying().template make_aggregate_type< raw >(type.getQuals())) .template take_wrapped< maybe_type_t >(); }; } @@ -79,7 +77,7 @@ namespace vast::conv::tc { auto convert_paren_type() { return [&](hl::ParenType type) { return Maybe(type.getElementType()) - .and_then(self().convert_type_to_type()) + .and_then(underlying().convert_type_to_type()) .unwrap() .template take_wrapped< maybe_type_t >(); }; @@ -90,9 +88,9 @@ namespace vast::conv::tc { return [&](auto t) -> maybe_type_t { if (t.template isa< hl::VoidType >()) { auto sign = mlir::IntegerType::SignednessSemantics::Signless; - return self().int_type(8u, sign); + return underlying().int_type(8u, sign); } - return self().convert_type_to_type(t); + return underlying().convert_type_to_type(t); }; } @@ -105,33 +103,23 @@ namespace vast::conv::tc { } }; - template< typename self_t > - struct CoreToStd : ConvertFunctionType< self_t > - { - private: - const self_t &self() const { return static_cast< const self_t & >(*this); } - self_t &self() { return static_cast< self_t & >(*this); } - - public: - void init() { self().addConversion(this->template convert_fn_type< core::FunctionType >()); } - }; - - struct HLToStd + struct high_level_to_std_type_converter : base_type_converter - , mixins< HLToStd > - , HLAggregates< HLToStd > - , CoreToStd< HLToStd > + , mixins< high_level_to_std_type_converter > + , aggregates_type_converter< high_level_to_std_type_converter > + , function_type_converter< high_level_to_std_type_converter > { - using Base = mixins< HLToStd >; - using Base::convert_type; - using Base::convert_type_to_type; - using Base::convert_type_to_types; + using base = mixins< high_level_to_std_type_converter >; + using base::convert_type; + using base::convert_type_to_type; + using base::convert_type_to_types; const mlir::DataLayout &dl; mlir::MLIRContext &mctx; - HLToStd(const mlir::DataLayout &dl, mcontext_t &mctx) - : base_type_converter(), dl(dl), mctx(mctx) { + high_level_to_std_type_converter(const mlir::DataLayout &dl, mcontext_t &mctx) + : base_type_converter(), dl(dl), mctx(mctx) + { // Fallthrough option - we define it first as it seems the framework // goes from the last added conversion. addConversion([&](mlir_type t) -> maybe_type_t { @@ -148,8 +136,7 @@ namespace vast::conv::tc { return { mlir::NoneType::get(&mctx) }; }); - HLAggregates< HLToStd >::init(); - CoreToStd< HLToStd >::init(); + aggregates_type_converter< high_level_to_std_type_converter >::init(); } maybe_types_t convert_type(mlir_type t) { diff --git a/include/vast/Conversion/TypeConverters/TypeConverter.hpp b/include/vast/Conversion/TypeConverters/TypeConverter.hpp index 8a884bd4c5..337d1305ff 100644 --- a/include/vast/Conversion/TypeConverters/TypeConverter.hpp +++ b/include/vast/Conversion/TypeConverters/TypeConverter.hpp @@ -10,6 +10,8 @@ VAST_RELAX_WARNINGS #include VAST_UNRELAX_WARNINGS +#include + #include "vast/Dialect/Core/CoreTypes.hpp" #include "vast/Dialect/HighLevel/HighLevelDialect.hpp" @@ -19,9 +21,12 @@ VAST_UNRELAX_WARNINGS #include "vast/Util/TypeUtils.hpp" namespace vast::conv::tc { + using signature_conversion_t = mlir::TypeConverter::SignatureConversion; using maybe_signature_conversion_t = std::optional< signature_conversion_t >; + using core_function_type = core::FunctionType; + struct base_type_converter : mlir::TypeConverter { using base = mlir::TypeConverter; @@ -48,6 +53,31 @@ namespace vast::conv::tc { } }; + template< typename derived > + struct function_type_converter : gap::core::crtp< derived, function_type_converter > + { + using base = gap::core::crtp< derived, function_type_converter >; + using base::underlying; + + function_type_converter() { + underlying().addConversion([&](core_function_type t) -> maybe_type_t { + auto [sig, results] = std::make_tuple( + underlying().signature_conversion(t.getInputs()), + underlying().convert_types_to_types(t.getResults()) + ); + + if (!sig || !results) { + return std::nullopt; + } + + return core_function_type::get( + t.getContext(), sig->getConvertedTypes(), *results, + t.isVarArg() + ); + }); + } + }; + struct type_converter_with_dl : base_type_converter { using base = base_type_converter; @@ -222,33 +252,4 @@ namespace vast::conv::tc { }; } - template< typename self_t > - struct ConvertFunctionType - { - private: - const self_t &self() const { return static_cast< const self_t & >(*this); } - self_t &self() { return static_cast< self_t & >(*this); } - - public: - template< typename fn_t > - auto convert_fn_type() { - return [&](fn_t t) -> maybe_type_t { - // To be consistent with how others use the conversion, we - // do not convert input types directly. - auto signature_conversion = self().signature_conversion(t.getInputs()); - - auto results = self().convert_types_to_types(t.getResults()); - - if (!signature_conversion || !results) { - return {}; - } - - return { fn_t::get( - t.getContext(), signature_conversion->getConvertedTypes(), *results, - t.isVarArg() - ) }; - }; - } - - }; } // namespace vast::conv::tc diff --git a/include/vast/Conversion/TypeConverters/TypeConvertingPattern.hpp b/include/vast/Conversion/TypeConverters/TypeConvertingPattern.hpp index 1c620fbe75..1b167f379e 100644 --- a/include/vast/Conversion/TypeConverters/TypeConvertingPattern.hpp +++ b/include/vast/Conversion/TypeConverters/TypeConvertingPattern.hpp @@ -33,9 +33,10 @@ namespace vast::conv::tc { // TODO(conv:tc): This should probably be some interface instead, since // we are only updating the root? - logical_result replace(mlir::FunctionOpInterface fn, - auto &rewriter) const - { + logical_result replace( + mlir::FunctionOpInterface fn, + auto &rewriter + ) const { auto old_type = fn.getFunctionType(); auto trg_type = get_type_converter().convert_type_to_type(old_type); VAST_CHECK(trg_type, "Type conversion failed for {0}", old_type); @@ -65,8 +66,7 @@ namespace vast::conv::tc { replacer.addReplacement(conv::tc::convert_data_layout_attrs(tc)); replacer.addReplacement(conv::tc::convert_string_attr(tc)); - replacer.addReplacement([&](mlir_type t) { return tc.convert_type_to_type(t); } - ); + replacer.addReplacement([&](mlir_type t) { return tc.convert_type_to_type(t); }); replacer.recursivelyReplaceElementsIn( op @@ -82,7 +82,6 @@ namespace vast::conv::tc { }; rewriter.modifyOpInPlace(op, update); - return mlir::success(); } diff --git a/lib/vast/Conversion/Generic/LowerValueCategories.cpp b/lib/vast/Conversion/Generic/LowerValueCategories.cpp index 4b8c81d374..a981265767 100644 --- a/lib/vast/Conversion/Generic/LowerValueCategories.cpp +++ b/lib/vast/Conversion/Generic/LowerValueCategories.cpp @@ -26,51 +26,21 @@ VAST_UNRELAX_WARNINGS namespace vast::conv { namespace { struct value_category_type_converter - : tc::base_type_converter + : tc::identity_type_converter , tc::mixins< value_category_type_converter > - , tc::ConvertFunctionType< value_category_type_converter > + , tc::function_type_converter< value_category_type_converter > { mlir::MLIRContext &mctx; // Do we need data layout? Probably not as everything should be explicit // type size wise. value_category_type_converter(mcontext_t &mctx) : mctx(mctx) { - init(); - - addConversion(this->template convert_fn_type< core::FunctionType >()); - } - - using mixin_base = tc::mixins< value_category_type_converter >; - using mixin_base::convert_type_to_type; - using mixin_base::convert_type_to_types; - - template< typename T, typename... Args > - auto make_aggregate_type(Args... args) { - return [=](mlir_type elem) { return T::get(elem.getContext(), elem, args...); }; - } - - auto convert_lvalue_type() { - return [&](hl::LValueType type) { - return Maybe(type.getElementType()) - .and_then(convert_type_to_type()) - .unwrap() - .and_then(make_aggregate_type< hl::PointerType >()) - .template take_wrapped< maybe_type_t >(); - }; - } - - template< typename T > - auto pointerlike_as_memref() { - return [&](T type) { + addConversion([&](mlir_type t) { return t; }); + addConversion([&](hl::LValueType type) { // It should never happen that we have nested lvalues? auto element_type = this->convert_type_to_type(type.getElementType()); return hl::PointerType::get(&mctx, *element_type); - }; - } - - void init() { - addConversion([&](mlir_type t) { return t; }); - addConversion(pointerlike_as_memref< hl::LValueType >()); + }); addTargetMaterialization( [&](mlir::OpBuilder &builder, mlir::Type resultType, mlir::ValueRange inputs, mlir::Location loc) -> std::optional< Value > { @@ -96,6 +66,25 @@ namespace vast::conv { } ); } + + using mixin_base = tc::mixins< value_category_type_converter >; + using mixin_base::convert_type_to_type; + using mixin_base::convert_type_to_types; + + template< typename T, typename... Args > + auto make_aggregate_type(Args... args) { + return [=](mlir_type elem) { return T::get(elem.getContext(), elem, args...); }; + } + + auto convert_lvalue_type() { + return [&](hl::LValueType type) { + return Maybe(type.getElementType()) + .and_then(convert_type_to_type()) + .unwrap() + .and_then(make_aggregate_type< hl::PointerType >()) + .template take_wrapped< maybe_type_t >(); + }; + } }; #define VAST_DEFINE_REWRITE \ diff --git a/lib/vast/Dialect/HighLevel/Transforms/HLLowerTypes.cpp b/lib/vast/Dialect/HighLevel/Transforms/HLLowerTypes.cpp index be254405ca..b4cef03593 100644 --- a/lib/vast/Dialect/HighLevel/Transforms/HLLowerTypes.cpp +++ b/lib/vast/Dialect/HighLevel/Transforms/HLLowerTypes.cpp @@ -34,7 +34,7 @@ VAST_UNRELAX_WARNINGS namespace vast::hl { - using type_converter_t = conv::tc::HLToStd; + using type_converter_t = conv::tc::high_level_to_std_type_converter; namespace pattern { using lower_type = conv::tc::generic_type_converting_pattern< type_converter_t >; From ad2bdaffbe57b0f047daffe28c188030eb2b0f6b Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 13:53:39 +0200 Subject: [PATCH 24/50] conv:tomem: Implement StripParamLValuesPass. --- include/vast/Conversion/Passes.hpp | 2 + include/vast/Conversion/Passes.td | 23 +++-- lib/vast/Conversion/FromHL/Passes.cpp | 10 ++- lib/vast/Conversion/ToMem/CMakeLists.txt | 1 + .../Conversion/ToMem/StripParamLValues.cpp | 86 +++++++++++++++++++ 5 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 lib/vast/Conversion/ToMem/StripParamLValues.cpp diff --git a/include/vast/Conversion/Passes.hpp b/include/vast/Conversion/Passes.hpp index 3f94e20c55..b9474b6efc 100644 --- a/include/vast/Conversion/Passes.hpp +++ b/include/vast/Conversion/Passes.hpp @@ -62,6 +62,8 @@ namespace vast // ToMem std::unique_ptr< mlir::Pass > createRefsToSSAPass(); + std::unique_ptr< mlir::Pass > createStripParamLValuesPass(); + std::unique_ptr< mlir::Pass > createVarsToCellsPass(); // Generate the code for registering passes. diff --git a/include/vast/Conversion/Passes.td b/include/vast/Conversion/Passes.td index eb5905ec78..765a23058f 100644 --- a/include/vast/Conversion/Passes.td +++ b/include/vast/Conversion/Passes.td @@ -65,28 +65,39 @@ def IRsToLLVM : Pass<"vast-irs-to-llvm", "mlir::ModuleOp"> { ]; } -def VarsToCells : Pass<"vast-vars-to-cells", "core::ModuleOp"> { - let summary = "Lower `hl.var` into ssa-based `ll.cell`."; +def RefsToSSA : Pass<"vast-refs-to-ssa", "core::ModuleOp"> { + let summary = "Lower `hl.ref` into ssa-based `ll.cell`."; let description = [{ TBD }]; - let constructor = "vast::createVarsToCellsPass()"; + let constructor = "vast::createRefsToSSAPass()"; let dependentDialects = [ "vast::ll::LowLevelDialect", "vast::hl::HighLevelDialect", ]; } -def RefsToSSA : Pass<"vast-refs-to-ssa", "core::ModuleOp"> { - let summary = "Lower `hl.ref` into ssa-based `ll.cell`."; +def StripParamLValues : Pass<"vast-strip-param-lvalues", "core::ModuleOp"> { + let summary = "Strip `hl.lvalue` from types in the module."; let description = [{ TBD }]; - let constructor = "vast::createRefsToSSAPass()"; + let constructor = "vast::createStripParamLValuesPass()"; + let dependentDialects = [ + "vast::hl::HighLevelDialect", + ]; +} + +def VarsToCells : Pass<"vast-vars-to-cells", "core::ModuleOp"> { + let summary = "Lower `hl.var` into ssa-based `ll.cell`."; + let description = [{ TBD }]; + + let constructor = "vast::createVarsToCellsPass()"; let dependentDialects = [ "vast::ll::LowLevelDialect", "vast::hl::HighLevelDialect", ]; } + def LowerValueCategories : Pass<"vast-lower-value-categories", "core::ModuleOp"> { let summary = "Lower `hl.lvalue` into explicit pointers and loads."; let description = [{ diff --git a/lib/vast/Conversion/FromHL/Passes.cpp b/lib/vast/Conversion/FromHL/Passes.cpp index a6fc8cf81e..00164b7f59 100644 --- a/lib/vast/Conversion/FromHL/Passes.cpp +++ b/lib/vast/Conversion/FromHL/Passes.cpp @@ -9,6 +9,8 @@ VAST_UNRELAX_WARNINGS #include "vast/Conversion/Passes.hpp" +#include "vast/Dialect/LowLevel/LowLevelOps.hpp" + namespace vast::conv::pipeline { pipeline_step_ptr to_hlbi() { @@ -45,10 +47,16 @@ namespace vast::conv::pipeline { .depends_on(vars_to_cells); } + // FIXME: run on hl.FuncOp. Once we remove graph regions ll::FuncOp is no longer needed + pipeline_step_ptr strip_param_lvalues() { + return pass(createStripParamLValuesPass); + } + pipeline_step_ptr to_mem() { return compose("to-mem", vars_to_cells, - refs_to_ssa + refs_to_ssa, + strip_param_lvalues ); } diff --git a/lib/vast/Conversion/ToMem/CMakeLists.txt b/lib/vast/Conversion/ToMem/CMakeLists.txt index fa23436af6..2e1ac897ed 100644 --- a/lib/vast/Conversion/ToMem/CMakeLists.txt +++ b/lib/vast/Conversion/ToMem/CMakeLists.txt @@ -2,5 +2,6 @@ add_vast_conversion_library(ToMemConversionPasses RefsToSSA.cpp + StripParamLValues.cpp VarsToCells.cpp ) diff --git a/lib/vast/Conversion/ToMem/StripParamLValues.cpp b/lib/vast/Conversion/ToMem/StripParamLValues.cpp new file mode 100644 index 0000000000..9932e4f2fc --- /dev/null +++ b/lib/vast/Conversion/ToMem/StripParamLValues.cpp @@ -0,0 +1,86 @@ +// Copyright (c) 2024-present, Trail of Bits, Inc. + +#include "vast/Conversion/Passes.hpp" + +VAST_RELAX_WARNINGS +#include +#include +#include +VAST_UNRELAX_WARNINGS + +#include "../PassesDetails.hpp" + +#include "vast/Dialect/LowLevel/LowLevelOps.hpp" + +#include "vast/Util/Common.hpp" +#include "vast/Conversion/Common/Mixins.hpp" +#include "vast/Conversion/Common/Patterns.hpp" +#include "vast/Conversion/TypeConverters/TypeConvertingPattern.hpp" +#include "vast/Conversion/TypeConverters/HLToStd.hpp" + +#include + +namespace rns = std::ranges; + +namespace vast::conv { + + struct strip_param_lvalue_type_converter + : tc::identity_type_converter + , tc::mixins< strip_param_lvalue_type_converter > + , tc::function_type_converter< strip_param_lvalue_type_converter > + { + mcontext_t &mctx; + + explicit strip_param_lvalue_type_converter(mcontext_t &mctx) + : mctx(mctx) + { + addConversion([&](hl::LValueType type) { + return Maybe(type.getElementType()) + .and_then(convert_type_to_type()) + .unwrap() + .template take_wrapped< maybe_type_t >(); + }); + } + }; + + namespace pattern { + using strip_param_lvalue = tc::generic_type_converting_pattern< + strip_param_lvalue_type_converter + >; + } // namespace pattern + + struct StripParamLValuesPass + : TypeConvertingConversionPassMixin< + StripParamLValuesPass, + StripParamLValuesBase, + strip_param_lvalue_type_converter + > + { + using base = ConversionPassMixin< StripParamLValuesPass, StripParamLValuesBase >; + + static bool is_lvalue_type(mlir_value val) { + return !mlir::isa< hl::LValueType >(val.getType()); + } + + static conversion_target create_conversion_target(mcontext_t &mctx) { + conversion_target trg(mctx); + + trg.markUnknownOpDynamicallyLegal([] (operation op) { + if (auto fn = mlir::dyn_cast< mlir::FunctionOpInterface >(op)) + return rns::all_of(fn.getArguments(), is_lvalue_type); + return true; + }); + + return trg; + } + + static void populate_conversions(auto &cfg) { + base::populate_conversions< pattern::strip_param_lvalue >(cfg); + } + }; + +} // namespace vast::conv + +std::unique_ptr< mlir::Pass > vast::createStripParamLValuesPass() { + return std::make_unique< vast::conv::StripParamLValuesPass >(); +} From 6b8eda1931d18fdefa295bbaf69f58eb6dc7550d Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 13:53:56 +0200 Subject: [PATCH 25/50] conv: Add type_converting_conversion_config. --- include/vast/Conversion/Common/Mixins.hpp | 31 +++++++++++++++++++++ include/vast/Conversion/Common/Patterns.hpp | 3 ++ 2 files changed, 34 insertions(+) diff --git a/include/vast/Conversion/Common/Mixins.hpp b/include/vast/Conversion/Common/Mixins.hpp index ffdbb7cff2..f6f64c1b22 100644 --- a/include/vast/Conversion/Common/Mixins.hpp +++ b/include/vast/Conversion/Common/Mixins.hpp @@ -82,6 +82,25 @@ namespace vast { } }; + + template< typename type_converter > + struct type_converting_conversion_config : base_conversion_config { + type_converter &tc; + + type_converting_conversion_config( + rewrite_pattern_set patterns, + conversion_target target, + type_converter &tc + ) + : base_conversion_config{std::move(patterns), std::move(target)}, tc(tc) + {} + + template< typename pattern > + void add_pattern() { + patterns.template add< pattern >(tc, patterns.getContext()); + } + }; + // Configuration class for LLVM conversion using llvm_type_converter = conv::tc::FullLLVMTypeConverter; @@ -190,6 +209,18 @@ namespace vast { } }; + template< typename derived, template< typename > typename base, typename type_converter > + struct TypeConvertingConversionPassMixin : ConversionPassMixinBase< derived, base > + { + std::shared_ptr< type_converter > tc; + + type_converting_conversion_config< type_converter > make_config() { + auto &ctx = this->getContext(); + tc = std::make_shared< type_converter >(ctx); + return { rewrite_pattern_set(&ctx), derived::create_conversion_target(ctx), *tc }; + } + }; + // // Mixin for conversion passes that target the LLVM dialect. // Requires the derived pass to specify LLVM-specific conversion logic. diff --git a/include/vast/Conversion/Common/Patterns.hpp b/include/vast/Conversion/Common/Patterns.hpp index 8f22a847e0..14ba48275f 100644 --- a/include/vast/Conversion/Common/Patterns.hpp +++ b/include/vast/Conversion/Common/Patterns.hpp @@ -97,6 +97,9 @@ namespace vast { generic_conversion_pattern(mlir::TypeConverter &tc, mcontext_t &mctx) : base(tc, mlir::Pattern::MatchAnyOpTypeTag{}, 1, &mctx) {} + + generic_conversion_pattern(mlir::TypeConverter &tc, mcontext_t *mctx) + : base(tc, mlir::Pattern::MatchAnyOpTypeTag{}, 1, mctx) {} }; template< typename op_t > From b382ccd54101cdfcf6362707eb1388c7ad6fcfee Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 14:09:25 +0200 Subject: [PATCH 26/50] test: Remove obsolete tool substitutions. --- test/lit.cfg.py | 41 ---------------------- test/vast/Conversion/array-a.c | 4 +-- test/vast/Conversion/array-b.c | 4 +-- test/vast/Conversion/assign-a.c | 2 +- test/vast/Conversion/bin_chain-a.c | 2 +- test/vast/Conversion/bin_not.c | 2 +- test/vast/Conversion/binland-a.c | 2 +- test/vast/Conversion/binlor-a.c | 2 +- test/vast/Conversion/cmake-platform-test.c | 3 +- test/vast/Conversion/deref-a.c | 2 +- test/vast/Conversion/deref-b.c | 2 +- test/vast/Conversion/divfloat-a.c | 2 +- test/vast/Conversion/divsigned-a.c | 2 +- test/vast/Conversion/divunsigned-a.c | 2 +- test/vast/Conversion/float-a.c | 2 +- test/vast/Conversion/hl-assign-a.c | 2 +- test/vast/Conversion/hl-assign-b.c | 2 +- test/vast/Conversion/hl-assign-c.c | 2 +- test/vast/Conversion/mul-a.c | 2 +- test/vast/Conversion/mulfloat-a.c | 2 +- test/vast/Conversion/not-float.c | 2 +- test/vast/Conversion/not.c | 2 +- test/vast/Conversion/pre-post-a.c | 2 +- test/vast/Conversion/pre-post-b.c | 2 +- test/vast/Conversion/remsigned-a.c | 2 +- test/vast/Conversion/remunsigned-a.c | 2 +- test/vast/Conversion/shift-a.c | 2 +- test/vast/Conversion/signs.c | 2 +- test/vast/Conversion/sizeof-a.c | 2 +- test/vast/Conversion/sub-a.c | 2 +- test/vast/Conversion/subfloat-a.c | 2 +- test/vast/Conversion/subscript-a.c | 2 +- 32 files changed, 33 insertions(+), 75 deletions(-) diff --git a/test/lit.cfg.py b/test/lit.cfg.py index 561f6d8d4e..f3fe72c1f4 100644 --- a/test/lit.cfg.py +++ b/test/lit.cfg.py @@ -53,47 +53,6 @@ "--no-implicit-module" ] ), - ToolSubst('%vast-opt-irs-to-llvm', command = 'vast-opt', - extra_args=[ - "--vast-hl-lower-elaborated-types", - "--vast-hl-lower-typedefs", - "--vast-hl-lower-types", - "--vast-hl-to-ll-func", - "--vast-hl-to-ll-vars", - "--vast-hl-to-ll-cf", - "--vast-hl-to-ll-geps", - "--vast-fn-args-to-alloca", - "--vast-lower-value-categories", - "--vast-hl-to-lazy-regions", - "--vast-irs-to-llvm", - "--vast-core-to-llvm", - ] - ), - ToolSubst('%vast-opt-lower-value-categories', command = 'vast-opt', - extra_args=[ - "--vast-hl-lower-elaborated-types", - "--vast-hl-lower-typedefs", - "--vast-hl-lower-types", - "--vast-hl-to-ll-func", - "--vast-hl-to-ll-vars", - "--vast-hl-to-ll-cf", - "--vast-hl-to-ll-geps", - "--vast-fn-args-to-alloca", - "--vast-lower-value-categories", - ] - ), - ToolSubst('%vast-opt-core-to-llvm', command = 'vast-opt', - extra_args=[ - "--vast-hl-lower-types", - "--vast-hl-to-ll-cf", - "--vast-hl-to-ll-vars", - "--vast-hl-lower-elaborated-types", - "--vast-hl-lower-typedefs", - "--vast-hl-to-lazy-regions", - "--vast-irs-to-llvm", - "--vast-core-to-llvm" - ] - ), ToolSubst('%vast-cc', command = 'vast-cc'), ToolSubst('%vast-query', command = 'vast-query'), ToolSubst('%vast-front', command = 'vast-front'), diff --git a/test/vast/Conversion/array-a.c b/test/vast/Conversion/array-a.c index bb35d13b5c..7baa9188ae 100644 --- a/test/vast/Conversion/array-a.c +++ b/test/vast/Conversion/array-a.c @@ -1,7 +1,7 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s void count() { - // CHECK: llvm.store [[V4:%[0-9]+]], [[V10:%[0-9]+]] : !llvm.array<3 x i32>, !llvm.ptr + // CHECK: llvm.store {{.*}} : !llvm.array<3 x i32>, !llvm.ptr int x[3] = { 112, 212, 4121 }; } diff --git a/test/vast/Conversion/array-b.c b/test/vast/Conversion/array-b.c index e7788cbc39..0379dec8dc 100644 --- a/test/vast/Conversion/array-b.c +++ b/test/vast/Conversion/array-b.c @@ -1,7 +1,7 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s void count() { - // CHECK: llvm.store [[V4:%[0-9]+]], [[V10:%[0-9]+]] : !llvm.array<3 x f32>, !llvm.ptr + // CHECK: llvm.store {{.*}} : !llvm.array<3 x f32>, !llvm.ptr float x[3] = { 112.0f, 212.0f, 4121.0f }; } diff --git a/test/vast/Conversion/assign-a.c b/test/vast/Conversion/assign-a.c index c9706ced9c..9b61ce7294 100644 --- a/test/vast/Conversion/assign-a.c +++ b/test/vast/Conversion/assign-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-lower-value-categories | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir-after=vast-lower-value-categories %s -o - | %file-check %s void fn(int x, int v) { diff --git a/test/vast/Conversion/bin_chain-a.c b/test/vast/Conversion/bin_chain-a.c index 50f42b37ef..10ed8311ea 100644 --- a/test/vast/Conversion/bin_chain-a.c +++ b/test/vast/Conversion/bin_chain-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-front -vast-emit-mlir=llvm -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s int main() { int a = 5; diff --git a/test/vast/Conversion/bin_not.c b/test/vast/Conversion/bin_not.c index 73fbd33f18..f3acb0d63f 100644 --- a/test/vast/Conversion/bin_not.c +++ b/test/vast/Conversion/bin_not.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s int main() { int a = 5; diff --git a/test/vast/Conversion/binland-a.c b/test/vast/Conversion/binland-a.c index 2d67f2369f..9ad84a75e2 100644 --- a/test/vast/Conversion/binland-a.c +++ b/test/vast/Conversion/binland-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s int fun(int arg1, int arg2) { int res = arg1 && arg2; diff --git a/test/vast/Conversion/binlor-a.c b/test/vast/Conversion/binlor-a.c index ed1b1c4d09..288b73cd73 100644 --- a/test/vast/Conversion/binlor-a.c +++ b/test/vast/Conversion/binlor-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s int fun(int arg1, int arg2) { int res = arg1 || arg2; diff --git a/test/vast/Conversion/cmake-platform-test.c b/test/vast/Conversion/cmake-platform-test.c index 13e1aef691..7b56953a73 100644 --- a/test/vast/Conversion/cmake-platform-test.c +++ b/test/vast/Conversion/cmake-platform-test.c @@ -1,4 +1,4 @@ -// RUN: %vast-front -vast-emit-mlir=llvm -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s #include #undef KEY @@ -49,4 +49,3 @@ int main(int argc, char *argv[]) (void)argv; return require; } - diff --git a/test/vast/Conversion/deref-a.c b/test/vast/Conversion/deref-a.c index c2830aea5d..6efb532b54 100644 --- a/test/vast/Conversion/deref-a.c +++ b/test/vast/Conversion/deref-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-lower-value-categories | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir-after=vast-lower-value-categories %s -o - | %file-check %s void set(int *ptr, int v) { diff --git a/test/vast/Conversion/deref-b.c b/test/vast/Conversion/deref-b.c index e51228dfe3..060ea29786 100644 --- a/test/vast/Conversion/deref-b.c +++ b/test/vast/Conversion/deref-b.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-lower-value-categories | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir-after=vast-lower-value-categories %s -o - | %file-check %s void set(int *ptr, int *v) { diff --git a/test/vast/Conversion/divfloat-a.c b/test/vast/Conversion/divfloat-a.c index 2e192f3542..c755432136 100644 --- a/test/vast/Conversion/divfloat-a.c +++ b/test/vast/Conversion/divfloat-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: f32, %arg1: f32) -> f32 { float fn(float arg0, float arg1) diff --git a/test/vast/Conversion/divsigned-a.c b/test/vast/Conversion/divsigned-a.c index 58e192e192..fa2cb2f7b1 100644 --- a/test/vast/Conversion/divsigned-a.c +++ b/test/vast/Conversion/divsigned-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: i32, %arg1: i32) -> i32 { int fn(int arg0, int arg1) diff --git a/test/vast/Conversion/divunsigned-a.c b/test/vast/Conversion/divunsigned-a.c index aef0bdb6e8..32f78e6a17 100644 --- a/test/vast/Conversion/divunsigned-a.c +++ b/test/vast/Conversion/divunsigned-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: i32, %arg1: i32) -> i32 { unsigned int fn(unsigned int arg0, unsigned int arg1) diff --git a/test/vast/Conversion/float-a.c b/test/vast/Conversion/float-a.c index 17f0b1b33b..1609942ed2 100644 --- a/test/vast/Conversion/float-a.c +++ b/test/vast/Conversion/float-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s void count() { diff --git a/test/vast/Conversion/hl-assign-a.c b/test/vast/Conversion/hl-assign-a.c index ef4030407a..92f62d06a5 100644 --- a/test/vast/Conversion/hl-assign-a.c +++ b/test/vast/Conversion/hl-assign-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @count([[ARG:%arg[0-9]+]]: i32) void count(int arg) diff --git a/test/vast/Conversion/hl-assign-b.c b/test/vast/Conversion/hl-assign-b.c index 3984305e40..e7ec9ec64b 100644 --- a/test/vast/Conversion/hl-assign-b.c +++ b/test/vast/Conversion/hl-assign-b.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @count([[ARG:%arg[0-9]+]]: i32) void count(int arg) diff --git a/test/vast/Conversion/hl-assign-c.c b/test/vast/Conversion/hl-assign-c.c index 5c1633a021..a91a1fcbd0 100644 --- a/test/vast/Conversion/hl-assign-c.c +++ b/test/vast/Conversion/hl-assign-c.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s void count() { diff --git a/test/vast/Conversion/mul-a.c b/test/vast/Conversion/mul-a.c index 686bdd610e..ff0372c907 100644 --- a/test/vast/Conversion/mul-a.c +++ b/test/vast/Conversion/mul-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: i32, %arg1: i32) -> i32 { int fn(int arg0, int arg1) diff --git a/test/vast/Conversion/mulfloat-a.c b/test/vast/Conversion/mulfloat-a.c index 7ba3665c00..3a5e933d85 100644 --- a/test/vast/Conversion/mulfloat-a.c +++ b/test/vast/Conversion/mulfloat-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: f32, %arg1: f32) -> f32 { float fn(float arg0, float arg1) diff --git a/test/vast/Conversion/not-float.c b/test/vast/Conversion/not-float.c index e0ef433140..2ead0e6b48 100644 --- a/test/vast/Conversion/not-float.c +++ b/test/vast/Conversion/not-float.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s int main() { float a = 5; diff --git a/test/vast/Conversion/not.c b/test/vast/Conversion/not.c index 5e30f7bac2..8b15cc2c01 100644 --- a/test/vast/Conversion/not.c +++ b/test/vast/Conversion/not.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s int main() { int a = 5; diff --git a/test/vast/Conversion/pre-post-a.c b/test/vast/Conversion/pre-post-a.c index 3cff2ebe3b..48ebe4cd03 100644 --- a/test/vast/Conversion/pre-post-a.c +++ b/test/vast/Conversion/pre-post-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-lower-value-categories | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir-after=vast-lower-value-categories %s -o - | %file-check %s void fn() { diff --git a/test/vast/Conversion/pre-post-b.c b/test/vast/Conversion/pre-post-b.c index 81ee981b14..13af32342c 100644 --- a/test/vast/Conversion/pre-post-b.c +++ b/test/vast/Conversion/pre-post-b.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-lower-value-categories | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir-after=vast-lower-value-categories %s -o - | %file-check %s void fn() { diff --git a/test/vast/Conversion/remsigned-a.c b/test/vast/Conversion/remsigned-a.c index 698605564c..3e12c3b892 100644 --- a/test/vast/Conversion/remsigned-a.c +++ b/test/vast/Conversion/remsigned-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: i32, %arg1: i32) -> i32 { int fn(int arg0, int arg1) diff --git a/test/vast/Conversion/remunsigned-a.c b/test/vast/Conversion/remunsigned-a.c index cecc4df7fc..276aa390a3 100644 --- a/test/vast/Conversion/remunsigned-a.c +++ b/test/vast/Conversion/remunsigned-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: i32, %arg1: i32) -> i32 { unsigned int fn(unsigned int arg0, unsigned int arg1) diff --git a/test/vast/Conversion/shift-a.c b/test/vast/Conversion/shift-a.c index 6548deea08..28b506d510 100644 --- a/test/vast/Conversion/shift-a.c +++ b/test/vast/Conversion/shift-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-front -vast-emit-mlir=llvm -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s #include diff --git a/test/vast/Conversion/signs.c b/test/vast/Conversion/signs.c index c2adcb71f1..5af35a43ee 100644 --- a/test/vast/Conversion/signs.c +++ b/test/vast/Conversion/signs.c @@ -1,4 +1,4 @@ -// RUN: %vast-front -vast-emit-mlir=llvm -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s int main() { int a = 5; diff --git a/test/vast/Conversion/sizeof-a.c b/test/vast/Conversion/sizeof-a.c index 264d22963f..1d74f1e928 100644 --- a/test/vast/Conversion/sizeof-a.c +++ b/test/vast/Conversion/sizeof-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s unsigned long sizeof_int() { // CHECK: llvm.mlir.constant(4 : i64) : i64 diff --git a/test/vast/Conversion/sub-a.c b/test/vast/Conversion/sub-a.c index 08e9fe38d0..575ccb98cf 100644 --- a/test/vast/Conversion/sub-a.c +++ b/test/vast/Conversion/sub-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: i32, %arg1: i32) -> i32 { int fn(int arg0, int arg1) diff --git a/test/vast/Conversion/subfloat-a.c b/test/vast/Conversion/subfloat-a.c index 20bd370e8e..c2efb3f5a2 100644 --- a/test/vast/Conversion/subfloat-a.c +++ b/test/vast/Conversion/subfloat-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt-irs-to-llvm | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s // CHECK: llvm.func @fn(%arg0: f32, %arg1: f32) -> f32 { float fn(float arg0, float arg1) diff --git a/test/vast/Conversion/subscript-a.c b/test/vast/Conversion/subscript-a.c index adcae32725..8a64332aac 100644 --- a/test/vast/Conversion/subscript-a.c +++ b/test/vast/Conversion/subscript-a.c @@ -2,7 +2,7 @@ // RUN: %check-lower-value-categories %s | %file-check %s -check-prefix=VAL_CAT // RUN: %check-core-to-llvm %s | %file-check %s -check-prefix=C_LLVM -// STD_TYPES: [[V2:%[0-9]+]] = hl.ref {{.*}} : (!hl.lvalue>) -> !hl.lvalue> +// STD_TYPES: [[V2:%[0-9]+]] = hl.ref @arr1 : !hl.lvalue> // STD_TYPES: [[V3:%[0-9]+]] = hl.implicit_cast [[V2]] ArrayToPointerDecay : !hl.lvalue> -> !hl.ptr // STD_TYPES: [[V4:%[0-9]+]] = hl.const #core.integer<0> : si32 // STD_TYPES: [[V5:%[0-9]+]] = hl.subscript [[V3]] at [[[V4]] : si32] : !hl.ptr -> !hl.lvalue Date: Mon, 16 Sep 2024 14:23:54 +0200 Subject: [PATCH 27/50] test: Update ll.var to ll.cell tests. --- test/lit.cfg.py | 7 ++++--- test/vast/Conversion/empty-a.c | 2 +- test/vast/Conversion/fn-c.c | 24 +++++++++++++----------- test/vast/Conversion/vars-a.c | 8 ++++---- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/test/lit.cfg.py b/test/lit.cfg.py index f3fe72c1f4..5af157aba3 100644 --- a/test/lit.cfg.py +++ b/test/lit.cfg.py @@ -68,7 +68,7 @@ ToolSubst('%cc', command = config.host_cc) ] -passes = [ +passes: list[str] = [ "vast-hl-splice-trailing-scopes" , "vast-hl-to-hl-builtin" , "vast-hl-ude" @@ -78,10 +78,11 @@ , "vast-hl-lower-enums" , "vast-hl-lower-types" , "vast-hl-to-ll-func" - , "vast-hl-to-ll-vars" , "vast-hl-to-ll-cf" , "vast-hl-to-ll-geps" - , "vast-fn-args-to-alloca" + , "vast-vars-to-cells" + , "vast-refs-to-ssa" + , "vast-strip-param-lvalues" , "vast-lower-value-categories" , "vast-hl-to-lazy-regions" , "vast-emit-abi" diff --git a/test/vast/Conversion/empty-a.c b/test/vast/Conversion/empty-a.c index ddf1ffa9b0..730aba83e8 100644 --- a/test/vast/Conversion/empty-a.c +++ b/test/vast/Conversion/empty-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt --vast-hl-to-ll-func --vast-fn-args-to-alloca | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir-after=vast-strip-param-lvalues %s -o - | %file-check %s // No new operations should be emitted since the args are not used. // CHECK: ll.func {{.*}} diff --git a/test/vast/Conversion/fn-c.c b/test/vast/Conversion/fn-c.c index 2b209e24c0..41ed3b9c51 100644 --- a/test/vast/Conversion/fn-c.c +++ b/test/vast/Conversion/fn-c.c @@ -1,12 +1,14 @@ -// RUN: %check-fn-args-to-alloca %s | %file-check %s -check-prefix=ARGS_ALLOCA +// RUN: %check-vast-vars-to-cells %s | %file-check %s -check-prefix=CELLS +// RUN: %check-strip-param-lvalues %s | %file-check %s -check-prefix=PARAMS // RUN: %check-lower-value-categories %s | %file-check %s -check-prefix=VAL_CAT // RUN: %check-core-to-llvm %s | %file-check %s -check-prefix=C_LLVM -// ARGS_ALLOCA: ll.func @fn external ([[A1:%.*]]: si32, [[A2:%.*]]: si32) -> si32 { -// ARGS_ALLOCA: {{.*}} = ll.arg_alloca [[A1]] : (si32) -> !hl.lvalue -// ARGS_ALLOCA: {{.*}} = ll.arg_alloca [[A2]] : (si32) -> !hl.lvalue +// CELLS: {{.*}} = ll.cell @a +// CELLS: {{.*}} = ll.cell @b -// VAL_CAT: ll.func @fn external ([[A0:%.*]]: si32, [[A1:%.*]]: si32) -> si32 { +// PARAMS: ll.func @fn external ([[A1:%.*]]: si32, [[A2:%.*]]: si32) -> si32 + +// VAL_CAT: ll.func @fn external ([[A0:%.*]]: si32, [[A1:%.*]]: si32) -> si32 // VAL_CAT: [[V0:%[0-9]+]] = ll.alloca : !hl.ptr // VAL_CAT: ll.store [[V0]], [[A0]] : !hl.ptr, si32 // VAL_CAT: [[V1:%[0-9]+]] = ll.alloca : !hl.ptr @@ -20,11 +22,11 @@ // C_LLVM: [[V3:%[0-9]+]] = llvm.alloca {{.*}} x i32 : (i64) -> !llvm.ptr // C_LLVM: llvm.store [[A1]], [[V3]] : i32, !llvm.ptr -int fn(int arg0, int arg1) +int fn(int a, int b) { - // CHECK: %0 = ll.arg_alloca %arg0 : (!hl.int) -> !hl.lvalue - // CHECK: %1 = ll.arg_alloca %arg1 : (!hl.int) -> !hl.lvalue - // CHECK: {{.*}} = hl.ref %0 : (!hl.lvalue) -> !hl.lvalue - // CHECK: {{.*}} = hl.ref %1 : (!hl.lvalue) -> !hl.lvalue - return arg0 + arg1; + // CHECK: %0 = ll.cell @a + // CHECK: %1 = ll.cell @b + // CHECK: {{.*}} = hl.ref %0 + // CHECK: {{.*}} = hl.ref %1 + return a + b; } diff --git a/test/vast/Conversion/vars-a.c b/test/vast/Conversion/vars-a.c index f65c8babb9..c81d223416 100644 --- a/test/vast/Conversion/vars-a.c +++ b/test/vast/Conversion/vars-a.c @@ -1,12 +1,12 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt --vast-hl-dce --vast-hl-lower-types --vast-hl-to-ll-vars | %file-check %s +// RUN: %vast-cc1 -vast-emit-mlir-after=vast-refs-to-ssa %s -o - | %file-check %s int main() { - // CHECK: [[V0:%[0-9]+]] = ll.uninitialized_var : !hl.lvalue + // CHECK: [[V0:%[0-9]+]] = ll.cell @a : !hl.lvalue int a; - // CHECK: [[V1:%[0-9]+]] = ll.uninitialized_var : !hl.lvalue + // CHECK: [[V1:%[0-9]+]] = ll.cell @b : !hl.lvalue // CHECK: [[V2:%[0-9]+]] = hl.const #core.integer<1> : si32 - // CHECK: [[V3:%[0-9]+]] = ll.initialize [[V1]], [[V2]] : (!hl.lvalue, si32) -> !hl.lvalue + // CHECK: [[V3:%[0-9]+]] = ll.cell_init [[V1]], [[V2]] : (!hl.lvalue, si32) -> !hl.lvalue int b = 1; } From 7d6d395c456106466a91264a29a21129cbfd9926 Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 14:56:17 +0200 Subject: [PATCH 28/50] abi: Add FuncOp traits to define its symbol table. --- include/vast/Dialect/ABI/ABIOps.hpp | 1 + include/vast/Dialect/ABI/ABIOps.td | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/vast/Dialect/ABI/ABIOps.hpp b/include/vast/Dialect/ABI/ABIOps.hpp index a32efc735f..83f3f9202a 100644 --- a/include/vast/Dialect/ABI/ABIOps.hpp +++ b/include/vast/Dialect/ABI/ABIOps.hpp @@ -22,6 +22,7 @@ VAST_RELAX_WARNINGS #include "vast/Dialect/Core/CoreAttributes.hpp" #include "vast/Dialect/Core/Func.hpp" #include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp" +#include "vast/Dialect/Core/Interfaces/SymbolTableInterface.hpp" #define GET_OP_CLASSES #include "vast/Dialect/ABI/ABI.h.inc" diff --git a/include/vast/Dialect/ABI/ABIOps.td b/include/vast/Dialect/ABI/ABIOps.td index 9d865e038b..34d1a3f6f9 100644 --- a/include/vast/Dialect/ABI/ABIOps.td +++ b/include/vast/Dialect/ABI/ABIOps.td @@ -10,6 +10,9 @@ include "mlir/IR/OpBase.td" include "vast/Dialect/Core/CommonAttrConstraints.td" include "vast/Dialect/Core/Func.td" +include "vast/Dialect/Core/Interfaces/SymbolInterface.td" +include "vast/Dialect/Core/Interfaces/SymbolTableInterface.td" + def DirectOp : ABI_Op< "direct" > , Arguments<(ins Variadic:$value)> @@ -196,7 +199,13 @@ class ABIFuncBase< string mnemonic, list< Trait> traits = [] > : Core_FuncBaseOp< ABI_Dialect, mnemonic, traits > {} -def FuncOp : ABIFuncBase< "func" > +def FuncOp : ABIFuncBase< "func", [ + Core_FuncSymbol, + Core_ShadowingSymbolTable< [ + [Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol] + ] >, + IsolatedFromAbove +] > { let summary = [{ Function with transformed type. }]; } From 11538e2b157e7141733996d42db282acd2c87a19 Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 14:56:49 +0200 Subject: [PATCH 29/50] abi: Add FuncOp traits to define its symbol table. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index 5fd2bd7a4d..d02be36689 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -12,6 +12,7 @@ include "vast/Dialect/Core/Interfaces/SymbolInterface.td" include "vast/Interfaces/ElementTypeInterface.td" include "vast/Dialect/Core/CoreTraits.td" +include "vast/Dialect/Core/Interfaces/SymbolInterface.td" include "vast/Dialect/Core/Interfaces/SymbolTableInterface.td" include "vast/Dialect/Core/Func.td" @@ -362,6 +363,12 @@ def LowLevel_InlineScope let regions = (region AnyRegion:$body); } -def LowLevel_FuncOp : Core_FuncBaseOp< LowLevel_Dialect, "func", [] > {} +def LowLevel_FuncOp : Core_FuncBaseOp< LowLevel_Dialect, "func", [ + Core_FuncSymbol, + Core_ShadowingSymbolTable< [ + [Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol] + ] >, + IsolatedFromAbove +] > {} #endif // VAST_DIALECT_IR_LOWLEVELOPS From eb91084eb26d340a53b24c1a450d0ed4cce3cf1e Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 14:58:34 +0200 Subject: [PATCH 30/50] conv:tomem: Fix variable symbol lookup. --- lib/vast/Conversion/ToMem/RefsToSSA.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/vast/Conversion/ToMem/RefsToSSA.cpp b/lib/vast/Conversion/ToMem/RefsToSSA.cpp index ee5af34844..800d99fc17 100644 --- a/lib/vast/Conversion/ToMem/RefsToSSA.cpp +++ b/lib/vast/Conversion/ToMem/RefsToSSA.cpp @@ -30,10 +30,8 @@ namespace vast::conv { logical_result matchAndRewrite( hl::DeclRefOp op, adaptor_t adaptor, conversion_rewriter &rewriter ) const override { - auto st = core::get_effective_symbol_table_for< core::var_symbol >(op); - VAST_CHECK(st, "No effective symbol table found for variable reference resolution."); + auto var = core::symbol_table::lookup< core::var_symbol >(op, op.getName()); - auto var = st->lookup< core::var_symbol >(op.getName()); VAST_CHECK(var, "Variable {} not present in the symbol table.", op.getName()); VAST_CHECK(mlir::isa< ll::Cell >(var), "Variable {} is not a cell." "Lower variable to cells before lowering of references.", From 5351a8a4e64976d516d7dd41dafbc5c295d106fa Mon Sep 17 00:00:00 2001 From: xlauko Date: Mon, 16 Sep 2024 14:58:50 +0200 Subject: [PATCH 31/50] hl: Fix function type name resolution. --- lib/vast/Dialect/HighLevel/HighLevelTypes.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp b/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp index 18ee91bed6..961ffed6ba 100644 --- a/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp +++ b/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp @@ -108,12 +108,8 @@ namespace vast::hl } if (auto sym = callee.dyn_cast< mlir::SymbolRefAttr >()) { - auto st = core::get_effective_symbol_table_for< core::func_symbol >(from); - VAST_CHECK(st, "No effective symbol table found for function type resolution."); - - auto fn = st->lookup< core::func_symbol >(sym.getRootReference()); + auto fn = core::symbol_table::lookup< core::func_symbol >(from, sym.getRootReference()); VAST_CHECK(fn, "Function {} not present in the symbol table.", sym.getRootReference()); - return mlir::cast< FuncOp >(fn).getFunctionType(); } From 8b534a3c41ca8f663bdad178eb0843d08356fc23 Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 13:56:20 +0200 Subject: [PATCH 32/50] core: Introduce `ScopeLikeTrait`. --- include/vast/Dialect/Core/CoreTraits.hpp | 6 ++++++ include/vast/Dialect/Core/CoreTraits.td | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/include/vast/Dialect/Core/CoreTraits.hpp b/include/vast/Dialect/Core/CoreTraits.hpp index 7ef6e12ca1..cb85841ec9 100644 --- a/include/vast/Dialect/Core/CoreTraits.hpp +++ b/include/vast/Dialect/Core/CoreTraits.hpp @@ -44,4 +44,10 @@ namespace vast::core template< typename ConcreteType > struct ConstantLikeAttrTrait : attr_trait_base< ConcreteType, ConstantLikeAttrTrait > {}; + // + // ScopeLikeTrait + // + template< typename ConcreteType > + struct ScopeLikeTrait : op_trait_base< ConcreteType, ScopeLikeTrait > {}; + } // namespace vast::core diff --git a/include/vast/Dialect/Core/CoreTraits.td b/include/vast/Dialect/Core/CoreTraits.td index e9790d0dfb..fc24c88336 100644 --- a/include/vast/Dialect/Core/CoreTraits.td +++ b/include/vast/Dialect/Core/CoreTraits.td @@ -33,4 +33,9 @@ def Core_ReturnLikeTrait : Core_NativeOpTrait< "ReturnLikeTrait" >, StructuralOp def Core_ConstantLikeAttrTrait : Core_NativeAttrTrait<"ConstantLikeAttrTrait">; +// +// Trait to generalize scope lookups, can be removed once we have single scope operation +// +def Core_ScopeLikeTrait : Core_NativeOpTrait< "ScopeLikeTrait" >; + #endif //VAST_DIALECT_CORE_CORETRAITS From b37ebc6577cc851070ebaeb95f80f91ad5b2d8cf Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 13:56:51 +0200 Subject: [PATCH 33/50] core: Allow to access SymbolTable defining operation. --- include/vast/Dialect/Core/SymbolTable.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/vast/Dialect/Core/SymbolTable.hpp b/include/vast/Dialect/Core/SymbolTable.hpp index 4c949db8cb..62cb3da7d0 100644 --- a/include/vast/Dialect/Core/SymbolTable.hpp +++ b/include/vast/Dialect/Core/SymbolTable.hpp @@ -150,6 +150,8 @@ namespace vast::core { return symbol_tables.contains(kind); } + operation get_defining_operation() { return symbol_table_op; } + protected: template< util::flat_list symbols_list > From aeba5892983ab4029701a102d5e01773c1ad7b4b Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 13:57:20 +0200 Subject: [PATCH 34/50] core: Let ScopeOp to have ScopeLikeTrait. --- include/vast/Dialect/Core/CoreOps.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vast/Dialect/Core/CoreOps.td b/include/vast/Dialect/Core/CoreOps.td index 7eeea0a8ff..7b780bfe38 100644 --- a/include/vast/Dialect/Core/CoreOps.td +++ b/include/vast/Dialect/Core/CoreOps.td @@ -74,7 +74,7 @@ def Core_ModuleOp : Core_Op< "module", [ } def Core_ScopeOp : Core_Op< "scope", [ - NoTerminator, + NoTerminator, Core_ScopeLikeTrait, Core_ShadowingSymbolTable< [ [Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol] ] >, From 305af464d8f30f9001b4e2c7bdb59e50d762139d Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 13:57:31 +0200 Subject: [PATCH 35/50] ll: core: Let Scope to have ScopeLikeTrait. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 1 + 1 file changed, 1 insertion(+) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index d02be36689..da339e0b64 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -328,6 +328,7 @@ def LowLevel_Scope : LowLevel_Op< "scope", [ NoRegionArguments, NoTerminator, + Core_ScopeLikeTrait, Core_ShadowingSymbolTable< [ [Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol] ] > From ef5620a614a2f62c4b7fe33c111279d3c4016dd7 Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 13:58:42 +0200 Subject: [PATCH 36/50] hl: Fix variable storage classes. --- .../vast/Dialect/HighLevel/HighLevelOps.hpp | 81 +++---------------- .../vast/Dialect/HighLevel/HighLevelVar.td | 37 ++------- lib/vast/CodeGen/DefaultDeclVisitor.cpp | 31 +++---- lib/vast/Dialect/HighLevel/HighLevelOps.cpp | 53 +++++++++++- lib/vast/Dialect/HighLevel/HighLevelVar.cpp | 10 ++- 5 files changed, 85 insertions(+), 127 deletions(-) diff --git a/include/vast/Dialect/HighLevel/HighLevelOps.hpp b/include/vast/Dialect/HighLevel/HighLevelOps.hpp index a8b3a91faa..ebb478fd0e 100644 --- a/include/vast/Dialect/HighLevel/HighLevelOps.hpp +++ b/include/vast/Dialect/HighLevel/HighLevelOps.hpp @@ -25,80 +25,19 @@ VAST_UNRELAX_WARNINGS #include "vast/Interfaces/AST/DeclInterface.hpp" -namespace vast::hl -{ - static constexpr auto external_storage = "is_external"; - static constexpr auto static_storage = "is_static"; - static constexpr auto auto_storage = "is_auto"; - static constexpr auto register_storage = "is_register"; - static constexpr auto thread_storage = "is_thread_local"; - - template< typename Self > - void set_unit_attr(Self &self, std::string_view attr) { - self->setAttr(attr, mlir::UnitAttr::get(self.getContext())); - } - - template< typename Self > - void set_external_storage(Self &self) { - set_unit_attr(self, external_storage); - } - - template< typename Self > - void set_static_storage(Self &self) { - set_unit_attr(self, static_storage); - } - - template< typename Self > - void set_auto_storage(Self &self) { - set_unit_attr(self, auto_storage); - } - - template< typename Self > - void set_register_storage(Self &self) { - set_unit_attr(self, register_storage); - } - - template< typename Self > - void set_thread_local_storage(Self &self) { - set_unit_attr(self, thread_storage); - } - - template< typename Self > - bool has_unit_attr(const Self &self, std::string_view attr) { - return self->hasAttr(attr); - } - - template< typename Self > - bool has_external_storage(const Self &self) { - return has_unit_attr(self, external_storage); - } - - template< typename Self > - bool has_static_storage(const Self &self) { - return has_unit_attr(self, static_storage); - } - - template< typename Self > - bool has_auto_storage(const Self &self) { - return has_unit_attr(self, auto_storage); - } - - template< typename Self > - bool has_register_storage(const Self &self) { - return has_unit_attr(self, register_storage); - } - - template< typename Self > - bool has_thread_local_storage(const Self &self) { - return has_unit_attr(self, thread_storage); - } - -} // namespace vast::hl - #define GET_OP_CLASSES #include "vast/Dialect/HighLevel/HighLevel.h.inc" namespace vast::hl { FuncOp getCallee(CallOp call); -} + + ParseResult parseStorageClasses( + Parser &parser, Attribute &storage_class, Attribute &thread_storage_class + ); + + void printStorageClasses( + Printer &printer, mlir::Operation *op, StorageClassAttr storage_class, TSClassAttr thread_storage_class + ); + +} // namespace vast::hl diff --git a/include/vast/Dialect/HighLevel/HighLevelVar.td b/include/vast/Dialect/HighLevel/HighLevelVar.td index 402f0967e3..1428a75a4d 100644 --- a/include/vast/Dialect/HighLevel/HighLevelVar.td +++ b/include/vast/Dialect/HighLevel/HighLevelVar.td @@ -30,15 +30,6 @@ def HighLevel_StorageClass : HighLevel_StorageClassList< "StorageClass", "storag HighLevel_SC_Register ] >; -class HighLevel_StorageClassImpl -{ - code storageClassImpl = [{ - constexpr static auto storage_class = "storageClass"; - - void setStorageClass(StorageClass spec) { setAttr< StorageClassAttr >(storage_class, spec); } - }]; -} - // thread storage class class HighLevel_TSCAttr< string name, int val > : I64EnumAttrCase< name, val > {} @@ -61,15 +52,6 @@ def HighLevel_ThreadStorage : HighLevel_TSCList< "TSClass", "thread storage clas HighLevel_TSC_C_Thread ] >; -class HighLevel_ThreadStorageClassImpl -{ - code threadStorageClassImpl = [{ - constexpr static auto thread_storage_class = "threadStorageClass"; - - void setThreadStorageClass(TSClass spec) { setAttr< TSClassAttr >(thread_storage_class, spec); } - }]; -} - // Storage Duration class HighLevel_StorageDurationAttr< string name, int val > : I64EnumAttrCase< name, val > {} @@ -160,14 +142,10 @@ class HighLevel_DeclContextImpl } class HighLevel_StorageSpecifiers : - HighLevel_StorageClassImpl, - HighLevel_ThreadStorageClassImpl, HighLevel_StorageDurationImpl, HighLevel_DeclContextImpl { code storageSpecifiersImpl = - storageClassImpl # - threadStorageClassImpl # storageDurationImpl # declContextImpl; } @@ -183,8 +161,8 @@ def HighLevel_VarDeclOp let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$type, - OptionalAttr:$storageClass, - OptionalAttr:$threadStorageClass + HighLevel_StorageClass:$storageClass, + HighLevel_ThreadStorage:$threadStorageClass ); let regions = (region @@ -197,24 +175,21 @@ def HighLevel_VarDeclOp OpBuilder<(ins "Type":$type, "llvm::StringRef":$sym_name, + "StorageClass":$storageClass, + "TSClass":$threadStorageClass, CArg< "maybe_builder_callback_ref", "std::nullopt" >:$initBuilder, CArg< "maybe_builder_callback_ref", "std::nullopt" >:$allocaBuilder )> ]; let assemblyFormat = [{ - $sym_name attr-dict ($storageClass^)? ($threadStorageClass^)? + $sym_name attr-dict custom< StorageClasses >($storageClass, $threadStorageClass) `:` $type (`=` $initializer^)? (`allocation_size` $allocation_size^)? }]; - let extraClassDeclaration = [{ - template< typename Attr, typename Value > - void setAttr(llvm::StringRef name, Value value) { - (*this)->setAttr(name, Attr::get(getContext(), value)); - } - }] # storageSpecifiersImpl; + let extraClassDeclaration = storageSpecifiersImpl; } #endif // VAST_DIALECT_HIGHLEVEL_IR_HIGHLEVELVAR diff --git a/lib/vast/CodeGen/DefaultDeclVisitor.cpp b/lib/vast/CodeGen/DefaultDeclVisitor.cpp index ca5b85d9d4..0affa9ec3e 100644 --- a/lib/vast/CodeGen/DefaultDeclVisitor.cpp +++ b/lib/vast/CodeGen/DefaultDeclVisitor.cpp @@ -209,16 +209,11 @@ namespace vast::cg { } }; - auto set_storage_classes = [&](auto var) { - if (auto sc = storage_class(decl); sc != hl::StorageClass::sc_none) { - var.setStorageClass(sc); - } - - if (auto tsc = thread_storage_class(decl); tsc != hl::TSClass::tsc_none) { - var.setThreadStorageClass(tsc); - } - - return var; + auto initializer_builder = [this, decl](auto &state, auto loc) { + bld.compose< hl::ValueYieldOp >() + .bind_always(loc) + .bind_transform(self.visit(decl->getInit()), first_result) + .freeze(); }; auto var = maybe_declare([&] { @@ -226,22 +221,16 @@ namespace vast::cg { .bind(self.location(decl)) .bind(visit_as_lvalue_type(self, mctx, decl->getType())) .bind(self.symbol(decl)) - // The initializer region is filled later as it might + .bind_always(storage_class(decl)) + .bind_always(thread_storage_class(decl)) + // FIXME: The initializer region is filled later as it might // have references to the VarDecl we are currently // visiting - int *x = malloc(sizeof(*x)) - .bind_choose( - emit_init, [](auto, auto) {}, std::nullopt - ) + .bind_choose(emit_init, std::move(initializer_builder), std::nullopt) .bind_choose(has_allocator, std::move(array_allocator), std::nullopt) - .freeze_as_maybe() // construct global - .transform(set_storage_classes) - .take(); + .freeze(); }); - if (emit_init) { - fill_init(decl->getInit(), var); - } - return var; } diff --git a/lib/vast/Dialect/HighLevel/HighLevelOps.cpp b/lib/vast/Dialect/HighLevel/HighLevelOps.cpp index 79f9e15abe..2eb3bc6a4e 100644 --- a/lib/vast/Dialect/HighLevel/HighLevelOps.cpp +++ b/lib/vast/Dialect/HighLevel/HighLevelOps.cpp @@ -340,18 +340,69 @@ namespace vast::hl } void VarDeclOp::build( - Builder &bld, State &st, Type type, llvm::StringRef name, + Builder &bld, State &st, + Type type, + llvm::StringRef name, + StorageClass storage_class, + TSClass thread_storage_class, maybe_builder_callback_ref init, maybe_builder_callback_ref alloc ) { + auto ctx = bld.getContext(); st.addAttribute(core::symbol_attr_name(), bld.getStringAttr(name)); st.addAttribute("type", mlir::TypeAttr::get(type)); + st.addAttribute("storageClass", StorageClassAttr::get(ctx, storage_class)); + st.addAttribute("threadStorageClass", TSClassAttr::get(ctx, thread_storage_class)); InsertionGuard guard(bld); build_region(bld, st, init); build_region(bld, st, alloc); } + ParseResult parseStorageClasses( + Parser &parser, Attribute &storage_class, Attribute &thread_storage_class + ) { + std::string keyword; + auto parse_result = parser.parseOptionalKeywordOrString(&keyword); + + if (mlir::failed(parse_result)) { + storage_class = StorageClassAttr::get(parser.getContext(), StorageClass::sc_none); + thread_storage_class = TSClassAttr::get(parser.getContext(), TSClass::tsc_none); + return mlir::success(); + } else if (auto attr = symbolizeEnum< StorageClass >(keyword)) { + storage_class = StorageClassAttr::get(parser.getContext(), attr.value()); + } else if (auto attr = symbolizeEnum< TSClass >(keyword)) { + storage_class = StorageClassAttr::get(parser.getContext(), StorageClass::sc_none); + thread_storage_class = TSClassAttr::get(parser.getContext(), attr.value()); + return mlir::success(); + } else { + return mlir::failure(); + } + + parse_result = parser.parseOptionalKeywordOrString(&keyword); + if (mlir::failed(parse_result)) { + thread_storage_class = TSClassAttr::get(parser.getContext(), TSClass::tsc_none); + } else if (auto attr = symbolizeEnum< TSClass >(keyword)) { + thread_storage_class = TSClassAttr::get(parser.getContext(), attr.value()); + } else { + return mlir::failure(); + } + + return mlir::success(); + } + + void printStorageClasses( + Printer &printer, mlir::Operation *op, StorageClassAttr storage_class, TSClassAttr thread_storage_class + ) { + if (storage_class.getValue() != StorageClass::sc_none) { + printer << ' ' << storage_class.getValue(); + } + + if (thread_storage_class.getValue() != TSClass::tsc_none) { + printer << ' ' << thread_storage_class.getValue(); + } + } + void EnumDeclOp::build( Builder &bld, State &st, llvm::StringRef name, Type type, builder_callback_ref constants diff --git a/lib/vast/Dialect/HighLevel/HighLevelVar.cpp b/lib/vast/Dialect/HighLevel/HighLevelVar.cpp index 2419b7c711..7c5af38276 100644 --- a/lib/vast/Dialect/HighLevel/HighLevelVar.cpp +++ b/lib/vast/Dialect/HighLevel/HighLevelVar.cpp @@ -5,6 +5,8 @@ #include "vast/Dialect/HighLevel/HighLevelOps.hpp" #include "vast/Dialect/HighLevel/HighLevelTypes.hpp" +#include "vast/Dialect/Core/CoreTraits.hpp" + namespace vast::hl { bool isFileContext(DeclContextKind kind) { @@ -29,8 +31,10 @@ namespace vast::hl bool VarDeclOp::isInRecordContext() { return isRecordContext(getDeclContextKind()); } DeclContextKind VarDeclOp::getDeclContextKind() { - auto st = mlir::SymbolTable::getNearestSymbolTable(*this); - if (mlir::isa< FuncOp >(st)) + auto st = core::get_effective_symbol_table_for< core::var_symbol >(*this)->get_defining_operation(); + if (mlir::isa< mlir::FunctionOpInterface >(st)) + return DeclContextKind::dc_function; + if (st->hasTrait< core::ScopeLikeTrait >()) return DeclContextKind::dc_function; if (mlir::isa< core::ModuleOp >(st)) return DeclContextKind::dc_translation_unit; @@ -53,7 +57,7 @@ namespace vast::hl bool VarDeclOp::isLocalVarDecl() { return isInFunctionOrMethodContext(); } bool VarDeclOp::hasLocalStorage() { - switch (getStorageClass().value()) { + switch (getStorageClass()) { case StorageClass::sc_none: return !isFileVarDecl() && getThreadStorageClass() == TSClass::tsc_none; case StorageClass::sc_register: return isLocalVarDecl(); From 403cde9acd166e89f58685c0e87ce9b3d5f9efcf Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 13:59:10 +0200 Subject: [PATCH 37/50] conv:tomem: Convert to cells only local variables. --- lib/vast/Conversion/ToMem/VarsToCells.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/vast/Conversion/ToMem/VarsToCells.cpp b/lib/vast/Conversion/ToMem/VarsToCells.cpp index 627149b7b4..f3a06b79be 100644 --- a/lib/vast/Conversion/ToMem/VarsToCells.cpp +++ b/lib/vast/Conversion/ToMem/VarsToCells.cpp @@ -61,7 +61,9 @@ namespace vast::conv { } static void legalize(conversion_target &trg) { - base::legalize(trg); + trg.addDynamicallyLegalOp< hl::VarDeclOp >([] (hl::VarDeclOp op) { + return !op.hasLocalStorage(); + }); trg.addLegalOp< ll::Cell >(); trg.addLegalOp< ll::CellInit >(); } From 4442a2cce5ad133e7277414d720db0148fb1b471 Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 15:14:15 +0200 Subject: [PATCH 38/50] conv: Remove obsolete lvalue type conversion. --- .../Conversion/Generic/LowerValueCategories.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/vast/Conversion/Generic/LowerValueCategories.cpp b/lib/vast/Conversion/Generic/LowerValueCategories.cpp index a981265767..f3f8295924 100644 --- a/lib/vast/Conversion/Generic/LowerValueCategories.cpp +++ b/lib/vast/Conversion/Generic/LowerValueCategories.cpp @@ -35,7 +35,6 @@ namespace vast::conv { // Do we need data layout? Probably not as everything should be explicit // type size wise. value_category_type_converter(mcontext_t &mctx) : mctx(mctx) { - addConversion([&](mlir_type t) { return t; }); addConversion([&](hl::LValueType type) { // It should never happen that we have nested lvalues? auto element_type = this->convert_type_to_type(type.getElementType()); @@ -70,21 +69,6 @@ namespace vast::conv { using mixin_base = tc::mixins< value_category_type_converter >; using mixin_base::convert_type_to_type; using mixin_base::convert_type_to_types; - - template< typename T, typename... Args > - auto make_aggregate_type(Args... args) { - return [=](mlir_type elem) { return T::get(elem.getContext(), elem, args...); }; - } - - auto convert_lvalue_type() { - return [&](hl::LValueType type) { - return Maybe(type.getElementType()) - .and_then(convert_type_to_type()) - .unwrap() - .and_then(make_aggregate_type< hl::PointerType >()) - .template take_wrapped< maybe_type_t >(); - }; - } }; #define VAST_DEFINE_REWRITE \ From a2ff6db52b222c69e98b5f3a99a2ab9922be9b0a Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 15:15:02 +0200 Subject: [PATCH 39/50] conv: Make hl.var with lvalue illegal in LowerValueCategoriesPass. --- lib/vast/Conversion/Generic/LowerValueCategories.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/vast/Conversion/Generic/LowerValueCategories.cpp b/lib/vast/Conversion/Generic/LowerValueCategories.cpp index f3f8295924..8587d491fd 100644 --- a/lib/vast/Conversion/Generic/LowerValueCategories.cpp +++ b/lib/vast/Conversion/Generic/LowerValueCategories.cpp @@ -482,12 +482,17 @@ namespace vast::conv { populate(unary_in_place_conversions{}, patterns, trg, mctx, tc); populate(assign_conversions{}, patterns, trg, mctx, tc); - auto is_legal = [&](auto op) { + auto is_legal = [&](operation op) { return tc.template get_has_legal_return_type< operation >()(op) && tc.template get_has_legal_operand_types< operation >()(op); }; + trg.markUnknownOpDynamicallyLegal(is_legal); + trg.addDynamicallyLegalOp< hl::VarDeclOp >([&](hl::VarDeclOp op) { + return !mlir::isa< hl::LValueType >(op.getType()); + }); + // As we go and replace operands, sometimes it can happen that this cast // already will be in form `hl.ptr< T > -> T` instead of `hl.lvalue< T > -> T`. // I am not sure why this is happening, quite possibly some pattern is doing From 48e6057acefbe907f3b31a37dc05f23f079fb863 Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 17 Sep 2024 15:18:05 +0200 Subject: [PATCH 40/50] test: Fix filecheck output parameters. --- test/vast/Conversion/bin_chain-a.c | 2 +- test/vast/Conversion/cmake-platform-test.c | 2 +- test/vast/Conversion/signs.c | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/vast/Conversion/bin_chain-a.c b/test/vast/Conversion/bin_chain-a.c index 10ed8311ea..02010d59fb 100644 --- a/test/vast/Conversion/bin_chain-a.c +++ b/test/vast/Conversion/bin_chain-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - | %file-check %s int main() { int a = 5; diff --git a/test/vast/Conversion/cmake-platform-test.c b/test/vast/Conversion/cmake-platform-test.c index 7b56953a73..725f2c8a74 100644 --- a/test/vast/Conversion/cmake-platform-test.c +++ b/test/vast/Conversion/cmake-platform-test.c @@ -1,4 +1,4 @@ -// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - | %file-check %s #include #undef KEY diff --git a/test/vast/Conversion/signs.c b/test/vast/Conversion/signs.c index 5af35a43ee..82a4a509d4 100644 --- a/test/vast/Conversion/signs.c +++ b/test/vast/Conversion/signs.c @@ -1,13 +1,13 @@ -// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - | %file-check %s int main() { int a = 5; - // CHECK: {{.* = llvm.load.*}} - // CHECK-NEXT: {{.* = llvm.mlir.constant.*}} - // CHECK-NEXT: {{.* = llvm.sub.*}} - // CHECK-NEXT: {{.*llvm.store.*}} - // CHECK: {{.* = llvm.load.*}} - // CHECK-NEXT: {{.*llvm.store.*}} + // CHECK: llvm.load + // CHECK-NEXT: llvm.mlir.constant + // CHECK-NEXT: llvm.sub + // CHECK-NEXT: llvm.store + // CHECK: llvm.load + // CHECK-NEXT: llvm.store int b = -a; int c = +a; return 0; From c7bf438553b5b63da6ab29e665168674ffbeea2d Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 18 Sep 2024 10:40:51 +0200 Subject: [PATCH 41/50] conv:tomem: Make StripParamLValuesPass work on external function without named parameters. --- lib/vast/Conversion/ToMem/StripParamLValues.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/vast/Conversion/ToMem/StripParamLValues.cpp b/lib/vast/Conversion/ToMem/StripParamLValues.cpp index 9932e4f2fc..8dfcdac2b2 100644 --- a/lib/vast/Conversion/ToMem/StripParamLValues.cpp +++ b/lib/vast/Conversion/ToMem/StripParamLValues.cpp @@ -58,16 +58,18 @@ namespace vast::conv { { using base = ConversionPassMixin< StripParamLValuesPass, StripParamLValuesBase >; - static bool is_lvalue_type(mlir_value val) { - return !mlir::isa< hl::LValueType >(val.getType()); + static bool is_not_lvalue_type(mlir_type ty) { + return !mlir::isa< hl::LValueType >(ty); } static conversion_target create_conversion_target(mcontext_t &mctx) { conversion_target trg(mctx); trg.markUnknownOpDynamicallyLegal([] (operation op) { - if (auto fn = mlir::dyn_cast< mlir::FunctionOpInterface >(op)) - return rns::all_of(fn.getArguments(), is_lvalue_type); + if (auto fn = mlir::dyn_cast< mlir::FunctionOpInterface >(op)) { + auto fty = mlir::cast< core::FunctionType >(fn.getFunctionType()); + return rns::all_of(fty.getInputs(), is_not_lvalue_type); + } return true; }); From 0fd639d3736aad20921939275fd09ee6b271257e Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 18 Sep 2024 10:42:06 +0200 Subject: [PATCH 42/50] conv: Remove now obsolete lvalue function type conversion. --- .../Generic/LowerValueCategories.cpp | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/vast/Conversion/Generic/LowerValueCategories.cpp b/lib/vast/Conversion/Generic/LowerValueCategories.cpp index 8587d491fd..a5a90ee469 100644 --- a/lib/vast/Conversion/Generic/LowerValueCategories.cpp +++ b/lib/vast/Conversion/Generic/LowerValueCategories.cpp @@ -28,7 +28,6 @@ namespace vast::conv { struct value_category_type_converter : tc::identity_type_converter , tc::mixins< value_category_type_converter > - , tc::function_type_converter< value_category_type_converter > { mlir::MLIRContext &mctx; @@ -463,10 +462,11 @@ namespace vast::conv { patterns.add< fallback >(tc, mctx); patterns.add< store_and_forward_ptr< ll::CellInit > >(mctx, tc); - patterns - .add< ignore< hl::DeclRefOp >, ignore< hl::Deref >, ignore< hl::AddressOf > >( - mctx, tc - ); + patterns.add< + ignore< hl::DeclRefOp >, + ignore< hl::Deref >, + ignore< hl::AddressOf > + >(mctx, tc); patterns.add< memory_allocation< ll::Cell > >(mctx, tc); patterns.add< subscript >(mctx, tc); @@ -506,22 +506,10 @@ namespace vast::conv { // This will never have correct types but we want to have it legal. trg.addLegalOp< mlir::UnrealizedConversionCastOp >(); - convert_function_types(tc); if (mlir::failed(mlir::applyPartialConversion(root, trg, std::move(patterns)))) { return signalPassFailure(); } } - - void convert_function_types(value_category_type_converter &tc) { - auto root = getOperation(); - auto pattern = fn< ll::FuncOp >(getContext(), tc); - auto walker = [&](mlir::FunctionOpInterface op) { - type_rewriter bld(&getContext()); - [[maybe_unused]] auto status = pattern.replace(op, bld); - }; - - root->walk(walker); - } }; } // namespace vast::conv From 3e9b913c4ea62394088dcb8c5cc0afeb58f9a109 Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 18 Sep 2024 10:46:15 +0200 Subject: [PATCH 43/50] test: Update conversion checks to adhere new results. --- test/vast/Conversion/{hl-assign-a.c => assign-b.c} | 4 ++-- test/vast/Conversion/{hl-assign-b.c => assign-c.c} | 4 ++-- test/vast/Conversion/{hl-assign-c.c => assign-d.c} | 0 test/vast/Conversion/direct-overlap-a.c | 2 +- test/vast/Conversion/do-while-a.c | 9 +++++---- test/vast/Conversion/do-while-b.c | 7 ++++--- test/vast/Conversion/empty-a.c | 6 +++++- test/vast/Conversion/fn-c.c | 2 +- test/vast/Conversion/scope-a.c | 9 +++++---- test/vast/Conversion/select-c.c | 8 +++----- test/vast/Conversion/shift-a.c | 2 +- 11 files changed, 29 insertions(+), 24 deletions(-) rename test/vast/Conversion/{hl-assign-a.c => assign-b.c} (91%) rename test/vast/Conversion/{hl-assign-b.c => assign-c.c} (90%) rename test/vast/Conversion/{hl-assign-c.c => assign-d.c} (100%) diff --git a/test/vast/Conversion/hl-assign-a.c b/test/vast/Conversion/assign-b.c similarity index 91% rename from test/vast/Conversion/hl-assign-a.c rename to test/vast/Conversion/assign-b.c index 92f62d06a5..0ba90c992a 100644 --- a/test/vast/Conversion/hl-assign-a.c +++ b/test/vast/Conversion/assign-b.c @@ -1,7 +1,7 @@ // RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s -// CHECK: llvm.func @count([[ARG:%arg[0-9]+]]: i32) -void count(int arg) +// CHECK: llvm.func @count +void count() { // CHECK: [[C:%[0-9]+]] = llvm.mlir.constant(1 : index) : i64 // CHECK: [[V1:%[0-9]+]] = llvm.alloca [[C]] x i32 : (i64) -> !llvm.ptr diff --git a/test/vast/Conversion/hl-assign-b.c b/test/vast/Conversion/assign-c.c similarity index 90% rename from test/vast/Conversion/hl-assign-b.c rename to test/vast/Conversion/assign-c.c index e7ec9ec64b..06e6c98e14 100644 --- a/test/vast/Conversion/hl-assign-b.c +++ b/test/vast/Conversion/assign-c.c @@ -1,7 +1,7 @@ // RUN: %vast-cc1 -vast-emit-mlir=llvm %s -o - | %file-check %s -// CHECK: llvm.func @count([[ARG:%arg[0-9]+]]: i32) -void count(int arg) +// CHECK: llvm.func @count +void count() { // CHECK: [[V0:%[0-9]+]] = llvm.mlir.constant(1 : index) : i64 // CHECK: [[V1:%[0-9]+]] = llvm.alloca [[V0]] x i32 : (i64) -> !llvm.ptr diff --git a/test/vast/Conversion/hl-assign-c.c b/test/vast/Conversion/assign-d.c similarity index 100% rename from test/vast/Conversion/hl-assign-c.c rename to test/vast/Conversion/assign-d.c diff --git a/test/vast/Conversion/direct-overlap-a.c b/test/vast/Conversion/direct-overlap-a.c index 877938b73d..2196ed2c1b 100644 --- a/test/vast/Conversion/direct-overlap-a.c +++ b/test/vast/Conversion/direct-overlap-a.c @@ -35,7 +35,7 @@ int sum( struct data d ) // ABI-NEXT: [[V28:%[0-9]+]] = abi.direct [[V15]] : si32 -> si32 // ABI-NEXT: {{.*}} = abi.yield [[V28]] : si32 -> si32 // ABI-NEXT: } : si32 -// ABI-NEXT: %7 = abi.yield [[V16]] : si32 -> si32 +// ABI-NEXT: abi.yield [[V16]] : si32 -> si32 // ABI-NEXT: } : (!hl.elaborated>) -> si32 // ABI-NEXT: hl.return [[V13]] : si32 diff --git a/test/vast/Conversion/do-while-a.c b/test/vast/Conversion/do-while-a.c index ecaffae1df..b6e5b31dd6 100644 --- a/test/vast/Conversion/do-while-a.c +++ b/test/vast/Conversion/do-while-a.c @@ -1,19 +1,20 @@ // RUN: %check-hl-to-ll-cf %s | %file-check %s -check-prefix=LL_CF // RUN: %check-core-to-llvm %s | %file-check %s -check-prefix=C_LLVM -// LL_CF: ll.func @fn external ([[ARG0:%.*]]: !hl.lvalue) -> none { +// LL_CF: ll.func @fn external ([[ARG0:%.*]]: !hl.lvalue) -> none +// LL_CF: hl.param @a // LL_CF: ll.scope { -// LL_CF: [[V3:%[0-9]+]] = ll.initialize {{.*}} : (!hl.lvalue, si32) -> !hl.lvalue +// LL_CF: hl.var @sum // LL_CF: ll.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb2 -// LL_CF: [[V8:%[0-9]+]] = hl.ref [[ARG0]] : !hl.lvalue +// LL_CF: [[V8:%[0-9]+]] = hl.ref @a : !hl.lvalue // LL_CF: [[V9:%[0-9]+]] = hl.implicit_cast [[V8]] LValueToRValue : !hl.lvalue -> si32 // LL_CF: [[V11:%[0-9]+]] = hl.cmp sgt [[V9]], {{.*}} : si32, si32 -> si32 // LL_CF: [[V12:%[0-9]+]] = hl.implicit_cast [[V11]] IntegralCast : si32 -> i1 // LL_CF: ll.cond_scope_ret [[V12]] : i1, ^bb2 // LL_CF: ^bb2: // 2 preds: ^bb0, ^bb1 -// LL_CF: [[V6:%[0-9]+]] = hl.ref [[ARG0]] : !hl.lvalue +// LL_CF: [[V6:%[0-9]+]] = hl.ref @a : !hl.lvalue // LL_CF: {{,*}} = hl.pre.dec [[V6]] : !hl.lvalue -> si32 // LL_CF: ll.br ^bb1 // LL_CF: } diff --git a/test/vast/Conversion/do-while-b.c b/test/vast/Conversion/do-while-b.c index 38f04d1886..c633cc4b33 100644 --- a/test/vast/Conversion/do-while-b.c +++ b/test/vast/Conversion/do-while-b.c @@ -2,8 +2,9 @@ // RUN: %check-core-to-llvm %s | %file-check %s -check-prefix=C_LLVM // LL_CF: ll.func @fn external ([[ARG0:%.*]]: !hl.lvalue) -> none { +// LL_CF: hl.param @a // LL_CF: ll.scope { -// LL_CF: [[V3:%[0-9]+]] = ll.initialize {{.*}} : (!hl.lvalue, si32) -> !hl.lvalue +// LL_CF: hl.var @sum // LL_CF: ll.scope { // LL_CF: ll.br ^bb2 // LL_CF: ^bb1: // pred: ^bb4 @@ -12,7 +13,7 @@ // LL_CF: [[B1V8:%[0-9]+]] = hl.implicit_cast [[B1V7]] IntegralCast : si32 -> i1 // LL_CF: ll.cond_scope_ret [[B1V8]] : i1, ^bb2 // LL_CF: ^bb2: // 2 preds: ^bb0, ^bb1 -// LL_CF: [[V4:%[0-9]+]] = hl.ref [[ARG0]] : !hl.lvalue +// LL_CF: [[V4:%[0-9]+]] = hl.ref @a : !hl.lvalue // LL_CF: [[V5:%[0-9]+]] = hl.implicit_cast [[V4]] LValueToRValue : !hl.lvalue -> si32 // LL_CF: [[V6:%[0-9]+]] = hl.const #core.integer<42> : si32 // LL_CF: [[V7:%[0-9]+]] = hl.cmp eq [[V5]], [[V6]] : si32, si32 -> si32 @@ -21,7 +22,7 @@ // LL_CF: ^bb3: // pred: ^bb2 // LL_CF: ll.scope_ret // LL_CF: ^bb4: // pred: ^bb2 -// LL_CF: [[V9:%[0-9]+]] = hl.ref [[V3]] : !hl.lvalue +// LL_CF: [[V9:%[0-9]+]] = hl.ref @sum : !hl.lvalue // LL_CF: [[V10:%[0-9]+]] = hl.post.inc [[V9]] : !hl.lvalue -> si32 // LL_CF: ll.br ^bb1 // LL_CF: } diff --git a/test/vast/Conversion/empty-a.c b/test/vast/Conversion/empty-a.c index 730aba83e8..5ff80b045a 100644 --- a/test/vast/Conversion/empty-a.c +++ b/test/vast/Conversion/empty-a.c @@ -2,5 +2,9 @@ // No new operations should be emitted since the args are not used. // CHECK: ll.func {{.*}} -// CHECK-NEXT: %0 = hl.const #void_value +// CHECK-NEXT: ll.cell @arg0 +// CHECK-NEXT: ll.cell_init +// CHECK-NEXT: ll.cell @arg1 +// CHECK-NEXT: ll.cell_init +// CHECK-NEXT: hl.const #void_value void empty(int arg0, int arg1) {} diff --git a/test/vast/Conversion/fn-c.c b/test/vast/Conversion/fn-c.c index 41ed3b9c51..36c8efae9f 100644 --- a/test/vast/Conversion/fn-c.c +++ b/test/vast/Conversion/fn-c.c @@ -1,4 +1,4 @@ -// RUN: %check-vast-vars-to-cells %s | %file-check %s -check-prefix=CELLS +// RUN: %check-vars-to-cells %s | %file-check %s -check-prefix=CELLS // RUN: %check-strip-param-lvalues %s | %file-check %s -check-prefix=PARAMS // RUN: %check-lower-value-categories %s | %file-check %s -check-prefix=VAL_CAT // RUN: %check-core-to-llvm %s | %file-check %s -check-prefix=C_LLVM diff --git a/test/vast/Conversion/scope-a.c b/test/vast/Conversion/scope-a.c index bc2bd2fab6..4e1add0cd8 100644 --- a/test/vast/Conversion/scope-a.c +++ b/test/vast/Conversion/scope-a.c @@ -4,12 +4,13 @@ void fn(int arg) { // LL_CF: ll.scope { - // LL_CF: [[V3:%[0-9]+]] = ll.initialize {{.*}} : (!hl.lvalue, si32) -> !hl.lvalue + // LL_CF: hl.var @a // LL_CF: ll.scope { - // LL_CF: ll.cond_br {{.8}} : i1, ^bb1, ^bb2 + // LL_CF: ll.cond_br {{.*}} : i1, ^bb1, ^bb2 // LL_CF: ^bb1: // pred: ^bb0 - // LL_CF: [[V9:%[0-9]+]] = hl.ref [[V3]] : (!hl.lvalue) -> !hl.lvalue - // LL_CF: {{.*}} = hl.assign {{.*}} to [[V9]] : si32, !hl.lvalue -> si32 + // LL_CF: hl.ref @a + // LL_CF: hl.ref @arg + // LL_CF: hl.assign // LL_CF: ll.br ^bb2 // LL_CF: ^bb2: // 2 preds: ^bb0, ^bb1 // LL_CF: ll.scope_ret diff --git a/test/vast/Conversion/select-c.c b/test/vast/Conversion/select-c.c index 3a673781e3..d68875b45e 100644 --- a/test/vast/Conversion/select-c.c +++ b/test/vast/Conversion/select-c.c @@ -27,8 +27,8 @@ int main(int argc, char** argv) // C_LLVM: llvm.cond_br {{.*}}, ^bb1, ^bb5 // C_LLVM: ^bb1: // pred: ^bb0 - // C_LLVM: {{.*}} = llvm.mlir.constant(3 : i32) : i32 - // C_LLVM: llvm.cond_br %13, ^bb2, ^bb3 + // C_LLVM: llvm.mlir.constant(3 : i32) : i32 + // C_LLVM: llvm.cond_br {{.*}}, ^bb2, ^bb3 // C_LLVM: ^bb2: // pred: ^bb1 // C_LLVM: [[V14:%[0-9]+]] = llvm.mlir.constant(0 : i32) : i32 // C_LLVM: llvm.br ^bb4([[V14]] : i32) @@ -43,7 +43,5 @@ int main(int argc, char** argv) // C_LLVM: ^bb6([[V18:%[0-9]+]]: i32): // 2 preds: ^bb4, ^bb5 // C_LLVM: llvm.return [[V18]] : i32 - - return (argc >= 3) ? ( ( argc == 3) ? 0 : 1 ) - : 2; + return (argc >= 3) ? ((argc == 3) ? 0 : 1) : 2; } diff --git a/test/vast/Conversion/shift-a.c b/test/vast/Conversion/shift-a.c index 28b506d510..969fa285e5 100644 --- a/test/vast/Conversion/shift-a.c +++ b/test/vast/Conversion/shift-a.c @@ -1,4 +1,4 @@ -// RUN: %vast-front -vast-emit-mlir=llvm %s -o - %s | %file-check %s +// RUN: %vast-front -vast-emit-mlir=llvm %s -o - | %file-check %s #include From 6baf878058b2acbf2d7ba3322a803fd5426e8949 Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Wed, 18 Sep 2024 14:48:01 +0200 Subject: [PATCH 44/50] conv:tomem: Replace invalid uses of replaceOp with eraseOp. --- lib/vast/Conversion/ToMem/VarsToCells.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vast/Conversion/ToMem/VarsToCells.cpp b/lib/vast/Conversion/ToMem/VarsToCells.cpp index f3a06b79be..8ed2f6ca8f 100644 --- a/lib/vast/Conversion/ToMem/VarsToCells.cpp +++ b/lib/vast/Conversion/ToMem/VarsToCells.cpp @@ -56,7 +56,7 @@ namespace vast::conv { rewriter.eraseOp(yield); } - rewriter.replaceOp(op, cell); + rewriter.eraseOp(op); return mlir::success(); } @@ -84,7 +84,7 @@ namespace vast::conv { auto loc = op.getLoc(); auto cell = rewriter.create< ll::Cell >(loc, type, op.getSymName()); rewriter.create< ll::CellInit >(loc, type, cell, param); - rewriter.replaceOp(op, cell); + rewriter.eraseOp(op); return mlir::success(); } From 1fd72ed03b5be94e2cffdb1598d0ac18bb33efa1 Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Wed, 18 Sep 2024 17:16:14 +0200 Subject: [PATCH 45/50] conv:tollvm: Add missing include. --- lib/vast/Conversion/ToLLVM/LLCFToLLVM.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/vast/Conversion/ToLLVM/LLCFToLLVM.hpp b/lib/vast/Conversion/ToLLVM/LLCFToLLVM.hpp index 20c7814dba..b923f51d29 100644 --- a/lib/vast/Conversion/ToLLVM/LLCFToLLVM.hpp +++ b/lib/vast/Conversion/ToLLVM/LLCFToLLVM.hpp @@ -2,6 +2,8 @@ #pragma once +#include "vast/Util/Warnings.hpp" + VAST_RELAX_WARNINGS #include #include From 961fe461f652f9abeb72d6b6cdf9013e62a75fbb Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Wed, 18 Sep 2024 17:17:06 +0200 Subject: [PATCH 46/50] util: Make trailing scope detection skip vast-specific ops. --- include/vast/Util/Scopes.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/vast/Util/Scopes.hpp b/include/vast/Util/Scopes.hpp index 7bc5fc9314..d7043222f0 100644 --- a/include/vast/Util/Scopes.hpp +++ b/include/vast/Util/Scopes.hpp @@ -5,17 +5,20 @@ #include #include "vast/Dialect/Core/CoreOps.hpp" +#include "vast/Dialect/HighLevel/HighLevelOps.hpp" namespace vast { - static inline bool is_trailing_scope(operation op) { - if (!mlir::isa< core::ScopeOp >(op)) - return false; + static inline bool is_trailing_scope(core::ScopeOp op) { if (auto parent = op->getParentRegion()) { if(parent->hasOneBlock()) { auto &block = parent->back(); auto last = std::prev(block.end()); - return block.begin() == last; + auto begin = block.begin(); + while (mlir::isa< hl::ParmVarDeclOp, hl::LabelDeclOp >(begin)) { + begin = std::next(begin); + } + return begin == last; } } return false; From 89d9c177ac107db55529c84d36a23434fb9c9b9c Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Wed, 18 Sep 2024 17:18:11 +0200 Subject: [PATCH 47/50] hl:splicescopes: Use mlir walk method instead of custom functions. --- .../Transforms/SpliceTrailingScopes.cpp | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/lib/vast/Dialect/HighLevel/Transforms/SpliceTrailingScopes.cpp b/lib/vast/Dialect/HighLevel/Transforms/SpliceTrailingScopes.cpp index 166d96e078..425ad84926 100644 --- a/lib/vast/Dialect/HighLevel/Transforms/SpliceTrailingScopes.cpp +++ b/lib/vast/Dialect/HighLevel/Transforms/SpliceTrailingScopes.cpp @@ -51,30 +51,10 @@ namespace vast::hl scope.erase(); } - void find(block_t &block) - { - for (auto &op : block.getOperations()) - find(&op); - } - - void find(Region ®ion) - { - for (auto &block : region.getBlocks()) - find(block); - } - - void find(operation op) - { - if (is_trailing_scope(op)) - to_splice.emplace_back(op); - for (auto ®ion : op->getRegions()) - find(region); - } - void runOnOperation() override { auto op = getOperation(); - find(op); + op->walk([&](core::ScopeOp op){ if (is_trailing_scope(op)) { to_splice.emplace_back(op); } }); std::reverse(to_splice.begin(), to_splice.end()); for (auto op : to_splice) splice_trailing_scope(op); From 20562923e18ea95cbc40150842942bee39fba54e Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Wed, 18 Sep 2024 17:18:49 +0200 Subject: [PATCH 48/50] conv:tomem: Add LowLevel as legal dialect to avoid legalizer issues. --- lib/vast/Conversion/ToMem/VarsToCells.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vast/Conversion/ToMem/VarsToCells.cpp b/lib/vast/Conversion/ToMem/VarsToCells.cpp index 8ed2f6ca8f..7cd0633388 100644 --- a/lib/vast/Conversion/ToMem/VarsToCells.cpp +++ b/lib/vast/Conversion/ToMem/VarsToCells.cpp @@ -102,7 +102,10 @@ namespace vast::conv { using base = ConversionPassMixin< VarsToCellsPass, VarsToCellsBase >; static conversion_target create_conversion_target(mcontext_t &mctx) { - return conversion_target(mctx); + auto trg = conversion_target(mctx); + // Block inlining might trigger legalization on some operations + trg.addLegalDialect< ll::LowLevelDialect >(); + return trg; } static void populate_conversions(auto &cfg) { From 38dac208221d6b3ea8ceb7cd7c6b02a0bc582d22 Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Thu, 19 Sep 2024 15:33:30 +0200 Subject: [PATCH 49/50] conv:tc: Resolve UB by moving methods requiring downcast out of crtp class constructor. --- include/vast/Conversion/TypeConverters/HLToStd.hpp | 4 ++++ include/vast/Conversion/TypeConverters/TypeConverter.hpp | 5 ++++- lib/vast/Conversion/ToMem/StripParamLValues.cpp | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/vast/Conversion/TypeConverters/HLToStd.hpp b/include/vast/Conversion/TypeConverters/HLToStd.hpp index 5687ca97ab..9c636997af 100644 --- a/include/vast/Conversion/TypeConverters/HLToStd.hpp +++ b/include/vast/Conversion/TypeConverters/HLToStd.hpp @@ -36,6 +36,9 @@ namespace vast::conv::tc { using base::underlying; // This is not a ctor so that users can position it as they want // in their initialization. + // These can not be moved to the constructor, because we would be downcasting + // to the dervied class while it not yet exists, resulting in UB + // Calling this in the derived class constructor should be safe void init() { underlying().addConversion(convert_decayed_type()); underlying().addConversion(convert_lvalue_type()); @@ -137,6 +140,7 @@ namespace vast::conv::tc { }); aggregates_type_converter< high_level_to_std_type_converter >::init(); + function_type_converter< high_level_to_std_type_converter >::init(); } maybe_types_t convert_type(mlir_type t) { diff --git a/include/vast/Conversion/TypeConverters/TypeConverter.hpp b/include/vast/Conversion/TypeConverters/TypeConverter.hpp index 337d1305ff..8ae205ab0c 100644 --- a/include/vast/Conversion/TypeConverters/TypeConverter.hpp +++ b/include/vast/Conversion/TypeConverters/TypeConverter.hpp @@ -59,7 +59,10 @@ namespace vast::conv::tc { using base = gap::core::crtp< derived, function_type_converter >; using base::underlying; - function_type_converter() { + // These can not be moved to the constructor, because we would be downcasting + // to the dervied class while it not yet exists, resulting in UB + // Calling this in the derived class constructor should be safe + void init() { underlying().addConversion([&](core_function_type t) -> maybe_type_t { auto [sig, results] = std::make_tuple( underlying().signature_conversion(t.getInputs()), diff --git a/lib/vast/Conversion/ToMem/StripParamLValues.cpp b/lib/vast/Conversion/ToMem/StripParamLValues.cpp index 8dfcdac2b2..508c4c3563 100644 --- a/lib/vast/Conversion/ToMem/StripParamLValues.cpp +++ b/lib/vast/Conversion/ToMem/StripParamLValues.cpp @@ -34,6 +34,7 @@ namespace vast::conv { explicit strip_param_lvalue_type_converter(mcontext_t &mctx) : mctx(mctx) { + tc::function_type_converter< strip_param_lvalue_type_converter >::init(); addConversion([&](hl::LValueType type) { return Maybe(type.getElementType()) .and_then(convert_type_to_type()) From ab0782a6c01dd987f173c0e98aef5cbe6caf220f Mon Sep 17 00:00:00 2001 From: xlauko Date: Fri, 20 Sep 2024 08:47:40 +0200 Subject: [PATCH 50/50] treewide: Fix formatting. --- include/vast/CodeGen/ScopeContext.hpp | 6 +++--- include/vast/Conversion/Passes.td | 3 --- .../vast/Conversion/TypeConverters/TypeConverter.hpp | 11 ++++------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/vast/CodeGen/ScopeContext.hpp b/include/vast/CodeGen/ScopeContext.hpp index e046f519b4..06864ec753 100644 --- a/include/vast/CodeGen/ScopeContext.hpp +++ b/include/vast/CodeGen/ScopeContext.hpp @@ -232,10 +232,10 @@ namespace vast::cg virtual ~module_scope() = default; - symbol_table_scope< string_ref, operation > functions; - symbol_table_scope< string_ref, operation > types; + symbol_table_scope< string_ref, operation > functions; + symbol_table_scope< string_ref, operation > types; symbol_table_scope< string_ref, operation > globals; - symbol_table_scope< string_ref, operation > enum_constants; + symbol_table_scope< string_ref, operation > enum_constants; }; // Scope of member names for structures and unions diff --git a/include/vast/Conversion/Passes.td b/include/vast/Conversion/Passes.td index 765a23058f..26b7d361b0 100644 --- a/include/vast/Conversion/Passes.td +++ b/include/vast/Conversion/Passes.td @@ -67,7 +67,6 @@ def IRsToLLVM : Pass<"vast-irs-to-llvm", "mlir::ModuleOp"> { def RefsToSSA : Pass<"vast-refs-to-ssa", "core::ModuleOp"> { let summary = "Lower `hl.ref` into ssa-based `ll.cell`."; - let description = [{ TBD }]; let constructor = "vast::createRefsToSSAPass()"; let dependentDialects = [ @@ -78,7 +77,6 @@ def RefsToSSA : Pass<"vast-refs-to-ssa", "core::ModuleOp"> { def StripParamLValues : Pass<"vast-strip-param-lvalues", "core::ModuleOp"> { let summary = "Strip `hl.lvalue` from types in the module."; - let description = [{ TBD }]; let constructor = "vast::createStripParamLValuesPass()"; let dependentDialects = [ @@ -88,7 +86,6 @@ def StripParamLValues : Pass<"vast-strip-param-lvalues", "core::ModuleOp"> { def VarsToCells : Pass<"vast-vars-to-cells", "core::ModuleOp"> { let summary = "Lower `hl.var` into ssa-based `ll.cell`."; - let description = [{ TBD }]; let constructor = "vast::createVarsToCellsPass()"; let dependentDialects = [ diff --git a/include/vast/Conversion/TypeConverters/TypeConverter.hpp b/include/vast/Conversion/TypeConverters/TypeConverter.hpp index 8ae205ab0c..2ce6f60b64 100644 --- a/include/vast/Conversion/TypeConverters/TypeConverter.hpp +++ b/include/vast/Conversion/TypeConverters/TypeConverter.hpp @@ -60,22 +60,19 @@ namespace vast::conv::tc { using base::underlying; // These can not be moved to the constructor, because we would be downcasting - // to the dervied class while it not yet exists, resulting in UB + // to the derived class while it not yet exists, resulting in UB // Calling this in the derived class constructor should be safe void init() { underlying().addConversion([&](core_function_type t) -> maybe_type_t { - auto [sig, results] = std::make_tuple( - underlying().signature_conversion(t.getInputs()), - underlying().convert_types_to_types(t.getResults()) - ); + auto sig = underlying().signature_conversion(t.getInputs()); + auto results = underlying().convert_types_to_types(t.getResults()); if (!sig || !results) { return std::nullopt; } return core_function_type::get( - t.getContext(), sig->getConvertedTypes(), *results, - t.isVarArg() + t.getContext(), sig->getConvertedTypes(), *results, t.isVarArg() ); }); }