Commit 9031bdd9 by Clemen Deng Committed by Commit Bot

Use perfect-hash module in gen_builtin_symbols.py

The script currently takes ~4 minutes to run Using this module instead of manually hashing will improve runtime significantly Bug: angleproject:3747 Change-Id: I7e2d2ef5bbfd136b0299d571e0acc11f334c80b5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1724667 Commit-Queue: Clemen Deng <clemendeng@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b8a27c5e
{
"src/compiler/translator/ImmutableString_autogen.cpp":
"325dc410635436401990388b73531c11",
"src/compiler/translator/ParseContext_autogen.h":
"58786d2f352ee1a58d529fb7572c86a4",
"src/compiler/translator/SymbolTable_autogen.cpp":
"9a0b524e9254116e1a38e3ef1b57b669",
"040a451ff0ad57612d5614d853cebd5a",
"src/compiler/translator/SymbolTable_autogen.h":
"bdb3c8eab0d48267a2f264e3af635e1a",
"src/compiler/translator/builtin_function_declarations.txt":
"d0c15cb9f2ef6c0ba5cd6612470db000",
"src/compiler/translator/builtin_symbols_hash_autogen.txt":
"e2fb536afe6669e60e45f6b5d0730631",
"src/compiler/translator/builtin_variables.json":
"04f763459cfbd47831bec22299287e82",
"src/compiler/translator/gen_builtin_symbols.py":
"5d5467e17ca5ed5bf9938df9a3391e6f",
"5fca8cb433dcbbd956ec27dc583ccee8",
"src/compiler/translator/tree_util/BuiltIn_autogen.h":
"69268b2f3bda048ba8aaabe60c9b9912",
"src/tests/compiler_tests/ImmutableString_test_autogen.cpp":
"e23f23bbd011ab29c4bb37ea69cfb3bd"
"aafd90302c36e2a848711576aa3a1aee"
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import json
import os
import subprocess
import sys
import platform
script_dir = sys.path[0]
root_dir = os.path.abspath(os.path.join(script_dir, '..'))
......@@ -37,8 +38,12 @@ def rebase_script_path(script_path, relative_path):
return os.path.relpath(os.path.join(os.path.dirname(script_path), relative_path), root_dir)
def get_executable_name():
return 'vpython.bat' if platform.system() == 'Windows' else 'vpython'
def grab_from_script(script, param):
res = subprocess.check_output(['python', script, param]).strip()
res = subprocess.check_output([get_executable_name(), script, param]).strip()
if res == '':
return []
return [clean_path_slashes(rebase_script_path(script, name)) for name in res.split(',')]
......@@ -183,7 +188,7 @@ def main():
os.chdir(get_child_script_dirname(script))
print('Running ' + name + ' code generator')
if subprocess.call(['python', os.path.basename(script)]) != 0:
if subprocess.call([get_executable_name(), os.path.basename(script)]) != 0:
sys.exit(1)
# Update the hash dictionary.
......
......@@ -44,7 +44,7 @@ angle_translator_sources = [
"src/compiler/translator/FunctionLookup.h",
"src/compiler/translator/HashNames.cpp",
"src/compiler/translator/HashNames.h",
"src/compiler/translator/ImmutableString.cpp",
"src/compiler/translator/ImmutableString_autogen.cpp",
"src/compiler/translator/ImmutableString.h",
"src/compiler/translator/ImmutableStringBuilder.cpp",
"src/compiler/translator/ImmutableStringBuilder.h",
......
//
// Copyright (c) 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ImmutableString.cpp: Wrapper for static or pool allocated char arrays, that are guaranteed to be
// valid and unchanged for the duration of the compilation.
//
#include "compiler/translator/ImmutableString.h"
std::ostream &operator<<(std::ostream &os, const sh::ImmutableString &str)
{
return os.write(str.data(), str.length());
}
#if defined(_MSC_VER)
# pragma warning(disable : 4309) // truncation of constant value
#endif
namespace sh
{
template <>
const size_t ImmutableString::FowlerNollVoHash<4>::kFnvPrime = 16777619u;
template <>
const size_t ImmutableString::FowlerNollVoHash<4>::kFnvOffsetBasis = 0x811c9dc5u;
template <>
const size_t ImmutableString::FowlerNollVoHash<8>::kFnvPrime =
static_cast<size_t>(1099511628211ull);
template <>
const size_t ImmutableString::FowlerNollVoHash<8>::kFnvOffsetBasis =
static_cast<size_t>(0xcbf29ce484222325ull);
uint32_t ImmutableString::mangledNameHash() const
{
const char *dataPtr = data();
uint32_t hash = static_cast<uint32_t>(FowlerNollVoHash<4>::kFnvOffsetBasis);
const uint32_t kMaxSixBitValue = (1u << 6) - 1u;
uint32_t parenLocation = kMaxSixBitValue;
uint32_t hasArrayOrBlockParamBit = 0u;
uint32_t index = 0;
while (dataPtr[index] != '\0')
{
hash = hash ^ dataPtr[index];
hash = hash * static_cast<uint32_t>(FowlerNollVoHash<4>::kFnvPrime);
if (dataPtr[index] == '(')
{
// We should only reach here once, since this function should not be called with invalid
// mangled names.
ASSERT(parenLocation == kMaxSixBitValue);
parenLocation = index;
}
else if (dataPtr[index] == '{' || dataPtr[index] == '[')
{
hasArrayOrBlockParamBit = 1u;
}
++index;
}
// Should not be called with strings longer than 63 characters.
ASSERT(index <= kMaxSixBitValue);
return ((hash >> 13) ^ (hash & 0x1fff)) | (index << 19) | (parenLocation << 25) |
(hasArrayOrBlockParamBit << 31);
}
} // namespace sh
This source diff could not be displayed because it is too large. You can view the blob instead.
571dbbc401f64a7bd3d3dca5d9002ba1
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment