[mlir][spirv] Put debug-only variable in LLVM_DEBUG
authorLei Zhang <antiagainst@google.com>
Mon, 12 Apr 2021 19:09:49 +0000 (15:09 -0400)
committerLei Zhang <antiagainst@google.com>
Mon, 12 Apr 2021 19:14:43 +0000 (15:14 -0400)
This avoids paying the cost when building in release.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D100325

mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp

index d26299f..9063b5f 100644 (file)
@@ -42,14 +42,15 @@ static LogicalResult checkExtensionRequirements(
     if (targetEnv.allows(ors))
       continue;
 
-    SmallVector<StringRef, 4> extStrings;
-    for (spirv::Extension ext : ors)
-      extStrings.push_back(spirv::stringifyExtension(ext));
-
-    LLVM_DEBUG(llvm::dbgs()
-               << label << " illegal: requires at least one extension in ["
-               << llvm::join(extStrings, ", ")
-               << "] but none allowed in target environment\n");
+    LLVM_DEBUG({
+      SmallVector<StringRef> extStrings;
+      for (spirv::Extension ext : ors)
+        extStrings.push_back(spirv::stringifyExtension(ext));
+
+      llvm::dbgs() << label << " illegal: requires at least one extension in ["
+                   << llvm::join(extStrings, ", ")
+                   << "] but none allowed in target environment\n";
+    });
     return failure();
   }
   return success();
@@ -69,14 +70,15 @@ static LogicalResult checkCapabilityRequirements(
     if (targetEnv.allows(ors))
       continue;
 
-    SmallVector<StringRef, 4> capStrings;
-    for (spirv::Capability cap : ors)
-      capStrings.push_back(spirv::stringifyCapability(cap));
+    LLVM_DEBUG({
+      SmallVector<StringRef> capStrings;
+      for (spirv::Capability cap : ors)
+        capStrings.push_back(spirv::stringifyCapability(cap));
 
-    LLVM_DEBUG(llvm::dbgs()
-               << label << " illegal: requires at least one capability in ["
-               << llvm::join(capStrings, ", ")
-               << "] but none allowed in target environment\n");
+      llvm::dbgs() << label << " illegal: requires at least one capability in ["
+                   << llvm::join(capStrings, ", ")
+                   << "] but none allowed in target environment\n";
+    });
     return failure();
   }
   return success();