[Mlir-commits] [mlir] ecba7c5 - [mlir] Rename FunctionOpInterface::getBody to getFunctionBody

River Riddle llvmlistbot at llvm.org
Mon Oct 3 12:00:13 PDT 2022


Author: River Riddle
Date: 2022-10-03T11:53:57-07:00
New Revision: ecba7c58bd69c18d8127676737040a4d8f25fc83

URL: https://github.com/llvm/llvm-project/commit/ecba7c58bd69c18d8127676737040a4d8f25fc83
DIFF: https://github.com/llvm/llvm-project/commit/ecba7c58bd69c18d8127676737040a4d8f25fc83.diff

LOG: [mlir] Rename FunctionOpInterface::getBody to getFunctionBody

This is much more explicit, and prevents annoying conflicts with op
specific accessors (which may have a different contract). This is similar
to the past rename of getType -> getFunctionType,

Fixes #58030

Differential Revision: https://reviews.llvm.org/D135007

Added: 
    

Modified: 
    mlir/include/mlir/IR/FunctionInterfaces.td
    mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp
    mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
    mlir/lib/Transforms/Utils/DialectConversion.cpp
    mlir/test/lib/IR/TestMatchers.cpp
    mlir/test/lib/Pass/TestPassManager.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/FunctionInterfaces.td b/mlir/include/mlir/IR/FunctionInterfaces.td
index 0dba0f7afc7f..e6165af5a721 100644
--- a/mlir/include/mlir/IR/FunctionInterfaces.td
+++ b/mlir/include/mlir/IR/FunctionInterfaces.td
@@ -169,36 +169,36 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface"> {
     bool isExternal() { return empty(); }
 
     /// Return the region containing the body of this function.
-    Region &getBody() { return $_op->getRegion(0); }
+    Region &getFunctionBody() { return $_op->getRegion(0); }
 
     /// Delete all blocks from this function.
     void eraseBody() {
-      getBody().dropAllReferences();
-      getBody().getBlocks().clear();
+      getFunctionBody().dropAllReferences();
+      getFunctionBody().getBlocks().clear();
     }
 
     /// Return the list of blocks within the function body.
-    BlockListType &getBlocks() { return getBody().getBlocks(); }
+    BlockListType &getBlocks() { return getFunctionBody().getBlocks(); }
 
-    iterator begin() { return getBody().begin(); }
-    iterator end() { return getBody().end(); }
-    reverse_iterator rbegin() { return getBody().rbegin(); }
-    reverse_iterator rend() { return getBody().rend(); }
+    iterator begin() { return getFunctionBody().begin(); }
+    iterator end() { return getFunctionBody().end(); }
+    reverse_iterator rbegin() { return getFunctionBody().rbegin(); }
+    reverse_iterator rend() { return getFunctionBody().rend(); }
 
     /// Returns true if this function has no blocks within the body.
-    bool empty() { return getBody().empty(); }
+    bool empty() { return getFunctionBody().empty(); }
 
     /// Push a new block to the back of the body region.
-    void push_back(Block *block) { getBody().push_back(block); }
+    void push_back(Block *block) { getFunctionBody().push_back(block); }
 
     /// Push a new block to the front of the body region.
-    void push_front(Block *block) { getBody().push_front(block); }
+    void push_front(Block *block) { getFunctionBody().push_front(block); }
 
     /// Return the last block in the body region.
-    Block &back() { return getBody().back(); }
+    Block &back() { return getFunctionBody().back(); }
 
     /// Return the first block in the body region.
-    Block &front() { return getBody().front(); }
+    Block &front() { return getFunctionBody().front(); }
 
     /// Add an entry block to an empty function, and set up the block arguments
     /// to match the signature of the function. The newly inserted entry block
@@ -280,13 +280,13 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface"> {
 
     /// Returns the entry block function argument at the given index.
     BlockArgument getArgument(unsigned idx) {
-      return getBody().getArgument(idx);
+      return getFunctionBody().getArgument(idx);
     }
 
     /// Support argument iteration.
-    args_iterator args_begin() { return getBody().args_begin(); }
-    args_iterator args_end() { return getBody().args_end(); }
-    BlockArgListType getArguments() { return getBody().getArguments(); }
+    args_iterator args_begin() { return getFunctionBody().args_begin(); }
+    args_iterator args_end() { return getFunctionBody().args_end(); }
+    BlockArgListType getArguments() { return getFunctionBody().getArguments(); }
 
     /// Insert a single argument of type `argType` with attributes `argAttrs` and
     /// location `argLoc` at `argIndex`.

diff  --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp
index 61f7f9f9e26a..48957dfa377c 100644
--- a/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp
+++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp
@@ -40,8 +40,8 @@ struct ForLoopMapper : public impl::ConvertAffineForToGPUBase<ForLoopMapper> {
   }
 
   void runOnOperation() override {
-    for (Operation &op :
-         llvm::make_early_inc_range(getOperation().getBody().getOps())) {
+    for (Operation &op : llvm::make_early_inc_range(
+             getOperation().getFunctionBody().getOps())) {
       if (auto forOp = dyn_cast<AffineForOp>(&op)) {
         if (failed(convertAffineLoopNestToGPULaunch(forOp, numBlockDims,
                                                     numThreadDims)))

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
index 2a980ea96b5a..03b752626031 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
@@ -106,7 +106,7 @@ struct FunctionNonEntryBlockConversion
   matchAndRewrite(FunctionOpInterface op, ArrayRef<Value> operands,
                   ConversionPatternRewriter &rewriter) const override {
     rewriter.startRootUpdate(op);
-    Region &region = op.getBody();
+    Region &region = op.getFunctionBody();
     SmallVector<TypeConverter::SignatureConversion, 2> conversions;
 
     for (Block &block : llvm::drop_begin(region, 1)) {
@@ -461,7 +461,7 @@ struct LinalgDetensorize
           opsToDetensor.insert(genericOp);
       });
 
-      for (Block &block : llvm::drop_begin(func.getBody(), 1))
+      for (Block &block : llvm::drop_begin(func.getFunctionBody(), 1))
         for (BlockArgument blockArgument : block.getArguments())
           blockArgsToDetensor.insert(blockArgument);
     }
@@ -500,7 +500,7 @@ struct LinalgDetensorize
       // boundaries, which we conservatively approximate as all function
       // signatures.
       if (auto funcOp = dyn_cast<FunctionOpInterface>(op)) {
-        Region &body = funcOp.getBody();
+        Region &body = funcOp.getFunctionBody();
         return llvm::all_of(llvm::drop_begin(body, 1), [&](Block &block) {
           return !llvm::any_of(
               blockArgsToDetensor, [&](BlockArgument blockArgument) {

diff  --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index ccbfc78d7090..505127c45965 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -3077,8 +3077,8 @@ struct FunctionOpInterfaceSignatureConversion : public ConversionPattern {
     SmallVector<Type, 1> newResults;
     if (failed(typeConverter->convertSignatureArgs(type.getInputs(), result)) ||
         failed(typeConverter->convertTypes(type.getResults(), newResults)) ||
-        failed(rewriter.convertRegionTypes(&funcOp.getBody(), *typeConverter,
-                                           &result)))
+        failed(rewriter.convertRegionTypes(&funcOp.getFunctionBody(),
+                                           *typeConverter, &result)))
       return failure();
 
     // Update the function signature in-place.

diff  --git a/mlir/test/lib/IR/TestMatchers.cpp b/mlir/test/lib/IR/TestMatchers.cpp
index 99eab3aa86dd..4f87517235e2 100644
--- a/mlir/test/lib/IR/TestMatchers.cpp
+++ b/mlir/test/lib/IR/TestMatchers.cpp
@@ -139,7 +139,7 @@ void test2(FunctionOpInterface f) {
       m_Op<arith::MulFOp>(a, m_Op<arith::AddFOp>(a, m_Constant(&floatAttr)));
   auto p1 = m_Op<arith::MulFOp>(a, m_Op<arith::AddFOp>(a, m_Constant()));
   // Last operation that is not the terminator.
-  Operation *lastOp = f.getBody().front().back().getPrevNode();
+  Operation *lastOp = f.getFunctionBody().front().back().getPrevNode();
   if (p.match(lastOp))
     llvm::outs()
         << "Pattern add(add(a, constant), a) matched and bound constant to: "

diff  --git a/mlir/test/lib/Pass/TestPassManager.cpp b/mlir/test/lib/Pass/TestPassManager.cpp
index b22bcaf2db44..a968d81e71e3 100644
--- a/mlir/test/lib/Pass/TestPassManager.cpp
+++ b/mlir/test/lib/Pass/TestPassManager.cpp
@@ -129,7 +129,7 @@ struct TestInvalidIRPass
       signalPassFailure();
     if (!emitInvalidIR)
       return;
-    OpBuilder b(getOperation().getBody());
+    OpBuilder b(getOperation().getFunctionBody());
     OperationState state(b.getUnknownLoc(), "test.any_attr_of_i32_str");
     b.create(state);
   }
@@ -156,7 +156,7 @@ struct TestInvalidParentPass
   }
   void runOnOperation() final {
     FunctionOpInterface op = getOperation();
-    OpBuilder b(getOperation().getBody());
+    OpBuilder b(op.getFunctionBody());
     b.create<test::TestCallOp>(op.getLoc(), TypeRange(), "some_unknown_func",
                                ValueRange());
   }


        


More information about the Mlir-commits mailing list