1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
|
// Copyright (c) 2016 Google Inc.
// Modifications Copyright (C) 2024 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file provides a class hierarchy for representing SPIR-V types.
#ifndef SOURCE_OPT_TYPES_H_
#define SOURCE_OPT_TYPES_H_
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "source/latest_version_spirv_header.h"
#include "source/opt/instruction.h"
#include "source/util/small_vector.h"
#include "spirv-tools/libspirv.h"
namespace spvtools {
namespace opt {
namespace analysis {
class Void;
class Bool;
class Integer;
class Float;
class Vector;
class Matrix;
class Image;
class Sampler;
class SampledImage;
class Array;
class RuntimeArray;
class NodePayloadArrayAMDX;
class Struct;
class Opaque;
class Pointer;
class Function;
class Event;
class DeviceEvent;
class ReserveId;
class Queue;
class Pipe;
class ForwardPointer;
class PipeStorage;
class NamedBarrier;
class AccelerationStructureNV;
class CooperativeMatrixNV;
class CooperativeMatrixKHR;
class CooperativeVectorNV;
class RayQueryKHR;
class HitObjectNV;
class HitObjectEXT;
class TensorLayoutNV;
class TensorViewNV;
class TensorARM;
class GraphARM;
// Abstract class for a SPIR-V type. It has a bunch of As<sublcass>() methods,
// which is used as a way to probe the actual <subclass>.
class Type {
public:
typedef std::set<std::pair<const Pointer*, const Pointer*>> IsSameCache;
using SeenTypes = spvtools::utils::SmallVector<const Type*, 8>;
// Available subtypes.
//
// When adding a new derived class of Type, please add an entry to the enum.
enum Kind {
kVoid,
kBool,
kInteger,
kFloat,
kVector,
kMatrix,
kImage,
kSampler,
kSampledImage,
kArray,
kRuntimeArray,
kNodePayloadArrayAMDX,
kStruct,
kOpaque,
kPointer,
kFunction,
kEvent,
kDeviceEvent,
kReserveId,
kQueue,
kPipe,
kForwardPointer,
kPipeStorage,
kNamedBarrier,
kAccelerationStructureNV,
kCooperativeMatrixNV,
kCooperativeMatrixKHR,
kCooperativeVectorNV,
kRayQueryKHR,
kHitObjectNV,
kHitObjectEXT,
kTensorLayoutNV,
kTensorViewNV,
kTensorARM,
kGraphARM,
kLast
};
Type(Kind k) : kind_(k) {}
virtual ~Type() = default;
// Attaches a decoration directly on this type.
void AddDecoration(std::vector<uint32_t>&& d) {
decorations_.push_back(std::move(d));
}
// Returns the decorations on this type as a string.
std::string GetDecorationStr() const;
// Returns true if this type has exactly the same decorations as |that| type.
bool HasSameDecorations(const Type* that) const;
// Returns true if this type is exactly the same as |that| type, including
// decorations.
bool IsSame(const Type* that) const {
IsSameCache seen;
return IsSameImpl(that, &seen);
}
// Returns true if this type is exactly the same as |that| type, including
// decorations. |seen| is the set of |Pointer*| pair that are currently being
// compared in a parent call to |IsSameImpl|.
virtual bool IsSameImpl(const Type* that, IsSameCache* seen) const = 0;
// Returns a human-readable string to represent this type.
virtual std::string str() const = 0;
Kind kind() const { return kind_; }
const std::vector<std::vector<uint32_t>>& decorations() const {
return decorations_;
}
// Returns true if there is no decoration on this type. For struct types,
// returns true only when there is no decoration for both the struct type
// and the struct members.
virtual bool decoration_empty() const { return decorations_.empty(); }
// Creates a clone of |this|.
std::unique_ptr<Type> Clone() const;
// Returns a clone of |this| minus any decorations.
std::unique_ptr<Type> RemoveDecorations() const;
// Returns true if this cannot hash to the same value as another type in the
// module. For example, structs are not unique types because the module could
// have two types
//
// %1 = OpTypeStruct %int
// %2 = OpTypeStruct %int
//
// The only way to distinguish these types is the result id. The type manager
// will hash them to the same value.
bool IsUniqueType() const;
bool operator==(const Type& other) const;
// Returns the hash value of this type.
size_t HashValue() const;
size_t ComputeHashValue(size_t hash, SeenTypes* seen) const;
// Returns the number of components in a composite type. Returns 0 for a
// non-composite type.
uint64_t NumberOfComponents() const;
// A bunch of methods for casting this type to a given type. Returns this if
// the cast can be done, nullptr otherwise.
// clang-format off
#define DeclareCastMethod(target) \
virtual target* As##target() { return nullptr; } \
virtual const target* As##target() const { return nullptr; }
DeclareCastMethod(Void)
DeclareCastMethod(Bool)
DeclareCastMethod(Integer)
DeclareCastMethod(Float)
DeclareCastMethod(Vector)
DeclareCastMethod(Matrix)
DeclareCastMethod(Image)
DeclareCastMethod(Sampler)
DeclareCastMethod(SampledImage)
DeclareCastMethod(Array)
DeclareCastMethod(RuntimeArray)
DeclareCastMethod(NodePayloadArrayAMDX)
DeclareCastMethod(Struct)
DeclareCastMethod(Opaque)
DeclareCastMethod(Pointer)
DeclareCastMethod(Function)
DeclareCastMethod(Event)
DeclareCastMethod(DeviceEvent)
DeclareCastMethod(ReserveId)
DeclareCastMethod(Queue)
DeclareCastMethod(Pipe)
DeclareCastMethod(ForwardPointer)
DeclareCastMethod(PipeStorage)
DeclareCastMethod(NamedBarrier)
DeclareCastMethod(AccelerationStructureNV)
DeclareCastMethod(CooperativeMatrixNV)
DeclareCastMethod(CooperativeMatrixKHR)
DeclareCastMethod(CooperativeVectorNV)
DeclareCastMethod(RayQueryKHR)
DeclareCastMethod(HitObjectNV)
DeclareCastMethod(HitObjectEXT)
DeclareCastMethod(TensorLayoutNV)
DeclareCastMethod(TensorViewNV)
DeclareCastMethod(TensorARM)
DeclareCastMethod(GraphARM)
#undef DeclareCastMethod
protected:
// Add any type-specific state to |hash| and returns new hash.
virtual size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const = 0;
protected:
// Decorations attached to this type. Each decoration is encoded as a vector
// of uint32_t numbers. The first uint32_t number is the decoration value,
// and the rest are the parameters to the decoration (if any exist).
// The parameters can be either all literals or all ids depending on the
// decoration value.
std::vector<std::vector<uint32_t>> decorations_;
private:
// Removes decorations on this type. For struct types, also removes element
// decorations.
virtual void ClearDecorations() { decorations_.clear(); }
Kind kind_;
};
// clang-format on
class Integer : public Type {
public:
Integer(uint32_t w, bool is_signed)
: Type(kInteger), width_(w), signed_(is_signed) {}
Integer(const Integer&) = default;
std::string str() const override;
Integer* AsInteger() override { return this; }
const Integer* AsInteger() const override { return this; }
uint32_t width() const { return width_; }
bool IsSigned() const { return signed_; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
uint32_t width_; // bit width
bool signed_; // true if this integer is signed
};
class Float : public Type {
public:
Float(uint32_t w, spv::FPEncoding encoding = spv::FPEncoding::Max)
: Type(kFloat), width_(w), encoding_(encoding) {}
Float(const Float&) = default;
std::string str() const override;
Float* AsFloat() override { return this; }
const Float* AsFloat() const override { return this; }
uint32_t width() const { return width_; }
spv::FPEncoding encoding() const { return encoding_; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
uint32_t width_; // bit width
spv::FPEncoding encoding_; // FPEncoding
};
class Vector : public Type {
public:
Vector(const Type* element_type, uint32_t count);
Vector(const Vector&) = default;
std::string str() const override;
const Type* element_type() const { return element_type_; }
uint32_t element_count() const { return count_; }
Vector* AsVector() override { return this; }
const Vector* AsVector() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* element_type_;
uint32_t count_;
};
class Matrix : public Type {
public:
Matrix(const Type* element_type, uint32_t count);
Matrix(const Matrix&) = default;
std::string str() const override;
const Type* element_type() const { return element_type_; }
uint32_t element_count() const { return count_; }
Matrix* AsMatrix() override { return this; }
const Matrix* AsMatrix() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* element_type_;
uint32_t count_;
};
class Image : public Type {
public:
Image(Type* type, spv::Dim dimen, uint32_t d, bool array, bool multisample,
uint32_t sampling, spv::ImageFormat f,
spv::AccessQualifier qualifier = spv::AccessQualifier::ReadOnly);
Image(const Image&) = default;
std::string str() const override;
Image* AsImage() override { return this; }
const Image* AsImage() const override { return this; }
const Type* sampled_type() const { return sampled_type_; }
spv::Dim dim() const { return dim_; }
uint32_t depth() const { return depth_; }
bool is_arrayed() const { return arrayed_; }
bool is_multisampled() const { return ms_; }
uint32_t sampled() const { return sampled_; }
spv::ImageFormat format() const { return format_; }
spv::AccessQualifier access_qualifier() const { return access_qualifier_; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
Type* sampled_type_;
spv::Dim dim_;
uint32_t depth_;
bool arrayed_;
bool ms_;
uint32_t sampled_;
spv::ImageFormat format_;
spv::AccessQualifier access_qualifier_;
};
class SampledImage : public Type {
public:
SampledImage(Type* image) : Type(kSampledImage), image_type_(image) {}
SampledImage(const SampledImage&) = default;
std::string str() const override;
SampledImage* AsSampledImage() override { return this; }
const SampledImage* AsSampledImage() const override { return this; }
const Type* image_type() const { return image_type_; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
Type* image_type_;
};
class Array : public Type {
public:
// Data about the length operand, that helps us distinguish between one
// array length and another.
struct LengthInfo {
// The result id of the instruction defining the length.
const uint32_t id;
enum Case : uint32_t {
kConstant = 0,
kConstantWithSpecId = 1,
kDefiningId = 2
};
// Extra words used to distinshish one array length and another.
// - if OpConstant, then it's 0, then the words in the literal constant
// value.
// - if OpSpecConstant, then it's 1, then the SpecID decoration if there
// is one, followed by the words in the literal constant value.
// The spec might not be overridden, in which case we'll end up using
// the literal value.
// - Otherwise, it's an OpSpecConsant, and this 2, then the ID (again).
const std::vector<uint32_t> words;
};
// Constructs an array type with given element and length. If the length
// is an OpSpecConstant, then |spec_id| should be its SpecId decoration.
Array(const Type* element_type, const LengthInfo& length_info_arg);
Array(const Array&) = default;
std::string str() const override;
const Type* element_type() const { return element_type_; }
uint32_t LengthId() const { return length_info_.id; }
const LengthInfo& length_info() const { return length_info_; }
Array* AsArray() override { return this; }
const Array* AsArray() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
void ReplaceElementType(const Type* element_type);
LengthInfo GetConstantLengthInfo(uint32_t const_id, uint32_t length) const;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* element_type_;
const LengthInfo length_info_;
};
class RuntimeArray : public Type {
public:
RuntimeArray(const Type* element_type);
RuntimeArray(const RuntimeArray&) = default;
std::string str() const override;
const Type* element_type() const { return element_type_; }
RuntimeArray* AsRuntimeArray() override { return this; }
const RuntimeArray* AsRuntimeArray() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
void ReplaceElementType(const Type* element_type);
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* element_type_;
};
class NodePayloadArrayAMDX : public Type {
public:
NodePayloadArrayAMDX(const Type* element_type);
NodePayloadArrayAMDX(const NodePayloadArrayAMDX&) = default;
std::string str() const override;
const Type* element_type() const { return element_type_; }
NodePayloadArrayAMDX* AsNodePayloadArrayAMDX() override { return this; }
const NodePayloadArrayAMDX* AsNodePayloadArrayAMDX() const override {
return this;
}
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
void ReplaceElementType(const Type* element_type);
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* element_type_;
};
class Struct : public Type {
public:
Struct(const std::vector<const Type*>& element_types);
Struct(const Struct&) = default;
// Adds a decoration to the member at the given index. The first word is the
// decoration enum, and the remaining words, if any, are its operands.
void AddMemberDecoration(uint32_t index, std::vector<uint32_t>&& decoration);
std::string str() const override;
const std::vector<const Type*>& element_types() const {
return element_types_;
}
std::vector<const Type*>& element_types() { return element_types_; }
bool decoration_empty() const override {
return decorations_.empty() && element_decorations_.empty();
}
const std::map<uint32_t, std::vector<std::vector<uint32_t>>>&
element_decorations() const {
return element_decorations_;
}
Struct* AsStruct() override { return this; }
const Struct* AsStruct() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
void ClearDecorations() override {
decorations_.clear();
element_decorations_.clear();
}
std::vector<const Type*> element_types_;
// We can attach decorations to struct members and that should not affect the
// underlying element type. So we need an extra data structure here to keep
// track of element type decorations. They must be stored in an ordered map
// because |GetExtraHashWords| will traverse the structure. It must have a
// fixed order in order to hash to the same value every time.
std::map<uint32_t, std::vector<std::vector<uint32_t>>> element_decorations_;
};
class Opaque : public Type {
public:
Opaque(std::string n) : Type(kOpaque), name_(std::move(n)) {}
Opaque(const Opaque&) = default;
std::string str() const override;
Opaque* AsOpaque() override { return this; }
const Opaque* AsOpaque() const override { return this; }
const std::string& name() const { return name_; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
std::string name_;
};
class Pointer : public Type {
public:
Pointer(const Type* pointee, spv::StorageClass sc);
Pointer(const Pointer&) = default;
std::string str() const override;
const Type* pointee_type() const { return pointee_type_; }
spv::StorageClass storage_class() const { return storage_class_; }
bool is_untyped() const { return pointee_type_ == nullptr; }
Pointer* AsPointer() override { return this; }
const Pointer* AsPointer() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
void SetPointeeType(const Type* type);
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* pointee_type_;
spv::StorageClass storage_class_;
};
class Function : public Type {
public:
Function(const Type* ret_type, const std::vector<const Type*>& params);
Function(const Type* ret_type, std::vector<const Type*>& params);
Function(const Function&) = default;
std::string str() const override;
Function* AsFunction() override { return this; }
const Function* AsFunction() const override { return this; }
const Type* return_type() const { return return_type_; }
const std::vector<const Type*>& param_types() const { return param_types_; }
std::vector<const Type*>& param_types() { return param_types_; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
void SetReturnType(const Type* type);
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* return_type_;
std::vector<const Type*> param_types_;
};
class Pipe : public Type {
public:
Pipe(spv::AccessQualifier qualifier)
: Type(kPipe), access_qualifier_(qualifier) {}
Pipe(const Pipe&) = default;
std::string str() const override;
Pipe* AsPipe() override { return this; }
const Pipe* AsPipe() const override { return this; }
spv::AccessQualifier access_qualifier() const { return access_qualifier_; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
spv::AccessQualifier access_qualifier_;
};
class ForwardPointer : public Type {
public:
ForwardPointer(uint32_t id, spv::StorageClass sc)
: Type(kForwardPointer),
target_id_(id),
storage_class_(sc),
pointer_(nullptr) {}
ForwardPointer(const ForwardPointer&) = default;
uint32_t target_id() const { return target_id_; }
void SetTargetPointer(const Pointer* pointer) { pointer_ = pointer; }
spv::StorageClass storage_class() const { return storage_class_; }
const Pointer* target_pointer() const { return pointer_; }
std::string str() const override;
ForwardPointer* AsForwardPointer() override { return this; }
const ForwardPointer* AsForwardPointer() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
uint32_t target_id_;
spv::StorageClass storage_class_;
const Pointer* pointer_;
};
class CooperativeMatrixNV : public Type {
public:
CooperativeMatrixNV(const Type* type, const uint32_t scope,
const uint32_t rows, const uint32_t columns);
CooperativeMatrixNV(const CooperativeMatrixNV&) = default;
std::string str() const override;
CooperativeMatrixNV* AsCooperativeMatrixNV() override { return this; }
const CooperativeMatrixNV* AsCooperativeMatrixNV() const override {
return this;
}
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
const Type* component_type() const { return component_type_; }
uint32_t scope_id() const { return scope_id_; }
uint32_t rows_id() const { return rows_id_; }
uint32_t columns_id() const { return columns_id_; }
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* component_type_;
const uint32_t scope_id_;
const uint32_t rows_id_;
const uint32_t columns_id_;
};
class CooperativeMatrixKHR : public Type {
public:
CooperativeMatrixKHR(const Type* type, const uint32_t scope,
const uint32_t rows, const uint32_t columns,
const uint32_t use);
CooperativeMatrixKHR(const CooperativeMatrixKHR&) = default;
std::string str() const override;
CooperativeMatrixKHR* AsCooperativeMatrixKHR() override { return this; }
const CooperativeMatrixKHR* AsCooperativeMatrixKHR() const override {
return this;
}
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
const Type* component_type() const { return component_type_; }
uint32_t scope_id() const { return scope_id_; }
uint32_t rows_id() const { return rows_id_; }
uint32_t columns_id() const { return columns_id_; }
uint32_t use_id() const { return use_id_; }
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* component_type_;
const uint32_t scope_id_;
const uint32_t rows_id_;
const uint32_t columns_id_;
const uint32_t use_id_;
};
class TensorLayoutNV : public Type {
public:
TensorLayoutNV(const uint32_t dim, const uint32_t clamp_mode);
TensorLayoutNV(const TensorLayoutNV&) = default;
std::string str() const override;
TensorLayoutNV* AsTensorLayoutNV() override { return this; }
const TensorLayoutNV* AsTensorLayoutNV() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
uint32_t dim_id() const { return dim_id_; }
uint32_t clamp_mode_id() const { return clamp_mode_id_; }
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const uint32_t dim_id_;
const uint32_t clamp_mode_id_;
};
class TensorViewNV : public Type {
public:
TensorViewNV(const uint32_t dim, const uint32_t clamp_mode,
const std::vector<uint32_t>& perm);
TensorViewNV(const TensorViewNV&) = default;
std::string str() const override;
TensorViewNV* AsTensorViewNV() override { return this; }
const TensorViewNV* AsTensorViewNV() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
uint32_t dim_id() const { return dim_id_; }
uint32_t has_dimensions_id() const { return has_dimensions_id_; }
const std::vector<uint32_t>& perm() const { return perm_; }
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const uint32_t dim_id_;
const uint32_t has_dimensions_id_;
std::vector<uint32_t> perm_;
};
class CooperativeVectorNV : public Type {
public:
CooperativeVectorNV(const Type* type, const uint32_t components);
CooperativeVectorNV(const CooperativeVectorNV&) = default;
std::string str() const override;
CooperativeVectorNV* AsCooperativeVectorNV() override { return this; }
const CooperativeVectorNV* AsCooperativeVectorNV() const override {
return this;
}
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
const Type* component_type() const { return component_type_; }
uint32_t components() const { return components_; }
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* component_type_;
const uint32_t components_;
};
class TensorARM : public Type {
public:
TensorARM(const Type* elty, const uint32_t rank = 0,
const uint32_t shape = 0);
TensorARM(const TensorARM&) = default;
std::string str() const override;
TensorARM* AsTensorARM() override { return this; }
const TensorARM* AsTensorARM() const override { return this; }
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
const Type* element_type() const { return element_type_; }
uint32_t rank_id() const { return rank_id_; }
uint32_t shape_id() const { return shape_id_; }
bool is_ranked() const { return rank_id_ != 0; }
bool is_shaped() const { return shape_id_ != 0; }
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const Type* element_type_;
const uint32_t rank_id_;
const uint32_t shape_id_;
};
class GraphARM : public Type {
public:
GraphARM(const uint32_t num_inputs, const std::vector<const Type*>& io_types);
GraphARM(const GraphARM&) = default;
std::string str() const override;
GraphARM* AsGraphARM() override { return this; }
const GraphARM* AsGraphARM() const override { return this; }
uint32_t num_inputs() const { return num_inputs_; }
const std::vector<const Type*>& io_types() const { return io_types_; }
bool is_shaped() const;
size_t ComputeExtraStateHash(size_t hash, SeenTypes* seen) const override;
private:
bool IsSameImpl(const Type* that, IsSameCache*) const override;
const uint32_t num_inputs_;
const std::vector<const Type*> io_types_;
};
#define DefineParameterlessType(type, name) \
class type : public Type { \
public: \
type() : Type(k##type) {} \
type(const type&) = default; \
\
std::string str() const override { return #name; } \
\
type* As##type() override { return this; } \
const type* As##type() const override { return this; } \
\
size_t ComputeExtraStateHash(size_t hash, SeenTypes*) const override { \
return hash; \
} \
\
private: \
bool IsSameImpl(const Type* that, IsSameCache*) const override { \
return that->As##type() && HasSameDecorations(that); \
} \
}
DefineParameterlessType(Void, void);
DefineParameterlessType(Bool, bool);
DefineParameterlessType(Sampler, sampler);
DefineParameterlessType(Event, event);
DefineParameterlessType(DeviceEvent, device_event);
DefineParameterlessType(ReserveId, reserve_id);
DefineParameterlessType(Queue, queue);
DefineParameterlessType(PipeStorage, pipe_storage);
DefineParameterlessType(NamedBarrier, named_barrier);
DefineParameterlessType(AccelerationStructureNV, accelerationStructureNV);
DefineParameterlessType(RayQueryKHR, rayQueryKHR);
DefineParameterlessType(HitObjectNV, hitObjectNV);
DefineParameterlessType(HitObjectEXT, hitObjectEXT);
#undef DefineParameterlessType
} // namespace analysis
} // namespace opt
} // namespace spvtools
#endif // SOURCE_OPT_TYPES_H_
|