1 //===- OperationSupport.cpp -----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains out-of-line implementations of the support types that 10 // Operation and related classes build on top of. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "mlir/IR/OperationSupport.h" 15 #include "mlir/IR/Block.h" 16 #include "mlir/IR/OpDefinition.h" 17 #include "mlir/IR/Operation.h" 18 #include "mlir/IR/StandardTypes.h" 19 using namespace mlir; 20 21 //===----------------------------------------------------------------------===// 22 // NamedAttrList 23 //===----------------------------------------------------------------------===// 24 25 NamedAttrList::NamedAttrList(ArrayRef<NamedAttribute> attributes) { 26 assign(attributes.begin(), attributes.end()); 27 } 28 29 NamedAttrList::NamedAttrList(const_iterator in_start, const_iterator in_end) { 30 assign(in_start, in_end); 31 } 32 33 ArrayRef<NamedAttribute> NamedAttrList::getAttrs() const { return attrs; } 34 35 DictionaryAttr NamedAttrList::getDictionary(MLIRContext *context) const { 36 if (!isSorted()) { 37 DictionaryAttr::sortInPlace(attrs); 38 dictionarySorted.setPointerAndInt(nullptr, true); 39 } 40 if (!dictionarySorted.getPointer()) 41 dictionarySorted.setPointer(DictionaryAttr::getWithSorted(attrs, context)); 42 return dictionarySorted.getPointer().cast<DictionaryAttr>(); 43 } 44 45 NamedAttrList::operator MutableDictionaryAttr() const { 46 if (attrs.empty()) 47 return MutableDictionaryAttr(); 48 return getDictionary(attrs.front().second.getContext()); 49 } 50 51 /// Add an attribute with the specified name. 52 void NamedAttrList::append(StringRef name, Attribute attr) { 53 append(Identifier::get(name, attr.getContext()), attr); 54 } 55 56 /// Add an attribute with the specified name. 57 void NamedAttrList::append(Identifier name, Attribute attr) { 58 push_back({name, attr}); 59 } 60 61 /// Add an array of named attributes. 62 void NamedAttrList::append(ArrayRef<NamedAttribute> newAttributes) { 63 append(newAttributes.begin(), newAttributes.end()); 64 } 65 66 /// Add a range of named attributes. 67 void NamedAttrList::append(const_iterator in_start, const_iterator in_end) { 68 // TODO: expand to handle case where values appended are in order & after 69 // end of current list. 70 dictionarySorted.setPointerAndInt(nullptr, false); 71 attrs.append(in_start, in_end); 72 } 73 74 /// Replaces the attributes with new list of attributes. 75 void NamedAttrList::assign(const_iterator in_start, const_iterator in_end) { 76 DictionaryAttr::sort(ArrayRef<NamedAttribute>{in_start, in_end}, attrs); 77 dictionarySorted.setPointerAndInt(nullptr, true); 78 } 79 80 void NamedAttrList::push_back(NamedAttribute newAttribute) { 81 if (isSorted()) 82 dictionarySorted.setInt( 83 attrs.empty() || 84 strcmp(attrs.back().first.data(), newAttribute.first.data()) < 0); 85 dictionarySorted.setPointer(nullptr); 86 attrs.push_back(newAttribute); 87 } 88 89 /// Helper function to find attribute in possible sorted vector of 90 /// NamedAttributes. 91 template <typename T> 92 static auto *findAttr(SmallVectorImpl<NamedAttribute> &attrs, T name, 93 bool sorted) { 94 if (!sorted) { 95 return llvm::find_if( 96 attrs, [name](NamedAttribute attr) { return attr.first == name; }); 97 } 98 99 auto *it = llvm::lower_bound(attrs, name); 100 if (it->first != name) 101 return attrs.end(); 102 return it; 103 } 104 105 /// Return the specified attribute if present, null otherwise. 106 Attribute NamedAttrList::get(StringRef name) const { 107 auto *it = findAttr(attrs, name, isSorted()); 108 return it != attrs.end() ? it->second : nullptr; 109 } 110 111 /// Return the specified attribute if present, null otherwise. 112 Attribute NamedAttrList::get(Identifier name) const { 113 auto *it = findAttr(attrs, name, isSorted()); 114 return it != attrs.end() ? it->second : nullptr; 115 } 116 117 /// Return the specified named attribute if present, None otherwise. 118 Optional<NamedAttribute> NamedAttrList::getNamed(StringRef name) const { 119 auto *it = findAttr(attrs, name, isSorted()); 120 return it != attrs.end() ? *it : Optional<NamedAttribute>(); 121 } 122 Optional<NamedAttribute> NamedAttrList::getNamed(Identifier name) const { 123 auto *it = findAttr(attrs, name, isSorted()); 124 return it != attrs.end() ? *it : Optional<NamedAttribute>(); 125 } 126 127 /// If the an attribute exists with the specified name, change it to the new 128 /// value. Otherwise, add a new attribute with the specified name/value. 129 void NamedAttrList::set(Identifier name, Attribute value) { 130 assert(value && "attributes may never be null"); 131 132 // Look for an existing value for the given name, and set it in-place. 133 auto *it = findAttr(attrs, name, isSorted()); 134 if (it != attrs.end()) { 135 // Bail out early if the value is the same as what we already have. 136 if (it->second == value) 137 return; 138 dictionarySorted.setPointer(nullptr); 139 it->second = value; 140 return; 141 } 142 143 // Otherwise, insert the new attribute into its sorted position. 144 it = llvm::lower_bound(attrs, name); 145 dictionarySorted.setPointer(nullptr); 146 attrs.insert(it, {name, value}); 147 } 148 void NamedAttrList::set(StringRef name, Attribute value) { 149 assert(value && "setting null attribute not supported"); 150 return set(mlir::Identifier::get(name, value.getContext()), value); 151 } 152 153 NamedAttrList & 154 NamedAttrList::operator=(const SmallVectorImpl<NamedAttribute> &rhs) { 155 assign(rhs.begin(), rhs.end()); 156 return *this; 157 } 158 159 NamedAttrList::operator ArrayRef<NamedAttribute>() const { return attrs; } 160 161 //===----------------------------------------------------------------------===// 162 // OperationState 163 //===----------------------------------------------------------------------===// 164 165 OperationState::OperationState(Location location, StringRef name) 166 : location(location), name(name, location->getContext()) {} 167 168 OperationState::OperationState(Location location, OperationName name) 169 : location(location), name(name) {} 170 171 OperationState::OperationState(Location location, StringRef name, 172 ValueRange operands, ArrayRef<Type> types, 173 ArrayRef<NamedAttribute> attributes, 174 ArrayRef<Block *> successors, 175 MutableArrayRef<std::unique_ptr<Region>> regions) 176 : location(location), name(name, location->getContext()), 177 operands(operands.begin(), operands.end()), 178 types(types.begin(), types.end()), 179 attributes(attributes.begin(), attributes.end()), 180 successors(successors.begin(), successors.end()) { 181 for (std::unique_ptr<Region> &r : regions) 182 this->regions.push_back(std::move(r)); 183 } 184 185 void OperationState::addOperands(ValueRange newOperands) { 186 operands.append(newOperands.begin(), newOperands.end()); 187 } 188 189 void OperationState::addSuccessors(SuccessorRange newSuccessors) { 190 successors.append(newSuccessors.begin(), newSuccessors.end()); 191 } 192 193 Region *OperationState::addRegion() { 194 regions.emplace_back(new Region); 195 return regions.back().get(); 196 } 197 198 void OperationState::addRegion(std::unique_ptr<Region> &®ion) { 199 regions.push_back(std::move(region)); 200 } 201 202 //===----------------------------------------------------------------------===// 203 // OperandStorage 204 //===----------------------------------------------------------------------===// 205 206 detail::OperandStorage::OperandStorage(Operation *owner, ValueRange values) 207 : representation(0) { 208 auto &inlineStorage = getInlineStorage(); 209 inlineStorage.numOperands = inlineStorage.capacity = values.size(); 210 auto *operandPtrBegin = getTrailingObjects<OpOperand>(); 211 for (unsigned i = 0, e = inlineStorage.numOperands; i < e; ++i) 212 new (&operandPtrBegin[i]) OpOperand(owner, values[i]); 213 } 214 215 detail::OperandStorage::~OperandStorage() { 216 // Destruct the current storage container. 217 if (isDynamicStorage()) { 218 TrailingOperandStorage &storage = getDynamicStorage(); 219 storage.~TrailingOperandStorage(); 220 free(&storage); 221 } else { 222 getInlineStorage().~TrailingOperandStorage(); 223 } 224 } 225 226 /// Replace the operands contained in the storage with the ones provided in 227 /// 'values'. 228 void detail::OperandStorage::setOperands(Operation *owner, ValueRange values) { 229 MutableArrayRef<OpOperand> storageOperands = resize(owner, values.size()); 230 for (unsigned i = 0, e = values.size(); i != e; ++i) 231 storageOperands[i].set(values[i]); 232 } 233 234 /// Replace the operands beginning at 'start' and ending at 'start' + 'length' 235 /// with the ones provided in 'operands'. 'operands' may be smaller or larger 236 /// than the range pointed to by 'start'+'length'. 237 void detail::OperandStorage::setOperands(Operation *owner, unsigned start, 238 unsigned length, ValueRange operands) { 239 // If the new size is the same, we can update inplace. 240 unsigned newSize = operands.size(); 241 if (newSize == length) { 242 MutableArrayRef<OpOperand> storageOperands = getOperands(); 243 for (unsigned i = 0, e = length; i != e; ++i) 244 storageOperands[start + i].set(operands[i]); 245 return; 246 } 247 // If the new size is greater, remove the extra operands and set the rest 248 // inplace. 249 if (newSize < length) { 250 eraseOperands(start + operands.size(), length - newSize); 251 setOperands(owner, start, newSize, operands); 252 return; 253 } 254 // Otherwise, the new size is greater so we need to grow the storage. 255 auto storageOperands = resize(owner, size() + (newSize - length)); 256 257 // Shift operands to the right to make space for the new operands. 258 unsigned rotateSize = storageOperands.size() - (start + length); 259 auto rbegin = storageOperands.rbegin(); 260 std::rotate(rbegin, std::next(rbegin, newSize - length), rbegin + rotateSize); 261 262 // Update the operands inplace. 263 for (unsigned i = 0, e = operands.size(); i != e; ++i) 264 storageOperands[start + i].set(operands[i]); 265 } 266 267 /// Erase an operand held by the storage. 268 void detail::OperandStorage::eraseOperands(unsigned start, unsigned length) { 269 TrailingOperandStorage &storage = getStorage(); 270 MutableArrayRef<OpOperand> operands = storage.getOperands(); 271 assert((start + length) <= operands.size()); 272 storage.numOperands -= length; 273 274 // Shift all operands down if the operand to remove is not at the end. 275 if (start != storage.numOperands) { 276 auto *indexIt = std::next(operands.begin(), start); 277 std::rotate(indexIt, std::next(indexIt, length), operands.end()); 278 } 279 for (unsigned i = 0; i != length; ++i) 280 operands[storage.numOperands + i].~OpOperand(); 281 } 282 283 /// Resize the storage to the given size. Returns the array containing the new 284 /// operands. 285 MutableArrayRef<OpOperand> detail::OperandStorage::resize(Operation *owner, 286 unsigned newSize) { 287 TrailingOperandStorage &storage = getStorage(); 288 289 // If the number of operands is less than or equal to the current amount, we 290 // can just update in place. 291 unsigned &numOperands = storage.numOperands; 292 MutableArrayRef<OpOperand> operands = storage.getOperands(); 293 if (newSize <= numOperands) { 294 // If the number of new size is less than the current, remove any extra 295 // operands. 296 for (unsigned i = newSize; i != numOperands; ++i) 297 operands[i].~OpOperand(); 298 numOperands = newSize; 299 return operands.take_front(newSize); 300 } 301 302 // If the new size is within the original inline capacity, grow inplace. 303 if (newSize <= storage.capacity) { 304 OpOperand *opBegin = operands.data(); 305 for (unsigned e = newSize; numOperands != e; ++numOperands) 306 new (&opBegin[numOperands]) OpOperand(owner); 307 return MutableArrayRef<OpOperand>(opBegin, newSize); 308 } 309 310 // Otherwise, we need to allocate a new storage. 311 unsigned newCapacity = 312 std::max(unsigned(llvm::NextPowerOf2(storage.capacity + 2)), newSize); 313 auto *newStorageMem = 314 malloc(TrailingOperandStorage::totalSizeToAlloc<OpOperand>(newCapacity)); 315 auto *newStorage = ::new (newStorageMem) TrailingOperandStorage(); 316 newStorage->numOperands = newSize; 317 newStorage->capacity = newCapacity; 318 319 // Move the current operands to the new storage. 320 MutableArrayRef<OpOperand> newOperands = newStorage->getOperands(); 321 std::uninitialized_copy(std::make_move_iterator(operands.begin()), 322 std::make_move_iterator(operands.end()), 323 newOperands.begin()); 324 325 // Destroy the original operands. 326 for (auto &operand : operands) 327 operand.~OpOperand(); 328 329 // Initialize any new operands. 330 for (unsigned e = newSize; numOperands != e; ++numOperands) 331 new (&newOperands[numOperands]) OpOperand(owner); 332 333 // If the current storage is also dynamic, free it. 334 if (isDynamicStorage()) 335 free(&storage); 336 337 // Update the storage representation to use the new dynamic storage. 338 representation = reinterpret_cast<intptr_t>(newStorage); 339 representation |= DynamicStorageBit; 340 return newOperands; 341 } 342 343 //===----------------------------------------------------------------------===// 344 // ResultStorage 345 //===----------------------------------------------------------------------===// 346 347 /// Returns the parent operation of this trailing result. 348 Operation *detail::TrailingOpResult::getOwner() { 349 // We need to do some arithmetic to get the operation pointer. Move the 350 // trailing owner to the start of the array. 351 TrailingOpResult *trailingIt = this - trailingResultNumber; 352 353 // Move the owner past the inline op results to get to the operation. 354 auto *inlineResultIt = reinterpret_cast<InLineOpResult *>(trailingIt) - 355 OpResult::getMaxInlineResults(); 356 return reinterpret_cast<Operation *>(inlineResultIt) - 1; 357 } 358 359 //===----------------------------------------------------------------------===// 360 // Operation Value-Iterators 361 //===----------------------------------------------------------------------===// 362 363 //===----------------------------------------------------------------------===// 364 // TypeRange 365 366 TypeRange::TypeRange(ArrayRef<Type> types) 367 : TypeRange(types.data(), types.size()) {} 368 TypeRange::TypeRange(OperandRange values) 369 : TypeRange(values.begin().getBase(), values.size()) {} 370 TypeRange::TypeRange(ResultRange values) 371 : TypeRange(values.getBase()->getResultTypes().slice(values.getStartIndex(), 372 values.size())) {} 373 TypeRange::TypeRange(ArrayRef<Value> values) 374 : TypeRange(values.data(), values.size()) {} 375 TypeRange::TypeRange(ValueRange values) : TypeRange(OwnerT(), values.size()) { 376 detail::ValueRangeOwner owner = values.begin().getBase(); 377 if (auto *op = reinterpret_cast<Operation *>(owner.ptr.dyn_cast<void *>())) 378 this->base = op->getResultTypes().drop_front(owner.startIndex).data(); 379 else if (auto *operand = owner.ptr.dyn_cast<OpOperand *>()) 380 this->base = operand; 381 else 382 this->base = owner.ptr.get<const Value *>(); 383 } 384 385 /// See `llvm::detail::indexed_accessor_range_base` for details. 386 TypeRange::OwnerT TypeRange::offset_base(OwnerT object, ptrdiff_t index) { 387 if (auto *value = object.dyn_cast<const Value *>()) 388 return {value + index}; 389 if (auto *operand = object.dyn_cast<OpOperand *>()) 390 return {operand + index}; 391 return {object.dyn_cast<const Type *>() + index}; 392 } 393 /// See `llvm::detail::indexed_accessor_range_base` for details. 394 Type TypeRange::dereference_iterator(OwnerT object, ptrdiff_t index) { 395 if (auto *value = object.dyn_cast<const Value *>()) 396 return (value + index)->getType(); 397 if (auto *operand = object.dyn_cast<OpOperand *>()) 398 return (operand + index)->get().getType(); 399 return object.dyn_cast<const Type *>()[index]; 400 } 401 402 //===----------------------------------------------------------------------===// 403 // OperandRange 404 405 OperandRange::OperandRange(Operation *op) 406 : OperandRange(op->getOpOperands().data(), op->getNumOperands()) {} 407 408 /// Return the operand index of the first element of this range. The range 409 /// must not be empty. 410 unsigned OperandRange::getBeginOperandIndex() const { 411 assert(!empty() && "range must not be empty"); 412 return base->getOperandNumber(); 413 } 414 415 //===----------------------------------------------------------------------===// 416 // MutableOperandRange 417 418 /// Construct a new mutable range from the given operand, operand start index, 419 /// and range length. 420 MutableOperandRange::MutableOperandRange( 421 Operation *owner, unsigned start, unsigned length, 422 ArrayRef<OperandSegment> operandSegments) 423 : owner(owner), start(start), length(length), 424 operandSegments(operandSegments.begin(), operandSegments.end()) { 425 assert((start + length) <= owner->getNumOperands() && "invalid range"); 426 } 427 MutableOperandRange::MutableOperandRange(Operation *owner) 428 : MutableOperandRange(owner, /*start=*/0, owner->getNumOperands()) {} 429 430 /// Slice this range into a sub range, with the additional operand segment. 431 MutableOperandRange 432 MutableOperandRange::slice(unsigned subStart, unsigned subLen, 433 Optional<OperandSegment> segment) { 434 assert((subStart + subLen) <= length && "invalid sub-range"); 435 MutableOperandRange subSlice(owner, start + subStart, subLen, 436 operandSegments); 437 if (segment) 438 subSlice.operandSegments.push_back(*segment); 439 return subSlice; 440 } 441 442 /// Append the given values to the range. 443 void MutableOperandRange::append(ValueRange values) { 444 if (values.empty()) 445 return; 446 owner->insertOperands(start + length, values); 447 updateLength(length + values.size()); 448 } 449 450 /// Assign this range to the given values. 451 void MutableOperandRange::assign(ValueRange values) { 452 owner->setOperands(start, length, values); 453 if (length != values.size()) 454 updateLength(/*newLength=*/values.size()); 455 } 456 457 /// Assign the range to the given value. 458 void MutableOperandRange::assign(Value value) { 459 if (length == 1) { 460 owner->setOperand(start, value); 461 } else { 462 owner->setOperands(start, length, value); 463 updateLength(/*newLength=*/1); 464 } 465 } 466 467 /// Erase the operands within the given sub-range. 468 void MutableOperandRange::erase(unsigned subStart, unsigned subLen) { 469 assert((subStart + subLen) <= length && "invalid sub-range"); 470 if (length == 0) 471 return; 472 owner->eraseOperands(start + subStart, subLen); 473 updateLength(length - subLen); 474 } 475 476 /// Clear this range and erase all of the operands. 477 void MutableOperandRange::clear() { 478 if (length != 0) { 479 owner->eraseOperands(start, length); 480 updateLength(/*newLength=*/0); 481 } 482 } 483 484 /// Allow implicit conversion to an OperandRange. 485 MutableOperandRange::operator OperandRange() const { 486 return owner->getOperands().slice(start, length); 487 } 488 489 /// Update the length of this range to the one provided. 490 void MutableOperandRange::updateLength(unsigned newLength) { 491 int32_t diff = int32_t(newLength) - int32_t(length); 492 length = newLength; 493 494 // Update any of the provided segment attributes. 495 for (OperandSegment &segment : operandSegments) { 496 auto attr = segment.second.second.cast<DenseIntElementsAttr>(); 497 SmallVector<int32_t, 8> segments(attr.getValues<int32_t>()); 498 segments[segment.first] += diff; 499 segment.second.second = DenseIntElementsAttr::get(attr.getType(), segments); 500 owner->setAttr(segment.second.first, segment.second.second); 501 } 502 } 503 504 //===----------------------------------------------------------------------===// 505 // ResultRange 506 507 ResultRange::ResultRange(Operation *op) 508 : ResultRange(op, /*startIndex=*/0, op->getNumResults()) {} 509 510 ArrayRef<Type> ResultRange::getTypes() const { 511 return getBase()->getResultTypes().slice(getStartIndex(), size()); 512 } 513 514 /// See `llvm::indexed_accessor_range` for details. 515 OpResult ResultRange::dereference(Operation *op, ptrdiff_t index) { 516 return op->getResult(index); 517 } 518 519 //===----------------------------------------------------------------------===// 520 // ValueRange 521 522 ValueRange::ValueRange(ArrayRef<Value> values) 523 : ValueRange(values.data(), values.size()) {} 524 ValueRange::ValueRange(OperandRange values) 525 : ValueRange(values.begin().getBase(), values.size()) {} 526 ValueRange::ValueRange(ResultRange values) 527 : ValueRange( 528 {values.getBase(), static_cast<unsigned>(values.getStartIndex())}, 529 values.size()) {} 530 531 /// See `llvm::detail::indexed_accessor_range_base` for details. 532 ValueRange::OwnerT ValueRange::offset_base(const OwnerT &owner, 533 ptrdiff_t index) { 534 if (auto *value = owner.ptr.dyn_cast<const Value *>()) 535 return {value + index}; 536 if (auto *operand = owner.ptr.dyn_cast<OpOperand *>()) 537 return {operand + index}; 538 Operation *operation = reinterpret_cast<Operation *>(owner.ptr.get<void *>()); 539 return {operation, owner.startIndex + static_cast<unsigned>(index)}; 540 } 541 /// See `llvm::detail::indexed_accessor_range_base` for details. 542 Value ValueRange::dereference_iterator(const OwnerT &owner, ptrdiff_t index) { 543 if (auto *value = owner.ptr.dyn_cast<const Value *>()) 544 return value[index]; 545 if (auto *operand = owner.ptr.dyn_cast<OpOperand *>()) 546 return operand[index].get(); 547 Operation *operation = reinterpret_cast<Operation *>(owner.ptr.get<void *>()); 548 return operation->getResult(owner.startIndex + index); 549 } 550 551 //===----------------------------------------------------------------------===// 552 // Operation Equivalency 553 //===----------------------------------------------------------------------===// 554 555 llvm::hash_code OperationEquivalence::computeHash(Operation *op, Flags flags) { 556 // Hash operations based upon their: 557 // - Operation Name 558 // - Attributes 559 llvm::hash_code hash = 560 llvm::hash_combine(op->getName(), op->getMutableAttrDict()); 561 562 // - Result Types 563 ArrayRef<Type> resultTypes = op->getResultTypes(); 564 switch (resultTypes.size()) { 565 case 0: 566 // We don't need to add anything to the hash. 567 break; 568 case 1: 569 // Add in the result type. 570 hash = llvm::hash_combine(hash, resultTypes.front()); 571 break; 572 default: 573 // Use the type buffer as the hash, as we can guarantee it is the same for 574 // any given range of result types. This takes advantage of the fact the 575 // result types >1 are stored in a TupleType and uniqued. 576 hash = llvm::hash_combine(hash, resultTypes.data()); 577 break; 578 } 579 580 // - Operands 581 bool ignoreOperands = flags & Flags::IgnoreOperands; 582 if (!ignoreOperands) { 583 // TODO: Allow commutative operations to have different ordering. 584 hash = llvm::hash_combine( 585 hash, llvm::hash_combine_range(op->operand_begin(), op->operand_end())); 586 } 587 return hash; 588 } 589 590 bool OperationEquivalence::isEquivalentTo(Operation *lhs, Operation *rhs, 591 Flags flags) { 592 if (lhs == rhs) 593 return true; 594 595 // Compare the operation name. 596 if (lhs->getName() != rhs->getName()) 597 return false; 598 // Check operand counts. 599 if (lhs->getNumOperands() != rhs->getNumOperands()) 600 return false; 601 // Compare attributes. 602 if (lhs->getMutableAttrDict() != rhs->getMutableAttrDict()) 603 return false; 604 // Compare result types. 605 ArrayRef<Type> lhsResultTypes = lhs->getResultTypes(); 606 ArrayRef<Type> rhsResultTypes = rhs->getResultTypes(); 607 if (lhsResultTypes.size() != rhsResultTypes.size()) 608 return false; 609 switch (lhsResultTypes.size()) { 610 case 0: 611 break; 612 case 1: 613 // Compare the single result type. 614 if (lhsResultTypes.front() != rhsResultTypes.front()) 615 return false; 616 break; 617 default: 618 // Use the type buffer for the comparison, as we can guarantee it is the 619 // same for any given range of result types. This takes advantage of the 620 // fact the result types >1 are stored in a TupleType and uniqued. 621 if (lhsResultTypes.data() != rhsResultTypes.data()) 622 return false; 623 break; 624 } 625 // Compare operands. 626 bool ignoreOperands = flags & Flags::IgnoreOperands; 627 if (ignoreOperands) 628 return true; 629 // TODO: Allow commutative operations to have different ordering. 630 return std::equal(lhs->operand_begin(), lhs->operand_end(), 631 rhs->operand_begin()); 632 } 633