Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ jobs:
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 20
sudo ./llvm.sh 21
rm llvm.sh

sudo apt-get install -y libmlir-20-dev mlir-20-tools
sudo apt-get install -y libmlir-21-dev mlir-21-tools

- name: Install unit tests requirements
run: |
Expand All @@ -86,7 +86,7 @@ jobs:
run: |
. .venv/bin/activate

PATH=/usr/lib/llvm-20/bin:$PATH
PATH=/usr/lib/llvm-21/bin:$PATH

cmake --preset default-mlir

Expand Down
13 changes: 11 additions & 2 deletions scripts/build-mlir.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async function main() {
"-DCMAKE_CXX_FLAGS=-DLLVM_BUILD_STATIC",
"-DCMAKE_EXE_LINKER_FLAGS=-sNODERAWFS -sEXIT_RUNTIME -sALLOW_MEMORY_GROWTH",
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
"-DCMAKE_CXX_FLAGS=-Wno-c2y-extensions",
"-DLLVM_BUILD_EXTERNAL_COMPILER_RT=OFF",
"-DLLVM_BUILD_TOOLS=OFF",
"-DLLVM_ENABLE_EH=OFF",
Expand All @@ -81,11 +82,12 @@ async function main() {
"-DLLVM_ENABLE_RTTI=OFF",
"-DLLVM_ENABLE_RUNTIMES=",
"-DLLVM_ENABLE_Z3_SOLVER=OFF",
"-DLLVM_ENABLE_WERROR=OFF",
"-DLLVM_INCLUDE_DOCS=OFF",
"-DLLVM_INCLUDE_TESTS=OFF",
"-DLLVM_INSTALL_UTILS=OFF",
"-DLLVM_LINK_LLVM_DYLIB=OFF",
"-DLLVM_OPTIMIZED_TABLEGEN=OFF",
"-DLLVM_OPTIMIZED_TABLEGEN=ON",
"-DLLVM_TARGETS_TO_BUILD=WebAssembly",
];

Expand Down Expand Up @@ -164,4 +166,11 @@ require("./${app}.js");`
}
}

await await main();
main().catch((err) => {
if (err instanceof Error) {
console.error(err.message);
} else {
console.error(err);
}
process.exit(1);
});
8 changes: 4 additions & 4 deletions src/frontend/cxx/frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,14 @@ void Frontend::Private::emitCode() {
#ifdef CXX_WITH_MLIR
llvm::InitializeAllAsmPrinters();

auto triple = toolchain_->memoryLayout()->triple();
auto triple = llvm::Triple{toolchain_->memoryLayout()->triple()};

std::string error;
auto target = llvm::TargetRegistry::lookupTarget(triple, error);

if (!target) {
std::cerr << std::format("cxx: cannot find target for triple '{}': {}\n",
triple, error);
triple.getTriple(), error);
shouldExit_ = true;
exitStatus_ = EXIT_FAILURE;
return;
Expand All @@ -567,11 +567,11 @@ void Frontend::Private::emitCode() {
auto RM = std::optional<llvm::Reloc::Model>();

auto targetMachine =
target->createTargetMachine(triple, "generic", "", opt, RM);
target->createTargetMachine(llvm::Triple{triple}, "generic", "", opt, RM);

if (!targetMachine) {
std::cerr << std::format("cxx: cannot create target machine for '{}': {}\n",
triple, error);
triple.getTriple(), error);
shouldExit_ = true;
exitStatus_ = EXIT_FAILURE;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ endif()

find_package(MLIR REQUIRED CONFIG)

if (MLIR_VERSION VERSION_LESS "20.0")
message(FATAL_ERROR "MLIR >= 20.0 is required")
if (MLIR_VERSION VERSION_LESS "21.0")
message(FATAL_ERROR "MLIR >= 21.0 is required")
endif()

LIST(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}" "${LLVM_CMAKE_DIR}")
Expand Down
6 changes: 6 additions & 0 deletions src/mlir/cxx/mlir/CxxOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def Cxx_MemberOp : Cxx_Op<"member"> {
let results = (outs Cxx_PointerType:$result);
}

def Cxx_PtrAddOp : Cxx_Op<"ptr_add"> {
let arguments = (ins Cxx_PointerType:$base, Cxx_IntegerType:$offset);

let results = (outs Cxx_PointerType:$result);
}

def Cxx_AddressOfOp : Cxx_Op<"addressof"> {
let arguments = (ins FlatSymbolRefAttr:$sym_name);

Expand Down
8 changes: 8 additions & 0 deletions src/mlir/cxx/mlir/codegen_expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ auto Codegen::ExpressionVisitor::operator()(SubscriptExpressionAST* ast)

auto resultType = gen.convertType(control()->add_pointer(ast->type));

if (control()->is_pointer(ast->baseExpression->type)) {
auto op = gen.builder_.create<mlir::cxx::PtrAddOp>(
loc, resultType, baseExpressionResult.value,
indexExpressionResult.value);

return {op};
}

auto op = gen.builder_.create<mlir::cxx::SubscriptOp>(
loc, resultType, baseExpressionResult.value, indexExpressionResult.value);

Expand Down
4 changes: 2 additions & 2 deletions src/mlir/cxx/mlir/codegen_units.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ auto Codegen::UnitVisitor::operator()(TranslationUnitAST* ast) -> UnitResult {

auto memoryLayout = gen.control()->memoryLayout();

auto triple = gen.control()->memoryLayout()->triple();
auto triple = llvm::Triple{gen.control()->memoryLayout()->triple()};

std::string error;
auto target = llvm::TargetRegistry::lookupTarget(triple, error);

if (!target) {
cxx_runtime_error(std::format("failed to find target for triple '{}': {}",
triple, error));
triple.getTriple(), error));
}

llvm::TargetOptions opt;
Expand Down
Loading