Skip to content

Commit

Permalink
Merge front and back end.
Browse files Browse the repository at this point in the history
There are still some unresolved issues regarding node_type_func_decl_dummy.
  • Loading branch information
Snektron committed Nov 8, 2021
1 parent d07e8e8 commit 2497669
Show file tree
Hide file tree
Showing 22 changed files with 1,018 additions and 743 deletions.
4 changes: 2 additions & 2 deletions include/pareas/compiler/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct HostAst {
std::unique_ptr<int32_t[]> node_depths;
std::unique_ptr<int32_t[]> child_indexes;

std::unique_ptr<int32_t[]> fn_tab;
std::unique_ptr<uint32_t[]> fn_tab;

void dump_dot(std::ostream& os) const;
};
Expand All @@ -47,7 +47,7 @@ struct DeviceAst {
futhark_i32_1d* node_depths;
futhark_i32_1d* child_indexes;

futhark_i32_1d* fn_tab;
futhark_u32_1d* fn_tab;

explicit DeviceAst(futhark_context* ctx);

Expand Down
14 changes: 14 additions & 0 deletions include/pareas/compiler/backend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _PAREAS_COMPILER_BACKEND_HPP
#define _PAREAS_COMPILER_BACKEND_HPP

#include "futhark_generated.h"

#include "pareas/compiler/ast.hpp"
#include "pareas/compiler/module.hpp"
#include "pareas/profiler/profiler.hpp"

namespace backend {
DeviceModule compile(futhark_context* ctx, DeviceAst& ast, pareas::Profiler& p);
}

#endif
12 changes: 12 additions & 0 deletions include/pareas/compiler/futhark_interop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ namespace futhark {
using UniqueParseTable = UniqueOpaqueArray<futhark_opaque_parse_table, futhark_free_opaque_parse_table>;
using UniqueStackChangeTable = UniqueOpaqueArray<futhark_opaque_stack_change_table, futhark_free_opaque_stack_change_table>;
using UniqueTokenArray = UniqueOpaqueArray<futhark_opaque_arr_token_1d, futhark_free_opaque_arr_token_1d>;
using UniqueTree = UniqueOpaqueArray<futhark_opaque_Tree, futhark_free_opaque_Tree>;
using UniqueFuncInfoArray = UniqueOpaqueArray<futhark_opaque_arr_FuncInfo_1d, futhark_free_opaque_arr_FuncInfo_1d>;
using UniqueInstrArray = UniqueOpaqueArray<futhark_opaque_arr_Instr_1d, futhark_free_opaque_arr_Instr_1d>;

template <typename T, size_t N>
struct ArrayTraits;
Expand Down Expand Up @@ -165,6 +168,15 @@ namespace futhark {
}
};

template <>
struct ArrayTraits<bool, 1> {
using Array = futhark_bool_1d;
constexpr static const auto new_fn = futhark_new_bool_1d;
constexpr static const auto free_fn = futhark_free_bool_1d;
constexpr static const auto shape_fn = futhark_shape_bool_1d;
constexpr static const auto values_fn = futhark_values_bool_1d;
};

template <>
struct ArrayTraits<uint8_t, 1> {
using Array = futhark_u8_1d;
Expand Down
27 changes: 27 additions & 0 deletions include/pareas/compiler/module.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _PAREAS_COMPILER_MODULE_HPP
#define _PAREAS_COMPILER_MODULE_HPP

#include "futhark_generated.h"

#include <cstdint>

struct DeviceModule {
futhark_context* ctx;

futhark_u32_1d* func_id;
futhark_u32_1d* func_start;
futhark_u32_1d* func_size;
futhark_u32_1d* instructions;

explicit DeviceModule(futhark_context* ctx);

DeviceModule(const DeviceModule&) = delete;
DeviceModule& operator=(const DeviceModule&) = delete;

DeviceModule(DeviceModule&& other);
DeviceModule& operator=(DeviceModule&& other);

~DeviceModule();
};

#endif
15 changes: 14 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ grammar_asm = grammar[3]
futhark_sources = [
'lib/github.com/diku-dk/sorts/radix_sort.fut',
'lib/github.com/diku-dk/segmented/segmented.fut',
'src/compiler/main.fut',
'src/compiler/string.fut',
'src/compiler/util.fut',
'src/compiler/datatypes.fut',
'src/compiler/frontend.fut',
'src/compiler/backend.fut',
'src/compiler/bridge.fut',
'src/compiler/lexer/lexer.fut',
'src/compiler/parser/binary_tree.fut',
'src/compiler/parser/bracket_matching.fut',
Expand All @@ -123,6 +126,14 @@ futhark_sources = [
'src/compiler/passes/type_resolution.fut',
'src/compiler/passes/check_return_paths.fut',
'src/compiler/passes/ids.fut',
'src/compiler/codegen/datatypes.fut',
'src/compiler/codegen/instr.fut',
'src/compiler/codegen/instr_count.fut',
'src/compiler/codegen/optimizer.fut',
'src/compiler/codegen/postprocess.fut',
'src/compiler/codegen/preprocess.fut',
'src/compiler/codegen/register.fut',
'src/compiler/codegen/tree.fut',
]

futhark_compile_command = [
Expand All @@ -131,7 +142,7 @@ futhark_compile_command = [
'--futhark-backend', futhark_backend,
'--output', '@OUTDIR@/futhark_generated',
'--dir', '@PRIVATE_DIR@',
'--main', 'src/compiler/frontend.fut',
'--main', 'src/compiler/main.fut',
]

inputs = []
Expand All @@ -157,6 +168,8 @@ sources = files(
'src/compiler/main.cpp',
'src/compiler/frontend.cpp',
'src/compiler/ast.cpp',
'src/compiler/module.cpp',
'src/compiler/backend.cpp',
)

pareas_exe = executable(
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ DeviceAst::~DeviceAst() {
futhark_free_i32_1d(this->ctx, this->child_indexes);

if (this->fn_tab)
futhark_free_i32_1d(this->ctx, this->fn_tab);
futhark_free_u32_1d(this->ctx, this->fn_tab);
}

size_t DeviceAst::num_nodes() const {
Expand All @@ -147,7 +147,7 @@ size_t DeviceAst::num_nodes() const {
size_t DeviceAst::num_functions() const {
if (!this->fn_tab)
return 0;
return futhark_shape_i32_1d(this->ctx, this->fn_tab)[0];
return futhark_shape_u32_1d(this->ctx, this->fn_tab)[0];
}

HostAst DeviceAst::download() const {
Expand All @@ -163,7 +163,7 @@ HostAst DeviceAst::download() const {
.data_types = std::make_unique<DataType[]>(num_nodes),
.node_depths = std::make_unique<int32_t[]>(num_nodes),
.child_indexes = std::make_unique<int32_t[]>(num_nodes),
.fn_tab = std::make_unique<int32_t[]>(num_functions)
.fn_tab = std::make_unique<uint32_t[]>(num_functions)
};

int err = futhark_values_u8_1d(
Expand All @@ -184,7 +184,7 @@ HostAst DeviceAst::download() const {
err |= futhark_values_i32_1d(this->ctx, this->node_depths, ast.node_depths.get());
err |= futhark_values_i32_1d(this->ctx, this->child_indexes, ast.child_indexes.get());

err |= futhark_values_i32_1d(this->ctx, this->fn_tab, ast.fn_tab.get());
err |= futhark_values_u32_1d(this->ctx, this->fn_tab, ast.fn_tab.get());

if (err)
throw futhark::Error(this->ctx);
Expand Down
Loading

0 comments on commit 2497669

Please sign in to comment.