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

Upgrade brutus to LLVM 14 #27

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 2 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-18.04]
julia-repository: [JuliaLang/julia]
julia-commit: [f3e3554910a79fa38d5662d14abe04e137075e18] # Julia 1.8-dev
llvm-commit: [4743f8ded72e15f916fa1d4cc198bdfd7bfb2193] # LLVM 13.0.1-0
julia-repository: [JuliaLabs/julia-mlir]
julia-commit: [581269b6e2366738eab09bda2a632fce755e4e43] # Julia 1.8-dev

env:
CCACHE_DIR: ${GITHUB_WORKSPACE}/.ccache
Expand Down Expand Up @@ -64,10 +63,8 @@ jobs:
cd julia
make -j `nproc` \
USE_BINARYBUILDER_LLVM=0 \
DEPS_GIT=1 \
LLVM_DEBUG=0 \
USE_MLIR=1 \
LLVM_SHA1=${{ matrix.llvm-commit }} \
JULIA_CPU_TARGET="generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)"

- name: Check Julia version
Expand Down
21 changes: 6 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
cmake_minimum_required(VERSION 3.10)

if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
cmake_minimum_required(VERSION 3.13.4)
project(brutus)

if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)

if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()

project(brutus)
set(BRUTUS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")

find_package(MLIR REQUIRED CONFIG)

Expand All @@ -25,6 +14,8 @@ set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})

set(BRUTUS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${BRUTUS_SOURCE_DIR}/cmake/modules")
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ _Brutus_
`Brutus` currently requires that you create a non-standard build of Julia.

```
export LLVM_SHA1=4743f8ded72e15f916fa1d4cc198bdfd7bfb2193 # LLVM 13.0.1-0
export JULIA_SHA1=6c16f717f9871401eed9350f36cd84ab51778b72 # Julia 1.8-dev

git clone https://github.com/JuliaLabs/brutus
cd brutus
git clone https://github.com/JuliaLang/julia
git clone https://github.com/JuliaLabs/julia-mlir
cd julia
git checkout ${JULIA_SHA1}
git checkout staging
make -j `nproc` \
USE_BINARYBUILDER_LLVM=0 \
DEPS_GIT=1 \
LLVM_DEBUG=0 \
USE_MLIR=1 \
LLVM_SHA1="${LLVM_SHA1}"
cd ..
mkdir build && cd build
cmake .. -G Ninja \
Expand Down
24 changes: 24 additions & 0 deletions include/brutus-c/Dialects.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- Dialects.h - CAPI for dialects -----------------------------*- C -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef BRUTUS_C_DIALECTS_H
#define BRUTUS_C_DIALECTS_H

#include "mlir-c/Registration.h"

#ifdef __cplusplus
extern "C" {
#endif

MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(JLIR, jlir);

#ifdef __cplusplus
}
#endif

#endif // BRUTUS_C_DIALECTS_H
2 changes: 1 addition & 1 deletion include/brutus/Conversion/JLIRToStandard/JLIRToStandard.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct JLIRToStandardTypeConverter : public TypeConverter {
/// conversion patterns capture the LLVMTypeConverter and the LowerToLLVMOptions
/// by reference meaning the references have to remain alive during the entire
/// pattern lifetime.
void populateJLIRToStdConversionPatterns(OwningRewritePatternList &patterns,
void populateJLIRToStdConversionPatterns(RewritePatternSet &patterns,
MLIRContext &context,
JLIRToStandardTypeConverter &converter);

Expand Down
23 changes: 12 additions & 11 deletions include/brutus/Dialect/Julia/JuliaOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define JULIA_MLIR_JLIR_TD

include "mlir/IR/OpBase.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"

// Provide a definition of the 'JLIR' dialect in the ODS framework so that we
Expand Down Expand Up @@ -37,25 +38,25 @@ def JLIR_IsJLArrayTypePred : CPred<"jl_is_array_type($_self.cast<JuliaType>().ge
// * The parent dialect of the operation.
// * The mnemonic for the operation, or the name without the dialect prefix.
// * A list of traits for the operation.
class JLIR_Op<string mnemonic, list<OpTrait> traits = []> :
class JLIR_Op<string mnemonic, list<Trait> traits = []> :
Op<JLIR_Dialect, mnemonic, traits>;

// Base clase for JLIR intrinsics
class JLIR_IntrinsicBuiltinOp<string mnemonic, list<OpTrait> traits = []> :
class JLIR_IntrinsicBuiltinOp<string mnemonic, list<Trait> traits = []> :
JLIR_Op<mnemonic, traits> {

let arguments = (ins Variadic<JLIR_JuliaType>:$arguments);
let results = (outs JLIR_JuliaType);
}

class JLIR_ArithmeticOp<string mnemonic, list<OpTrait> traits = []>:
class JLIR_ArithmeticOp<string mnemonic, list<Trait> traits = []>:
JLIR_IntrinsicBuiltinOp<mnemonic, !listconcat([NoSideEffect, SameOperandsAndResultType], traits)> {

let arguments = (ins JLIR_JuliaType:$rhs, JLIR_JuliaType:$lhs);
let results = (outs JLIR_JuliaType);
}

class JLIR_UnaryArithmeticOp<string mnemonic, list<OpTrait> traits = []>:
class JLIR_UnaryArithmeticOp<string mnemonic, list<Trait> traits = []>:
JLIR_IntrinsicBuiltinOp<mnemonic, !listconcat([NoSideEffect, SameOperandsAndResultType], traits)> {

let arguments = (ins JLIR_JuliaType:$arg);
Expand Down Expand Up @@ -140,11 +141,11 @@ def InvokeOp : JLIR_Op<"invoke"> {
let arguments = (ins JLIR_JuliaValueAttr:$methodInstance,
JLIR_JuliaType:$callee,
Variadic<JLIR_JuliaType>:$arguments);

let results = (outs JLIR_JuliaType);

let builders = [
OpBuilder<(ins "jl_method_instance_t *":$methodInstance,
OpBuilder<(ins "jl_method_instance_t *":$methodInstance,
"Value":$callee,
"ArrayRef<Value>":$arguments,
"jl_datatype_t *":$type)>
Expand Down Expand Up @@ -174,15 +175,15 @@ def GotoIfNotOp : JLIR_Op<"gotoifnot", [AttrSizedOperandSegments, Terminator]> {
let arguments = (ins JLIR_JuliaType:$condition,
Variadic<JLIR_JuliaType>:$branchOperands,
Variadic<JLIR_JuliaType>:$fallthroughOperands);
let successors = (successor AnySuccessor:$branchDest,

let successors = (successor AnySuccessor:$branchDest,
AnySuccessor:$fallthroughDest);

let builders = [
OpBuilder<(ins "Value":$condition,
"Block *":$branchDest,
"Block *":$branchDest,
"ValueRange":$branchOperands,
"Block *":$fallthroughDest,
"Block *":$fallthroughDest,
"ValueRange":$fallthroughOperands),
[{
build($_builder, $_state, condition,
Expand Down
5 changes: 5 additions & 0 deletions lib/CAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_mlir_public_c_api_library(BRUTUSCAPI
Dialects.cpp
LINK_LIBS PUBLIC
MLIRJulia
)
16 changes: 16 additions & 0 deletions lib/CAPI/Dialects.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

//===- Dialects.cpp - CAPI for dialects -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "brutus-c/Dialects.h"

#include "brutus/Dialect/Julia/JuliaOps.h"
#include "mlir/CAPI/Registration.h"

MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(JLIR, jlir,
mlir::jlir::JLIRDialect)
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(Codegen)
add_subdirectory(Conversion)
add_subdirectory(Dialect)
add_subdirectory(CAPI)
12 changes: 8 additions & 4 deletions lib/Codegen/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mlir::FuncOp emit_function(jl_mlirctx_t &ctx,
if (fname.empty())
fname = "macro expansion";
assert(inlined_at <= i);
mlir::Location current = mlir::NameLoc::get(mlir::Identifier::get(fname, ctx.context),
mlir::Location current = mlir::NameLoc::get(mlir::StringAttr::get(ctx.context, fname),
mlir::FileLineColLoc::get(ctx.context, file, line, 0));

// codegen.cpp uses a better heuristic for now just live with this
Expand Down Expand Up @@ -327,7 +327,8 @@ mlir::FuncOp emit_function(jl_mlirctx_t &ctx,
bool found = false;
for (int edge = 0; edge < nedges; ++edge)
{
int frombb = jl_unbox_long(jl_arrayref(edges, edge)); // frombb is 1-indexed
// Julia 1.9 PhiNode -> Int32[]
int frombb = jl_unbox_int32(jl_arrayref(edges, edge)); // frombb is 1-indexed
if (frombb == current_block)
{
mlir::Value value =
Expand Down Expand Up @@ -416,7 +417,10 @@ mlir::FuncOp emit_function(jl_mlirctx_t &ctx,
else if (jl_is_phinode(stmt))
{
// add argument slot to current_block
auto arg = bbs[current_block]->addArgument((mlir::Type)JuliaType::get(ctx.context, type));
auto arg = bbs[current_block]->addArgument(
(mlir::Type)JuliaType::get(ctx.context, type),
loc
);
// add argument reference to values
ctx.values[i] = arg;
}
Expand Down Expand Up @@ -619,7 +623,7 @@ extern "C"

std::string cabi_name = "ciface_" + name;
ExecutionEngine *engine = expectedEngine.get().release();
auto expectedFPtr = engine->lookup(cabi_name);
auto expectedFPtr = engine->lookupPacked(cabi_name);
if (!expectedFPtr)
{
handleLLVMError(expectedFPtr.takeError());
Expand Down
Loading