Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement configurable codegen pipelines #458

Merged
merged 37 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
61e96c0
cc: Introduce CIR target dialect.
xlauko Nov 20, 2023
da7c731
hl: Obliterate canonicalize pass.
xlauko Nov 27, 2023
9273062
util: Implement pipeline wrappers.
xlauko Nov 27, 2023
6dbd967
hl: Setup canonicalize pipeline.
xlauko Nov 27, 2023
9a2f835
cc: Specify default pipelines config.
xlauko Nov 27, 2023
811031b
cc: Simplify optional list options.
xlauko Nov 27, 2023
7f27af3
util: Add pipelines initializer state.
xlauko Nov 27, 2023
9b465e5
hl: Setup more conversion pipelines.
xlauko Nov 27, 2023
fb06c33
cc: Update pipelines config.
xlauko Nov 27, 2023
1a3a35c
util: Simplify pipeline constructors.
xlauko Nov 27, 2023
13b1a99
hl: Update pipelines to simplified form.
xlauko Nov 27, 2023
f675bbc
cc: Refactor target dialects.
xlauko Nov 27, 2023
7bd89d1
cc: Move output types to targets.
xlauko Dec 5, 2023
ca5a1f5
util: Add better pipeline chaining.
xlauko Dec 5, 2023
bfd2b9c
cc: Implement pipeline builder.
xlauko Dec 5, 2023
97d6299
treewide: Integrate default pipeline.
xlauko Dec 7, 2023
8868f88
conv: Setup conversion pipelines.
xlauko Dec 11, 2023
7a8f378
cc: Fix pipeline steps lifetimes.
xlauko Dec 11, 2023
46dfd37
cc: Do not run simplification when not requested.
xlauko Dec 11, 2023
1b67068
cc: Remove obsolete high level pass.
xlauko Dec 11, 2023
a20f2e6
cc: Remove obsolete abi pipeline interface.
xlauko Dec 11, 2023
03fb74a
cc: Add vast-debug option.
xlauko Dec 13, 2023
e97cff4
treewide: Fix unreachable to more appropriate macros.
xlauko Jan 23, 2024
5fba8cf
cc: Add option to print vast pipeline.
xlauko Jan 23, 2024
c828e70
cc: Add option to produce minimal crash reports and disable multithre…
xlauko Jan 23, 2024
e015502
docs: Add description of some debug options.
xlauko Jan 23, 2024
033b672
www: Add debug section.
xlauko Jan 23, 2024
871fc56
conv: Fix core conversion dependencies.
xlauko Jan 23, 2024
1e3cdda
util: Allow nested pipelines.
xlauko Jan 24, 2024
785f605
conv: Fix debug scope pipeline type to be nested.
xlauko Jan 24, 2024
09f013c
conv: Add dependency to irs to llvm pipeline.
xlauko Jan 24, 2024
50c535a
cc: Refactor mlir pipeline to be used in any workflow.
xlauko Jan 24, 2024
e040c60
cc: Add abi to standard pipeline.
xlauko Jan 25, 2024
cb8aacf
test: Make some tests runner independent.
xlauko Jan 25, 2024
bdf5943
test: Turn off tests failing after abi pass.
xlauko Jan 25, 2024
8ac6ca9
hl: Remove obsolete pipelines definitions.
xlauko Jan 25, 2024
57ec541
conv: Remove obsolete pipelines definitions.
xlauko Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/GettingStarted/debug.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion include/vast/CodeGen/CodeGen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion include/vast/CodeGen/CodeGenContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 += "::";
Expand Down
10 changes: 5 additions & 5 deletions include/vast/CodeGen/CodeGenDeclVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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");
}

//
Expand Down
2 changes: 1 addition & 1 deletion include/vast/CodeGen/CodeGenStmtVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions include/vast/CodeGen/Passes.hpp

This file was deleted.

10 changes: 5 additions & 5 deletions include/vast/CodeGen/UnreachableVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};

Expand Down
30 changes: 11 additions & 19 deletions include/vast/Conversion/Passes.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Conversion/Passes.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on include/vast/Conversion/Passes.hpp

File include/vast/Conversion/Passes.hpp does not conform to Custom style guidelines. (lines 64)

#pragma once

Expand All @@ -20,6 +20,8 @@
#include <vast/Dialect/Core/CoreDialect.hpp>
#include <vast/Dialect/ABI/ABIDialect.hpp>

#include <vast/Util/Pipeline.hpp>

#include <memory>

namespace vast
Expand Down Expand Up @@ -59,26 +61,16 @@
#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)
namespace conv::pipeline
{
pm.addPass(createEmitABIPass());
pm.addPass(createLowerABIPass());
}
pipeline_step_ptr abi();
pipeline_step_ptr irs_to_llvm();
pipeline_step_ptr core_to_llvm();

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());
}
pipeline_step_ptr to_ll();

pipeline_step_ptr to_llvm();

} // namespace conv::pipeline

} // namespace vast
2 changes: 1 addition & 1 deletion include/vast/Conversion/TypeConverters/HLToStd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/HighLevel/HighLevelTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
27 changes: 13 additions & 14 deletions include/vast/Dialect/HighLevel/Passes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ VAST_RELAX_WARNINGS
VAST_UNRELAX_WARNINGS

#include <vast/Dialect/HighLevel/HighLevelDialect.hpp>
#include <vast/Util/Pipeline.hpp>

#include <memory>

namespace vast::hl
{
namespace vast::hl {
std::unique_ptr< mlir::Pass > createHLLowerTypesPass();

std::unique_ptr< mlir::Pass > createExportFnInfoPass();
Expand All @@ -25,20 +26,18 @@ namespace vast::hl

std::unique_ptr< mlir::Pass > createSpliceTrailingScopes();

std::unique_ptr< mlir::Pass > createHLCanonicalizePass();
/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "vast/Dialect/HighLevel/Passes.h.inc"

namespace pipeline {
pipeline_step_ptr canonicalize();

void registerHLToLLVMIR(mlir::DialectRegistry &);
void registerHLToLLVMIR(mlir::MLIRContext &);
pipeline_step_ptr desugar();

/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "vast/Dialect/HighLevel/Passes.h.inc"
pipeline_step_ptr simplify();

static inline void build_simplify_hl_pipeline(mlir::PassManager &pm)
{
pm.addPass(createHLLowerTypesPass());
pm.addPass(createDCEPass());
pm.addPass(createLowerTypeDefsPass());
}
pipeline_step_ptr stdtypes();
} // namespace pipeline

} // namespace vast::hl
13 changes: 0 additions & 13 deletions include/vast/Dialect/HighLevel/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/vast/Frontend/Action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions include/vast/Frontend/Consumer.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Frontend/Consumer.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on include/vast/Frontend/Consumer.hpp

File include/vast/Frontend/Consumer.hpp does not conform to Custom style guidelines. (lines 101, 102)

#pragma once

Expand All @@ -12,6 +12,7 @@
#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"
Expand All @@ -22,9 +23,6 @@

using clang_ast_consumer = clang::ASTConsumer;

// TODO: Introduce helper wrapper on top of `vast_args`?
enum class target_dialect { high_level, low_level, llvm };

using backend = clang::BackendAction;

struct vast_consumer : clang_ast_consumer
Expand Down Expand Up @@ -63,8 +61,6 @@

protected:

void compile_via_vast(vast_module mod, mcontext_t *mctx);

virtual void anchor() {}

action_options opts;
Expand Down Expand Up @@ -102,6 +98,10 @@
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;
};
Expand Down
8 changes: 0 additions & 8 deletions include/vast/Frontend/FrontendAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
15 changes: 9 additions & 6 deletions include/vast/Frontend/Options.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Frontend/Options.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on include/vast/Frontend/Options.hpp

File include/vast/Frontend/Options.hpp does not conform to Custom style guidelines. (lines 75, 79, 83)

#pragma once

Expand Down Expand Up @@ -47,7 +47,6 @@
struct vast_args
{
using option_list = std::vector< string_ref >;
using maybe_option_list = std::optional< option_list >;

argv_storage args;

Expand All @@ -60,7 +59,7 @@
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);
};
Expand All @@ -71,14 +70,18 @@
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 show_locs = "show-locs";
constexpr string_ref locs_as_meta_ids = "locs-as-meta-ids";
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 opt_pipeline = "pipeline";
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 disable_vast_verifier = "disable-vast-verifier";
constexpr string_ref vast_verify_diags = "verify-diags";
Expand Down
Loading
Loading