[mlir][llvm] Add assertion in LLVM IR import (NFC).
authorTobias Gysi <tobias.gysi@nextsilicon.com>
Thu, 27 Apr 2023 05:45:46 +0000 (05:45 +0000)
committerTobias Gysi <tobias.gysi@nextsilicon.com>
Thu, 27 Apr 2023 05:52:36 +0000 (05:52 +0000)
This revision adds an assertion to convertConstantExpr to ensure the
function is not called if the constant has been converted before.

This is a follow up for https://reviews.llvm.org/D149247.

Reviewed By: victor-eds

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

mlir/lib/Target/LLVMIR/ModuleImport.cpp

index 64d4843f06388db23c36930b4ead9420467d5c33..5c585e7104b67601098ca6ad7243dc8ed671768d 100644 (file)
@@ -1024,10 +1024,15 @@ FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) {
 }
 
 FailureOr<Value> ModuleImport::convertConstantExpr(llvm::Constant *constant) {
+  // Only call the function for constants that have not been translated before
+  // since it updates the constant insertion point assuming the converted
+  // constant has been introduced at the end of the constant section.
+  assert(!valueMapping.contains(constant) &&
+         "expected constant has not been converted before");
   assert(constantInsertionBlock &&
          "expected the constant insertion block to be non-null");
 
-  // Insert the constant after the last one or at the start or the entry block.
+  // Insert the constant after the last one or at the start of the entry block.
   OpBuilder::InsertionGuard guard(builder);
   if (!constantInsertionOp)
     builder.setInsertionPointToStart(constantInsertionBlock);