mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-18 16:34:43 -05:00
This commit rebases the compiler onto commit 465ee9bfb26d from
llvm-project with locally maintained patches on top, i.e.:
* 5d8669d669ee: Fix the element alignment (size) for memrefCopy
* 4239163ea337: fix: Do not fold the memref.subview if the offset are
!= 0 and strides != 1
* 72c5decfcc21: remove github stuff from llvm
* 8d0ce8f9eca1: Support arbitrary element types in named operations
via attributes
* 94f64805c38c: Copy attributes of scf.for on bufferization and make
it an allocation hoisting barrier
Main upstream changes from llvm-project that required modification of
concretecompiler:
* Switch to C++17
* Various changes in the interfaces for linalg named operations
* Transition from `llvm::Optional` to `std::optional`
* Use of enums instead of string values for iterator types in linalg
* Changed default naming convention of getter methods in
ODS-generated operation classes from `some_value()` to
`getSomeValue()`
* Renaming of Arithmetic dialect to Arith
* Refactoring of side effect interfaces (i.e., renaming from
`NoSideEffect` to `Pure`)
* Re-design of the data flow analysis framework
* Refactoring of build targets for Python bindings
* Refactoring of array attributes with integer values
* Renaming of `linalg.init_tensor` to `tensor.empty`
* Emission of `linalg.map` operations in bufferization of the Tensor
dialect requiring another linalg conversion pass and registration
of the bufferization op interfaces for linalg operations
* Refactoring of the one-shot bufferizer
* Necessity to run the expand-strided-metadata, affine-to-std and
finalize-memref-to-llvm passes before converson to the LLVM
dialect
* Renaming of `BlockAndValueMapping` to `IRMapping`
* Changes in the build function of `LLVM::CallOp`
* Refactoring of the construction of `llvm::ArrayRef` and
`llvm::MutableArrayRef` (direct invocation of constructor instead
of builder functions for some cases)
* New naming conventions for generated SSA values requiring rewrite
of some check tests
* Refactoring of `mlir::LLVM::lookupOrCreateMallocFn()`
* Interface changes in generated type parsers
* New dependencies for to mlir_float16_utils and
MLIRSparseTensorRuntime for the runtime
* Overhaul of MLIR-c deleting `mlir-c/Registration.h`
* Deletion of library MLIRLinalgToSPIRV
* Deletion of library MLIRLinalgAnalysis
* Deletion of library MLIRMemRefUtils
* Deletion of library MLIRQuantTransforms
* Deletion of library MLIRVectorToROCDL
100 lines
4.0 KiB
C++
100 lines
4.0 KiB
C++
// Part of the Concrete Compiler Project, under the BSD3 License with Zama
|
|
// Exceptions. See
|
|
// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt
|
|
// for license information.
|
|
|
|
#include "mlir/IR/Attributes.h"
|
|
#include "mlir/IR/Builders.h"
|
|
#include "mlir/IR/BuiltinOps.h"
|
|
#include "mlir/IR/BuiltinTypes.h"
|
|
#include "mlir/IR/Region.h"
|
|
#include "mlir/IR/TypeUtilities.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "concretelang/Dialect/RT/IR/RTOps.h"
|
|
#include "concretelang/Dialect/RT/IR/RTTypes.h"
|
|
|
|
#define GET_OP_CLASSES
|
|
#include "concretelang/Dialect/RT/IR/RTOps.cpp.inc"
|
|
|
|
using namespace mlir::concretelang::RT;
|
|
|
|
void DataflowTaskOp::build(
|
|
::mlir::OpBuilder &builder, ::mlir::OperationState &result,
|
|
::mlir::TypeRange resultTypes, ::mlir::ValueRange operands,
|
|
::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {
|
|
result.addOperands(operands);
|
|
result.addAttributes(attributes);
|
|
Region *reg = result.addRegion();
|
|
Block *body = new Block();
|
|
reg->push_back(body);
|
|
result.addTypes(resultTypes);
|
|
}
|
|
|
|
void DataflowTaskOp::getSuccessorRegions(
|
|
Optional<unsigned> index, ArrayRef<Attribute> operands,
|
|
SmallVectorImpl<RegionSuccessor> ®ions) {}
|
|
|
|
std::optional<mlir::Operation *>
|
|
DataflowTaskOp::buildDealloc(OpBuilder &builder, Value alloc) {
|
|
return builder.create<DeallocateFutureOp>(alloc.getLoc(), alloc)
|
|
.getOperation();
|
|
}
|
|
std::optional<mlir::Value> DataflowTaskOp::buildClone(OpBuilder &builder,
|
|
Value alloc) {
|
|
return builder.create<CloneFutureOp>(alloc.getLoc(), alloc).getResult();
|
|
}
|
|
void DataflowTaskOp::getEffects(
|
|
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
|
|
&effects) {
|
|
for (auto input : getInputs())
|
|
effects.emplace_back(MemoryEffects::Read::get(), input,
|
|
SideEffects::DefaultResource::get());
|
|
for (auto output : getOutputs())
|
|
effects.emplace_back(MemoryEffects::Write::get(), output,
|
|
SideEffects::DefaultResource::get());
|
|
for (auto output : getOutputs())
|
|
effects.emplace_back(MemoryEffects::Allocate::get(), output,
|
|
SideEffects::DefaultResource::get());
|
|
}
|
|
|
|
std::optional<mlir::Operation *> CloneFutureOp::buildDealloc(OpBuilder &builder,
|
|
Value alloc) {
|
|
return builder.create<DeallocateFutureOp>(alloc.getLoc(), alloc)
|
|
.getOperation();
|
|
}
|
|
std::optional<mlir::Value> CloneFutureOp::buildClone(OpBuilder &builder,
|
|
Value alloc) {
|
|
return builder.create<CloneFutureOp>(alloc.getLoc(), alloc).getResult();
|
|
}
|
|
void CloneFutureOp::getEffects(
|
|
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
|
|
&effects) {
|
|
effects.emplace_back(MemoryEffects::Read::get(), getInput(),
|
|
SideEffects::DefaultResource::get());
|
|
effects.emplace_back(MemoryEffects::Write::get(), getOutput(),
|
|
SideEffects::DefaultResource::get());
|
|
effects.emplace_back(MemoryEffects::Allocate::get(), getOutput(),
|
|
SideEffects::DefaultResource::get());
|
|
}
|
|
|
|
std::optional<mlir::Operation *>
|
|
MakeReadyFutureOp::buildDealloc(OpBuilder &builder, Value alloc) {
|
|
return builder.create<DeallocateFutureOp>(alloc.getLoc(), alloc)
|
|
.getOperation();
|
|
}
|
|
std::optional<mlir::Value> MakeReadyFutureOp::buildClone(OpBuilder &builder,
|
|
Value alloc) {
|
|
return builder.create<CloneFutureOp>(alloc.getLoc(), alloc).getResult();
|
|
}
|
|
void MakeReadyFutureOp::getEffects(
|
|
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
|
|
&effects) {
|
|
effects.emplace_back(MemoryEffects::Read::get(), getInput(),
|
|
SideEffects::DefaultResource::get());
|
|
effects.emplace_back(MemoryEffects::Write::get(), getOutput(),
|
|
SideEffects::DefaultResource::get());
|
|
effects.emplace_back(MemoryEffects::Allocate::get(), getOutput(),
|
|
SideEffects::DefaultResource::get());
|
|
}
|