@@ -50,9 +50,7 @@ static cl::opt<bool> ForceIsInSpecializedModule(
5050 " ctx-profile-force-is-specialized" , cl::init(false ),
5151 cl::desc(" Treat the given module as-if it were containing the "
5252 " post-thinlink module containing the root" ));
53-
54- const char *AssignGUIDPass::GUIDMetadataName = " guid" ;
55-
53+
5654class ProfileAnnotatorImpl final {
5755 friend class ProfileAnnotator ;
5856 class BBInfo ;
@@ -420,33 +418,6 @@ bool ProfileAnnotator::getOutgoingBranchWeights(
420418 return MaxCount > 0 ;
421419}
422420
423- PreservedAnalyses AssignGUIDPass::run (Module &M, ModuleAnalysisManager &MAM ) {
424- for (auto &F : M.functions ()) {
425- if (F.isDeclaration ())
426- continue ;
427- if (F.getMetadata (GUIDMetadataName))
428- continue ;
429- const GlobalValue::GUID GUID = F.getGUID ();
430- F.setMetadata (GUIDMetadataName,
431- MDNode::get (M.getContext (),
432- {ConstantAsMetadata::get (ConstantInt::get (
433- Type::getInt64Ty (M.getContext ()), GUID ))}));
434- }
435- return PreservedAnalyses::none ();
436- }
437-
438- GlobalValue::GUID AssignGUIDPass::getGUID (const Function &F) {
439- if (F.isDeclaration ()) {
440- assert (GlobalValue::isExternalLinkage (F.getLinkage ()));
441- return F.getGUID ();
442- }
443- auto *MD = F.getMetadata (GUIDMetadataName);
444- assert (MD && " guid not found for defined function" );
445- return cast<ConstantInt>(cast<ConstantAsMetadata>(MD ->getOperand (0 ))
446- ->getValue ()
447- ->stripPointerCasts ())
448- ->getZExtValue ();
449- }
450421AnalysisKey CtxProfAnalysis::Key;
451422
452423CtxProfAnalysis::CtxProfAnalysis (std::optional<StringRef> Profile)
@@ -515,7 +486,7 @@ PGOContextualProfile CtxProfAnalysis::run(Module &M,
515486 for (const auto &F : M) {
516487 if (F.isDeclaration ())
517488 continue ;
518- auto GUID = AssignGUIDPass:: getGUID (F );
489+ auto GUID = F. getGUID ();
519490 assert (GUID && " guid not found for defined function" );
520491 const auto &Entry = F.begin ();
521492 uint32_t MaxCounters = 0 ; // we expect at least a counter.
@@ -549,13 +520,6 @@ PGOContextualProfile CtxProfAnalysis::run(Module &M,
549520 return Result;
550521}
551522
552- GlobalValue::GUID
553- PGOContextualProfile::getDefinedFunctionGUID (const Function &F) const {
554- if (auto It = FuncInfo.find (AssignGUIDPass::getGUID (F)); It != FuncInfo.end ())
555- return It->first ;
556- return 0 ;
557- }
558-
559523CtxProfAnalysisPrinterPass::CtxProfAnalysisPrinterPass (raw_ostream &OS )
560524 : OS (OS ), Mode(PrintLevel) {}
561525
@@ -671,7 +635,7 @@ bool PGOContextualProfile::isInSpecializedModule() const {
671635
672636void PGOContextualProfile::update (Visitor V, const Function &F) {
673637 assert (isFunctionKnown (F));
674- GlobalValue::GUID G = getDefinedFunctionGUID (F );
638+ GlobalValue::GUID G = F. getGUID ( );
675639 for (auto *Node = FuncInfo.find (G)->second .Index .Next ; Node;
676640 Node = Node->Next )
677641 V (*reinterpret_cast <PGOCtxProfContext *>(Node));
@@ -682,7 +646,7 @@ void PGOContextualProfile::visit(ConstVisitor V, const Function *F) const {
682646 return preorderVisit<const PGOCtxProfContext::CallTargetMapTy,
683647 const PGOCtxProfContext>(Profiles.Contexts , V);
684648 assert (isFunctionKnown (*F));
685- GlobalValue::GUID G = getDefinedFunctionGUID (*F );
649+ GlobalValue::GUID G = F-> getGUID ( );
686650 for (const auto *Node = FuncInfo.find (G)->second .Index .Next ; Node;
687651 Node = Node->Next )
688652 V (*reinterpret_cast <const PGOCtxProfContext *>(Node));
0 commit comments