Integrate llvm-project and bump dependencies 20230405 (#12929)

* llvm-project: d3aed4f401fa
* mlir-mhlo: f762541041379eee1253e76b6787aa2b2e70a506
* tensorflow: 4f1dd6d5123f4eb6afc85fac36df09b4a8b49c83
diff --git a/compiler/src/iree/compiler/API/Internal/Embed.cpp b/compiler/src/iree/compiler/API/Internal/Embed.cpp
index aabd131..78f368b 100644
--- a/compiler/src/iree/compiler/API/Internal/Embed.cpp
+++ b/compiler/src/iree/compiler/API/Internal/Embed.cpp
@@ -538,7 +538,10 @@
 Invocation::Invocation(Session &session)
     : session(session), passManager(&session.context) {
   if (session.globalInit.usesCommandLine) {
-    mlir::applyPassManagerCLOptions(passManager);
+    if (failed(mlir::applyPassManagerCLOptions(passManager))) {
+      emitError(UnknownLoc::get(&session.context))
+          << "Failed to apply pass manager CL options";
+    }
     mlir::applyDefaultTimingPassManagerCLOptions(passManager);
   }
   passManager.addInstrumentation(std::make_unique<PassTracing>());
diff --git a/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp b/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp
index f31afe8..487e54a 100644
--- a/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp
+++ b/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp
@@ -209,7 +209,9 @@
   }
 
   PassManager passManager(context);
-  mlir::applyPassManagerCLOptions(passManager);
+  // TODO(12938): Handle or investigate failure result.
+  auto logicalRes = mlir::applyPassManagerCLOptions(passManager);
+  (void)logicalRes;
   mlir::applyDefaultTimingPassManagerCLOptions(passManager);
   passManager.addInstrumentation(std::make_unique<PassTracing>());
   auto &modulePasses = passManager.nest<IREE::VM::ModuleOp>();
diff --git a/compiler/src/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp b/compiler/src/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp
index 7c30edb..404de82 100644
--- a/compiler/src/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp
+++ b/compiler/src/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp
@@ -321,7 +321,9 @@
   }
 
   PassManager passManager(context);
-  mlir::applyPassManagerCLOptions(passManager);
+  if (failed(mlir::applyPassManagerCLOptions(passManager))) {
+    return moduleOp.emitError() << "Failed to apply pass manager CL options";
+  }
   mlir::applyDefaultTimingPassManagerCLOptions(passManager);
   auto &modulePasses = passManager.nest<IREE::VM::ModuleOp>();
 
diff --git a/integrations/tensorflow/WORKSPACE b/integrations/tensorflow/WORKSPACE
index 9653e87..531322e 100644
--- a/integrations/tensorflow/WORKSPACE
+++ b/integrations/tensorflow/WORKSPACE
@@ -7,7 +7,7 @@
 
 load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
 
-TENSORFLOW_COMMIT = "3fb52f183ff77b71e8de558b03ec92aa3011d447"
+TENSORFLOW_COMMIT = "4f1dd6d5123f4eb6afc85fac36df09b4a8b49c83"
 
 git_repository(
     name = "org_tensorflow",
diff --git a/integrations/tensorflow/iree-dialects/include/iree-dialects/Dialect/LinalgTransform/StructuredTransformOpsExt.td b/integrations/tensorflow/iree-dialects/include/iree-dialects/Dialect/LinalgTransform/StructuredTransformOpsExt.td
index c39d12f..c475e76 100644
--- a/integrations/tensorflow/iree-dialects/include/iree-dialects/Dialect/LinalgTransform/StructuredTransformOpsExt.td
+++ b/integrations/tensorflow/iree-dialects/include/iree-dialects/Dialect/LinalgTransform/StructuredTransformOpsExt.td
@@ -20,24 +20,31 @@
     [FunctionalStyleTransformOpTrait,
      MemoryEffectsOpInterface,
      DeclareOpInterfaceMethods<TransformOpInterface>]> {
-  let description = [{Indicates that the entire module should be converted
-  to the LLVM dialect. This is expected to be the last transformation in
-  a sequence.}];
+  let description = [{
+    Indicates that the entire targeted module should be converted
+    to the LLVM dialect. This is expected to be the last transformation in
+    a sequence.
+
+    #### Return modes
+
+    This operation consumes the `target` handle and produces the `transformed`
+    handle.
+  }];
 
   let arguments =
-    (ins DefaultValuedAttr<BoolAttr, "false">:$reassociate_fp_reductions,
+    (ins TransformHandleTypeInterface:$target,
+     DefaultValuedAttr<BoolAttr, "false">:$reassociate_fp_reductions,
      DefaultValuedAttr<BoolAttr, "false">:$enable_index_optimizations,
      DefaultValuedAttr<BoolAttr, "false">:$enable_arm_neon,
      DefaultValuedAttr<BoolAttr, "false">:$enable_arm_sve,
      DefaultValuedAttr<BoolAttr, "false">:$enable_amx,
      DefaultValuedAttr<BoolAttr, "false">:$enable_x86vector,
      DefaultValuedAttr<BoolAttr, "false">:$enable_async);
-
-  let assemblyFormat = "attr-dict";
+  let results = (outs TransformHandleTypeInterface:$transformed);
+  let assemblyFormat = "$target attr-dict `:` functional-type($target, results)";
   let cppNamespace = "mlir::transform_ext";
 }
 
-
 def RegisterMatchCallbacksOp :
     Op<Transform_Dialect, "iree.register_match_callbacks",
       [DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
diff --git a/integrations/tensorflow/iree-dialects/lib/Dialect/LinalgTransform/IR/StructuredTransformOpsExt.cpp b/integrations/tensorflow/iree-dialects/lib/Dialect/LinalgTransform/IR/StructuredTransformOpsExt.cpp
index 7a0f88a..ab71e3b 100644
--- a/integrations/tensorflow/iree-dialects/lib/Dialect/LinalgTransform/IR/StructuredTransformOpsExt.cpp
+++ b/integrations/tensorflow/iree-dialects/lib/Dialect/LinalgTransform/IR/StructuredTransformOpsExt.cpp
@@ -519,6 +519,10 @@
 DiagnosedSilenceableFailure
 transform_ext::LowerToLLVMOp::apply(mlir::transform::TransformResults &result,
                                     mlir::transform::TransformState &state) {
+  ArrayRef<Operation *> payloadOps = state.getPayloadOps(getTarget());
+  if (payloadOps.size() != 1 || !isa<ModuleOp>(payloadOps[0]))
+    return emitSilenceableError() << "expected single module target";
+  ModuleOp moduleOp = cast<ModuleOp>(payloadOps[0]);
 
   //===------------------------------------------------------------------===//
   // BEGIN: Copied from upstream, this needs to be retired once we have a
@@ -584,7 +588,7 @@
   // Convert remaining unrealized_casts (always needed).
   pm.addPass(createReconcileUnrealizedCastsPass());
 
-  if (failed(pm.run(state.getTopLevel())))
+  if (failed(pm.run(moduleOp)))
     return DiagnosedSilenceableFailure::definiteFailure();
 
   //===------------------------------------------------------------------===//
@@ -594,7 +598,7 @@
 
   // Make all arguments noalias for now.
   // FIXME: this is a terrible hack!
-  state.getTopLevel()->walk([](LLVM::LLVMFuncOp funcOp) {
+  moduleOp->walk([](LLVM::LLVMFuncOp funcOp) {
     for (int64_t i = 0; i < funcOp.getNumArguments(); ++i) {
       if (!funcOp.getFunctionType()
                .getParamType(i)
@@ -603,6 +607,8 @@
       funcOp.setArgAttr(i, "llvm.noalias", UnitAttr::get(funcOp.getContext()));
     }
   });
+
+  result.set(getTransformed().cast<OpResult>(), payloadOps);
   return DiagnosedSilenceableFailure::success();
 }
 
diff --git a/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/roundtrip.mlir b/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/roundtrip.mlir
index 17a3e45..a19a1be 100644
--- a/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/roundtrip.mlir
+++ b/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/roundtrip.mlir
@@ -23,8 +23,8 @@
   // CHECK: vector.lower_contraction %[[FUNC]] {{.*}}
   %6 = transform.structured.match ops{["func.func"]} in %arg0 : (!pdl.operation) -> !pdl.operation
   transform.vector.lower_contraction %6
-    lowering_strategy = "outerproduct" 
+    lowering_strategy = "outerproduct"
       : (!pdl.operation) -> !pdl.operation
   // CHECK: lower_to_llvm
-  lower_to_llvm
+  lower_to_llvm %arg0 : (!pdl.operation) -> !pdl.operation
 }
diff --git a/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/single-tiling-full-script.mlir b/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/single-tiling-full-script.mlir
index 888a4c0..a00cc20 100644
--- a/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/single-tiling-full-script.mlir
+++ b/integrations/tensorflow/iree-dialects/test/Dialect/linalg_transform/single-tiling-full-script.mlir
@@ -23,18 +23,18 @@
   transform.structured.vectorize %2 { vectorize_padding }
   transform.bufferization.one_shot_bufferize layout{IdentityLayoutMap} %module_op
     {bufferize_function_boundaries = true}
-  %3 = transform.structured.match ops{["func.func"]} in %module_op 
+  %3 = transform.structured.match ops{["func.func"]} in %module_op
     : (!pdl.operation) -> !pdl.operation
 
 
   %func = transform.structured.match ops{["func.func"]} in %module_op
     : (!pdl.operation) -> !pdl.operation
   %func_e_2 = transform.vector.lower_contraction %func
-    lowering_strategy = "outerproduct" 
+    lowering_strategy = "outerproduct"
       : (!pdl.operation) -> !pdl.operation
   %func_e_3 = transform.vector.lower_transpose %func_e_2
-    lowering_strategy = "shuffle" 
+    lowering_strategy = "shuffle"
       : (!pdl.operation) -> !pdl.operation
 
-  lower_to_llvm
+  lower_to_llvm %module_op : (!pdl.operation) -> !pdl.operation
 }
diff --git a/integrations/tensorflow/iree_tf_compiler/iree-import-tf-main.cpp b/integrations/tensorflow/iree_tf_compiler/iree-import-tf-main.cpp
index 532dce1..111f15b 100644
--- a/integrations/tensorflow/iree_tf_compiler/iree-import-tf-main.cpp
+++ b/integrations/tensorflow/iree_tf_compiler/iree-import-tf-main.cpp
@@ -250,7 +250,10 @@
   {
     PassManager pm(&context, module.get()->getName().getStringRef(),
                    PassManager::Nesting::Implicit);
-    applyPassManagerCLOptions(pm);
+    if (failed(applyPassManagerCLOptions(pm))) {
+      llvm::errs() << "Failed to apply pass manager CL options\n";
+      return 1;
+    }
 
     if (prettifyTfDebugInfo) {
       pm.addPass(iree_integrations::TF::createPrettifyDebugInfoPass());
diff --git a/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp b/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp
index bf7564b..eb7397c 100644
--- a/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp
+++ b/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp
@@ -164,7 +164,10 @@
   // Run transformations.
   PassManager pm(&context, module.get()->getName().getStringRef(),
                  PassManager::Nesting::Implicit);
-  applyPassManagerCLOptions(pm);
+  if (failed(applyPassManagerCLOptions(pm))) {
+    llvm::errs() << "Failed to apply pass manager CL options\n";
+    return 1;
+  }
   applyDefaultTimingPassManagerCLOptions(pm);
   mlir::iree_integrations::TFL::buildTFLImportPassPipeline(pm);
   if (failed(pm.run(*module))) {
diff --git a/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp b/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp
index c2aa44a..af7e777 100644
--- a/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp
+++ b/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp
@@ -298,7 +298,10 @@
   // Run passes.
   PassManager pm(&context, module.get()->getName().getStringRef(),
                  PassManager::Nesting::Implicit);
-  applyPassManagerCLOptions(pm);
+  if (failed(applyPassManagerCLOptions(pm))) {
+    llvm::errs() << "Failed to apply pass manager CL options\n";
+    return 1;
+  }
   applyDefaultTimingPassManagerCLOptions(pm);
 
   iree_integrations::MHLO::buildMHLOImportPassPipeline(pm);
diff --git a/third_party/llvm-project b/third_party/llvm-project
index a52054c..d3aed4f 160000
--- a/third_party/llvm-project
+++ b/third_party/llvm-project
@@ -1 +1 @@
-Subproject commit a52054cfa29d665c43141c66c20a7b8f7a96b546
+Subproject commit d3aed4f401fa35ea986d3967c529f4d2b24e2bb6
diff --git a/third_party/mlir-hlo b/third_party/mlir-hlo
index 024b0fd..f762541 160000
--- a/third_party/mlir-hlo
+++ b/third_party/mlir-hlo
@@ -1 +1 @@
-Subproject commit 024b0fdcd358604a1b38fa0534c271f344a6249d
+Subproject commit f762541041379eee1253e76b6787aa2b2e70a506
diff --git a/tools/iree-run-mlir-main.cc b/tools/iree-run-mlir-main.cc
index ab030a5..0cc309c 100644
--- a/tools/iree-run-mlir-main.cc
+++ b/tools/iree-run-mlir-main.cc
@@ -271,7 +271,10 @@
   printf("Compiling for target backend '%s'...\n", target_backend.c_str());
   mlir::PassManager pass_manager(mlir_module->getContext());
   pass_manager.enableVerifier(verify_passes_flag);
-  mlir::applyPassManagerCLOptions(pass_manager);
+  if (failed(mlir::applyPassManagerCLOptions(pass_manager))) {
+    return iree_make_status(IREE_STATUS_INTERNAL,
+                            "failed to apply pass manager CL options");
+  }
   mlir::applyDefaultTimingPassManagerCLOptions(pass_manager);
   BuildDefaultIREEVMTransformPassPipeline(pass_manager);
   if (failed(pass_manager.run(mlir_module.get()))) {