@@ -517,35 +517,46 @@ Error InstrProfSymtab::create(StringRef NameStrings) {
517
517
std::bind (&InstrProfSymtab::addFuncName, this , std::placeholders::_1));
518
518
}
519
519
520
- Error InstrProfSymtab::addFuncWithName (Function &F, StringRef PGOFuncName) {
521
- if (Error E = addFuncName (PGOFuncName))
522
- return E;
523
- MD5FuncMap.emplace_back (Function::getGUID (PGOFuncName), &F);
520
+ StringRef InstrProfSymtab::getCanonicalName (StringRef PGOName) {
524
521
// In ThinLTO, local function may have been promoted to global and have
525
522
// suffix ".llvm." added to the function name. We need to add the
526
523
// stripped function name to the symbol table so that we can find a match
527
524
// from profile.
528
525
//
529
- // We may have other suffixes similar as ".llvm." which are needed to
530
- // be stripped before the matching, but ".__uniq." suffix which is used
531
- // to differentiate internal linkage functions in different modules
532
- // should be kept. Now this is the only suffix with the pattern ".xxx"
533
- // which is kept before matching.
526
+ // ".__uniq." suffix is used to differentiate internal linkage functions in
527
+ // different modules and should be kept. This is the only suffix with the
528
+ // pattern ".xxx" which is kept before matching, other suffixes similar as
529
+ // ".llvm." will be stripped.
534
530
const std::string UniqSuffix = " .__uniq." ;
535
- auto pos = PGOFuncName.find (UniqSuffix);
536
- // Search '.' after ".__uniq." if ".__uniq." exists, otherwise
537
- // search '.' from the beginning.
538
- if (pos != std::string::npos)
531
+ size_t pos = PGOName.find (UniqSuffix);
532
+ if (pos != StringRef::npos)
539
533
pos += UniqSuffix.length ();
540
534
else
541
535
pos = 0 ;
542
- pos = PGOFuncName.find (' .' , pos);
543
- if (pos != std::string::npos && pos != 0 ) {
544
- StringRef OtherFuncName = PGOFuncName.substr (0 , pos);
545
- if (Error E = addFuncName (OtherFuncName))
536
+
537
+ // Search '.' after ".__uniq." if ".__uniq." exists, otherwise search '.' from
538
+ // the beginning.
539
+ pos = PGOName.find (' .' , pos);
540
+ if (pos != StringRef::npos && pos != 0 )
541
+ return PGOName.substr (0 , pos);
542
+
543
+ return PGOName;
544
+ }
545
+
546
+ Error InstrProfSymtab::addFuncWithName (Function &F, StringRef PGOFuncName) {
547
+ auto mapName = [&](StringRef Name) -> Error {
548
+ if (Error E = addFuncName (Name))
546
549
return E;
547
- MD5FuncMap.emplace_back (Function::getGUID (OtherFuncName), &F);
548
- }
550
+ MD5FuncMap.emplace_back (Function::getGUID (Name), &F);
551
+ return Error::success ();
552
+ };
553
+ if (Error E = mapName (PGOFuncName))
554
+ return E;
555
+
556
+ StringRef CanonicalFuncName = getCanonicalName (PGOFuncName);
557
+ if (CanonicalFuncName != PGOFuncName)
558
+ return mapName (CanonicalFuncName);
559
+
549
560
return Error::success ();
550
561
}
551
562
0 commit comments