Split the giant lookup table into 3 smaller ones
Instead of having a single, enormous LUT for all CUDA names, let's
have separate ones for different types of entity. We often know
that we're looking at a typename, or a function name, or a macro
name - so we can be more efficient (and resilient to name
collisions) by having smaller lookup tables for each of those
classes of entity).
Here we start that off by having three LUTs:
- Header names
- Type names
- Everything else
Future work could usefully split "everything else" into:
- enum values
- macro names
- function names
- everything else
It's worth noting that the "needs new matcher" todos I delete here
were actually resolved with the previous commit. It no longer
naively searches for things that start with "cu*" - it will find
exactly those things that are present in our lookup tables.
[ROCm/hip commit: 695a1eb059]
This commit is contained in:
Plik diff jest za duży
Load Diff
@@ -16,6 +16,24 @@ struct hipCounter {
|
||||
|
||||
#define HIP_UNSUPPORTED -1
|
||||
|
||||
// Static lookup tables for mapping the CUDA API to the HIP API.
|
||||
/// Macros to ignore.
|
||||
extern const std::set<llvm::StringRef> CUDA_EXCLUDES;
|
||||
extern const std::map<llvm::StringRef, hipCounter> CUDA_TO_HIP_RENAMES;
|
||||
|
||||
/// Maps cuda header names to hip header names.
|
||||
extern const std::map<llvm::StringRef, hipCounter> CUDA_INCLUDE_MAP;
|
||||
|
||||
/// Maps the names of CUDA types to the corresponding hip types.
|
||||
extern const std::map<llvm::StringRef, hipCounter> CUDA_TYPE_NAME_MAP;
|
||||
|
||||
/// Map all other CUDA identifiers (function/macro names, enum values) to hip versions.
|
||||
extern const std::map<llvm::StringRef, hipCounter> CUDA_IDENTIFIER_MAP;
|
||||
|
||||
/**
|
||||
* The union of all the above maps.
|
||||
*
|
||||
* This should be used rarely, but is still needed to convert macro definitions (which can
|
||||
* contain any combination of the above things). AST walkers can usually get away with just
|
||||
* looking in the lookup table for the type of element they are processing, however, saving
|
||||
* a great deal of time.
|
||||
*/
|
||||
const std::map<llvm::StringRef, hipCounter>& CUDA_RENAMES_MAP();
|
||||
|
||||
@@ -239,8 +239,8 @@ protected:
|
||||
while ((begin = s.find("cu", begin)) != StringRef::npos) {
|
||||
const size_t end = s.find_first_of(" ", begin + 4);
|
||||
StringRef name = s.slice(begin, end);
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
const auto found = CUDA_RENAMES_MAP().find(name);
|
||||
if (found != CUDA_RENAMES_MAP().end()) {
|
||||
StringRef repName = found->second.hipName;
|
||||
hipCounter counter = {"", CONV_LITERAL, API_RUNTIME, found->second.unsupported};
|
||||
updateCounters(counter, name.str());
|
||||
@@ -293,8 +293,8 @@ public:
|
||||
const clang::Module *imported) override {
|
||||
if (_sm->isWrittenInMainFile(hash_loc)) {
|
||||
if (is_angled) {
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(file_name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
const auto found = CUDA_INCLUDE_MAP.find(file_name);
|
||||
if (found != CUDA_INCLUDE_MAP.end()) {
|
||||
updateCounters(found->second, file_name.str());
|
||||
if (!found->second.unsupported) {
|
||||
StringRef repName = found->second.hipName;
|
||||
@@ -325,8 +325,8 @@ public:
|
||||
for (auto T : MD->getMacroInfo()->tokens()) {
|
||||
if (T.isAnyIdentifier()) {
|
||||
StringRef name = T.getIdentifierInfo()->getName();
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
const auto found = CUDA_RENAMES_MAP().find(name);
|
||||
if (found != CUDA_RENAMES_MAP().end()) {
|
||||
updateCounters(found->second, name.str());
|
||||
if (!found->second.unsupported) {
|
||||
StringRef repName = found->second.hipName;
|
||||
@@ -379,8 +379,8 @@ public:
|
||||
for (auto tok : toks) {
|
||||
if (tok.isAnyIdentifier()) {
|
||||
StringRef name = tok.getIdentifierInfo()->getName();
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
const auto found = CUDA_RENAMES_MAP().find(name);
|
||||
if (found != CUDA_RENAMES_MAP().end()) {
|
||||
updateCounters(found->second, name.str());
|
||||
if (!found->second.unsupported) {
|
||||
StringRef repName = found->second.hipName;
|
||||
@@ -413,8 +413,8 @@ public:
|
||||
SourceLocation sl_end = Lexer::getLocForEndOfToken(sl_macro, 0, *_sm, DefaultLangOptions);
|
||||
size_t length = _sm->getCharacterData(sl_end) - _sm->getCharacterData(sl_macro);
|
||||
StringRef name = StringRef(_sm->getCharacterData(sl_macro), length);
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
const auto found = CUDA_RENAMES_MAP().find(name);
|
||||
if (found != CUDA_RENAMES_MAP().end()) {
|
||||
updateCounters(found->second, name.str());
|
||||
if (!found->second.unsupported) {
|
||||
StringRef repName = found->second.hipName;
|
||||
@@ -481,8 +481,10 @@ private:
|
||||
std::string name = funcDcl->getDeclName().getAsString();
|
||||
SourceManager *SM = Result.SourceManager;
|
||||
SourceLocation sl = call->getLocStart();
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
|
||||
// TODO: Make a lookup table just for functions to improve performance.
|
||||
const auto found = CUDA_IDENTIFIER_MAP.find(name);
|
||||
if (found != CUDA_IDENTIFIER_MAP.end()) {
|
||||
if (!found->second.unsupported) {
|
||||
StringRef repName = found->second.hipName;
|
||||
size_t length = name.size();
|
||||
@@ -614,8 +616,10 @@ private:
|
||||
memberName = memberName.slice(pos, memberName.size());
|
||||
SmallString<128> tmpData;
|
||||
name = Twine(name + "." + memberName).toStringRef(tmpData);
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
|
||||
// TODO: Make a lookup table just for builtins to improve performance.
|
||||
const auto found = CUDA_IDENTIFIER_MAP.find(name);
|
||||
if (found != CUDA_IDENTIFIER_MAP.end()) {
|
||||
updateCounters(found->second, name.str());
|
||||
if (!found->second.unsupported) {
|
||||
StringRef repName = found->second.hipName;
|
||||
@@ -639,8 +643,10 @@ private:
|
||||
StringRef name = enumConstantRef->getDecl()->getName();
|
||||
SourceLocation sl = enumConstantRef->getLocStart();
|
||||
SourceManager *SM = Result.SourceManager;
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(name);
|
||||
if (found != CUDA_TO_HIP_RENAMES.end()) {
|
||||
|
||||
// TODO: Make a lookup table just for enum values to improve performance.
|
||||
const auto found = CUDA_IDENTIFIER_MAP.find(name);
|
||||
if (found != CUDA_IDENTIFIER_MAP.end()) {
|
||||
updateCounters(found->second, name.str());
|
||||
if (!found->second.unsupported) {
|
||||
StringRef repName = found->second.hipName;
|
||||
@@ -680,8 +686,8 @@ private:
|
||||
}
|
||||
|
||||
// Do we have a replacement for this type?
|
||||
const auto found = CUDA_TO_HIP_RENAMES.find(typeName);
|
||||
if (found == CUDA_TO_HIP_RENAMES.end()) {
|
||||
const auto found = CUDA_TYPE_NAME_MAP.find(typeName);
|
||||
if (found == CUDA_TYPE_NAME_MAP.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user