Skip to content

Commit b86a132

Browse files
committed
Revert "Expose callbacks for encoding of types/attributes"
This reverts commit b299ec1. The authorship informations were incorrect.
1 parent b08d358 commit b86a132

20 files changed

+152
-950
lines changed

mlir/include/mlir/Bytecode/BytecodeImplementation.h

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@
2424
#include "llvm/ADT/Twine.h"
2525

2626
namespace mlir {
27-
//===--------------------------------------------------------------------===//
28-
// Dialect Version Interface.
29-
//===--------------------------------------------------------------------===//
30-
31-
/// This class is used to represent the version of a dialect, for the purpose
32-
/// of polymorphic destruction.
33-
class DialectVersion {
34-
public:
35-
virtual ~DialectVersion() = default;
36-
};
37-
3827
//===----------------------------------------------------------------------===//
3928
// DialectBytecodeReader
4029
//===----------------------------------------------------------------------===//
@@ -49,14 +38,7 @@ class DialectBytecodeReader {
4938
virtual ~DialectBytecodeReader() = default;
5039

5140
/// Emit an error to the reader.
52-
virtual InFlightDiagnostic emitError(const Twine &msg = {}) const = 0;
53-
54-
/// Retrieve the dialect version by name if available.
55-
virtual FailureOr<const DialectVersion *>
56-
getDialectVersion(StringRef dialectName) const = 0;
57-
58-
/// Retrieve the context associated to the reader.
59-
virtual MLIRContext *getContext() const = 0;
41+
virtual InFlightDiagnostic emitError(const Twine &msg = {}) = 0;
6042

6143
/// Return the bytecode version being read.
6244
virtual uint64_t getBytecodeVersion() const = 0;
@@ -402,6 +384,17 @@ class DialectBytecodeWriter {
402384
virtual int64_t getBytecodeVersion() const = 0;
403385
};
404386

387+
//===--------------------------------------------------------------------===//
388+
// Dialect Version Interface.
389+
//===--------------------------------------------------------------------===//
390+
391+
/// This class is used to represent the version of a dialect, for the purpose
392+
/// of polymorphic destruction.
393+
class DialectVersion {
394+
public:
395+
virtual ~DialectVersion() = default;
396+
};
397+
405398
//===----------------------------------------------------------------------===//
406399
// BytecodeDialectInterface
407400
//===----------------------------------------------------------------------===//
@@ -416,23 +409,47 @@ class BytecodeDialectInterface
416409
//===--------------------------------------------------------------------===//
417410

418411
/// Read an attribute belonging to this dialect from the given reader. This
419-
/// method should return null in the case of failure. Optionally, the dialect
420-
/// version can be accessed through the reader.
412+
/// method should return null in the case of failure.
421413
virtual Attribute readAttribute(DialectBytecodeReader &reader) const {
422414
reader.emitError() << "dialect " << getDialect()->getNamespace()
423415
<< " does not support reading attributes from bytecode";
424416
return Attribute();
425417
}
426418

419+
/// Read a versioned attribute encoding belonging to this dialect from the
420+
/// given reader. This method should return null in the case of failure, and
421+
/// falls back to the non-versioned reader in case the dialect implements
422+
/// versioning but it does not support versioned custom encodings for the
423+
/// attributes.
424+
virtual Attribute readAttribute(DialectBytecodeReader &reader,
425+
const DialectVersion &version) const {
426+
reader.emitError()
427+
<< "dialect " << getDialect()->getNamespace()
428+
<< " does not support reading versioned attributes from bytecode";
429+
return Attribute();
430+
}
431+
427432
/// Read a type belonging to this dialect from the given reader. This method
428-
/// should return null in the case of failure. Optionally, the dialect version
429-
/// can be accessed thorugh the reader.
433+
/// should return null in the case of failure.
430434
virtual Type readType(DialectBytecodeReader &reader) const {
431435
reader.emitError() << "dialect " << getDialect()->getNamespace()
432436
<< " does not support reading types from bytecode";
433437
return Type();
434438
}
435439

440+
/// Read a versioned type encoding belonging to this dialect from the given
441+
/// reader. This method should return null in the case of failure, and
442+
/// falls back to the non-versioned reader in case the dialect implements
443+
/// versioning but it does not support versioned custom encodings for the
444+
/// types.
445+
virtual Type readType(DialectBytecodeReader &reader,
446+
const DialectVersion &version) const {
447+
reader.emitError()
448+
<< "dialect " << getDialect()->getNamespace()
449+
<< " does not support reading versioned types from bytecode";
450+
return Type();
451+
}
452+
436453
//===--------------------------------------------------------------------===//
437454
// Writing
438455
//===--------------------------------------------------------------------===//

mlir/include/mlir/Bytecode/BytecodeReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SourceMgr;
2525
} // namespace llvm
2626

2727
namespace mlir {
28+
2829
/// The BytecodeReader allows to load MLIR bytecode files, while keeping the
2930
/// state explicitly available in order to support lazy loading.
3031
/// The `finalize` method must be called before destruction.

mlir/include/mlir/Bytecode/BytecodeReaderConfig.h

Lines changed: 0 additions & 120 deletions
This file was deleted.

mlir/include/mlir/Bytecode/BytecodeWriter.h

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,6 @@
1717

1818
namespace mlir {
1919
class Operation;
20-
class DialectBytecodeWriter;
21-
22-
/// A class to interact with the attributes and types printer when emitting MLIR
23-
/// bytecode.
24-
template <class T>
25-
class AttrTypeBytecodeWriter {
26-
public:
27-
AttrTypeBytecodeWriter() = default;
28-
virtual ~AttrTypeBytecodeWriter() = default;
29-
30-
/// Callback writer API used in IRNumbering, where groups are created and
31-
/// type/attribute components are numbered. At this stage, writer is expected
32-
/// to be a `NumberingDialectWriter`.
33-
virtual LogicalResult write(T entry, std::optional<StringRef> &name,
34-
DialectBytecodeWriter &writer) = 0;
35-
36-
/// Callback writer API used in BytecodeWriter, where groups are created and
37-
/// type/attribute components are numbered. Here, DialectBytecodeWriter is
38-
/// expected to be an actual writer. The optional stringref specified by
39-
/// the user is ignored, since the group was already specified when numbering
40-
/// the IR.
41-
LogicalResult write(T entry, DialectBytecodeWriter &writer) {
42-
std::optional<StringRef> dummy;
43-
return write(entry, dummy, writer);
44-
}
45-
46-
/// Return an Attribute/Type printer implemented via the given callable, whose
47-
/// form should match that of the `write` function above.
48-
template <typename CallableT,
49-
std::enable_if_t<std::is_convertible_v<
50-
CallableT, std::function<LogicalResult(
51-
T, std::optional<StringRef> &,
52-
DialectBytecodeWriter &)>>,
53-
bool> = true>
54-
static std::unique_ptr<AttrTypeBytecodeWriter<T>>
55-
fromCallable(CallableT &&writeFn) {
56-
struct Processor : public AttrTypeBytecodeWriter<T> {
57-
Processor(CallableT &&writeFn)
58-
: AttrTypeBytecodeWriter(), writeFn(std::move(writeFn)) {}
59-
LogicalResult write(T entry, std::optional<StringRef> &name,
60-
DialectBytecodeWriter &writer) override {
61-
return writeFn(entry, name, writer);
62-
}
63-
64-
std::decay_t<CallableT> writeFn;
65-
};
66-
return std::make_unique<Processor>(std::forward<CallableT>(writeFn));
67-
}
68-
};
6920

7021
/// This class contains the configuration used for the bytecode writer. It
7122
/// controls various aspects of bytecode generation, and contains all of the
@@ -97,43 +48,6 @@ class BytecodeWriterConfig {
9748
/// Get the set desired bytecode version to emit.
9849
int64_t getDesiredBytecodeVersion() const;
9950

100-
//===--------------------------------------------------------------------===//
101-
// Types and Attributes encoding
102-
//===--------------------------------------------------------------------===//
103-
104-
/// Retrieve the callbacks.
105-
ArrayRef<std::unique_ptr<AttrTypeBytecodeWriter<Attribute>>>
106-
getAttributeWriterCallbacks() const;
107-
ArrayRef<std::unique_ptr<AttrTypeBytecodeWriter<Type>>>
108-
getTypeWriterCallbacks() const;
109-
110-
/// Attach a custom bytecode printer callback to the configuration for the
111-
/// emission of custom type/attributes encodings.
112-
void attachAttributeCallback(
113-
std::unique_ptr<AttrTypeBytecodeWriter<Attribute>> callback);
114-
void
115-
attachTypeCallback(std::unique_ptr<AttrTypeBytecodeWriter<Type>> callback);
116-
117-
/// Attach a custom bytecode printer callback to the configuration for the
118-
/// emission of custom type/attributes encodings.
119-
template <typename CallableT>
120-
std::enable_if_t<std::is_convertible_v<
121-
CallableT,
122-
std::function<LogicalResult(Attribute, std::optional<StringRef> &,
123-
DialectBytecodeWriter &)>>>
124-
attachAttributeCallback(CallableT &&emitFn) {
125-
attachAttributeCallback(AttrTypeBytecodeWriter<Attribute>::fromCallable(
126-
std::forward<CallableT>(emitFn)));
127-
}
128-
template <typename CallableT>
129-
std::enable_if_t<std::is_convertible_v<
130-
CallableT, std::function<LogicalResult(Type, std::optional<StringRef> &,
131-
DialectBytecodeWriter &)>>>
132-
attachTypeCallback(CallableT &&emitFn) {
133-
attachTypeCallback(AttrTypeBytecodeWriter<Type>::fromCallable(
134-
std::forward<CallableT>(emitFn)));
135-
}
136-
13751
//===--------------------------------------------------------------------===//
13852
// Resources
13953
//===--------------------------------------------------------------------===//

mlir/include/mlir/IR/AsmState.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef MLIR_IR_ASMSTATE_H_
1515
#define MLIR_IR_ASMSTATE_H_
1616

17-
#include "mlir/Bytecode/BytecodeReaderConfig.h"
1817
#include "mlir/IR/OperationSupport.h"
1918
#include "mlir/Support/LLVM.h"
2019
#include "llvm/ADT/MapVector.h"
@@ -476,11 +475,6 @@ class ParserConfig {
476475
/// Returns if the parser should verify the IR after parsing.
477476
bool shouldVerifyAfterParse() const { return verifyAfterParse; }
478477

479-
/// Returns the parsing configurations associated to the bytecode read.
480-
BytecodeReaderConfig &getBytecodeReaderConfig() const {
481-
return const_cast<BytecodeReaderConfig &>(bytecodeReaderConfig);
482-
}
483-
484478
/// Return the resource parser registered to the given name, or nullptr if no
485479
/// parser with `name` is registered.
486480
AsmResourceParser *getResourceParser(StringRef name) const {
@@ -515,7 +509,6 @@ class ParserConfig {
515509
bool verifyAfterParse;
516510
DenseMap<StringRef, std::unique_ptr<AsmResourceParser>> resourceParsers;
517511
FallbackAsmResourceMap *fallbackResourceMap;
518-
BytecodeReaderConfig bytecodeReaderConfig;
519512
};
520513

521514
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)