@@ -199,6 +199,11 @@ static cl::opt<std::string> RemappingFile("remapping-file",
199
199
cl::desc(" Symbol remapping file" ));
200
200
static cl::alias RemappingFileA (" r" , cl::desc(" Alias for --remapping-file" ),
201
201
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));
202
207
static cl::opt<bool >
203
208
UseMD5 (" use-md5" , cl::init(false ), cl::Hidden,
204
209
cl::desc(" Choose to use MD5 to represent string in name table (only "
@@ -690,32 +695,32 @@ static void overlapInput(const std::string &BaseFilename,
690
695
}
691
696
}
692
697
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
+ // }
699
704
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
+ // }
704
709
705
- std::unique_ptr<llvm::object::ObjectFile> &Object = ObjectOrError.get ();
710
+ // std::unique_ptr<llvm::object::ObjectFile> &Object = ObjectOrError.get();
706
711
707
- StringRef ArchStr = Object->getArch () != Triple::UnknownArch ? Triple::getArchTypeName (Object->getArch ()) : " unknown" ;
712
+ // StringRef ArchStr = Object->getArch() != Triple::UnknownArch ? Triple::getArchTypeName(Object->getArch()) : "unknown";
708
713
709
- return ArchStr.str ();
710
- }
711
- // ANDRES FUNCTION
714
+ // return ArchStr.str();
715
+ // }
716
+ // // ANDRES FUNCTION
712
717
713
718
// / Load an input into a writer context.
714
719
static void
715
720
loadInput (const WeightedFile &Input, SymbolRemapper *Remapper,
716
721
const InstrProfCorrelator *Correlator, const StringRef ProfiledBinary,
717
722
WriterContext *WC, const object::BuildIDFetcher *BIDFetcher = nullptr ,
718
- const ProfCorrelatorKind *BIDFetcherCorrelatorKind = nullptr ) {
723
+ const ProfCorrelatorKind *BIDFetcherCorrelatorKind = nullptr , StringRef ObjectFilename = " " ) {
719
724
std::unique_lock<std::mutex> CtxGuard{WC->Lock };
720
725
721
726
// Copy the filename, because llvm::ThreadPool copied the input "const
@@ -726,24 +731,24 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
726
731
// ANDRES CODE
727
732
std::string ExecutableName;
728
733
std::string ProfileFile = Input.Filename ;
729
- std::string Architecture = " " ;
734
+ std::string ObjectFilename = " " ;
730
735
731
736
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;
747
752
}
748
753
// ANDRES CODE
749
754
@@ -837,7 +842,7 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
837
842
? *BIDFetcherCorrelatorKind
838
843
: ProfCorrelatorKind::NONE;
839
844
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*/ );
841
846
if (Error E = ReaderOrErr.takeError ()) {
842
847
// Skip the empty profiles by returning silently.
843
848
auto [ErrCode, Msg] = InstrProfError::take (std::move (E));
@@ -875,7 +880,7 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
875
880
bool firstTime = WC->WriterErrorCodes .insert (ErrCode).second ;
876
881
handleMergeWriterError (make_error<InstrProfError>(ErrCode, Msg),
877
882
Input.Filename , FuncName, firstTime);
878
- }, Architecture );
883
+ }, ObjectFilename );
879
884
}
880
885
881
886
if (KeepVTableSymbols) {
@@ -1084,18 +1089,18 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
1084
1089
MaxTraceLength));
1085
1090
1086
1091
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] : " " );
1090
1095
} else {
1091
1096
DefaultThreadPool Pool (hardware_concurrency (NumThreads));
1092
1097
1093
1098
// Load the inputs in parallel (N/NumThreads serial steps).
1094
1099
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,
1097
1102
Contexts[Ctx].get (), BIDFetcher.get (),
1098
- &BIDFetcherCorrelateKind);
1103
+ &BIDFetcherCorrelateKind, !ObjectAwareHashing[I]. empty () ? ObjectAwareHashing[I] : " " );
1099
1104
Ctx = (Ctx + 1 ) % NumThreads;
1100
1105
}
1101
1106
Pool.wait ();
0 commit comments