@@ -526,24 +526,24 @@ class InstrProfSymtab {
526
526
// so it doesn't use a StringSet for function names.
527
527
StringSet<> VTableNames;
528
528
// A map from MD5 keys to function name strings.
529
- std::vector<std::pair<uint64_t , StringRef>> MD5NameMap;
529
+ mutable std::vector<std::pair<uint64_t , StringRef>> MD5NameMap;
530
530
// A map from MD5 keys to function define. We only populate this map
531
531
// when build the Symtab from a Module.
532
- std::vector<std::pair<uint64_t , Function *>> MD5FuncMap;
532
+ mutable std::vector<std::pair<uint64_t , Function *>> MD5FuncMap;
533
533
// A map from MD5 to the global variable. This map is only populated when
534
534
// building the symtab from a module. Use separate container instances for
535
535
// `MD5FuncMap` and `MD5VTableMap`.
536
536
// TODO: Unify the container type and the lambda function 'mapName' inside
537
537
// add{Func,VTable}WithName.
538
- DenseMap<uint64_t , GlobalVariable *> MD5VTableMap;
538
+ mutable DenseMap<uint64_t , GlobalVariable *> MD5VTableMap;
539
539
// A map from function runtime address to function name MD5 hash.
540
540
// This map is only populated and used by raw instr profile reader.
541
- AddrHashMap AddrToMD5Map;
541
+ mutable AddrHashMap AddrToMD5Map;
542
542
543
543
AddrIntervalMap::Allocator VTableAddrMapAllocator;
544
544
// This map is only populated and used by raw instr profile reader.
545
545
AddrIntervalMap VTableAddrMap;
546
- bool Sorted = false ;
546
+ mutable bool Sorted = false ;
547
547
548
548
static StringRef getExternalSymbol () { return " ** External Symbol **" ; }
549
549
@@ -566,7 +566,7 @@ class InstrProfSymtab {
566
566
// finalizeSymtab needs to be called before looking up function names.
567
567
// This is required because the underlying map is a vector (for space
568
568
// efficiency) which needs to be sorted.
569
- inline void finalizeSymtab ();
569
+ inline void finalizeSymtab () const ;
570
570
571
571
public:
572
572
InstrProfSymtab () : VTableAddrMap(VTableAddrMapAllocator) {}
@@ -676,36 +676,37 @@ class InstrProfSymtab {
676
676
}
677
677
678
678
// / Return a function's hash, or 0, if the function isn't in this SymTab.
679
- LLVM_ABI uint64_t getFunctionHashFromAddress (uint64_t Address);
679
+ LLVM_ABI uint64_t getFunctionHashFromAddress (uint64_t Address) const ;
680
680
681
681
// / Return a vtable's hash, or 0 if the vtable doesn't exist in this SymTab.
682
- LLVM_ABI uint64_t getVTableHashFromAddress (uint64_t Address);
682
+ LLVM_ABI uint64_t getVTableHashFromAddress (uint64_t Address) const ;
683
683
684
684
// / Return function's PGO name from the function name's symbol
685
685
// / address in the object file. If an error occurs, return
686
686
// / an empty string.
687
- LLVM_ABI StringRef getFuncName (uint64_t FuncNameAddress, size_t NameSize);
687
+ LLVM_ABI StringRef getFuncName (uint64_t FuncNameAddress,
688
+ size_t NameSize) const ;
688
689
689
690
// / Return name of functions or global variables from the name's md5 hash
690
691
// / value. If not found, return an empty string.
691
- inline StringRef getFuncOrVarName (uint64_t ValMD5Hash);
692
+ inline StringRef getFuncOrVarName (uint64_t ValMD5Hash) const ;
692
693
693
694
// / Just like getFuncOrVarName, except that it will return literal string
694
695
// / 'External Symbol' if the function or global variable is external to
695
696
// / this symbol table.
696
- inline StringRef getFuncOrVarNameIfDefined (uint64_t ValMD5Hash);
697
+ inline StringRef getFuncOrVarNameIfDefined (uint64_t ValMD5Hash) const ;
697
698
698
699
// / True if Symbol is the value used to represent external symbols.
699
700
static bool isExternalSymbol (const StringRef &Symbol) {
700
701
return Symbol == InstrProfSymtab::getExternalSymbol ();
701
702
}
702
703
703
704
// / Return function from the name's md5 hash. Return nullptr if not found.
704
- inline Function *getFunction (uint64_t FuncMD5Hash);
705
+ inline Function *getFunction (uint64_t FuncMD5Hash) const ;
705
706
706
707
// / Return the global variable corresponding to md5 hash. Return nullptr if
707
708
// / not found.
708
- inline GlobalVariable *getGlobalVariable (uint64_t MD5Hash);
709
+ inline GlobalVariable *getGlobalVariable (uint64_t MD5Hash) const ;
709
710
710
711
// / Return the name section data.
711
712
inline StringRef getNameData () const { return Data; }
@@ -748,7 +749,7 @@ Error InstrProfSymtab::create(const FuncNameIterRange &FuncIterRange,
748
749
return Error::success ();
749
750
}
750
751
751
- void InstrProfSymtab::finalizeSymtab () {
752
+ void InstrProfSymtab::finalizeSymtab () const {
752
753
if (Sorted)
753
754
return ;
754
755
llvm::sort (MD5NameMap, less_first ());
@@ -758,14 +759,14 @@ void InstrProfSymtab::finalizeSymtab() {
758
759
Sorted = true ;
759
760
}
760
761
761
- StringRef InstrProfSymtab::getFuncOrVarNameIfDefined (uint64_t MD5Hash) {
762
- StringRef ret = getFuncOrVarName (MD5Hash);
763
- if (ret .empty ())
762
+ StringRef InstrProfSymtab::getFuncOrVarNameIfDefined (uint64_t MD5Hash) const {
763
+ StringRef Ret = getFuncOrVarName (MD5Hash);
764
+ if (Ret .empty ())
764
765
return InstrProfSymtab::getExternalSymbol ();
765
- return ret ;
766
+ return Ret ;
766
767
}
767
768
768
- StringRef InstrProfSymtab::getFuncOrVarName (uint64_t MD5Hash) {
769
+ StringRef InstrProfSymtab::getFuncOrVarName (uint64_t MD5Hash) const {
769
770
finalizeSymtab ();
770
771
auto Result = llvm::lower_bound (MD5NameMap, MD5Hash,
771
772
[](const std::pair<uint64_t , StringRef> &LHS,
@@ -775,7 +776,7 @@ StringRef InstrProfSymtab::getFuncOrVarName(uint64_t MD5Hash) {
775
776
return StringRef ();
776
777
}
777
778
778
- Function* InstrProfSymtab::getFunction (uint64_t FuncMD5Hash) {
779
+ Function * InstrProfSymtab::getFunction (uint64_t FuncMD5Hash) const {
779
780
finalizeSymtab ();
780
781
auto Result = llvm::lower_bound (MD5FuncMap, FuncMD5Hash,
781
782
[](const std::pair<uint64_t , Function *> &LHS,
@@ -785,7 +786,7 @@ Function* InstrProfSymtab::getFunction(uint64_t FuncMD5Hash) {
785
786
return nullptr ;
786
787
}
787
788
788
- GlobalVariable *InstrProfSymtab::getGlobalVariable (uint64_t MD5Hash) {
789
+ GlobalVariable *InstrProfSymtab::getGlobalVariable (uint64_t MD5Hash) const {
789
790
return MD5VTableMap.lookup (MD5Hash);
790
791
}
791
792
0 commit comments