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

[WIP][CIR] Single-source C++ lowering with ClangIR MLIR CIR #1913

Draft
wants to merge 75 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
760dc69
Use Clang infrastructure for CIR in the project
keryell Apr 19, 2024
3bc698d
Support CIR dialect in AIE LSP server
keryell Apr 19, 2024
b53c584
[CIR] Support CIR and other dialects in aie-opt
keryell Apr 19, 2024
2179bae
[CIR] Support CIR and other dialects in aie-translate
keryell Apr 22, 2024
bb17bf7
[CIR] Add all MLIR translations to aie-translate
keryell Apr 22, 2024
120f41a
[CIR] Add empty CIRtoAIEidiomsPass
keryell Apr 26, 2024
c5493f4
[CIR] Added allow_unregistered_dialects to aiecc.py
keryell May 3, 2024
33cd60a
[CIR] Update aie-opt passes from latest ClangIR LLVM branch
keryell Sep 7, 2024
b68da02
[CIR] Generate aie.device operation from C++ aie::device<> use
keryell Sep 11, 2024
b43d1a6
[NFC] Remove useless using
keryell Sep 12, 2024
8987f18
[CIR] Generate aie.tile operation from C++ aie::tile_t<> use
keryell Sep 12, 2024
70b9ebd
Do not enforce aie.device to be a top-module operation
keryell Sep 18, 2024
6906595
Add a result to aie.device so it can be used in a bigger picture
keryell Sep 18, 2024
6c80285
[CIR] Add new conversion pass to lower C++ aie::device to aie.device
keryell Sep 19, 2024
e0e8b97
[CIR] First version of a AIE-like type detection analysis
keryell Sep 26, 2024
4d1c485
[CIR] Legallize mlir::cir::AllocaOp according to analyzed types
keryell Sep 27, 2024
6004c72
[CIR] Bless CIRToAIETypesAnalysis as an analysis
keryell Sep 28, 2024
5f4080a
[CIR] Also use CIRToAIETypesAnalysis analysis in DeviceLowering
keryell Sep 28, 2024
026fb27
[CIR] Lower the aie++ tile creation to unrealized_conversion_cast
keryell Oct 1, 2024
3b71b54
[CIR][NFC] Factorize code into isCallingFunctionWithAnnotation
keryell Oct 1, 2024
f8f8e15
[CIR] Lower C++ aie++ buffer creation
keryell Oct 1, 2024
08338ef
[CIR][NFC] Generalize isCallingFunctionWithAnnotation
keryell Oct 1, 2024
bf34c4e
[CIR] Change device lowering to just emit UnrealizedConversionCastOp
keryell Oct 1, 2024
990a5ff
[CIR] Add runtime header prototype for aie++ and test example
keryell Oct 2, 2024
c0dd56b
[CIR][header] Makes aie::buffer a real data type to be cleaner
keryell Oct 2, 2024
ba9fd67
[CIR] Improve tile and buffer lowering by keeping attribute on types
keryell Oct 2, 2024
40aecb4
[CIR] Split the lowering pass into cir-to-aie-prepare and cir-to-aie
keryell Oct 2, 2024
890fc05
[CIR] WIP on PrepareCoreLowering
keryell Oct 2, 2024
b4d4301
[CIR] Prototype of lowering to aie.device
keryell Oct 3, 2024
ec895bf
[CIR] Fix device lowering
keryell Oct 3, 2024
be4c52a
[CIR] Add missing namespaces
keryell Oct 8, 2024
2a416be
[CIR] Lower aie::buffer
keryell Oct 8, 2024
f0e7be2
[CIR] Erase operations which have been translated to AIE operations
keryell Oct 15, 2024
211da9a
[CIR] Start lowering Lower aie::tile::program(<tile code>)
keryell Oct 18, 2024
a9a941b
[CIR] Update to latest ClangIR and clean up code
keryell Oct 25, 2024
012f97c
[CIR] Prepare to use a pass without pattern rewriter
keryell Oct 25, 2024
6277506
[CIR] Lower to device operations with normal pass without rewriter
keryell Oct 25, 2024
f3c403e
[CIR][NFC] Move tile lowering logic inside its pass
keryell Oct 26, 2024
dfd5b90
[CIR] Add lowering to aie.tile and aie.buffer
keryell Oct 29, 2024
aceec0d
[CIR] Lower aie::tile::program(<tile code>) to aie.core
keryell Oct 29, 2024
1e3da16
[CIR] Clone all the symbols used by aie.device into the aie.device
keryell Oct 31, 2024
e3ad1fa
[CIR] Fix the insertion point of operations inside aie.device
keryell Oct 31, 2024
866c01a
[CIR] Remove old CIRtoAIEidiomsPass experiment
keryell Oct 31, 2024
5a80ed3
[CIR][NFC] Remove unused code from CIRToAIE passes
keryell Oct 31, 2024
3255be0
[CIR] Improve aie++ type safety to unique aie::device types
keryell Nov 2, 2024
468c17a
[CIR] Example code with aie::channel to represent aie.objectfifo
keryell Nov 6, 2024
265fe06
[CIR] Add a better API to CIRToAIETypesAnalysis
keryell Nov 7, 2024
11baf11
[CIR] Generalize operand remapping in kernel outlining to aie.tile
keryell Nov 8, 2024
a14b2f6
[CIR] Start a new lowering respecting the C++ program order
keryell Nov 9, 2024
3e973dc
[CIR] Use LLVM debug infrastructure gated with "cir-to-aie"
keryell Nov 9, 2024
0adfd9f
[CIR] New lowering for aie::tile
keryell Nov 11, 2024
975f00a
[CIR] New lowering for aie::buffer
keryell Nov 11, 2024
6714342
[CIR] New lowering for aie::tile::program
keryell Nov 12, 2024
fdde33a
[CIR] Resolve some cloning issues in aie::tile::program lowering
keryell Nov 13, 2024
53f36cd
Merge branch 'main' into clangir
keryell Nov 13, 2024
abce593
[CIR] Use only cir:: instead of mlir::cir:: to match latest ClangIR
keryell Nov 13, 2024
0bd966f
[CIR] Improve aie++ type analysis to cope with already-lowered file
keryell Nov 14, 2024
b5f21f8
[CIR] Add pass to inline the kernel lambda call chain in an aie.core
keryell Nov 16, 2024
92c79a4
[CIR] Add second function inlining to generate aie.core kernel
keryell Nov 20, 2024
186295b
[CIR] CIRToAIEDecaptureKernel pass to remove kernel lambda capture
keryell Nov 22, 2024
3597e58
[CIR] Add CLANGIR_MLIR_FRONTEND CMake option to enable CIR C++
keryell Nov 22, 2024
3f114b0
[CIR][NFC] Match coding style with clang-format CI version
keryell Nov 22, 2024
ed7d103
[CIR] Revert aie.device to not having any result
keryell Nov 23, 2024
09c5386
[CIR] Track the original aie++ type in the generated AIE operations
keryell Nov 23, 2024
4950526
Merge branch 'main' into clangir
keryell Nov 23, 2024
4eb1ab4
[CIR] Handle new aie.end terminator for aie.device
keryell Nov 23, 2024
3931c65
[CIR] Update debug code to new IR for C/C++ function returning void
keryell Dec 4, 2024
171b5b2
[CIR] Allow use of CIR to MLIR lowering conversion --cir-to-mlir
keryell Dec 4, 2024
3b582cd
[CIR] Simplify channel syntax and add range interface to buffer
keryell Dec 6, 2024
b10665d
[CIR] Add all the missing ClangIR passes to aie-opt
keryell Dec 9, 2024
4e9f5e0
[CIR] Add new --cir-keep-aie-device pass
keryell Dec 11, 2024
481e5da
[CIR] Inject AIE dialects into CIR lowering passes
keryell Dec 18, 2024
4a1c37f
[CIR] Use data-layout to allow structs to be lowered to tuple
keryell Jan 24, 2025
841ce28
[CIR] Represent buffers as C array instead of a std::array
keryell Jan 24, 2025
06c06f5
Merge branch 'main' into clangir
keryell Jan 28, 2025
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
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ set(PEANO_INSTALL_DIR
option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
option(LLVM_BUILD_TOOLS
"Build the LLVM tools. If OFF, just generate build targets." ON)
option(CLANGIR_MLIR_FRONTEND
"Use ClangIR version of Clang/LLVM to provide aie++ C++ support." OFF)

option(AIE_INCLUDE_INTEGRATION_TESTS
"Generate build targets for the mlir-aie integration tests." OFF)

Expand All @@ -85,8 +88,8 @@ execute_process(COMMAND git rev-parse HEAD OUTPUT_VARIABLE AIE_GIT_COMMIT ERROR_

find_package(MLIR REQUIRED CONFIG)

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

# These are a bit of a hack, because we're hijacking alot of LLVM machinery
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
Expand Down Expand Up @@ -135,8 +138,8 @@ set(LLVM_LIT_ARGS
"${LIT_ARGS_DEFAULT}"
CACHE STRING "Default options for lit")

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

include(TableGen)
include(AddLLVM)
Expand All @@ -145,6 +148,16 @@ include(HandleLLVMOptions)
include(ExternalProject)
include(CMakeDependentOption)

if (CLANGIR_MLIR_FRONTEND)
# To understand how to influence the find_package config, see
# https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
find_package(Clang REQUIRED CONFIG)
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")
# Use Clang infrastructure like CIR in this project
list(APPEND CMAKE_MODULE_PATH "${CLANG_CMAKE_DIR}")
include(AddClang)
endif()

include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
Expand Down
42 changes: 42 additions & 0 deletions include/aie/CIR/CIRToAIEPasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===- CIRToAIEpasses.h -----------------------------------------*- 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
//
// (c) Copyright 2024 Advanced Micro Devices, Inc.
//===----------------------------------------------------------------------===//

#ifndef CIR_AIE_PASSES_H
#define CIR_AIE_PASSES_H

#include "aie/Dialect/AIE/IR/AIEDialect.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"

#include "mlir/Pass/Pass.h"

namespace xilinx::AIE::CIR {

#define GEN_PASS_CLASSES
#include "aie/CIR/CIRToAIEPasses.h.inc"

std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
createCIRToAIEPreparePass();

std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createCIRToAIEPass();

std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
createCIRToAIEInlineKernelLambdaPass();

std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
createCIRToAIEDecaptureKernelPass();

std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>> createCIRKeepAIEDevice();

/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "aie/CIR/CIRToAIEPasses.h.inc"

} // namespace xilinx::AIE::CIR

#endif
108 changes: 108 additions & 0 deletions include/aie/CIR/CIRToAIEPasses.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//===- CIRToAIEpasses.td -----------------------------------*- 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
//
// (c) Copyright 2024 AMD
//
//===----------------------------------------------------------------------===//

#ifndef AIE_CIR_PASSES
#define AIE_CIR_PASSES

include "mlir/Pass/PassBase.td"

def CIRToAIEPrepare : Pass<"cir-to-aie-prepare", "mlir::ModuleOp"> {
let summary = "Prepare some transformations of some AIE++ patterns in CIR into AIE equivalent operations";
let description = [{
Some AIE constructs are represented in AIE++ by C++ abstractions expressed
in normal C++. These are compiled to CIR as plain C++ constructs.
This pass recognize these AIE++ C++ constructs and replace them by
equivalent AIE operations.
}];

let constructor = "xilinx::AIE::CIR::createCIRToAIEPreparePass()";
let dependentDialects = [
"cir::CIRDialect",
"xilinx::AIE::AIEDialect",
];
}

def CIRToAIE : Pass<"cir-to-aie", "mlir::ModuleOp"> {
let summary = "Transform some AIE++ patterns in CIR into AIE equivalent operations";
let description = [{
Some AIE constructs are represented in AIE++ by C++ abstractions expressed
in normal C++. These are compiled to CIR as plain C++ constructs.
This pass recognize these AIE++ C++ constructs and replace them by
equivalent AIE operations.
}];

let constructor = "xilinx::AIE::CIR::createCIRToAIEPass()";
let dependentDialects = [
"cir::CIRDialect",
"xilinx::AIE::AIEDialect",
];
}

def CIRToAIEInlineKernelLambda : Pass<"cir-to-aie-inline-kernel-lambda", "mlir::ModuleOp"> {

let summary = "Inline the call to the kernel lambda inside the aie.core operation";

let description = [{ In aie++ the tile kernel is represented by a lambda
called from "aie::tile::program" which end up to be lowered in a aie.core
operation.

This pass remove the call operations to the lambda by inlining the lambda
itself.

TODO: this might be possible to use the inliner in a restrictive way for
this, with some SROA, mem2reg...
}];

let constructor = "xilinx::AIE::CIR::createCIRToAIEInlineKernelLambdaPass()";
let dependentDialects = [
"cir::CIRDialect",
"xilinx::AIE::AIEDialect",
];
}

def CIRToAIEDecaptureKernel : Pass<"cir-to-aie-decapture-kernel", "mlir::ModuleOp"> {

let summary = "Remove the useless capture storage of a kernel in an aie.core operation";

let description = [{ After kernel lambda call inlining into an aie.core
operation, there is a left-over of capture allocation with write+read for
each kernel argument.

This pass connect directly the kernel argument to their producers without
going through the capture storage and then remove the storage itself.

TODO: this should be handled by a clever mem2reg or after standard dialect
lowering with mem2reg.
}];

let constructor = "xilinx::AIE::CIR::createCIRToAIEDecaptureKernelPass()";
let dependentDialects = [
"cir::CIRDialect",
"xilinx::AIE::AIEDialect",
];
}

def CIRKeepAIEDevice : Pass<"cir-keep-aie-device", "mlir::ModuleOp"> {

let summary = "Remove everything but the first aie.device";

let description = [{ Extract the aie.device from a CIR module by removing everything but the first aie.device.

TODO: handle multiple devices.
}];

let constructor = "xilinx::AIE::CIR::createCIRKeepAIEDevice()";
let dependentDialects = [
"cir::CIRDialect",
"xilinx::AIE::AIEDialect",
];
}

#endif
13 changes: 13 additions & 0 deletions include/aie/CIR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# 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
#
# (c) Copyright 2024 Advanced Micro Devices, Inc.


set(LLVM_TARGET_DEFINITIONS CIRToAIEPasses.td)
mlir_tablegen(CIRToAIEPasses.h.inc -gen-pass-decls -name CIRToAIE)
add_public_tablegen_target(MLIRCIRToAIEPassesIncGen)

add_mlir_doc(CIRToAIEPasses CIRToAIEPasses ./ -gen-pass-doc)
8 changes: 8 additions & 0 deletions include/aie/CIR/runtime/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -1
BreakInheritanceList: BeforeComma
BreakConstructorInitializers: BeforeComma
Cpp11BracedListStyle: false
PointerAlignment: Left
SpaceBeforeCpp11BracedList: true
Loading
Loading