From 61e96c07053bed3db561f09a6fe51ded45179594 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 20 Nov 2023 14:59:42 +0100 Subject: [PATCH 01/37] cc: Introduce CIR target dialect. --- include/vast/Frontend/Consumer.hpp | 2 +- lib/vast/Frontend/Consumer.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/vast/Frontend/Consumer.hpp b/include/vast/Frontend/Consumer.hpp index c1f5a800e6..289a33c26d 100644 --- a/include/vast/Frontend/Consumer.hpp +++ b/include/vast/Frontend/Consumer.hpp @@ -23,7 +23,7 @@ namespace vast::cc { using clang_ast_consumer = clang::ASTConsumer; // TODO: Introduce helper wrapper on top of `vast_args`? - enum class target_dialect { high_level, low_level, llvm }; + enum class target_dialect { high_level, low_level, llvm, cir }; using backend = clang::BackendAction; diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index 3655b9c3cf..a45ef36a74 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -322,6 +322,9 @@ namespace vast::cc { if (trg == "llvm") { return target_dialect::llvm; } + if (trg == "cir") { + return target_dialect::cir; + } VAST_UNREACHABLE("Unknown option of target dialect: {0}", trg); } @@ -333,6 +336,8 @@ namespace vast::cc { return "low_level"; case target_dialect::llvm: return "llvm"; + case target_dialect::cir: + return "cir"; } } From da7c7312707a10644095b752733fbadcbbcbbd3f Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 13:01:08 +0100 Subject: [PATCH 02/37] hl: Obliterate canonicalize pass. --- include/vast/Dialect/HighLevel/Passes.hpp | 2 - include/vast/Dialect/HighLevel/Passes.td | 13 --- .../HighLevel/Transforms/CMakeLists.txt | 1 - .../HighLevel/Transforms/HLCanonicalize.cpp | 92 ------------------- 4 files changed, 108 deletions(-) delete mode 100644 lib/vast/Dialect/HighLevel/Transforms/HLCanonicalize.cpp diff --git a/include/vast/Dialect/HighLevel/Passes.hpp b/include/vast/Dialect/HighLevel/Passes.hpp index 3d6667e5c5..fc94594df4 100644 --- a/include/vast/Dialect/HighLevel/Passes.hpp +++ b/include/vast/Dialect/HighLevel/Passes.hpp @@ -25,8 +25,6 @@ namespace vast::hl std::unique_ptr< mlir::Pass > createSpliceTrailingScopes(); - std::unique_ptr< mlir::Pass > createHLCanonicalizePass(); - void registerHLToLLVMIR(mlir::DialectRegistry &); void registerHLToLLVMIR(mlir::MLIRContext &); diff --git a/include/vast/Dialect/HighLevel/Passes.td b/include/vast/Dialect/HighLevel/Passes.td index 015a9d594e..3cc48cc4f8 100644 --- a/include/vast/Dialect/HighLevel/Passes.td +++ b/include/vast/Dialect/HighLevel/Passes.td @@ -90,17 +90,4 @@ def SpliceTrailingScopes : Pass<"vast-hl-splice-trailing-scopes", "mlir::ModuleO let constructor = "vast::hl::createSpliceTrailingScopes()"; } -def HLCanonicalize : Pass<"vast-hl-canonicalize", "mlir::ModuleOp"> { - let summary = "Canonicalize hl dialect."; - let description = [{ - This pass inserts returns with void values where missing and removes surplus skips. - }]; - - let constructor = "vast::hl::createHLCanonicalizePass()"; - let dependentDialects = [ - "vast::hl::HighLevelDialect", - "vast::core::CoreDialect" - ]; -} - #endif // VAST_DIALECT_HIGHLEVEL_PASSES_TD diff --git a/lib/vast/Dialect/HighLevel/Transforms/CMakeLists.txt b/lib/vast/Dialect/HighLevel/Transforms/CMakeLists.txt index 94688c250e..6c774ac1e5 100644 --- a/lib/vast/Dialect/HighLevel/Transforms/CMakeLists.txt +++ b/lib/vast/Dialect/HighLevel/Transforms/CMakeLists.txt @@ -6,6 +6,5 @@ add_vast_conversion_library(HighLevelTransforms DCE.cpp LowerTypeDefs.cpp SpliceTrailingScopes.cpp - HLCanonicalize.cpp ) diff --git a/lib/vast/Dialect/HighLevel/Transforms/HLCanonicalize.cpp b/lib/vast/Dialect/HighLevel/Transforms/HLCanonicalize.cpp deleted file mode 100644 index 0fad41115c..0000000000 --- a/lib/vast/Dialect/HighLevel/Transforms/HLCanonicalize.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2023-present, Trail of Bits, Inc. -#include "vast/Dialect/HighLevel/Passes.hpp" - -#include "vast/Util/Warnings.hpp" - -VAST_RELAX_WARNINGS -#include -VAST_UNRELAX_WARNINGS - -#include "vast/Util/Common.hpp" -#include "vast/Util/DialectConversion.hpp" - -#include "vast/Conversion/Common/Types.hpp" -#include "vast/Conversion/Common/Rewriter.hpp" - -#include "vast/Dialect/HighLevel/HighLevelDialect.hpp" -#include "vast/Dialect/HighLevel/HighLevelOps.hpp" - -#include "vast/Dialect/Core/CoreOps.hpp" - -#include "PassesDetails.hpp" - -namespace vast::hl -{ - - struct HLCanonicalize : HLCanonicalizeBase< HLCanonicalize > { - using base = HLCanonicalizeBase< HLCanonicalize >; - using rewriter_t = conv::rewriter_wrapper_t< mlir::IRRewriter >; - - std::vector< operation > to_remove; - void insert_void_return(hl::FuncOp &op, rewriter_t &rewriter ) { - auto g = rewriter.guard(); - rewriter->setInsertionPointToEnd(&op.getBody().back()); - auto void_type = rewriter->getType< hl::VoidType >(); - auto void_const = rewriter->create< hl::ConstantOp >(op.getLoc(), void_type); - rewriter->create< core::ImplicitReturnOp >(op.getLoc(), void_const.getResult()); - } - - void canonicalize_func_op(hl::FuncOp fn, rewriter_t &rewriter) { - if(!fn.isDeclaration()) { - auto &last_block = fn.getBody().back(); - if (last_block.empty() || !last_block.back().hasTrait< core::return_trait >()) - { - insert_void_return(fn, rewriter); - } - } - } - - void run(Operation *op, rewriter_t &rewriter) { - if (mlir::isa< hl::SkipStmt >(op)) { - to_remove.emplace_back(op); - return; - } - - if (auto fn = mlir::dyn_cast< hl::FuncOp >(op)) { - canonicalize_func_op(fn, rewriter); - } - - for (auto ®ion : op->getRegions()) { - run(®ion, rewriter); - } - } - - void run(Region *region, rewriter_t &rewriter) { - for (auto &block : region->getBlocks()) - run(&block, rewriter); - } - - void run(Block *block, rewriter_t &rewriter) { - for (auto &op : block->getOperations()) - run(&op, rewriter); - } - - void runOnOperation() override - { - auto op = getOperation(); - auto rewriter = mlir::IRRewriter(&getContext()); - auto bld = rewriter_t(rewriter); - - run(op, bld); - - for (auto op : to_remove) - op->erase(); - } - }; - - std::unique_ptr< mlir::Pass > createHLCanonicalizePass() - { - return std::make_unique< vast::hl::HLCanonicalize >(); - } -} // namespace vast::hl - From 9273062381188408b8df52ef769471ee3c254b44 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 13:17:49 +0100 Subject: [PATCH 03/37] util: Implement pipeline wrappers. --- include/vast/Util/Pipeline.hpp | 112 +++++++++++++++++++++++++++++++++ lib/vast/Util/CMakeLists.txt | 1 + lib/vast/Util/Pipeline.cpp | 23 +++++++ 3 files changed, 136 insertions(+) create mode 100644 include/vast/Util/Pipeline.hpp create mode 100644 lib/vast/Util/Pipeline.cpp diff --git a/include/vast/Util/Pipeline.hpp b/include/vast/Util/Pipeline.hpp new file mode 100644 index 0000000000..506b7ae385 --- /dev/null +++ b/include/vast/Util/Pipeline.hpp @@ -0,0 +1,112 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#pragma once + +#include "vast/Util/Warnings.hpp" + +VAST_RELAX_WARNINGS +#include +#include +#include +#include +#include +VAST_UNRELAX_WARNINGS + +#include "vast/Util/Common.hpp" + +#include "gap/core/generator.hpp" + +namespace vast { + + // + // pipeline is a pass manager, which keeps track of duplicit passes and does + // not schedule them twice + // + struct pipeline_t : mlir::PassManager + { + using base = mlir::PassManager; + using pass_id_t = mlir::TypeID; + + void addPass(std::unique_ptr< mlir::Pass > pass) { + auto id = pass->getTypeID(); + if (seen.count(id)) { + return; + } + + seen.insert(id); + base::addPass(std::move(pass)); + } + + llvm::DenseSet< pass_id_t > seen; + }; + + + // + // pipeline_step is a single step in the pipeline that is a pass or a list + // of pipelines + // + // Each step defiens a list of dependencies, which are scheduled before the step + // + struct pipeline_step; + + using pipeline_step_ptr = std::unique_ptr< pipeline_step >; + + using pipeline_step_builder = llvm::function_ref< pipeline_step_ptr(void) >; + + struct pipeline_step + { + explicit pipeline_step( + std::vector< pipeline_step_builder > dependencies + ) + : dependencies(std::move(dependencies)) + {} + + explicit pipeline_step() = default; + + virtual ~pipeline_step() = default; + + virtual void schedule_on(pipeline_t &ppl) const = 0; + + void schedule_dependencies(pipeline_t &ppl) const; + + std::vector< pipeline_step_builder > dependencies; + }; + + using pass_builder_t = std::unique_ptr< mlir::Pass >(void); + + struct pass_pipeline_step : pipeline_step + { + explicit pass_pipeline_step(pass_builder_t *builder) + : pass_builder(builder) + {} + + void schedule_on(pipeline_t &ppl) const override; + + static pipeline_step_ptr make(pass_builder_t *builder) { + return std::make_unique< pass_pipeline_step >(builder); + } + + pass_builder_t *pass_builder; + }; + + // compund step represents subpipeline to be run + struct compound_pipeline_step : pipeline_step + { + explicit compound_pipeline_step( + std::vector< pipeline_step_builder > dependencies + ) + : pipeline_step(std::move(dependencies)) + {} + + void schedule_on(pipeline_t &ppl) const override; + + static pipeline_step_ptr make( + std::vector< pipeline_step_builder > dependencies + ) { + return std::make_unique< compound_pipeline_step >( + std::move(dependencies) + ); + } + }; + +} // namespace vast diff --git a/lib/vast/Util/CMakeLists.txt b/lib/vast/Util/CMakeLists.txt index f86c4c8244..3a3060650e 100644 --- a/lib/vast/Util/CMakeLists.txt +++ b/lib/vast/Util/CMakeLists.txt @@ -1,6 +1,7 @@ # Copyright (c) 2022-present, Trail of Bits, Inc. add_vast_library(Util + Pipeline.cpp Region.cpp Warnings.cpp ) diff --git a/lib/vast/Util/Pipeline.cpp b/lib/vast/Util/Pipeline.cpp new file mode 100644 index 0000000000..2f373696c0 --- /dev/null +++ b/lib/vast/Util/Pipeline.cpp @@ -0,0 +1,23 @@ + +// Copyright (c) 2023, Trail of Bits, Inc. + +#include "vast/Util/Pipeline.hpp" + +namespace vast { + void pipeline_step::schedule_dependencies(pipeline_t &ppl) const { + for (const auto &dep : dependencies) { + dep()->schedule_on(ppl); + } + } + + void pass_pipeline_step::schedule_on(pipeline_t &ppl) const { + schedule_dependencies(ppl); + ppl.addPass(pass_builder()); + } + + + void compound_pipeline_step::schedule_on(pipeline_t &ppl) const { + schedule_dependencies(ppl); + } + +} // namespace vast From 6dbd9679b237d91d81752ff498e529bd8f124142 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 13:21:39 +0100 Subject: [PATCH 04/37] hl: Setup canonicalize pipeline. --- include/vast/Dialect/HighLevel/Passes.hpp | 4 ++++ lib/vast/Dialect/HighLevel/CMakeLists.txt | 1 + lib/vast/Dialect/HighLevel/Passes.cpp | 24 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 lib/vast/Dialect/HighLevel/Passes.cpp diff --git a/include/vast/Dialect/HighLevel/Passes.hpp b/include/vast/Dialect/HighLevel/Passes.hpp index fc94594df4..550a3e0efe 100644 --- a/include/vast/Dialect/HighLevel/Passes.hpp +++ b/include/vast/Dialect/HighLevel/Passes.hpp @@ -11,6 +11,8 @@ VAST_RELAX_WARNINGS VAST_UNRELAX_WARNINGS #include +#include + #include namespace vast::hl @@ -39,4 +41,6 @@ namespace vast::hl pm.addPass(createLowerTypeDefsPass()); } + pipeline_step_ptr make_canonicalize_pipeline(); + } // namespace vast::hl diff --git a/lib/vast/Dialect/HighLevel/CMakeLists.txt b/lib/vast/Dialect/HighLevel/CMakeLists.txt index 030aa8e784..e52c6d5129 100644 --- a/lib/vast/Dialect/HighLevel/CMakeLists.txt +++ b/lib/vast/Dialect/HighLevel/CMakeLists.txt @@ -6,6 +6,7 @@ add_vast_dialect_library(HighLevel HighLevelOps.cpp HighLevelAttributes.cpp HighLevelTypes.cpp + Passes.cpp LINK_LIBS PRIVATE VASTAliasTypeInterface diff --git a/lib/vast/Dialect/HighLevel/Passes.cpp b/lib/vast/Dialect/HighLevel/Passes.cpp new file mode 100644 index 0000000000..58e535c7ca --- /dev/null +++ b/lib/vast/Dialect/HighLevel/Passes.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#include "vast/Util/Warnings.hpp" + +VAST_RELAX_WARNINGS +#include +#include +VAST_UNRELAX_WARNINGS + +#include "vast/Dialect/HighLevel/Passes.hpp" + +namespace vast::cg { + + static pipeline_step_ptr splice_trailing_scopes() { + return pass_pipeline_step::make(hl::createSpliceTrailingScopes); + } + + pipeline_step_ptr make_canonicalize_pipeline() { + return compound_pipeline_step::make({ + splice_trailing_scopes, + }); + } + +} // namespace vast::cg From 9a2f835b402b8fb387da7d9ce9bb17d74d98da29 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 13:22:22 +0100 Subject: [PATCH 05/37] cc: Specify default pipelines config. --- include/vast/Frontend/Pipelines.hpp | 21 +++++++++++++++++++++ lib/vast/Frontend/CMakeLists.txt | 1 + lib/vast/Frontend/Pipelines.cpp | 15 +++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 include/vast/Frontend/Pipelines.hpp create mode 100644 lib/vast/Frontend/Pipelines.cpp diff --git a/include/vast/Frontend/Pipelines.hpp b/include/vast/Frontend/Pipelines.hpp new file mode 100644 index 0000000000..6336efc122 --- /dev/null +++ b/include/vast/Frontend/Pipelines.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#pragma once + +#include "vast/Util/Warnings.hpp" + +VAST_RELAX_WARNINGS +#include +VAST_UNRELAX_WARNINGS + +#include "vast/Util/Pipeline.hpp" + +namespace vast::cc { + + struct pipelines_config { + llvm::StringMap< pipeline_step_builder > pipelines; + }; + + pipelines_config default_pipelines_config(); + +} // namespace vast::cc diff --git a/lib/vast/Frontend/CMakeLists.txt b/lib/vast/Frontend/CMakeLists.txt index a864b40b88..91530ffbe1 100644 --- a/lib/vast/Frontend/CMakeLists.txt +++ b/lib/vast/Frontend/CMakeLists.txt @@ -4,6 +4,7 @@ add_vast_library(Frontend Action.cpp Consumer.cpp Options.cpp + Pipelines.cpp LINK_LIBS PUBLIC VASTCodeGen diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp new file mode 100644 index 0000000000..4a34afe79c --- /dev/null +++ b/lib/vast/Frontend/Pipelines.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#include "vast/Frontend/Pipelines.hpp" + +#include "vast/Dialect/HighLevel/Passes.hpp" + +namespace vast::cc { + + pipelines_config default_pipelines_config() { + return pipelines_config{{ + { "canonicalize", hl::make_canonicalize_pipeline }, + }}; + } + +} // namespace vast::cc From 811031b9938dcfb5093241b8a9ae5c67c2009586 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 13:23:31 +0100 Subject: [PATCH 06/37] cc: Simplify optional list options. --- include/vast/Frontend/Options.hpp | 3 +-- lib/vast/Frontend/Options.cpp | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/vast/Frontend/Options.hpp b/include/vast/Frontend/Options.hpp index 49047848ad..1ca1ac3f24 100644 --- a/include/vast/Frontend/Options.hpp +++ b/include/vast/Frontend/Options.hpp @@ -47,7 +47,6 @@ namespace vast::cc struct vast_args { using option_list = std::vector< string_ref >; - using maybe_option_list = std::optional< option_list >; argv_storage args; @@ -60,7 +59,7 @@ namespace vast::cc std::optional< string_ref > get_option(string_ref opt) const; // from option of form -vast-"name"="value1;value2;value3" returns list of values - maybe_option_list get_options_list(string_ref opt) const; + std::optional< option_list > get_options_list(string_ref opt) const; void push_back(arg_t arg); }; diff --git a/lib/vast/Frontend/Options.cpp b/lib/vast/Frontend/Options.cpp index 09913640f2..453d7a33f9 100644 --- a/lib/vast/Frontend/Options.cpp +++ b/lib/vast/Frontend/Options.cpp @@ -35,9 +35,14 @@ namespace vast::cc { return detail::get_option_impl(args, name).has_value(); } + bool is_options_list(string_ref opt) { + return opt.contains(';'); + } + std::optional< string_ref > vast_args::get_option(string_ref name) const { if (auto opt = detail::get_option_impl(args, name)) { if (auto [lhs, rhs] = opt->split('='); !rhs.empty()) { + VAST_ASSERT(!is_options_list(rhs)); return rhs; } } From 7f27af345cf9c3a21c1cdbbd28fff27e1c02eea6 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 14:18:11 +0100 Subject: [PATCH 07/37] util: Add pipelines initializer state. --- include/vast/Util/Pipeline.hpp | 46 ++++++++++++++++++++++++---------- lib/vast/Util/Pipeline.cpp | 7 ++++++ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/include/vast/Util/Pipeline.hpp b/include/vast/Util/Pipeline.hpp index 506b7ae385..2e773743da 100644 --- a/include/vast/Util/Pipeline.hpp +++ b/include/vast/Util/Pipeline.hpp @@ -53,6 +53,26 @@ namespace vast { using pipeline_step_builder = llvm::function_ref< pipeline_step_ptr(void) >; + // + // initilizer wrapper to setup dependencies after make is called + // + template< typename step_t > + struct pipeline_step_init : pipeline_step_ptr { + using pipeline_step_ptr::pipeline_step_ptr; + + template< typename ...Args > + pipeline_step_init(Args &&...args) + : pipeline_step_ptr(std::make_unique< step_t >( + std::forward< Args >(args)... + )) + {} + + pipeline_step_init depends_on(std::vector< pipeline_step_builder > deps) && { + get()->depends_on(std::move(deps)); + return std::move(*this); + } + }; + struct pipeline_step { explicit pipeline_step( @@ -69,44 +89,44 @@ namespace vast { void schedule_dependencies(pipeline_t &ppl) const; + void depends_on(std::vector< pipeline_step_builder > deps); + std::vector< pipeline_step_builder > dependencies; }; - using pass_builder_t = std::unique_ptr< mlir::Pass >(void); + using pass_builder_t = llvm::function_ref< std::unique_ptr< mlir::Pass >(void) >; struct pass_pipeline_step : pipeline_step { - explicit pass_pipeline_step(pass_builder_t *builder) + explicit pass_pipeline_step(pass_builder_t builder) : pass_builder(builder) {} void schedule_on(pipeline_t &ppl) const override; - static pipeline_step_ptr make(pass_builder_t *builder) { - return std::make_unique< pass_pipeline_step >(builder); + static decltype(auto) make(pass_builder_t builder) { + return pipeline_step_init< pass_pipeline_step >(builder); } - pass_builder_t *pass_builder; + pass_builder_t pass_builder; }; // compund step represents subpipeline to be run struct compound_pipeline_step : pipeline_step { explicit compound_pipeline_step( - std::vector< pipeline_step_builder > dependencies + std::vector< pipeline_step_builder > steps ) - : pipeline_step(std::move(dependencies)) + : steps(std::move(steps)) {} void schedule_on(pipeline_t &ppl) const override; - static pipeline_step_ptr make( - std::vector< pipeline_step_builder > dependencies - ) { - return std::make_unique< compound_pipeline_step >( - std::move(dependencies) - ); + static decltype(auto) make(std::vector< pipeline_step_builder > dependencies) { + return pipeline_step_init< compound_pipeline_step >(std::move(dependencies)); } + + std::vector< pipeline_step_builder > steps; }; } // namespace vast diff --git a/lib/vast/Util/Pipeline.cpp b/lib/vast/Util/Pipeline.cpp index 2f373696c0..375575d04f 100644 --- a/lib/vast/Util/Pipeline.cpp +++ b/lib/vast/Util/Pipeline.cpp @@ -10,6 +10,10 @@ namespace vast { } } + void pipeline_step::depends_on(std::vector< pipeline_step_builder > deps) { + std::ranges::move(deps, std::back_inserter(dependencies)); + } + void pass_pipeline_step::schedule_on(pipeline_t &ppl) const { schedule_dependencies(ppl); ppl.addPass(pass_builder()); @@ -18,6 +22,9 @@ namespace vast { void compound_pipeline_step::schedule_on(pipeline_t &ppl) const { schedule_dependencies(ppl); + for (const auto &step : steps) { + step()->schedule_on(ppl); + } } } // namespace vast From 9b465e5a6968eb8b1ea9cea502e01508f1fffa72 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 14:18:51 +0100 Subject: [PATCH 08/37] hl: Setup more conversion pipelines. --- include/vast/Dialect/HighLevel/Passes.hpp | 22 ++++++---- lib/vast/Dialect/HighLevel/Passes.cpp | 53 +++++++++++++++++++++-- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/include/vast/Dialect/HighLevel/Passes.hpp b/include/vast/Dialect/HighLevel/Passes.hpp index 550a3e0efe..d526382e25 100644 --- a/include/vast/Dialect/HighLevel/Passes.hpp +++ b/include/vast/Dialect/HighLevel/Passes.hpp @@ -15,8 +15,7 @@ VAST_UNRELAX_WARNINGS #include -namespace vast::hl -{ +namespace vast::hl { std::unique_ptr< mlir::Pass > createHLLowerTypesPass(); std::unique_ptr< mlir::Pass > createExportFnInfoPass(); @@ -30,17 +29,24 @@ namespace vast::hl void registerHLToLLVMIR(mlir::DialectRegistry &); void registerHLToLLVMIR(mlir::MLIRContext &); - /// Generate the code for registering passes. - #define GEN_PASS_REGISTRATION - #include "vast/Dialect/HighLevel/Passes.h.inc" +/// Generate the code for registering passes. +#define GEN_PASS_REGISTRATION +#include "vast/Dialect/HighLevel/Passes.h.inc" - static inline void build_simplify_hl_pipeline(mlir::PassManager &pm) - { + static inline void build_simplify_hl_pipeline(mlir::PassManager &pm) { pm.addPass(createHLLowerTypesPass()); pm.addPass(createDCEPass()); pm.addPass(createLowerTypeDefsPass()); } - pipeline_step_ptr make_canonicalize_pipeline(); + namespace pipeline { + pipeline_step_ptr canonicalize(); + + pipeline_step_ptr desugar(); + + pipeline_step_ptr simplify(); + + pipeline_step_ptr stdtypes(); + } // namespace pipeline } // namespace vast::hl diff --git a/lib/vast/Dialect/HighLevel/Passes.cpp b/lib/vast/Dialect/HighLevel/Passes.cpp index 58e535c7ca..031245fcb3 100644 --- a/lib/vast/Dialect/HighLevel/Passes.cpp +++ b/lib/vast/Dialect/HighLevel/Passes.cpp @@ -9,16 +9,63 @@ VAST_UNRELAX_WARNINGS #include "vast/Dialect/HighLevel/Passes.hpp" -namespace vast::cg { +namespace vast::hl::pipeline { + // + // canonicalization pipeline passes + // static pipeline_step_ptr splice_trailing_scopes() { return pass_pipeline_step::make(hl::createSpliceTrailingScopes); } - pipeline_step_ptr make_canonicalize_pipeline() { + // TODO: add more passes here (remove reduntant skips etc.) + + pipeline_step_ptr canonicalize() { return compound_pipeline_step::make({ splice_trailing_scopes, }); } -} // namespace vast::cg + // + // desugar pipeline passes + // + static pipeline_step_ptr lower_types() { + return pass_pipeline_step::make(hl::createLowerTypeDefsPass); + } + + // TODO: add more passes here (remove elaborations, decayed types, lvalue types etc.) + + pipeline_step_ptr desugar() { + return compound_pipeline_step::make({ + lower_types + }); + } + + // + // simplifcaiton passes + // + static pipeline_step_ptr dce() { + return pass_pipeline_step::make(hl::createDCEPass) + .depends_on({ canonicalize }); + } + + pipeline_step_ptr simplify() { + return compound_pipeline_step::make({ + dce, desugar + }); + } + + // + // stdtypes passes + // + static pipeline_step_ptr lower_types_to_std() { + return pass_pipeline_step::make(hl::createHLLowerTypesPass); + } + + pipeline_step_ptr stdtypes() { + return compound_pipeline_step::make({ + lower_types_to_std + }).depends_on({ desugar }); + } + +} // namespace vast::hl::pipeline From fb06c335b3fda3fc364ba44308c524fd7d0a217c Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 14:19:09 +0100 Subject: [PATCH 09/37] cc: Update pipelines config. --- lib/vast/Frontend/Pipelines.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index 4a34afe79c..1d103adff4 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -8,7 +8,10 @@ namespace vast::cc { pipelines_config default_pipelines_config() { return pipelines_config{{ - { "canonicalize", hl::make_canonicalize_pipeline }, + { "canonicalize", hl::pipeline::canonicalize }, + { "desugar", hl::pipeline::desugar }, + { "simplify", hl::pipeline::simplify }, + { "stdtypes", hl::pipeline::stdtypes } }}; } From 1a3a35c4edca04bbbdaea943b05276c97c06d191 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 15:26:23 +0100 Subject: [PATCH 10/37] util: Simplify pipeline constructors. --- include/vast/Util/Pipeline.hpp | 64 ++++++++++++++++++++++++---------- lib/vast/Util/Pipeline.cpp | 12 ++++--- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/include/vast/Util/Pipeline.hpp b/include/vast/Util/Pipeline.hpp index 2e773743da..72bd8d66e2 100644 --- a/include/vast/Util/Pipeline.hpp +++ b/include/vast/Util/Pipeline.hpp @@ -60,15 +60,16 @@ namespace vast { struct pipeline_step_init : pipeline_step_ptr { using pipeline_step_ptr::pipeline_step_ptr; - template< typename ...Args > - pipeline_step_init(Args &&...args) + template< typename ...args_t > + pipeline_step_init(args_t &&...args) : pipeline_step_ptr(std::make_unique< step_t >( - std::forward< Args >(args)... + std::forward< args_t >(args)... )) {} - pipeline_step_init depends_on(std::vector< pipeline_step_builder > deps) && { - get()->depends_on(std::move(deps)); + template< typename ...deps_t > + pipeline_step_init depends_on(deps_t &&... deps) && { + get()->depends_on(std::forward< deps_t >(deps)...); return std::move(*this); } }; @@ -89,7 +90,10 @@ namespace vast { void schedule_dependencies(pipeline_t &ppl) const; - void depends_on(std::vector< pipeline_step_builder > deps); + template< typename ...deps_t > + void depends_on(deps_t &&... deps) { + (dependencies.emplace_back(std::forward< deps_t >(deps)), ...); + } std::vector< pipeline_step_builder > dependencies; }; @@ -104,29 +108,51 @@ namespace vast { void schedule_on(pipeline_t &ppl) const override; - static decltype(auto) make(pass_builder_t builder) { - return pipeline_step_init< pass_pipeline_step >(builder); - } - pass_builder_t pass_builder; }; - // compund step represents subpipeline to be run + // compound step represents subpipeline to be run struct compound_pipeline_step : pipeline_step { - explicit compound_pipeline_step( - std::vector< pipeline_step_builder > steps - ) - : steps(std::move(steps)) + template< typename... steps_t > + explicit compound_pipeline_step(steps_t &&...steps) + : steps{ std::forward< steps_t >(steps)... } {} void schedule_on(pipeline_t &ppl) const override; - static decltype(auto) make(std::vector< pipeline_step_builder > dependencies) { - return pipeline_step_init< compound_pipeline_step >(std::move(dependencies)); - } - std::vector< pipeline_step_builder > steps; }; + struct optional_pipeline : pipeline_step { + + explicit optional_pipeline(pipeline_step_builder step) + : step(std::move(step)) + {} + + void schedule_on(pipeline_t &ppl) const override; + + bool enabled = true; + pipeline_step_builder step; + }; + + template< typename... args_t > + decltype(auto) pass(args_t &&... args) { + return pipeline_step_init< pass_pipeline_step >( + std::forward< args_t >(args)... + ); + } + + template< auto step > + decltype(auto) optional() { + return pipeline_step_init< optional_pipeline >(step); + } + + template< typename... steps_t > + decltype(auto) compose(steps_t &&...steps) { + return pipeline_step_init< compound_pipeline_step >( + std::forward< steps_t >(steps)... + ); + } + } // namespace vast diff --git a/lib/vast/Util/Pipeline.cpp b/lib/vast/Util/Pipeline.cpp index 375575d04f..e1611afa52 100644 --- a/lib/vast/Util/Pipeline.cpp +++ b/lib/vast/Util/Pipeline.cpp @@ -10,10 +10,6 @@ namespace vast { } } - void pipeline_step::depends_on(std::vector< pipeline_step_builder > deps) { - std::ranges::move(deps, std::back_inserter(dependencies)); - } - void pass_pipeline_step::schedule_on(pipeline_t &ppl) const { schedule_dependencies(ppl); ppl.addPass(pass_builder()); @@ -27,4 +23,12 @@ namespace vast { } } + void optional_pipeline::schedule_on(pipeline_t &ppl) const { + if (enabled) { + schedule_dependencies(ppl); + step()->schedule_on(ppl); + } + } + + } // namespace vast From 13b1a998028cbfa18772492b648479d4398c1481 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 15:26:53 +0100 Subject: [PATCH 11/37] hl: Update pipelines to simplified form. --- lib/vast/Dialect/HighLevel/Passes.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/lib/vast/Dialect/HighLevel/Passes.cpp b/lib/vast/Dialect/HighLevel/Passes.cpp index 031245fcb3..99f3613b16 100644 --- a/lib/vast/Dialect/HighLevel/Passes.cpp +++ b/lib/vast/Dialect/HighLevel/Passes.cpp @@ -15,57 +15,48 @@ namespace vast::hl::pipeline { // canonicalization pipeline passes // static pipeline_step_ptr splice_trailing_scopes() { - return pass_pipeline_step::make(hl::createSpliceTrailingScopes); + return pass(hl::createSpliceTrailingScopes); } // TODO: add more passes here (remove reduntant skips etc.) pipeline_step_ptr canonicalize() { - return compound_pipeline_step::make({ - splice_trailing_scopes, - }); + return compose(splice_trailing_scopes); } // // desugar pipeline passes // static pipeline_step_ptr lower_types() { - return pass_pipeline_step::make(hl::createLowerTypeDefsPass); + return pass(hl::createLowerTypeDefsPass); } // TODO: add more passes here (remove elaborations, decayed types, lvalue types etc.) pipeline_step_ptr desugar() { - return compound_pipeline_step::make({ - lower_types - }); + return compose(lower_types); } // // simplifcaiton passes // static pipeline_step_ptr dce() { - return pass_pipeline_step::make(hl::createDCEPass) - .depends_on({ canonicalize }); + return pass(hl::createDCEPass).depends_on(canonicalize); } pipeline_step_ptr simplify() { - return compound_pipeline_step::make({ - dce, desugar - }); + return compose(optional< dce >, optional< desugar >); } // // stdtypes passes // static pipeline_step_ptr lower_types_to_std() { - return pass_pipeline_step::make(hl::createHLLowerTypesPass); + return pass(hl::createHLLowerTypesPass); } pipeline_step_ptr stdtypes() { - return compound_pipeline_step::make({ - lower_types_to_std - }).depends_on({ desugar }); + return compose(lower_types_to_std).depends_on(desugar); } } // namespace vast::hl::pipeline From f675bbc8d9922157e72504884997c709a2a46c37 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 27 Nov 2023 16:48:22 +0100 Subject: [PATCH 12/37] cc: Refactor target dialects. --- include/vast/Frontend/Consumer.hpp | 4 +-- include/vast/Frontend/Targets.hpp | 15 +++++++++ lib/vast/Frontend/CMakeLists.txt | 1 + lib/vast/Frontend/Consumer.cpp | 54 +++++------------------------- lib/vast/Frontend/Targets.cpp | 34 +++++++++++++++++++ 5 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 include/vast/Frontend/Targets.hpp create mode 100644 lib/vast/Frontend/Targets.cpp diff --git a/include/vast/Frontend/Consumer.hpp b/include/vast/Frontend/Consumer.hpp index 289a33c26d..54e9390edd 100644 --- a/include/vast/Frontend/Consumer.hpp +++ b/include/vast/Frontend/Consumer.hpp @@ -12,6 +12,7 @@ VAST_UNRELAX_WARNINGS #include "vast/Frontend/Diagnostics.hpp" #include "vast/Frontend/FrontendAction.hpp" #include "vast/Frontend/Options.hpp" +#include "vast/Frontend/Targets.hpp" #include "vast/CodeGen/CodeGenContext.hpp" #include "vast/CodeGen/CodeGenDriver.hpp" @@ -22,9 +23,6 @@ namespace vast::cc { using clang_ast_consumer = clang::ASTConsumer; - // TODO: Introduce helper wrapper on top of `vast_args`? - enum class target_dialect { high_level, low_level, llvm, cir }; - using backend = clang::BackendAction; struct vast_consumer : clang_ast_consumer diff --git a/include/vast/Frontend/Targets.hpp b/include/vast/Frontend/Targets.hpp new file mode 100644 index 0000000000..15f945df97 --- /dev/null +++ b/include/vast/Frontend/Targets.hpp @@ -0,0 +1,15 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#pragma once + +#include "vast/Util/Common.hpp" + +namespace vast::cc { + + enum class target_dialect { high_level, std, llvm, cir }; + + target_dialect parse_target_dialect(string_ref from); + + std::string to_string(target_dialect target); + +} // namespace vast::cc diff --git a/lib/vast/Frontend/CMakeLists.txt b/lib/vast/Frontend/CMakeLists.txt index 91530ffbe1..ba00eb40e4 100644 --- a/lib/vast/Frontend/CMakeLists.txt +++ b/lib/vast/Frontend/CMakeLists.txt @@ -5,6 +5,7 @@ add_vast_library(Frontend Consumer.cpp Options.cpp Pipelines.cpp + Targets.cpp LINK_LIBS PUBLIC VASTCodeGen diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index a45ef36a74..e5a6c4e013 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -5,6 +5,8 @@ VAST_RELAX_WARNINGS #include +#include + #include #include @@ -18,6 +20,7 @@ VAST_UNRELAX_WARNINGS #include "vast/Util/Common.hpp" +#include "vast/Frontend/Targets.hpp" #include "vast/Target/LLVMIR/Convert.hpp" namespace vast::cc { @@ -26,9 +29,7 @@ namespace vast::cc { using pipeline = llvmir::pipeline; - [[nodiscard]] target_dialect parse_target_dialect(const vast_args::maybe_option_list &list); - - [[nodiscard]] pipeline parse_pipeline(const vast_args::maybe_option_list &list); + [[nodiscard]] pipeline parse_pipeline(const std::optional< vast_args::option_list > &list); [[nodiscard]] pipeline parse_pipeline(string_ref from); @@ -157,7 +158,7 @@ namespace vast::cc { backend::Backend_EmitAssembly, std::move(mod), mctx.get() ); case output_type::emit_mlir: { - auto trg = parse_target_dialect(vargs.get_options_list(opt::emit_mlir)); + auto trg = parse_target_dialect(vargs.get_option(opt::emit_mlir).value()); return emit_mlir_output(trg, std::move(mod), mctx.get()); } case output_type::emit_llvm: @@ -207,6 +208,8 @@ namespace vast::cc { llvmir::lower_hl_module(mod.get(), pipeline); break; } + // case target_dialect::cir: { + // } default: VAST_UNREACHABLE("Cannot emit {0}, missing support", to_string(target)); } @@ -275,19 +278,7 @@ namespace vast::cc { VAST_UNIMPLEMENTED_MSG("VAST does not yet support the given source language"); } - target_dialect parse_target_dialect(const vast_args::maybe_option_list &list) { - if (!list) { - return target_dialect::high_level; - } - - if (list->size() != 1) { - VAST_UNREACHABLE("Can emit only one dialect."); - } - - return parse_target_dialect(list->front()); - } - - pipeline parse_pipeline(const vast_args::maybe_option_list &list) { + pipeline parse_pipeline(const std::optional< vast_args::option_list > &list) { if (!list) { return llvmir::default_pipeline(); } @@ -311,34 +302,5 @@ namespace vast::cc { VAST_UNREACHABLE("Unknown option of pipeline to use: {0}", trg); } - target_dialect parse_target_dialect(string_ref from) { - auto trg = from.lower(); - if (trg == "hl" || trg == "high_level") { - return target_dialect::high_level; - } - if (trg == "ll" || trg == "low_level") { - return target_dialect::low_level; - } - if (trg == "llvm") { - return target_dialect::llvm; - } - if (trg == "cir") { - return target_dialect::cir; - } - VAST_UNREACHABLE("Unknown option of target dialect: {0}", trg); - } - - std::string to_string(target_dialect target) { - switch (target) { - case target_dialect::high_level: - return "high_level"; - case target_dialect::low_level: - return "low_level"; - case target_dialect::llvm: - return "llvm"; - case target_dialect::cir: - return "cir"; - } - } } // namespace vast::cc diff --git a/lib/vast/Frontend/Targets.cpp b/lib/vast/Frontend/Targets.cpp new file mode 100644 index 0000000000..afa9fe2185 --- /dev/null +++ b/lib/vast/Frontend/Targets.cpp @@ -0,0 +1,34 @@ +#include "vast/Frontend/Targets.hpp" + +namespace vast::cc { + target_dialect parse_target_dialect(string_ref from) { + auto trg = from.lower(); + if (trg == "hl" || trg == "high_level") { + return target_dialect::high_level; + } + if (trg == "std") { + return target_dialect::std; + } + if (trg == "llvm") { + return target_dialect::llvm; + } + if (trg == "cir") { + return target_dialect::cir; + } + VAST_UNREACHABLE("Unknown option of target dialect: {0}", trg); + } + + std::string to_string(target_dialect target) { + switch (target) { + case target_dialect::high_level: + return "high_level"; + case target_dialect::std: + return "std"; + case target_dialect::llvm: + return "llvm"; + case target_dialect::cir: + return "cir"; + } + } + +} // namespace vast::cc From 7bd89d17a3ce58176ab0bcc2c584e153fb285b6c Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Tue, 5 Dec 2023 17:53:43 +0100 Subject: [PATCH 13/37] cc: Move output types to targets. --- include/vast/Frontend/Action.hpp | 1 + include/vast/Frontend/FrontendAction.hpp | 8 -------- include/vast/Frontend/Targets.hpp | 8 ++++++++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/vast/Frontend/Action.hpp b/include/vast/Frontend/Action.hpp index 141f44d0bb..d5e2a059cb 100644 --- a/include/vast/Frontend/Action.hpp +++ b/include/vast/Frontend/Action.hpp @@ -12,6 +12,7 @@ VAST_UNRELAX_WARNINGS #include "vast/Frontend/CompilerInstance.hpp" #include "vast/Frontend/FrontendAction.hpp" #include "vast/Frontend/Options.hpp" +#include "vast/Frontend/Targets.hpp" namespace llvm { class LLVMIRContext; diff --git a/include/vast/Frontend/FrontendAction.hpp b/include/vast/Frontend/FrontendAction.hpp index 3f231424ce..7be83ef1b3 100644 --- a/include/vast/Frontend/FrontendAction.hpp +++ b/include/vast/Frontend/FrontendAction.hpp @@ -16,14 +16,6 @@ namespace vast::cc { using frontend_action = clang::ASTFrontendAction; using plugin_ast_action = clang::PluginASTAction; - enum class output_type { - emit_assembly, - emit_mlir, - emit_llvm, - emit_obj, - none - }; - static inline action_options options(compiler_instance &ci) { return { .headers = ci.getHeaderSearchOpts(), diff --git a/include/vast/Frontend/Targets.hpp b/include/vast/Frontend/Targets.hpp index 15f945df97..fc724ca2db 100644 --- a/include/vast/Frontend/Targets.hpp +++ b/include/vast/Frontend/Targets.hpp @@ -6,6 +6,14 @@ namespace vast::cc { + enum class output_type { + emit_assembly, + emit_mlir, + emit_llvm, + emit_obj, + none + }; + enum class target_dialect { high_level, std, llvm, cir }; target_dialect parse_target_dialect(string_ref from); From ca5a1f59008933b99a96bcdf59e5b262c94a908f Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Tue, 5 Dec 2023 17:54:54 +0100 Subject: [PATCH 14/37] util: Add better pipeline chaining. --- include/vast/Util/Pipeline.hpp | 28 ++++++++++++++++------------ lib/vast/Util/Pipeline.cpp | 10 ++++++++-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/vast/Util/Pipeline.hpp b/include/vast/Util/Pipeline.hpp index 72bd8d66e2..4e795490d0 100644 --- a/include/vast/Util/Pipeline.hpp +++ b/include/vast/Util/Pipeline.hpp @@ -18,6 +18,17 @@ VAST_UNRELAX_WARNINGS namespace vast { + // + // pipeline_step is a single step in the pipeline that is a pass or a list + // of pipelines + // + // Each step defiens a list of dependencies, which are scheduled before the step + // + struct pipeline_step; + + using pipeline_step_ptr = std::unique_ptr< pipeline_step >; + + // // pipeline is a pass manager, which keeps track of duplicit passes and does // not schedule them twice @@ -27,6 +38,8 @@ namespace vast { using base = mlir::PassManager; using pass_id_t = mlir::TypeID; + using base::base; + void addPass(std::unique_ptr< mlir::Pass > pass) { auto id = pass->getTypeID(); if (seen.count(id)) { @@ -37,20 +50,12 @@ namespace vast { base::addPass(std::move(pass)); } + friend pipeline_t &operator<<(pipeline_t &ppl, pipeline_step_ptr pass); + llvm::DenseSet< pass_id_t > seen; }; - // - // pipeline_step is a single step in the pipeline that is a pass or a list - // of pipelines - // - // Each step defiens a list of dependencies, which are scheduled before the step - // - struct pipeline_step; - - using pipeline_step_ptr = std::unique_ptr< pipeline_step >; - using pipeline_step_builder = llvm::function_ref< pipeline_step_ptr(void) >; // @@ -86,7 +91,7 @@ namespace vast { virtual ~pipeline_step() = default; - virtual void schedule_on(pipeline_t &ppl) const = 0; + virtual void schedule_on(pipeline_t &ppl) const; void schedule_dependencies(pipeline_t &ppl) const; @@ -125,7 +130,6 @@ namespace vast { }; struct optional_pipeline : pipeline_step { - explicit optional_pipeline(pipeline_step_builder step) : step(std::move(step)) {} diff --git a/lib/vast/Util/Pipeline.cpp b/lib/vast/Util/Pipeline.cpp index e1611afa52..5add79b547 100644 --- a/lib/vast/Util/Pipeline.cpp +++ b/lib/vast/Util/Pipeline.cpp @@ -4,6 +4,14 @@ #include "vast/Util/Pipeline.hpp" namespace vast { + + pipeline_t &operator<<(pipeline_t &ppl, pipeline_step_ptr pass) { + pass->schedule_on(ppl); + return ppl; + } + + void pipeline_step::schedule_on(pipeline_t &) const {} + void pipeline_step::schedule_dependencies(pipeline_t &ppl) const { for (const auto &dep : dependencies) { dep()->schedule_on(ppl); @@ -15,7 +23,6 @@ namespace vast { ppl.addPass(pass_builder()); } - void compound_pipeline_step::schedule_on(pipeline_t &ppl) const { schedule_dependencies(ppl); for (const auto &step : steps) { @@ -30,5 +37,4 @@ namespace vast { } } - } // namespace vast From bfd2b9c644d5d9ac697f7be577c63a5c849555bf Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Tue, 5 Dec 2023 17:55:52 +0100 Subject: [PATCH 15/37] cc: Implement pipeline builder. --- include/vast/Frontend/Pipelines.hpp | 25 +++++++ lib/vast/Frontend/Pipelines.cpp | 109 ++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) diff --git a/include/vast/Frontend/Pipelines.hpp b/include/vast/Frontend/Pipelines.hpp index 6336efc122..9fe0c2f4cb 100644 --- a/include/vast/Frontend/Pipelines.hpp +++ b/include/vast/Frontend/Pipelines.hpp @@ -9,6 +9,8 @@ VAST_RELAX_WARNINGS VAST_UNRELAX_WARNINGS #include "vast/Util/Pipeline.hpp" +#include "vast/Frontend/Options.hpp" +#include "vast/Frontend/Targets.hpp" namespace vast::cc { @@ -18,4 +20,27 @@ namespace vast::cc { pipelines_config default_pipelines_config(); + enum class pipeline_source { ast }; + + // + // Create pipeline schedule from source `src` to target `trg` + // + // Source can be either AST or MLIR dialect + // + // Target can be either MLIR dialect, LLVM IR or other downstream target + // (object file, assembly, etc.) + // + // If the target is LLVM IR or other downstream target, the pipeline will + // proceed into LLVM dialect. + // + // Pipeline configuration describe named pipelines that are used in the + // scheduled pipeline. + // + pipeline_t setup_pipeline( + pipeline_source src, output_type trg, + const vast_args &vargs, + const pipelines_config &config + ); + } // namespace vast::cc + diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index 1d103adff4..72103913ed 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -15,4 +15,113 @@ namespace vast::cc { }}; } + namespace pipeline { + + pipeline_step_ptr empty() { + return pipeline_step_init< pipeline_step >(); + } + + // Generates almost AST like MLIR, without any conversions applied + pipeline_step_ptr high_level() { + return compose( + hl::pipeline::canonicalize + ); + } + + // Simplifies high level MLIR + pipeline_step_ptr reduce_high_level() { + return compose( + hl::pipeline::desugar, + hl::pipeline::simplify + ); + } + + // Generates MLIR with standard types + pipeline_step_ptr standard_types() { + return compose( + hl::pipeline::stdtypes + ); + } + + // Conversion to LLVM dialects + pipeline_step_ptr llvm() { + // TODO: implement + return empty(); + } + + pipeline_step_ptr codegen() { + // TODO: pass further options to augment high level MLIR + return high_level(); + } + + // Defines a sequence of dialects and for each conversion dialect a + // passes to be run. This allows to stop conversion at any point (i.e., + // specify some intermediate taarget dialect) but produce all dependend + // steps before. + using conversion_path = std::vector< + std::pair< target_dialect, std::vector< llvm::function_ref< pipeline_step_ptr() > > > + >; + + conversion_path default_conversion_path = { + { target_dialect::high_level, { reduce_high_level } }, + { target_dialect::std, { standard_types } }, + { target_dialect::llvm, { llvm } } + }; + + gap::generator< pipeline_step_ptr > conversion( + pipeline_source src, + output_type trg, + const vast_args &vargs, + const pipelines_config &config + ) { + // TODO: add support for custom conversion paths + // deduced from source, target and vargs + auto path = default_conversion_path; + + auto target_dialect = [&] () -> enum target_dialect { + if (trg == output_type::emit_mlir) { + return parse_target_dialect(vargs.get_option(opt::emit_mlir).value()); + } + // if we user do not specify target dialect, we convert all the way to llvm + return target_dialect::llvm; + } (); + + for (const auto &[dialect, step_passes] : path) { + for (auto &step : step_passes) { + co_yield step(); + } + + if (target_dialect == dialect) { + break; + } + } + } + + } // namespace pipeline + + std::unique_ptr< pipeline_t > setup_pipeline( + pipeline_source src, + output_type trg, + mcontext_t &mctx, + const vast_args &vargs, + const pipelines_config &config + ) { + auto passes = std::make_unique< pipeline_t >(&mctx); + + // generate high level MLIR in case of AST input + if (pipeline_source::ast == src) { + *passes << pipeline::codegen(); + } + + // apply desired conversion to target dialect, if target is llvm or + // binary/assembly, we perform entire conversion to llvm dialect vargs + // can specify how we want to convert to llvm dialect and allows to turn + // off optional pipelines + for (auto &&step : pipeline::conversion(src, trg, vargs, config)) { + *passes << std::move(step); + } + + return passes; + } + } // namespace vast::cc From 97d629963ef05631f21460b761b18fc542eb7fcf Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Thu, 7 Dec 2023 16:39:39 +0100 Subject: [PATCH 16/37] treewide: Integrate default pipeline. --- include/vast/Frontend/Pipelines.hpp | 3 +- include/vast/Target/LLVMIR/Convert.hpp | 9 ----- lib/vast/Dialect/HighLevel/Passes.cpp | 16 ++++++++ lib/vast/Frontend/Consumer.cpp | 54 ++++++++++---------------- lib/vast/Frontend/Pipelines.cpp | 9 +++++ lib/vast/Target/LLVMIR/Convert.cpp | 26 ------------- 6 files changed, 48 insertions(+), 69 deletions(-) diff --git a/include/vast/Frontend/Pipelines.hpp b/include/vast/Frontend/Pipelines.hpp index 9fe0c2f4cb..9c4fc14e27 100644 --- a/include/vast/Frontend/Pipelines.hpp +++ b/include/vast/Frontend/Pipelines.hpp @@ -36,8 +36,9 @@ namespace vast::cc { // Pipeline configuration describe named pipelines that are used in the // scheduled pipeline. // - pipeline_t setup_pipeline( + std::unique_ptr< pipeline_t > setup_pipeline( pipeline_source src, output_type trg, + mcontext_t &mctx, const vast_args &vargs, const pipelines_config &config ); diff --git a/include/vast/Target/LLVMIR/Convert.hpp b/include/vast/Target/LLVMIR/Convert.hpp index 4e250cc921..08cef7ffc1 100644 --- a/include/vast/Target/LLVMIR/Convert.hpp +++ b/include/vast/Target/LLVMIR/Convert.hpp @@ -45,15 +45,6 @@ namespace vast::target::llvmir vast_module mlir_module, llvm::LLVMContext &llvm_ctx ); - // Run all passes needed to go from a product of vast frontend (module in `hl` dialect) - // to a module in lowest representation (mostly LLVM dialect right now). - void lower_hl_module(mlir::Operation *op, pipeline p); - - static inline void lower_hl_module(mlir::Operation *op) - { - return lower_hl_module(op, default_pipeline()); - } - void register_vast_to_llvm_ir(mlir::DialectRegistry ®istry); void register_vast_to_llvm_ir(mcontext_t &mctx); diff --git a/lib/vast/Dialect/HighLevel/Passes.cpp b/lib/vast/Dialect/HighLevel/Passes.cpp index 99f3613b16..cfba2f6378 100644 --- a/lib/vast/Dialect/HighLevel/Passes.cpp +++ b/lib/vast/Dialect/HighLevel/Passes.cpp @@ -5,6 +5,8 @@ VAST_RELAX_WARNINGS #include #include + +#include VAST_UNRELAX_WARNINGS #include "vast/Dialect/HighLevel/Passes.hpp" @@ -59,4 +61,18 @@ namespace vast::hl::pipeline { return compose(lower_types_to_std).depends_on(desugar); } + // + // llvm emition passes + // + static pipeline_step_ptr llvm_debug_scope() { + // This is necessary to have line tables emitted and basic debugger + // working. In the future we will add proper debug information emission + // directly from our frontend. + return pass(mlir::LLVM::createDIScopeForLLVMFuncOpPass); + } + + pipeline_step_ptr to_llvm() { + return compose(llvm_debug_scope).depends_on(stdtypes); + } + } // namespace vast::hl::pipeline diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index e5a6c4e013..fbdffd4f70 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -20,7 +20,9 @@ VAST_UNRELAX_WARNINGS #include "vast/Util/Common.hpp" +#include "vast/Frontend/Pipelines.hpp" #include "vast/Frontend/Targets.hpp" + #include "vast/Target/LLVMIR/Convert.hpp" namespace vast::cc { @@ -179,8 +181,8 @@ namespace vast::cc { ) { llvm::LLVMContext llvm_context; llvmir::register_vast_to_llvm_ir(*mctx); - auto pipeline = parse_pipeline(vargs.get_options_list(opt::opt_pipeline)); - llvmir::lower_hl_module(mlir_module.get(), pipeline); + // auto pipeline = parse_pipeline(vargs.get_options_list(opt::opt_pipeline)); + // llvmir::lower_hl_module(mlir_module.get(), pipeline); auto mod = llvmir::translate(mlir_module.get(), llvm_context); auto dl = cgctx->actx.getTargetInfo().getDataLayoutString(); @@ -197,24 +199,6 @@ namespace vast::cc { return; } - auto setup_pipeline_and_execute = [&] { - auto pipeline = parse_pipeline(vargs.get_options_list(opt::opt_pipeline)); - switch (target) { - case target_dialect::high_level: - break; - case target_dialect::llvm: { - // TODO: These should probably be moved outside of `target::llvmir`. - llvmir::register_vast_to_llvm_ir(*mctx); - llvmir::lower_hl_module(mod.get(), pipeline); - break; - } - // case target_dialect::cir: { - // } - default: - VAST_UNREACHABLE("Cannot emit {0}, missing support", to_string(target)); - } - }; - // Handle source manager properly given that lifetime analysis // might emit warnings and remarks. auto &src_mgr = cgctx->actx.getSourceManager(); @@ -227,20 +211,24 @@ namespace vast::cc { llvm::SourceMgr mlir_src_mgr; mlir_src_mgr.AddNewSourceBuffer(std::move(file_buff), llvm::SMLoc()); - if (vargs.has_option(opt::vast_verify_diags)) { - mlir::SourceMgrDiagnosticVerifierHandler src_mgr_handler(mlir_src_mgr, mctx); - mctx->printOpOnDiagnostic(false); - setup_pipeline_and_execute(); + bool verify_diagnostics = vargs.has_option(opt::vast_verify_diags); - // Verify the diagnostic handler to make sure that each of the - // diagnostics matched. - if (src_mgr_handler.verify().failed()) { - llvm::sys::RunInterruptHandlers(); - VAST_UNREACHABLE("failed mlir codegen"); - } - } else { - mlir::SourceMgrDiagnosticHandler src_mgr_handler(mlir_src_mgr, mctx); - setup_pipeline_and_execute(); + mlir::SourceMgrDiagnosticVerifierHandler src_mgr_handler(mlir_src_mgr, mctx); + mctx->printOpOnDiagnostic(false); + + auto pipeline = setup_pipeline( + pipeline_source::ast, output_type::emit_mlir, *mctx, vargs, default_pipelines_config() + ); + + if (mlir::failed(pipeline->run(mod.get()))) { + VAST_UNREACHABLE("MLIR pass manager failed when running vast passes"); + } + + // Verify the diagnostic handler to make sure that each of the + // diagnostics matched. + if (verify_diagnostics && src_mgr_handler.verify().failed()) { + llvm::sys::RunInterruptHandlers(); + VAST_UNREACHABLE("failed mlir codegen"); } // Emit remaining defaulted C++ methods diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index 72103913ed..a8da0c911f 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -108,6 +108,15 @@ namespace vast::cc { ) { auto passes = std::make_unique< pipeline_t >(&mctx); + passes->enableIRPrinting( + [](auto *, auto *) { return false; }, // before + [](auto *, auto *) { return true; }, // after + false, // module scope + false, // after change + true, // after failure + llvm::errs() + ); + // generate high level MLIR in case of AST input if (pipeline_source::ast == src) { *passes << pipeline::codegen(); diff --git a/lib/vast/Target/LLVMIR/Convert.cpp b/lib/vast/Target/LLVMIR/Convert.cpp index 5eef4b3e33..56aa214783 100644 --- a/lib/vast/Target/LLVMIR/Convert.cpp +++ b/lib/vast/Target/LLVMIR/Convert.cpp @@ -118,32 +118,6 @@ namespace vast::target::llvmir return mlir::translateModuleToLLVMIR(mlir_module, llvm_ctx); } - void lower_hl_module(mlir::Operation *op, pipeline p) - { - auto mctx = op->getContext(); - mlir::PassManager pm(mctx); - populate_pm(pm, p); - - // This is necessary to have line tables emitted and basic - // debugger working. In the future we will add proper debug information - // emission directly from our frontend. - pm.addNestedPass( - mlir::LLVM::createDIScopeForLLVMFuncOpPass() - ); - - pm.enableIRPrinting([](auto *, auto *) { return false; }, // before - [](auto *, auto *) { return true; }, //after - false, // module scope - false, // after change - true, // after failure - llvm::errs()); - - - auto run_result = pm.run(op); - - VAST_CHECK(mlir::succeeded(run_result), "Some pass in prepare_module() failed"); - } - void register_vast_to_llvm_ir(mlir::DialectRegistry ®istry) { registry.insert< hl::HighLevelDialect >(); From 8868f884194ac4736a2547ed8e9226c803fef50b Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 11 Dec 2023 13:52:23 +0100 Subject: [PATCH 17/37] conv: Setup conversion pipelines. --- include/vast/Conversion/Passes.hpp | 14 +++++++ lib/vast/Conversion/ABI/CMakeLists.txt | 1 + lib/vast/Conversion/ABI/Passes.cpp | 27 +++++++++++++ lib/vast/Conversion/Common/CMakeLists.txt | 1 + lib/vast/Conversion/Common/Passes.cpp | 19 +++++++++ lib/vast/Conversion/Core/CMakeLists.txt | 1 + lib/vast/Conversion/Core/Passes.cpp | 33 +++++++++++++++ lib/vast/Conversion/FromHL/CMakeLists.txt | 3 +- lib/vast/Conversion/FromHL/Passes.cpp | 49 +++++++++++++++++++++++ lib/vast/Dialect/HighLevel/Passes.cpp | 16 -------- 10 files changed, 147 insertions(+), 17 deletions(-) create mode 100644 lib/vast/Conversion/ABI/Passes.cpp create mode 100644 lib/vast/Conversion/Common/Passes.cpp create mode 100644 lib/vast/Conversion/Core/Passes.cpp create mode 100644 lib/vast/Conversion/FromHL/Passes.cpp diff --git a/include/vast/Conversion/Passes.hpp b/include/vast/Conversion/Passes.hpp index 759ff19dfd..10764e0bc9 100644 --- a/include/vast/Conversion/Passes.hpp +++ b/include/vast/Conversion/Passes.hpp @@ -20,6 +20,8 @@ VAST_UNRELAX_WARNINGS #include #include +#include + #include namespace vast @@ -81,4 +83,16 @@ namespace vast pm.addPass(createCoreToLLVMPass()); } + namespace conv::pipeline + { + pipeline_step_ptr abi(); + pipeline_step_ptr irs_to_llvm(); + pipeline_step_ptr core_to_llvm(); + + pipeline_step_ptr to_ll(); + + pipeline_step_ptr to_llvm(); + + } // namespace conv::pipeline + } // namespace vast diff --git a/lib/vast/Conversion/ABI/CMakeLists.txt b/lib/vast/Conversion/ABI/CMakeLists.txt index 79cdc6c4b5..9a1eda5b76 100644 --- a/lib/vast/Conversion/ABI/CMakeLists.txt +++ b/lib/vast/Conversion/ABI/CMakeLists.txt @@ -3,4 +3,5 @@ add_vast_conversion_library(ABIConversionPasses EmitABI.cpp LowerABI.cpp + Passes.cpp ) diff --git a/lib/vast/Conversion/ABI/Passes.cpp b/lib/vast/Conversion/ABI/Passes.cpp new file mode 100644 index 0000000000..d152f08322 --- /dev/null +++ b/lib/vast/Conversion/ABI/Passes.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#include "vast/Util/Warnings.hpp" + +VAST_RELAX_WARNINGS +#include +#include +VAST_UNRELAX_WARNINGS + +#include "vast/Conversion/Passes.hpp" + +namespace vast::conv::pipeline { + + static pipeline_step_ptr emit_abi() { + // TODO add dependencies + return pass(createEmitABIPass); + } + + static pipeline_step_ptr lower_abi() { + return pass(createLowerABIPass).depends_on(emit_abi); + } + + pipeline_step_ptr abi() { + return lower_abi(); + } + +} // namespace vast::conv::pipeline diff --git a/lib/vast/Conversion/Common/CMakeLists.txt b/lib/vast/Conversion/Common/CMakeLists.txt index a194df0298..be8dc691f0 100644 --- a/lib/vast/Conversion/Common/CMakeLists.txt +++ b/lib/vast/Conversion/Common/CMakeLists.txt @@ -2,4 +2,5 @@ add_vast_conversion_library(CommonConversionPasses IRsToLLVM.cpp + Passes.cpp ) diff --git a/lib/vast/Conversion/Common/Passes.cpp b/lib/vast/Conversion/Common/Passes.cpp new file mode 100644 index 0000000000..05e3ffe80c --- /dev/null +++ b/lib/vast/Conversion/Common/Passes.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#include "vast/Util/Warnings.hpp" + +VAST_RELAX_WARNINGS +#include +#include +VAST_UNRELAX_WARNINGS + +#include "vast/Conversion/Passes.hpp" + +namespace vast::conv::pipeline { + + pipeline_step_ptr irs_to_llvm() { + // TODO add dependencies + return pass(createIRsToLLVMPass).depends_on(core_to_llvm); + } + +} // namespace vast::conv::pipeline diff --git a/lib/vast/Conversion/Core/CMakeLists.txt b/lib/vast/Conversion/Core/CMakeLists.txt index d8a9563112..0f1f706fbd 100644 --- a/lib/vast/Conversion/Core/CMakeLists.txt +++ b/lib/vast/Conversion/Core/CMakeLists.txt @@ -1,5 +1,6 @@ # Copyright (c) 2022-present, Trail of Bits, Inc. add_vast_conversion_library(CoreConversionPasses + Passes.cpp ToLLVM.cpp ) diff --git a/lib/vast/Conversion/Core/Passes.cpp b/lib/vast/Conversion/Core/Passes.cpp new file mode 100644 index 0000000000..550eb67a4b --- /dev/null +++ b/lib/vast/Conversion/Core/Passes.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#include "vast/Util/Warnings.hpp" + +VAST_RELAX_WARNINGS +#include +#include + +#include +VAST_UNRELAX_WARNINGS + +#include "vast/Conversion/Passes.hpp" + +namespace vast::conv::pipeline { + + static pipeline_step_ptr llvm_debug_scope() { + // This is necessary to have line tables emitted and basic debugger + // working. In the future we will add proper debug information emission + // directly from our frontend. + return pass(mlir::LLVM::createDIScopeForLLVMFuncOpPass) + .depends_on(core_to_llvm); + } + + pipeline_step_ptr core_to_llvm() { + // TODO add dependencies + return pass(createCoreToLLVMPass); + } + + pipeline_step_ptr to_llvm() { + return compose(irs_to_llvm, core_to_llvm, llvm_debug_scope); + } + +} // namespace vast::conv::pipeline diff --git a/lib/vast/Conversion/FromHL/CMakeLists.txt b/lib/vast/Conversion/FromHL/CMakeLists.txt index f7b8f3f7a0..0aa35239c2 100644 --- a/lib/vast/Conversion/FromHL/CMakeLists.txt +++ b/lib/vast/Conversion/FromHL/CMakeLists.txt @@ -1,8 +1,9 @@ # Copyright (c) 2022-present, Trail of Bits, Inc. add_vast_conversion_library(HighLevelConversionPasses - ToLLCF.cpp EmitLazyRegions.cpp + Passes.cpp + ToLLCF.cpp ToLLGEPs.cpp ToLLVars.cpp ToLLFunc.cpp diff --git a/lib/vast/Conversion/FromHL/Passes.cpp b/lib/vast/Conversion/FromHL/Passes.cpp new file mode 100644 index 0000000000..085b789ec5 --- /dev/null +++ b/lib/vast/Conversion/FromHL/Passes.cpp @@ -0,0 +1,49 @@ +// Copyright (c) 2023-present, Trail of Bits, Inc. + +#include "vast/Util/Warnings.hpp" + +VAST_RELAX_WARNINGS +#include +#include +VAST_UNRELAX_WARNINGS + +#include "vast/Conversion/Passes.hpp" + +namespace vast::conv::pipeline { + + pipeline_step_ptr hl_to_ll_cf() { + // TODO add dependencies + return pass(createHLToLLCFPass); + } + + pipeline_step_ptr hl_to_ll_geps() { + // TODO add dependencies + 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); + } + + pipeline_step_ptr hl_to_ll_func() { + // TODO add dependencies + return pass(createHLToLLFuncPass); + } + + pipeline_step_ptr to_ll() { + return compose( + hl_to_ll_func, + hl_to_ll_vars, + hl_to_ll_cf, + lazy_regions, + hl_to_ll_geps + ); + } + +} // namespace vast::conv::pipeline diff --git a/lib/vast/Dialect/HighLevel/Passes.cpp b/lib/vast/Dialect/HighLevel/Passes.cpp index cfba2f6378..99f3613b16 100644 --- a/lib/vast/Dialect/HighLevel/Passes.cpp +++ b/lib/vast/Dialect/HighLevel/Passes.cpp @@ -5,8 +5,6 @@ VAST_RELAX_WARNINGS #include #include - -#include VAST_UNRELAX_WARNINGS #include "vast/Dialect/HighLevel/Passes.hpp" @@ -61,18 +59,4 @@ namespace vast::hl::pipeline { return compose(lower_types_to_std).depends_on(desugar); } - // - // llvm emition passes - // - static pipeline_step_ptr llvm_debug_scope() { - // This is necessary to have line tables emitted and basic debugger - // working. In the future we will add proper debug information emission - // directly from our frontend. - return pass(mlir::LLVM::createDIScopeForLLVMFuncOpPass); - } - - pipeline_step_ptr to_llvm() { - return compose(llvm_debug_scope).depends_on(stdtypes); - } - } // namespace vast::hl::pipeline From 7a8f378ca11bc5c1d58fd639a0033f85efad1498 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 11 Dec 2023 14:37:12 +0100 Subject: [PATCH 18/37] cc: Fix pipeline steps lifetimes. --- include/vast/Util/Pipeline.hpp | 2 +- lib/vast/Frontend/Pipelines.cpp | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/include/vast/Util/Pipeline.hpp b/include/vast/Util/Pipeline.hpp index 4e795490d0..c12f993c71 100644 --- a/include/vast/Util/Pipeline.hpp +++ b/include/vast/Util/Pipeline.hpp @@ -56,7 +56,7 @@ namespace vast { }; - using pipeline_step_builder = llvm::function_ref< pipeline_step_ptr(void) >; + using pipeline_step_builder = std::function< pipeline_step_ptr(void) >; // // initilizer wrapper to setup dependencies after make is called diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index a8da0c911f..ed13c311ca 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -3,6 +3,7 @@ #include "vast/Frontend/Pipelines.hpp" #include "vast/Dialect/HighLevel/Passes.hpp" +#include "vast/Conversion/Passes.hpp" namespace vast::cc { @@ -17,15 +18,9 @@ namespace vast::cc { namespace pipeline { - pipeline_step_ptr empty() { - return pipeline_step_init< pipeline_step >(); - } - // Generates almost AST like MLIR, without any conversions applied pipeline_step_ptr high_level() { - return compose( - hl::pipeline::canonicalize - ); + return hl::pipeline::canonicalize(); } // Simplifies high level MLIR @@ -38,15 +33,12 @@ namespace vast::cc { // Generates MLIR with standard types pipeline_step_ptr standard_types() { - return compose( - hl::pipeline::stdtypes - ); + return hl::pipeline::stdtypes(); } // Conversion to LLVM dialects pipeline_step_ptr llvm() { - // TODO: implement - return empty(); + return conv::pipeline::to_llvm(); } pipeline_step_ptr codegen() { @@ -122,10 +114,10 @@ namespace vast::cc { *passes << pipeline::codegen(); } - // apply desired conversion to target dialect, if target is llvm or - // binary/assembly, we perform entire conversion to llvm dialect vargs + // Apply desired conversion to target dialect, if target is llvm or + // binary/assembly. We perform entire conversion to llvm dialect. Vargs // can specify how we want to convert to llvm dialect and allows to turn - // off optional pipelines + // off optional pipelines. for (auto &&step : pipeline::conversion(src, trg, vargs, config)) { *passes << std::move(step); } From 46dfd370d86deedc987b28c81e21fd721a786c1e Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 11 Dec 2023 19:09:27 +0100 Subject: [PATCH 19/37] cc: Do not run simplification when not requested. --- include/vast/Frontend/Options.hpp | 3 ++- lib/vast/Dialect/HighLevel/Passes.cpp | 10 +++------- lib/vast/Frontend/Pipelines.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/vast/Frontend/Options.hpp b/include/vast/Frontend/Options.hpp index 1ca1ac3f24..2ac0118f89 100644 --- a/include/vast/Frontend/Options.hpp +++ b/include/vast/Frontend/Options.hpp @@ -73,10 +73,11 @@ namespace vast::cc constexpr string_ref emit_mlir = "emit-mlir"; + constexpr string_ref simplify = "simplify"; + constexpr string_ref show_locs = "show-locs"; constexpr string_ref locs_as_meta_ids = "locs-as-meta-ids"; - constexpr string_ref opt_pipeline = "pipeline"; constexpr string_ref disable_vast_verifier = "disable-vast-verifier"; diff --git a/lib/vast/Dialect/HighLevel/Passes.cpp b/lib/vast/Dialect/HighLevel/Passes.cpp index 99f3613b16..0cd3f85853 100644 --- a/lib/vast/Dialect/HighLevel/Passes.cpp +++ b/lib/vast/Dialect/HighLevel/Passes.cpp @@ -21,7 +21,7 @@ namespace vast::hl::pipeline { // TODO: add more passes here (remove reduntant skips etc.) pipeline_step_ptr canonicalize() { - return compose(splice_trailing_scopes); + return splice_trailing_scopes(); } // @@ -34,7 +34,7 @@ namespace vast::hl::pipeline { // TODO: add more passes here (remove elaborations, decayed types, lvalue types etc.) pipeline_step_ptr desugar() { - return compose(lower_types); + return lower_types(); } // @@ -51,12 +51,8 @@ namespace vast::hl::pipeline { // // stdtypes passes // - static pipeline_step_ptr lower_types_to_std() { - return pass(hl::createHLLowerTypesPass); - } - pipeline_step_ptr stdtypes() { - return compose(lower_types_to_std).depends_on(desugar); + return pass(hl::createHLLowerTypesPass).depends_on(desugar); } } // namespace vast::hl::pipeline diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index ed13c311ca..4c8e6f0bb0 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -78,6 +78,12 @@ namespace vast::cc { return target_dialect::llvm; } (); + bool simplify = vargs.has_option(opt::simplify); + + if (target_dialect == target_dialect::high_level && !simplify) { + co_return; + } + for (const auto &[dialect, step_passes] : path) { for (auto &step : step_passes) { co_yield step(); From 1b670686b9454ff2dae5c9ecdc3f992f617e0492 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 11 Dec 2023 19:57:44 +0100 Subject: [PATCH 20/37] cc: Remove obsolete high level pass. --- include/vast/CodeGen/Passes.hpp | 15 --------------- include/vast/Frontend/Consumer.hpp | 2 +- lib/vast/CodeGen/CMakeLists.txt | 1 - lib/vast/CodeGen/Passes.cpp | 27 --------------------------- lib/vast/Frontend/Consumer.cpp | 23 ++++++++--------------- 5 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 include/vast/CodeGen/Passes.hpp delete mode 100644 lib/vast/CodeGen/Passes.cpp diff --git a/include/vast/CodeGen/Passes.hpp b/include/vast/CodeGen/Passes.hpp deleted file mode 100644 index d98113c557..0000000000 --- a/include/vast/CodeGen/Passes.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2023-present, Trail of Bits, Inc. - -#pragma once - -#include "vast/Util/Warnings.hpp" - -#include "vast/Util/Common.hpp" - -namespace vast::cg { - - logical_result emit_high_level_pass( - vast_module mod, mcontext_t *mctx, acontext_t *actx, bool enable_verifier - ); - -} // namespace vast::cg diff --git a/include/vast/Frontend/Consumer.hpp b/include/vast/Frontend/Consumer.hpp index 54e9390edd..173642edf9 100644 --- a/include/vast/Frontend/Consumer.hpp +++ b/include/vast/Frontend/Consumer.hpp @@ -61,7 +61,7 @@ namespace vast::cc { protected: - void compile_via_vast(vast_module mod, mcontext_t *mctx); + void execute_pipeline(vast_module mod, mcontext_t *mctx); virtual void anchor() {} diff --git a/lib/vast/CodeGen/CMakeLists.txt b/lib/vast/CodeGen/CMakeLists.txt index a707136b9e..b8cfa332c5 100644 --- a/lib/vast/CodeGen/CMakeLists.txt +++ b/lib/vast/CodeGen/CMakeLists.txt @@ -11,7 +11,6 @@ add_vast_library(CodeGen CodeGenFunction.cpp DataLayout.cpp Mangler.cpp - Passes.cpp LINK_LIBS PUBLIC ${CLANG_LIBS} diff --git a/lib/vast/CodeGen/Passes.cpp b/lib/vast/CodeGen/Passes.cpp deleted file mode 100644 index 5bb8dec3cd..0000000000 --- a/lib/vast/CodeGen/Passes.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2023-present, Trail of Bits, Inc. - -#include "vast/Util/Warnings.hpp" - -VAST_RELAX_WARNINGS -#include -#include -VAST_UNRELAX_WARNINGS - -#include "vast/Dialect/HighLevel/Passes.hpp" -#include "vast/CodeGen/Passes.hpp" - -namespace vast::cg { - - logical_result emit_high_level_pass( - vast_module mod, mcontext_t *mctx, acontext_t */* actx */, bool enable_verifier - ) { - mlir::PassManager mgr(mctx); - - // TODO: setup vast intermediate codegen passes - mgr.addPass(hl::createSpliceTrailingScopes()); - - mgr.enableVerifier(enable_verifier); - return mgr.run(mod); - } - -} // namespace vast::cg diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index fbdffd4f70..5c38cb009c 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -14,7 +14,6 @@ VAST_RELAX_WARNINGS #include VAST_UNRELAX_WARNINGS -#include "vast/CodeGen/Passes.hpp" #include "vast/CodeGen/CodeGenContext.hpp" #include "vast/CodeGen/CodeGenDriver.hpp" @@ -91,8 +90,6 @@ namespace vast::cc { VAST_UNREACHABLE("codegen: module verification error before running vast passes"); } } - - compile_via_vast(cgctx->mod.get(), mctx.get()); } void vast_consumer::HandleTagDeclDefinition(clang::TagDecl *decl) { @@ -216,13 +213,7 @@ namespace vast::cc { mlir::SourceMgrDiagnosticVerifierHandler src_mgr_handler(mlir_src_mgr, mctx); mctx->printOpOnDiagnostic(false); - auto pipeline = setup_pipeline( - pipeline_source::ast, output_type::emit_mlir, *mctx, vargs, default_pipelines_config() - ); - - if (mlir::failed(pipeline->run(mod.get()))) { - VAST_UNREACHABLE("MLIR pass manager failed when running vast passes"); - } + execute_pipeline(mod.get(), mctx); // Verify the diagnostic handler to make sure that each of the // diagnostics matched. @@ -243,11 +234,13 @@ namespace vast::cc { mod->print(*output_stream, flags); } - void vast_consumer::compile_via_vast(vast_module mod, mcontext_t *mctx) { - const bool enable_vast_verifier = !vargs.has_option(opt::disable_vast_verifier); - auto pass = cg::emit_high_level_pass(mod, mctx, &cgctx->actx, enable_vast_verifier); - if (pass.failed()) { - VAST_UNREACHABLE("codegen: MLIR pass manager fails when running vast passes"); + void vast_consumer::execute_pipeline(vast_module mod, mcontext_t *mctx) { + auto pipeline = setup_pipeline( + pipeline_source::ast, output_type::emit_mlir, *mctx, vargs, default_pipelines_config() + ); + + if (mlir::failed(pipeline->run(mod))) { + VAST_UNREACHABLE("MLIR pass manager failed when running vast passes"); } } From a20f2e6810e0830414e84c583f1407a55b7080af Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Mon, 11 Dec 2023 20:15:36 +0100 Subject: [PATCH 21/37] cc: Remove obsolete abi pipeline interface. --- include/vast/Target/LLVMIR/Convert.hpp | 13 --------- lib/vast/Frontend/Consumer.cpp | 38 +------------------------- lib/vast/Target/LLVMIR/Convert.cpp | 27 ------------------ 3 files changed, 1 insertion(+), 77 deletions(-) diff --git a/include/vast/Target/LLVMIR/Convert.hpp b/include/vast/Target/LLVMIR/Convert.hpp index 08cef7ffc1..b1e4cd6384 100644 --- a/include/vast/Target/LLVMIR/Convert.hpp +++ b/include/vast/Target/LLVMIR/Convert.hpp @@ -25,19 +25,6 @@ namespace mlir namespace vast::target::llvmir { - // TODO(target): Do we want to fully replace this with composite passes, - // or instead should live at the same time? - enum class pipeline : uint32_t - { - baseline = 0, - with_abi = 1 - }; - - static inline pipeline default_pipeline() - { - return pipeline::baseline; - } - // Lower module into `llvm::Module` - it is expected that `mlir_module` is already // lowered as much as possible by vast (for example by calling the `prepare_module` // function). diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index 5c38cb009c..9d824000c9 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -26,14 +26,6 @@ VAST_UNRELAX_WARNINGS namespace vast::cc { - namespace llvmir = target::llvmir; - - using pipeline = llvmir::pipeline; - - [[nodiscard]] pipeline parse_pipeline(const std::optional< vast_args::option_list > &list); - - [[nodiscard]] pipeline parse_pipeline(string_ref from); - [[nodiscard]] target_dialect parse_target_dialect(string_ref from); [[nodiscard]] std::string to_string(target_dialect target); @@ -177,11 +169,8 @@ namespace vast::cc { backend backend_action, owning_module_ref mlir_module, mcontext_t *mctx ) { llvm::LLVMContext llvm_context; - llvmir::register_vast_to_llvm_ir(*mctx); - // auto pipeline = parse_pipeline(vargs.get_options_list(opt::opt_pipeline)); - // llvmir::lower_hl_module(mlir_module.get(), pipeline); - auto mod = llvmir::translate(mlir_module.get(), llvm_context); + auto mod = target::llvmir::translate(mlir_module.get(), llvm_context); auto dl = cgctx->actx.getTargetInfo().getDataLayoutString(); clang::EmitBackendOutput( opts.diags, opts.headers, opts.codegen, opts.target, opts.lang, dl, mod.get(), @@ -259,29 +248,4 @@ namespace vast::cc { VAST_UNIMPLEMENTED_MSG("VAST does not yet support the given source language"); } - pipeline parse_pipeline(const std::optional< vast_args::option_list > &list) { - if (!list) { - return llvmir::default_pipeline(); - } - - if (list->size() != 1) { - VAST_UNREACHABLE("Cannot use more than one pipeline!"); - } - - return parse_pipeline(list->front()); - } - - pipeline parse_pipeline(string_ref from) { - auto trg = from.lower(); - if (trg == "with-abi") { - return pipeline::with_abi; - } - if (trg == "baseline") { - return pipeline::baseline; - } - - VAST_UNREACHABLE("Unknown option of pipeline to use: {0}", trg); - } - - } // namespace vast::cc diff --git a/lib/vast/Target/LLVMIR/Convert.cpp b/lib/vast/Target/LLVMIR/Convert.cpp index 56aa214783..db4bf0532b 100644 --- a/lib/vast/Target/LLVMIR/Convert.cpp +++ b/lib/vast/Target/LLVMIR/Convert.cpp @@ -30,33 +30,6 @@ VAST_UNRELAX_WARNINGS namespace vast::target::llvmir { - namespace - { - // TODO(target): Unify with tower and opt. - void populate_pm(mlir::PassManager &pm, pipeline p) - { - switch (p) - { - case pipeline::baseline: - { - hl::build_simplify_hl_pipeline(pm); - build_to_ll_pipeline(pm); - build_to_llvm_pipeline(pm); - return; - } - case pipeline::with_abi: - { - hl::build_simplify_hl_pipeline(pm); - build_abi_pipeline(pm); - build_to_ll_pipeline(pm); - build_to_llvm_pipeline(pm); - return; - } - } - - } - } // namespace - class ToLLVMIR : public mlir::LLVMTranslationDialectInterface { public: From 03fb74a53ddc2fb5803aae9c346da4bb2ba9b9c9 Mon Sep 17 00:00:00 2001 From: Henrich Lauko Date: Wed, 13 Dec 2023 13:50:01 +0100 Subject: [PATCH 22/37] cc: Add vast-debug option. --- include/vast/Frontend/Options.hpp | 3 ++- lib/vast/Frontend/Consumer.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/vast/Frontend/Options.hpp b/include/vast/Frontend/Options.hpp index 2ac0118f89..8331dcb866 100644 --- a/include/vast/Frontend/Options.hpp +++ b/include/vast/Frontend/Options.hpp @@ -70,9 +70,10 @@ namespace vast::cc constexpr string_ref emit_llvm = "emit-llvm"; constexpr string_ref emit_obj = "emit-obj"; constexpr string_ref emit_asm = "emit-asm"; - constexpr string_ref emit_mlir = "emit-mlir"; + constexpr string_ref debug = "debug"; + constexpr string_ref simplify = "simplify"; constexpr string_ref show_locs = "show-locs"; diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index 9d824000c9..ea69b278c9 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -200,7 +200,12 @@ namespace vast::cc { bool verify_diagnostics = vargs.has_option(opt::vast_verify_diags); mlir::SourceMgrDiagnosticVerifierHandler src_mgr_handler(mlir_src_mgr, mctx); - mctx->printOpOnDiagnostic(false); + + if (vargs.has_option(opt::debug)) { + mctx->printOpOnDiagnostic(true); + mctx->printStackTraceOnDiagnostic(true); + llvm::DebugFlag = true; + } execute_pipeline(mod.get(), mctx); From e97cff4ecc37c2dea99b79ab1f80c2a5126e973a Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 23 Jan 2024 13:05:40 +0100 Subject: [PATCH 23/37] treewide: Fix unreachable to more appropriate macros. --- include/vast/CodeGen/CodeGen.hpp | 2 +- include/vast/CodeGen/CodeGenContext.hpp | 2 +- include/vast/CodeGen/CodeGenDeclVisitor.hpp | 10 +++++----- include/vast/CodeGen/CodeGenStmtVisitor.hpp | 2 +- include/vast/CodeGen/UnreachableVisitor.hpp | 10 +++++----- include/vast/Conversion/TypeConverters/HLToStd.hpp | 2 +- include/vast/Dialect/HighLevel/HighLevelTypes.hpp | 2 +- include/vast/Tower/Tower.hpp | 2 +- include/vast/Util/TypeList.hpp | 2 +- include/vast/repl/command.hpp | 10 +++++----- lib/vast/CodeGen/CodeGenDriver.cpp | 4 ++-- lib/vast/CodeGen/CodeGenStmtVisitor.cpp | 2 +- lib/vast/CodeGen/CodeGenTypeVisitor.cpp | 4 ++-- lib/vast/Dialect/Core/Linkage.cpp | 6 ++---- lib/vast/Dialect/HighLevel/HighLevelTypes.cpp | 6 +++--- lib/vast/Dialect/HighLevel/HighLevelVar.cpp | 4 ++-- lib/vast/Frontend/Action.cpp | 2 +- lib/vast/Frontend/Consumer.cpp | 9 ++++----- lib/vast/Frontend/Targets.cpp | 2 +- tools/vast-front/compiler_invocation.cpp | 2 +- tools/vast-repl/command.cpp | 2 +- tools/vast-repl/vast-repl.cpp | 2 +- 22 files changed, 43 insertions(+), 46 deletions(-) diff --git a/include/vast/CodeGen/CodeGen.hpp b/include/vast/CodeGen/CodeGen.hpp index 4fef413bc0..a38d105f4a 100644 --- a/include/vast/CodeGen/CodeGen.hpp +++ b/include/vast/CodeGen/CodeGen.hpp @@ -450,7 +450,7 @@ namespace vast::cg VAST_UNIMPLEMENTED; } else if (body) { if (mlir::failed(build_function_body(body))) { - VAST_UNREACHABLE("failed function body codegen"); + VAST_FATAL("failed function body codegen"); } } else { VAST_UNIMPLEMENTED_MSG("no definition for emitted function"); diff --git a/include/vast/CodeGen/CodeGenContext.hpp b/include/vast/CodeGen/CodeGenContext.hpp index 2e91ff53a7..3c53ff352e 100644 --- a/include/vast/CodeGen/CodeGenContext.hpp +++ b/include/vast/CodeGen/CodeGenContext.hpp @@ -215,7 +215,7 @@ namespace vast::cg if (const auto *d = llvm::dyn_cast< clang::NamedDecl >(dctx)) { name += get_decl_name(d); } else { - VAST_UNREACHABLE("unknown decl context: {0}", dctx->getDeclKindName()); + VAST_FATAL("unknown decl context: {0}", dctx->getDeclKindName()); } name += "::"; diff --git a/include/vast/CodeGen/CodeGenDeclVisitor.hpp b/include/vast/CodeGen/CodeGenDeclVisitor.hpp index f1f8560ffc..431b366bf3 100644 --- a/include/vast/CodeGen/CodeGenDeclVisitor.hpp +++ b/include/vast/CodeGen/CodeGenDeclVisitor.hpp @@ -185,7 +185,7 @@ namespace vast::cg { return fn; } - VAST_UNREACHABLE("NYI"); + VAST_UNIMPLEMENTED; // TODO: clang checks here if this is a llvm::GlobalAlias... how will we // support this? @@ -282,7 +282,7 @@ namespace vast::cg { return fn; } - VAST_UNREACHABLE("codegen of incomplete function"); + VAST_FATAL("codegen of incomplete function"); } vast_function get_addr_of_function( @@ -486,7 +486,7 @@ namespace vast::cg { case clang::SC_PrivateExtern: return hl::StorageClass::sc_private_extern; case clang::SC_Register: return hl::StorageClass::sc_register; } - VAST_UNREACHABLE("unknown storage class"); + VAST_UNIMPLEMENTED_MSG("unknown storage class"); } hl::TSClass VisitThreadStorageClass(const clang::VarDecl *decl) const { @@ -496,7 +496,7 @@ namespace vast::cg { case clang::TSCS_thread_local: return hl::TSClass::tsc_cxx_thread; case clang::TSCS__Thread_local: return hl::TSClass::tsc_c_thread; } - VAST_UNREACHABLE("unknown storage class"); + VAST_UNIMPLEMENTED_MSG("unknown thread storage class"); } operation VisitVarDecl(const clang::VarDecl *decl) { @@ -713,7 +713,7 @@ namespace vast::cg { case clang::AccessSpecifier::AS_none: return hl::AccessSpecifier::as_none; } - VAST_UNREACHABLE("unknown access specifier"); + VAST_UNIMPLEMENTED_MSG("unknown access specifier"); } // diff --git a/include/vast/CodeGen/CodeGenStmtVisitor.hpp b/include/vast/CodeGen/CodeGenStmtVisitor.hpp index 8fe8e88354..e684ef52dc 100644 --- a/include/vast/CodeGen/CodeGenStmtVisitor.hpp +++ b/include/vast/CodeGen/CodeGenStmtVisitor.hpp @@ -747,7 +747,7 @@ namespace vast::cg { return VisitFunctionDeclRefExpr(expr); } - VAST_UNREACHABLE("unknown underlying declaration to be referenced"); + VAST_UNIMPLEMENTED_MSG("unknown underlying declaration to be referenced"); } Operation *VisitPredefinedExpr(const clang::PredefinedExpr *expr) diff --git a/include/vast/CodeGen/UnreachableVisitor.hpp b/include/vast/CodeGen/UnreachableVisitor.hpp index 3088db7fe6..33352daa37 100644 --- a/include/vast/CodeGen/UnreachableVisitor.hpp +++ b/include/vast/CodeGen/UnreachableVisitor.hpp @@ -9,32 +9,32 @@ namespace vast::cg template< typename derived_t > struct unreach_stmt_visitor { operation Visit(const clang::Stmt *stmt) { - VAST_UNREACHABLE("unsupported stmt: {0}", stmt->getStmtClassName()); + VAST_FATAL("unsupported stmt: {0}", stmt->getStmtClassName()); } }; template< typename derived_t > struct unreach_decl_visitor { operation Visit(const clang::Decl *decl) { - VAST_UNREACHABLE("unsupported decl: {0}", decl->getDeclKindName()); + VAST_FATAL("unsupported decl: {0}", decl->getDeclKindName()); } }; template< typename derived_t > struct unreach_type_visitor { mlir_type Visit(clang::QualType type) { - VAST_UNREACHABLE("unsupported type: {0}", type.getAsString()); + VAST_FATAL("unsupported type: {0}", type.getAsString()); } mlir_type Visit(const clang::Type *type) { - VAST_UNREACHABLE("unsupported type: {0}", type->getTypeClassName()); + VAST_FATAL("unsupported type: {0}", type->getTypeClassName()); } }; template< typename derived_t > struct unreach_attr_visitor { mlir_attr Visit(const clang::Attr *attr) { - VAST_UNREACHABLE("unsupported attr: {0}", attr->getSpelling()); + VAST_FATAL("unsupported attr: {0}", attr->getSpelling()); } }; diff --git a/include/vast/Conversion/TypeConverters/HLToStd.hpp b/include/vast/Conversion/TypeConverters/HLToStd.hpp index ae7034ee25..950b5e1e79 100644 --- a/include/vast/Conversion/TypeConverters/HLToStd.hpp +++ b/include/vast/Conversion/TypeConverters/HLToStd.hpp @@ -227,7 +227,7 @@ namespace vast::conv::tc { case 128: return mlir::FloatType::getF128(&mctx); default: - VAST_UNREACHABLE("Cannot lower float bitsize {0}", target_bw); + VAST_FATAL("Cannot lower float bitsize {0}", target_bw); } }; } diff --git a/include/vast/Dialect/HighLevel/HighLevelTypes.hpp b/include/vast/Dialect/HighLevel/HighLevelTypes.hpp index 0728e1dfa5..e826e8c2f4 100644 --- a/include/vast/Dialect/HighLevel/HighLevelTypes.hpp +++ b/include/vast/Dialect/HighLevel/HighLevelTypes.hpp @@ -166,7 +166,7 @@ namespace vast::hl .Case< LongDoubleType >([&] (auto t) { return fty::getF80(ctx); }) .Case< Float128Type >([&] (auto t) { return fty::getF128(ctx); }) .Default([] (auto t) { - VAST_UNREACHABLE("unknown float type: {0}", format_type(t)); + VAST_FATAL("unknown float type: {0}", format_type(t)); return mlir_type(); }); } diff --git a/include/vast/Tower/Tower.hpp b/include/vast/Tower/Tower.hpp index 6d12a8d31e..ea822a76d8 100644 --- a/include/vast/Tower/Tower.hpp +++ b/include/vast/Tower/Tower.hpp @@ -46,7 +46,7 @@ namespace vast::tw { auto mod = _modules.back().get(); if (mlir::failed(pm.run(mod))) { - VAST_UNREACHABLE("error: some pass in apply() failed"); + VAST_FATAL("some pass in apply() failed"); } handle.mod.walk(loc_rewriter::remove); diff --git a/include/vast/Util/TypeList.hpp b/include/vast/Util/TypeList.hpp index 0c0206d6c9..cb5b110c63 100644 --- a/include/vast/Util/TypeList.hpp +++ b/include/vast/Util/TypeList.hpp @@ -158,7 +158,7 @@ namespace vast::util { constexpr ret dispatch(mlir_type type, fn &&f) { if constexpr ( list::empty ) { - VAST_UNREACHABLE( "missing type to dispatch" ); + VAST_FATAL( "missing type to dispatch" ); } else { using head = typename list::head; diff --git a/include/vast/repl/command.hpp b/include/vast/repl/command.hpp index 30138c7fb8..d336fe0b45 100644 --- a/include/vast/repl/command.hpp +++ b/include/vast/repl/command.hpp @@ -60,7 +60,7 @@ namespace vast::repl if (token == "ast") return enum_type::ast; if (token == "module") return enum_type::module; if (token == "symbols") return enum_type::symbols; - VAST_UNREACHABLE("uknnown show kind: {0}", token.str()); + VAST_FATAL("uknnown show kind: {0}", token.str()); } enum class meta_action { add, get }; @@ -69,7 +69,7 @@ namespace vast::repl enum_type from_string(string_ref token) requires(std::is_same_v< enum_type, meta_action >) { if (token == "add") return enum_type::add; if (token == "get") return enum_type::get; - VAST_UNREACHABLE("uknnown action kind: {0}", token.str()); + VAST_FATAL("uknnown action kind: {0}", token.str()); } // @@ -112,7 +112,7 @@ namespace vast::repl template< const char *name, typename params_storage > auto get_param(const params_storage ¶ms) { if constexpr (std::tuple_size_v< params_storage > == 0) { - VAST_UNREACHABLE(("unknown param name " + std::string(name)).c_str()); + VAST_FATAL(("unknown param name " + std::string(name)).c_str()); } else { using current = typename std::tuple_element< 0, params_storage >::type; @@ -267,7 +267,7 @@ namespace vast::repl } if constexpr (params_list::empty) { - VAST_UNREACHABLE(("no match for param: " + tokens.front()).str().c_str()); + VAST_FATAL(("no match for param: " + tokens.front()).str().c_str()); } else { using current_param = typename params_list::head; using rest = typename params_list::tail; @@ -296,7 +296,7 @@ namespace vast::repl if constexpr (commands::empty) { // we did not recursivelly match any of known commands - VAST_UNREACHABLE(("no match for command: " + tokens.front()).str().c_str()); + VAST_FATAL(("no match for command: " + tokens.front()).str().c_str()); } else { using current_command = typename commands::head; using rest = typename commands::tail; diff --git a/lib/vast/CodeGen/CodeGenDriver.cpp b/lib/vast/CodeGen/CodeGenDriver.cpp index da77e59b66..077b9764b1 100644 --- a/lib/vast/CodeGen/CodeGenDriver.cpp +++ b/lib/vast/CodeGen/CodeGenDriver.cpp @@ -163,7 +163,7 @@ namespace vast::cg if (const auto *var = llvm::dyn_cast< clang::VarDecl >(decl)) return build_global_var_definition(var, !var->hasDefinition()); - VAST_UNREACHABLE("Invalid argument to buildGlobalDefinition()"); + VAST_FATAL("Invalid argument to buildGlobalDefinition()"); } @@ -312,7 +312,7 @@ namespace vast::cg return true; } - VAST_UNREACHABLE("unsupported value decl"); + VAST_UNIMPLEMENTED_MSG("unsupported value decl"); } void codegen_driver::build_default_methods() { diff --git a/lib/vast/CodeGen/CodeGenStmtVisitor.cpp b/lib/vast/CodeGen/CodeGenStmtVisitor.cpp index 98233f2e7d..a5e32378bc 100644 --- a/lib/vast/CodeGen/CodeGenStmtVisitor.cpp +++ b/lib/vast/CodeGen/CodeGenStmtVisitor.cpp @@ -86,7 +86,7 @@ namespace vast::hl case clang::CastKind::CK_MatrixCast: return CastKind::MatrixCast; } - VAST_UNREACHABLE( "unsupported cast kind" ); + VAST_UNIMPLEMENTED_MSG( "unsupported cast kind" ); } IdentKind ident_kind(const clang::PredefinedExpr *expr) diff --git a/lib/vast/CodeGen/CodeGenTypeVisitor.cpp b/lib/vast/CodeGen/CodeGenTypeVisitor.cpp index 2b740dda18..0b52eb2e94 100644 --- a/lib/vast/CodeGen/CodeGenTypeVisitor.cpp +++ b/lib/vast/CodeGen/CodeGenTypeVisitor.cpp @@ -30,7 +30,7 @@ namespace vast::cg { case BuiltinType::UInt128: return hl::IntegerKind::Int128; default: - VAST_UNREACHABLE("unknown integer kind"); + VAST_UNIMPLEMENTED_MSG("unknown integer kind"); } } @@ -51,7 +51,7 @@ namespace vast::cg { case BuiltinType::Float128: return hl::FloatingKind::Float128; default: - VAST_UNREACHABLE("unknown floating kind"); + VAST_UNIMPLEMENTED_MSG("unknown floating kind"); } } diff --git a/lib/vast/Dialect/Core/Linkage.cpp b/lib/vast/Dialect/Core/Linkage.cpp index b968c2454a..11e15615d3 100644 --- a/lib/vast/Dialect/Core/Linkage.cpp +++ b/lib/vast/Dialect/Core/Linkage.cpp @@ -39,7 +39,7 @@ namespace vast::core { return true; } - VAST_UNREACHABLE("No such linkage"); + VAST_FATAL("No such linkage"); } bool is_vardecl_strong_definition(const clang::VarDecl* decl) { @@ -149,10 +149,8 @@ namespace vast::core { case GlobalLinkageKind::PrivateLinkage: return Visibility::Private; default: - VAST_UNREACHABLE("unsupported linkage kind {0}", stringifyGlobalLinkageKind(linkage)); + VAST_FATAL("unsupported linkage kind {0}", stringifyGlobalLinkageKind(linkage)); } - - VAST_UNREACHABLE("missed linkage kind"); } GlobalLinkageKind get_declarator_linkage( diff --git a/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp b/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp index f24fac26d0..428a077d79 100644 --- a/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp +++ b/lib/vast/Dialect/HighLevel/HighLevelTypes.cpp @@ -57,7 +57,7 @@ namespace vast::hl } } - VAST_UNREACHABLE("unknown typedef name"); + VAST_FATAL("unknown typedef name"); } auto name_of_record(mlir_type t) -> std::optional< std::string > @@ -77,7 +77,7 @@ namespace vast::hl if (auto ty = type.dyn_cast< TypedefType >()) return getFunctionType(getTypedefType(ty, mod), mod); - VAST_UNREACHABLE("unknown type to extract function type"); + VAST_UNIMPLEMENTED_MSG("unknown type to extract function type"); } core::FunctionType getFunctionType(Value callee) { @@ -102,7 +102,7 @@ namespace vast::hl return getFunctionType(value.getType(), mod); } - VAST_UNREACHABLE("unknown callee type"); + VAST_UNIMPLEMENTED_MSG("unknown callee type"); } diff --git a/lib/vast/Dialect/HighLevel/HighLevelVar.cpp b/lib/vast/Dialect/HighLevel/HighLevelVar.cpp index f4f801b26e..1516690427 100644 --- a/lib/vast/Dialect/HighLevel/HighLevelVar.cpp +++ b/lib/vast/Dialect/HighLevel/HighLevelVar.cpp @@ -38,7 +38,7 @@ namespace vast::hl return DeclContextKind::dc_record; if (mlir::isa< EnumDeclOp >(st)) return DeclContextKind::dc_enum; - VAST_UNREACHABLE("unknown declaration context"); + VAST_UNIMPLEMENTED_MSG("unknown declaration context"); } bool VarDeclOp::isStaticDataMember() { @@ -63,7 +63,7 @@ namespace vast::hl case StorageClass::sc_private_extern: return false; } - VAST_UNREACHABLE("unknown starage class"); + VAST_UNIMPLEMENTED_MSG("unknown starage class"); } bool VarDeclOp::isStaticLocal() { diff --git a/lib/vast/Frontend/Action.cpp b/lib/vast/Frontend/Action.cpp index f369f6f09b..17998798e3 100644 --- a/lib/vast/Frontend/Action.cpp +++ b/lib/vast/Frontend/Action.cpp @@ -44,7 +44,7 @@ namespace vast::cc { break; } - VAST_UNREACHABLE("unsupported action type"); + VAST_FATAL("unsupported action type"); } static auto get_output_stream(compiler_instance &ci, string_ref in, output_type act) diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index ea69b278c9..c676da20c3 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -79,7 +79,7 @@ namespace vast::cc { if (!vargs.has_option(opt::disable_vast_verifier)) { if (!codegen->verify_module()) { - VAST_UNREACHABLE("codegen: module verification error before running vast passes"); + VAST_FATAL("codegen: module verification error before running vast passes"); } } } @@ -213,7 +213,7 @@ namespace vast::cc { // diagnostics matched. if (verify_diagnostics && src_mgr_handler.verify().failed()) { llvm::sys::RunInterruptHandlers(); - VAST_UNREACHABLE("failed mlir codegen"); + VAST_FATAL("failed mlir codegen"); } // Emit remaining defaulted C++ methods @@ -233,9 +233,8 @@ namespace vast::cc { pipeline_source::ast, output_type::emit_mlir, *mctx, vargs, default_pipelines_config() ); - if (mlir::failed(pipeline->run(mod))) { - VAST_UNREACHABLE("MLIR pass manager failed when running vast passes"); - } + auto result = pipeline->run(mod); + VAST_CHECK(mlir::succeeded(result), "MLIR pass manager failed when running vast passes"); } source_language get_source_language(const cc::language_options &opts) { diff --git a/lib/vast/Frontend/Targets.cpp b/lib/vast/Frontend/Targets.cpp index afa9fe2185..ac291d0bff 100644 --- a/lib/vast/Frontend/Targets.cpp +++ b/lib/vast/Frontend/Targets.cpp @@ -15,7 +15,7 @@ namespace vast::cc { if (trg == "cir") { return target_dialect::cir; } - VAST_UNREACHABLE("Unknown option of target dialect: {0}", trg); + VAST_FATAL("Unknown option of target dialect: {0}", trg); } std::string to_string(target_dialect target) { diff --git a/tools/vast-front/compiler_invocation.cpp b/tools/vast-front/compiler_invocation.cpp index dadd8a2791..346d5f7417 100644 --- a/tools/vast-front/compiler_invocation.cpp +++ b/tools/vast-front/compiler_invocation.cpp @@ -51,7 +51,7 @@ namespace vast::cc case EmitAssembly: return std::make_unique< vast::cc::emit_assembly_action >(vargs); case EmitLLVM: return std::make_unique< vast::cc::emit_llvm_action >(vargs); case EmitObj: return std::make_unique< vast::cc::emit_obj_action >(vargs); - default: VAST_UNREACHABLE("unsupported frontend action"); + default: VAST_UNIMPLEMENTED_MSG("unsupported frontend action"); } VAST_UNIMPLEMENTED_MSG("not implemented frontend action"); diff --git a/tools/vast-repl/command.cpp b/tools/vast-repl/command.cpp index 9ec3cbb567..f1f79d73d5 100644 --- a/tools/vast-repl/command.cpp +++ b/tools/vast-repl/command.cpp @@ -145,7 +145,7 @@ namespace vast::repl::cmd { auto th = state.tower->top(); for (auto pass : passes) { if (mlir::failed(mlir::parsePassPipeline(pass, pm))) { - VAST_UNREACHABLE("error: failed to parse pass pipeline"); + VAST_FATAL("failed to parse pass pipeline"); } th = state.tower->apply(th, pm); } diff --git a/tools/vast-repl/vast-repl.cpp b/tools/vast-repl/vast-repl.cpp index 765a7676b0..84c1d0c5e3 100644 --- a/tools/vast-repl/vast-repl.cpp +++ b/tools/vast-repl/vast-repl.cpp @@ -44,7 +44,7 @@ namespace vast::repl auto params = parse_params< cmd::load::command_params >(args); cli.exec(make_command< cmd::load >(params)); } else { - VAST_UNREACHABLE("unsupported arguments"); + VAST_FATAL("unsupported arguments"); } } From 5fba8cf49b2b2d07af43a4b6699ef67aae5cbc1a Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 23 Jan 2024 14:40:55 +0100 Subject: [PATCH 24/37] cc: Add option to print vast pipeline. --- include/vast/Frontend/Consumer.hpp | 2 -- include/vast/Frontend/Options.hpp | 4 ++-- lib/vast/Frontend/Consumer.cpp | 23 +++++++++++--------- todo.txt | 34 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 todo.txt diff --git a/include/vast/Frontend/Consumer.hpp b/include/vast/Frontend/Consumer.hpp index 173642edf9..3e4ecbf154 100644 --- a/include/vast/Frontend/Consumer.hpp +++ b/include/vast/Frontend/Consumer.hpp @@ -61,8 +61,6 @@ namespace vast::cc { protected: - void execute_pipeline(vast_module mod, mcontext_t *mctx); - virtual void anchor() {} action_options opts; diff --git a/include/vast/Frontend/Options.hpp b/include/vast/Frontend/Options.hpp index 8331dcb866..4b7ed0d7b2 100644 --- a/include/vast/Frontend/Options.hpp +++ b/include/vast/Frontend/Options.hpp @@ -72,6 +72,8 @@ namespace vast::cc constexpr string_ref emit_asm = "emit-asm"; constexpr string_ref emit_mlir = "emit-mlir"; + constexpr string_ref print_pipeline = "print-pipeline"; + constexpr string_ref debug = "debug"; constexpr string_ref simplify = "simplify"; @@ -79,8 +81,6 @@ namespace vast::cc constexpr string_ref show_locs = "show-locs"; constexpr string_ref locs_as_meta_ids = "locs-as-meta-ids"; - constexpr string_ref opt_pipeline = "pipeline"; - constexpr string_ref disable_vast_verifier = "disable-vast-verifier"; constexpr string_ref vast_verify_diags = "verify-diags"; constexpr string_ref disable_emit_cxx_default = "disable-emit-cxx-default"; diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index c676da20c3..4773812766 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -207,7 +207,19 @@ namespace vast::cc { llvm::DebugFlag = true; } - execute_pipeline(mod.get(), mctx); + // Setup and execute vast pipeline + auto pipeline = setup_pipeline( + pipeline_source::ast, output_type::emit_mlir, *mctx, vargs, + default_pipelines_config() + ); + VAST_CHECK(pipeline, "failed to setup pipeline"); + + if (vargs.has_option(opt::print_pipeline)) { + pipeline->dump(); + } + + auto result = pipeline->run(mod.get()); + VAST_CHECK(mlir::succeeded(result), "MLIR pass manager failed when running vast passes"); // Verify the diagnostic handler to make sure that each of the // diagnostics matched. @@ -228,15 +240,6 @@ namespace vast::cc { mod->print(*output_stream, flags); } - void vast_consumer::execute_pipeline(vast_module mod, mcontext_t *mctx) { - auto pipeline = setup_pipeline( - pipeline_source::ast, output_type::emit_mlir, *mctx, vargs, default_pipelines_config() - ); - - auto result = pipeline->run(mod); - VAST_CHECK(mlir::succeeded(result), "MLIR pass manager failed when running vast passes"); - } - source_language get_source_language(const cc::language_options &opts) { using ClangStd = clang::LangStandard; diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000000..7328437bf8 --- /dev/null +++ b/todo.txt @@ -0,0 +1,34 @@ +Failed Tests (27): + VAST :: vast/Compile/ObjectFiles/identity-a.c + VAST :: vast/Compile/ObjectFiles/struct-a.c + VAST :: vast/Compile/ObjectFiles/struct-b.c + VAST :: vast/Compile/ObjectFiles/void-return-a.c + VAST :: vast/Compile/SingleSource/argc.c + VAST :: vast/Compile/SingleSource/argv-a.c + VAST :: vast/Compile/SingleSource/fib-a.c + VAST :: vast/Compile/SingleSource/global-a.c + VAST :: vast/Compile/SingleSource/putchar-a.c + VAST :: vast/Compile/SingleSource/puts-a.c + VAST :: vast/Compile/SingleSource/strlit-a.c + VAST :: vast/Conversion/Common/IRsToLLVM/bin_chain-a.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-a.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-b.cpp + VAST :: vast/Conversion/Common/IRsToLLVM/cast-c.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-d.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-e.cpp + VAST :: vast/Conversion/Common/IRsToLLVM/cast-f.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-g.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-h.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-i.c + VAST :: vast/Conversion/Common/IRsToLLVM/cast-j.c + VAST :: vast/Conversion/Common/IRsToLLVM/signs.c + VAST :: vast/Dialect/HighLevel/asm-c.c + VAST :: vast/Dialect/HighLevel/attr-c.c + VAST :: vast/Dialect/HighLevel/vararg-a.c + VAST :: vast/Transform/HL/LowerTypes/vars-b.cpp + + +Testing Time: 1.96s + Unsupported: 14 + Passed : 219 + Failed : 27 \ No newline at end of file From c828e705a6b84f94b28413b2293c65b4b3a0b753 Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 23 Jan 2024 15:24:24 +0100 Subject: [PATCH 25/37] cc: Add option to produce minimal crash reports and disable multithreading. --- include/vast/Frontend/Options.hpp | 2 ++ lib/vast/Frontend/Consumer.cpp | 4 ---- lib/vast/Frontend/Pipelines.cpp | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/vast/Frontend/Options.hpp b/include/vast/Frontend/Options.hpp index 4b7ed0d7b2..e29478041a 100644 --- a/include/vast/Frontend/Options.hpp +++ b/include/vast/Frontend/Options.hpp @@ -73,7 +73,9 @@ namespace vast::cc constexpr string_ref emit_mlir = "emit-mlir"; constexpr string_ref print_pipeline = "print-pipeline"; + constexpr string_ref emit_crash_reproducer = "emit-crash-reproducer"; + constexpr string_ref disable_multithreading = "disable-multithreading"; constexpr string_ref debug = "debug"; constexpr string_ref simplify = "simplify"; diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index 4773812766..43754aaeb7 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -214,10 +214,6 @@ namespace vast::cc { ); VAST_CHECK(pipeline, "failed to setup pipeline"); - if (vargs.has_option(opt::print_pipeline)) { - pipeline->dump(); - } - auto result = pipeline->run(mod.get()); VAST_CHECK(mlir::succeeded(result), "MLIR pass manager failed when running vast passes"); diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index 4c8e6f0bb0..974d635fa0 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -128,6 +128,20 @@ namespace vast::cc { *passes << std::move(step); } + if (vargs.has_option(opt::print_pipeline)) { + passes->dump(); + } + + if (vargs.has_option(opt::disable_multithreading) || vargs.has_option(opt::emit_crash_reproducer)) { + mctx.disableMultithreading(); + } + + if (vargs.has_option(opt::emit_crash_reproducer)) { + auto reproducer_path = vargs.get_option(opt::emit_crash_reproducer); + VAST_CHECK(reproducer_path.has_value(), "expected path to reproducer"); + passes->enableCrashReproducerGeneration(reproducer_path.value(), true /* local reproducer */); + } + return passes; } From e015502847081aa7d0e6d1e33ce3f1adc1ac022a Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 23 Jan 2024 15:45:45 +0100 Subject: [PATCH 26/37] docs: Add description of some debug options. --- docs/GettingStarted/debug.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 docs/GettingStarted/debug.md diff --git a/docs/GettingStarted/debug.md b/docs/GettingStarted/debug.md new file mode 100644 index 0000000000..df3c470d5e --- /dev/null +++ b/docs/GettingStarted/debug.md @@ -0,0 +1,35 @@ +## Debugging + +VAST makes use of the MLIR infrastructure to facilitate the reproduction of crashes within the pipeline. You can refer to the MLIR documentation on [crash and failure reproduction](https://mlir.llvm.org/docs/PassManagement/#crash-and-failure-reproduction) for more details. We provide a similar set of options in vast-front to aid in debugging. + +### Generating Crash Reproducers + +To generate a minimal reproducer for a crashed pipeline of `vast-front`, use the following option: + +``` +-vast-emit-crash-reproducer="reproducer.mlir" +``` + +This option disables multithreading to ensure a comprehensive crash report. You can then load and examine the crash report using the following command: + +``` +vast-opt -run-reproducer reproducer.mlir +``` + +### Pipeline Information + +To obtain a detailed insight into the pipeline, you can use the following option of `vast-front`: + +``` +-vast-print-pipeline +``` + +This option dumps the pipeline string to the standard error stream. You can use this information for a more specific investigation of the pipeline. Execute the pipeline with the printed string using the following command: + +``` +vast-opt --pass-pipeline="pipeline-string" +``` + +### Debug Pipeline + +With the `-vast-debug` option, you get more detailed crash reports. It shows MLIR operations when there's an error and provides current stack traces. \ No newline at end of file From 033b672b3e7a6690cb9268224eaacda66f870fa3 Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 23 Jan 2024 15:45:56 +0100 Subject: [PATCH 27/37] www: Add debug section. --- www/mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/www/mkdocs.yml b/www/mkdocs.yml index d036b10bde..ede7d0b908 100644 --- a/www/mkdocs.yml +++ b/www/mkdocs.yml @@ -4,6 +4,7 @@ nav: - Introduction: README.md - Getting Started: - Build & Run: GettingStarted/build.md + - Debug: GettingStarted/debug.md - How to contribute: CONTRIBUTING.md - How to create a new dialect: GettingStarted/extend.md - Dialects: From 871fc565e08392db577049f1d51abff192e376a2 Mon Sep 17 00:00:00 2001 From: xlauko Date: Tue, 23 Jan 2024 16:27:26 +0100 Subject: [PATCH 28/37] conv: Fix core conversion dependencies. --- lib/vast/Conversion/Common/Passes.cpp | 2 +- lib/vast/Conversion/Core/Passes.cpp | 3 ++- todo.txt | 34 --------------------------- 3 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 todo.txt diff --git a/lib/vast/Conversion/Common/Passes.cpp b/lib/vast/Conversion/Common/Passes.cpp index 05e3ffe80c..bde2d4345a 100644 --- a/lib/vast/Conversion/Common/Passes.cpp +++ b/lib/vast/Conversion/Common/Passes.cpp @@ -13,7 +13,7 @@ namespace vast::conv::pipeline { pipeline_step_ptr irs_to_llvm() { // TODO add dependencies - return pass(createIRsToLLVMPass).depends_on(core_to_llvm); + return pass(createIRsToLLVMPass); } } // namespace vast::conv::pipeline diff --git a/lib/vast/Conversion/Core/Passes.cpp b/lib/vast/Conversion/Core/Passes.cpp index 550eb67a4b..8ae55cc4ee 100644 --- a/lib/vast/Conversion/Core/Passes.cpp +++ b/lib/vast/Conversion/Core/Passes.cpp @@ -23,7 +23,8 @@ namespace vast::conv::pipeline { pipeline_step_ptr core_to_llvm() { // TODO add dependencies - return pass(createCoreToLLVMPass); + return pass(createCoreToLLVMPass) + .depends_on(to_ll, irs_to_llvm); } pipeline_step_ptr to_llvm() { diff --git a/todo.txt b/todo.txt deleted file mode 100644 index 7328437bf8..0000000000 --- a/todo.txt +++ /dev/null @@ -1,34 +0,0 @@ -Failed Tests (27): - VAST :: vast/Compile/ObjectFiles/identity-a.c - VAST :: vast/Compile/ObjectFiles/struct-a.c - VAST :: vast/Compile/ObjectFiles/struct-b.c - VAST :: vast/Compile/ObjectFiles/void-return-a.c - VAST :: vast/Compile/SingleSource/argc.c - VAST :: vast/Compile/SingleSource/argv-a.c - VAST :: vast/Compile/SingleSource/fib-a.c - VAST :: vast/Compile/SingleSource/global-a.c - VAST :: vast/Compile/SingleSource/putchar-a.c - VAST :: vast/Compile/SingleSource/puts-a.c - VAST :: vast/Compile/SingleSource/strlit-a.c - VAST :: vast/Conversion/Common/IRsToLLVM/bin_chain-a.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-a.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-b.cpp - VAST :: vast/Conversion/Common/IRsToLLVM/cast-c.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-d.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-e.cpp - VAST :: vast/Conversion/Common/IRsToLLVM/cast-f.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-g.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-h.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-i.c - VAST :: vast/Conversion/Common/IRsToLLVM/cast-j.c - VAST :: vast/Conversion/Common/IRsToLLVM/signs.c - VAST :: vast/Dialect/HighLevel/asm-c.c - VAST :: vast/Dialect/HighLevel/attr-c.c - VAST :: vast/Dialect/HighLevel/vararg-a.c - VAST :: vast/Transform/HL/LowerTypes/vars-b.cpp - - -Testing Time: 1.96s - Unsupported: 14 - Passed : 219 - Failed : 27 \ No newline at end of file From 1e3cdda53e3d6a4b640b1c2a355cf7ce144b56f9 Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 24 Jan 2024 15:03:11 +0100 Subject: [PATCH 29/37] util: Allow nested pipelines. --- include/vast/Util/Pipeline.hpp | 29 +++++++++++++++++++++++++++-- lib/vast/Util/Pipeline.cpp | 10 ++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/vast/Util/Pipeline.hpp b/include/vast/Util/Pipeline.hpp index c12f993c71..88969176c9 100644 --- a/include/vast/Util/Pipeline.hpp +++ b/include/vast/Util/Pipeline.hpp @@ -40,14 +40,17 @@ namespace vast { using base::base; - void addPass(std::unique_ptr< mlir::Pass > pass) { + void addPass(std::unique_ptr< mlir::Pass > pass); + + template< typename parent_t > + void addNestedPass(std::unique_ptr< mlir::Pass > pass) { auto id = pass->getTypeID(); if (seen.count(id)) { return; } seen.insert(id); - base::addPass(std::move(pass)); + base::addNestedPass< parent_t >(std::move(pass)); } friend pipeline_t &operator<<(pipeline_t &ppl, pipeline_step_ptr pass); @@ -116,6 +119,21 @@ namespace vast { pass_builder_t pass_builder; }; + template< typename parent_t > + struct nested_pass_pipeline_step : pipeline_step + { + explicit nested_pass_pipeline_step(pass_builder_t builder) + : pass_builder(builder) + {} + + void schedule_on(pipeline_t &ppl) const override { + schedule_dependencies(ppl); + ppl.addNestedPass< parent_t >(pass_builder()); + } + + pass_builder_t pass_builder; + }; + // compound step represents subpipeline to be run struct compound_pipeline_step : pipeline_step { @@ -147,6 +165,13 @@ namespace vast { ); } + template< typename parent, typename... args_t > + decltype(auto) nested(args_t &&... args) { + return pipeline_step_init< nested_pass_pipeline_step< parent > >( + std::forward< args_t >(args)... + ); + } + template< auto step > decltype(auto) optional() { return pipeline_step_init< optional_pipeline >(step); diff --git a/lib/vast/Util/Pipeline.cpp b/lib/vast/Util/Pipeline.cpp index 5add79b547..989b5b3d02 100644 --- a/lib/vast/Util/Pipeline.cpp +++ b/lib/vast/Util/Pipeline.cpp @@ -5,6 +5,16 @@ namespace vast { + void pipeline_t::addPass(std::unique_ptr pass) { + auto id = pass->getTypeID(); + if (seen.count(id)) { + return; + } + + seen.insert(id); + base::addPass(std::move(pass)); + } + pipeline_t &operator<<(pipeline_t &ppl, pipeline_step_ptr pass) { pass->schedule_on(ppl); return ppl; From 785f605a50d2c02458846b38b8ec74da4e7d1f0b Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 24 Jan 2024 15:06:19 +0100 Subject: [PATCH 30/37] conv: Fix debug scope pipeline type to be nested. --- lib/vast/Conversion/Core/Passes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vast/Conversion/Core/Passes.cpp b/lib/vast/Conversion/Core/Passes.cpp index 8ae55cc4ee..fd5012a92a 100644 --- a/lib/vast/Conversion/Core/Passes.cpp +++ b/lib/vast/Conversion/Core/Passes.cpp @@ -17,7 +17,7 @@ namespace vast::conv::pipeline { // This is necessary to have line tables emitted and basic debugger // working. In the future we will add proper debug information emission // directly from our frontend. - return pass(mlir::LLVM::createDIScopeForLLVMFuncOpPass) + return nested< mlir::LLVM::LLVMFuncOp >(mlir::LLVM::createDIScopeForLLVMFuncOpPass) .depends_on(core_to_llvm); } From 09f013c55f337020d0d0b24a36e6126b7f060b02 Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 24 Jan 2024 15:06:52 +0100 Subject: [PATCH 31/37] conv: Add dependency to irs to llvm pipeline. --- lib/vast/Conversion/Common/Passes.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vast/Conversion/Common/Passes.cpp b/lib/vast/Conversion/Common/Passes.cpp index bde2d4345a..9b1ed55aaf 100644 --- a/lib/vast/Conversion/Common/Passes.cpp +++ b/lib/vast/Conversion/Common/Passes.cpp @@ -13,7 +13,8 @@ namespace vast::conv::pipeline { pipeline_step_ptr irs_to_llvm() { // TODO add dependencies - return pass(createIRsToLLVMPass); + return pass(createIRsToLLVMPass) + .depends_on(to_ll); } } // namespace vast::conv::pipeline From 50c535acf47f9c40340a9abe97ebcc3d289564e0 Mon Sep 17 00:00:00 2001 From: xlauko Date: Wed, 24 Jan 2024 17:37:35 +0100 Subject: [PATCH 32/37] cc: Refactor mlir pipeline to be used in any workflow. --- include/vast/Frontend/Consumer.hpp | 4 ++++ include/vast/Frontend/Pipelines.hpp | 2 +- lib/vast/Frontend/Consumer.cpp | 31 +++++++++++++++++++---------- lib/vast/Frontend/Pipelines.cpp | 16 ++++----------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/include/vast/Frontend/Consumer.hpp b/include/vast/Frontend/Consumer.hpp index 3e4ecbf154..2767cc8027 100644 --- a/include/vast/Frontend/Consumer.hpp +++ b/include/vast/Frontend/Consumer.hpp @@ -98,6 +98,10 @@ namespace vast::cc { target_dialect target, owning_module_ref mod, mcontext_t *mctx ); + void process_mlir_module( + target_dialect target, mlir::ModuleOp mod, mcontext_t *mctx + ); + output_type action; output_stream_ptr output_stream; }; diff --git a/include/vast/Frontend/Pipelines.hpp b/include/vast/Frontend/Pipelines.hpp index 9c4fc14e27..99b1549553 100644 --- a/include/vast/Frontend/Pipelines.hpp +++ b/include/vast/Frontend/Pipelines.hpp @@ -37,7 +37,7 @@ namespace vast::cc { // scheduled pipeline. // std::unique_ptr< pipeline_t > setup_pipeline( - pipeline_source src, output_type trg, + pipeline_source src, target_dialect trg, mcontext_t &mctx, const vast_args &vargs, const pipelines_config &config diff --git a/lib/vast/Frontend/Consumer.cpp b/lib/vast/Frontend/Consumer.cpp index 43754aaeb7..e3795c8abd 100644 --- a/lib/vast/Frontend/Consumer.cpp +++ b/lib/vast/Frontend/Consumer.cpp @@ -149,8 +149,10 @@ namespace vast::cc { backend::Backend_EmitAssembly, std::move(mod), mctx.get() ); case output_type::emit_mlir: { - auto trg = parse_target_dialect(vargs.get_option(opt::emit_mlir).value()); - return emit_mlir_output(trg, std::move(mod), mctx.get()); + if (auto trg = vargs.get_option(opt::emit_mlir)) { + return emit_mlir_output(parse_target_dialect(trg.value()), std::move(mod), mctx.get()); + } + VAST_FATAL("no target dialect specified for MLIR output"); } case output_type::emit_llvm: return emit_backend_output( @@ -170,21 +172,20 @@ namespace vast::cc { ) { llvm::LLVMContext llvm_context; + process_mlir_module(target_dialect::llvm, mlir_module.get(), mctx); + auto mod = target::llvmir::translate(mlir_module.get(), llvm_context); auto dl = cgctx->actx.getTargetInfo().getDataLayoutString(); + clang::EmitBackendOutput( opts.diags, opts.headers, opts.codegen, opts.target, opts.lang, dl, mod.get(), backend_action, &opts.vfs, std::move(output_stream) ); } - void vast_stream_consumer::emit_mlir_output( - target_dialect target, owning_module_ref mod, mcontext_t *mctx + void vast_stream_consumer::process_mlir_module( + target_dialect target, mlir::ModuleOp mod, mcontext_t *mctx ) { - if (!output_stream || !mod) { - return; - } - // Handle source manager properly given that lifetime analysis // might emit warnings and remarks. auto &src_mgr = cgctx->actx.getSourceManager(); @@ -209,12 +210,12 @@ namespace vast::cc { // Setup and execute vast pipeline auto pipeline = setup_pipeline( - pipeline_source::ast, output_type::emit_mlir, *mctx, vargs, + pipeline_source::ast, target, *mctx, vargs, default_pipelines_config() ); VAST_CHECK(pipeline, "failed to setup pipeline"); - auto result = pipeline->run(mod.get()); + auto result = pipeline->run(mod); VAST_CHECK(mlir::succeeded(result), "MLIR pass manager failed when running vast passes"); // Verify the diagnostic handler to make sure that each of the @@ -228,6 +229,16 @@ namespace vast::cc { // if (!vargs.has_option(opt::disable_emit_cxx_default)) { // generator->build_default_methods(); // } + } + + void vast_stream_consumer::emit_mlir_output( + target_dialect target, owning_module_ref mod, mcontext_t *mctx + ) { + if (!output_stream || !mod) { + return; + } + + process_mlir_module(target, mod.get(), mctx); // FIXME: we cannot roundtrip prettyForm=true right now. mlir::OpPrintingFlags flags; diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index 974d635fa0..799909b1ee 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -62,7 +62,7 @@ namespace vast::cc { gap::generator< pipeline_step_ptr > conversion( pipeline_source src, - output_type trg, + target_dialect trg, const vast_args &vargs, const pipelines_config &config ) { @@ -70,17 +70,9 @@ namespace vast::cc { // deduced from source, target and vargs auto path = default_conversion_path; - auto target_dialect = [&] () -> enum target_dialect { - if (trg == output_type::emit_mlir) { - return parse_target_dialect(vargs.get_option(opt::emit_mlir).value()); - } - // if we user do not specify target dialect, we convert all the way to llvm - return target_dialect::llvm; - } (); - bool simplify = vargs.has_option(opt::simplify); - if (target_dialect == target_dialect::high_level && !simplify) { + if (trg == target_dialect::high_level && !simplify) { co_return; } @@ -89,7 +81,7 @@ namespace vast::cc { co_yield step(); } - if (target_dialect == dialect) { + if (trg == dialect) { break; } } @@ -99,7 +91,7 @@ namespace vast::cc { std::unique_ptr< pipeline_t > setup_pipeline( pipeline_source src, - output_type trg, + target_dialect trg, mcontext_t &mctx, const vast_args &vargs, const pipelines_config &config From e040c604b4f4b41b671aa533edb95b5aee8aeed9 Mon Sep 17 00:00:00 2001 From: xlauko Date: Thu, 25 Jan 2024 14:11:10 +0100 Subject: [PATCH 33/37] cc: Add abi to standard pipeline. --- lib/vast/Frontend/Pipelines.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/vast/Frontend/Pipelines.cpp b/lib/vast/Frontend/Pipelines.cpp index 799909b1ee..4351a3b03b 100644 --- a/lib/vast/Frontend/Pipelines.cpp +++ b/lib/vast/Frontend/Pipelines.cpp @@ -36,6 +36,10 @@ namespace vast::cc { return hl::pipeline::stdtypes(); } + pipeline_step_ptr abi() { + return optional< conv::pipeline::abi >(); + } + // Conversion to LLVM dialects pipeline_step_ptr llvm() { return conv::pipeline::to_llvm(); @@ -56,7 +60,7 @@ namespace vast::cc { conversion_path default_conversion_path = { { target_dialect::high_level, { reduce_high_level } }, - { target_dialect::std, { standard_types } }, + { target_dialect::std, { standard_types, abi } }, { target_dialect::llvm, { llvm } } }; From cb8aacfb732fea207fae1da699588d810f329867 Mon Sep 17 00:00:00 2001 From: xlauko Date: Thu, 25 Jan 2024 14:12:12 +0100 Subject: [PATCH 34/37] test: Make some tests runner independent. --- test/vast/Dialect/HighLevel/asm-c.c | 4 ++-- test/vast/Dialect/HighLevel/attr-c.c | 2 +- test/vast/Dialect/HighLevel/vararg-a.c | 6 +++--- test/vast/Transform/HL/LowerTypes/vars-b.cpp | 4 +--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test/vast/Dialect/HighLevel/asm-c.c b/test/vast/Dialect/HighLevel/asm-c.c index a4592fc07d..1f2f3e160d 100644 --- a/test/vast/Dialect/HighLevel/asm-c.c +++ b/test/vast/Dialect/HighLevel/asm-c.c @@ -1,5 +1,5 @@ -// RUN: %vast-front -vast-emit-mlir=hl %s -o - | %file-check %s -// RUN: %vast-front -vast-emit-mlir=hl %s -o %t && %vast-opt %t | diff -B %t - +// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-mlir=hl %s -o - | %file-check %s +// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-mlir=hl %s -o %t && %vast-opt %t | diff -B %t - int frob(int x) { diff --git a/test/vast/Dialect/HighLevel/attr-c.c b/test/vast/Dialect/HighLevel/attr-c.c index aa417d0c5e..db7f97502f 100644 --- a/test/vast/Dialect/HighLevel/attr-c.c +++ b/test/vast/Dialect/HighLevel/attr-c.c @@ -1,7 +1,7 @@ // RUN: %vast-front -vast-emit-mlir=hl -o - %s | %file-check %s // RUN: %vast-front -vast-emit-mlir=hl -o - %s > %t && %vast-opt %t | diff -B %t - -// CHECK: hl.func @malloc {{.*}} attributes {alloc_size = #hl.alloc_size, builtin = #hl.builtin<{{[0-9]+}}>, malloc = #hl.restrict, nothrow = #hl.nothrow, sym_visibility = "private"} +// CHECK: hl.func @malloc {{.*}} #include int main() { diff --git a/test/vast/Dialect/HighLevel/vararg-a.c b/test/vast/Dialect/HighLevel/vararg-a.c index 6d3c501005..a90c3fbc48 100644 --- a/test/vast/Dialect/HighLevel/vararg-a.c +++ b/test/vast/Dialect/HighLevel/vararg-a.c @@ -3,9 +3,9 @@ #include -// CHECK: hl.func @__builtin_va_end (!hl.lvalue>>) -> !hl.void -// CHECK: hl.func @__builtin_va_start (!hl.lvalue>>, ...) -> !hl.void -// CHECK: hl.typedef "va_list" : !hl.elaborated> +// CHECK: hl.func @__builtin_va_end +// CHECK: hl.func @__builtin_va_start +// CHECK: hl.typedef "va_list" // CHECK: hl.func @format ({{%.*}}: !hl.lvalue>>, ...) -> !hl.void void format(const char *fmt, ...) { diff --git a/test/vast/Transform/HL/LowerTypes/vars-b.cpp b/test/vast/Transform/HL/LowerTypes/vars-b.cpp index 31b564dbe2..958551195e 100644 --- a/test/vast/Transform/HL/LowerTypes/vars-b.cpp +++ b/test/vast/Transform/HL/LowerTypes/vars-b.cpp @@ -1,4 +1,4 @@ -// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %vast-opt --vast-hl-lower-types | %file-check %s +// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-mlir=hl %s -o - | %vast-opt --vast-hl-lower-types | %file-check %s // CHECK-LABEL: hl.func @main () -> si32 int main() @@ -33,8 +33,6 @@ int main() // CHECK: } long long ll = 142; - - // CHECK: hl.var "ld" : !hl.lvalue = { // CHECK: [[V9:%[0-9]+]] = hl.const #core.float<91.019999999999996> : f64 // CHECK: [[V10:%[0-9]+]] = hl.implicit_cast [[V9]] FloatingCast : f64 -> f128 From bdf59439bdaada670bfc803c851ce5656a9d59c3 Mon Sep 17 00:00:00 2001 From: xlauko Date: Thu, 25 Jan 2024 14:12:33 +0100 Subject: [PATCH 35/37] test: Turn off tests failing after abi pass. --- test/vast/Compile/SingleSource/putchar-a.c | 1 + test/vast/Compile/SingleSource/puts-a.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/vast/Compile/SingleSource/putchar-a.c b/test/vast/Compile/SingleSource/putchar-a.c index a57916883f..ee3757be33 100644 --- a/test/vast/Compile/SingleSource/putchar-a.c +++ b/test/vast/Compile/SingleSource/putchar-a.c @@ -1,4 +1,5 @@ // RUN: %vast-front -o %t %s && %t | %file-check %s +// REQUIRES: abi int putchar(int); diff --git a/test/vast/Compile/SingleSource/puts-a.c b/test/vast/Compile/SingleSource/puts-a.c index 8d074eee28..dab02571b5 100644 --- a/test/vast/Compile/SingleSource/puts-a.c +++ b/test/vast/Compile/SingleSource/puts-a.c @@ -1,4 +1,5 @@ // RUN: %vast-front -o %t %s && %t hello | %file-check %s +// REQUIRES: abi int puts(const char *); @@ -12,6 +13,4 @@ int main(int argc, char **argv) // CHECK: hello puts(argv[1]); - // Workaround as `vast-front` and `vast-cc` behave differently. - return 0; } From 8ac6ca982419308d96d8806a475fa06572ef108f Mon Sep 17 00:00:00 2001 From: xlauko Date: Thu, 25 Jan 2024 14:17:01 +0100 Subject: [PATCH 36/37] hl: Remove obsolete pipelines definitions. --- include/vast/Dialect/HighLevel/Passes.hpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/vast/Dialect/HighLevel/Passes.hpp b/include/vast/Dialect/HighLevel/Passes.hpp index d526382e25..679d3fb234 100644 --- a/include/vast/Dialect/HighLevel/Passes.hpp +++ b/include/vast/Dialect/HighLevel/Passes.hpp @@ -26,19 +26,10 @@ namespace vast::hl { std::unique_ptr< mlir::Pass > createSpliceTrailingScopes(); - void registerHLToLLVMIR(mlir::DialectRegistry &); - void registerHLToLLVMIR(mlir::MLIRContext &); - /// Generate the code for registering passes. #define GEN_PASS_REGISTRATION #include "vast/Dialect/HighLevel/Passes.h.inc" - static inline void build_simplify_hl_pipeline(mlir::PassManager &pm) { - pm.addPass(createHLLowerTypesPass()); - pm.addPass(createDCEPass()); - pm.addPass(createLowerTypeDefsPass()); - } - namespace pipeline { pipeline_step_ptr canonicalize(); From 57ec541114ba15490b7bfa88ac948462bfb663d5 Mon Sep 17 00:00:00 2001 From: xlauko Date: Thu, 25 Jan 2024 14:17:06 +0100 Subject: [PATCH 37/37] conv: Remove obsolete pipelines definitions. --- include/vast/Conversion/Passes.hpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/include/vast/Conversion/Passes.hpp b/include/vast/Conversion/Passes.hpp index 10764e0bc9..958c34bfa9 100644 --- a/include/vast/Conversion/Passes.hpp +++ b/include/vast/Conversion/Passes.hpp @@ -61,28 +61,6 @@ namespace vast #define GEN_PASS_REGISTRATION #include "vast/Conversion/Passes.h.inc" - // TODO(conv): Define dependencies between these. - static inline void build_abi_pipeline(mlir::PassManager &pm) - { - pm.addPass(createEmitABIPass()); - pm.addPass(createLowerABIPass()); - } - - static inline void build_to_ll_pipeline(mlir::PassManager &pm) - { - pm.addPass(createHLToLLFuncPass()); - pm.addPass(createHLToLLVarsPass()); - pm.addPass(createHLToLLCFPass()); - pm.addPass(createHLEmitLazyRegionsPass()); - pm.addPass(createHLToLLGEPsPass()); - } - - static inline void build_to_llvm_pipeline(mlir::PassManager &pm) - { - pm.addPass(createIRsToLLVMPass()); - pm.addPass(createCoreToLLVMPass()); - } - namespace conv::pipeline { pipeline_step_ptr abi();