Browse Source

[spirv] Clean up SPIR-V types (#1366)

Lei Zhang 7 years ago
parent
commit
0c68569f59

+ 1 - 24
tools/clang/include/clang/SPIRV/Type.h

@@ -96,36 +96,13 @@ public:
   static const Type *getStruct(SPIRVContext &ctx,
                                llvm::ArrayRef<uint32_t> members,
                                DecorationSet d = {});
-  static const Type *getOpaque(SPIRVContext &ctx, std::string name,
-                               DecorationSet decs = {});
   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 = {});
-  static const Type *getEvent(SPIRVContext &ctx, DecorationSet decs = {});
-  static const Type *getDeviceEvent(SPIRVContext &ctx, DecorationSet decs = {});
-  static const Type *getReserveId(SPIRVContext &ctx, DecorationSet decs = {});
-  static const Type *getQueue(SPIRVContext &ctx, DecorationSet decs = {});
-  static const Type *getPipe(SPIRVContext &ctx, spv::AccessQualifier qualifier,
-                             DecorationSet decs = {});
-  static const Type *getForwardPointer(SPIRVContext &ctx, uint32_t pointer_type,
-                                       spv::StorageClass storage_class,
-                                       DecorationSet decs = {});
-  bool operator==(const Type &other) const {
-    if (opcode == other.opcode && args == other.args &&
-        decorations.size() == other.decorations.size()) {
-      // 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 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;

+ 13 - 33
tools/clang/lib/SPIRV/Type.cpp

@@ -130,11 +130,6 @@ const Type *Type::getStruct(SPIRVContext &context,
   Type t = Type(spv::Op::OpTypeStruct, std::vector<uint32_t>(members), d);
   return getUniqueType(context, t);
 }
-const Type *Type::getOpaque(SPIRVContext &context, std::string name,
-                            DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeOpaque, string::encodeSPIRVString(name), d);
-  return getUniqueType(context, t);
-}
 const Type *Type::getPointer(SPIRVContext &context,
                              spv::StorageClass storage_class, uint32_t type,
                              DecorationSet d) {
@@ -150,34 +145,19 @@ const Type *Type::getFunction(SPIRVContext &context, uint32_t return_type,
   Type t = Type(spv::Op::OpTypeFunction, args, d);
   return getUniqueType(context, t);
 }
-const Type *Type::getEvent(SPIRVContext &context, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeEvent, {}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getDeviceEvent(SPIRVContext &context, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeDeviceEvent, {}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getReserveId(SPIRVContext &context, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeReserveId, {}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getQueue(SPIRVContext &context, DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeQueue, {}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getPipe(SPIRVContext &context, spv::AccessQualifier qualifier,
-                          DecorationSet d) {
-  Type t = Type(spv::Op::OpTypePipe, {static_cast<uint32_t>(qualifier)}, d);
-  return getUniqueType(context, t);
-}
-const Type *Type::getForwardPointer(SPIRVContext &context,
-                                    uint32_t pointer_type,
-                                    spv::StorageClass storage_class,
-                                    DecorationSet d) {
-  Type t = Type(spv::Op::OpTypeForwardPointer,
-                {pointer_type, static_cast<uint32_t>(storage_class)}, d);
-  return getUniqueType(context, t);
+
+bool Type::operator==(const Type &other) const {
+  if (opcode == other.opcode && args == other.args &&
+      decorations.size() == other.decorations.size()) {
+    // 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; }

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

@@ -384,23 +384,6 @@ TEST(Type, StructWithDecoratedMembers) {
   EXPECT_TRUE(t->hasDecoration(mem_1_offset));
 }
 
-TEST(Type, Opaque) {
-  SPIRVContext ctx;
-  const Type *t = Type::getOpaque(ctx, "opaque_type");
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeOpaque);
-  EXPECT_EQ(string::decodeSPIRVString(t->getArgs()), "opaque_type");
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedOpaque) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getOpaque(ctx, "opaque_type", {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeOpaque);
-  EXPECT_EQ(string::decodeSPIRVString(t->getArgs()), "opaque_type");
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
 TEST(Type, Pointer) {
   SPIRVContext ctx;
   const Type *t = Type::getPointer(ctx, spv::StorageClass::Uniform, 2);
@@ -439,113 +422,6 @@ TEST(Type, DecoratedFunction) {
   EXPECT_THAT(t->getDecorations(), ElementsAre(d));
 }
 
-TEST(Type, Event) {
-  SPIRVContext ctx;
-  const Type *t = Type::getEvent(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeEvent);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedEvent) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getEvent(ctx, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeEvent);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, DeviceEvent) {
-  SPIRVContext ctx;
-  const Type *t = Type::getDeviceEvent(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeDeviceEvent);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedDeviceEvent) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getDeviceEvent(ctx, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeDeviceEvent);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, ReserveId) {
-  SPIRVContext ctx;
-  const Type *t = Type::getReserveId(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeReserveId);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedReserveId) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getReserveId(ctx, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeReserveId);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, Queue) {
-  SPIRVContext ctx;
-  const Type *t = Type::getQueue(ctx);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeQueue);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedQueue) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getQueue(ctx, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeQueue);
-  EXPECT_TRUE(t->getArgs().empty());
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, Pipe) {
-  SPIRVContext ctx;
-  const Type *t = Type::getPipe(ctx, spv::AccessQualifier::WriteOnly);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypePipe);
-  EXPECT_THAT(t->getArgs(), ElementsAre(static_cast<uint32_t>(
-                                spv::AccessQualifier::WriteOnly)));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedPipe) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t = Type::getPipe(ctx, spv::AccessQualifier::WriteOnly, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypePipe);
-  EXPECT_THAT(t->getArgs(), ElementsAre(static_cast<uint32_t>(
-                                spv::AccessQualifier::WriteOnly)));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
-TEST(Type, ForwardPointer) {
-  SPIRVContext ctx;
-  const Type *t = Type::getForwardPointer(ctx, 6, spv::StorageClass::Workgroup);
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeForwardPointer);
-  EXPECT_THAT(t->getArgs(), ElementsAre(6, static_cast<uint32_t>(
-                                               spv::StorageClass::Workgroup)));
-  EXPECT_TRUE(t->getDecorations().empty());
-}
-
-TEST(Type, DecoratedForwardPointer) {
-  SPIRVContext ctx;
-  const Decoration *d = Decoration::getAliased(ctx);
-  const Type *t =
-      Type::getForwardPointer(ctx, 6, spv::StorageClass::Workgroup, {d});
-  EXPECT_EQ(t->getOpcode(), spv::Op::OpTypeForwardPointer);
-  EXPECT_THAT(t->getArgs(), ElementsAre(6, static_cast<uint32_t>(
-                                               spv::StorageClass::Workgroup)));
-  EXPECT_THAT(t->getDecorations(), ElementsAre(d));
-}
-
 TEST(Type, BoolWithResultId) {
   SPIRVContext ctx;
   const Type *t = Type::getBool(ctx);