Overriding default buffer constraints for the vulkan-spirv target.
These are conservative values for android. We should pull this from the
target vk.env attribute.
diff --git a/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp b/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp
index 882c7aa..b2037e6 100644
--- a/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp
+++ b/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp
@@ -71,6 +71,26 @@
   return false;
 }
 
+// static
+BufferConstraintsAttr TargetBackend::makeDefaultBufferConstraints(
+    MLIRContext *context) {
+  // Picked to represent what we kind of want on CPU today.
+  uint64_t maxAllocationSize = 1 * 1024 * 1024 * 1024ull;
+  uint64_t minBufferOffsetAlignment = 16ull;
+  uint64_t maxBufferRange = 1 * 1024 * 1024 * 1024ull;
+  uint64_t minBufferRangeAlignment = 16ull;
+  Builder b(context);
+  return BufferConstraintsAttr::get(b.getIndexAttr(maxAllocationSize),
+                                    b.getIndexAttr(minBufferOffsetAlignment),
+                                    b.getIndexAttr(maxBufferRange),
+                                    b.getIndexAttr(minBufferRangeAlignment));
+}
+
+BufferConstraintsAttr TargetBackend::queryBufferConstraints(
+    MLIRContext *context) {
+  return makeDefaultBufferConstraints(context);
+}
+
 void TargetBackend::declareTargetOps(IREE::Flow::ExecutableOp sourceOp,
                                      IREE::HAL::ExecutableOp executableOp) {
   OpBuilder targetBuilder(&executableOp.getBlock().back());
diff --git a/iree/compiler/Dialect/HAL/Target/TargetBackend.h b/iree/compiler/Dialect/HAL/Target/TargetBackend.h
index 1cd4b4f..4f03b80 100644
--- a/iree/compiler/Dialect/HAL/Target/TargetBackend.h
+++ b/iree/compiler/Dialect/HAL/Target/TargetBackend.h
@@ -116,6 +116,10 @@
   // 'foo-10?' matches: 'foo-101', 'foo-102'
   static bool matchPattern(StringRef value, StringRef pattern);
 
+  // Returns a generic host-like set of constraints.
+  static BufferConstraintsAttr makeDefaultBufferConstraints(
+      MLIRContext *context);
+
   virtual ~TargetBackend() = default;
 
   // Returns a name for the backend used to differentiate between other targets.
@@ -124,6 +128,21 @@
   // call to matchPattern. For example, 'vulkan-v1.1' or 'vmla*'.
   virtual std::string filter_pattern() const = 0;
 
+  // Register dependent dialects for the TargetBackend.
+  // Mirrors the method on mlir::Pass of the same name. A TargetBackend is
+  // expected to register the dialects it will create entities for (Operations,
+  // Types, Attributes), other than dialects that exist in the input. These are
+  // the dialects that will be used in |declareTargetOps| and
+  // |buildTranslationPassPipeline|.
+  // TODO(#1036): We might be able to get rid of this with dynamic pass
+  // registration.
+  virtual void getDependentDialects(DialectRegistry &registry) const {}
+
+  // Queries for compile-time known buffer constraints.
+  // These should conservatively represent the min/max values even if the
+  // backend may support others at runtime.
+  virtual BufferConstraintsAttr queryBufferConstraints(MLIRContext *context);
+
   // Creates an interface representing the bindings and push constants required
   // to dispatch the executable. Interfaces used across backends and executables
   // will be deduplicated to reduce code size and runtime overhead and being
@@ -152,16 +171,6 @@
   virtual void declareTargetOps(IREE::Flow::ExecutableOp sourceOp,
                                 IREE::HAL::ExecutableOp executableOp);
 
-  // Register dependent dialects for the TargetBackend.
-  // Mirrors the method on mlir::Pass of the same name. A TargetBackend is
-  // expected to register the dialects it will create entities for (Operations,
-  // Types, Attributes), other than dialects that exist in the input. These are
-  // the dialects that will be used in |declareTargetOps| and
-  // |buildTranslationPassPipeline|.
-  // TODO(#1036): We might be able to get rid of this with dynamic pass
-  // registration.
-  virtual void getDependentDialects(DialectRegistry &registry) const {}
-
   // Captured state from the point at which a dispatch is to be recorded.
   struct DispatchState {
     // The original flow.dispatch op.
diff --git a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
index 23bde9c..91de450c 100644
--- a/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
+++ b/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
@@ -144,6 +144,22 @@
     // clang-format on
   }
 
+  BufferConstraintsAttr queryBufferConstraints(MLIRContext *context) override {
+    // Picked from here to start:
+    // https://vulkan.gpuinfo.org/displaydevicelimit.php?name=minStorageBufferOffsetAlignment&platform=android
+    // https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxStorageBufferRange&platform=android
+    // We should instead be querying the vulkan environment attributes.
+    uint64_t maxAllocationSize = 1 * 1024 * 1024 * 1024ull;
+    uint64_t minBufferOffsetAlignment = 256ull;
+    uint64_t maxBufferRange = 128 * 1024 * 1024ull;
+    uint64_t minBufferRangeAlignment = 16ull;
+    Builder b(context);
+    return BufferConstraintsAttr::get(b.getIndexAttr(maxAllocationSize),
+                                      b.getIndexAttr(minBufferOffsetAlignment),
+                                      b.getIndexAttr(maxBufferRange),
+                                      b.getIndexAttr(minBufferRangeAlignment));
+  }
+
   void declareTargetOps(IREE::Flow::ExecutableOp sourceOp,
                         IREE::HAL::ExecutableOp executableOp) override {
     spirv::TargetEnvAttr spvTargetEnv =