Add the ability to have "Ops" defined as small C++ classes, with some nice
properties:
- They allow type checked dynamic casting from their base Operation.
- They allow nice accessors for C++ clients, e.g. a "getIndex()" method on
'dim' that returns an unsigned.
- They work with both OperationInst/OperationStmt (once OperationStmt is
implemented).
- They get custom printing logic. They will eventually get custom parsing,
verifier, and builder logic as well.
- Out of tree clients can register their own operation set without having to
change MLIR core, e.g. for TensorFlow or custom target instructions.
This registers addf and dim as examples.
PiperOrigin-RevId: 203382993
diff --git a/lib/IR/MLIRContext.cpp b/lib/IR/MLIRContext.cpp
index 3524909..ca084de 100644
--- a/lib/IR/MLIRContext.cpp
+++ b/lib/IR/MLIRContext.cpp
@@ -20,6 +20,8 @@
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Identifier.h"
+#include "mlir/IR/OperationSet.h"
+#include "mlir/IR/StandardOps.h"
#include "mlir/IR/Types.h"
#include "mlir/Support/STLExtras.h"
#include "llvm/ADT/DenseSet.h"
@@ -134,6 +136,9 @@
/// We put immortal objects into this allocator.
llvm::BumpPtrAllocator allocator;
+ /// This is the set of all operations that are registered with the system.
+ OperationSet operationSet;
+
/// These are identifiers uniqued into this MLIRContext.
llvm::StringMap<char, llvm::BumpPtrAllocator&> identifiers;
@@ -178,7 +183,9 @@
ArrayAttrSet arrayAttrs;
public:
- MLIRContextImpl() : identifiers(allocator) {}
+ MLIRContextImpl() : identifiers(allocator) {
+ registerStandardOperations(operationSet);
+ }
/// Copy the specified array of elements into memory managed by our bump
/// pointer allocator. This assumes the elements are all PODs.
@@ -197,6 +204,10 @@
MLIRContext::~MLIRContext() {
}
+/// Return the operation set associated with the specified MLIRContext object.
+OperationSet &OperationSet::get(MLIRContext *context) {
+ return context->getImpl().operationSet;
+}
//===----------------------------------------------------------------------===//
// Identifier uniquing