Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update antlr to 4.13 for 33% speed up on some inputs #89

Merged
merged 11 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AzslcException.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace AZ::ShaderCompiler
BakeErrorMessage();
}

const char* what() const NOEXCEPT
const char* what() const noexcept
{
return m_errorMessage.c_str();
}
Expand Down
33 changes: 16 additions & 17 deletions src/AzslcMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace StdFs = std::filesystem;
// For large features or milestones. Minor version allows for breaking changes. Existing tests can change.
#define AZSLC_MINOR "8" // last change: introduction of class inheritance
// For small features or bug fixes. They cannot introduce breaking changes. Existing tests shouldn't change.
#define AZSLC_REVISION "19" // last change: fix crash in option ranks analysis in case of bodiless functions
#define AZSLC_REVISION "20" // last change: update antlrv4 to 4.13.2

namespace AZ::ShaderCompiler
{
Expand All @@ -43,11 +43,11 @@ namespace AZ::ShaderCompiler
size_t maxToken = vocabulary.getMaxTokenType();
for (size_t ii = 0; ii < maxToken; ++ii)
{
string token = vocabulary.getLiteralName(ii);
string_view token = vocabulary.getLiteralName(ii);
token = Trim(token, "\"'"); // because AntlR gives us e.g "'float'"
if (!token.empty()) // empty when there is a complex rule (not a straight unconditional keyword)
{
TypeClass tc = AnalyzeTypeClass(TentativeName{token});
TypeClass tc = AnalyzeTypeClass(TentativeName{string{token}});
bool accept = true;
if constexpr (!is_same_v<std::nullptr_t, std::remove_reference_t<decltype(tcFilter)>>)
{
Expand All @@ -56,7 +56,7 @@ namespace AZ::ShaderCompiler

if (tc == TypeClass::IsNotType)
{
notTypes1.insert(token);
notTypes1.insert(string{token});
}

if (accept)
Expand Down Expand Up @@ -220,30 +220,29 @@ namespace AZ::ShaderCompiler::Main
/// This function will support the --ast option. It uses an AntlR facility and prettifies it.
void PrintAst(tree::ParseTree* tree, azslParser& parser)
{
// not sure why wstring, but I'm going along the AntlR's doc example.
std::wstring s = antlrcpp::s2ws(tree->toStringTree(&parser));
std::string s = tree->toStringTree(&parser);
// hopefully easy to read indentator
std::wstring curindent = L"";
for (wchar_t c : s)
std::string curindent = "";
for (char c : s)
{
if (c == L'(')
if (c == '(')
{
std::wcout << "\n";
curindent += L" ";
std::wcout << curindent << c;
std::cout << "\n";
curindent += " ";
std::cout << curindent << c;
}
else if (c == L')')
else if (c == ')')
{
std::wcout << c << "\n";
std::cout << c << "\n";
curindent = curindent.substr(0, std::max(2_sz, curindent.size()) - 2);
std::wcout << curindent;
std::cout << curindent;
}
else
{
std::wcout << c;
std::cout << c;
}
}
std::wcout << std::endl; // flush
std::cout << std::endl; // flush
}

/// this function supports the --visitsym option
Expand Down
2 changes: 1 addition & 1 deletion src/AzslcSemanticOrchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ namespace AZ::ShaderCompiler
optional<int64_t> SemanticOrchestrator::TryFoldSRGSemantic(azslParser::SrgSemanticContext* ctx, size_t semanticTokenType, bool required)
{
// const ref used, to extend the returned object's temporary life
const string& intrinsicVarNameFromLexer = m_lexer->getVocabulary().getLiteralName(semanticTokenType);
string_view intrinsicVarNameFromLexer = m_lexer->getVocabulary().getLiteralName(semanticTokenType);
string_view intrinsicVarName = Trim(intrinsicVarNameFromLexer, "\'");

auto semanticSymbol = LookupSymbol(UnqualifiedNameView{ intrinsicVarName });
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ FetchContent_Declare(
# Antlr4 external dependency
FetchContent_Declare(
antlr4
GIT_REPOSITORY https://github.com/o3de/antlr4.git
GIT_TAG o3de-4.9.3
GIT_REPOSITORY https://github.com/o3de/antlr4/
GIT_TAG o3de-4.13.2
SOURCE_SUBDIR runtime/Cpp
CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release"
GIT_SHALLOW TRUE
Expand Down
Binary file removed src/external/antlr-4.9.3-complete.jar
Binary file not shown.
Binary file added src/external/antlr4-4.13.2-complete.jar
Binary file not shown.
5,616 changes: 2,014 additions & 3,602 deletions src/generated/azslLexer.cpp

Large diffs are not rendered by default.

45 changes: 19 additions & 26 deletions src/generated/azslLexer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Generated from ../azslLexer.g4 by ANTLR 4.9.3
// Generated from ../azslLexer.g4 by ANTLR 4.13.2

#pragma once

Expand Down Expand Up @@ -108,41 +108,34 @@ class azslLexer : public antlr4::Lexer {
};

explicit azslLexer(antlr4::CharStream *input);
~azslLexer();

virtual std::string getGrammarFileName() const override;
virtual const std::vector<std::string>& getRuleNames() const override;
~azslLexer() override;

virtual const std::vector<std::string>& getChannelNames() const override;
virtual const std::vector<std::string>& getModeNames() const override;
virtual const std::vector<std::string>& getTokenNames() const override; // deprecated, use vocabulary instead
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;

virtual const std::vector<uint16_t> getSerializedATN() const override;
virtual const antlr4::atn::ATN& getATN() const override;
std::string getGrammarFileName() const override;

private:
static std::vector<antlr4::dfa::DFA> _decisionToDFA;
static antlr4::atn::PredictionContextCache _sharedContextCache;
static std::vector<std::string> _ruleNames;
static std::vector<std::string> _tokenNames;
static std::vector<std::string> _channelNames;
static std::vector<std::string> _modeNames;
const std::vector<std::string>& getRuleNames() const override;

const std::vector<std::string>& getChannelNames() const override;

const std::vector<std::string>& getModeNames() const override;

const antlr4::dfa::Vocabulary& getVocabulary() const override;

static std::vector<std::string> _literalNames;
static std::vector<std::string> _symbolicNames;
static antlr4::dfa::Vocabulary _vocabulary;
static antlr4::atn::ATN _atn;
static std::vector<uint16_t> _serializedATN;
antlr4::atn::SerializedATNView getSerializedATN() const override;

const antlr4::atn::ATN& getATN() const override;

// By default the static state used to implement the lexer is lazily initialized during the first
// call to the constructor. You can call this function if you wish to initialize the static state
// ahead of time.
static void initialize();

private:

// Individual action functions triggered by action() above.

// Individual semantic predicate functions triggered by sempred() above.

struct Initializer {
Initializer();
};
static Initializer _init;
};

Loading
Loading