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>
This commit is contained in:
Ben Clayton 2021-10-15 13:46:50 +00:00 committed by Tint LUCI CQ
parent c40d15d5da
commit 4dfa394a3c
3 changed files with 33 additions and 23 deletions

View File

@ -18,7 +18,6 @@
#include <string> #include <string>
#include "src/clone_context.h" #include "src/clone_context.h"
#include "src/program_id.h"
namespace tint { namespace tint {

View File

@ -32,4 +32,27 @@ ProgramID ProgramID::New() {
return ProgramID(next_program_id++); 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 } // namespace tint

View File

@ -83,27 +83,15 @@ inline std::ostream& operator<<(std::ostream& out, ProgramID id) {
namespace detail { namespace detail {
/// AssertProgramIDsEqual is called by TINT_ASSERT_PROGRAM_IDS_EQUAL() and /// 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. /// `a` and `b` are equal.
template <typename A, typename B> void AssertProgramIDsEqual(ProgramID a,
void AssertProgramIDsEqual(A&& a, ProgramID b,
B&& b,
bool if_valid, bool if_valid,
diag::System system, diag::System system,
const char* msg, const char* msg,
const char* file, const char* file,
size_t line) { 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;
}
} // namespace detail } // namespace detail
@ -115,13 +103,13 @@ void AssertProgramIDsEqual(A&& a,
/// valid program identifiers. /// valid program identifiers.
#if TINT_CHECK_FOR_CROSS_PROGRAM_LEAKS #if TINT_CHECK_FOR_CROSS_PROGRAM_LEAKS
#define TINT_ASSERT_PROGRAM_IDS_EQUAL(system, a, b) \ #define TINT_ASSERT_PROGRAM_IDS_EQUAL(system, a, b) \
detail::AssertProgramIDsEqual(a, b, false, tint::diag::System::system, \ detail::AssertProgramIDsEqual( \
"TINT_ASSERT_PROGRAM_IDS_EQUAL(" #system \ ProgramIDOf(a), ProgramIDOf(b), false, tint::diag::System::system, \
"," #a ", " #b ")", \ "TINT_ASSERT_PROGRAM_IDS_EQUAL(" #system "," #a ", " #b ")", __FILE__, \
__FILE__, __LINE__) __LINE__)
#define TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(system, a, b) \ #define TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(system, a, b) \
detail::AssertProgramIDsEqual( \ 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 ")", \ "TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(" #system ", " #a ", " #b ")", \
__FILE__, __LINE__) __FILE__, __LINE__)
#else #else