Merge pull request #3757 from google/benvanik-aot-windows

diff --git a/SUBMODULE_VERSIONS b/SUBMODULE_VERSIONS
index 7371f9a..ec37869 100644
--- a/SUBMODULE_VERSIONS
+++ b/SUBMODULE_VERSIONS
@@ -5,8 +5,8 @@
 a5d9d0f7d368054fd1691aedf1db4116efcc233e third_party/flatbuffers
 4fb0ff7069bd88ee85902f4d0bb62794e5f6d021 third_party/flatcc
 f2fb48c3b3d79a75a88a99fba6576b25d42ec528 third_party/googletest
-6d15aaeb7ac6cb70b6c67f04a081939b5f121136 third_party/llvm-bazel
-a8db144169279332db59d30051f249efa0201ab3 third_party/llvm-project
+9c04d22c6068ec07d25e236b14e3362f3e5efc2c third_party/llvm-bazel
+499bce3abab8a362b9b4197944bd40b826c736c4 third_party/llvm-project
 55801f03f9cc69abfcf8b508a873f702c11b3b5f third_party/mlir-emitc
 74d7261be17cf659d5930d4830609406bd7553e3 third_party/pffft
 d8c7ee00a687ac369e62e2032514a93a9b413502 third_party/pybind11
@@ -14,7 +14,7 @@
 a1390ed39ec77ecfb574bc6fcd5bfc5e3adbdea9 third_party/sdl2
 685f86471e9d26b3eb7676695a2e2cefb4551ae9 third_party/spirv_cross
 f8bf11a0253a32375c32cad92c841237b96696c0 third_party/spirv_headers
-6468a1d17ae43c161e836bd3d1af081e8e44ef0d third_party/tensorflow
+448e080c752a1b5f54c422401b41e824b0274a91 third_party/tensorflow
 d7059eca6351546d1f51e248fc75e49dfeee709e third_party/tracy
 9bd3f561bcee3f01d22912de10bb07ce4e23d378 third_party/vulkan_headers
 3528e2aed3e8808f33e1e7d63eeb1560456a605a third_party/vulkan_memory_allocator
diff --git a/integrations/tensorflow/bindings/python/pyiree/tf/support/tf_utils.py b/integrations/tensorflow/bindings/python/pyiree/tf/support/tf_utils.py
index c1281dd..591df43 100644
--- a/integrations/tensorflow/bindings/python/pyiree/tf/support/tf_utils.py
+++ b/integrations/tensorflow/bindings/python/pyiree/tf/support/tf_utils.py
@@ -718,7 +718,7 @@
   functions = []
   for name in exported_names:
     functions.append(getattr(instance, name).get_concrete_function())
-  return functions, exported_names
+  return functions, exported_names, instance
 
 
 def tf_module_to_tflite_module_bytes(
@@ -736,10 +736,14 @@
     A dict mapping method names to compiled TFLite module bytes.
   """
   tflite_modules = []
-  methods, method_names = _get_concrete_functions(module_class, exported_names)
+  methods, method_names, instance = _get_concrete_functions(
+      module_class, exported_names)
   for method in methods:
     converter = tf.lite.TFLiteConverter.from_concrete_functions([method])
     tflite_modules.append(converter.convert())
+  # Keep variables alive until TFLite has done the conversion; ConcreteFunctions
+  # themselves only keep weak references to variables.
+  del instance
   return dict(zip(method_names, tflite_modules))
 
 
diff --git a/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.cpp b/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.cpp
index 16d4510..0600b24 100644
--- a/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.cpp
+++ b/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.cpp
@@ -328,7 +328,7 @@
 
 LogicalResult LaunchConfig::init(
     MLIRContext *context, const linalg::LinalgDependenceGraph &dependenceGraph,
-    const SPIRVCodegenOptions &options, ArrayRef<Operation *> linalgOps) {
+    const SPIRVCodegenOptions &options, ArrayRef<linalg::LinalgOp> linalgOps) {
   unsigned numTiledOps = 0;
   auto setKey = [&](Operation *op) -> std::string {
     std::string key = llvm::formatv("__op_num_{0}__", numTiledOps++).str();
@@ -338,7 +338,7 @@
   };
 
   if (!options.workgroupSize.empty()) {
-    for (Operation *linalgOp : linalgOps)
+    for (linalg::LinalgOp linalgOp : linalgOps)
       tileSizes[setKey(linalgOp)].emplace_back(options.tileSizes.begin(),
                                                options.tileSizes.end());
     workgroupSize = {1, 1, 1};
@@ -355,20 +355,20 @@
 
   Optional<linalg::LinalgOp> rootOperation = {};
 
-  for (Operation *op : linalgOps) {
-#define DISPATCH(opName)                                                      \
-  if (auto linalgOp = dyn_cast<opName>(op)) {                                 \
-    if (rootOperation) {                                                      \
-      return linalgOp.emitError(                                              \
-          "unhandled multiple root operations in dispatch region");           \
-    }                                                                         \
-    rootOperation = cast<linalg::LinalgOp>(linalgOp.getOperation());          \
-    TileSizesListType &tileSizesInfo = tileSizes[setKey(*rootOperation)];     \
-    if (failed(getOpLaunchConfig(linalgOp, targetEnv, options, tileSizesInfo, \
-                                 workgroupSize, numSubgroups))) {             \
-      return failure();                                                       \
-    }                                                                         \
-    continue;                                                                 \
+  for (linalg::LinalgOp linalgOp : linalgOps) {
+#define DISPATCH(opName)                                                  \
+  if (auto op = dyn_cast<opName>(linalgOp.getOperation())) {              \
+    if (rootOperation) {                                                  \
+      return op.emitError(                                                \
+          "unhandled multiple root operations in dispatch region");       \
+    }                                                                     \
+    rootOperation = linalgOp;                                             \
+    TileSizesListType &tileSizesInfo = tileSizes[setKey(*rootOperation)]; \
+    if (failed(getOpLaunchConfig(op, targetEnv, options, tileSizesInfo,   \
+                                 workgroupSize, numSubgroups))) {         \
+      return failure();                                                   \
+    }                                                                     \
+    continue;                                                             \
   }
 
     DISPATCH(linalg::BatchMatmulOp)
diff --git a/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.h b/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.h
index 38b9718..17f3bc5 100644
--- a/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.h
+++ b/iree/compiler/Conversion/LinalgToSPIRV/KernelDispatchUtils.h
@@ -75,7 +75,7 @@
   LogicalResult init(MLIRContext *context,
                      const linalg::LinalgDependenceGraph &dependenceGraph,
                      const SPIRVCodegenOptions &options,
-                     ArrayRef<Operation *> linalgOps);
+                     ArrayRef<linalg::LinalgOp> linalgOps);
 
   /// Remove attributed added to operations for retrieving tile size
   /// information.
diff --git a/iree/compiler/Conversion/LinalgToSPIRV/LinalgTileAndFusePass.cpp b/iree/compiler/Conversion/LinalgToSPIRV/LinalgTileAndFusePass.cpp
index 44b0841..39b6bbf 100644
--- a/iree/compiler/Conversion/LinalgToSPIRV/LinalgTileAndFusePass.cpp
+++ b/iree/compiler/Conversion/LinalgToSPIRV/LinalgTileAndFusePass.cpp
@@ -529,8 +529,10 @@
     if (linalgOps.empty()) continue;
 
     LaunchConfig launchConfig;
-    SmallVector<Operation *, 4> linalgOpsVec(linalgOps.begin(),
-                                             linalgOps.end());
+    SmallVector<linalg::LinalgOp, 4> linalgOpsVec =
+        llvm::to_vector<4>(llvm::map_range(linalgOps, [](Operation *op) {
+          return cast<linalg::LinalgOp>(op);
+        }));
     linalg::Aliases aliases;
     linalg::LinalgDependenceGraph dependenceGraph(aliases, linalgOpsVec);
     if (failed(launchConfig.init(context, dependenceGraph, options,
diff --git a/third_party/llvm-bazel b/third_party/llvm-bazel
index 6d15aae..9c04d22 160000
--- a/third_party/llvm-bazel
+++ b/third_party/llvm-bazel
@@ -1 +1 @@
-Subproject commit 6d15aaeb7ac6cb70b6c67f04a081939b5f121136
+Subproject commit 9c04d22c6068ec07d25e236b14e3362f3e5efc2c
diff --git a/third_party/llvm-project b/third_party/llvm-project
index a8db144..499bce3 160000
--- a/third_party/llvm-project
+++ b/third_party/llvm-project
@@ -1 +1 @@
-Subproject commit a8db144169279332db59d30051f249efa0201ab3
+Subproject commit 499bce3abab8a362b9b4197944bd40b826c736c4
diff --git a/third_party/tensorflow b/third_party/tensorflow
index 6468a1d..448e080 160000
--- a/third_party/tensorflow
+++ b/third_party/tensorflow
@@ -1 +1 @@
-Subproject commit 6468a1d17ae43c161e836bd3d1af081e8e44ef0d
+Subproject commit 448e080c752a1b5f54c422401b41e824b0274a91