Skip to content

Commit 6cdb2e1

Browse files
author
Andres Wearden
committed
updating repository
1 parent 41d03b0 commit 6cdb2e1

File tree

2 files changed

+58
-50
lines changed

2 files changed

+58
-50
lines changed

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <stack>
4141
#include <string>
4242
#include <system_error>
43-
#include <unordered_map>
43+
#include <unordered_set>
4444
#include <utility>
4545
#include <vector>
4646

@@ -1113,24 +1113,27 @@ Error CoverageMapping::loadFunctionRecord(
11131113
if (It != RecordIndices.end()) {
11141114
auto &ExistingFunction = Functions[It->second];
11151115

1116+
// Step 1: Build a set of existing ObjectFilenames
1117+
std::unordered_set<std::string> ExistingFilenames;
1118+
for (const auto &ExistingRegion : ExistingFunction.CountedRegions) {
1119+
ExistingFilenames.insert(ExistingRegion.ObjectFilename.str());
1120+
}
1121+
1122+
// Step 2: Only add NewRegions with unique ObjectFilenames
11161123
for (const auto &NewRegion : Function.CountedRegions) {
1117-
for (auto &ExistingRegion : ExistingFunction.CountedRegions) {
1118-
if((NewRegion.ObjectFilename != ExistingRegion.ObjectFilename) &&
1119-
(NewRegion.startLoc() >= ExistingRegion.startLoc()) &&
1120-
(NewRegion.endLoc() <= ExistingRegion.endLoc())){
1121-
RegionsToAdd.push_back(NewRegion);
1122-
}
1124+
if (ExistingFilenames.find(NewRegion.ObjectFilename.str()) == ExistingFilenames.end()) {
1125+
ExistingFunction.CountedRegions.push_back(NewRegion);
11231126
}
1127+
11241128
}
1125-
ExistingFunction.CountedRegions.insert(ExistingFunction.CountedRegions.end(), RegionsToAdd.begin(), RegionsToAdd.end());
11261129
}
11271130
RecordIndices[LogicalFuncKey] = Functions.size();
11281131
}
11291132
//CHANGES MADE HERE
11301133

11311134
// Don't create records for (filenames, function) pairs we've already seen.
1132-
StringRef HashStrRef(HashStr);
1133-
if (!RecordProvenance[FilenamesHash].insert(hash_value(HashStrRef)).second){
1135+
StringRef Hash(HashStr);
1136+
if (!RecordProvenance[FilenamesHash].insert(hash_value(Hash)).second){
11341137
return Error::success();
11351138
}
11361139

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ static cl::opt<std::string> RemappingFile("remapping-file",
199199
cl::desc("Symbol remapping file"));
200200
static cl::alias RemappingFileA("r", cl::desc("Alias for --remapping-file"),
201201
cl::aliasopt(RemappingFile));
202+
static cl::list<std::string> ObjectAwareHashing("object-aware-hashing",
203+
cl::desc("Includes the object file name when hashing function names "
204+
"and control flow hashes, allowing functions from different "
205+
"binaries to be distinguished"),
206+
cl::sub(MergeSubcommand));
202207
static cl::opt<bool>
203208
UseMD5("use-md5", cl::init(false), cl::Hidden,
204209
cl::desc("Choose to use MD5 to represent string in name table (only "
@@ -690,32 +695,32 @@ static void overlapInput(const std::string &BaseFilename,
690695
}
691696
}
692697

693-
//ANDRES FUNCTION
694-
Expected<std::string> getArchitectureFromExecutable(StringRef ExecutablePath){
695-
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError = MemoryBuffer::getFile(ExecutablePath);
696-
if(!BufferOrError){
697-
return createStringError(BufferOrError.getError(), "Failed to load input file");
698-
}
698+
// //ANDRES FUNCTION
699+
// Expected<std::string> getArchitectureFromExecutable(StringRef ExecutablePath){
700+
// ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrError = MemoryBuffer::getFile(ExecutablePath);
701+
// if(!BufferOrError){
702+
// return createStringError(BufferOrError.getError(), "Failed to load input file");
703+
// }
699704

700-
Expected<std::unique_ptr<object::ObjectFile>> ObjectOrError = object::ObjectFile::createObjectFile(BufferOrError.get()->getMemBufferRef());
701-
if(!ObjectOrError){
702-
return ObjectOrError.takeError();
703-
}
705+
// Expected<std::unique_ptr<object::ObjectFile>> ObjectOrError = object::ObjectFile::createObjectFile(BufferOrError.get()->getMemBufferRef());
706+
// if(!ObjectOrError){
707+
// return ObjectOrError.takeError();
708+
// }
704709

705-
std::unique_ptr<llvm::object::ObjectFile> &Object = ObjectOrError.get();
710+
// std::unique_ptr<llvm::object::ObjectFile> &Object = ObjectOrError.get();
706711

707-
StringRef ArchStr = Object->getArch() != Triple::UnknownArch ? Triple::getArchTypeName(Object->getArch()) : "unknown";
712+
// StringRef ArchStr = Object->getArch() != Triple::UnknownArch ? Triple::getArchTypeName(Object->getArch()) : "unknown";
708713

709-
return ArchStr.str();
710-
}
711-
//ANDRES FUNCTION
714+
// return ArchStr.str();
715+
// }
716+
// //ANDRES FUNCTION
712717

713718
/// Load an input into a writer context.
714719
static void
715720
loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
716721
const InstrProfCorrelator *Correlator, const StringRef ProfiledBinary,
717722
WriterContext *WC, const object::BuildIDFetcher *BIDFetcher = nullptr,
718-
const ProfCorrelatorKind *BIDFetcherCorrelatorKind = nullptr) {
723+
const ProfCorrelatorKind *BIDFetcherCorrelatorKind = nullptr, StringRef ObjectFilename = "") {
719724
std::unique_lock<std::mutex> CtxGuard{WC->Lock};
720725

721726
// Copy the filename, because llvm::ThreadPool copied the input "const
@@ -726,24 +731,24 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
726731
//ANDRES CODE
727732
std::string ExecutableName;
728733
std::string ProfileFile = Input.Filename;
729-
std::string Architecture = "";
734+
std::string ObjectFilename = "";
730735

731736
StringRef FilenameRef = Filename;
732-
if(FilenameRef.contains(':')){
733-
StringRef ExeRef, ProfRef;
734-
std::tie(ExeRef, ProfRef) = FilenameRef.split(':');
735-
if(!ExeRef.empty() && !ProfRef.empty()){
736-
ExecutableName = ExeRef.str();
737-
ProfileFile = ProfRef.str();
738-
}
739-
Expected<std::string> ArchOrError = getArchitectureFromExecutable(ExeRef);
740-
if(ArchOrError){
741-
Architecture = std::move(ArchOrError.get());
742-
}else{
743-
consumeError(ArchOrError.takeError());
744-
Architecture = "unknown";
745-
}
746-
Architecture = ExeRef;
737+
if(!ObjectFilename.empty()){
738+
// StringRef ExeRef, ProfRef;
739+
// std::tie(ExeRef, ProfRef) = FilenameRef.split(':');
740+
// if(!ExeRef.empty() && !ProfRef.empty()){
741+
ObjectFilename = ObjectFilename.data();
742+
// ProfileFile = ProfRef.str();
743+
// }
744+
// Expected<std::string> ArchOrError = getArchitectureFromExecutable(ExeRef);
745+
// if(ArchOrError){
746+
// Architecture = std::move(ArchOrError.get());
747+
// }else{
748+
// consumeError(ArchOrError.takeError());
749+
// Architecture = "unknown";
750+
// }
751+
// ObjectFilename = ExeRef;
747752
}
748753
//ANDRES CODE
749754

@@ -837,7 +842,7 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
837842
? *BIDFetcherCorrelatorKind
838843
: ProfCorrelatorKind::NONE;
839844
auto ReaderOrErr = InstrProfReader::create(ProfileFile /*ANDRES changed from Input.Filename to ProfileFile*/, *FS, Correlator, //THIS IS THE IMPORTANT LINE!!!!
840-
BIDFetcher, CorrelatorKind, Warn, Architecture /*ANDRES added this parameter*/);
845+
BIDFetcher, CorrelatorKind, Warn, ObjectFilename /*ANDRES added this parameter*/);
841846
if (Error E = ReaderOrErr.takeError()) {
842847
// Skip the empty profiles by returning silently.
843848
auto [ErrCode, Msg] = InstrProfError::take(std::move(E));
@@ -875,7 +880,7 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
875880
bool firstTime = WC->WriterErrorCodes.insert(ErrCode).second;
876881
handleMergeWriterError(make_error<InstrProfError>(ErrCode, Msg),
877882
Input.Filename, FuncName, firstTime);
878-
}, Architecture);
883+
}, ObjectFilename);
879884
}
880885

881886
if (KeepVTableSymbols) {
@@ -1084,18 +1089,18 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
10841089
MaxTraceLength));
10851090

10861091
if (NumThreads == 1) {
1087-
for (const auto &Input : Inputs)
1088-
loadInput(Input, Remapper, Correlator.get(), ProfiledBinary,
1089-
Contexts[0].get(), BIDFetcher.get(), &BIDFetcherCorrelateKind);
1092+
for (int I = 0; I < int(Inputs.size()); ++I)
1093+
loadInput(Inputs[I], Remapper, Correlator.get(), ProfiledBinary,
1094+
Contexts[0].get(), BIDFetcher.get(), &BIDFetcherCorrelateKind, !ObjectAwareHashing.empty() ? ObjectAwareHashing[I] : "");
10901095
} else {
10911096
DefaultThreadPool Pool(hardware_concurrency(NumThreads));
10921097

10931098
// Load the inputs in parallel (N/NumThreads serial steps).
10941099
unsigned Ctx = 0;
1095-
for (const auto &Input : Inputs) {
1096-
Pool.async(loadInput, Input, Remapper, Correlator.get(), ProfiledBinary,
1100+
for (int I = 0; I < int(Inputs.size()); ++I) {
1101+
Pool.async(loadInput, Inputs[I], Remapper, Correlator.get(), ProfiledBinary,
10971102
Contexts[Ctx].get(), BIDFetcher.get(),
1098-
&BIDFetcherCorrelateKind);
1103+
&BIDFetcherCorrelateKind, !ObjectAwareHashing[I].empty() ? ObjectAwareHashing[I] : "");
10991104
Ctx = (Ctx + 1) % NumThreads;
11001105
}
11011106
Pool.wait();

0 commit comments

Comments
 (0)