NFC: Remove the explicit context from Operation::create and OperationState.
authorRiver Riddle <riverriddle@google.com>
Tue, 27 Aug 2019 00:34:06 +0000 (17:34 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Tue, 27 Aug 2019 00:34:48 +0000 (17:34 -0700)
The context can easily be recovered from the Location in these situations.

PiperOrigin-RevId: 265578574

mlir/include/mlir/IR/Operation.h
mlir/include/mlir/IR/OperationSupport.h
mlir/lib/IR/Operation.cpp
mlir/lib/IR/OperationSupport.cpp
mlir/lib/Parser/Parser.cpp
mlir/lib/Transforms/DialectConversion.cpp
mlir/test/lib/TestDialect/TestOps.td
mlir/unittests/IR/OperationSupportTest.cpp

index db10a1a..d61dc06 100644 (file)
@@ -56,7 +56,7 @@ public:
                            ArrayRef<Type> resultTypes,
                            ArrayRef<NamedAttribute> attributes,
                            ArrayRef<Block *> successors, unsigned numRegions,
-                           bool resizableOperandList, MLIRContext *context);
+                           bool resizableOperandList);
 
   /// Overload of create that takes an existing NamedAttributeList to avoid
   /// unnecessarily uniquing a list of attributes.
@@ -65,7 +65,7 @@ public:
                            ArrayRef<Type> resultTypes,
                            const NamedAttributeList &attributes,
                            ArrayRef<Block *> successors, unsigned numRegions,
-                           bool resizableOperandList, MLIRContext *context);
+                           bool resizableOperandList);
 
   /// Create a new Operation from the fields stored in `state`.
   static Operation *create(const OperationState &state);
@@ -526,7 +526,7 @@ public:
 private:
   Operation(Location location, OperationName name, unsigned numResults,
             unsigned numSuccessors, unsigned numRegions,
-            const NamedAttributeList &attributes, MLIRContext *context);
+            const NamedAttributeList &attributes);
 
   // Operations are deleted through the destroy() member because they are
   // allocated with malloc.
index 4871c85..fd5e969 100644 (file)
@@ -255,7 +255,6 @@ inline llvm::hash_code hash_value(OperationName arg) {
 /// be used as a temporary object on the stack.  It is generally unwise to put
 /// this in a collection.
 struct OperationState {
-  MLIRContext *const context;
   Location location;
   OperationName name;
   SmallVector<Value *, 4> operands;
index fa2ce8c..205d561 100644 (file)
@@ -105,10 +105,10 @@ Operation *Operation::create(Location location, OperationName name,
                              ArrayRef<Type> resultTypes,
                              ArrayRef<NamedAttribute> attributes,
                              ArrayRef<Block *> successors, unsigned numRegions,
-                             bool resizableOperandList, MLIRContext *context) {
+                             bool resizableOperandList) {
   return create(location, name, operands, resultTypes,
                 NamedAttributeList(attributes), successors, numRegions,
-                resizableOperandList, context);
+                resizableOperandList);
 }
 
 /// Create a new Operation from operation state.
@@ -116,7 +116,7 @@ Operation *Operation::create(const OperationState &state) {
   unsigned numRegions = state.regions.size();
   Operation *op = create(state.location, state.name, state.operands,
                          state.types, state.attributes, state.successors,
-                         numRegions, state.resizableOperandList, state.context);
+                         numRegions, state.resizableOperandList);
   for (unsigned i = 0; i < numRegions; ++i)
     if (state.regions[i])
       op->getRegion(i).takeBody(*state.regions[i]);
@@ -130,7 +130,7 @@ Operation *Operation::create(Location location, OperationName name,
                              ArrayRef<Type> resultTypes,
                              const NamedAttributeList &attributes,
                              ArrayRef<Block *> successors, unsigned numRegions,
-                             bool resizableOperandList, MLIRContext *context) {
+                             bool resizableOperandList) {
   unsigned numSuccessors = successors.size();
 
   // Input operands are nullptr-separated for each successor, the null operands
@@ -148,9 +148,8 @@ Operation *Operation::create(Location location, OperationName name,
   void *rawMem = malloc(byteSize);
 
   // Create the new Operation.
-  auto op =
-      ::new (rawMem) Operation(location, name, resultTypes.size(),
-                               numSuccessors, numRegions, attributes, context);
+  auto op = ::new (rawMem) Operation(location, name, resultTypes.size(),
+                                     numSuccessors, numRegions, attributes);
 
   assert((numSuccessors == 0 || !op->isKnownNonTerminator()) &&
          "unexpected successors in a non-terminator operation");
@@ -229,7 +228,7 @@ Operation *Operation::create(Location location, OperationName name,
 
 Operation::Operation(Location location, OperationName name, unsigned numResults,
                      unsigned numSuccessors, unsigned numRegions,
-                     const NamedAttributeList &attributes, MLIRContext *context)
+                     const NamedAttributeList &attributes)
     : location(location), numResults(numResults), numSuccs(numSuccessors),
       numRegions(numRegions), name(name), attrs(attributes) {}
 
@@ -576,9 +575,9 @@ Operation *Operation::cloneWithoutRegions(BlockAndValueMapping &mapper) {
 
   SmallVector<Type, 8> resultTypes(getResultTypes());
   unsigned numRegions = getNumRegions();
-  auto *newOp = Operation::create(getLoc(), getName(), operands, resultTypes,
-                                  attrs, successors, numRegions,
-                                  hasResizableOperandsList(), getContext());
+  auto *newOp =
+      Operation::create(getLoc(), getName(), operands, resultTypes, attrs,
+                        successors, numRegions, hasResizableOperandsList());
 
   // Remember the mapping of any results.
   for (unsigned i = 0, e = getNumResults(); i != e; ++i)
index fdc9c03..ab665f5 100644 (file)
@@ -30,11 +30,10 @@ using namespace mlir;
 //===----------------------------------------------------------------------===//
 
 OperationState::OperationState(Location location, StringRef name)
-    : context(location->getContext()), location(location),
-      name(name, location->getContext()) {}
+    : location(location), name(name, location->getContext()) {}
 
 OperationState::OperationState(Location location, OperationName name)
-    : context(location->getContext()), location(location), name(name) {}
+    : location(location), name(name) {}
 
 OperationState::OperationState(Location location, StringRef name,
                                ArrayRef<Value *> operands, ArrayRef<Type> types,
@@ -42,15 +41,13 @@ OperationState::OperationState(Location location, StringRef name,
                                ArrayRef<Block *> successors,
                                MutableArrayRef<std::unique_ptr<Region>> regions,
                                bool resizableOperandList)
-    : context(location->getContext()), location(location),
-      name(name, location->getContext()),
+    : location(location), name(name, location->getContext()),
       operands(operands.begin(), operands.end()),
       types(types.begin(), types.end()),
       attributes(attributes.begin(), attributes.end()),
       successors(successors.begin(), successors.end()) {
-  for (std::unique_ptr<Region> &r : regions) {
+  for (std::unique_ptr<Region> &r : regions)
     this->regions.push_back(std::move(r));
-  }
 }
 
 Region *OperationState::addRegion() {
index 2e61616..c377ccd 100644 (file)
@@ -2984,7 +2984,7 @@ Value *OperationParser::createForwardRefPlaceholder(SMLoc loc, Type type) {
   auto *op = Operation::create(
       getEncodedSourceLocation(loc), name, /*operands=*/{}, type,
       /*attributes=*/llvm::None, /*successors=*/{}, /*numRegions=*/0,
-      /*resizableOperandList=*/false, getContext());
+      /*resizableOperandList=*/false);
   forwardRefPlaceholders[op->getResult(0)] = loc;
   return op->getResult(0);
 }
index adbed67..903e13b 100644 (file)
@@ -265,7 +265,7 @@ Operation *ArgConverter::convertArgument(BlockArgument *origArg,
 /// given input and result types.
 Operation *ArgConverter::createCast(ArrayRef<Value *> inputs, Type outputType) {
   return Operation::create(loc, castOpName, inputs, outputType, llvm::None,
-                           llvm::None, 0, false, outputType.getContext());
+                           llvm::None, 0, false);
 }
 
 //===----------------------------------------------------------------------===//
index fd2d235..e2fdf37 100644 (file)
@@ -109,8 +109,9 @@ def TypeStringAttrWithTypeOp : TEST_Op<"string_attr_with_type"> {
   let printer = [{ *p << getAttr("attr"); }];
   let parser = [{
     Attribute attr;
-    Type stringType = OpaqueType::get(Identifier::get("foo", result->context),
-                                      "string", result->context);
+    Type stringType = OpaqueType::get(Identifier::get("foo",
+                                      result->getContext()), "string",
+                                      result->getContext());
     return parser->parseAttribute(attr, stringType, "attr", result->attributes);
   }];
 }
index cb0801e..2cebba6 100644 (file)
@@ -29,7 +29,7 @@ Operation *createOp(MLIRContext *context, bool resizableOperands,
                     ArrayRef<Type> resultTypes = llvm::None) {
   return Operation::create(
       UnknownLoc::get(context), OperationName("foo.bar", context), operands,
-      resultTypes, llvm::None, llvm::None, 0, resizableOperands, context);
+      resultTypes, llvm::None, llvm::None, 0, resizableOperands);
 }
 
 TEST(OperandStorageTest, NonResizable) {