Selaa lähdekoodia

[spirv] Fix potential Release build issues (#845)

Ehsan 7 vuotta sitten
vanhempi
commit
8d072dc9ad

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

@@ -381,6 +381,12 @@ 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));
 }

+ 3 - 6
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -843,7 +843,7 @@ bool DeclResultIdMapper::decorateResourceBindings() {
 
 bool DeclResultIdMapper::createStageVars(
     const hlsl::SigPoint *sigPoint, const DeclaratorDecl *decl, bool asInput,
-    QualType type, uint32_t arraySize, const llvm::Twine &namePrefix,
+    QualType type, uint32_t arraySize, const llvm::StringRef namePrefix,
     llvm::Optional<uint32_t> invocationId, uint32_t *value, bool noWriteBack,
     SemanticInfo *inheritSemantic) {
   // invocationId should only be used for handling HS per-vertex output.
@@ -958,10 +958,7 @@ bool DeclResultIdMapper::createStageVars(
 
     StageVar stageVar(sigPoint, semanticToUse->str, semanticToUse->semantic,
                       semanticToUse->name, semanticToUse->index, typeId);
-    // Note: we must have a separate variable here otherwise name
-    // (of Twine type) won't work.
-    const std::string semanticStr = stageVar.getSemanticStr();
-    llvm::Twine name = namePrefix + "." + semanticStr;
+    const auto name = namePrefix.str() + "." + stageVar.getSemanticStr();
     const uint32_t varId =
         createSpirvStageVar(&stageVar, decl, name, semanticToUse->loc);
 
@@ -1297,7 +1294,7 @@ void DeclResultIdMapper::decoratePSInterpolationMode(const DeclaratorDecl *decl,
 
 uint32_t DeclResultIdMapper::createSpirvStageVar(StageVar *stageVar,
                                                  const DeclaratorDecl *decl,
-                                                 const llvm::Twine &name,
+                                                 const llvm::StringRef name,
                                                  SourceLocation srcLoc) {
   using spv::BuiltIn;
   const auto sigPoint = stageVar->getSigPoint();

+ 2 - 3
tools/clang/lib/SPIRV/DeclResultIdMapper.h

@@ -23,7 +23,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/Twine.h"
 
 #include "GlPerVertex.h"
 #include "SpirvEvalInfo.h"
@@ -389,7 +388,7 @@ private:
   /// the semantic in inheritSemantic, with index increasing sequentially.
   bool createStageVars(const hlsl::SigPoint *sigPoint,
                        const DeclaratorDecl *decl, bool asInput, QualType type,
-                       uint32_t arraySize, const llvm::Twine &namePrefix,
+                       uint32_t arraySize, const llvm::StringRef namePrefix,
                        llvm::Optional<uint32_t> invocationId, uint32_t *value,
                        bool noWriteBack, SemanticInfo *inheritSemantic);
 
@@ -398,7 +397,7 @@ private:
   /// its storage class accordingly. name will be used as the debug name when
   /// creating a stage input/output variable.
   uint32_t createSpirvStageVar(StageVar *, const DeclaratorDecl *decl,
-                               const llvm::Twine &name, SourceLocation);
+                               const llvm::StringRef name, SourceLocation);
 
   /// Creates the associated counter variable for RW/Append/Consume
   /// structured buffer.

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

@@ -62,12 +62,6 @@ BasicBlock &BasicBlock::operator=(BasicBlock &&that) {
   return *this;
 }
 
-void BasicBlock::clear() {
-  labelId = 0;
-  debugName = "";
-  instructions.clear();
-}
-
 void BasicBlock::take(InstBuilder *builder) {
   // Make sure we have a terminator instruction at the end.
   assert(isTerminated() && "found basic block without terminator");