-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[utils][TableGen] Handle versions on clause/directive spellings #143021
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3298791
[utils][TableGen] Handle versions on clause/directive spellings
kparzysz 7a7c502
Use linear search instead of std::lower_bound
kparzysz 1640711
Set the minimum possible version to 0 instead of 1
kparzysz c0f76d2
Fix testcase
kparzysz 9d978ca
Use BaseRecord instead of Clause for getSpellings()
kparzysz 2e1bd7f
Address review comments
kparzysz a1f65b6
format
kparzysz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===-------------------------------------------------------------- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_FRONTEND_DIRECTIVE_SPELLING_H | ||
#define LLVM_FRONTEND_DIRECTIVE_SPELLING_H | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/ADT/iterator_range.h" | ||
|
||
#include <limits> | ||
#include <tuple> | ||
|
||
namespace llvm::directive { | ||
|
||
struct VersionRange { | ||
static constexpr int MaxValue = std::numeric_limits<int>::max(); | ||
// The default "Version" value in get<Lang><Enum>Name() is 0, include that | ||
// in the maximum range. | ||
int Min = 0; | ||
int Max = MaxValue; | ||
|
||
bool operator<(const VersionRange &R) const { | ||
return std::tie(Min, Max) < std::tie(R.Min, R.Max); | ||
} | ||
}; | ||
|
||
struct Spelling { | ||
StringRef Name; | ||
VersionRange Versions; | ||
}; | ||
|
||
StringRef FindName(llvm::iterator_range<const Spelling *>, unsigned Version); | ||
|
||
} // namespace llvm::directive | ||
|
||
#endif // LLVM_FRONTEND_DIRECTIVE_SPELLING_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
add_llvm_component_library(LLVMFrontendDirective | ||
Spelling.cpp | ||
|
||
LINK_COMPONENTS | ||
Support | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===-------------------------------------------------------------- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/Frontend/Directive/Spelling.h" | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/MathExtras.h" | ||
|
||
#include <cassert> | ||
|
||
kparzysz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using namespace llvm; | ||
|
||
static bool Contains(directive::VersionRange V, int P) { | ||
return V.Min <= P && P <= V.Max; | ||
} | ||
|
||
llvm::StringRef llvm::directive::FindName( | ||
llvm::iterator_range<const directive::Spelling *> Range, unsigned Version) { | ||
assert(llvm::isInt<8 * sizeof(int)>(Version) && "Version value out of range"); | ||
|
||
int V = Version; | ||
// Do a linear search to find the first Spelling that contains Version. | ||
// The condition "contains(S, Version)" does not partition the list of | ||
// spellings, so std::[lower|upper]_bound cannot be used. | ||
// In practice the list of spellings is expected to be very short, so | ||
// linear search seems appropriate. In general, an interval tree may be | ||
// a better choice, but in this case it may be an overkill. | ||
for (auto &S : Range) { | ||
if (Contains(S.Versions, V)) | ||
return S.Name; | ||
} | ||
return StringRef(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ add_llvm_component_library(LLVMFrontendOpenMP | |
BitReader | ||
FrontendOffloading | ||
FrontendAtomic | ||
FrontendDirective | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.