Skip to content

Commit

Permalink
Update Arc-MLIR to support Arc-Lang v1
Browse files Browse the repository at this point in the history
  • Loading branch information
segeljakt committed Aug 16, 2023
1 parent aa7f604 commit 67d8bf8
Show file tree
Hide file tree
Showing 45 changed files with 16,655 additions and 16,084 deletions.
29 changes: 13 additions & 16 deletions arc-mlir/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(ARC_MLIR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ARC_MLIR_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})

include_directories(../llvm-project/mlir/include/)
include_directories(include/)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../mlir/include/)
Expand All @@ -20,37 +21,33 @@ get_filename_component(ARC_CARGO_BIN "../../bin"
get_filename_component(ARC_TOOLS_BIN_DIR "../../bin"
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE)

get_filename_component(ARC_LANG_SRC_DIR "../../arc-lang"
get_filename_component(ARC_LANG_DIR "../../arc-lang"
REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE)

get_filename_component(ARC_LANG_BUILD_DIR "../../arc-lang/build"
get_filename_component(ARC_LANG_TARGET_DIR "../../arc-lang/target"
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE)

get_filename_component(ARC_RUNTIME_SRC_DIR "../../arc-runtime"
get_filename_component(ARC_RUNTIME_DIR "../../arc-lang/crates/runtime/"
REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE)

get_filename_component(ARC_MLIR_SRC_DIR "../"
get_filename_component(ARC_MLIR_DIR "../"
REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE)

add_custom_target(dune-build ALL
WORKING_DIRECTORY ${ARC_LANG_SRC_DIR}
COMMAND mkdir -p ${ARC_LANG_BUILD_DIR}
COMMAND ${ARC_LANG_SRC_DIR}/dune-wrapper build
--root ${ARC_LANG_SRC_DIR}
--build-dir ${ARC_LANG_BUILD_DIR} src/main.exe
COMMAND mv -f ${ARC_LANG_BUILD_DIR}/default/src/main.exe ${ARC_LANG_EXE}
add_custom_target(arc-lang ALL
COMMAND cargo build --manifest-path=${ARC_LANG_DIR}/Cargo.toml --release --target-dir=${ARC_LANG_TARGET_DIR}
COMMAND mv -f ${ARC_LANG_TARGET_DIR}/release/arc-lang ${ARC_LANG_EXE}
)

add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(tests)
add_subdirectory(tools)

add_custom_target(arc-runtime-check DEPENDS check-arc-mlir
COMMAND cd ${ARC_SCRIPT_SRC_DIR}; ${ARC_CARGO_BIN}/arc-cargo test --package=arc-runtime
add_custom_target(arc-lang-check DEPENDS check-arc-mlir
COMMAND cd ${ARC_LANG_DIR}; ${ARC_CARGO_BIN}/arc-cargo test
)

install(DIRECTORY ${ARC_LANG_SRC_DIR}/stdlib DESTINATION share/arc/)
install(DIRECTORY ${ARC_RUNTIME_SRC_DIR} DESTINATION share/arc/)
install(DIRECTORY ${ARC_LANG_DIR}/stdlib DESTINATION share/arc/)
install(DIRECTORY ${ARC_RUNTIME_DIR} DESTINATION share/arc/)
install(PROGRAMS ${LLVM_TOOLS_BINARY_DIR}/arc DESTINATION bin)
install(PROGRAMS ${LLVM_TOOLS_BINARY_DIR}/arc-lang DESTINATION bin)
4 changes: 2 additions & 2 deletions arc-mlir/src/include/Arc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(MLIR_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/../../../llvm-project/mlir/include/
)

set(LLVM_TARGET_DEFINITIONS ${ARC_MLIR_SOURCE_DIR}/include/Arc/Arc.td)
set(LLVM_TARGET_DEFINITIONS ${ARC_MLIR_SRC_DIR}/include/Arc/Arc.td)
set(TBLGEN_INCDIRS "-I${CMAKE_CURRENT_SOURCE_DIR}/../../../llvm-project/mlir/include/")

mlir_tablegen(ArcOps.h.inc -gen-op-decls)
Expand All @@ -15,7 +15,7 @@ mlir_tablegen(ArcOpsEnums.cpp.inc -gen-enum-defs)

add_public_tablegen_target(ArcDialectOpsEnumsIncGen)

set(LLVM_TARGET_DEFINITIONS ${ARC_MLIR_SOURCE_DIR}/include/Arc/Opts.td)
set(LLVM_TARGET_DEFINITIONS ${ARC_MLIR_SRC_DIR}/include/Arc/Opts.td)
set(TBLGEN_INCDIRS "-I${CMAKE_CURRENT_SOURCE_DIR}/../../../llvm-project/mlir/include/")
mlir_tablegen(ArcOpts.h.inc -gen-rewriters ${TBLGEN_INCDIRS} "-I${CMAKE_CURRENT_SOURCE_DIR}/include")
add_public_tablegen_target(ArcDialectOptsIncGen)
Expand Down
2 changes: 1 addition & 1 deletion arc-mlir/src/include/Rust/Rust.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ LogicalResult writeModuleAsInline(ModuleOp module, llvm::raw_ostream &o);
/// A single place to define the versions for the external crates
/// used by the Rust code generated by the backend.
struct CrateVersions {
static const char *ndarray;

};

bool isRustFunctionType(Type type);
Expand Down
21 changes: 0 additions & 21 deletions arc-mlir/src/include/Rust/Rust.td
Original file line number Diff line number Diff line change
Expand Up @@ -513,27 +513,6 @@ def Rust_RustBinaryOp : Rust_Op<"binaryop", [SameTypeOperands]> {
}];
}

def Rust_RustBinaryRcOp : Rust_Op<"binaryrcop", [SameTypeOperands]> {
let summary = "a Rust binary operation operating on a Rc value.";
let description = [{
A Rust binary operation, the op attribute is the string representation of
the operator in Rust syntax. The operands will be dereferenced and the
result wrapped in a Rc.
}];

let arguments = (ins StrAttr : $op, AnyRustType : $LHS, AnyRustType : $RHS);
let results = (outs AnyRustType);

let extraClassDeclaration = [{
StringRef getOperator() {
return (*this)->getAttrOfType<StringAttr>("op").getValue();
}

// Write this operation as Rust code to the stream
void writeRust(RustPrinterStream &);
}];
}

def Rust_RustCompOp : Rust_Op<"compop", [SameTypeOperands]> {
let summary = "a Rust comparison operation.";
let description = [{
Expand Down
48 changes: 5 additions & 43 deletions arc-mlir/src/include/Rust/RustPrinterStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,53 +84,15 @@ class RustPrinterStream {
Includefile(includefile){};

void flush(llvm::raw_ostream &o) {
o << "#![allow(non_snake_case)]\n"
<< "#![allow(unused_must_use)]\n"
<< "#![allow(non_camel_case_types)]"
<< "#![allow(dead_code)]\n"
<< "#![allow(unused_variables)]\n"
<< "#![allow(unused_imports)]\n"
<< "#![allow(unused_braces)]\n"
o << "#![allow(unused)]\n"
<< "#![allow(non_snake_case)]\n"
<< "#![allow(non_camel_case_types)]\n";

o << "pub mod " << ModuleName
<< "{\n"
"use super::*;\n"
"pub use arc_runtime::prelude::*;\n";

o << "pub use hexf::*;\n";

if (!DeclaredFunctions.empty() || !DeclaredTasks.empty()) {
o << "declare!(";
o << "functions: [ ";
for (Operation *t : DeclaredFunctions) {
if (t->hasAttr("arc.rust_name"))
o << t->getAttrOfType<StringAttr>("arc.rust_name").getValue();
else
o << t->getAttrOfType<StringAttr>("sym_name").getValue();
o << ", ";
}
o << "],";
o << "tasks: [ ";
for (RustFuncOp &t : DeclaredTasks) {
if (t->hasAttr("arc.rust_name"))
o << t->getAttrOfType<StringAttr>("arc.rust_name").getValue();
else
o << t->getAttrOfType<StringAttr>("sym_name").getValue();
o << "(";
unsigned numFuncArguments = t.getNumArguments();
for (unsigned i = 0; i < numFuncArguments; i++) {
Value v = t.front().getArgument(i);
if (i != 0)
o << ", ";
o << "v" << std::to_string(Value2ID[v]) << ": ";
printType(o, v.getType());
}
o << "), ";
}
o << "]";
o << ");\n";
}
"pub use runtime::prelude::*;\n"
"pub use hexf::*;\n";

for (auto i : CrateDirectives)
o << i.second << "\n";
Expand Down Expand Up @@ -180,7 +142,7 @@ class RustPrinterStream {
if (id < 0)
return "C" + std::to_string(-id);
else
return "val!(v" + std::to_string(id) + ")";
return "v" + std::to_string(id) + ".clone()";
}

std::string getConstant(RustConstantOp v);
Expand Down
Loading

0 comments on commit 67d8bf8

Please sign in to comment.