Jelajahi Sumber

[spirv] Remove old representation of type, constant, and decoration.

Ehsan Nasiri 6 tahun lalu
induk
melakukan
b257554a5f

+ 0 - 106
tools/clang/include/clang/SPIRV/Constant.h

@@ -1,106 +0,0 @@
-//===-- Constant.h - SPIR-V Constant ----------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_SPIRV_CONSTANT_H
-#define LLVM_CLANG_SPIRV_CONSTANT_H
-
-#include <vector>
-
-#include "spirv/unified1/spirv.hpp11"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallVector.h"
-
-namespace clang {
-namespace spirv {
-
-class SPIRVContext;
-
-/// \brief SPIR-V Constant
-///
-/// This class defines a unique SPIR-V constant.
-/// A SPIR-V constant includes its <opcode> defined by the SPIR-V Spec.
-/// It also incldues any arguments (32-bit words) needed to initialize that
-/// constant.
-///
-/// The class includes static getXXX(...) functions for getting pointers of any
-/// needed constant. A unique constant has a unique pointer (e.g. calling
-/// 'getTrue' function will always return the same pointer for the given
-/// context).
-class Constant {
-public:
-  spv::Op getOpcode() const { return opcode; }
-  uint32_t getTypeId() const { return typeId; }
-  const llvm::SmallVector<uint32_t, 4> &getArgs() const { return args; }
-
-  // OpConstantTrue and OpConstantFalse are boolean.
-  // OpSpecConstantTrue and OpSpecConstantFalse are boolean.
-  bool isBoolean() const;
-
-  // OpConstant and OpSpecConstant are only allowed to take integers and floats.
-  bool isNumerical() const;
-
-  // OpConstantComposite and OpSpecConstantComposite.
-  bool isComposite() const;
-
-  // Get constants.
-  static const Constant *getTrue(SPIRVContext &ctx, uint32_t type_id);
-  static const Constant *getFalse(SPIRVContext &ctx, uint32_t type_id);
-  static const Constant *getInt16(SPIRVContext &ctx, uint32_t type_id,
-                                  int16_t value);
-  static const Constant *getInt32(SPIRVContext &ctx, uint32_t type_id,
-                                  int32_t value);
-  static const Constant *getInt64(SPIRVContext &ctx, uint32_t type_id,
-                                  int64_t value);
-  static const Constant *getUint16(SPIRVContext &ctx, uint32_t type_id,
-                                   uint16_t value);
-  static const Constant *getUint32(SPIRVContext &ctx, uint32_t type_id,
-                                   uint32_t value);
-  static const Constant *getUint64(SPIRVContext &ctx, uint32_t type_id,
-                                   uint64_t value);
-  static const Constant *getFloat16(SPIRVContext &ctx, uint32_t type_id,
-                                    int16_t value);
-  static const Constant *getFloat32(SPIRVContext &ctx, uint32_t type_id,
-                                    float value);
-  static const Constant *getFloat64(SPIRVContext &ctx, uint32_t type_id,
-                                    double value);
-
-  // TODO: 64-bit float and integer constant implementation
-
-  static const Constant *getComposite(SPIRVContext &ctx, uint32_t type_id,
-                                      llvm::ArrayRef<uint32_t> constituents);
-  static const Constant *getSampler(SPIRVContext &ctx, uint32_t type_id,
-                                    spv::SamplerAddressingMode, uint32_t param,
-                                    spv::SamplerFilterMode);
-  static const Constant *getNull(SPIRVContext &ctx, uint32_t type_id);
-
-  bool operator==(const Constant &other) const {
-    return opcode == other.opcode && typeId == other.typeId &&
-           args == other.args;
-  }
-
-  // \brief Construct the SPIR-V words for this constant with the given
-  // <result-id>.
-  std::vector<uint32_t> withResultId(uint32_t resultId) const;
-
-private:
-  /// \brief Private constructor.
-  Constant(spv::Op, uint32_t type, llvm::ArrayRef<uint32_t> arg = {});
-
-  /// \brief Returns the unique constant pointer within the given context.
-  static const Constant *getUniqueConstant(SPIRVContext &, const Constant &);
-
-private:
-  spv::Op opcode;  ///< OpCode of the constant
-  uint32_t typeId; ///< <result-id> of the type of the constant
-  llvm::SmallVector<uint32_t, 4> args; ///< Arguments defining the constant
-};
-
-} // end namespace spirv
-} // end namespace clang
-
-#endif

+ 0 - 180
tools/clang/include/clang/SPIRV/Decoration.h

@@ -1,180 +0,0 @@
-//===-- Decoration.h - SPIR-V Decoration ------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_SPIRV_DECORATION_H
-#define LLVM_CLANG_SPIRV_DECORATION_H
-
-#include <vector>
-
-#include "spirv/unified1/spirv.hpp11"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-
-namespace clang {
-namespace spirv {
-
-class SPIRVContext;
-
-/// \brief SPIR-V Decoration.
-///
-/// This class defines a unique SPIR-V Decoration.
-/// A SPIR-V Decoration includes an identifier defined by the SPIR-V Spec.
-/// It also incldues any arguments (32-bit words) needed to define the
-/// decoration. If the decoration applies to a structure member, it also
-/// includes the index of the member to which the decoration applies.
-///
-/// The class includes static getXXX(...) functions for getting pointers of any
-/// needed decoration. A unique Decoration has a unique pointer (e.g. calling
-/// 'getRelaxedPrecision' function will always return the same pointer for the
-/// given context).
-class Decoration {
-
-public:
-  spv::Decoration getValue() const { return id; }
-  const llvm::SmallVector<uint32_t, 2> &getArgs() const { return args; }
-  llvm::Optional<uint32_t> getMemberIndex() const { return memberIndex; }
-
-  static const Decoration *getRelaxedPrecision(SPIRVContext &ctx);
-  static const Decoration *getSpecId(SPIRVContext &ctx, uint32_t id);
-  static const Decoration *getBlock(SPIRVContext &ctx);
-  static const Decoration *getBufferBlock(SPIRVContext &ctx);
-  static const Decoration *getRowMajor(SPIRVContext &ctx, uint32_t member_idx);
-  static const Decoration *getColMajor(SPIRVContext &ctx, uint32_t member_idx);
-  static const Decoration *getArrayStride(SPIRVContext &ctx, uint32_t stride);
-  static const Decoration *getMatrixStride(SPIRVContext &ctx, uint32_t stride,
-                                           uint32_t member_idx);
-  static const Decoration *getGLSLShared(SPIRVContext &ctx);
-  static const Decoration *getGLSLPacked(SPIRVContext &ctx);
-  static const Decoration *getCPacked(SPIRVContext &ctx);
-  static const Decoration *
-  getBuiltIn(SPIRVContext &ctx, spv::BuiltIn builtin,
-             llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getNoPerspective(SPIRVContext &ctx,
-                   llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getFlat(SPIRVContext &ctx, llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getPatch(SPIRVContext &ctx, llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getCentroid(SPIRVContext &ctx,
-              llvm::Optional<uint32_t> member_idx = llvm::None);
-
-  static const Decoration *
-  getSample(SPIRVContext &ctx,
-            llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *getInvariant(SPIRVContext &ctx);
-  static const Decoration *getRestrict(SPIRVContext &ctx);
-  static const Decoration *getAliased(SPIRVContext &ctx);
-  static const Decoration *
-  getVolatile(SPIRVContext &ctx,
-              llvm::Optional<uint32_t> member_idx = llvm::None);
-
-  static const Decoration *getConstant(SPIRVContext &ctx);
-  static const Decoration *
-  getCoherent(SPIRVContext &ctx,
-              llvm::Optional<uint32_t> member_idx = llvm::None);
-
-  static const Decoration *
-  getNonWritable(SPIRVContext &ctx,
-                 llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getNonReadable(SPIRVContext &ctx,
-                 llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getUniform(SPIRVContext &ctx,
-             llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *getSaturatedConversion(SPIRVContext &ctx);
-  static const Decoration *
-  getStream(SPIRVContext &ctx, uint32_t stream_number,
-            llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getLocation(SPIRVContext &ctx, uint32_t location,
-              llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getComponent(SPIRVContext &ctx, uint32_t component,
-               llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *getIndex(SPIRVContext &ctx, uint32_t index);
-  static const Decoration *getBinding(SPIRVContext &ctx,
-                                      uint32_t binding_point);
-  static const Decoration *getDescriptorSet(SPIRVContext &ctx, uint32_t set);
-  static const Decoration *getOffset(SPIRVContext &ctx, uint32_t byte_offset,
-                                     uint32_t member_idx);
-  static const Decoration *
-  getXfbBuffer(SPIRVContext &ctx, uint32_t xfb_buf,
-               llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getXfbStride(SPIRVContext &ctx, uint32_t xfb_stride,
-               llvm::Optional<uint32_t> member_idx = llvm::None);
-  static const Decoration *
-  getFuncParamAttr(SPIRVContext &ctx, spv::FunctionParameterAttribute attr);
-  static const Decoration *getFPRoundingMode(SPIRVContext &ctx,
-                                             spv::FPRoundingMode mode);
-  static const Decoration *getFPFastMathMode(SPIRVContext &ctx,
-                                             spv::FPFastMathModeShift mode);
-  static const Decoration *getLinkageAttributes(SPIRVContext &ctx,
-                                                std::string name,
-                                                spv::LinkageType linkage_type);
-  static const Decoration *getNoContraction(SPIRVContext &ctx);
-  static const Decoration *getInputAttachmentIndex(SPIRVContext &ctx,
-                                                   uint32_t index);
-  static const Decoration *getAlignment(SPIRVContext &ctx, uint32_t alignment);
-  static const Decoration *getNonUniformEXT(SPIRVContext &ctx);
-  static const Decoration *getOverrideCoverageNV(SPIRVContext &ctx);
-  static const Decoration *getPassthroughNV(SPIRVContext &ctx);
-  static const Decoration *getViewportRelativeNV(SPIRVContext &ctx);
-  static const Decoration *getSecondaryViewportRelativeNV(SPIRVContext &ctx,
-                                                          uint32_t offset);
-  static const Decoration *getHlslCounterBufferGOOGLE(SPIRVContext &ctx,
-                                                      uint32_t id);
-  static const Decoration *
-  getHlslSemanticGOOGLE(SPIRVContext &ctx, llvm::StringRef semantic,
-                        llvm ::Optional<uint32_t> memberIdx = llvm::None);
-
-  bool operator==(const Decoration &other) const {
-    return id == other.id && args == other.args &&
-           memberIndex.hasValue() == other.memberIndex.hasValue() &&
-           (!memberIndex.hasValue() ||
-            memberIndex.getValue() == other.memberIndex.getValue());
-  }
-
-  // \brief Construct the SPIR-V words for this decoration with the given
-  // target <result-id>.
-  std::vector<uint32_t> withTargetId(uint32_t targetId) const;
-
-private:
-  /// \brief prevent public APIs from creating Decoration objects.
-  Decoration(spv::Decoration dec_id, llvm::ArrayRef<uint32_t> arg = {},
-             llvm::Optional<uint32_t> idx = llvm::None)
-      : id(dec_id), args(arg.begin(), arg.end()), memberIndex(idx) {}
-
-  /// \brief Sets the index of the structure member to which the decoration
-  /// applies.
-  void setMemberIndex(llvm::Optional<uint32_t> idx) { memberIndex = idx; }
-
-  /// \brief Returns the OpDecorate* variant to use for the given decoration and
-  /// struct member index.
-  static spv::Op getDecorateOpcode(spv::Decoration,
-                                   const llvm::Optional<uint32_t> &memberIndex);
-
-  /// \brief Returns the unique decoration pointer within the given context.
-  static const Decoration *getUniqueDecoration(SPIRVContext &ctx,
-                                               const Decoration &d);
-
-private:
-  spv::Decoration id;                   ///< Defined by SPIR-V Spec
-  llvm::SmallVector<uint32_t, 2> args;  ///< Decoration parameters
-  llvm::Optional<uint32_t> memberIndex; ///< Struct member index (if applicable)
-};
-
-} // end namespace spirv
-} // end namespace clang
-
-#endif

+ 0 - 95
tools/clang/include/clang/SPIRV/SPIRVContext.h

@@ -13,11 +13,8 @@
 #include <unordered_map>
 
 #include "clang/Frontend/FrontendAction.h"
-#include "clang/SPIRV/Constant.h"
-#include "clang/SPIRV/Decoration.h"
 #include "clang/SPIRV/SpirvInstruction.h"
 #include "clang/SPIRV/SpirvType.h"
-#include "clang/SPIRV/Type.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/Support/Allocator.h"
@@ -25,98 +22,6 @@
 namespace clang {
 namespace spirv {
 
-struct TypeHash {
-  std::size_t operator()(const Type &t) const {
-    // TODO: We could improve this hash function if necessary.
-    return std::hash<uint32_t>{}(static_cast<uint32_t>(t.getOpcode()));
-  }
-};
-struct DecorationHash {
-  std::size_t operator()(const Decoration &d) const {
-    // TODO: We could probably improve this hash function if needed.
-    return std::hash<uint32_t>{}(static_cast<uint32_t>(d.getValue()));
-  }
-};
-struct ConstantHash {
-  std::size_t operator()(const Constant &c) const {
-    // TODO: We could improve this hash function if necessary.
-    return std::hash<uint32_t>{}(static_cast<uint32_t>(c.getTypeId()));
-  }
-};
-
-/// \brief A class for holding various data needed in SPIR-V codegen.
-/// It should outlive all SPIR-V codegen components that requires/allocates
-/// data.
-class SPIRVContext {
-public:
-  /// \brief Constructs a default SPIR-V context.
-  inline SPIRVContext();
-
-  // Disable copy/move constructors/assignments.
-  SPIRVContext(const SPIRVContext &) = delete;
-  SPIRVContext(SPIRVContext &&) = delete;
-  SPIRVContext &operator=(const SPIRVContext &) = delete;
-  SPIRVContext &operator=(SPIRVContext &&) = delete;
-
-  /// \brief Returns the next unused <result-id>.
-  inline uint32_t getNextId() const;
-  /// \brief Consumes the next unused <result-id>.
-  inline uint32_t takeNextId();
-
-  /// \brief Returns the <result-id> that defines the given Type. If the type
-  /// has not been defined, it will define and store its instruction.
-  /// If isRegistered is not nullptr, *isRegistered will contain whether the
-  /// type was previously seen.
-  uint32_t getResultIdForType(const Type *type, bool *isRegistered = nullptr);
-
-  /// \brief Returns the <result-id> that defines the given Constant. If the
-  /// constant has not been defined, it will define and return its result-id.
-  uint32_t getResultIdForConstant(const Constant *);
-
-  /// \brief Registers the existence of the given type in the current context,
-  /// and returns the unique Type pointer.
-  const Type *registerType(const Type &);
-
-  /// \brief Registers the existence of the given constant in the current
-  /// context, and returns the unique pointer to it.
-  const Constant *registerConstant(const Constant &);
-
-  /// \brief Registers the existence of the given decoration in the current
-  /// context, and returns the unique Decoration pointer.
-  const Decoration *registerDecoration(const Decoration &);
-
-private:
-  using TypeSet = std::unordered_set<Type, TypeHash>;
-  using ConstantSet = std::unordered_set<Constant, ConstantHash>;
-  using DecorationSet = std::unordered_set<Decoration, DecorationHash>;
-
-  uint32_t nextId;
-
-  /// \brief All the unique Decorations defined in the current context.
-  DecorationSet existingDecorations;
-
-  /// \brief All the unique types defined in the current context.
-  TypeSet existingTypes;
-
-  /// \brief All constants defined in the current context.
-  /// These can be boolean, integer, float, or composite constants.
-  ConstantSet existingConstants;
-
-  /// \brief Maps a given type to the <result-id> that is defined for
-  /// that type. If a Type* does not exist in the map, the type
-  /// is not yet defined and is not associated with a <result-id>.
-  std::unordered_map<const Type *, uint32_t> typeResultIdMap;
-
-  /// \brief Maps a given constant to the <result-id> that is defined for
-  /// that constant. If a Constant* does not exist in the map, the constant
-  /// is not yet defined and is not associated with a <result-id>.
-  std::unordered_map<const Constant *, uint32_t> constantResultIdMap;
-};
-
-SPIRVContext::SPIRVContext() : nextId(1) {}
-uint32_t SPIRVContext::getNextId() const { return nextId; }
-uint32_t SPIRVContext::takeNextId() { return nextId++; }
-
 // Provides DenseMapInfo for spv::StorageClass so that we can use
 // spv::StorageClass as key to DenseMap.
 //

+ 0 - 540
tools/clang/include/clang/SPIRV/Structure.h

@@ -1,540 +0,0 @@
-//===--- Structure.h - SPIR-V representation structures ------*- C++ -*---===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines several classes for representing SPIR-V basic blocks,
-// functions, and modules. They are not intended to be general representations
-// that can be used for various purposes; instead, they are just special
-// crafted to be provide structured representation of SPIR-V modules in the
-// ModuleBuilder.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_SPIRV_STRUCTURE_H
-#define LLVM_CLANG_SPIRV_STRUCTURE_H
-
-#include <deque>
-#include <memory>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "spirv/unified1/spirv.hpp11"
-#include "clang/SPIRV/Constant.h"
-#include "clang/SPIRV/InstBuilder.h"
-#include "clang/SPIRV/Type.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/MapVector.h"
-#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/StringRef.h"
-#include "dxc/Support/SPIRVOptions.h"
-
-namespace clang {
-namespace spirv {
-
-// === Instruction definition ===
-
-/// \brief The class representing a SPIR-V instruction.
-class Instruction {
-public:
-  /// Constructs an instruction from the given underlying SPIR-V binary words.
-  inline Instruction(std::vector<uint32_t> &&);
-
-  // Copy constructor/assignment
-  Instruction(const Instruction &) = default;
-  Instruction &operator=(const Instruction &) = default;
-
-  // Move constructor/assignment
-  Instruction(Instruction &&) = default;
-  Instruction &operator=(Instruction &&) = default;
-
-  /// Returns true if this instruction is empty, which contains no underlying
-  /// SPIR-V binary words.
-  inline bool isEmpty() const;
-
-  /// Returns the opcode for this instruction. Returns spv::Op::Max if this
-  /// instruction is empty.
-  spv::Op getOpcode() const;
-
-  /// Returns the underlying SPIR-v binary words for this instruction.
-  /// This instruction will be in an empty state after this call.
-  inline std::vector<uint32_t> take();
-
-  /// Returns true if this instruction is a termination instruction.
-  ///
-  /// See "2.2.4. Control Flow" in the SPIR-V spec for the defintion of
-  /// termination instructions.
-  bool isTerminator() const;
-
-private:
-  // TODO: do some statistics and switch to use SmallVector here if helps.
-  std::vector<uint32_t> words; ///< Underlying SPIR-V words
-};
-
-// === Basic block definition ===
-
-/// \brief The class representing a SPIR-V basic block.
-class BasicBlock {
-public:
-  /// \brief Constructs a basic block with the given <label-id>.
-  inline explicit BasicBlock(uint32_t labelId, llvm::StringRef debugName = "");
-
-  // Disable copy constructor/assignment
-  BasicBlock(const BasicBlock &) = delete;
-  BasicBlock &operator=(const BasicBlock &) = delete;
-
-  // Move constructor/assignment
-  BasicBlock(BasicBlock &&that);
-  BasicBlock &operator=(BasicBlock &&that);
-
-  /// \brief Returns true if this basic block is empty, which has no <label-id>
-  /// assigned and no instructions.
-  inline bool isEmpty() const;
-  /// \brief Clears everything in this basic block and turns it into an
-  /// empty basic block.
-  inline void clear();
-
-  /// \brief Serializes this basic block and feeds it to the comsumer in the
-  /// given InstBuilder. After this call, this basic block will be in an empty
-  /// state.
-  void take(InstBuilder *builder);
-
-  /// \brief Appends an instruction to this basic block.
-  inline void appendInstruction(Instruction &&);
-
-  /// \brief Preprends an instruction to this basic block.
-  inline void prependInstruction(Instruction &&);
-
-  /// \brief Adds the given basic block as a successsor to this basic block.
-  inline void addSuccessor(BasicBlock *);
-
-  /// \brief Gets all successor basic blocks.
-  inline const llvm::SmallVector<BasicBlock *, 2> &getSuccessors() const;
-
-  /// \brief Sets the merge target to the given basic block.
-  /// The caller must make sure this basic block contains an OpSelectionMerge or
-  /// OpLoopMerge instruction.
-  inline void setMergeTarget(BasicBlock *);
-
-  /// \brief Returns the merge target if this basic block contains an
-  /// OpSelectionMerge or OpLoopMerge instruction. Returns nullptr otherwise.
-  inline BasicBlock *getMergeTarget() const;
-
-  /// \brief Sets the continue target to the given basic block.
-  /// The caller must make sure this basic block contains an OpLoopMerge
-  /// instruction.
-  inline void setContinueTarget(BasicBlock *);
-
-  /// \brief Returns the continue target if this basic block contains an
-  /// OpLoopMerge instruction. Returns nullptr otherwise.
-  inline BasicBlock *getContinueTarget() const;
-
-  /// \brief Returns the label id of this basic block.
-  inline uint32_t getLabelId() const;
-
-  /// \brief Returns the debug name of this basic block.
-  inline llvm::StringRef getDebugName() const;
-
-  /// \brief Returns true if this basic block is terminated.
-  bool isTerminated() const;
-
-private:
-  uint32_t labelId; ///< The label id for this basic block. Zero means invalid.
-  std::string debugName;
-  std::deque<Instruction> instructions;
-
-  llvm::SmallVector<BasicBlock *, 2> successors;
-  BasicBlock *mergeTarget;
-  BasicBlock *continueTarget;
-};
-
-// === Function definition ===
-
-/// \brief The class representing a SPIR-V function.
-class Function {
-public:
-  /// \brief Constructs a SPIR-V function with the given parameters.
-  inline Function(uint32_t resultType, uint32_t resultId,
-                  spv::FunctionControlMask control, uint32_t functionType);
-
-  // Disable copy constructor/assignment
-  Function(const Function &) = delete;
-  Function &operator=(const Function &) = delete;
-
-  // Move constructor/assignment
-  Function(Function &&that);
-  Function &operator=(Function &&that);
-
-  /// \brief Returns true if this function is empty.
-  inline bool isEmpty() const;
-
-  /// \brief Clears all paramters and basic blocks and turns this function into
-  /// an empty function.
-  void clear();
-
-  /// \brief Serializes this function and feeds it to the comsumer in the given
-  /// InstBuilder. After this call, this function will be in an empty state.
-  void take(InstBuilder *builder);
-
-  /// \brief Adds a parameter to this function.
-  inline void addParameter(uint32_t paramResultType, uint32_t paramResultId);
-
-  /// \brief Adds a local variable to this function.
-  void addVariable(uint32_t varResultType, uint32_t varResultId,
-                   llvm::Optional<uint32_t> init);
-
-  /// \brief Adds a basic block to this function.
-  inline void addBasicBlock(std::unique_ptr<BasicBlock> block);
-
-  /// \brief Adds the reachable basic blocks of this function to the given
-  /// vector.
-  void getReachableBasicBlocks(std::vector<BasicBlock *> *) const;
-
-private:
-  uint32_t resultType;
-  uint32_t resultId;
-  spv::FunctionControlMask funcControl;
-  uint32_t funcType;
-
-  /// Parameter <result-type> and <result-id> pairs.
-  std::vector<std::pair<uint32_t, uint32_t>> parameters;
-  /// Local variables.
-  std::vector<Instruction> variables;
-  std::vector<std::unique_ptr<BasicBlock>> blocks;
-};
-
-// === Module components defintion ====
-
-/// \brief The struct representing a SPIR-V module header.
-struct Header {
-  /// \brief Default constructs a SPIR-V module header with id bound 0.
-  Header();
-
-  /// \brief Feeds the consumer with all the SPIR-V words for this header.
-  void collect(const WordConsumer &consumer);
-
-  const uint32_t magicNumber;
-  uint32_t version;
-  const uint32_t generator;
-  uint32_t bound;
-  const uint32_t reserved;
-};
-
-/// \brief The struct representing an entry point.
-struct EntryPoint {
-  inline EntryPoint(spv::ExecutionModel, uint32_t id, std::string name,
-                    const std::vector<uint32_t> &interface);
-
-  const spv::ExecutionModel executionModel;
-  const uint32_t targetId;
-  const std::string targetName;
-  const std::vector<uint32_t> interfaces;
-};
-
-/// \brief The struct representing a debug name.
-struct DebugName {
-  inline DebugName(uint32_t id, std::string targetName,
-                   llvm::Optional<uint32_t> index = llvm::None);
-
-  bool operator==(const DebugName &that) const;
-  bool operator<(const DebugName &that) const;
-
-  const uint32_t targetId;
-  const std::string name;
-  const llvm::Optional<uint32_t> memberIndex;
-};
-
-/// \brief The struct representing a deocoration and its target <result-id>.
-struct DecorationIdPair {
-  inline DecorationIdPair(const Decoration &decor, uint32_t id);
-
-  const Decoration &decoration;
-  const uint32_t targetId;
-};
-
-/// \brief The struct representing a type and its <result-id>.
-struct TypeIdPair {
-  inline TypeIdPair(const Type &ty, uint32_t id);
-
-  const Type &type;
-  const uint32_t resultId;
-};
-
-// === Module defintion ====
-
-/// \brief The class representing a SPIR-V module.
-class SPIRVModule {
-public:
-  /// \brief Default constructs an empty SPIR-V module.
-  inline SPIRVModule(const SpirvCodeGenOptions &options);
-
-  // Disable copy constructor/assignment
-  SPIRVModule(const SPIRVModule &) = delete;
-  SPIRVModule &operator=(const SPIRVModule &) = delete;
-
-  // Move constructor/assignment
-  SPIRVModule(SPIRVModule &&that) = default;
-  SPIRVModule &operator=(SPIRVModule &&that) = default;
-
-  /// \brief Returns true if this module is empty.
-  bool isEmpty() const;
-  /// \brief Clears all instructions and functions and turns this module into
-  /// an empty module.
-  void clear();
-
-  /// \brief Collects all the SPIR-V words in this module and consumes them
-  /// using the consumer within the given InstBuilder. This method is
-  /// destructive; the module will be consumed and cleared after calling it.
-  void take(InstBuilder *builder);
-
-  /// \brief Sets the id bound to the given bound.
-  inline void setBound(uint32_t newBound);
-
-  /// \brief Sets the string representation of the command line options.
-  inline void addCapability(spv::Capability);
-  inline void addExtension(llvm::StringRef extension);
-  inline void addExtInstSet(uint32_t setId, llvm::StringRef extInstSet);
-  inline void setAddressingModel(spv::AddressingModel);
-  inline void setMemoryModel(spv::MemoryModel);
-  inline void addEntryPoint(spv::ExecutionModel, uint32_t targetId,
-                            std::string targetName,
-                            llvm::ArrayRef<uint32_t> intefaces);
-  inline void addExecutionMode(Instruction &&);
-  inline void setShaderModelVersion(uint32_t);
-  inline void setSourceFileName(uint32_t id, std::string name);
-  inline void setSourceFileContent(llvm::StringRef content);
-  // TODO: source code debug information
-  inline void addDebugName(uint32_t targetId, llvm::StringRef name,
-                           llvm::Optional<uint32_t> memberIndex = llvm::None);
-  /// \brief Adds a decoration to the given target.
-  inline void addDecoration(const Decoration *decoration, uint32_t targetId);
-  /// \brief Adds a type to the module. Also adds the type's decorations to the
-  /// set of decorations of the module.
-  void addType(const Type *type, uint32_t resultId);
-  /// \brief Adds a constant to the module. Also adds the constant's decorations
-  /// to the set of decorations of the module.
-  void addConstant(const Constant *constant, uint32_t resultId);
-  inline void addVariable(Instruction &&);
-  inline void addFunction(std::unique_ptr<Function>);
-
-  /// \brief Returns the <result-id> of the given extended instruction set.
-  /// Returns 0 if the given set has not been imported.
-  inline uint32_t getExtInstSetId(llvm::StringRef setName);
-
-private:
-  const SpirvCodeGenOptions &spirvOptions;
-
-  Header header; ///< SPIR-V module header.
-  llvm::SetVector<spv::Capability> capabilities;
-  llvm::SetVector<std::string> extensions;
-  llvm::MapVector<const char *, uint32_t> extInstSets;
-  // Addressing and memory model must exist for a valid SPIR-V module.
-  // We make them optional here just to provide extra flexibility of
-  // the representation.
-  llvm::Optional<spv::AddressingModel> addressingModel;
-  llvm::Optional<spv::MemoryModel> memoryModel;
-  std::vector<EntryPoint> entryPoints;
-  std::vector<Instruction> executionModes;
-  uint32_t shaderModelVersion;
-  uint32_t sourceFileNameId; // The <result-id> for the OpString for file name
-  std::string sourceFileName;
-  llvm::StringRef sourceFileContent;
-  // TODO: source code debug information
-  std::set<DebugName> debugNames;
-  llvm::SetVector<std::pair<uint32_t, const Decoration *>> decorations;
-
-  // Note that types and constants are interdependent; Types like arrays have
-  // <result-id>s for constants in their definition, and constants all have
-  // their corresponding types. They should be handled together.
-  std::vector<Instruction> typeConstant;
-  // Keep track of whether we have already emitted code into the above vector
-  // for a certain type or constant.
-  llvm::DenseSet<const Type *> types;
-  llvm::DenseSet<const Constant *> constants;
-
-  std::vector<Instruction> variables;
-  std::vector<std::unique_ptr<Function>> functions;
-
-  std::string clOptions; ///< String representation of command line options.
-};
-
-// === Instruction inline implementations ===
-
-Instruction::Instruction(std::vector<uint32_t> &&data)
-    : words(std::move(data)) {}
-
-bool Instruction::isEmpty() const { return words.empty(); }
-
-std::vector<uint32_t> Instruction::take() { return std::move(words); }
-
-// === Basic block inline implementations ===
-
-BasicBlock::BasicBlock(uint32_t id, llvm::StringRef name)
-    : labelId(id), debugName(name), mergeTarget(nullptr),
-      continueTarget(nullptr) {}
-
-bool BasicBlock::isEmpty() const {
-  return labelId == 0 && instructions.empty();
-}
-
-void BasicBlock::clear() {
-  labelId = 0;
-  debugName = "";
-  instructions.clear();
-}
-
-void BasicBlock::appendInstruction(Instruction &&inst) {
-  instructions.push_back(std::move(inst));
-}
-
-void BasicBlock::prependInstruction(Instruction &&inst) {
-  instructions.push_front(std::move(inst));
-}
-
-void BasicBlock::addSuccessor(BasicBlock *successor) {
-  successors.push_back(successor);
-}
-
-const llvm::SmallVector<BasicBlock *, 2> &BasicBlock::getSuccessors() const {
-  return successors;
-}
-
-void BasicBlock::setMergeTarget(BasicBlock *target) { mergeTarget = target; }
-
-BasicBlock *BasicBlock::getMergeTarget() const { return mergeTarget; }
-
-void BasicBlock::setContinueTarget(BasicBlock *target) {
-  continueTarget = target;
-}
-
-BasicBlock *BasicBlock::getContinueTarget() const { return continueTarget; }
-
-uint32_t BasicBlock::getLabelId() const { return labelId; }
-llvm::StringRef BasicBlock::getDebugName() const { return debugName; }
-
-// === Function inline implementations ===
-
-Function::Function(uint32_t rType, uint32_t rId,
-                   spv::FunctionControlMask control, uint32_t fType)
-    : resultType(rType), resultId(rId), funcControl(control), funcType(fType) {}
-
-bool Function::isEmpty() const {
-  return resultType == 0 && resultId == 0 &&
-         funcControl == spv::FunctionControlMask::MaskNone && funcType == 0 &&
-         parameters.empty() && blocks.empty();
-}
-
-void Function::addParameter(uint32_t rType, uint32_t rId) {
-  parameters.emplace_back(rType, rId);
-}
-
-void Function::addBasicBlock(std::unique_ptr<BasicBlock> block) {
-  blocks.push_back(std::move(block));
-}
-
-// === Module components inline implementations ===
-
-EntryPoint::EntryPoint(spv::ExecutionModel em, uint32_t id, std::string name,
-                       const std::vector<uint32_t> &interface)
-    : executionModel(em), targetId(id), targetName(std::move(name)),
-      interfaces(interface) {}
-
-DebugName::DebugName(uint32_t id, std::string targetName,
-                     llvm::Optional<uint32_t> index)
-    : targetId(id), name(std::move(targetName)), memberIndex(index) {}
-
-DecorationIdPair::DecorationIdPair(const Decoration &decor, uint32_t id)
-    : decoration(decor), targetId(id) {}
-
-TypeIdPair::TypeIdPair(const Type &ty, uint32_t id) : type(ty), resultId(id) {}
-
-// === Module inline implementations ===
-
-SPIRVModule::SPIRVModule(const SpirvCodeGenOptions &options)
-    : spirvOptions(options), addressingModel(llvm::None),
-      memoryModel(llvm::None), shaderModelVersion(0), sourceFileNameId(0) {}
-
-void SPIRVModule::setBound(uint32_t newBound) { header.bound = newBound; }
-
-void SPIRVModule::addCapability(spv::Capability cap) {
-  capabilities.insert(cap);
-}
-
-void SPIRVModule::addExtension(llvm::StringRef ext) {
-  extensions.insert(ext.str());
-}
-
-uint32_t SPIRVModule::getExtInstSetId(llvm::StringRef setName) {
-  const auto &iter = extInstSets.find(setName.data());
-  if (iter != extInstSets.end())
-    return iter->second;
-  return 0;
-}
-
-void SPIRVModule::addExtInstSet(uint32_t setId, llvm::StringRef extInstSet) {
-  extInstSets.insert(std::make_pair(extInstSet.data(), setId));
-}
-
-void SPIRVModule::setAddressingModel(spv::AddressingModel am) {
-  addressingModel = llvm::Optional<spv::AddressingModel>(am);
-}
-
-void SPIRVModule::setMemoryModel(spv::MemoryModel mm) {
-  memoryModel = llvm::Optional<spv::MemoryModel>(mm);
-}
-
-void SPIRVModule::addEntryPoint(spv::ExecutionModel em, uint32_t targetId,
-                                std::string name,
-                                llvm::ArrayRef<uint32_t> interfaces) {
-  entryPoints.emplace_back(em, targetId, std::move(name), interfaces);
-}
-
-void SPIRVModule::addExecutionMode(Instruction &&execMode) {
-  executionModes.push_back(std::move(execMode));
-}
-
-void SPIRVModule::setShaderModelVersion(uint32_t version) {
-  shaderModelVersion = version;
-}
-
-void SPIRVModule::setSourceFileName(uint32_t id, std::string name) {
-  sourceFileNameId = id;
-  sourceFileName = std::move(name);
-}
-
-void SPIRVModule::setSourceFileContent(llvm::StringRef content) {
-  sourceFileContent = content;
-}
-
-void SPIRVModule::addDebugName(uint32_t targetId, llvm::StringRef name,
-                               llvm::Optional<uint32_t> memberIndex) {
-
-  if (!name.empty()) {
-    debugNames.insert(DebugName(targetId, name, memberIndex));
-  }
-}
-
-void SPIRVModule::addDecoration(const Decoration *decoration,
-                                uint32_t targetId) {
-  decorations.insert(std::make_pair(targetId, decoration));
-}
-
-void SPIRVModule::addVariable(Instruction &&var) {
-  variables.push_back(std::move(var));
-}
-
-void SPIRVModule::addFunction(std::unique_ptr<Function> f) {
-  functions.push_back(std::move(f));
-}
-
-} // end namespace spirv
-} // end namespace clang
-
-#endif

+ 0 - 134
tools/clang/include/clang/SPIRV/Type.h

@@ -1,134 +0,0 @@
-//===-- Type.h - SPIR-V Type ------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_SPIRV_TYPE_H
-#define LLVM_CLANG_SPIRV_TYPE_H
-
-#include <set>
-#include <unordered_set>
-#include <vector>
-
-#include "spirv/unified1/spirv.hpp11"
-#include "clang/SPIRV/Decoration.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/StringRef.h"
-
-namespace clang {
-namespace spirv {
-
-class SPIRVContext;
-
-/// \brief SPIR-V Type
-///
-/// This class defines a unique SPIR-V Type.
-/// A SPIR-V Type includes its <opcode> defined by the SPIR-V Spec.
-/// It also incldues any arguments (32-bit words) needed to define the
-/// type. It also includes a set of decorations that are applied to that type.
-///
-/// The class includes static getXXX(...) functions for getting pointers of any
-/// needed type. A unique type has a unique pointer (e.g. calling
-/// 'getBoolean' function will always return the same pointer for the given
-/// context).
-class Type {
-public:
-  using DecorationSet = llvm::ArrayRef<const Decoration *>;
-
-  spv::Op getOpcode() const { return opcode; }
-  const std::vector<uint32_t> &getArgs() const { return args; }
-  const llvm::SetVector<const Decoration *> &getDecorations() const {
-    return decorations;
-  }
-  bool hasDecoration(const Decoration *) const;
-
-  bool isBooleanType() const;
-  bool isIntegerType() const;
-  bool isFloatType() const;
-  bool isNumericalType() const;
-  bool isScalarType() const;
-  bool isVectorType() const;
-  bool isMatrixType() const;
-  bool isArrayType() const;
-  bool isStructureType() const;
-  bool isAggregateType() const;
-  bool isCompositeType() const;
-  bool isImageType() const;
-
-  // Scalar types do not take any decorations.
-  static const Type *getVoid(SPIRVContext &ctx);
-  static const Type *getBool(SPIRVContext &ctx);
-  static const Type *getInt8(SPIRVContext &ctx);
-  static const Type *getUint8(SPIRVContext &ctx);
-  static const Type *getInt16(SPIRVContext &ctx);
-  static const Type *getUint16(SPIRVContext &ctx);
-  static const Type *getInt32(SPIRVContext &ctx);
-  static const Type *getUint32(SPIRVContext &ctx);
-  static const Type *getInt64(SPIRVContext &ctx);
-  static const Type *getUint64(SPIRVContext &ctx);
-  static const Type *getFloat16(SPIRVContext &ctx);
-  static const Type *getFloat32(SPIRVContext &ctx);
-  static const Type *getFloat64(SPIRVContext &ctx);
-  static const Type *getVec2(SPIRVContext &ctx, uint32_t component_type);
-  static const Type *getVec3(SPIRVContext &ctx, uint32_t component_type);
-  static const Type *getVec4(SPIRVContext &ctx, uint32_t component_type);
-  static const Type *getMatrix(SPIRVContext &ctx, uint32_t column_type_id,
-                               uint32_t column_count);
-
-  static const Type *
-  getImage(SPIRVContext &ctx, uint32_t sampled_type, spv::Dim dim,
-           uint32_t depth, uint32_t arrayed, uint32_t ms, uint32_t sampled,
-           spv::ImageFormat image_format,
-           llvm::Optional<spv::AccessQualifier> access_qualifier = llvm::None,
-           DecorationSet decs = {});
-  static const Type *getSampler(SPIRVContext &ctx, DecorationSet decs = {});
-  static const Type *getSampledImage(SPIRVContext &ctx, uint32_t imag_type_id,
-                                     DecorationSet decs = {});
-  static const Type *getArray(SPIRVContext &ctx, uint32_t component_type_id,
-                              uint32_t len_id, DecorationSet decs = {});
-  static const Type *getRuntimeArray(SPIRVContext &ctx,
-                                     uint32_t component_type_id,
-                                     DecorationSet decs = {});
-  static const Type *getStruct(SPIRVContext &ctx,
-                               llvm::ArrayRef<uint32_t> members,
-                               llvm::StringRef name = {}, DecorationSet d = {});
-  static const Type *getPointer(SPIRVContext &ctx,
-                                spv::StorageClass storage_class, uint32_t type,
-                                DecorationSet decs = {});
-  static const Type *getFunction(SPIRVContext &ctx, uint32_t return_type,
-                                 const std::vector<uint32_t> &params,
-                                 DecorationSet decs = {});
-  bool operator==(const Type &other) const;
-
-  // \brief Construct the SPIR-V words for this type with the given <result-id>.
-  std::vector<uint32_t> withResultId(uint32_t resultId) const;
-
-private:
-  /// \brief Private constructor.
-  Type(spv::Op op, std::vector<uint32_t> arg = {}, DecorationSet dec = {},
-       llvm::StringRef name = {});
-
-  /// \brief Returns the unique Type pointer within the given context.
-  static const Type *getUniqueType(SPIRVContext &, const Type &);
-
-private:
-  spv::Op opcode;             ///< OpCode of the Type defined in SPIR-V Spec
-  std::vector<uint32_t> args; ///< Arguments needed to define the type
-  std::string name;           ///< Source code name of this type
-
-  /// The decorations that are applied to a type.
-  /// Note: we use a SetVector because:
-  /// a) Duplicate decorations should be removed.
-  /// b) Order of insertion matters for deterministic SPIR-V emitting
-  llvm::SetVector<const Decoration *> decorations;
-};
-
-} // end namespace spirv
-} // end namespace clang
-
-#endif

+ 0 - 4
tools/clang/lib/SPIRV/CMakeLists.txt

@@ -7,9 +7,7 @@ add_clang_library(clangSPIRV
   AstTypeProbe.cpp
   BlockReadableOrder.cpp
   CapabilityVisitor.cpp
-  Constant.cpp
   DeclResultIdMapper.cpp
-  Decoration.cpp
   EmitSPIRVAction.cpp
   EmitVisitor.cpp
   FeatureManager.cpp
@@ -28,8 +26,6 @@ add_clang_library(clangSPIRV
   SpirvModule.cpp
   SpirvType.cpp
   String.cpp
-  Structure.cpp
-  Type.cpp
 
   LINK_LIBS
   clangAST

+ 0 - 210
tools/clang/lib/SPIRV/Constant.cpp

@@ -1,210 +0,0 @@
-//===--- Constant.cpp - SPIR-V Constant implementation --------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/SPIRV/Constant.h"
-#include "clang/SPIRV/BitwiseCast.h"
-#include "clang/SPIRV/SPIRVContext.h"
-
-namespace {
-uint32_t zeroExtendTo32Bits(uint16_t value) {
-  // TODO: The ordering of the 2 words depends on the endian-ness of the host
-  // machine. Assuming Little Endian at the moment.
-  struct two16Bits {
-    uint16_t low;
-    uint16_t high;
-  };
-
-  two16Bits result = {value, 0};
-  return clang::spirv::cast::BitwiseCast<uint32_t, two16Bits>(result);
-}
-
-uint32_t signExtendTo32Bits(int16_t value) {
-  // TODO: The ordering of the 2 words depends on the endian-ness of the host
-  // machine. Assuming Little Endian at the moment.
-  struct two16Bits {
-    int16_t low;
-    uint16_t high;
-  };
-
-  two16Bits result = {value, 0};
-
-  // Sign bit is 1
-  if (value >> 15) {
-    result.high = 0xffff;
-  }
-  return clang::spirv::cast::BitwiseCast<uint32_t, two16Bits>(result);
-}
-} // namespace
-
-namespace clang {
-namespace spirv {
-
-Constant::Constant(spv::Op op, uint32_t type, llvm::ArrayRef<uint32_t> arg)
-    : opcode(op), typeId(type), args(arg.begin(), arg.end()) {}
-
-const Constant *Constant::getUniqueConstant(SPIRVContext &context,
-                                            const Constant &c) {
-  return context.registerConstant(c);
-}
-
-const Constant *Constant::getTrue(SPIRVContext &ctx, uint32_t type_id) {
-  Constant c = Constant(spv::Op::OpConstantTrue, type_id, {});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getFalse(SPIRVContext &ctx, uint32_t type_id) {
-  Constant c = Constant(spv::Op::OpConstantFalse, type_id, {});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getFloat16(SPIRVContext &ctx, uint32_t type_id,
-                                     int16_t value) {
-  // According to the SPIR-V Spec:
-  // When the type's bit width is less than 32-bits, the literal's value appears
-  // in the low-order bits of the word, and the high-order bits must be 0 for a
-  // floating-point type.
-  Constant c =
-      Constant(spv::Op::OpConstant, type_id, {zeroExtendTo32Bits(value)});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getFloat32(SPIRVContext &ctx, uint32_t type_id,
-                                     float value) {
-  Constant c = Constant(spv::Op::OpConstant, type_id,
-                        {cast::BitwiseCast<uint32_t, float>(value)});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getFloat64(SPIRVContext &ctx, uint32_t type_id,
-                                     double value) {
-  // TODO: The ordering of the 2 words depends on the endian-ness of the host
-  // machine.
-  struct wideFloat {
-    uint32_t word0;
-    uint32_t word1;
-  };
-  wideFloat words = cast::BitwiseCast<wideFloat, double>(value);
-  Constant c =
-      Constant(spv::Op::OpConstant, type_id, {words.word0, words.word1});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getUint16(SPIRVContext &ctx, uint32_t type_id,
-                                    uint16_t value) {
-  // According to the SPIR-V Spec:
-  // When the type's bit width is less than 32-bits, the literal's value appears
-  // in the low-order bits of the word, and the high-order bits must be 0 for an
-  // integer type with Signedness of 0.
-  Constant c =
-      Constant(spv::Op::OpConstant, type_id, {zeroExtendTo32Bits(value)});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getUint32(SPIRVContext &ctx, uint32_t type_id,
-                                    uint32_t value) {
-  Constant c = Constant(spv::Op::OpConstant, type_id, {value});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getUint64(SPIRVContext &ctx, uint32_t type_id,
-                                    uint64_t value) {
-  struct wideInt {
-    uint32_t word0;
-    uint32_t word1;
-  };
-  wideInt words = cast::BitwiseCast<wideInt, uint64_t>(value);
-  Constant c =
-      Constant(spv::Op::OpConstant, type_id, {words.word0, words.word1});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getInt16(SPIRVContext &ctx, uint32_t type_id,
-                                   int16_t value) {
-  // According to the SPIR-V Spec:
-  // When the type's bit width is less than 32-bits, the literal's value appears
-  // in the low-order bits of the word, and the high-order bits must be
-  // sign-extended for integers with Signedness of 1.
-  Constant c =
-      Constant(spv::Op::OpConstant, type_id, {signExtendTo32Bits(value)});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getInt32(SPIRVContext &ctx, uint32_t type_id,
-                                   int32_t value) {
-  Constant c = Constant(spv::Op::OpConstant, type_id,
-                        {cast::BitwiseCast<uint32_t, int32_t>(value)});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getInt64(SPIRVContext &ctx, uint32_t type_id,
-                                   int64_t value) {
-  struct wideInt {
-    uint32_t word0;
-    uint32_t word1;
-  };
-  wideInt words = cast::BitwiseCast<wideInt, int64_t>(value);
-  Constant c =
-      Constant(spv::Op::OpConstant, type_id, {words.word0, words.word1});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getComposite(SPIRVContext &ctx, uint32_t type_id,
-                                       llvm::ArrayRef<uint32_t> constituents) {
-  Constant c = Constant(spv::Op::OpConstantComposite, type_id, constituents);
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getSampler(SPIRVContext &ctx, uint32_t type_id,
-                                     spv::SamplerAddressingMode sam,
-                                     uint32_t param,
-                                     spv::SamplerFilterMode sfm) {
-  Constant c =
-      Constant(spv::Op::OpConstantSampler, type_id,
-               {static_cast<uint32_t>(sam), param, static_cast<uint32_t>(sfm)});
-  return getUniqueConstant(ctx, c);
-}
-
-const Constant *Constant::getNull(SPIRVContext &ctx, uint32_t type_id) {
-  Constant c = Constant(spv::Op::OpConstantNull, type_id, {});
-  return getUniqueConstant(ctx, c);
-}
-
-bool Constant::isBoolean() const {
-  return (opcode == spv::Op::OpConstantTrue ||
-          opcode == spv::Op::OpConstantFalse ||
-          opcode == spv::Op::OpSpecConstantTrue ||
-          opcode == spv::Op::OpSpecConstantFalse);
-}
-
-bool Constant::isNumerical() const {
-  return (opcode == spv::Op::OpConstant || opcode == spv::Op::OpSpecConstant);
-}
-
-bool Constant::isComposite() const {
-  return (opcode == spv::Op::OpConstantComposite ||
-          opcode == spv::Op::OpSpecConstantComposite);
-}
-
-std::vector<uint32_t> Constant::withResultId(uint32_t resultId) const {
-  std::vector<uint32_t> words;
-
-  // TODO: we are essentially duplicate the work InstBuilder is responsible for.
-  // Should figure out a way to unify them.
-  words.reserve(3 + args.size());
-  words.push_back(static_cast<uint32_t>(opcode));
-  words.push_back(typeId);
-  words.push_back(resultId);
-  words.insert(words.end(), args.begin(), args.end());
-  words.front() |= static_cast<uint32_t>(words.size()) << 16;
-
-  return words;
-}
-
-} // end namespace spirv
-} // end namespace clang

+ 0 - 336
tools/clang/lib/SPIRV/Decoration.cpp

@@ -1,336 +0,0 @@
-//===--- Decoration.cpp - SPIR-V Decoration implementation-----------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/SPIRV/Decoration.h"
-#include "clang/SPIRV/SPIRVContext.h"
-#include "clang/SPIRV/String.h"
-#include "llvm/llvm_assert/assert.h"
-
-namespace clang {
-namespace spirv {
-
-const Decoration *Decoration::getUniqueDecoration(SPIRVContext &context,
-                                                  const Decoration &d) {
-  return context.registerDecoration(d);
-}
-const Decoration *Decoration::getRelaxedPrecision(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::RelaxedPrecision);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getSpecId(SPIRVContext &context, uint32_t id) {
-  Decoration d = Decoration(spv::Decoration::SpecId, {id});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getBlock(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::Block);
-  return getUniqueDecoration(context, d);
-}
-
-const Decoration *Decoration::getBufferBlock(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::BufferBlock);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getRowMajor(SPIRVContext &context,
-                                          uint32_t member_idx) {
-  Decoration d = Decoration(spv::Decoration::RowMajor);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getColMajor(SPIRVContext &context,
-                                          uint32_t member_idx) {
-  Decoration d = Decoration(spv::Decoration::ColMajor);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getArrayStride(SPIRVContext &context,
-                                             uint32_t stride) {
-  Decoration d = Decoration(spv::Decoration::ArrayStride, {stride});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getMatrixStride(SPIRVContext &context,
-                                              uint32_t stride,
-                                              uint32_t member_idx) {
-  Decoration d = Decoration(spv::Decoration::MatrixStride, {stride});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getGLSLShared(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::GLSLShared);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getGLSLPacked(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::GLSLPacked);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getCPacked(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::CPacked);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getBuiltIn(SPIRVContext &context,
-                                         spv::BuiltIn builtin,
-                                         llvm::Optional<uint32_t> member_idx) {
-  Decoration d =
-      Decoration(spv::Decoration::BuiltIn, {static_cast<uint32_t>(builtin)});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getNoPerspective(SPIRVContext &context,
-                             llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::NoPerspective);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getFlat(SPIRVContext &context,
-                                      llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Flat);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getPatch(SPIRVContext &context,
-                                       llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Patch);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getCentroid(SPIRVContext &context,
-                                          llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Centroid);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getSample(SPIRVContext &context,
-                                        llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Sample);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getInvariant(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::Invariant);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getRestrict(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::Restrict);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getAliased(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::Aliased);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getVolatile(SPIRVContext &context,
-                                          llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Volatile);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getConstant(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::Constant);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getCoherent(SPIRVContext &context,
-                                          llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Coherent);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getNonWritable(SPIRVContext &context,
-                           llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::NonWritable);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getNonReadable(SPIRVContext &context,
-                           llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::NonReadable);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getUniform(SPIRVContext &context,
-                                         llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Uniform);
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getSaturatedConversion(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::SaturatedConversion);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getStream(SPIRVContext &context,
-                                        uint32_t stream_number,
-                                        llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Stream, {stream_number});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getLocation(SPIRVContext &context,
-                                          uint32_t location,
-                                          llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Location, {location});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getComponent(SPIRVContext &context, uint32_t component,
-                         llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::Component, {component});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getIndex(SPIRVContext &context, uint32_t index) {
-  Decoration d = Decoration(spv::Decoration::Index, {index});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getBinding(SPIRVContext &context,
-                                         uint32_t binding_point) {
-  Decoration d = Decoration(spv::Decoration::Binding, {binding_point});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getDescriptorSet(SPIRVContext &context,
-                                               uint32_t set) {
-  Decoration d = Decoration(spv::Decoration::DescriptorSet, {set});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getOffset(SPIRVContext &context,
-                                        uint32_t byte_offset,
-                                        uint32_t member_idx) {
-  Decoration d = Decoration(spv::Decoration::Offset, {byte_offset});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getXfbBuffer(SPIRVContext &context, uint32_t xfb_buf,
-                         llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::XfbBuffer, {xfb_buf});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getXfbStride(SPIRVContext &context, uint32_t xfb_stride,
-                         llvm::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::XfbStride, {xfb_stride});
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getFuncParamAttr(SPIRVContext &context,
-                             spv::FunctionParameterAttribute attr) {
-  Decoration d =
-      Decoration(spv::Decoration::FuncParamAttr, {static_cast<uint32_t>(attr)});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getFPRoundingMode(SPIRVContext &context,
-                                                spv::FPRoundingMode mode) {
-  Decoration d = Decoration(spv::Decoration::FPRoundingMode,
-                            {static_cast<uint32_t>(mode)});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getFPFastMathMode(SPIRVContext &context,
-                                                spv::FPFastMathModeShift mode) {
-  Decoration d = Decoration(spv::Decoration::FPFastMathMode,
-                            {static_cast<uint32_t>(mode)});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getLinkageAttributes(SPIRVContext &context, std::string name,
-                                 spv::LinkageType linkage_type) {
-  llvm::SmallVector<uint32_t, 2> args;
-  const auto &vec = string::encodeSPIRVString(name);
-  args.insert(args.end(), vec.begin(), vec.end());
-  args.push_back(static_cast<uint32_t>(linkage_type));
-  Decoration d = Decoration(spv::Decoration::LinkageAttributes, args);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getNoContraction(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::NoContraction);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getInputAttachmentIndex(SPIRVContext &context,
-                                                      uint32_t index) {
-  Decoration d = Decoration(spv::Decoration::InputAttachmentIndex, {index});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getAlignment(SPIRVContext &context,
-                                           uint32_t alignment) {
-  Decoration d = Decoration(spv::Decoration::Alignment, {alignment});
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getOverrideCoverageNV(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::OverrideCoverageNV);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getPassthroughNV(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::PassthroughNV);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getViewportRelativeNV(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::ViewportRelativeNV);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *
-Decoration::getSecondaryViewportRelativeNV(SPIRVContext &context,
-                                           uint32_t offset) {
-  Decoration d = Decoration(spv::Decoration::SecondaryViewportRelativeNV);
-  return getUniqueDecoration(context, d);
-}
-const Decoration *Decoration::getNonUniformEXT(SPIRVContext &context) {
-  Decoration d = Decoration(spv::Decoration::NonUniformEXT);
-  return getUniqueDecoration(context, d);
-}
-
-const Decoration *Decoration::getHlslCounterBufferGOOGLE(SPIRVContext &context,
-                                                         uint32_t id) {
-  Decoration d = Decoration(spv::Decoration::HlslCounterBufferGOOGLE, {id});
-  return getUniqueDecoration(context, d);
-}
-
-const Decoration *
-Decoration::getHlslSemanticGOOGLE(SPIRVContext &context,
-                                  llvm::StringRef semantic,
-                                  llvm ::Optional<uint32_t> member_idx) {
-  Decoration d = Decoration(spv::Decoration::HlslSemanticGOOGLE,
-                            string::encodeSPIRVString(semantic));
-  d.setMemberIndex(member_idx);
-  return getUniqueDecoration(context, d);
-}
-
-std::vector<uint32_t> Decoration::withTargetId(uint32_t targetId) const {
-  std::vector<uint32_t> words;
-
-  // TODO: we are essentially duplicate the work InstBuilder is responsible for.
-  // Should figure out a way to unify them.
-  words.reserve(3 + args.size() + (memberIndex.hasValue() ? 1 : 0));
-  words.push_back(static_cast<uint32_t>(getDecorateOpcode(id, memberIndex)));
-  words.push_back(targetId);
-  if (memberIndex.hasValue())
-    words.push_back(*memberIndex);
-  words.push_back(static_cast<uint32_t>(id));
-  words.insert(words.end(), args.begin(), args.end());
-  words.front() |= static_cast<uint32_t>(words.size()) << 16;
-
-  return words;
-}
-
-spv::Op
-Decoration::getDecorateOpcode(spv::Decoration decoration,
-                              const llvm::Optional<uint32_t> &memberIndex) {
-  if (decoration == spv::Decoration::HlslCounterBufferGOOGLE)
-    return spv::Op::OpDecorateId;
-
-  if (decoration == spv::Decoration::HlslSemanticGOOGLE)
-    return memberIndex.hasValue() ? spv::Op::OpMemberDecorateStringGOOGLE
-                                  : spv::Op::OpDecorateStringGOOGLE;
-
-  return memberIndex.hasValue() ? spv::Op::OpMemberDecorate
-                                : spv::Op::OpDecorate;
-}
-
-} // end namespace spirv
-} // end namespace clang

+ 0 - 59
tools/clang/lib/SPIRV/SPIRVContext.cpp

@@ -15,65 +15,6 @@
 namespace clang {
 namespace spirv {
 
-uint32_t SPIRVContext::getResultIdForType(const Type *t, bool *isRegistered) {
-  assert(t != nullptr);
-  uint32_t result_id = 0;
-
-  auto iter = typeResultIdMap.find(t);
-  if (iter == typeResultIdMap.end()) {
-    // The Type has not been defined yet. Reserve an ID for it.
-    result_id = takeNextId();
-    typeResultIdMap[t] = result_id;
-    if (isRegistered)
-      *isRegistered = false;
-  } else {
-    result_id = iter->second;
-    if (isRegistered)
-      *isRegistered = true;
-  }
-
-  assert(result_id != 0);
-  return result_id;
-}
-
-uint32_t SPIRVContext::getResultIdForConstant(const Constant *c) {
-  assert(c != nullptr);
-  uint32_t result_id = 0;
-
-  auto iter = constantResultIdMap.find(c);
-  if (iter == constantResultIdMap.end()) {
-    // The constant has not been defined yet. Reserve an ID for it.
-    result_id = takeNextId();
-    constantResultIdMap[c] = result_id;
-  } else {
-    result_id = iter->second;
-  }
-
-  assert(result_id != 0);
-  return result_id;
-}
-
-const Type *SPIRVContext::registerType(const Type &t) {
-  // Insert function will only insert if it doesn't already exist in the set.
-  TypeSet::iterator it;
-  std::tie(it, std::ignore) = existingTypes.insert(t);
-  return &*it;
-}
-
-const Constant *SPIRVContext::registerConstant(const Constant &c) {
-  // Insert function will only insert if it doesn't already exist in the set.
-  ConstantSet::iterator it;
-  std::tie(it, std::ignore) = existingConstants.insert(c);
-  return &*it;
-}
-
-const Decoration *SPIRVContext::registerDecoration(const Decoration &d) {
-  // Insert function will only insert if it doesn't already exist in the set.
-  DecorationSet::iterator it;
-  std::tie(it, std::ignore) = existingDecorations.insert(d);
-  return &*it;
-}
-
 SpirvContext::SpirvContext()
     : allocator(), voidType(nullptr), boolType(nullptr), sintTypes({}),
       uintTypes({}), floatTypes({}), samplerType(nullptr) {

+ 0 - 440
tools/clang/lib/SPIRV/Structure.cpp

@@ -1,440 +0,0 @@
-//===--- Structure.cpp - SPIR-V representation structures -----*- C++ -*---===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/SPIRV/Structure.h"
-
-#include "BlockReadableOrder.h"
-
-#ifdef SUPPORT_QUERY_GIT_COMMIT_INFO
-#include "clang/Basic/Version.h"
-#else
-namespace clang {
-uint32_t getGitCommitCount() { return 0; }
-const char *getGitCommitHash() { return "<unknown-hash>"; }
-} // namespace clang
-#endif // SUPPORT_QUERY_GIT_COMMIT_INFO
-
-namespace clang {
-namespace spirv {
-
-namespace {
-constexpr uint32_t kGeneratorNumber = 14;
-constexpr uint32_t kToolVersion = 0;
-
-/// Chops the given original string into multiple smaller ones to make sure they
-/// can be encoded in a sequence of OpSourceContinued instructions following an
-/// OpSource instruction.
-void chopString(llvm::StringRef original,
-                llvm::SmallVectorImpl<llvm::StringRef> *chopped) {
-  const uint32_t maxCharInOpSource = 0xFFFFu - 5u; // Minus operands and nul
-  const uint32_t maxCharInContinue = 0xFFFFu - 2u; // Minus opcode and nul
-
-  chopped->clear();
-  if (original.size() > maxCharInOpSource) {
-    chopped->push_back(llvm::StringRef(original.data(), maxCharInOpSource));
-    original = llvm::StringRef(original.data() + maxCharInOpSource,
-                               original.size() - maxCharInOpSource);
-    while (original.size() > maxCharInContinue) {
-      chopped->push_back(llvm::StringRef(original.data(), maxCharInContinue));
-      original = llvm::StringRef(original.data() + maxCharInContinue,
-                                 original.size() - maxCharInContinue);
-    }
-    if (!original.empty()) {
-      chopped->push_back(original);
-    }
-  } else if (!original.empty()) {
-    chopped->push_back(original);
-  }
-}
-} // namespace
-
-// === Instruction implementations ===
-
-spv::Op Instruction::getOpcode() const {
-  if (!isEmpty()) {
-    return static_cast<spv::Op>(words.front() & spv::OpCodeMask);
-  }
-
-  return spv::Op::Max;
-}
-
-bool Instruction::isTerminator() const {
-  switch (getOpcode()) {
-  case spv::Op::OpBranch:
-  case spv::Op::OpBranchConditional:
-  case spv::Op::OpReturn:
-  case spv::Op::OpReturnValue:
-  case spv::Op::OpSwitch:
-  case spv::Op::OpKill:
-  case spv::Op::OpUnreachable:
-    return true;
-  default:
-    return false;
-  }
-}
-
-// === Basic block implementations ===
-
-BasicBlock::BasicBlock(BasicBlock &&that)
-    : labelId(that.labelId), debugName(that.debugName),
-      instructions(std::move(that.instructions)) {
-  that.clear();
-}
-
-BasicBlock &BasicBlock::operator=(BasicBlock &&that) {
-  labelId = that.labelId;
-  debugName = that.debugName;
-  instructions = std::move(that.instructions);
-
-  that.clear();
-
-  return *this;
-}
-
-void BasicBlock::take(InstBuilder *builder) {
-  // Make sure we have a terminator instruction at the end.
-  assert(isTerminated() && "found basic block without terminator");
-
-  builder->opLabel(labelId).x();
-
-  for (auto &inst : instructions) {
-    builder->getConsumer()(inst.take());
-  }
-
-  clear();
-}
-
-bool BasicBlock::isTerminated() const {
-  return !instructions.empty() && instructions.back().isTerminator();
-}
-
-// === Function implementations ===
-
-Function::Function(Function &&that)
-    : resultType(that.resultType), resultId(that.resultId),
-      funcControl(that.funcControl), funcType(that.funcType),
-      parameters(std::move(that.parameters)),
-      variables(std::move(that.variables)), blocks(std::move(that.blocks)) {
-  that.clear();
-}
-
-Function &Function::operator=(Function &&that) {
-  resultType = that.resultType;
-  resultId = that.resultId;
-  funcControl = that.funcControl;
-  funcType = that.funcType;
-  parameters = std::move(that.parameters);
-  variables = std::move(that.variables);
-  blocks = std::move(that.blocks);
-
-  that.clear();
-
-  return *this;
-}
-
-void Function::clear() {
-  resultType = 0;
-  resultId = 0;
-  funcControl = spv::FunctionControlMask::MaskNone;
-  funcType = 0;
-  parameters.clear();
-  variables.clear();
-  blocks.clear();
-}
-
-void Function::take(InstBuilder *builder) {
-  builder->opFunction(resultType, resultId, funcControl, funcType).x();
-
-  // Write out all parameters.
-  for (auto &param : parameters) {
-    builder->opFunctionParameter(param.first, param.second).x();
-  }
-
-  if (!variables.empty()) {
-    assert(!blocks.empty());
-  }
-
-  // Preprend all local variables to the entry block.
-  // This is necessary since SPIR-V requires all local variables to be defined
-  // at the very begining of the entry block.
-  // We need to do it in the reverse order to guarantee variables have the
-  // same definition order in SPIR-V as in the source code.
-  for (auto it = variables.rbegin(), ie = variables.rend(); it != ie; ++it) {
-    blocks.front()->prependInstruction(std::move(*it));
-  }
-
-  // Collect basic blocks in a human-readable order that satisfies SPIR-V
-  // validation rules.
-  std::vector<BasicBlock *> orderedBlocks;
-  /*
-  if (!blocks.empty()) {
-    BlockReadableOrderVisitor(
-        [&orderedBlocks](BasicBlock *block) { orderedBlocks.push_back(block); })
-        .visit(blocks.front().get());
-  }
-  */
-
-  // Write out all basic blocks.
-  for (auto *block : orderedBlocks) {
-    block->take(builder);
-  }
-
-  builder->opFunctionEnd().x();
-  clear();
-}
-
-void Function::addVariable(uint32_t varType, uint32_t varId,
-                           llvm::Optional<uint32_t> init) {
-  variables.emplace_back(
-      InstBuilder(nullptr)
-          .opVariable(varType, varId, spv::StorageClass::Function, init)
-          .take());
-}
-
-void Function::getReachableBasicBlocks(std::vector<BasicBlock *> *bbVec) const {
-  /*
-  if (!blocks.empty()) {
-    BlockReadableOrderVisitor(
-        [&bbVec](BasicBlock *block) { bbVec->push_back(block); })
-        .visit(blocks.front().get());
-  }
-  */
-}
-
-// === Module components implementations ===
-
-Header::Header()
-    // We are using the unfied header, which shows spv::Version as the newest
-    // version. But we need to stick to 1.0 for Vulkan consumption by default.
-    : magicNumber(spv::MagicNumber), version(0x00010000),
-      generator((kGeneratorNumber << 16) | kToolVersion), bound(0),
-      reserved(0) {}
-
-void Header::collect(const WordConsumer &consumer) {
-  std::vector<uint32_t> words;
-  words.push_back(magicNumber);
-  words.push_back(version);
-  words.push_back(generator);
-  words.push_back(bound);
-  words.push_back(reserved);
-  consumer(std::move(words));
-}
-
-bool DebugName::operator==(const DebugName &that) const {
-  if (targetId == that.targetId && name == that.name) {
-    if (memberIndex.hasValue()) {
-      return that.memberIndex.hasValue() &&
-             memberIndex.getValue() == that.memberIndex.getValue();
-    }
-    return !that.memberIndex.hasValue();
-  }
-  return false;
-}
-
-bool DebugName::operator<(const DebugName &that) const {
-  // Sort according to target id first
-  if (targetId != that.targetId)
-    return targetId < that.targetId;
-
-  if (memberIndex.hasValue()) {
-    // Sort member decorations according to member index
-    if (that.memberIndex.hasValue())
-      return memberIndex.getValue() < that.memberIndex.getValue();
-    // Decorations on the id itself goes before those on its members
-    return false;
-  }
-
-  // Decorations on the id itself goes before those on its members
-  if (that.memberIndex.hasValue())
-    return true;
-
-  return name < that.name;
-}
-
-// === Module implementations ===
-
-bool SPIRVModule::isEmpty() const {
-  return header.bound == 0 && capabilities.empty() && extensions.empty() &&
-         extInstSets.empty() && !addressingModel.hasValue() &&
-         !memoryModel.hasValue() && entryPoints.empty() &&
-         executionModes.empty() && debugNames.empty() && decorations.empty() &&
-         types.empty() && constants.empty() && variables.empty() &&
-         functions.empty();
-}
-
-void SPIRVModule::clear() {
-  header.bound = 0;
-
-  capabilities.clear();
-  extensions.clear();
-  extInstSets.clear();
-  addressingModel = llvm::None;
-  memoryModel = llvm::None;
-  entryPoints.clear();
-  executionModes.clear();
-  debugNames.clear();
-  decorations.clear();
-  types.clear();
-  constants.clear();
-  variables.clear();
-
-  functions.clear();
-}
-
-void SPIRVModule::take(InstBuilder *builder) {
-  const auto &consumer = builder->getConsumer();
-
-  // Order matters here.
-
-  if (spirvOptions.targetEnv == "vulkan1.1")
-    header.version = 0x00010300u;
-  header.collect(consumer);
-
-  for (auto &cap : capabilities) {
-    builder->opCapability(cap).x();
-  }
-
-  for (auto &ext : extensions) {
-    builder->opExtension(ext).x();
-  }
-
-  for (auto &inst : extInstSets) {
-    builder->opExtInstImport(inst.second, inst.first).x();
-  }
-
-  if (addressingModel.hasValue() && memoryModel.hasValue()) {
-    builder->opMemoryModel(*addressingModel, *memoryModel).x();
-  }
-
-  for (auto &inst : entryPoints) {
-    builder
-        ->opEntryPoint(inst.executionModel, inst.targetId,
-                       std::move(inst.targetName), inst.interfaces)
-        .x();
-  }
-
-  for (auto &inst : executionModes) {
-    consumer(inst.take());
-  }
-
-  if (shaderModelVersion != 0) {
-    llvm::Optional<uint32_t> fileName = llvm::None;
-
-    if (spirvOptions.debugInfoFile && !sourceFileName.empty() &&
-        sourceFileNameId) {
-      builder->opString(sourceFileNameId, sourceFileName).x();
-      fileName = sourceFileNameId;
-    }
-
-    llvm::Optional<llvm::StringRef> firstSnippet;
-    if (spirvOptions.debugInfoSource) {
-      llvm::SmallVector<llvm::StringRef, 2> choppedSrcCode;
-      chopString(sourceFileContent, &choppedSrcCode);
-      if (!choppedSrcCode.empty()) {
-        firstSnippet = llvm::Optional<llvm::StringRef>(choppedSrcCode.front());
-      }
-
-      builder
-          ->opSource(spv::SourceLanguage::HLSL, shaderModelVersion, fileName,
-                     firstSnippet)
-          .x();
-
-      for (uint32_t i = 1; i < choppedSrcCode.size(); ++i) {
-        builder->opSourceContinued(choppedSrcCode[i]).x();
-      }
-    } else {
-      builder
-          ->opSource(spv::SourceLanguage::HLSL, shaderModelVersion, fileName,
-                     firstSnippet)
-          .x();
-    }
-  }
-
-  // BasicBlock debug names should be emitted only for blocks that are
-  // reachable.
-  // The debug name for a basic block is stored in the basic block object.
-  std::vector<BasicBlock *> reachableBasicBlocks;
-  for (const auto &fn : functions)
-    fn->getReachableBasicBlocks(&reachableBasicBlocks);
-  for (BasicBlock *bb : reachableBasicBlocks)
-    if (!bb->getDebugName().empty())
-      builder->opName(bb->getLabelId(), bb->getDebugName()).x();
-
-  // Emit other debug names
-  for (auto &inst : debugNames) {
-    if (inst.memberIndex.hasValue()) {
-      builder
-          ->opMemberName(inst.targetId, *inst.memberIndex, std::move(inst.name))
-          .x();
-    } else {
-      builder->opName(inst.targetId, std::move(inst.name)).x();
-    }
-  }
-
-  if (spirvOptions.debugInfoTool && spirvOptions.targetEnv == "vulkan1.1") {
-    // Emit OpModuleProcessed to indicate the commit information.
-    std::string commitHash =
-        std::string("dxc-commit-hash: ") + clang::getGitCommitHash();
-    builder->opModuleProcessed(commitHash).x();
-
-    // Emit OpModuleProcessed to indicate the command line options that were
-    // used to generate this module.
-    if (!spirvOptions.clOptions.empty()) {
-      // Using this format: "dxc-cl-option: XXXXXX"
-      std::string clOptionStr = "dxc-cl-option:" + spirvOptions.clOptions;
-      builder->opModuleProcessed(clOptionStr).x();
-    }
-  }
-
-  for (const auto &idDecorPair : decorations) {
-    consumer(idDecorPair.second->withTargetId(idDecorPair.first));
-  }
-
-  // Note on interdependence of types and constants:
-  // There is only one type (OpTypeArray) that requires the result-id of a
-  // constant. As a result, the constant integer should be defined before the
-  // array is defined. The integer type should also be defined before the
-  // constant integer is defined.
-
-  for (auto &v : typeConstant) {
-    consumer(v.take());
-  }
-
-  for (auto &v : variables) {
-    consumer(v.take());
-  }
-
-  for (uint32_t i = 0; i < functions.size(); ++i) {
-    functions[i]->take(builder);
-  }
-
-  clear();
-}
-
-void SPIRVModule::addType(const Type *type, uint32_t resultId) {
-  bool inserted = false;
-  std::tie(std::ignore, inserted) = types.insert(type);
-  if (inserted) {
-    typeConstant.push_back(type->withResultId(resultId));
-    for (const Decoration *d : type->getDecorations()) {
-      addDecoration(d, resultId);
-    }
-  }
-}
-
-void SPIRVModule::addConstant(const Constant *constant, uint32_t resultId) {
-  bool inserted = false;
-  std::tie(std::ignore, inserted) = constants.insert(constant);
-  if (inserted) {
-    typeConstant.push_back(constant->withResultId(resultId));
-  }
-}
-
-} // end namespace spirv
-} // end namespace clang

+ 0 - 201
tools/clang/lib/SPIRV/Type.cpp

@@ -1,201 +0,0 @@
-//===--- Type.cpp - SPIR-V Type implementation-----------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/SPIRV/Type.h"
-#include "clang/SPIRV/SPIRVContext.h"
-#include "clang/SPIRV/String.h"
-
-namespace clang {
-namespace spirv {
-
-Type::Type(spv::Op op, std::vector<uint32_t> arg, DecorationSet decs,
-           llvm::StringRef n)
-    : opcode(op), args(std::move(arg)), name(n.str()) {
-  decorations = llvm::SetVector<const Decoration *>(decs.begin(), decs.end());
-}
-
-const Type *Type::getUniqueType(SPIRVContext &context, const Type &t) {
-  return context.registerType(t);
-}
-const Type *Type::getVoid(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeVoid, {});
-  return getUniqueType(context, t);
-}
-const Type *Type::getBool(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeBool, {});
-  return getUniqueType(context, t);
-}
-const Type *Type::getInt8(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {8, 1});
-  return getUniqueType(context, t);
-}
-const Type *Type::getUint8(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {8, 0});
-  return getUniqueType(context, t);
-}
-const Type *Type::getInt16(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {16, 1});
-  return getUniqueType(context, t);
-}
-const Type *Type::getUint16(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {16, 0});
-  return getUniqueType(context, t);
-}
-const Type *Type::getInt32(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {32, 1});
-  return getUniqueType(context, t);
-}
-const Type *Type::getUint32(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {32, 0});
-  return getUniqueType(context, t);
-}
-const Type *Type::getInt64(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {64, 1});
-  return getUniqueType(context, t);
-}
-const Type *Type::getUint64(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeInt, {64, 0});
-  return getUniqueType(context, t);
-}
-const Type *Type::getFloat16(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeFloat, {16});
-  return getUniqueType(context, t);
-}
-const Type *Type::getFloat32(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeFloat, {32});
-  return getUniqueType(context, t);
-}
-const Type *Type::getFloat64(SPIRVContext &context) {
-  Type t = Type(spv::Op::OpTypeFloat, {64});
-  return getUniqueType(context, t);
-}
-const Type *Type::getVec2(SPIRVContext &context, uint32_t component_type) {
-  Type t = Type(spv::Op::OpTypeVector, {component_type, 2u});
-  return getUniqueType(context, t);
-}
-const Type *Type::getVec3(SPIRVContext &context, uint32_t component_type) {
-  Type t = Type(spv::Op::OpTypeVector, {component_type, 3u});
-  return getUniqueType(context, t);
-}
-const Type *Type::getVec4(SPIRVContext &context, uint32_t component_type) {
-  Type t = Type(spv::Op::OpTypeVector, {component_type, 4u});
-  return getUniqueType(context, t);
-}
-const Type *Type::getMatrix(SPIRVContext &context, uint32_t column_type_id,
-                            uint32_t column_count) {
-  Type t = Type(spv::Op::OpTypeMatrix, {column_type_id, column_count});
-  return getUniqueType(context, t);
-}
-const Type *
-Type::getImage(SPIRVContext &context, uint32_t sampled_type, spv::Dim dim,
-               uint32_t depth, uint32_t arrayed, uint32_t ms, uint32_t sampled,
-               spv::ImageFormat image_format,
-               llvm::Optional<spv::AccessQualifier> access_qualifier,
-               DecorationSet d) {
-  std::vector<uint32_t> args = {
-      sampled_type, uint32_t(dim),         depth, arrayed, ms,
-      sampled,      uint32_t(image_format)};
-  if (access_qualifier.hasValue()) {
-    args.push_back(static_cast<uint32_t>(access_qualifier.getValue()));
-  }
-  Type t = Type(spv::Op::OpTypeImage, args, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getSampler(SPIRVContext &context, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeSampler, {}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getSampledImage(SPIRVContext &context, uint32_t image_type_id,
-                                  DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeSampledImage, {image_type_id}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getArray(SPIRVContext &context, uint32_t component_type_id,
-                           uint32_t len_id, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeArray, {component_type_id, len_id}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getRuntimeArray(SPIRVContext &context,
-                                  uint32_t component_type_id, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeRuntimeArray, {component_type_id}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getStruct(SPIRVContext &context,
-                            llvm::ArrayRef<uint32_t> members,
-                            llvm::StringRef name, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeStruct, std::vector<uint32_t>(members), d, name);
-  return getUniqueType(context, t);
-}
-const Type *Type::getPointer(SPIRVContext &context,
-                             spv::StorageClass storage_class, uint32_t type,
-                             DecorationSet d) {
-  Type t = Type(spv::Op::OpTypePointer,
-                {static_cast<uint32_t>(storage_class), type}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getFunction(SPIRVContext &context, uint32_t return_type,
-                              const std::vector<uint32_t> &params,
-                              DecorationSet d) {
-  std::vector<uint32_t> args = {return_type};
-  args.insert(args.end(), params.begin(), params.end());
-  Type t = Type(spv::Op::OpTypeFunction, args, d);
-  return getUniqueType(context, t);
-}
-
-bool Type::operator==(const Type &other) const {
-  if (opcode == other.opcode && args == other.args &&
-      decorations.size() == other.decorations.size() && name == other.name) {
-    // If two types have the same decorations, but in different order,
-    // they are in fact the same type.
-    for (const Decoration *dec : decorations) {
-      if (other.decorations.count(dec) == 0)
-        return false;
-    }
-    return true;
-  }
-  return false;
-}
-
-bool Type::isBooleanType() const { return opcode == spv::Op::OpTypeBool; }
-bool Type::isIntegerType() const { return opcode == spv::Op::OpTypeInt; }
-bool Type::isFloatType() const { return opcode == spv::Op::OpTypeFloat; }
-bool Type::isNumericalType() const { return isFloatType() || isIntegerType(); }
-bool Type::isScalarType() const { return isBooleanType() || isNumericalType(); }
-bool Type::isVectorType() const { return opcode == spv::Op::OpTypeVector; }
-bool Type::isMatrixType() const { return opcode == spv::Op::OpTypeMatrix; }
-bool Type::isArrayType() const { return opcode == spv::Op::OpTypeArray; }
-bool Type::isStructureType() const { return opcode == spv::Op::OpTypeStruct; }
-bool Type::isAggregateType() const {
-  return isStructureType() || isArrayType();
-}
-bool Type::isCompositeType() const {
-  return isAggregateType() || isMatrixType() || isVectorType();
-}
-bool Type::isImageType() const { return opcode == spv::Op::OpTypeImage; }
-
-bool Type::hasDecoration(const Decoration *d) const {
-  return decorations.count(d);
-}
-
-std::vector<uint32_t> Type::withResultId(uint32_t resultId) const {
-  std::vector<uint32_t> words;
-
-  // TODO: we are essentially duplicate the work InstBuilder is responsible for.
-  // Should figure out a way to unify them.
-  words.reserve(2 + args.size());
-  words.push_back(static_cast<uint32_t>(opcode));
-  words.push_back(resultId);
-  words.insert(words.end(), args.begin(), args.end());
-  words.front() |= static_cast<uint32_t>(words.size()) << 16;
-
-  return words;
-}
-
-} // end namespace spirv
-} // end namespace clang

+ 0 - 4
tools/clang/unittests/SPIRV/CMakeLists.txt

@@ -8,18 +8,14 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_unittest(clang-spirv-tests
   CodeGenSPIRVTest.cpp
-  ConstantTest.cpp
-  DecorationTest.cpp
   FileTestFixture.cpp
   FileTestUtils.cpp
   InstBuilderTest.cpp
   SPIRVContextTest.cpp
   SPIRVTestOptions.cpp
-  StructureTest.cpp
   TestMain.cpp
   SpirvConstantTest.cpp
   StringTest.cpp
-  TypeTest.cpp
   WholeFileTestFixture.cpp
   )
 

+ 0 - 103
tools/clang/unittests/SPIRV/ConstantTest.cpp

@@ -1,103 +0,0 @@
-//===- unittests/SPIRV/ConstantTest.cpp ---------- Constant tests ---------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "SPIRVTestUtils.h"
-
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-#include "clang/SPIRV/BitwiseCast.h"
-#include "clang/SPIRV/Constant.h"
-#include "clang/SPIRV/SPIRVContext.h"
-
-using namespace clang::spirv;
-
-namespace {
-using ::testing::ContainerEq;
-using ::testing::ElementsAre;
-
-TEST(Constant, True) {
-  SPIRVContext ctx;
-  const Constant *c = Constant::getTrue(ctx, 2);
-  const auto result = c->withResultId(3);
-  const auto expected = constructInst(spv::Op::OpConstantTrue, {2, 3});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-TEST(Constant, False) {
-  SPIRVContext ctx;
-  const Constant *c = Constant::getFalse(ctx, 2);
-  const auto result = c->withResultId(3);
-  const auto expected = constructInst(spv::Op::OpConstantFalse, {2, 3});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-TEST(Constant, Uint32) {
-  SPIRVContext ctx;
-  const Constant *c = Constant::getUint32(ctx, 2, 7u);
-  const auto result = c->withResultId(3);
-  const auto expected = constructInst(spv::Op::OpConstant, {2, 3, 7u});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-TEST(Constant, Int32) {
-  SPIRVContext ctx;
-  const Constant *c = Constant::getInt32(ctx, 2, -7);
-  const auto result = c->withResultId(3);
-  const auto expected = constructInst(spv::Op::OpConstant, {2, 3, 0xFFFFFFF9});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-TEST(Constant, Float32) {
-  SPIRVContext ctx;
-  const Constant *c = Constant::getFloat32(ctx, 2, 7.0);
-  const auto result = c->withResultId(3);
-  const auto expected = constructInst(
-      spv::Op::OpConstant, {2, 3, cast::BitwiseCast<uint32_t, float>(7.0)});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-TEST(Constant, Composite) {
-  SPIRVContext ctx;
-  const Constant *c = Constant::getComposite(ctx, 8, {4, 5, 6, 7});
-  const auto result = c->withResultId(9);
-  const auto expected =
-      constructInst(spv::Op::OpConstantComposite, {8, 9, 4, 5, 6, 7});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-TEST(Constant, Sampler) {
-  SPIRVContext ctx;
-  const Constant *c =
-      Constant::getSampler(ctx, 8, spv::SamplerAddressingMode::Repeat, 1,
-                           spv::SamplerFilterMode::Linear);
-  const auto result = c->withResultId(9);
-  const auto expected = constructInst(
-      spv::Op::OpConstantSampler,
-      {8, 9, static_cast<uint32_t>(spv::SamplerAddressingMode::Repeat), 1,
-       static_cast<uint32_t>(spv::SamplerFilterMode::Linear)});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-TEST(Constant, Null) {
-  SPIRVContext ctx;
-  const Constant *c = Constant::getNull(ctx, 8);
-  const auto result = c->withResultId(9);
-  const auto expected = constructInst(spv::Op::OpConstantNull, {8, 9});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-
-TEST(Constant, ConstantsWithSameBitPatternButDifferentTypeIdAreNotEqual) {
-  SPIRVContext ctx;
-
-  const Constant *int1 = Constant::getInt32(ctx, /*type_id*/ 1, 0);
-  const Constant *uint1 = Constant::getUint32(ctx, /*type_id*/ 2, 0);
-  const Constant *float1 = Constant::getFloat32(ctx, /*type_id*/ 3, 0);
-  const Constant *anotherInt1 = Constant::getInt32(ctx, /*type_id*/ 4, 0);
-
-  EXPECT_FALSE(*int1 == *uint1);
-  EXPECT_FALSE(*int1 == *float1);
-  EXPECT_FALSE(*uint1 == *float1);
-  EXPECT_FALSE(*int1 == *anotherInt1);
-}
-
-} // anonymous namespace

+ 0 - 584
tools/clang/unittests/SPIRV/DecorationTest.cpp

@@ -1,584 +0,0 @@
-//===- unittests/SPIRV/DecorationTest.cpp ----- Decoration tests ----------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "SPIRVTestUtils.h"
-#include "gmock/gmock.h"
-#include "clang/SPIRV/Decoration.h"
-#include "clang/SPIRV/SPIRVContext.h"
-#include "clang/SPIRV/String.h"
-#include "gtest/gtest.h"
-
-using namespace clang::spirv;
-
-namespace {
-using ::testing::ElementsAre;
-using ::testing::ContainerEq;
-
-TEST(Decoration, SameDecorationWoParameterShouldHaveSameAddress) {
-  SPIRVContext ctx;
-  const Decoration *relaxed = Decoration::getRelaxedPrecision(ctx);
-  const Decoration *relaxed_2 = Decoration::getRelaxedPrecision(ctx);
-  EXPECT_EQ(relaxed, relaxed_2);
-}
-
-TEST(Decoration, SameMemberDecorationWoParameterShouldHaveSameAddress) {
-  SPIRVContext ctx;
-  const Decoration *mem_0_builtin_pos =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 0);
-  const Decoration *mem_0_builtin_pos_again =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 0);
-
-  // We must get the same pointer for the same decoration signature.
-  EXPECT_EQ(mem_0_builtin_pos, mem_0_builtin_pos_again);
-}
-
-TEST(Decoration, DifferentMemberIndexDecorationShouldHaveDifferentAddress) {
-  SPIRVContext ctx;
-  // Applied to member 0 of a structure.
-  const Decoration *mem_0_builtin_pos =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 0);
-  // Applied to member 1 of a structure.
-  const Decoration *mem_1_builtin_pos =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 1);
-
-  // We should get different pointers for these decorations as they are
-  // applied to different structure members.
-  EXPECT_NE(mem_0_builtin_pos, mem_1_builtin_pos);
-}
-
-TEST(Decoration, RelaxedPrecision) {
-  SPIRVContext ctx;
-  const Decoration *rp = Decoration::getRelaxedPrecision(ctx);
-  EXPECT_EQ(rp->getValue(), spv::Decoration::RelaxedPrecision);
-  EXPECT_FALSE(rp->getMemberIndex().hasValue());
-  EXPECT_TRUE(rp->getArgs().empty());
-}
-
-TEST(Decoration, SpecId) {
-  SPIRVContext ctx;
-  const Decoration *specId = Decoration::getSpecId(ctx, 15);
-  EXPECT_EQ(specId->getValue(), spv::Decoration::SpecId);
-  EXPECT_FALSE(specId->getMemberIndex().hasValue());
-  EXPECT_THAT(specId->getArgs(), ElementsAre(15));
-}
-
-TEST(Decoration, Block) {
-  SPIRVContext ctx;
-  const Decoration *block = Decoration::getBlock(ctx);
-  EXPECT_EQ(block->getValue(), spv::Decoration::Block);
-  EXPECT_FALSE(block->getMemberIndex().hasValue());
-  EXPECT_TRUE(block->getArgs().empty());
-}
-
-TEST(Decoration, BufferBlock) {
-  SPIRVContext ctx;
-  const Decoration *bufferblock = Decoration::getBufferBlock(ctx);
-  EXPECT_EQ(bufferblock->getValue(), spv::Decoration::BufferBlock);
-  EXPECT_FALSE(bufferblock->getMemberIndex().hasValue());
-  EXPECT_TRUE(bufferblock->getArgs().empty());
-}
-
-TEST(Decoration, RowMajor) {
-  SPIRVContext ctx;
-  const Decoration *rowMajor = Decoration::getRowMajor(ctx, 2);
-  EXPECT_EQ(rowMajor->getValue(), spv::Decoration::RowMajor);
-  EXPECT_EQ(rowMajor->getMemberIndex().getValue(), 2U);
-  EXPECT_TRUE(rowMajor->getArgs().empty());
-}
-
-TEST(Decoration, ColMajor) {
-  SPIRVContext ctx;
-  const Decoration *colMajor = Decoration::getColMajor(ctx, 2);
-  EXPECT_EQ(colMajor->getValue(), spv::Decoration::ColMajor);
-  EXPECT_EQ(colMajor->getMemberIndex().getValue(), 2U);
-  EXPECT_TRUE(colMajor->getArgs().empty());
-}
-
-TEST(Decoration, ArrayStride) {
-  SPIRVContext ctx;
-  const Decoration *arrStride = Decoration::getArrayStride(ctx, 4);
-  EXPECT_EQ(arrStride->getValue(), spv::Decoration::ArrayStride);
-  EXPECT_FALSE(arrStride->getMemberIndex().hasValue());
-  EXPECT_THAT(arrStride->getArgs(), ElementsAre(4));
-}
-
-TEST(Decoration, MatrixStride) {
-  SPIRVContext ctx;
-  const Decoration *matStride = Decoration::getMatrixStride(ctx, 4, 7);
-  EXPECT_EQ(matStride->getValue(), spv::Decoration::MatrixStride);
-  EXPECT_EQ(matStride->getMemberIndex().getValue(), 7U);
-  EXPECT_THAT(matStride->getArgs(), ElementsAre(4));
-}
-
-TEST(Decoration, GLSLShared) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getGLSLShared(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::GLSLShared);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, GLSLPacked) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getGLSLPacked(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::GLSLPacked);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, CPacked) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getCPacked(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::CPacked);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, BuiltIn) {
-  SPIRVContext ctx;
-  const Decoration *dec =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::InvocationId);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::BuiltIn);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(),
-              ElementsAre(static_cast<uint32_t>(spv::BuiltIn::InvocationId)));
-}
-
-TEST(Decoration, BuiltInAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::BuiltIn);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_THAT(dec->getArgs(),
-              ElementsAre(static_cast<uint32_t>(spv::BuiltIn::Position)));
-}
-
-TEST(Decoration, NoPerspective) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getNoPerspective(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::NoPerspective);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, NoPerspectiveAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getNoPerspective(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::NoPerspective);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-TEST(Decoration, Flat) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getFlat(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Flat);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, FlatAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getFlat(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Flat);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Patch) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getPatch(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Patch);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, PatchAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getPatch(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Patch);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-TEST(Decoration, Centroid) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getCentroid(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Centroid);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, CentroidAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getCentroid(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Centroid);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Sample) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getSample(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Sample);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, SampleAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getSample(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Sample);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Invariant) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getInvariant(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Invariant);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Restrict) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getRestrict(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Restrict);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Aliased) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getAliased(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Aliased);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Volatile) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getVolatile(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Volatile);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, VolatileAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getVolatile(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Volatile);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Constant) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getConstant(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Constant);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Coherent) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getCoherent(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Coherent);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, CoherentAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getCoherent(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Coherent);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-TEST(Decoration, NonWritable) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getNonWritable(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::NonWritable);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, NonWritableAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getNonWritable(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::NonWritable);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, NonReadable) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getNonReadable(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::NonReadable);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, NonReadableAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getNonReadable(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::NonReadable);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Uniform) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getUniform(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Uniform);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, UniformAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getUniform(ctx, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Uniform);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, SaturatedConversion) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getSaturatedConversion(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::SaturatedConversion);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, Stream) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getStream(ctx, 7);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Stream);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, StreamAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getStream(ctx, 7, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Stream);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, Location) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getLocation(ctx, 7);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Location);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, LocationAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getLocation(ctx, 7, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Location);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, Component) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getComponent(ctx, 7);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Component);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, ComponentAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getComponent(ctx, 7, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Component);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, Index) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getIndex(ctx, 2);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Index);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(2));
-}
-
-TEST(Decoration, Binding) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getBinding(ctx, 2);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Binding);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(2));
-}
-
-TEST(Decoration, DescriptorSet) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getDescriptorSet(ctx, 1);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::DescriptorSet);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(1));
-}
-
-TEST(Decoration, Offset) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getOffset(ctx, 3, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Offset);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_THAT(dec->getArgs(), ElementsAre(3));
-}
-
-TEST(Decoration, XfbBuffer) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getXfbBuffer(ctx, 7);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::XfbBuffer);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, XfbBufferAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getXfbBuffer(ctx, 7, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::XfbBuffer);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, XfbStride) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getXfbStride(ctx, 7);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::XfbStride);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, XfbStrideAppliedToMember) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getXfbStride(ctx, 7, 3);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::XfbStride);
-  EXPECT_EQ(dec->getMemberIndex().getValue(), 3U);
-  EXPECT_THAT(dec->getArgs(), ElementsAre(7));
-}
-
-TEST(Decoration, FuncParamAttr) {
-  SPIRVContext ctx;
-  const Decoration *dec =
-      Decoration::getFuncParamAttr(ctx, spv::FunctionParameterAttribute::Zext);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::FuncParamAttr);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(static_cast<uint32_t>(
-                                  spv::FunctionParameterAttribute::Zext)));
-}
-
-TEST(Decoration, FPRoundingMode) {
-  SPIRVContext ctx;
-  const Decoration *dec =
-      Decoration::getFPRoundingMode(ctx, spv::FPRoundingMode::RTZ);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::FPRoundingMode);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(),
-              ElementsAre(static_cast<uint32_t>(spv::FPRoundingMode::RTZ)));
-}
-
-TEST(Decoration, FPFastMathMode) {
-  SPIRVContext ctx;
-  const Decoration *dec =
-      Decoration::getFPFastMathMode(ctx, spv::FPFastMathModeShift::NotInf);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::FPFastMathMode);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(static_cast<uint32_t>(
-                                  spv::FPFastMathModeShift::NotInf)));
-}
-
-TEST(Decoration, LinkageAttributes) {
-  SPIRVContext ctx;
-  const Decoration *dec =
-      Decoration::getLinkageAttributes(ctx, "main", spv::LinkageType::Export);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::LinkageAttributes);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-
-  // Check arguments are as expected
-  std::vector<uint32_t> args =
-      std::vector<uint32_t>(dec->getArgs().begin(), dec->getArgs().end());
-  std::vector<uint32_t> expectedArgs = string::encodeSPIRVString("main");
-  expectedArgs.push_back(static_cast<uint32_t>(spv::LinkageType::Export));
-  EXPECT_EQ(args, expectedArgs);
-}
-
-TEST(Decoration, NoContraction) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getNoContraction(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::NoContraction);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, InputAttachmentIndex) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getInputAttachmentIndex(ctx, 1);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::InputAttachmentIndex);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(1));
-}
-
-TEST(Decoration, Alignment) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getAlignment(ctx, 1);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::Alignment);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_THAT(dec->getArgs(), ElementsAre(1));
-}
-
-TEST(Decoration, OverrideCoverageNV) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getOverrideCoverageNV(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::OverrideCoverageNV);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, PassthroughNV) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getPassthroughNV(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::PassthroughNV);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, ViewportRelativeNV) {
-  SPIRVContext ctx;
-  const Decoration *dec = Decoration::getViewportRelativeNV(ctx);
-  EXPECT_EQ(dec->getValue(), spv::Decoration::ViewportRelativeNV);
-  EXPECT_FALSE(dec->getMemberIndex().hasValue());
-  EXPECT_TRUE(dec->getArgs().empty());
-}
-
-TEST(Decoration, BlockWithTargetId) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getBlock(ctx);
-  const auto result = d->withTargetId(1);
-  const auto expected = constructInst(
-      spv::Op::OpDecorate, {1, static_cast<uint32_t>(spv::Decoration::Block)});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-
-TEST(Decoration, RowMajorWithTargetId) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getRowMajor(ctx, 3);
-  const auto result = d->withTargetId(2);
-  const auto expected =
-      constructInst(spv::Op::OpMemberDecorate,
-                    {2, 3, static_cast<uint32_t>(spv::Decoration::RowMajor)});
-  EXPECT_THAT(result, ContainerEq(expected));
-}
-
-} // anonymous namespace

+ 1 - 87
tools/clang/unittests/SPIRV/SPIRVContextTest.cpp

@@ -8,8 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/SPIRV/SPIRVContext.h"
-#include "clang/SPIRV/Decoration.h"
-#include "clang/SPIRV/Type.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -17,90 +15,6 @@ using namespace clang::spirv;
 
 namespace {
 
-TEST(SPIRVContext, GetNextId) {
-  SPIRVContext context;
-  // Check that the first ID is 1.
-  EXPECT_EQ(context.getNextId(), 1u);
-  // Check that calling getNextId() multiple times does not increment the ID
-  EXPECT_EQ(context.getNextId(), 1u);
-}
-
-TEST(SPIRVContext, TakeNextId) {
-  SPIRVContext context;
-  EXPECT_EQ(context.takeNextId(), 1u);
-  EXPECT_EQ(context.takeNextId(), 2u);
-  EXPECT_EQ(context.getNextId(), 3u);
-}
-
-TEST(SPIRVContext, UniqueIdForUniqueNonAggregateType) {
-  SPIRVContext ctx;
-  const Type *intt = Type::getInt32(ctx);
-  uint32_t intt_id = ctx.getResultIdForType(intt);
-  uint32_t intt_id_again = ctx.getResultIdForType(intt);
-  // We should get the same ID for the same non-aggregate type.
-  EXPECT_EQ(intt_id, intt_id_again);
-}
-
-TEST(SPIRVContext, UniqueIdForUniqueAggregateType) {
-  SPIRVContext ctx;
-  // In this test we construct a struct which includes an integer member and
-  // a boolean member.
-  // We also assign RelaxedPrecision decoration to the struct as a whole.
-  // We also assign BufferBlock decoration to the struct as a whole.
-  // We also assign Offset decoration to each member of the struct.
-  // We also assign a BuiltIn decoration to the first member of the struct.
-  const Type *intt = Type::getInt32(ctx);
-  const Type *boolt = Type::getBool(ctx);
-  const uint32_t intt_id = ctx.getResultIdForType(intt);
-  const uint32_t boolt_id = ctx.getResultIdForType(boolt);
-  const auto relaxed = Decoration::getRelaxedPrecision(ctx);
-  const auto bufferblock = Decoration::getBufferBlock(ctx);
-  const auto mem_0_offset = Decoration::getOffset(ctx, 0u, 0);
-  const auto mem_1_offset = Decoration::getOffset(ctx, 0u, 1);
-  const auto mem_0_position =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 0);
-
-  const Type *struct_1 = Type::getStruct(
-      ctx, {intt_id, boolt_id}, "struct1",
-      {relaxed, bufferblock, mem_0_offset, mem_1_offset, mem_0_position});
-
-  const Type *struct_2 = Type::getStruct(
-      ctx, {intt_id, boolt_id}, "struct1",
-      {relaxed, bufferblock, mem_0_offset, mem_1_offset, mem_0_position});
-
-  const Type *struct_3 = Type::getStruct(
-      ctx, {intt_id, boolt_id}, "struct2",
-      {relaxed, bufferblock, mem_0_offset, mem_1_offset, mem_0_position});
-
-  const uint32_t struct_1_id = ctx.getResultIdForType(struct_1);
-  const uint32_t struct_2_id = ctx.getResultIdForType(struct_2);
-  const uint32_t struct_3_id = ctx.getResultIdForType(struct_3);
-
-  // We should be able to retrieve the same ID for the same Type.
-  EXPECT_EQ(struct_1_id, struct_2_id);
-
-  // Name matters.
-  EXPECT_NE(struct_1_id, struct_3_id);
-}
-
-TEST(SPIRVContext, UniqueIdForUniqueConstants) {
-  SPIRVContext ctx;
-
-  const Constant *int1 = Constant::getInt32(ctx, /*type_id*/ 1, /*value*/ 0);
-  const Constant *uint1 = Constant::getUint32(ctx, 2, 0);
-  const Constant *float1 = Constant::getFloat32(ctx, 3, 0);
-  const Constant *anotherInt1 = Constant::getInt32(ctx, /*type_id*/ 4, 0);
-
-  const uint32_t int1Id = ctx.getResultIdForConstant(int1);
-  const uint32_t uint1Id = ctx.getResultIdForConstant(uint1);
-  const uint32_t float1Id = ctx.getResultIdForConstant(float1);
-  const uint32_t anotherInt1Id = ctx.getResultIdForConstant(anotherInt1);
-
-  EXPECT_NE(int1Id, uint1Id);
-  EXPECT_NE(int1Id, float1Id);
-  EXPECT_NE(uint1Id, float1Id);
-  EXPECT_NE(int1Id, anotherInt1Id);
-}
-// TODO: Add more SPIRVContext tests
+// TODO: Add SpirvContext tests
 
 } // anonymous namespace

+ 0 - 302
tools/clang/unittests/SPIRV/StructureTest.cpp

@@ -1,302 +0,0 @@
-//===- unittests/SPIRV/StructureTest.cpp ------ SPIR-V structures tests ---===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/SPIRV/Structure.h"
-
-#include "SPIRVTestUtils.h"
-#include "clang/SPIRV/SPIRVContext.h"
-
-namespace {
-
-using namespace clang::spirv;
-
-using ::testing::ContainerEq;
-
-TEST(Structure, InstructionHasCorrectOpcode) {
-  Instruction inst(constructInst(spv::Op::OpIAdd, {1, 2, 3, 4}));
-
-  ASSERT_TRUE(!inst.isEmpty());
-  EXPECT_EQ(inst.getOpcode(), spv::Op::OpIAdd);
-}
-
-TEST(Structure, InstructionGetOriginalContents) {
-  Instruction inst(constructInst(spv::Op::OpIAdd, {1, 2, 3, 4}));
-
-  EXPECT_THAT(inst.take(),
-              ContainerEq(constructInst(spv::Op::OpIAdd, {1, 2, 3, 4})));
-}
-
-TEST(Structure, InstructionIsTerminator) {
-  for (auto opcode :
-       {spv::Op::OpKill, spv::Op::OpUnreachable, spv::Op::OpBranch,
-        spv::Op::OpBranchConditional, spv::Op::OpSwitch, spv::Op::OpReturn,
-        spv::Op::OpReturnValue}) {
-    Instruction inst(constructInst(opcode, {/* wrong params here */ 1}));
-
-    EXPECT_TRUE(inst.isTerminator());
-  }
-}
-
-TEST(Structure, InstructionIsNotTerminator) {
-  for (auto opcode : {spv::Op::OpNop, spv::Op::OpAccessChain, spv::Op::OpAll}) {
-    Instruction inst(constructInst(opcode, {/* wrong params here */ 1}));
-
-    EXPECT_FALSE(inst.isTerminator());
-  }
-}
-
-TEST(Structure, TakeBasicBlockHaveAllContents) {
-  std::vector<uint32_t> result;
-  auto ib = constructInstBuilder(result);
-
-  auto bb = BasicBlock(42);
-  bb.appendInstruction(constructInst(spv::Op::OpReturn, {}));
-  bb.take(&ib);
-
-  SimpleInstBuilder sib;
-  sib.inst(spv::Op::OpLabel, {42});
-  sib.inst(spv::Op::OpReturn, {});
-
-  EXPECT_THAT(result, ContainerEq(sib.get()));
-  EXPECT_TRUE(bb.isEmpty());
-}
-
-TEST(Structure, AfterClearBasicBlockIsEmpty) {
-  auto bb = BasicBlock(42);
-  bb.appendInstruction(constructInst(spv::Op::OpNop, {}));
-  EXPECT_FALSE(bb.isEmpty());
-  bb.clear();
-  EXPECT_TRUE(bb.isEmpty());
-}
-
-/*
-TEST(Structure, TakeFunctionHaveAllContents) {
-  auto f = Function(1, 2, spv::FunctionControlMask::Inline, 3);
-  f.addParameter(1, 42);
-
-  auto bb = llvm::make_unique<BasicBlock>(10);
-  bb->appendInstruction(constructInst(spv::Op::OpReturn, {}));
-  f.addBasicBlock(std::move(bb));
-
-  std::vector<uint32_t> result;
-  auto ib = constructInstBuilder(result);
-  f.take(&ib);
-
-  SimpleInstBuilder sib;
-  sib.inst(spv::Op::OpFunction, {1, 2, 1, 3});
-  sib.inst(spv::Op::OpFunctionParameter, {1, 42});
-  sib.inst(spv::Op::OpLabel, {10});
-  sib.inst(spv::Op::OpReturn, {});
-  sib.inst(spv::Op::OpFunctionEnd, {});
-
-  EXPECT_THAT(result, ContainerEq(sib.get()));
-  EXPECT_TRUE(f.isEmpty());
-}
-*/
-
-TEST(Structure, AfterClearFunctionIsEmpty) {
-  auto f = Function(1, 2, spv::FunctionControlMask::Inline, 3);
-  f.addParameter(1, 42);
-  EXPECT_FALSE(f.isEmpty());
-  f.clear();
-  EXPECT_TRUE(f.isEmpty());
-}
-
-TEST(Structure, DefaultConstructedModuleIsEmpty) {
-  auto m = SPIRVModule({});
-  EXPECT_TRUE(m.isEmpty());
-}
-
-TEST(Structure, AfterClearModuleIsEmpty) {
-  auto m = SPIRVModule({});
-  m.setBound(12);
-  EXPECT_FALSE(m.isEmpty());
-  m.clear();
-  EXPECT_TRUE(m.isEmpty());
-}
-
-/*
-TEST(Structure, TakeModuleHaveAllContents) {
-  SPIRVContext context;
-  auto m = SPIRVModule({});
-
-  // Will fix up the bound later.
-  SimpleInstBuilder sib(0);
-
-  m.addCapability(spv::Capability::Shader);
-  sib.inst(spv::Op::OpCapability,
-           {static_cast<uint32_t>(spv::Capability::Shader)});
-
-  m.addExtension("ext");
-  const uint32_t extWord = 'e' | ('x' << 8) | ('t' << 16);
-  sib.inst(spv::Op::OpExtension, {extWord});
-
-  const uint32_t extInstSetId = context.takeNextId();
-  m.addExtInstSet(extInstSetId, "gl");
-  const uint32_t glWord = 'g' | ('l' << 8);
-  sib.inst(spv::Op::OpExtInstImport, {extInstSetId, glWord});
-
-  m.setAddressingModel(spv::AddressingModel::Logical);
-  m.setMemoryModel(spv::MemoryModel::GLSL450);
-  sib.inst(spv::Op::OpMemoryModel,
-           {static_cast<uint32_t>(spv::AddressingModel::Logical),
-            static_cast<uint32_t>(spv::MemoryModel::GLSL450)});
-
-  const uint32_t entryPointId = context.takeNextId();
-  m.addEntryPoint(spv::ExecutionModel::Fragment, entryPointId, "main", {42});
-  const uint32_t mainWord = 'm' | ('a' << 8) | ('i' << 16) | ('n' << 24);
-  sib.inst(spv::Op::OpEntryPoint,
-           {static_cast<uint32_t>(spv::ExecutionModel::Fragment), entryPointId,
-            mainWord, 0, 42});
-
-  m.addExecutionMode(constructInst(
-      spv::Op::OpExecutionMode,
-      {entryPointId,
-       static_cast<uint32_t>(spv::ExecutionMode::OriginUpperLeft)}));
-  sib.inst(spv::Op::OpExecutionMode,
-           {entryPointId,
-            static_cast<uint32_t>(spv::ExecutionMode::OriginUpperLeft)});
-
-  // TODO: source code debug information
-
-  m.addDebugName(entryPointId, "main");
-  sib.inst(spv::Op::OpName,
-           {entryPointId, mainWord, 0});
-
-  m.addDecoration(Decoration::getRelaxedPrecision(context), entryPointId);
-  sib.inst(
-      spv::Op::OpDecorate,
-      {entryPointId, static_cast<uint32_t>(spv::Decoration::RelaxedPrecision)});
-
-  const auto *i32Type = Type::getInt32(context);
-  const uint32_t i32Id = context.getResultIdForType(i32Type);
-  m.addType(i32Type, i32Id);
-  sib.inst(spv::Op::OpTypeInt, {i32Id, 32, 1});
-
-  const auto *voidType = Type::getVoid(context);
-  const uint32_t voidId = context.getResultIdForType(voidType);
-  m.addType(voidType, voidId);
-  sib.inst(spv::Op::OpTypeVoid, {voidId});
-
-  const auto *funcType = Type::getFunction(context, voidId, {voidId});
-  const uint32_t funcTypeId = context.getResultIdForType(funcType);
-  m.addType(funcType, funcTypeId);
-  sib.inst(spv::Op::OpTypeFunction, {funcTypeId, voidId, voidId});
-
-  const auto *i32Const = Constant::getInt32(context, i32Id, 42);
-  const uint32_t constantId = context.takeNextId();
-  m.addConstant(i32Const, constantId);
-  sib.inst(spv::Op::OpConstant, {i32Id, constantId, 42});
-
-  const uint32_t varId = context.takeNextId();
-  m.addVariable(constructInst(
-      spv::Op::OpVariable,
-      {i32Id, varId, static_cast<uint32_t>(spv::StorageClass::Input)}));
-  sib.inst(spv::Op::OpVariable,
-           {i32Id, varId, static_cast<uint32_t>(spv::StorageClass::Input)});
-
-  const uint32_t funcId = context.takeNextId();
-  auto f = llvm::make_unique<Function>(
-      voidId, funcId, spv::FunctionControlMask::MaskNone, funcTypeId);
-  const uint32_t bbId = context.takeNextId();
-  auto bb = llvm::make_unique<BasicBlock>(bbId);
-  bb->appendInstruction(constructInst(spv::Op::OpReturn, {}));
-  f->addBasicBlock(std::move(bb));
-  m.addFunction(std::move(f));
-  sib.inst(spv::Op::OpFunction, {voidId, funcId, 0, funcTypeId});
-  sib.inst(spv::Op::OpLabel, {bbId});
-  sib.inst(spv::Op::OpReturn, {});
-  sib.inst(spv::Op::OpFunctionEnd, {});
-
-  m.setBound(context.getNextId());
-
-  std::vector<uint32_t> expected = sib.get();
-  expected[3] = context.getNextId();
-
-  std::vector<uint32_t> result;
-  auto ib = constructInstBuilder(result);
-  m.take(&ib);
-
-  EXPECT_THAT(result, ContainerEq(expected));
-  EXPECT_TRUE(m.isEmpty());
-}
-*/
-
-TEST(Structure, TakeModuleWithArrayAndConstantDependency) {
-  SPIRVContext context;
-  auto m = SPIRVModule({});
-
-  // Will fix up the id bound later.
-  SimpleInstBuilder sib(0);
-
-  // Add void type
-  const auto *voidType = Type::getVoid(context);
-  const uint32_t voidId = context.getResultIdForType(voidType);
-  m.addType(voidType, voidId);
-
-  // Add float type
-  const auto *f32Type = Type::getFloat32(context);
-  const uint32_t f32Id = context.getResultIdForType(f32Type);
-  m.addType(f32Type, f32Id);
-
-  // Add int64 type
-  const auto *i64Type = Type::getInt64(context);
-  const uint32_t i64Id = context.getResultIdForType(i64Type);
-  m.addType(i64Type, i64Id);
-
-  // Add int32 type
-  const auto *i32Type = Type::getInt32(context);
-  const uint32_t i32Id = context.getResultIdForType(i32Type);
-  m.addType(i32Type, i32Id);
-
-  // Add 32-bit integer constant (8)
-  const auto *i32Const = Constant::getInt32(context, i32Id, 8);
-  const uint32_t constantId = context.getResultIdForConstant(i32Const);
-  m.addConstant(i32Const, constantId);
-
-  // Add array of 8 32-bit integers type
-  const auto *arrType = Type::getArray(context, i32Id, constantId);
-  const uint32_t arrId = context.getResultIdForType(arrType);
-  m.addType(arrType, arrId);
-  m.setBound(context.getNextId());
-
-  // Add another array of the same size. The constant does not need to be
-  // redefined.
-  const auto *arrStride = Decoration::getArrayStride(context, 4);
-  const auto *secondArrType =
-      Type::getArray(context, i32Id, constantId, {arrStride});
-  const uint32_t secondArrId = context.getResultIdForType(arrType);
-  m.addType(secondArrType, secondArrId);
-  m.addDecoration(arrStride, secondArrId);
-  m.setBound(context.getNextId());
-
-  // Decorations
-  sib.inst(
-      spv::Op::OpDecorate,
-      {secondArrId, static_cast<uint32_t>(spv::Decoration::ArrayStride), 4});
-  // Now the expected order: void, float, int64, int32, constant(8), array
-  sib.inst(spv::Op::OpTypeVoid, {voidId});
-  sib.inst(spv::Op::OpTypeFloat, {f32Id, 32});
-  sib.inst(spv::Op::OpTypeInt, {i64Id, 64, 1});
-  sib.inst(spv::Op::OpTypeInt, {i32Id, 32, 1});
-  sib.inst(spv::Op::OpConstant, {i32Id, constantId, 8});
-  sib.inst(spv::Op::OpTypeArray, {arrId, i32Id, constantId});
-  sib.inst(spv::Op::OpTypeArray, {secondArrId, i32Id, constantId});
-
-  std::vector<uint32_t> expected = sib.get();
-  expected[3] = context.getNextId();
-
-  std::vector<uint32_t> result;
-  auto ib = constructInstBuilder(result);
-  m.take(&ib);
-
-  EXPECT_THAT(result, ContainerEq(expected));
-  EXPECT_TRUE(m.isEmpty());
-}
-} // anonymous namespace

+ 0 - 447
tools/clang/unittests/SPIRV/TypeTest.cpp

@@ -1,447 +0,0 @@
-//===- unittests/SPIRV/TypeTest.cpp ----- Type tests ----------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/SPIRV/Type.h"
-#include "SPIRVTestUtils.h"
-#include "clang/SPIRV/SPIRVContext.h"
-#include "clang/SPIRV/String.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-using namespace clang::spirv;
-
-namespace {
-using ::testing::ContainerEq;
-using ::testing::ElementsAre;
-
-TEST(Type, SameTypeWoParameterShouldHaveSameAddress) {
-  SPIRVContext context;
-  const Type *pIntFirst = Type::getInt32(context);
-  const Type *pIntSecond = Type::getInt32(context);
-  EXPECT_EQ(pIntFirst, pIntSecond);
-}
-
-TEST(Type, SameAggregateTypeWithDecorationsShouldHaveSameAddress) {
-  clang::spirv::SPIRVContext ctx;
-  // In this test we will build a struct which includes an integer member and
-  // a boolean member.
-  // We also assign RelaxedPrecision decoration to the struct as a whole.
-  // We also assign BufferBlock decoration to the struct as a whole.
-  // We also assign Offset decoration to each member of the struct.
-  // We also assign a BuiltIn decoration to the first member of the struct.
-  const Type *intt = Type::getInt32(ctx);
-  const Type *boolt = Type::getBool(ctx);
-  const uint32_t intt_id = ctx.getResultIdForType(intt);
-  const uint32_t boolt_id = ctx.getResultIdForType(boolt);
-  const Decoration *relaxed = Decoration::getRelaxedPrecision(ctx);
-  const Decoration *bufferblock = Decoration::getBufferBlock(ctx);
-  const Decoration *mem_0_offset = Decoration::getOffset(ctx, 0u, 0);
-  const Decoration *mem_1_offset = Decoration::getOffset(ctx, 0u, 1);
-  const Decoration *mem_0_position =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 0);
-
-  const Type *struct_1 = Type::getStruct(
-      ctx, {intt_id, boolt_id}, "",
-      {relaxed, bufferblock, mem_0_offset, mem_1_offset, mem_0_position});
-
-  const Type *struct_2 = Type::getStruct(
-      ctx, {intt_id, boolt_id}, "",
-      {relaxed, bufferblock, mem_0_offset, mem_1_offset, mem_0_position});
-
-  const Type *struct_3 = Type::getStruct(
-      ctx, {intt_id, boolt_id}, "",
-      {bufferblock, mem_0_offset, mem_0_position, mem_1_offset, relaxed});
-
-  const Type *struct_4 = Type::getStruct(
-      ctx, {intt_id, boolt_id}, "name",
-      {bufferblock, mem_0_offset, mem_0_position, mem_1_offset, relaxed});
-
-  // 2 types with the same signature. We should get the same pointer.
-  EXPECT_EQ(struct_1, struct_2);
-
-  // The order of decorations does not matter.
-  EXPECT_EQ(struct_1, struct_3);
-
-  // Struct with different names are different.
-  EXPECT_NE(struct_3, struct_4);
-}
-
-TEST(Type, Void) {
-  SPIRVContext ctx;
-  const Type *t = Type::getVoid(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeVoid);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Bool) {
-  SPIRVContext ctx;
-  const Type *t = Type::getBool(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeBool);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Int8) {
-  SPIRVContext ctx;
-  const Type *t = Type::getInt8(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(8, 1));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Uint8) {
-  SPIRVContext ctx;
-  const Type *t = Type::getUint8(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(8, 0));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Int16) {
-  SPIRVContext ctx;
-  const Type *t = Type::getInt16(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(16, 1));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Uint16) {
-  SPIRVContext ctx;
-  const Type *t = Type::getUint16(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(16, 0));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Int32) {
-  SPIRVContext ctx;
-  const Type *t = Type::getInt32(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(32, 1));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Uint32) {
-  SPIRVContext ctx;
-  const Type *t = Type::getUint32(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(32, 0));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Int64) {
-  SPIRVContext ctx;
-  const Type *t = Type::getInt64(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(64, 1));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Uint64) {
-  SPIRVContext ctx;
-  const Type *t = Type::getUint64(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeInt);
-  EXPECT_THAT(t->getArgs(), ElementsAre(64, 0));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Float16) {
-  SPIRVContext ctx;
-  const Type *t = Type::getFloat16(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeFloat);
-  EXPECT_THAT(t->getArgs(), ElementsAre(16));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Float32) {
-  SPIRVContext ctx;
-  const Type *t = Type::getFloat32(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeFloat);
-  EXPECT_THAT(t->getArgs(), ElementsAre(32));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Float64) {
-  SPIRVContext ctx;
-  const Type *t = Type::getFloat64(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeFloat);
-  EXPECT_THAT(t->getArgs(), ElementsAre(64));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Vec2) {
-  SPIRVContext ctx;
-  const Type *t = Type::getVec2(ctx, 1);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeVector);
-  EXPECT_THAT(t->getArgs(), ElementsAre(1, 2));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Vec3) {
-  SPIRVContext ctx;
-  const Type *t = Type::getVec3(ctx, 1);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeVector);
-  EXPECT_THAT(t->getArgs(), ElementsAre(1, 3));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Vec4) {
-  SPIRVContext ctx;
-  const Type *t = Type::getVec4(ctx, 1);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeVector);
-  EXPECT_THAT(t->getArgs(), ElementsAre(1, 4));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, Matrix) {
-  SPIRVContext ctx;
-  const Type *t = Type::getMatrix(ctx, /*type-id*/ 7, /*column-count*/ 4);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeMatrix);
-  EXPECT_THAT(t->getArgs(), ElementsAre(7, 4));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, ImageWithoutAccessQualifier) {
-  SPIRVContext ctx;
-  const Type *t = Type::getImage(ctx, /*sampled-type*/ 5, spv::Dim::Cube,
-                                 /*depth*/ 1, /*arrayed*/ 1, /*multisampled*/ 0,
-                                 /*sampled*/ 2, spv::ImageFormat::Rgba32f);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeImage);
-  EXPECT_THAT(t->getArgs(),
-              ElementsAre(5, static_cast<uint32_t>(spv::Dim::Cube), 1, 1, 0, 2,
-                          static_cast<uint32_t>(spv::ImageFormat::Rgba32f)));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedImageWithoutAccessQualifier) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t =
-      Type::getImage(ctx, /*sampled-type*/ 5, spv::Dim::Cube, /*depth*/ 1,
-                     /*arrayed*/ 1, /*multisampled*/ 0, /*sampled*/ 2,
-                     spv::ImageFormat::Rgba32f, llvm::None, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeImage);
-  EXPECT_THAT(t->getArgs(),
-              ElementsAre(5, static_cast<uint32_t>(spv::Dim::Cube), 1, 1, 0, 2,
-                          static_cast<uint32_t>(spv::ImageFormat::Rgba32f)));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, ImageWithAccessQualifier) {
-  SPIRVContext ctx;
-  const Type *t = Type::getImage(
-      ctx, /*sampled-type*/ 5, spv::Dim::Cube, /*depth*/ 1, /*arrayed*/ 1,
-      /*multisampled*/ 0, /*sampled*/ 2, spv::ImageFormat::Rgba32f,
-      /*access-qualifier*/ spv::AccessQualifier::ReadWrite);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeImage);
-  EXPECT_THAT(
-      t->getArgs(),
-      ElementsAre(5, static_cast<uint32_t>(spv::Dim::Cube), 1, 1, 0, 2,
-                  static_cast<uint32_t>(spv::ImageFormat::Rgba32f),
-                  static_cast<uint32_t>(spv::AccessQualifier::ReadWrite)));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedImageWithAccessQualifier) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getImage(
-      ctx, /*sampled-type*/ 5, spv::Dim::Cube, /*depth*/ 1, /*arrayed*/ 1,
-      /*multisampled*/ 0, /*sampled*/ 2, spv::ImageFormat::Rgba32f,
-      /*access-qualifier*/ spv::AccessQualifier::ReadWrite, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeImage);
-  EXPECT_THAT(
-      t->getArgs(),
-      ElementsAre(5, static_cast<uint32_t>(spv::Dim::Cube), 1, 1, 0, 2,
-                  static_cast<uint32_t>(spv::ImageFormat::Rgba32f),
-                  static_cast<uint32_t>(spv::AccessQualifier::ReadWrite)));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, ImageWithAndWithoutAccessQualifierAreDifferentTypes) {
-  SPIRVContext ctx;
-  const Type *img1 =
-      Type::getImage(ctx, /*sampled-type*/ 5, spv::Dim::Cube,
-                     /*depth*/ 1, /*arrayed*/ 1, /*multisampled*/ 0,
-                     /*sampled*/ 2, spv::ImageFormat::Rgba32f);
-  const Type *img2 =
-      Type::getImage(ctx, /*sampled-type*/ 5, spv::Dim::Cube,
-                     /*depth*/ 1, /*arrayed*/ 1, /*multisampled*/ 0,
-                     /*sampled*/ 2, spv::ImageFormat::Rgba32f,
-                     /*access-qualifier*/ spv::AccessQualifier::ReadWrite);
-
-  // The only difference between these two types is the Access Qualifier which
-  // is an optional argument.
-  EXPECT_NE(img1, img2);
-}
-
-TEST(Type, Sampler) {
-  SPIRVContext ctx;
-  const Type *t = Type::getSampler(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeSampler);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedSampler) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getSampler(ctx, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeSampler);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, SampledImage) {
-  SPIRVContext ctx;
-  const Type *t = Type::getSampledImage(ctx, 1);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeSampledImage);
-  EXPECT_THAT(t->getArgs(), ElementsAre(1));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedSampledImage) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getSampledImage(ctx, 1, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeSampledImage);
-  EXPECT_THAT(t->getArgs(), ElementsAre(1));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, Array) {
-  SPIRVContext ctx;
-  const Type *t = Type::getArray(ctx, 2, 4);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeArray);
-  EXPECT_THAT(t->getArgs(), ElementsAre(2, 4));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedArray) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getArray(ctx, 2, 4, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeArray);
-  EXPECT_THAT(t->getArgs(), ElementsAre(2, 4));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, RuntimeArray) {
-  SPIRVContext ctx;
-  const Type *t = Type::getRuntimeArray(ctx, 2);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeRuntimeArray);
-  EXPECT_THAT(t->getArgs(), ElementsAre(2));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedRuntimeArray) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getRuntimeArray(ctx, 2, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeRuntimeArray);
-  EXPECT_THAT(t->getArgs(), ElementsAre(2));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, StructBasic) {
-  SPIRVContext ctx;
-  const Type *t = Type::getStruct(ctx, {2, 3, 4});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeStruct);
-  EXPECT_THAT(t->getArgs(), ElementsAre(2, 3, 4));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, StructWithDecoration) {
-  SPIRVContext ctx;
-  const Decoration *bufferblock = Decoration::getBufferBlock(ctx);
-  const Type *t = Type::getStruct(ctx, {2, 3, 4}, "", {bufferblock});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeStruct);
-  EXPECT_THAT(t->getArgs(), ElementsAre(2, 3, 4));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(bufferblock));
-}
-
-TEST(Type, StructWithDecoratedMembers) {
-  SPIRVContext ctx;
-  const Decoration *relaxed = Decoration::getRelaxedPrecision(ctx);
-  const Decoration *bufferblock = Decoration::getBufferBlock(ctx);
-  const Decoration *mem_0_offset = Decoration::getOffset(ctx, 0u, 0);
-  const Decoration *mem_1_offset = Decoration::getOffset(ctx, 0u, 1);
-  const Decoration *mem_0_position =
-      Decoration::getBuiltIn(ctx, spv::BuiltIn::Position, 0);
-
-  const Type *t = Type::getStruct(
-      ctx, {2, 3, 4}, "",
-      {relaxed, bufferblock, mem_0_position, mem_0_offset, mem_1_offset});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeStruct);
-  EXPECT_THAT(t->getArgs(), ElementsAre(2, 3, 4));
-  // Since decorations are an ordered set of pointers, it's better not to use
-  // ElementsAre()
-  EXPECT_EQ(t->getDecorations().size(), 5u);
-  EXPECT_TRUE(t->hasDecoration(relaxed));
-  EXPECT_TRUE(t->hasDecoration(bufferblock));
-  EXPECT_TRUE(t->hasDecoration(mem_0_offset));
-  EXPECT_TRUE(t->hasDecoration(mem_0_position));
-  EXPECT_TRUE(t->hasDecoration(mem_1_offset));
-}
-
-TEST(Type, Pointer) {
-  SPIRVContext ctx;
-  const Type *t = Type::getPointer(ctx, spv::StorageClass::Uniform, 2);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypePointer);
-  EXPECT_THAT(
-      t->getArgs(),
-      ElementsAre(static_cast<uint32_t>(spv::StorageClass::Uniform), 2));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedPointer) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getPointer(ctx, spv::StorageClass::Uniform, 2, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypePointer);
-  EXPECT_THAT(
-      t->getArgs(),
-      ElementsAre(static_cast<uint32_t>(spv::StorageClass::Uniform), 2));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, Function) {
-  SPIRVContext ctx;
-  const Type *t = Type::getFunction(ctx, 1, {2, 3, 4});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeFunction);
-  EXPECT_THAT(t->getArgs(), ElementsAre(1, 2, 3, 4));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedFunction) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getFunction(ctx, 1, {2, 3, 4}, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeFunction);
-  EXPECT_THAT(t->getArgs(), ElementsAre(1, 2, 3, 4));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, BoolWithResultId) {
-  SPIRVContext ctx;
-  const Type *t = Type::getBool(ctx);
-  const auto words = t->withResultId(1);
-  EXPECT_THAT(words, ContainerEq(constructInst(spv::Op::OpTypeBool, {1})));
-}
-
-TEST(Type, IntWithResultId) {
-  SPIRVContext ctx;
-  const Type *t = Type::getInt32(ctx);
-  const auto words = t->withResultId(42);
-  EXPECT_THAT(words,
-              ContainerEq(constructInst(spv::Op::OpTypeInt, {42, 32, 1})));
-}
-
-} // anonymous namespace