Skip to content

Commit 1487084

Browse files
authored
[NFC] Hoist pseudo probe desc emission code for reuse (#148756)
This PR is part of #123870. The pseudo probe desc emission code can be reused by other target.
1 parent 0c3a2fa commit 1487084

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

llvm/include/llvm/Target/TargetLoweringObjectFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class LLVM_ABI TargetLoweringObjectFile : public MCObjectFileInfo {
9393
/// Emit Call Graph Profile metadata.
9494
void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const;
9595

96+
/// Emit pseudo_probe_desc metadata.
97+
void emitPseudoProbeDescMetadata(MCStreamer &Streamer, Module &M) const;
98+
9699
/// Process linker options metadata and emit platform-specific bits.
97100
virtual void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const {}
98101

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -322,28 +322,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
322322
}
323323
}
324324

325-
if (NamedMDNode *FuncInfo = M.getNamedMetadata(PseudoProbeDescMetadataName)) {
326-
// Emit a descriptor for every function including functions that have an
327-
// available external linkage. We may not want this for imported functions
328-
// that has code in another thinLTO module but we don't have a good way to
329-
// tell them apart from inline functions defined in header files. Therefore
330-
// we put each descriptor in a separate comdat section and rely on the
331-
// linker to deduplicate.
332-
for (const auto *Operand : FuncInfo->operands()) {
333-
const auto *MD = cast<MDNode>(Operand);
334-
auto *GUID = mdconst::dyn_extract<ConstantInt>(MD->getOperand(0));
335-
auto *Hash = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
336-
auto *Name = cast<MDString>(MD->getOperand(2));
337-
auto *S = C.getObjectFileInfo()->getPseudoProbeDescSection(
338-
TM->getFunctionSections() ? Name->getString() : StringRef());
339-
340-
Streamer.switchSection(S);
341-
Streamer.emitInt64(GUID->getZExtValue());
342-
Streamer.emitInt64(Hash->getZExtValue());
343-
Streamer.emitULEB128IntValue(Name->getString().size());
344-
Streamer.emitBytes(Name->getString());
345-
}
346-
}
325+
emitPseudoProbeDescMetadata(Streamer, M);
347326

348327
if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {
349328
// Emit the metadata for llvm statistics into .llvm_stats section, which is

llvm/lib/Target/TargetLoweringObjectFile.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)