[MLIR][NFC] Eliminate .getBlocks() when not needed
authorRahul Joshi <jurahul@google.com>
Fri, 19 Jun 2020 19:33:21 +0000 (12:33 -0700)
committerRahul Joshi <jurahul@google.com>
Fri, 19 Jun 2020 21:16:21 +0000 (14:16 -0700)
Differential Revision: https://reviews.llvm.org/D82229

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
mlir/lib/Dialect/LLVMIR/Transforms/LegalizeForExport.cpp
mlir/lib/ExecutionEngine/JitRunner.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/lib/Transforms/LoopInvariantCodeMotion.cpp

index 6e45241..13c5ed8 100644 (file)
@@ -219,19 +219,19 @@ void LaunchOp::build(OpBuilder &builder, OperationState &result,
 
 KernelDim3 LaunchOp::getBlockIds() {
   assert(!body().empty() && "LaunchOp body must not be empty.");
-  auto args = body().getBlocks().front().getArguments();
+  auto args = body().front().getArguments();
   return KernelDim3{args[0], args[1], args[2]};
 }
 
 KernelDim3 LaunchOp::getThreadIds() {
   assert(!body().empty() && "LaunchOp body must not be empty.");
-  auto args = body().getBlocks().front().getArguments();
+  auto args = body().front().getArguments();
   return KernelDim3{args[3], args[4], args[5]};
 }
 
 KernelDim3 LaunchOp::getGridSize() {
   assert(!body().empty() && "LaunchOp body must not be empty.");
-  auto args = body().getBlocks().front().getArguments();
+  auto args = body().front().getArguments();
   return KernelDim3{args[6], args[7], args[8]};
 }
 
index ad40017..3dec1d1 100644 (file)
@@ -50,7 +50,7 @@ static void ensureDistinctSuccessors(Block &bb) {
 
 void mlir::LLVM::ensureDistinctSuccessors(Operation *op) {
   op->walk([](LLVMFuncOp f) {
-    for (auto &bb : f.getBlocks()) {
+    for (auto &bb : f) {
       ::ensureDistinctSuccessors(bb);
     }
   });
index 436ad72..7959183 100644 (file)
@@ -167,7 +167,7 @@ static Error compileAndExecuteVoidFunction(
     Options &options, ModuleOp module, StringRef entryPoint,
     std::function<llvm::Error(llvm::Module *)> transformer) {
   auto mainFunction = module.lookupSymbol<LLVM::LLVMFuncOp>(entryPoint);
-  if (!mainFunction || mainFunction.getBlocks().empty())
+  if (!mainFunction || mainFunction.empty())
     return make_string_error("entry point not found");
   void *empty = nullptr;
   return compileAndExecute(options, module, entryPoint, transformer, &empty);
index 32880a9..8e022f5 100644 (file)
@@ -611,7 +611,7 @@ static llvm::SetVector<Block *> topologicalSort(LLVMFuncOp f) {
   // predecessors), add it to the list and traverse its successors in DFS
   // preorder.
   llvm::SetVector<Block *> blocks;
-  for (Block &b : f.getBlocks()) {
+  for (Block &b : f) {
     if (blocks.count(&b) == 0)
       topologicalSortImpl(blocks, &b);
   }
index 0a78cb4..9386653 100644 (file)
@@ -65,7 +65,7 @@ static bool canBeHoisted(Operation *op,
   // Recurse into the regions for this op and check whether the contained ops
   // can be hoisted.
   for (auto &region : op->getRegions()) {
-    for (auto &block : region.getBlocks()) {
+    for (auto &block : region) {
       for (auto &innerOp : block.without_terminator())
         if (!canBeHoisted(&innerOp, definedOutside))
           return false;