[Mlir-commits] [mlir] 74170a3 - Use rewriter in SCFToSPIRV conversion.

Tres Popp llvmlistbot at llvm.org
Thu Nov 19 08:50:24 PST 2020


Author: Tres Popp
Date: 2020-11-19T17:50:14+01:00
New Revision: 74170a3aeff116d81c5a5f9476c83429da8fdc82

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

LOG: Use rewriter in SCFToSPIRV conversion.

Additionally, clear a data structure to ensure a proper state if multiple conversion attempts are needed.

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

Added: 
    

Modified: 
    mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
index 5f452f728dc7..c3a63e0add49 100644
--- a/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
+++ b/mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
@@ -96,6 +96,9 @@ static void replaceSCFOutputValue(ScfOp scfOp, OpTy newOp,
 
   Location loc = scfOp.getLoc();
   auto &allocas = scfToSPIRVContext->outputVars[newOp];
+  // Clearing the allocas is necessary in case a dialect conversion path failed
+  // previously, and this is the second attempt of this conversion.
+  allocas.clear();
   SmallVector<Value, 8> resultValue;
   for (Type convertedType : returnTypes) {
     auto pointerType =
@@ -214,12 +217,13 @@ IfOpConversion::matchAndRewrite(scf::IfOp ifOp, ArrayRef<Value> operands,
   auto selectionControl = rewriter.getI32IntegerAttr(
       static_cast<uint32_t>(spirv::SelectionControl::None));
   auto selectionOp = rewriter.create<spirv::SelectionOp>(loc, selectionControl);
-  selectionOp.addMergeBlock();
-  auto *mergeBlock = selectionOp.getMergeBlock();
+  auto *mergeBlock =
+      rewriter.createBlock(&selectionOp.body(), selectionOp.body().end());
+  rewriter.create<spirv::MergeOp>(loc);
 
   OpBuilder::InsertionGuard guard(rewriter);
-  auto *selectionHeaderBlock = new Block();
-  selectionOp.body().getBlocks().push_front(selectionHeaderBlock);
+  auto *selectionHeaderBlock =
+      rewriter.createBlock(&selectionOp.body().front());
 
   // Inline `then` region before the merge block and branch to it.
   auto &thenRegion = ifOp.thenRegion();


        


More information about the Mlir-commits mailing list