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

Initial changes for llvm uplift #2568

Merged
merged 10 commits into from
Nov 14, 2023
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
2 changes: 1 addition & 1 deletion docs/BuildOnLinuxOSX.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Firstly, install MLIR (as a part of LLVM-Project):
``` bash
git clone -n https://github.com/llvm/llvm-project.git
# Check out a specific branch that is known to work with ONNX-MLIR.
cd llvm-project && git checkout d13da154a7c7eff77df8686b2de1cfdfa7cc7029 && cd ..
cd llvm-project && git checkout b44b3494f60296db6aca38a14cab061d9b747a0a && cd ..
```

[same-as-file]: <> (utils/build-mlir.sh)
Expand Down
2 changes: 1 addition & 1 deletion docs/BuildOnWindows.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Install MLIR (as a part of LLVM-Project):
```shell
git clone -n https://github.com/llvm/llvm-project.git
# Check out a specific branch that is known to work with ONNX-MLIR.
cd llvm-project && git checkout d13da154a7c7eff77df8686b2de1cfdfa7cc7029 && cd ..
cd llvm-project && git checkout b44b3494f60296db6aca38a14cab061d9b747a0a && cd ..
```

[same-as-file]: <> (utils/build-mlir.cmd)
Expand Down
3 changes: 1 addition & 2 deletions src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ void addONNXToZHighPasses(mlir::PassManager &pm) {

// Constant propagation at ZHighIR: constant stickify.
// Only support BE machines.
bool isBE = llvm::support::endian::system_endianness() ==
llvm::support::endianness::big;
bool isBE = llvm::endianness::native == llvm::support::endianness::big;
if (isBE)
pm.addNestedPass<func::FuncOp>(
onnx_mlir::zhigh::createZHighConstPropagationPass());
Expand Down
5 changes: 2 additions & 3 deletions src/Builder/FrontendDialectHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ ElementsAttr createElmAttrFromArray(RankedTensorType tensorType,
// and llvm::sys::getSwappedBytes(bool) also happens to be broken.
template <typename T>
constexpr bool shouldSwapLEBytes =
sizeof(T) > 1 && llvm::support::endian::system_endianness() !=
llvm::support::endianness::little;

sizeof(T) > 1 && llvm::endianness::native
!= llvm::support::endianness::little;
// Extension of llvm::sys::getSwappedBytes to also handle float_16, bfloat_16.
template <typename T>
T swappedBytes(T x) {
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ add_onnx_mlir_library(OMCompilerPasses
${OMLibs}
OMCompilerOptions
MLIRAffineTransforms
MLIRBufferizationPipelines
MLIRBufferizationToMemRef
MLIRIR
MLIRLinalgTransforms
MLIRLLVMToLLVMIRTranslation
Expand Down
8 changes: 6 additions & 2 deletions src/Compiler/CompilerPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
#include "mlir/Conversion/VectorToSCF/VectorToSCF.h"
#include "mlir/Dialect/Bufferization/Pipelines/Passes.h"
#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
#include "mlir/Dialect/MemRef/Transforms/Passes.h"
#include "mlir/Pass/Pass.h"
Expand Down Expand Up @@ -225,8 +226,11 @@ void addKrnlToLLVMPasses(
// Currently this has to be done *after* lowering the affine dialect because
// operations in that dialect do not conform to the requirements explained
// in https://mlir.llvm.org/docs/BufferDeallocationInternals.
pm.addNestedPass<func::FuncOp>(
mlir::bufferization::createBufferDeallocationPass());
bufferization::BufferDeallocationPipelineOptions bufferDeallocOptions;
mlir::bufferization::buildBufferDeallocationPipeline(
pm, bufferDeallocOptions);

pm.addPass(mlir::createBufferizationToMemRefPass());

// The pass below is needed for subview and collapseShape.. Unfortunately,
// MLIR supports only collapse for scalar loaded by scalar memory at this
Expand Down
2 changes: 1 addition & 1 deletion src/Conversion/KrnlToAffine/ConvertKrnlToAffine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ static LogicalResult interpretOperation(Operation *op, OpBuilder &builder,
AffineParallelOp parallelLoop = opBuilder.create<AffineParallelOp>(loc,
ValueRange(reducedValues).getTypes(), reductionKinds, ArrayRef(lbsMap),
lbsOperands, ArrayRef(ubsMap), ubsOperands,
ArrayRef(loopToParallel.getStep()));
ArrayRef(loopToParallel.getStepAsInt()));
parallelLoop.getRegion().takeBody(loopToParallel.getRegion());
Operation *yieldOp = &parallelLoop.getBody()->back();

Expand Down
3 changes: 1 addition & 2 deletions src/Conversion/KrnlToLLVM/ConvertKrnlToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ bool extractConstantsToFile(ModuleOp &module, std::string filepath,
EXTERNAL_CONSTANT_PREFIX + "filesize",
b.getI64IntegerAttr(packedConst.size()));
// Create a global to store isLE.
bool isLE = llvm::support::endian::system_endianness() ==
llvm::support::endianness::little;
bool isLE = llvm::endianness::native == llvm::support::endianness::little;
create.llvm.globalOp(llvmI8Ty,
/*isConstant=*/true, LLVM::Linkage::Internal,
EXTERNAL_CONSTANT_PREFIX + "isLE", b.getI8IntegerAttr(isLE));
Expand Down
3 changes: 2 additions & 1 deletion src/Dialect/Krnl/Krnl.td
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include "mlir/IR/OpBase.td"
include "mlir/Dialect/Shape/IR/ShapeBase.td"
include "mlir/Dialect/Bufferization/IR/AllocationOpInterface.td"
include "mlir/Interfaces/CastInterfaces.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/ViewLikeInterface.td"
Expand Down Expand Up @@ -285,7 +286,7 @@ def KrnlSeqStoreOp : Op<Krnl_Dialect, "seqstore", [MemRefsNormalizable]> {
Index:$index);
}

def KrnlTerminatorOp : Op<Krnl_Dialect, "terminate", [Terminator]> {
def KrnlTerminatorOp : Op<Krnl_Dialect, "terminate", [ReturnLike, Terminator]> {
let summary = "Krnl terminator operation";
let description = [{
Krnl terminator is a special terminator operation for blocks inside krnl
Expand Down
2 changes: 1 addition & 1 deletion src/Dialect/Mlir/DialectBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ Value LLVMBuilder::mul(Value lhs, Value rhs) const {
}

Value LLVMBuilder::null(Type type) const {
return b().create<LLVM::NullOp>(loc(), type);
return b().create<LLVM::ZeroOp>(loc(), type);
}

Value LLVMBuilder::ptrtoint(Type type, Value val) const {
Expand Down
4 changes: 2 additions & 2 deletions src/Dialect/ONNX/ElementsAttr/DisposableElementsAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ DenseElementsAttr DisposableElementsAttr::toDenseElementsAttr() const {
namespace {
// Perform byte swap if system endianness is BE and elements are multi-byte.
bool shouldSwapLEBytes(unsigned elementByteWidth) {
return elementByteWidth > 1 && llvm::support::endian::system_endianness() !=
llvm::support::endianness::little;
return elementByteWidth > 1 &&
llvm::endianness::native != llvm::support::endianness::little;
}
} // namespace

Expand Down
3 changes: 3 additions & 0 deletions src/Tools/onnx-mlir-opt/onnx-mlir-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <llvm/Support/InitLLVM.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/ToolOutputFile.h>
#include <mlir/Dialect/Bufferization/Pipelines/Passes.h>
#include <mlir/Dialect/Bufferization/Transforms/Passes.h>
#include <mlir/Dialect/MemRef/Transforms/Passes.h>
#include <mlir/Dialect/Tosa/IR/TosaOps.h>
Expand Down Expand Up @@ -118,6 +119,8 @@ int main(int argc, char **argv) {
DialectRegistry registry = registerDialects(maccel);
registry.insert<tosa::TosaDialect>();

bufferization::registerBufferizationPipelines();

// Registered passes can be expressed as command line flags, so they must
// must be registered before command line options are parsed.
registerPasses(OptimizationLevel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ func.func @test_constants_to_file() -> memref<10xi64> {
// CHECK: llvm.func @omMMapBinaryFile(!llvm.ptr, !llvm.ptr, i64, i64)
// CHECK: llvm.mlir.global internal constant @constant_2(dense<[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]> : tensor<10xi64>) {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.array<10 x i64>
// CHECK: llvm.mlir.global internal @om_external_constant_data_constant_1() {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.ptr {
// CHECK: [[VAR_0_4_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_0_4_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_0_4_]] : !llvm.ptr
// CHECK: }
// CHECK: llvm.mlir.global internal constant @om_external_constant_offset_constant_1(0 : i64) {addr_space = 0 : i32} : i64
// CHECK: llvm.mlir.global internal @om_external_constant_data_constant_0() {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.ptr {
// CHECK: [[VAR_0_5_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_0_5_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_0_5_]] : !llvm.ptr
// CHECK: }
// CHECK: llvm.mlir.global internal constant @om_external_constant_offset_constant_0(4096 : i64) {addr_space = 0 : i32} : i64
// CHECK: llvm.mlir.global internal constant @om_external_constant_filename("model.constants.bin\00") {addr_space = 0 : i32}
// CHECK: llvm.mlir.global internal constant @om_external_constant_filesize(4176 : i64) {addr_space = 0 : i32} : i64
// CHECK: llvm.mlir.global internal constant @om_external_constant_isLE(0 : i8) {addr_space = 0 : i32} : i8
// CHECK: llvm.mlir.global internal @om_external_constant_packedConst() {addr_space = 0 : i32} : !llvm.ptr {
// CHECK: [[VAR_0_6_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_0_6_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_0_6_]] : !llvm.ptr
// CHECK: }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ func.func @test_constants_to_file() -> memref<10xi64> {
// CHECK: llvm.func @omMMapBinaryFile(!llvm.ptr, !llvm.ptr, i64, i64)
// CHECK: llvm.mlir.global internal constant @constant_2(dense<[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]> : tensor<10xi64>) {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.array<10 x i64>
// CHECK: llvm.mlir.global internal @om_external_constant_data_constant_1() {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.ptr {
// CHECK: [[VAR_0_4_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_0_4_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_0_4_]] : !llvm.ptr
// CHECK: }
// CHECK: llvm.mlir.global internal constant @om_external_constant_offset_constant_1(0 : i64) {addr_space = 0 : i32} : i64
// CHECK: llvm.mlir.global internal @om_external_constant_data_constant_0() {addr_space = 0 : i32, alignment = 4096 : i64} : !llvm.ptr {
// CHECK: [[VAR_0_5_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_0_5_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_0_5_]] : !llvm.ptr
// CHECK: }
// CHECK: llvm.mlir.global internal constant @om_external_constant_offset_constant_0(4096 : i64) {addr_space = 0 : i32} : i64
// CHECK: llvm.mlir.global internal constant @om_external_constant_filename("model.constants.bin\00") {addr_space = 0 : i32}
// CHECK: llvm.mlir.global internal constant @om_external_constant_filesize(4176 : i64) {addr_space = 0 : i32} : i64
// CHECK: llvm.mlir.global internal constant @om_external_constant_isLE(1 : i8) {addr_space = 0 : i32} : i8
// CHECK: llvm.mlir.global internal @om_external_constant_packedConst() {addr_space = 0 : i32} : !llvm.ptr {
// CHECK: [[VAR_0_6_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_0_6_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_0_6_]] : !llvm.ptr
// CHECK: }

Expand Down
18 changes: 9 additions & 9 deletions test/mlir/conversion/krnl_to_llvm/entry_point.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ module {
// CHECK-DAG: [[VAR_2_:%.+]] = llvm.mlir.addressof @_entry_point_0 : !llvm.ptr<array<15 x i8>>
// CHECK: [[VAR_3_:%.+]] = llvm.bitcast [[VAR_2_]] : !llvm.ptr<array<15 x i8>> to !llvm.ptr
// CHECK: [[VAR_4_:%.+]] = llvm.insertvalue [[VAR_3_]], [[VAR_0_]][0] : !llvm.array<2 x ptr>
// CHECK: [[VAR_5_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_5_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: [[VAR_6_:%.+]] = llvm.insertvalue [[VAR_5_]], [[VAR_4_]][1] : !llvm.array<2 x ptr>
// CHECK: llvm.return [[VAR_6_]] : !llvm.array<2 x ptr>
// CHECK: }

// CHECK: llvm.func @omQueryEntryPoints([[arg0_:%.+]]: !llvm.ptr) -> !llvm.ptr {
// CHECK-DAG: [[VAR_2_4_:%.+]] = llvm.mlir.constant(1 : i64) : i64
// CHECK-DAG: [[VAR_0_3_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK-DAG: [[VAR_0_3_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: [[VAR_1_4_:%.+]] = llvm.icmp "ne" [[arg0_]], [[VAR_0_3_]] : !llvm.ptr
// CHECK: llvm.cond_br [[VAR_1_4_]], ^bb1, ^bb2
// CHECK: ^bb1: // pred: ^bb0
Expand All @@ -54,7 +54,7 @@ module {
// CHECK: [[VAR_10_1_:%.+]] = llvm.bitcast [[VAR_9_1_]] : !llvm.ptr<array<9 x i8>> to !llvm.ptr
// CHECK: llvm.return [[VAR_10_1_]] : !llvm.ptr
// CHECK: ^bb2: // pred: ^bb0
// CHECK: [[VAR_11_1_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_11_1_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_11_1_]] : !llvm.ptr
// CHECK: }

Expand All @@ -71,7 +71,7 @@ module {
// CHECK: [[VAR_10_2_:%.+]] = llvm.bitcast [[VAR_9_2_]] : !llvm.ptr<array<10 x i8>> to !llvm.ptr
// CHECK: llvm.return [[VAR_10_2_]] : !llvm.ptr
// CHECK: ^bb2: // pred: ^bb0
// CHECK: [[VAR_11_2_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_11_2_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_11_2_]] : !llvm.ptr
// CHECK: }

Expand Down Expand Up @@ -112,13 +112,13 @@ module {
// CHECK: [[VAR_6_5_:%.+]] = llvm.mlir.addressof @_entry_point_1 : !llvm.ptr<array<17 x i8>>
// CHECK: [[VAR_7_3_:%.+]] = llvm.bitcast [[VAR_6_5_]] : !llvm.ptr<array<17 x i8>> to !llvm.ptr
// CHECK: [[VAR_8_3_:%.+]] = llvm.insertvalue [[VAR_7_3_]], [[VAR_4_6_]][1] : !llvm.array<3 x ptr>
// CHECK: [[VAR_9_3_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_9_3_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: [[VAR_10_3_:%.+]] = llvm.insertvalue [[VAR_9_3_]], [[VAR_8_3_]][2] : !llvm.array<3 x ptr>
// CHECK: llvm.return [[VAR_10_3_]] : !llvm.array<3 x ptr>
// CHECK: }

// CHECK: llvm.func @omQueryEntryPoints([[arg0_:%.+]]: !llvm.ptr) -> !llvm.ptr {
// CHECK-DAG: [[VAR_0_11_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK-DAG: [[VAR_0_11_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK-DAG: [[VAR_2_14_:%.+]] = llvm.mlir.constant(2 : i64) : i64
// CHECK: [[VAR_1_14_:%.+]] = llvm.icmp "ne" [[arg0_]], [[VAR_0_11_]] : !llvm.ptr
// CHECK: llvm.cond_br [[VAR_1_14_]], ^bb1, ^bb2
Expand Down Expand Up @@ -156,7 +156,7 @@ module {
// CHECK: [[LOAD_VAR_2_3_MEM_1_1_:%.+]] = llvm.bitcast [[VAR_17_3_]] : !llvm.ptr<array<11 x i8>> to !llvm.ptr
// CHECK: llvm.return [[LOAD_VAR_2_3_MEM_1_1_]] : !llvm.ptr
// CHECK: ^bb4: // pred: ^bb2
// CHECK: [[VAR_19_3_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_19_3_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_19_3_]] : !llvm.ptr
// CHECK: }

Expand Down Expand Up @@ -185,7 +185,7 @@ module {
// CHECK: [[LOAD_VAR_2_3_MEM_1_1_:%.+]] = llvm.bitcast [[VAR_17_4_]] : !llvm.ptr<array<12 x i8>> to !llvm.ptr
// CHECK: llvm.return [[LOAD_VAR_2_3_MEM_1_1_]] : !llvm.ptr
// CHECK: ^bb4: // pred: ^bb2
// CHECK: [[VAR_19_4_:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK: [[VAR_19_4_:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK: llvm.return [[VAR_19_4_]] : !llvm.ptr
// CHECK: }
}
Expand All @@ -208,7 +208,7 @@ module attributes {"onnx-mlir.accels" = ["Pseudo-0x10001", "NNPA-0x10000"]} {
// CHECK-NEXT: [[FAILED:%.+]] = llvm.icmp "eq" [[COMPATIBLE]], [[FALSE]] : i64
// CHECK-NEXT: llvm.cond_br [[FAILED]], ^bb1, ^bb2
// CHECK-NEXT: ^bb1: // 2 preds: ^bb0, ^bb2
// CHECK-NEXT: [[NULL:%.+]] = llvm.mlir.null : !llvm.ptr
// CHECK-NEXT: [[NULL:%.+]] = llvm.mlir.zero : !llvm.ptr
// CHECK-NEXT: llvm.return [[NULL]] : !llvm.ptr
// CHECK-NEXT: ^bb2: // pred: ^bb0
// CHECK-NEXT: [[COMPATIBLE:%.+]] = llvm.call @OMInitCompatibleAccelNNPA([[VERSION_NUMBER_1]]) : (i64) -> i64
Expand Down
Loading
Loading