Skip to content

Commit

Permalink
Update to LLVM commit c13b7485b87909fcf739f62cfa382b55407433c0 (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
github-actions[bot] and github-actions authored Apr 12, 2024
1 parent c29a66e commit 65de7a3
Show file tree
Hide file tree
Showing 32 changed files with 378 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
LLVM_COMMIT=18ddebe1a1a9bde349441631365f0472e9693520
LLVM_COMMIT=c13b7485b87909fcf739f62cfa382b55407433c0
CMAKE_FLAGS='-DCMAKE_LINKER=lld -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DMLIR_DIR=$GITHUB_WORKSPACE/llvm-project/prefix/lib/cmake/mlir/ -DLLVM_DIR=$GITHUB_WORKSPACE/llvm-project/prefix/lib/cmake/llvm/ -DLLVM_EXTERNAL_LIT=$GITHUB_WORKSPACE/llvm-project/build/bin/llvm-lit'
LLVM_REF=refs/tags/llvmorg-16.0.2
LLVM_REF=refs/tags/llvmorg-18.1.3
48 changes: 30 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
cmake_minimum_required(VERSION 3.13.4)
cmake_minimum_required(VERSION 3.20.0)
project(standalone-dialect LANGUAGES CXX C)

set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)

set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")

find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

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})

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

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})

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")

include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
else()
# Build via external projects mechanism
set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir)
set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include)
set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}")
endif()

if(MLIR_ENABLE_BINDINGS_PYTHON)
include(MLIRDetectPythonEnv)
mlir_configure_python_dev_packages()
endif()

set(STANDALONE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(STANDALONE_BINARY_DIR ${PROJECT_BINARY_DIR})
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_BINARY_DIR}/include)
include_directories(${STANDALONE_SOURCE_DIR}/include)
include_directories(${STANDALONE_BINARY_DIR}/include)
link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS})

Expand All @@ -41,4 +52,5 @@ if(MLIR_ENABLE_BINDINGS_PYTHON)
endif()
add_subdirectory(test)
add_subdirectory(standalone-opt)
add_subdirectory(standalone-plugin)
add_subdirectory(standalone-translate)
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is an example of an out-of-tree [MLIR](https://mlir.llvm.org/) dialect along with a standalone `opt`-like tool to operate on that dialect.

## Building
## Building - Component Build

This setup assumes that you have built LLVM and MLIR in `$BUILD_DIR` and installed them to `$PREFIX`. To build and launch the tests, run
```sh
Expand All @@ -16,3 +16,17 @@ cmake --build . --target mlir-doc
```
**Note**: Make sure to pass `-DLLVM_INSTALL_UTILS=ON` when building LLVM with CMake in order to install `FileCheck` to the chosen installation prefix.

## Building - Monolithic Build

This setup assumes that you build the project as part of a monolithic LLVM build via the `LLVM_EXTERNAL_PROJECTS` mechanism.
To build LLVM, MLIR, the example and launch the tests run
```sh
mkdir build && cd build
cmake -G Ninja `$LLVM_SRC_DIR/llvm` \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD=host \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_EXTERNAL_PROJECTS=standalone-dialect -DLLVM_EXTERNAL_STANDALONE_DIALECT_SOURCE_DIR=../
cmake --build . --target check-standalone
```
Here, `$LLVM_SRC_DIR` needs to point to the root of the monorepo.
4 changes: 4 additions & 0 deletions include/Standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
add_mlir_dialect(StandaloneOps standalone)
add_mlir_doc(StandaloneDialect StandaloneDialect Standalone/ -gen-dialect-doc)
add_mlir_doc(StandaloneOps StandaloneOps Standalone/ -gen-op-doc)

set(LLVM_TARGET_DEFINITIONS StandalonePasses.td)
mlir_tablegen(StandalonePasses.h.inc --gen-pass-decls)
add_public_tablegen_target(MLIRStandalonePassesIncGen)
1 change: 1 addition & 0 deletions include/Standalone/StandaloneDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef STANDALONE_STANDALONEDIALECT_H
#define STANDALONE_STANDALONEDIALECT_H

#include "mlir/Bytecode/BytecodeOpInterface.h"
#include "mlir/IR/Dialect.h"

#include "Standalone/StandaloneOpsDialect.h.inc"
Expand Down
5 changes: 5 additions & 0 deletions include/Standalone/StandaloneDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def Standalone_Dialect : Dialect {
working inside of the LLVM source tree.
}];
let cppNamespace = "::mlir::standalone";

let useDefaultTypePrinterParser = 1;
let extraClassDeclaration = [{
void registerTypes();
}];
}

//===----------------------------------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion include/Standalone/StandaloneOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef STANDALONE_OPS
#define STANDALONE_OPS

include "Standalone/StandaloneDialect.td"
include "Standalone/StandaloneTypes.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"

Expand Down
26 changes: 26 additions & 0 deletions include/Standalone/StandalonePasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- StandalonePasses.h - Standalone passes ------------------*- 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 STANDALONE_STANDALONEPASSES_H
#define STANDALONE_STANDALONEPASSES_H

#include "Standalone/StandaloneDialect.h"
#include "Standalone/StandaloneOps.h"
#include "mlir/Pass/Pass.h"
#include <memory>

namespace mlir {
namespace standalone {
#define GEN_PASS_DECL
#include "Standalone/StandalonePasses.h.inc"

#define GEN_PASS_REGISTRATION
#include "Standalone/StandalonePasses.h.inc"
} // namespace standalone
} // namespace mlir

#endif
30 changes: 30 additions & 0 deletions include/Standalone/StandalonePasses.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===- StandalonePsss.td - Standalone dialect passes -------*- tablegen -*-===//
//
// 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 STANDALONE_PASS
#define STANDALONE_PASS

include "mlir/Pass/PassBase.td"

def StandaloneSwitchBarFoo: Pass<"standalone-switch-bar-foo", "::mlir::ModuleOp"> {
let summary = "Switches the name of a FuncOp named `bar` to `foo` and folds.";
let description = [{
Switches the name of a FuncOp named `bar` to `foo` and folds.
```
func.func @bar() {
return
}
// Gets transformed to:
func.func @foo() {
return
}
```
}];
}

#endif // STANDALONE_PASS
17 changes: 17 additions & 0 deletions include/Standalone/StandaloneTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===- StandaloneTypes.h - Standalone dialect types -------------*- 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 STANDALONE_STANDALONETYPES_H
#define STANDALONE_STANDALONETYPES_H

#include "mlir/IR/BuiltinTypes.h"

#define GET_TYPEDEF_CLASSES
#include "Standalone/StandaloneOpsTypes.h.inc"

#endif // STANDALONE_STANDALONETYPES_H
31 changes: 31 additions & 0 deletions include/Standalone/StandaloneTypes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===- StandaloneTypes.td - Standalone dialect types -------*- tablegen -*-===//
//
// 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 STANDALONE_TYPES
#define STANDALONE_TYPES

include "mlir/IR/AttrTypeBase.td"
include "Standalone/StandaloneDialect.td"

//===----------------------------------------------------------------------===//
// Standalone type definitions
//===----------------------------------------------------------------------===//

class Standalone_Type<string name, string typeMnemonic, list<Trait> traits = []>
: TypeDef<Standalone_Dialect, name, traits> {
let mnemonic = typeMnemonic;
}

def Standalone_CustomType : Standalone_Type<"Custom", "custom"> {
let summary = "Standalone custom type";
let description = "Custom type in standalone dialect";
let parameters = (ins StringRefParameter<"the custom value">:$value);
let assemblyFormat = "`<` $value `>`";
}

#endif // STANDALONE_TYPES
10 changes: 7 additions & 3 deletions lib/Standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
add_mlir_dialect_library(MLIRStandalone
StandaloneTypes.cpp
StandaloneDialect.cpp
StandaloneOps.cpp
StandalonePasses.cpp

ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/Standalone

DEPENDS
MLIRStandaloneOpsIncGen
MLIRStandalonePassesIncGen

LINK_LIBS PUBLIC
MLIRIR
LINK_LIBS PUBLIC
MLIRIR
MLIRInferTypeOpInterface
)
MLIRFuncDialect
)
2 changes: 2 additions & 0 deletions lib/Standalone/StandaloneDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "Standalone/StandaloneDialect.h"
#include "Standalone/StandaloneOps.h"
#include "Standalone/StandaloneTypes.h"

using namespace mlir;
using namespace mlir::standalone;
Expand All @@ -23,4 +24,5 @@ void StandaloneDialect::initialize() {
#define GET_OP_LIST
#include "Standalone/StandaloneOps.cpp.inc"
>();
registerTypes();
}
1 change: 0 additions & 1 deletion lib/Standalone/StandaloneOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "Standalone/StandaloneOps.h"
#include "Standalone/StandaloneDialect.h"
#include "mlir/IR/OpImplementation.h"

#define GET_OP_CLASSES
#include "Standalone/StandaloneOps.cpp.inc"
48 changes: 48 additions & 0 deletions lib/Standalone/StandalonePasses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===- StandalonePasses.cpp - Standalone passes -----------------*- 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
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Rewrite/FrozenRewritePatternSet.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

#include "Standalone/StandalonePasses.h"

namespace mlir::standalone {
#define GEN_PASS_DEF_STANDALONESWITCHBARFOO
#include "Standalone/StandalonePasses.h.inc"

namespace {
class StandaloneSwitchBarFooRewriter : public OpRewritePattern<func::FuncOp> {
public:
using OpRewritePattern<func::FuncOp>::OpRewritePattern;
LogicalResult matchAndRewrite(func::FuncOp op,
PatternRewriter &rewriter) const final {
if (op.getSymName() == "bar") {
rewriter.modifyOpInPlace(op, [&op]() { op.setSymName("foo"); });
return success();
}
return failure();
}
};

class StandaloneSwitchBarFoo
: public impl::StandaloneSwitchBarFooBase<StandaloneSwitchBarFoo> {
public:
using impl::StandaloneSwitchBarFooBase<
StandaloneSwitchBarFoo>::StandaloneSwitchBarFooBase;
void runOnOperation() final {
RewritePatternSet patterns(&getContext());
patterns.add<StandaloneSwitchBarFooRewriter>(&getContext());
FrozenRewritePatternSet patternSet(std::move(patterns));
if (failed(applyPatternsAndFoldGreedily(getOperation(), patternSet)))
signalPassFailure();
}
};
} // namespace
} // namespace mlir::standalone
26 changes: 26 additions & 0 deletions lib/Standalone/StandaloneTypes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- StandaloneTypes.cpp - Standalone dialect types -----------*- 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
//
//===----------------------------------------------------------------------===//

#include "Standalone/StandaloneTypes.h"

#include "Standalone/StandaloneDialect.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/DialectImplementation.h"
#include "llvm/ADT/TypeSwitch.h"

using namespace mlir::standalone;

#define GET_TYPEDEF_CLASSES
#include "Standalone/StandaloneOpsTypes.cpp.inc"

void StandaloneDialect::registerTypes() {
addTypes<
#define GET_TYPEDEF_LIST
#include "Standalone/StandaloneOpsTypes.cpp.inc"
>();
}
1 change: 0 additions & 1 deletion python/StandaloneExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "Standalone-c/Dialects.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"

namespace py = pybind11;
using namespace mlir::python::adaptors;

PYBIND11_MODULE(_standaloneDialects, m) {
Expand Down
1 change: 0 additions & 1 deletion python/mlir_standalone/dialects/StandaloneOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_STANDALONE_OPS
#define PYTHON_BINDINGS_STANDALONE_OPS

include "mlir/Bindings/Python/Attributes.td"
include "Standalone/StandaloneOps.td"

#endif
Loading

0 comments on commit 65de7a3

Please sign in to comment.