ProgramID: Move hot code out of template function
This is causing code bloat. Move common code out to a single function that's implemented in the .cc file.
Saves about 25k from the all-features-enabled Release build of tint for x64.
Bug: tint:1226
Change-Id: Idc2fef1b9ca92a2f48dfc5e252a3853721d048aa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66447
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/ast/node.h b/src/ast/node.h
index cfc1111..10546b0 100644
--- a/src/ast/node.h
+++ b/src/ast/node.h
@@ -18,7 +18,6 @@
#include <string>
#include "src/clone_context.h"
-#include "src/program_id.h"
namespace tint {
diff --git a/src/program_id.cc b/src/program_id.cc
index c27ac45..13fdc53 100644
--- a/src/program_id.cc
+++ b/src/program_id.cc
@@ -32,4 +32,27 @@
return ProgramID(next_program_id++);
}
+namespace detail {
+
+/// AssertProgramIDsEqual is called by TINT_ASSERT_PROGRAM_IDS_EQUAL() and
+/// TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID() to assert that the ProgramIDs
+/// `a` and `b` are equal.
+void AssertProgramIDsEqual(ProgramID a,
+ ProgramID b,
+ bool if_valid,
+ diag::System system,
+ const char* msg,
+ const char* file,
+ size_t line) {
+ if (a == b) {
+ return; // matched
+ }
+ if (if_valid && (!a || !b)) {
+ return; // a or b were not valid
+ }
+ diag::List diagnostics;
+ tint::InternalCompilerError(file, line, system, diagnostics) << msg;
+}
+
+} // namespace detail
} // namespace tint
diff --git a/src/program_id.h b/src/program_id.h
index bd98220..92e341a 100644
--- a/src/program_id.h
+++ b/src/program_id.h
@@ -83,27 +83,15 @@
namespace detail {
/// AssertProgramIDsEqual is called by TINT_ASSERT_PROGRAM_IDS_EQUAL() and
-/// TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID() to assert that the ProgramIDs of
+/// TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID() to assert that the ProgramIDs
/// `a` and `b` are equal.
-template <typename A, typename B>
-void AssertProgramIDsEqual(A&& a,
- B&& b,
+void AssertProgramIDsEqual(ProgramID a,
+ ProgramID b,
bool if_valid,
diag::System system,
const char* msg,
const char* file,
- size_t line) {
- auto a_id = ProgramIDOf(std::forward<A>(a));
- auto b_id = ProgramIDOf(std::forward<B>(b));
- if (a_id == b_id) {
- return; // matched
- }
- if (if_valid && (!a_id || !b_id)) {
- return; // a or b were not valid
- }
- diag::List diagnostics;
- tint::InternalCompilerError(file, line, system, diagnostics) << msg;
-}
+ size_t line);
} // namespace detail
@@ -114,14 +102,14 @@
/// that the program identifiers for A and B are equal, if both A and B have
/// valid program identifiers.
#if TINT_CHECK_FOR_CROSS_PROGRAM_LEAKS
-#define TINT_ASSERT_PROGRAM_IDS_EQUAL(system, a, b) \
- detail::AssertProgramIDsEqual(a, b, false, tint::diag::System::system, \
- "TINT_ASSERT_PROGRAM_IDS_EQUAL(" #system \
- "," #a ", " #b ")", \
- __FILE__, __LINE__)
+#define TINT_ASSERT_PROGRAM_IDS_EQUAL(system, a, b) \
+ detail::AssertProgramIDsEqual( \
+ ProgramIDOf(a), ProgramIDOf(b), false, tint::diag::System::system, \
+ "TINT_ASSERT_PROGRAM_IDS_EQUAL(" #system "," #a ", " #b ")", __FILE__, \
+ __LINE__)
#define TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(system, a, b) \
detail::AssertProgramIDsEqual( \
- a, b, true, tint::diag::System::system, \
+ ProgramIDOf(a), ProgramIDOf(b), true, tint::diag::System::system, \
"TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(" #system ", " #a ", " #b ")", \
__FILE__, __LINE__)
#else