Removing unused HAL buffer constraints attr. (#9127)

This functionality was moved into the stream resource constraints attr.
diff --git a/compiler/src/iree/compiler/Dialect/HAL/IR/HALBase.td b/compiler/src/iree/compiler/Dialect/HAL/IR/HALBase.td
index eee5ffb..622fa64 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/IR/HALBase.td
+++ b/compiler/src/iree/compiler/Dialect/HAL/IR/HALBase.td
@@ -396,26 +396,6 @@
 // HAL structs
 //===----------------------------------------------------------------------===//
 
-def HAL_BufferConstraintsAttr :
-  Util_StructAttr<"buffer_constraints", "BufferConstraintsAttr", HAL_Dialect, [
-    // The maximum size of a memory allocation that can be created, even if
-    // there is more space available in the heap.
-    Util_StructFieldAttr<"max_allocation_size", HAL_DeviceSizeAttr>,
-    // The minimum required alignment, in bytes, for offsets used in runtime
-    // buffer bindings for target backends. Offset values (both dynamic and
-    // static) must be an integer multiple of this limit.
-    Util_StructFieldAttr<"min_buffer_offset_alignment", HAL_DeviceSizeAttr>,
-    // The maximum value that can be specified for size ranges of buffer
-    // bindings. The underlying allocation may be larger than this but only
-    // up to this amount will be visible to kernels.
-    Util_StructFieldAttr<"max_buffer_range", HAL_DeviceSizeAttr>,
-    // The minimum required alignment, in bytes, for size ranges of buffer
-    // bindings.
-    Util_StructFieldAttr<"min_buffer_range_alignment", HAL_DeviceSizeAttr>,
-  ]> {
-  let cppNamespace = "mlir::iree_compiler::IREE::HAL";
-}
-
 def HAL_DescriptorSetBindingAttr :
     AttrDef<HAL_Dialect, "DescriptorSetBinding", []> {
   let mnemonic = "descriptor_set.binding";
@@ -542,10 +522,6 @@
     // target device.
     Attribute getMatchExpression();
 
-    // Returns the constraints defining buffer allocation and usage allowed on
-    // the device or the host defaults if none are defined.
-    BufferConstraintsAttr getBufferConstraints();
-
     // Returns zero or more executable targets that this device supports.
     SmallVector<ExecutableTargetAttr, 4> getExecutableTargets();
 
@@ -554,22 +530,6 @@
     // the `hal.device.targets` attribute is found.
     static SmallVector<DeviceTargetAttr, 4> lookup(Operation *op);
 
-    // Returns a set of buffer constraints compatible with the host.
-    // These must only be used with device buffers when it is known that the
-    // device is local.
-    static BufferConstraintsAttr
-    getDefaultHostBufferConstraints(MLIRContext *context);
-
-    // Tries to find the min/max constraints on buffers across all target
-    // devices applicable to the given operation. If no target device specifies
-    // constraints then a generally acceptable default set with minimums will be
-    // returned.
-    //
-    // This can result in non-optimal constraints when multi-targeting wildly
-    // different device types and should only be used as a fallback.
-    static BufferConstraintsAttr
-    lookupConservativeBufferConstraints(Operation *op);
-
     // Returns a list of all target executable configurations that may be
     // required for the given operation.
     static SmallVector<ExecutableTargetAttr, 4>
diff --git a/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.cpp b/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.cpp
index 84df8ca..87dfedf 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.cpp
+++ b/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.cpp
@@ -295,114 +295,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// Struct types
-//===----------------------------------------------------------------------===//
-
-BufferConstraintsAttr intersectBufferConstraints(BufferConstraintsAttr lhs,
-                                                 BufferConstraintsAttr rhs) {
-  if (!lhs) return rhs;
-  if (!rhs) return lhs;
-  Builder b(lhs.getContext());
-  return BufferConstraintsAttr::get(
-      b.getIndexAttr(std::min(lhs.max_allocation_size().getSExtValue(),
-                              rhs.max_allocation_size().getSExtValue())),
-      b.getIndexAttr(
-          std::max(lhs.min_buffer_offset_alignment().getSExtValue(),
-                   rhs.min_buffer_offset_alignment().getSExtValue())),
-      b.getIndexAttr(std::min(lhs.max_buffer_range().getSExtValue(),
-                              rhs.max_buffer_range().getSExtValue())),
-      b.getIndexAttr(
-          std::max(lhs.min_buffer_range_alignment().getSExtValue(),
-                   rhs.min_buffer_range_alignment().getSExtValue())));
-}
-
-// TODO(benvanik): runtime buffer constraint queries from the allocator.
-// We can add folders for those when the allocator is strongly-typed with
-// #hal.buffer_constraints and otherwise leave them for runtime queries.
-BufferConstraintsAdaptor::BufferConstraintsAdaptor(Location loc,
-                                                   Value allocator)
-    : loc_(loc), allocator_(allocator) {
-  // 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(loc.getContext());
-  bufferConstraints_ = BufferConstraintsAttr::get(
-      b.getIndexAttr(maxAllocationSize),
-      b.getIndexAttr(minBufferOffsetAlignment), b.getIndexAttr(maxBufferRange),
-      b.getIndexAttr(minBufferRangeAlignment));
-}
-
-Value BufferConstraintsAdaptor::getMaxAllocationSize(OpBuilder &builder) {
-  return builder.createOrFold<mlir::arith::ConstantOp>(
-      loc_, bufferConstraints_.max_allocation_sizeAttr());
-}
-
-Value BufferConstraintsAdaptor::getMinBufferOffsetAlignment(
-    OpBuilder &builder) {
-  return builder.createOrFold<mlir::arith::ConstantOp>(
-      loc_, bufferConstraints_.min_buffer_offset_alignmentAttr());
-}
-
-Value BufferConstraintsAdaptor::getMaxBufferRange(OpBuilder &builder) {
-  return builder.createOrFold<mlir::arith::ConstantOp>(
-      loc_, bufferConstraints_.max_buffer_rangeAttr());
-}
-
-Value BufferConstraintsAdaptor::getMinBufferRangeAlignment(OpBuilder &builder) {
-  return builder.createOrFold<mlir::arith::ConstantOp>(
-      loc_, bufferConstraints_.min_buffer_range_alignmentAttr());
-}
-
-//===----------------------------------------------------------------------===//
-// Attribute printing and parsing
-//===----------------------------------------------------------------------===//
-
-// static
-Attribute BufferConstraintsAttr::parse(AsmParser &p) {
-  auto b = p.getBuilder();
-  if (failed(p.parseLess())) return {};
-
-  IntegerAttr maxAllocationSizeAttr;
-  IntegerAttr minBufferOffsetAlignmentAttr;
-  IntegerAttr maxBufferRangeAttr;
-  IntegerAttr minBufferRangeAlignmentAttr;
-  if (failed(p.parseKeyword("max_allocation_size")) || failed(p.parseEqual()) ||
-      failed(p.parseAttribute(maxAllocationSizeAttr, b.getIndexType())) ||
-      failed(p.parseComma()) ||
-      failed(p.parseKeyword("min_buffer_offset_alignment")) ||
-      failed(p.parseEqual()) ||
-      failed(
-          p.parseAttribute(minBufferOffsetAlignmentAttr, b.getIndexType())) ||
-      failed(p.parseComma()) || failed(p.parseKeyword("max_buffer_range")) ||
-      failed(p.parseEqual()) ||
-      failed(p.parseAttribute(maxBufferRangeAttr, b.getIndexType())) ||
-      failed(p.parseComma()) ||
-      failed(p.parseKeyword("min_buffer_range_alignment")) ||
-      failed(p.parseEqual()) ||
-      failed(p.parseAttribute(minBufferRangeAlignmentAttr, b.getIndexType()))) {
-    return {};
-  }
-
-  if (failed(p.parseGreater())) return {};
-  return BufferConstraintsAttr::get(
-      maxAllocationSizeAttr, minBufferOffsetAlignmentAttr, maxBufferRangeAttr,
-      minBufferRangeAlignmentAttr);
-}
-
-void BufferConstraintsAttr::print(AsmPrinter &p) const {
-  auto &os = p.getStream();
-  os << "<";
-  os << "max_allocation_size = " << max_allocation_size() << ", ";
-  os << "min_buffer_offset_alignment = " << min_buffer_offset_alignment()
-     << ", ";
-  os << "max_buffer_range = " << max_buffer_range() << ", ";
-  os << "min_buffer_range_alignment = " << min_buffer_range_alignment();
-  os << ">";
-}
-
-//===----------------------------------------------------------------------===//
 // #hal.device.target
 //===----------------------------------------------------------------------===//
 
@@ -456,17 +348,6 @@
   return DeviceMatchIDAttr::get(*this);
 }
 
-BufferConstraintsAttr DeviceTargetAttr::getBufferConstraints() {
-  BufferConstraintsAttr constraintsAttr;
-  auto configAttr = getConfiguration();
-  if (configAttr) {
-    constraintsAttr =
-        configAttr.getAs<BufferConstraintsAttr>("buffer_constraints");
-  }
-  return constraintsAttr ? constraintsAttr
-                         : getDefaultHostBufferConstraints(getContext());
-}
-
 SmallVector<ExecutableTargetAttr, 4> DeviceTargetAttr::getExecutableTargets() {
   SmallVector<ExecutableTargetAttr, 4> resultAttrs;
   auto configAttr = getConfiguration();
@@ -500,37 +381,6 @@
 }
 
 // static
-BufferConstraintsAttr DeviceTargetAttr::getDefaultHostBufferConstraints(
-    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));
-}
-
-// static
-BufferConstraintsAttr DeviceTargetAttr::lookupConservativeBufferConstraints(
-    Operation *op) {
-  BufferConstraintsAttr resultAttr = {};
-  for (auto targetAttr : IREE::HAL::DeviceTargetAttr::lookup(op)) {
-    auto configAttr = targetAttr.getConfiguration();
-    if (!configAttr) continue;
-    auto targetConstraintsAttr =
-        configAttr.getAs<BufferConstraintsAttr>("buffer_constraints");
-    if (!targetConstraintsAttr) continue;
-    resultAttr = intersectBufferConstraints(resultAttr, targetConstraintsAttr);
-  }
-  return resultAttr ? resultAttr
-                    : getDefaultHostBufferConstraints(op->getContext());
-}
-
-// static
 SmallVector<ExecutableTargetAttr, 4> DeviceTargetAttr::lookupExecutableTargets(
     Operation *op) {
   SmallVector<ExecutableTargetAttr, 4> resultAttrs;
@@ -818,7 +668,6 @@
 #include "iree/compiler/Dialect/HAL/IR/HALTypeInterfaces.cpp.inc"
 
 void HALDialect::registerAttributes() {
-  addAttributes<BufferConstraintsAttr>();
   addAttributes<
 #define GET_ATTRDEF_LIST
 #include "iree/compiler/Dialect/HAL/IR/HALAttrs.cpp.inc"  // IWYU pragma: keep
@@ -844,25 +693,17 @@
   OptionalParseResult parseResult =
       generatedAttributeParser(parser, mnemonic, type, genAttr);
   if (parseResult.hasValue()) return genAttr;
-  if (mnemonic == BufferConstraintsAttr::getKindName()) {
-    return BufferConstraintsAttr::parse(parser);
-  }
   parser.emitError(parser.getNameLoc())
       << "unknown HAL attribute: " << mnemonic;
   return {};
 }
 
 void HALDialect::printAttribute(Attribute attr, DialectAsmPrinter &p) const {
-  TypeSwitch<Attribute>(attr)
-      .Case<BufferConstraintsAttr>([&](auto typedAttr) {
-        p << typedAttr.getKindName();
-        typedAttr.print(p);
-      })
-      .Default([&](Attribute) {
-        if (failed(generatedAttributePrinter(attr, p))) {
-          assert(false && "unhandled HAL attribute kind");
-        }
-      });
+  TypeSwitch<Attribute>(attr).Default([&](Attribute) {
+    if (failed(generatedAttributePrinter(attr, p))) {
+      assert(false && "unhandled HAL attribute kind");
+    }
+  });
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.h b/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.h
index ac80b88..cbf6d4c 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.h
+++ b/compiler/src/iree/compiler/Dialect/HAL/IR/HALTypes.h
@@ -141,28 +141,6 @@
 // Struct types
 //===----------------------------------------------------------------------===//
 
-// Returns the intersection (most conservative) constraints |lhs| ∩ |rhs|.
-BufferConstraintsAttr intersectBufferConstraints(BufferConstraintsAttr lhs,
-                                                 BufferConstraintsAttr rhs);
-
-// TODO(benvanik): runtime buffer constraint queries from the allocator.
-// We can add folders for those when the allocator is strongly-typed with
-// #hal.buffer_constraints and otherwise leave them for runtime queries.
-class BufferConstraintsAdaptor {
- public:
-  BufferConstraintsAdaptor(Location loc, Value allocator);
-
-  Value getMaxAllocationSize(OpBuilder &builder);
-  Value getMinBufferOffsetAlignment(OpBuilder &builder);
-  Value getMaxBufferRange(OpBuilder &builder);
-  Value getMinBufferRangeAlignment(OpBuilder &builder);
-
- private:
-  Location loc_;
-  Value allocator_;
-  BufferConstraintsAttr bufferConstraints_;
-};
-
 // A tuple containing runtime values for a descriptor set binding.
 struct DescriptorSetBindingValue {
   Value ordinal;
diff --git a/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp b/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
index 044244c..329f10c 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
+++ b/compiler/src/iree/compiler/Dialect/HAL/Target/VulkanSPIRV/VulkanSPIRVTarget.cpp
@@ -126,21 +126,6 @@
     Builder b(context);
     SmallVector<NamedAttribute> configItems;
 
-    // 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;
-    configItems.emplace_back(
-        b.getStringAttr("buffer_constraints"),
-        BufferConstraintsAttr::get(b.getIndexAttr(maxAllocationSize),
-                                   b.getIndexAttr(minBufferOffsetAlignment),
-                                   b.getIndexAttr(maxBufferRange),
-                                   b.getIndexAttr(minBufferRangeAlignment)));
-
     configItems.emplace_back(b.getStringAttr("executable_targets"),
                              getExecutableTargets(context));