feat(compiler): Add a dialect for type inference debugging

The `TypeInference` dialect provides three operations.

The operation `TypeInference.propagate_downwards` respresents a type
barrier, which is supposed to forward the type of its operand as its
result type during type inference.

The operation `TypeInference.propagate_upwards` also respresents a
type barrier, but is supposed to forward the type of its result as the
type for its operand during type inference.

The operation `TypeInference.unresolved_conflict` can be used as a
marker when two different types have beed inferred for a value (e.g.,
one type during forward dataflow analysis and the other during
backward dataflow analysis)
This commit is contained in:
Andi Drebes
2024-01-19 15:43:58 +01:00
parent 9ca9369413
commit e78883cc24
13 changed files with 205 additions and 0 deletions

View File

@@ -5,3 +5,4 @@ add_subdirectory(Concrete)
add_subdirectory(RT)
add_subdirectory(SDFG)
add_subdirectory(Tracing)
add_subdirectory(TypeInference)

View File

@@ -0,0 +1,12 @@
set(LLVM_TARGET_DEFINITIONS TypeInferenceOps.td)
mlir_tablegen(TypeInferenceOps.h.inc -gen-op-decls)
mlir_tablegen(TypeInferenceOps.cpp.inc -gen-op-defs)
mlir_tablegen(TypeInferenceOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=TypeInference)
mlir_tablegen(TypeInferenceOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=TypeInference)
mlir_tablegen(TypeInferenceOpsDialect.h.inc -gen-dialect-decls -dialect=TypeInference)
mlir_tablegen(TypeInferenceOpsDialect.cpp.inc -gen-dialect-defs -dialect=TypeInference)
add_public_tablegen_target(MLIRTypeInferenceOpsIncGen)
add_dependencies(mlir-headers MLIRTypeInferenceOpsIncGen)
add_concretelang_doc(TypeInferenceOps TypeInferenceDialect concretelang/ -gen-dialect-doc -dialect=TypeInference)
add_concretelang_doc(TypeInferenceOps TypeInferenceOps concretelang/ -gen-op-doc)

View File

@@ -0,0 +1,15 @@
// 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.
#ifndef CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCEDIALECT_H
#define CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCEDIALECT_H
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "concretelang/Dialect/TypeInference/IR/TypeInferenceOpsDialect.h.inc"
#endif

View File

@@ -0,0 +1,15 @@
#ifndef CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCE_DIALECT
#define CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCE_DIALECT
include "mlir/IR/OpBase.td"
def TypeInference_Dialect : Dialect {
let name = "TypeInference";
let summary = "TypeInference dialect";
let description = [{
A dialect for debugging type inference
}];
let cppNamespace = "::mlir::concretelang::TypeInference";
}
#endif

View File

@@ -0,0 +1,16 @@
// 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.
#ifndef CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCEOPS_H
#define CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCEOPS_H
#include <mlir/IR/Builders.h>
#include <mlir/IR/BuiltinOps.h>
#include <mlir/IR/BuiltinTypes.h>
#define GET_OP_CLASSES
#include "concretelang/Dialect/TypeInference/IR/TypeInferenceOps.h.inc"
#endif

View File

@@ -0,0 +1,36 @@
#ifndef CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCE_OPS
#define CONCRETELANG_DIALECT_TYPEINFERENCE_IR_TYPEINFERENCE_OPS
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "concretelang/Dialect/TypeInference/IR/TypeInferenceDialect.td"
include "concretelang/Dialect/FHE/IR/FHETypes.td"
include "concretelang/Dialect/TFHE/IR/TFHETypes.td"
include "concretelang/Dialect/Concrete/IR/ConcreteTypes.td"
class TypeInference_Op<string mnemonic, list<Trait> traits = []>
: Op<TypeInference_Dialect, mnemonic, traits>;
def TypeInference_PropagateDownwardOp : TypeInference_Op<"propagate_downward"> {
let summary = "Causes the type of the operand to be forwarded upon type inference.";
let arguments = (ins AnyType);
let results = (outs AnyType);
}
def TypeInference_PropagateUpwardOp : TypeInference_Op<"propagate_upward"> {
let summary = "Causes the type of the result to be forwarded to the operands upon type inference.";
let arguments = (ins AnyType);
let results = (outs AnyType);
}
def TypeInference_UnresolvedConflictOp : TypeInference_Op<"unresolved_conflict"> {
let summary = "Represents an unresolved conflict";
let arguments = (ins AnyType);
let results = (outs AnyType);
}
#endif

View File

@@ -7,3 +7,4 @@ add_subdirectory(Concrete)
add_subdirectory(RT)
add_subdirectory(SDFG)
add_subdirectory(Tracing)
add_subdirectory(TypeInference)

View File

@@ -0,0 +1 @@
add_subdirectory(IR)

View File

@@ -0,0 +1,13 @@
add_mlir_dialect_library(
TypeInferenceDialect
TypeInferenceDialect.cpp
TypeInferenceOps.cpp
ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/concretelang/Dialect/TypeInference
DEPENDS
mlir-headers
LINK_LIBS
PUBLIC
MLIRIR)
target_link_libraries(TypeInferenceDialect PUBLIC MLIRIR)

View File

@@ -0,0 +1,18 @@
// 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 "concretelang/Dialect/TypeInference/IR/TypeInferenceDialect.h"
#include "concretelang/Dialect/TypeInference/IR/TypeInferenceOps.h"
#include "concretelang/Dialect/TypeInference/IR/TypeInferenceOpsDialect.cpp.inc"
using namespace mlir::concretelang::TypeInference;
void TypeInferenceDialect::initialize() {
addOperations<
#define GET_OP_LIST
#include "concretelang/Dialect/TypeInference/IR/TypeInferenceOps.cpp.inc"
>();
}

View File

@@ -0,0 +1,15 @@
// 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 "concretelang/Dialect/TypeInference/IR/TypeInferenceOps.h"
namespace mlir {
namespace concretelang {
namespace TypeInference {} // namespace TypeInference
} // namespace concretelang
} // namespace mlir
#define GET_OP_CLASSES
#include "concretelang/Dialect/TypeInference/IR/TypeInferenceOps.cpp.inc"