[Mlir-commits] [mlir] c00b7c8 - [mlir][llvm] Add assertion in LLVM IR import (NFC).

Tobias Gysi llvmlistbot at llvm.org
Wed Apr 26 22:55:51 PDT 2023


Author: Tobias Gysi
Date: 2023-04-27T05:52:36Z
New Revision: c00b7c84c7cb1d528464bf68305fd23a9755768c

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

LOG: [mlir][llvm] Add assertion in LLVM IR import (NFC).

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

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/ModuleImport.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 64d4843f06388..5c585e7104b67 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -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);


        


More information about the Mlir-commits mailing list