-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DMA] Split DMA operations into its own dialect
`quidditch_snitch` has turned into a bit of a god-dialect which even contains things not specific to snitch. This PR is the first step in reducing this by splitting everything DMA related out of the dialect. Future goal is to have lowerings of just DMA operations to lower-level hardware specific dialects where hardware specific optimizations and legalizations can occur.
- Loading branch information
Showing
51 changed files
with
1,849 additions
and
1,465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
484 changes: 484 additions & 0 deletions
484
codegen/compiler/src/Quidditch/Conversion/ConvertDMAToLLVM.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
codegen/compiler/src/Quidditch/Conversion/ConvertDMAToLLVM.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
#pragma once | ||
|
||
#include "mlir/Conversion/LLVMCommon/TypeConverter.h" | ||
|
||
namespace quidditch { | ||
void populateDMAToLLVMConversionPatterns(mlir::ModuleOp moduleOp, | ||
mlir::LLVMTypeConverter &converter, | ||
mlir::RewritePatternSet &patterns); | ||
} |
470 changes: 2 additions & 468 deletions
470
codegen/compiler/src/Quidditch/Conversion/ConvertSnitchToLLVM.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
iree_add_all_subdirs() |
12 changes: 12 additions & 0 deletions
12
codegen/compiler/src/Quidditch/Dialect/DMA/Extensions/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
iree_cc_library( | ||
NAME | ||
DMACoreSpecializationOpInterfaceImpl | ||
HDRS | ||
"DMACoreSpecializationOpInterfaceImpl.h" | ||
SRCS | ||
"DMACoreSpecializationOpInterfaceImpl.cpp" | ||
DEPS | ||
Quidditch::Dialect::Snitch::IR::QuidditchSnitchDialect | ||
Quidditch::Dialect::DMA::IR::DMADialect | ||
) |
76 changes: 76 additions & 0 deletions
76
...en/compiler/src/Quidditch/Dialect/DMA/Extensions/DMACoreSpecializationOpInterfaceImpl.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "DMACoreSpecializationOpInterfaceImpl.h" | ||
|
||
#include "Quidditch/Dialect/DMA/IR/DMADialect.h" | ||
#include "Quidditch/Dialect/DMA/IR/DMAOps.h" | ||
#include "Quidditch/Dialect/Snitch/IR/QuidditchSnitchInterfaces.h" | ||
#include "mlir/IR/DialectRegistry.h" | ||
|
||
using namespace mlir; | ||
using namespace quidditch::dma; | ||
using namespace quidditch::Snitch; | ||
|
||
namespace { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// StartTransferOp::DMACoreSpecializationOpInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
struct StartTransferOpImpl | ||
: CoreSpecializationOpInterface::ExternalModel<StartTransferOpImpl, | ||
StartTransferOp> { | ||
void replaceWithNoop(Operation *op, RewriterBase &rewriter) const { | ||
rewriter.replaceOpWithNewOp<CompletedTokenOp>(op); | ||
} | ||
}; | ||
|
||
struct StartTransferOpDMAImpl | ||
: DMACoreSpecializationOpInterface::ExternalModel<StartTransferOpDMAImpl, | ||
StartTransferOp> {}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// StartZeroMemTransferOp::DMACoreSpecializationOpInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
struct StartZeroMemTransferOpImpl | ||
: CoreSpecializationOpInterface::ExternalModel<StartZeroMemTransferOpImpl, | ||
StartZeroMemTransferOp> { | ||
void replaceWithNoop(Operation *op, RewriterBase &rewriter) const { | ||
rewriter.replaceOpWithNewOp<CompletedTokenOp>(op); | ||
} | ||
|
||
// bool needsSynchronization(Operation *op) const { return true; } | ||
}; | ||
|
||
struct StartZeroMemTransferOpDMAImpl | ||
: DMACoreSpecializationOpInterface::ExternalModel< | ||
StartZeroMemTransferOpDMAImpl, StartZeroMemTransferOp> {}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// WaitForTransfersOpImpl::DMACoreSpecializationOpInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
struct WaitForTransfersOpImpl | ||
: CoreSpecializationOpInterface::ExternalModel<WaitForTransfersOpImpl, | ||
WaitForTransfersOp> { | ||
void replaceWithNoop(Operation *op, RewriterBase &rewriter) const { | ||
rewriter.eraseOp(op); | ||
} | ||
|
||
bool needsSynchronization(Operation *op) const { return true; } | ||
}; | ||
|
||
struct WaitForTransfersOpDMAImpl | ||
: DMACoreSpecializationOpInterface::ExternalModel<WaitForTransfersOpDMAImpl, | ||
WaitForTransfersOp> {}; | ||
|
||
} // namespace | ||
|
||
void quidditch::dma::registerDMACoreSpecializationOpInterface( | ||
mlir::DialectRegistry ®istry) { | ||
registry.addExtension(+[](MLIRContext *context, DMADialect *dialect) { | ||
#define REGISTER_IMPLS(Op) Op::attachInterface<Op##Impl, Op##DMAImpl>(*context) | ||
REGISTER_IMPLS(StartTransferOp); | ||
REGISTER_IMPLS(StartZeroMemTransferOp); | ||
REGISTER_IMPLS(WaitForTransfersOp); | ||
}); | ||
} |
10 changes: 10 additions & 0 deletions
10
codegen/compiler/src/Quidditch/Dialect/DMA/Extensions/DMACoreSpecializationOpInterfaceImpl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
#pragma once | ||
|
||
namespace mlir { | ||
class DialectRegistry; | ||
} | ||
|
||
namespace quidditch::dma { | ||
void registerDMACoreSpecializationOpInterface(mlir::DialectRegistry ®istry); | ||
} |
73 changes: 73 additions & 0 deletions
73
codegen/compiler/src/Quidditch/Dialect/DMA/IR/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
iree_add_all_subdirs() | ||
|
||
iree_cc_library( | ||
NAME | ||
DMADialect | ||
HDRS | ||
"DMADialect.h" | ||
"DMAOps.h" | ||
TEXTUAL_HDRS | ||
"DMAAttrs.cpp.inc" | ||
"DMAAttrs.h.inc" | ||
"DMADialect.cpp.inc" | ||
"DMADialect.h.inc" | ||
"DMAOps.cpp.inc" | ||
"DMAOps.h.inc" | ||
"DMATypes.cpp.inc" | ||
"DMATypes.h.inc" | ||
SRCS | ||
"DMAAttrs.cpp" | ||
"DMADialect.cpp" | ||
"DMAOps.cpp" | ||
"DMATypes.cpp" | ||
DEPS | ||
::DMAAttrsGen | ||
::DMADialectGen | ||
::DMAOpsGen | ||
::DMATypesGen | ||
LLVMSupport | ||
MLIRIR | ||
MLIRInferTypeOpInterface | ||
MLIRSupport | ||
PUBLIC | ||
) | ||
|
||
iree_tablegen_library( | ||
NAME | ||
DMAOpsGen | ||
TD_FILE | ||
"DMAOps.td" | ||
OUTS | ||
--gen-op-decls DMAOps.h.inc | ||
--gen-op-defs DMAOps.cpp.inc | ||
) | ||
|
||
iree_tablegen_library( | ||
NAME | ||
DMADialectGen | ||
TD_FILE | ||
"DMADialect.td" | ||
OUTS | ||
--gen-dialect-decls DMADialect.h.inc | ||
--gen-dialect-defs DMADialect.cpp.inc | ||
) | ||
|
||
iree_tablegen_library( | ||
NAME | ||
DMAAttrsGen | ||
TD_FILE | ||
"DMAAttrs.td" | ||
OUTS | ||
--gen-attrdef-decls DMAAttrs.h.inc | ||
--gen-attrdef-defs DMAAttrs.cpp.inc | ||
) | ||
|
||
iree_tablegen_library( | ||
NAME | ||
DMATypesGen | ||
TD_FILE | ||
"DMATypes.td" | ||
OUTS | ||
--gen-typedef-decls DMATypes.h.inc | ||
--gen-typedef-defs DMATypes.cpp.inc | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "DMAAttrs.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
#pragma once | ||
|
||
#include "mlir/IR/Attributes.h" | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "Quidditch/Dialect/DMA/IR/DMAAttrs.h.inc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef QUIDDITCH_DIALECT_DMA_DMAATTRS | ||
#define QUIDDITCH_DIALECT_DMA_DMAATTRS | ||
|
||
include "Quidditch/Dialect/DMA/IR/DMADialect.td" | ||
include "mlir/IR/AttrTypeBase.td" | ||
|
||
class DMA_Attr<string name, list<Trait> traits = []> : | ||
AttrDef<DMA_Dialect, name, traits>; | ||
|
||
def DMA_CompletedTokenAttr : DMA_Attr<"CompletedToken"> { | ||
|
||
let mnemonic = "completed_token"; | ||
|
||
let description = [{ | ||
Attribute representing an instance of a `!dma.token` | ||
signaling a complete transfer. | ||
}]; | ||
} | ||
|
||
#endif |
44 changes: 44 additions & 0 deletions
44
codegen/compiler/src/Quidditch/Dialect/DMA/IR/DMADialect.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "DMADialect.h" | ||
|
||
#include "DMAAttrs.h" | ||
#include "DMAOps.h" | ||
#include "DMATypes.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
#include "mlir/IR/DialectImplementation.h" | ||
#include "mlir/IR/OpDefinition.h" | ||
#include "mlir/IR/OpImplementation.h" | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "Quidditch/Dialect/DMA/IR/DMAAttrs.cpp.inc" | ||
|
||
#include "Quidditch/Dialect/DMA/IR/DMADialect.cpp.inc" | ||
|
||
using namespace mlir; | ||
using namespace quidditch::dma; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DMADialect | ||
//===----------------------------------------------------------------------===// | ||
|
||
void DMADialect::initialize() { | ||
addOperations< | ||
#define GET_OP_LIST | ||
#include "Quidditch/Dialect/DMA/IR/DMAOps.cpp.inc" | ||
>(); | ||
addAttributes< | ||
#define GET_ATTRDEF_LIST | ||
#include "Quidditch/Dialect/DMA/IR/DMAAttrs.cpp.inc" | ||
>(); | ||
addTypes< | ||
#define GET_TYPEDEF_LIST | ||
#include "Quidditch/Dialect/DMA/IR/DMATypes.cpp.inc" | ||
>(); | ||
} | ||
|
||
Operation *DMADialect::materializeConstant(OpBuilder &builder, Attribute value, | ||
Type type, Location loc) { | ||
if (isa<CompletedTokenAttr>(value)) | ||
return builder.create<CompletedTokenOp>(loc); | ||
|
||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
#pragma once | ||
|
||
#include "mlir/IR/Dialect.h" | ||
#include "mlir/IR/Operation.h" | ||
|
||
#include "Quidditch/Dialect/DMA/IR/DMADialect.h.inc" |
15 changes: 15 additions & 0 deletions
15
codegen/compiler/src/Quidditch/Dialect/DMA/IR/DMADialect.td
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef QUIDDITCH_DIALECT_SNITCH_DMADIALECT | ||
#define QUIDDITCH_DIALECT_SNITCH_DMADIALECT | ||
|
||
include "mlir/IR/DialectBase.td" | ||
|
||
def DMA_Dialect : Dialect { | ||
let name = "dma"; | ||
let cppNamespace = "::quidditch::dma"; | ||
|
||
let useDefaultAttributePrinterParser = 1; | ||
let useDefaultTypePrinterParser = 1; | ||
let hasConstantMaterializer = 1; | ||
} | ||
|
||
#endif |
Oops, something went wrong.