Index: mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -691,8 +691,8 @@ // FIXME: Support uses of SubtargetData. Currently inbounds GEPs, fast-math // flags and call / operand attributes are not supported. Location loc = processDebugLoc(inst->getDebugLoc(), inst); - Value &v = instMap[inst]; - assert(!v && "processInstruction must be called only once per instruction!"); + assert(!instMap.count(inst) && + "processInstruction must be called only once per instruction!"); switch (inst->getOpcode()) { default: return emitError(loc) << "unknown instruction: " << diag(*inst); @@ -750,7 +750,7 @@ } Operation *op = b.create(state); if (!inst->getType()->isVoidTy()) - v = op->getResult(0); + instMap[inst] = op->getResult(0); return success(); } case llvm::Instruction::Alloca: { @@ -759,7 +759,8 @@ return failure(); auto *allocaInst = cast(inst); - v = b.create(loc, processType(inst->getType()), + instMap[inst] = + b.create(loc, processType(inst->getType()), processType(allocaInst->getAllocatedType()), size, allocaInst->getAlign().value()); return success(); @@ -769,7 +770,7 @@ Value rhs = processValue(inst->getOperand(1)); if (!lhs || !rhs) return failure(); - v = b.create( + instMap[inst] = b.create( loc, getICmpPredicate(cast(inst)->getPredicate()), lhs, rhs); return success(); @@ -808,7 +809,7 @@ Type type = processType(inst->getType()); if (!type) return failure(); - v = b.getInsertionBlock()->addArgument( + instMap[inst] = b.getInsertionBlock()->addArgument( type, processDebugLoc(inst->getDebugLoc(), inst)); return success(); } @@ -842,7 +843,7 @@ op = b.create(loc, tys, ops); } if (!ci->getType()->isVoidTy()) - v = op->getResult(0); + instMap[inst] = op->getResult(0); return success(); } case llvm::Instruction::LandingPad: { @@ -856,7 +857,7 @@ if (!ty) return failure(); - v = b.create(loc, ty, lpi->isCleanup(), ops); + instMap[inst] = b.create(loc, ty, lpi->isCleanup(), ops); return success(); } case llvm::Instruction::Invoke: { @@ -889,7 +890,7 @@ } if (!ii->getType()->isVoidTy()) - v = op->getResult(0); + instMap[inst] = op->getResult(0); return success(); } case llvm::Instruction::Fence: { @@ -938,8 +939,8 @@ Type type = processType(inst->getType()); if (!type) return failure(); - v = b.create(loc, type, sourceElementType, basePtr, dynamicIndices, - staticIndices); + instMap[inst] = b.create(loc, type, sourceElementType, basePtr, + dynamicIndices, staticIndices); return success(); } } Index: mlir/test/Target/LLVMIR/Import/incorrect-instmap-assignment.ll =================================================================== --- /dev/null +++ mlir/test/Target/LLVMIR/Import/incorrect-instmap-assignment.ll @@ -0,0 +1,138 @@ +; RUN: mlir-translate --import-llvm %s | FileCheck %s + +; This test file is meant to saturate `instMap` used in the translation +; and force it to resize. The code is a reduction created by bugpoint. + +; This test is primarily used to make sure it doesn't bail out with non-zero +; exit code. Thus, we only wrote minimum level of checks. + +%struct.Sqlite3Config.9.23.37 = type { i32, i8, i8, i8, i8, i8, i8, i32, i32, i32, i32, i32, %struct.sqlite3_mem_methods.0.14.28, %struct.sqlite3_mutex_methods.5.19.33, %struct.sqlite3_pcache_methods2.8.22.36, i8*, i32, i32, i32, i64, i64, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.sqlite3_mutex.4.18.32*, void (i8*, i32, i8*)*, i8*, i64, i32 (i32)*, i32, i32, i32, i32 } +%struct.sqlite3_mem_methods.0.14.28 = type { i8* (i32)*, void (i8*)*, i8* (i8*, i32)*, i32 (i8*)*, i32 (i32)*, i32 (i8*)*, void (i8*)*, i8* } +%struct.sqlite3_mutex_methods.5.19.33 = type { i32 ()*, i32 ()*, %struct.sqlite3_mutex.4.18.32* (i32)*, void (%struct.sqlite3_mutex.4.18.32*)*, void (%struct.sqlite3_mutex.4.18.32*)*, i32 (%struct.sqlite3_mutex.4.18.32*)*, void (%struct.sqlite3_mutex.4.18.32*)*, i32 (%struct.sqlite3_mutex.4.18.32*)*, i32 (%struct.sqlite3_mutex.4.18.32*)* } +%struct.sqlite3_pcache_methods2.8.22.36 = type { i32, i8*, i32 (i8*)*, void (i8*)*, %struct.sqlite3_pcache.6.20.34* (i32, i32, i32)*, void (%struct.sqlite3_pcache.6.20.34*, i32)*, i32 (%struct.sqlite3_pcache.6.20.34*)*, %struct.sqlite3_pcache_page.7.21.35* (%struct.sqlite3_pcache.6.20.34*, i32, i32)*, void (%struct.sqlite3_pcache.6.20.34*, %struct.sqlite3_pcache_page.7.21.35*, i32)*, void (%struct.sqlite3_pcache.6.20.34*, %struct.sqlite3_pcache_page.7.21.35*, i32, i32)*, void (%struct.sqlite3_pcache.6.20.34*, i32)*, void (%struct.sqlite3_pcache.6.20.34*)*, void (%struct.sqlite3_pcache.6.20.34*)* } +%struct.sqlite3_pcache.6.20.34 = type opaque +%struct.sqlite3_pcache_page.7.21.35 = type { i8*, i8* } +%struct.sqlite3_mutex.4.18.32 = type { %union.pthread_mutex_t.3.17.31 } +%union.pthread_mutex_t.3.17.31 = type { %struct.__pthread_mutex_s.2.16.30 } +%struct.__pthread_mutex_s.2.16.30 = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list.1.15.29 } +%struct.__pthread_internal_list.1.15.29 = type { %struct.__pthread_internal_list.1.15.29*, %struct.__pthread_internal_list.1.15.29* } +%struct.sqlite3_vfs.12.26.40 = type { i32, i32, i32, %struct.sqlite3_vfs.12.26.40*, i8*, i8*, i32 (%struct.sqlite3_vfs.12.26.40*, i8*, %struct.sqlite3_file.11.25.39*, i32, i32*)*, i32 (%struct.sqlite3_vfs.12.26.40*, i8*, i32)*, i32 (%struct.sqlite3_vfs.12.26.40*, i8*, i32, i32*)*, i32 (%struct.sqlite3_vfs.12.26.40*, i8*, i32, i8*)*, i8* (%struct.sqlite3_vfs.12.26.40*, i8*)*, void (%struct.sqlite3_vfs.12.26.40*, i32, i8*)*, void ()* (%struct.sqlite3_vfs.12.26.40*, i8*, i8*)*, void (%struct.sqlite3_vfs.12.26.40*, i8*)*, i32 (%struct.sqlite3_vfs.12.26.40*, i32, i8*)*, i32 (%struct.sqlite3_vfs.12.26.40*, i32)*, i32 (%struct.sqlite3_vfs.12.26.40*, double*)*, i32 (%struct.sqlite3_vfs.12.26.40*, i32, i8*)*, i32 (%struct.sqlite3_vfs.12.26.40*, i64*)*, i32 (%struct.sqlite3_vfs.12.26.40*, i8*, void ()*)*, void ()* (%struct.sqlite3_vfs.12.26.40*, i8*)*, i8* (%struct.sqlite3_vfs.12.26.40*, i8*)* } +%struct.sqlite3_file.11.25.39 = type { %struct.sqlite3_io_methods.10.24.38* } +%struct.sqlite3_io_methods.10.24.38 = type { i32, i32 (%struct.sqlite3_file.11.25.39*)*, i32 (%struct.sqlite3_file.11.25.39*, i8*, i32, i64)*, i32 (%struct.sqlite3_file.11.25.39*, i8*, i32, i64)*, i32 (%struct.sqlite3_file.11.25.39*, i64)*, i32 (%struct.sqlite3_file.11.25.39*, i32)*, i32 (%struct.sqlite3_file.11.25.39*, i64*)*, i32 (%struct.sqlite3_file.11.25.39*, i32)*, i32 (%struct.sqlite3_file.11.25.39*, i32)*, i32 (%struct.sqlite3_file.11.25.39*, i32*)*, i32 (%struct.sqlite3_file.11.25.39*, i32, i8*)*, i32 (%struct.sqlite3_file.11.25.39*)*, i32 (%struct.sqlite3_file.11.25.39*)*, i32 (%struct.sqlite3_file.11.25.39*, i32, i32, i32, i8**)*, i32 (%struct.sqlite3_file.11.25.39*, i32, i32, i32)*, void (%struct.sqlite3_file.11.25.39*)*, i32 (%struct.sqlite3_file.11.25.39*, i32)*, i32 (%struct.sqlite3_file.11.25.39*, i64, i32, i8**)*, i32 (%struct.sqlite3_file.11.25.39*, i64, i8*)* } +%struct.sqlite3PrngType.13.27.41 = type { i8, i8, i8, [256 x i8] } + +@sqlite3Config = external hidden global %struct.Sqlite3Config.9.23.37, align 8 +@vfsList = external hidden unnamed_addr global %struct.sqlite3_vfs.12.26.40*, align 8 +@sqlite3Prng = external hidden unnamed_addr global %struct.sqlite3PrngType.13.27.41, align 1 + +; Function Attrs: argmemonly nofree nosync nounwind willreturn +declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0 + +; Function Attrs: argmemonly nofree nosync nounwind willreturn +declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0 + +declare dso_local i32 @sqlite3_initialize() local_unnamed_addr #1 + +; CHECK: llvm.func @sqlite3_randomness(%arg0: i32, %arg1: !llvm.ptr) +define dso_local void @sqlite3_randomness(i32 %0, i8* %1) #1 { + br i1 undef, label %3, label %37 + +3: ; preds = %2 + br i1 undef, label %6, label %4 + +4: ; preds = %3 + br i1 undef, label %6, label %5 + +5: ; preds = %4 + br label %6 + +6: ; preds = %5, %4, %3 + br i1 undef, label %7, label %9 + +7: ; preds = %6 + br i1 undef, label %37, label %8 + +8: ; preds = %7 + br label %37 + +9: ; preds = %6 + br i1 undef, label %10, label %30 + +10: ; preds = %9 + br i1 undef, label %12, label %11 + +11: ; preds = %10 + store i8 0, i8* getelementptr inbounds (%struct.sqlite3PrngType.13.27.41, %struct.sqlite3PrngType.13.27.41* @sqlite3Prng, i64 0, i32 1), align 1 + br label %20 + +12: ; preds = %10 + %13 = icmp eq i8 undef, 0 + br i1 %13, label %17, label %14 + +14: ; preds = %12 + %15 = load %struct.sqlite3_mutex.4.18.32* (i32)*, %struct.sqlite3_mutex.4.18.32* (i32)** getelementptr inbounds (%struct.Sqlite3Config.9.23.37, %struct.Sqlite3Config.9.23.37* @sqlite3Config, i64 0, i32 13, i32 2), align 8 + %16 = icmp eq %struct.sqlite3_mutex.4.18.32* undef, null + br i1 %16, label %17, label %18 + +17: ; preds = %14, %12 + br label %19 + +18: ; preds = %14 + br label %19 + +19: ; preds = %18, %17 + br i1 undef, label %20, label %21 + +20: ; preds = %19, %11 + br label %25 + +21: ; preds = %19 + %22 = load i32, i32* getelementptr inbounds (%struct.Sqlite3Config.9.23.37, %struct.Sqlite3Config.9.23.37* @sqlite3Config, i64 0, i32 41), align 4 + br i1 undef, label %24, label %23 + +23: ; preds = %21 + br label %25 + +24: ; preds = %21 + br label %25 + +25: ; preds = %24, %23, %20 + store <16 x i8> , <16 x i8>* bitcast (i8* getelementptr inbounds (%struct.sqlite3PrngType.13.27.41, %struct.sqlite3PrngType.13.27.41* @sqlite3Prng, i64 0, i32 3, i64 128) to <16 x i8>*), align 1 + store <16 x i8> , <16 x i8>* bitcast (i8* getelementptr inbounds (%struct.sqlite3PrngType.13.27.41, %struct.sqlite3PrngType.13.27.41* @sqlite3Prng, i64 0, i32 3, i64 192) to <16 x i8>*), align 1 + br label %26 + +26: ; preds = %26, %25 + %27 = load i8, i8* undef, align 1 + store i8 undef, i8* undef, align 1 + %28 = add nuw nsw i64 undef, 2 + br i1 undef, label %29, label %26 + +29: ; preds = %26 + br label %30 + +30: ; preds = %30, %29, %9 + %31 = getelementptr inbounds %struct.sqlite3PrngType.13.27.41, %struct.sqlite3PrngType.13.27.41* @sqlite3Prng, i64 0, i32 3, i64 undef + %32 = load i8, i8* %31, align 1 + %33 = getelementptr inbounds %struct.sqlite3PrngType.13.27.41, %struct.sqlite3PrngType.13.27.41* @sqlite3Prng, i64 0, i32 3, i64 undef + br i1 undef, label %34, label %30 + +34: ; preds = %30 + br i1 undef, label %37, label %35 + +35: ; preds = %34 + %36 = load void (%struct.sqlite3_mutex.4.18.32*)*, void (%struct.sqlite3_mutex.4.18.32*)** getelementptr inbounds (%struct.Sqlite3Config.9.23.37, %struct.Sqlite3Config.9.23.37* @sqlite3Config, i64 0, i32 13, i32 6), align 8 + call void %36(%struct.sqlite3_mutex.4.18.32* nonnull undef) #3 + br label %37 + +37: ; preds = %35, %34, %8, %7, %2 + ret void +} + +; Function Attrs: argmemonly nofree nounwind willreturn writeonly +declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #2 + +attributes #0 = { argmemonly nofree nosync nounwind willreturn } +attributes #1 = { "use-soft-float"="false" } +attributes #2 = { argmemonly nofree nounwind willreturn writeonly } +attributes #3 = { nounwind } +