Skip to content

Commit 4b25f41

Browse files
author
Andres Wearden
committed
saving changes
1 parent 451e0fd commit 4b25f41

15 files changed

+342
-287
lines changed

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ LLVM_ABI bool needsComdatForCounter(const GlobalObject &GV, const Module &M);
369369
/// InstrProf.h:getInstrProfNameSeparator). This method decodes the string and
370370
/// calls `NameCallback` for each substring.
371371
LLVM_ABI Error readAndDecodeStrings(
372-
StringRef NameStrings, std::function<Error(StringRef)> NameCallback);
372+
StringRef NameStrings, std::function<Error(StringRef)> NameCallback, StringRef Architecture = "");
373+
373374

374-
LLVM_ABI Error readAndDecodeStrings(StringRef NameStrings, std::function<Error(StringRef)> NameCallback, const std::string &Architecture);
375375
/// An enum describing the attributes of an instrumented profile.
376376
enum class InstrProfKind {
377377
Unknown = 0x0,
@@ -515,11 +515,11 @@ class InstrProfSymtab {
515515
LLVM_ABI static StringRef getCanonicalName(StringRef PGOName);
516516

517517
//ANDRES Function
518-
const std::string &getArchitecture() {return Architecture;}
519-
void setArchitecture(const std::string &Arch) {Architecture = Arch;}
518+
StringRef getArchitecture() {return Architecture;}
519+
void setArchitecture(StringRef Arch) {Architecture = Arch;}
520520
//ANDRES Function
521521
private:
522-
std::string Architecture;
522+
StringRef Architecture;
523523
using AddrIntervalMap =
524524
IntervalMap<uint64_t, uint64_t, 4, IntervalMapHalfOpenInfo<uint64_t>>;
525525
StringRef Data;
@@ -635,35 +635,30 @@ class InstrProfSymtab {
635635

636636
// Map the MD5 of the symbol name to the name.
637637
Error addSymbolName(StringRef SymbolName) {
638-
StringRef FuncName;
639-
StringRef ArchName = Architecture;
640-
std::tie(FuncName, ArchName) = SymbolName.split("#");
638+
// StringRef FuncName;
639+
// StringRef ArchName = Architecture;
640+
// std::tie(FuncName, ArchName) = SymbolName.split("#");
641641
if (SymbolName.empty())
642642
return make_error<InstrProfError>(instrprof_error::malformed,
643643
"symbol name is empty");
644644

645645
// Insert into NameTab so that MD5NameMap (a vector that will be sorted)
646646
// won't have duplicated entries in the first place.
647647

648-
uint64_t HashValue = IndexedInstrProf::ComputeHash(FuncName);
649-
llvm::StringRef HashRef(FuncName);
650-
if(!ArchName.empty()){
648+
uint64_t HashValue = IndexedInstrProf::ComputeHash(SymbolName);
649+
llvm::StringRef HashRef(SymbolName);
650+
if(!Architecture.empty()){
651651
std::string HashStr = std::to_string(HashValue);
652-
std::string CombinedStr = HashStr + ":" + ArchName.str();
652+
std::string CombinedStr = HashStr + ":" + Architecture.str();
653653
HashRef = CombinedStr;
654654
HashValue = IndexedInstrProf::ComputeHash(HashRef);
655655
}
656-
llvm::errs() << "FuncName is " << FuncName << " is written in " << ArchName << "\n";
657-
printf("Hash Value for %.*s %" PRIu64 "\n", static_cast<int>(SymbolName.size()), SymbolName.data(), HashValue);
658-
auto Ins = NameTab.insert(FuncName);
659-
printf("mapped value for %" PRIu64 " hash: %.*s\n", HashValue, static_cast<int>(Ins.first->getKey().size()), Ins.first->getKey().data());
656+
auto Ins = NameTab.insert(SymbolName);
660657
if (Ins.second) {
661658
MD5NameMap.push_back(std::make_pair(HashValue /*IndexedInstrProf::ComputeHash(HashRef)*/, Ins.first->getKey()));
662659
Sorted = false;
663660
}
664-
llvm::errs() << "Hash values when inside of addSymbolName" << "\n";
665661
for(int I = 0; I < int(MD5NameMap.size()); ++I){
666-
llvm::errs() << "Hash: " << MD5NameMap[I].first << " Function Name: " << MD5NameMap[I].second << "\n";
667662
}
668663
return Error::success();
669664
}
@@ -792,19 +787,17 @@ StringRef InstrProfSymtab::getFuncOrVarNameIfDefined(uint64_t MD5Hash) {
792787
StringRef InstrProfSymtab::getFuncOrVarName(uint64_t MD5Hash) {
793788
finalizeSymtab();
794789
std::string TempMD5HashStr = std::to_string(MD5Hash);
795-
llvm::errs() << "Before: " << MD5Hash << "\n";
796790
if(!Architecture.empty()){
797-
std::string CombinedHashStr = TempMD5HashStr + ":" + Architecture;
791+
std::string CombinedHashStr = TempMD5HashStr + ":" + Architecture.str();
798792
llvm::StringRef CombinedHashRef(CombinedHashStr);
799793
MD5Hash = IndexedInstrProf::ComputeHash(CombinedHashRef);
800794
}
801-
llvm::errs() << "After: " << MD5Hash << "\n";
802-
llvm::errs() << "Hash values when inside of getFuncOrVarName" << "\n";
803-
for(int I = 0; I < int(MD5NameMap.size()); ++I){
804-
llvm::errs() << "Hash: " << MD5NameMap[I].first << " Function Name: " << MD5NameMap[I].second << "\n";
805-
}
806795
auto Result = llvm::lower_bound(MD5NameMap, MD5Hash, [](const std::pair<uint64_t, StringRef> &LHS, uint64_t RHS) { return LHS.first < RHS; });
807-
llvm::errs() << "Architecture: " << (!Architecture.empty() ? Architecture : "No Specified Architecture") << ": " << Result->second << ": " << "Result->first: " << Result->first << " vs. MD5hash: " << MD5Hash << "\n";
796+
797+
// for(auto name : MD5NameMap){
798+
// llvm::errs() << "Function Name " << name.second << " Result->first: " << name.first << "\n";
799+
// }
800+
// llvm::errs() << "Function Name " << Result->second << " Result->first: " << Result->first << " vs. " << MD5Hash << "\n";
808801
if (Result != MD5NameMap.end() && Result->first == MD5Hash)
809802
return Result->second;
810803
return StringRef();

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,19 @@ class InstrProfReader {
213213
const object::BuildIDFetcher *BIDFetcher = nullptr,
214214
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind =
215215
InstrProfCorrelator::ProfCorrelatorKind::NONE,
216-
std::function<void(Error)> Warn = nullptr, const std::string &Architecture = "");
216+
std::function<void(Error)> Warn = nullptr, StringRef Architecture = "");
217217

218218
LLVM_ABI static Expected<std::unique_ptr<InstrProfReader>> create(
219219
std::unique_ptr<MemoryBuffer> Buffer,
220220
const InstrProfCorrelator *Correlator = nullptr,
221221
const object::BuildIDFetcher *BIDFetcher = nullptr,
222222
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind =
223223
InstrProfCorrelator::ProfCorrelatorKind::NONE,
224-
std::function<void(Error)> Warn = nullptr, const std::string &Architecture = "");
224+
std::function<void(Error)> Warn = nullptr, StringRef Architecture = "");
225225

226-
const std::string &getArchitecture() {return Architecture;}
226+
StringRef getArchitecture() {return Architecture;}
227227

228-
void setArchitecture(const std::string &Arch) {Architecture = Arch;}
228+
void setArchitecture(StringRef Arch) {Architecture = Arch;}
229229
/// \param Weight for raw profiles use this as the temporal profile trace
230230
/// weight
231231
/// \returns a list of temporal profile traces.

llvm/include/llvm/ProfileData/InstrProfWriter.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,8 @@ class InstrProfWriter {
113113
/// for this function and the hash and number of counts match, each counter is
114114
/// summed. Optionally scale counts by \p Weight.
115115
LLVM_ABI void addRecord(NamedInstrProfRecord &&I, uint64_t Weight,
116-
function_ref<void(Error)> Warn);
117-
LLVM_ABI void addRecord(StringRef Name, uint64_t Hash,
118-
InstrProfRecord &&I, uint64_t Weight,
119-
function_ref<void(Error)> Warn, const std::string &Architecture);
120-
void addRecord(NamedInstrProfRecord &&I, uint64_t Weight, const std::string &Architecture,
121-
function_ref<void(Error)> Warn);
116+
function_ref<void(Error)> Warn, StringRef Architecture = "");
117+
// void addRecord(NamedInstrProfRecord &&I, uint64_t Weight, function_ref<void(Error)> Warn);
122118
void addRecord(NamedInstrProfRecord &&I, function_ref<void(Error)> Warn) {
123119
addRecord(std::move(I), 1, Warn);
124120
}
@@ -229,7 +225,7 @@ class InstrProfWriter {
229225

230226
private:
231227
void addRecord(StringRef Name, uint64_t Hash, InstrProfRecord &&I,
232-
uint64_t Weight, function_ref<void(Error)> Warn);
228+
uint64_t Weight, function_ref<void(Error)> Warn, StringRef Architecture = "");
233229
bool shouldEncodeData(const ProfilingData &PD);
234230
/// Add \p Trace using reservoir sampling.
235231
void addTemporalProfileTrace(TemporalProfTraceTy Trace);

0 commit comments

Comments
 (0)