@@ -191,6 +191,35 @@ void TargetLoweringObjectFile::emitCGProfileMetadata(MCStreamer &Streamer,
191191 }
192192}
193193
194+ void TargetLoweringObjectFile::emitPseudoProbeDescMetadata (MCStreamer &Streamer,
195+ Module &M) const {
196+ NamedMDNode *FuncInfo = M.getNamedMetadata (PseudoProbeDescMetadataName);
197+ if (!FuncInfo)
198+ return ;
199+
200+ // Emit a descriptor for every function including functions that have an
201+ // available external linkage. We may not want this for imported functions
202+ // that has code in another thinLTO module but we don't have a good way to
203+ // tell them apart from inline functions defined in header files. Therefore
204+ // we put each descriptor in a separate comdat section and rely on the
205+ // linker to deduplicate.
206+ auto &C = getContext ();
207+ for (const auto *Operand : FuncInfo->operands ()) {
208+ const auto *MD = cast<MDNode>(Operand);
209+ auto *GUID = mdconst::dyn_extract<ConstantInt>(MD->getOperand (0 ));
210+ auto *Hash = mdconst::dyn_extract<ConstantInt>(MD->getOperand (1 ));
211+ auto *Name = cast<MDString>(MD->getOperand (2 ));
212+ auto *S = C.getObjectFileInfo ()->getPseudoProbeDescSection (
213+ TM->getFunctionSections () ? Name->getString () : StringRef ());
214+
215+ Streamer.switchSection (S);
216+ Streamer.emitInt64 (GUID->getZExtValue ());
217+ Streamer.emitInt64 (Hash->getZExtValue ());
218+ Streamer.emitULEB128IntValue (Name->getString ().size ());
219+ Streamer.emitBytes (Name->getString ());
220+ }
221+ }
222+
194223// / getKindForGlobal - This is a top-level target-independent classifier for
195224// / a global object. Given a global variable and information from the TM, this
196225// / function classifies the global in a target independent manner. This function
0 commit comments