diff --git a/projects/clr/hipamd/src/hiprtc/hiprtc.cpp b/projects/clr/hipamd/src/hiprtc/hiprtc.cpp index ee68a82502..169b5fe21e 100644 --- a/projects/clr/hipamd/src/hiprtc/hiprtc.cpp +++ b/projects/clr/hipamd/src/hiprtc/hiprtc.cpp @@ -151,7 +151,7 @@ hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog, const char* name_expressio auto* rtcProgram = hiprtc::RTCCompileProgram::as_RTCCompileProgram(prog); - if (!rtcProgram->getDemangledName(name_expression, loweredName)) { + if (!rtcProgram->getMangledName(name_expression, loweredName)) { return HIPRTC_RETURN(HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID); } diff --git a/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.cpp b/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.cpp index 88af22a32b..e131c58cfc 100644 --- a/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.cpp +++ b/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.cpp @@ -466,7 +466,7 @@ std::string handleMangledName(std::string loweredName) { return loweredName; } -bool fillDemangledNames(std::vector& executable, std::vector& mangledNames) { +bool fillMangledNames(std::vector& executable, std::vector& mangledNames) { amd_comgr_data_t dataObject; if (auto res = amd::Comgr::create_data(AMD_COMGR_DATA_KIND_EXECUTABLE, &dataObject); res != AMD_COMGR_STATUS_SUCCESS) { @@ -504,8 +504,7 @@ bool fillDemangledNames(std::vector& executable, std::vector& return true; } -bool getMangledNames(const std::vector& mangledNames, - std::map& strippedNames, +bool getDemangledNames(const std::vector& mangledNames, std::map& demangledNames) { for (auto& i : mangledNames) { std::string demangledName; @@ -516,22 +515,10 @@ bool getMangledNames(const std::vector& mangledNames, [](unsigned char c) { return std::isspace(c); }), demangledName.end()); - if (auto res = strippedNames.find(demangledName); res != strippedNames.end()) { - auto& strippedName = res->second; - if (auto dres = demangledNames.find(strippedName); dres != demangledNames.end()) { - dres->second = i; - continue; - } else { - return false; - } - } - if (auto dres = demangledNames.find(demangledName); dres != demangledNames.end()) { dres->second = i; - continue; } } - return true; } } // namespace helpers diff --git a/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.hpp b/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.hpp index f9d403069a..c8abb17707 100644 --- a/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.hpp +++ b/projects/clr/hipamd/src/hiprtc/hiprtcComgrHelper.hpp @@ -52,9 +52,8 @@ bool dumpIsaFromBC(const amd_comgr_data_set_t isaInputs, const std::string& isa, std::vector& exeOptions, std::string name, std::string& buildLog); bool demangleName(const std::string& mangledName, std::string& demangledName); std::string handleMangledName(std::string loweredName); -bool fillDemangledNames(std::vector& executable, std::vector& mangledNames); -bool getMangledNames(const std::vector& mangledNames, - std::map& strippedNames, +bool fillMangledNames(std::vector& executable, std::vector& mangledNames); +bool getDemangledNames(const std::vector& mangledNames, std::map& demangledNames); } // namespace helpers } // namespace hiprtc diff --git a/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp b/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp index be3710b8cd..83fd089c69 100644 --- a/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp +++ b/projects/clr/hipamd/src/hiprtc/hiprtcInternal.cpp @@ -288,25 +288,21 @@ bool RTCCompileProgram::compile(const std::vector& options, bool fg } std::vector mangledNames; - if (!fillDemangledNames(executable_, mangledNames)) { - LogError("Error in hiprtc: unable to fill demangled names"); + if (!fillMangledNames(executable_, mangledNames)) { + LogError("Error in hiprtc: unable to fill mangled names"); return false; } - if (!getMangledNames(mangledNames, stripped_names_, demangled_names_)) { - LogError("Error in hiprtc: unable to get mangled names"); + if (!getDemangledNames(mangledNames, demangled_names_)) { + LogError("Error in hiprtc: unable to get demangled names"); return false; } return true; } -bool RTCCompileProgram::trackMangledName(std::string& name) { - amd::ScopedLock lock(lock_); +void RTCCompileProgram::stripNamedExpression(std::string& strippedName) { - if (name.size() == 0) return false; - - std::string strippedName = name; if (strippedName.back() == ')') { strippedName.pop_back(); strippedName.erase(0, strippedName.find('(')); @@ -314,16 +310,24 @@ bool RTCCompileProgram::trackMangledName(std::string& name) { if (strippedName.front() == '&') { strippedName.erase(0, 1); } - - std::string strippedNameNoSpace = strippedName; - strippedNameNoSpace.erase(std::remove_if(strippedNameNoSpace.begin(), - strippedNameNoSpace.end(), + // Removes the spaces from strippedName if present + strippedName.erase(std::remove_if(strippedName.begin(), + strippedName.end(), [](unsigned char c) { return std::isspace(c); - }), strippedNameNoSpace.end()); + }), strippedName.end()); +} + +bool RTCCompileProgram::trackMangledName(std::string& name) { + amd::ScopedLock lock(lock_); + + if (name.size() == 0) return false; + + std::string strippedNameNoSpace = name; + stripNamedExpression(strippedNameNoSpace); stripped_names_.insert(std::pair(name, strippedNameNoSpace)); - demangled_names_.insert(std::pair(strippedName, "")); + demangled_names_.insert(std::pair(strippedNameNoSpace, "")); const auto var{"__hiprtc_" + std::to_string(stripped_names_.size())}; const auto code{"\nextern \"C\" constexpr auto " + var + " = " + name + ";\n"}; @@ -332,23 +336,17 @@ bool RTCCompileProgram::trackMangledName(std::string& name) { return true; } -bool RTCCompileProgram::getDemangledName(const char* name_expression, const char** loweredName) { - std::string name = name_expression; - if (auto res = stripped_names_.find(name); res != stripped_names_.end()) { - if (auto dres = demangled_names_.find(res->second); dres != demangled_names_.end()) { - if (dres->second.size() != 0) { - *loweredName = dres->second.c_str(); - return true; - } else - return false; - } - } - if (auto dres = demangled_names_.find(name); dres != demangled_names_.end()) { +bool RTCCompileProgram::getMangledName(const char* name_expression, const char** loweredName) { + + std::string strippedName = name_expression; + stripNamedExpression(strippedName); + + if (auto dres = demangled_names_.find(strippedName); dres != demangled_names_.end()) { if (dres->second.size() != 0) { *loweredName = dres->second.c_str(); return true; - } - return false; + } else + return false; } return false; } diff --git a/projects/clr/hipamd/src/hiprtc/hiprtcInternal.hpp b/projects/clr/hipamd/src/hiprtc/hiprtcInternal.hpp index 99b4543af5..0ead8ff978 100644 --- a/projects/clr/hipamd/src/hiprtc/hiprtcInternal.hpp +++ b/projects/clr/hipamd/src/hiprtc/hiprtcInternal.hpp @@ -159,8 +159,9 @@ class RTCCompileProgram : public RTCProgram { bool addSource(const std::string& source, const std::string& name); bool addHeader(const std::string& source, const std::string& name); bool compile(const std::vector& options, bool fgpu_rdc); - bool getDemangledName(const char* name_expression, const char** loweredName); + bool getMangledName(const char* name_expression, const char** loweredName); bool trackMangledName(std::string& name); + void stripNamedExpression(std::string& named_expression); bool GetBitcode(char* bitcode); bool GetBitcodeSize(size_t* bitcode_size);