Skip to content
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
29d4db2
[𝘀𝗽𝗿] changes to main this commit is based on
Prabhuk Nov 20, 2024
8f53618
[𝘀𝗽𝗿] initial version
Prabhuk Nov 20, 2024
a794047
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Dec 10, 2024
abfcb9c
Reorder commits.
Prabhuk Dec 10, 2024
de23806
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 12, 2025
05307cf
Update LTO compilation CodeGen flag for call-graph-section.
Prabhuk Mar 12, 2025
6a12be2
Fix EOF newlines.
Prabhuk Mar 12, 2025
a068971
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
54a3db2
Add requested tests part 1.
Prabhuk Mar 13, 2025
74044aa
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
77672ec
Update comments in tests.
Prabhuk Mar 13, 2025
1826b03
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
a8e2bd8
Updated the test as reviewers suggested.
Prabhuk Mar 13, 2025
2f7dbf2
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
3b605a6
Scoped enum. Simplify test.
Prabhuk Mar 13, 2025
7014fef
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
db11fc7
Remove unnecessary cast.
Prabhuk Mar 13, 2025
eb582bd
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
673481e
Remove unnecessary asserts. Remove autos for better readability.
Prabhuk Mar 13, 2025
6388364
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 13, 2025
694cfd0
Reorder IR metadata and rename temporary var names in test.
Prabhuk Mar 13, 2025
f90b397
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 14, 2025
270074f
Add RISC-V support. Clean up test files.
Prabhuk Mar 14, 2025
da8ae04
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 15, 2025
6045320
Clean up test files.
Prabhuk Mar 15, 2025
573eebe
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Mar 19, 2025
a175709
Address review comments.
Prabhuk Mar 19, 2025
823a513
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 19, 2025
b5b2b10
Use callee_type metadata instead of OB.
Prabhuk Apr 19, 2025
2cac836
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 19, 2025
5ede050
Address review comments.
Prabhuk Apr 19, 2025
0c78d0a
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 23, 2025
d0a96ac
Rebase on top of llvm stack.
Prabhuk Apr 23, 2025
7a1c8fb
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 23, 2025
89c896b
Rebase on parent llvm change.
Prabhuk Apr 23, 2025
a56ccb8
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 23, 2025
c53d51d
Address review comments.
Prabhuk Apr 23, 2025
ab46191
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 24, 2025
839da25
Address review comments.
Prabhuk Apr 24, 2025
5b36796
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 24, 2025
43d6eed
Rebase on parent.
Prabhuk Apr 24, 2025
05057b8
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 24, 2025
5188f32
Rebase on parent.
Prabhuk Apr 24, 2025
2131b83
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 28, 2025
c5a12e9
Rebase on parent.
Prabhuk Apr 28, 2025
759a709
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Apr 29, 2025
5cdb84e
Rebase on llvm changes.
Prabhuk Apr 29, 2025
32c7adb
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 1, 2025
75dec8e
Rebase on parent.
Prabhuk May 1, 2025
8a289b1
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 5, 2025
e0020f5
Rebase on parent.
Prabhuk May 5, 2025
9c21da8
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 10, 2025
f165443
Rebase on parent change.
Prabhuk May 10, 2025
f83a155
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 13, 2025
2745a8a
Rebase on parent llvm changes.
Prabhuk May 13, 2025
03ad07f
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 13, 2025
12df871
Rebase on parent.
Prabhuk May 13, 2025
edf799d
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 14, 2025
2a3c23d
Rebase on parent
Prabhuk May 14, 2025
d04642b
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 14, 2025
d4d4533
Rebase on main.
Prabhuk May 14, 2025
8bbbe12
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 27, 2025
37d3ef9
Rebase on parent.
Prabhuk May 27, 2025
ca6d2cc
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil May 27, 2025
c02cbb9
Rebase change.
Prabhuk May 27, 2025
8f07a4c
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jun 11, 2025
b16770b
Rebase.
Prabhuk Jun 11, 2025
0e29abc
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jun 11, 2025
1e773e1
Rebase on parent
Prabhuk Jun 11, 2025
38fc4f5
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 10, 2025
7b9cbb3
Rebase on top of main.
Prabhuk Jul 10, 2025
b7d5e7f
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
9591c3a
Rebase on parent.
Prabhuk Jul 18, 2025
c262b69
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
07f7768
Rebase on parent
Prabhuk Jul 18, 2025
125ddcd
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
15a1b29
Rebase on top of parent change.
Prabhuk Jul 18, 2025
9eff07d
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
1c0f1ab
Rebase on parent.
Prabhuk Jul 18, 2025
1ba8c04
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
0c1ec48
Rebase on parent.
Prabhuk Jul 18, 2025
c9f6c5c
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 18, 2025
9592631
Address review comments.
Prabhuk Jul 18, 2025
c09082e
[𝘀𝗽𝗿] changes introduced through rebase
necipfazil Jul 21, 2025
80c3580
Rebase on parent.
Prabhuk Jul 21, 2025
c67f714
Fix review comment on test file.
Prabhuk Jul 21, 2025
7f95a40
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 22, 2025
410bb0d
Rebase.
Prabhuk Jul 22, 2025
7321a3e
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 23, 2025
66c858e
Rebase on parent llvm change.
Prabhuk Jul 23, 2025
2d81ecc
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 23, 2025
c2294fa
Rebase on main.
Prabhuk Jul 23, 2025
571a431
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 23, 2025
6884d2a
Rebase.
Prabhuk Jul 23, 2025
036be4e
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 28, 2025
1fb27f8
Rebase on parent.
Prabhuk Jul 28, 2025
4ec81ea
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 28, 2025
9d29e55
Rebase on llvm changes.
Prabhuk Jul 28, 2025
23c8579
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 30, 2025
00f7d91
Rebase on main.
Prabhuk Jul 30, 2025
2924f11
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 31, 2025
0aa3d97
Rebase on main.
Prabhuk Jul 31, 2025
50a5786
[𝘀𝗽𝗿] changes introduced through rebase
Prabhuk Jul 31, 2025
a6b4a13
Rebase on parent.
Prabhuk Jul 31, 2025
f4d6c96
Rebase on main.
Prabhuk Jul 31, 2025
d349feb
Make Driver flag experimental.
Prabhuk Jul 31, 2025
d50a454
Merge branch 'main' into users/Prabhuk/sprclangcallgraphsection-add-c…
Prabhuk Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ CODEGENOPT(EnableNoundefAttrs, 1, 0) ///< Enable emitting `noundef` attributes o
CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
///< pass manager.
CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled.
CODEGENOPT(CallGraphSection, 1, 0) ///< Emit a call graph section into the
///< object file.
CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
///< '-g' + 'O>0' level.
CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4318,6 +4318,12 @@ defm data_sections : BoolFOption<"data-sections",
PosFlag<SetTrue, [], [ClangOption, CC1Option],
"Place each data in its own section">,
NegFlag<SetFalse>>;
defm call_graph_section
: BoolFOption<"call-graph-section", CodeGenOpts<"CallGraphSection">,
DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option],
"Emit a call graph section">,
NegFlag<SetFalse>>;
defm stack_size_section : BoolFOption<"stack-size-section",
CodeGenOpts<"StackSizeSection">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option],
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ static bool initTargetOptions(const CompilerInstance &CI,
Options.StackUsageOutput = CodeGenOpts.StackUsageOutput;
Options.EmitAddrsig = CodeGenOpts.Addrsig;
Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
Options.EmitCallGraphSection = CodeGenOpts.CallGraphSection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TargetOptions :(

Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6656,6 +6656,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(A->getValue());
}

if (Args.hasFlag(options::OPT_fcall_graph_section,
options::OPT_fno_call_graph_section, false))
CmdArgs.push_back("-fcall-graph-section");

Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
options::OPT_fno_stack_size_section);

Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,11 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
CmdArgs.push_back(
Args.MakeArgString(Twine(PluginOptPrefix) + "-stack-size-section"));

if (Args.hasFlag(options::OPT_fcall_graph_section,
options::OPT_fno_call_graph_section, false))
CmdArgs.push_back(
Args.MakeArgString(Twine(PluginOptPrefix) + "-call-graph-section"));

// Setup statistics file output.
SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
if (!StatsFile.empty())
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/call-graph-section.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %clang -### -S -fcall-graph-section %s 2>&1 | FileCheck --check-prefix=CALL-GRAPH-SECTION %s
// RUN: %clang -### -S -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// RUN: %clang -### -S -fcall-graph-section %s 2>&1 | FileCheck --check-prefix=CALL-GRAPH-SECTION %s
// RUN: %clang -### -S -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s
// RUN: %clang -### -fcall-graph-section %s 2>&1 | FileCheck --check-prefix=CALL-GRAPH-SECTION %s
// RUN: %clang -### -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s

Don't really care about the output type if you aren't using it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


// CALL-GRAPH-SECTION: "-fcall-graph-section"
// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section"
33 changes: 33 additions & 0 deletions llvm/docs/CalleeTypeMetadata.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
====================
Callee Type Metadata
====================

Introduction
============
This ``!callee_type`` metadata is introduced to support the generation of a call graph
section in the object file. The ``!callee_type`` metadata is used
to identify the types of the intended callees of indirect call instructions. The ``!callee_type`` metadata is a
list of one or more generalized ``!type`` metadata objects (See :doc:`TypeMetadata`) with each ``!type``
metadata pointing to a callee's :ref:`type identifier <calleetype-type-identifier>`.
LLVM's `Control Flow Integrity (CFI)`_ also uses the ``!type`` metadata in its implementation.

.. _Control Flow Integrity (CFI): https://clang.llvm.org/docs/ControlFlowIntegrity.html

.. _calleetype-type-identifier:

Type identifier
================

The type for an indirect call target is the callee's function signature.
Mapping from a type to an identifier is an ABI detail.
In the current implementation, an identifier of type T is
computed as follows:

- Obtain the generalized mangled name for “typeinfo name for T”.
- Compute MD5 hash of the name as a string.
- Reinterpret the first 8 bytes of the hash as a little-endian 64-bit integer.

To avoid mismatched pointer types, generalizations are applied.
Pointers in return and argument types are treated as equivalent as long as the qualifiers for the
type they point to match. For example, ``char*``, ``char**``, and ``int*`` are considered equivalent
types. However, ``char*`` and ``const char*`` are considered distinct types.
5 changes: 5 additions & 0 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8091,6 +8091,11 @@ change in the future.

See :doc:`TypeMetadata`.

'``callee_type``' Metadata
^^^^^^^^^^^^^^^^^^^^^^^^^^

See :doc:`CalleeTypeMetadata`.

'``associated``' Metadata
^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions llvm/docs/Reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LLVM and API reference documentation.
BlockFrequencyTerminology
BranchWeightMetadata
Bugpoint
CalleeTypeMetadata
CIBestPractices
CommandGuide/index
ConvergenceAndUniformity
Expand Down
39 changes: 39 additions & 0 deletions llvm/include/llvm/CodeGen/AsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,36 @@ class AsmPrinter : public MachineFunctionPass {
/// Emit comments in assembly output if this is true.
bool VerboseAsm;

/// Store symbols and type identifiers used to create call graph section
/// entries related to a function.
struct FunctionInfo {
/// Numeric type identifier used in call graph section for indirect calls
/// and targets.
using CGTypeId = uint64_t;

/// Enumeration of function kinds, and their mapping to function kind values
/// stored in call graph section entries.
/// Must match the enum in llvm/tools/llvm-objdump/llvm-objdump.cpp.
enum class FunctionKind : uint64_t {
/// Function cannot be target to indirect calls.
NOT_INDIRECT_TARGET = 0,

/// Function may be target to indirect calls but its type id is unknown.
INDIRECT_TARGET_UNKNOWN_TID = 1,

/// Function may be target to indirect calls and its type id is known.
INDIRECT_TARGET_KNOWN_TID = 2,
};

/// Map type identifiers to callsite labels. Labels are only for indirect
/// calls and inclusive of all indirect calls of the function.
SmallVector<std::pair<CGTypeId, MCSymbol *>> CallSiteLabels;
};

enum CallGraphSectionFormatVersion : uint64_t {
V_0 = 0,
};

/// Output stream for the stack usage file (i.e., .su file).
std::unique_ptr<raw_fd_ostream> StackUsageStream;

Expand Down Expand Up @@ -342,6 +372,13 @@ class AsmPrinter : public MachineFunctionPass {
/// are available. Returns empty string otherwise.
StringRef getConstantSectionSuffix(const Constant *C) const;

/// Generate and emit labels for callees of the indirect callsites which will
/// be used to populate the .callgraph section.
void emitIndirectCalleeLabels(
FunctionInfo &FuncInfo,
const MachineFunction::CallSiteInfoMap &CallSitesInfoMap,
const MachineInstr &MI);

//===------------------------------------------------------------------===//
// XRay instrumentation implementation.
//===------------------------------------------------------------------===//
Expand Down Expand Up @@ -429,6 +466,8 @@ class AsmPrinter : public MachineFunctionPass {
void emitKCFITrapEntry(const MachineFunction &MF, const MCSymbol *Symbol);
virtual void emitKCFITypeId(const MachineFunction &MF);

void emitCallGraphSection(const MachineFunction &MF, FunctionInfo &FuncInfo);

void emitPseudoProbe(const MachineInstr &MI);

void emitRemarksSection(remarks::RemarkStreamer &RS);
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/CommandFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ bool getEnableStackSizeSection();

bool getEnableAddrsig();

bool getEnableCallGraphSection();

bool getEmitCallSiteInfo();

bool getEnableMachineFunctionSplitter();
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/MIRYamlMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ struct CallSiteInfo {

MachineInstrLoc CallLocation;
std::vector<ArgRegPair> ArgForwardingRegs;
/// Numeric callee type identifiers for the callgraph section.
std::vector<uint64_t> CalleeTypeIds;

bool operator==(const CallSiteInfo &Other) const {
return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
Expand Down Expand Up @@ -511,6 +513,7 @@ template <> struct MappingTraits<CallSiteInfo> {
YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
std::vector<CallSiteInfo::ArgRegPair>());
YamlIO.mapOptional("calleeTypeIds", CSInfo.CalleeTypeIds);
}

static const bool flow = true;
Expand Down
34 changes: 33 additions & 1 deletion llvm/include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/ArrayRecycler.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/Recycler.h"
#include "llvm/Target/TargetOptions.h"
#include <bitset>
Expand Down Expand Up @@ -496,18 +499,47 @@ class LLVM_ABI MachineFunction {
struct CallSiteInfo {
/// Vector of call argument and its forwarding register.
SmallVector<ArgRegPair, 1> ArgRegPairs;
/// Callee type ids.
SmallVector<ConstantInt *, 4> CalleeTypeIds;

CallSiteInfo() = default;

/// Extracts the numeric type id from the CallBase's callee_type Metadata,
/// and sets CalleeTypeIds. This is used as type id for the indirect call in
/// the call graph section.
CallSiteInfo(const CallBase &CB) {
// Call graph section needs numeric callee_type id only for indirect
// calls.
if (!CB.isIndirectCall())
return;

MDNode *CalleeTypeList = CB.getMetadata(LLVMContext::MD_callee_type);
if (!CalleeTypeList)
return;

for (const MDOperand &Op : CalleeTypeList->operands()) {
MDNode *TypeMD = cast<MDNode>(Op);
MDString *TypeIdStr = cast<MDString>(TypeMD->getOperand(1));
// Compute numeric type id from generalized type id string
uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString());
IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext());
CalleeTypeIds.push_back(
ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false));
}
}
};

struct CalledGlobalInfo {
const GlobalValue *Callee;
unsigned TargetFlags;
};

using CallSiteInfoMap = DenseMap<const MachineInstr *, CallSiteInfo>;

private:
Delegate *TheDelegate = nullptr;
GISelChangeObserver *Observer = nullptr;

using CallSiteInfoMap = DenseMap<const MachineInstr *, CallSiteInfo>;
/// Map a call instruction to call site arguments forwarding info.
CallSiteInfoMap CallSitesInfo;

Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/IR/FixedMetadataKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ LLVM_FIXED_MD_KIND(MD_DIAssignID, "DIAssignID", 38)
LLVM_FIXED_MD_KIND(MD_coro_outside_frame, "coro.outside.frame", 39)
LLVM_FIXED_MD_KIND(MD_mmra, "mmra", 40)
LLVM_FIXED_MD_KIND(MD_noalias_addrspace, "noalias.addrspace", 41)
LLVM_FIXED_MD_KIND(MD_callee_type, "callee_type", 42)
8 changes: 8 additions & 0 deletions llvm/include/llvm/IR/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,12 @@ class MDNode : public Metadata {
bool isReplaceable() const { return isTemporary() || isAlwaysReplaceable(); }
bool isAlwaysReplaceable() const { return getMetadataID() == DIAssignIDKind; }

bool hasGeneralizedMDString() const {
if (getNumOperands() < 2 || !isa<MDString>(getOperand(1)))
return false;
return cast<MDString>(getOperand(1))->getString().ends_with(".generalized");
}

unsigned getNumTemporaryUses() const {
assert(isTemporary() && "Only for temporaries");
return Context.getReplaceableUses()->getNumUses();
Expand Down Expand Up @@ -1463,6 +1469,8 @@ class MDNode : public Metadata {
const Instruction *BInstr);
static MDNode *getMergedMemProfMetadata(MDNode *A, MDNode *B);
static MDNode *getMergedCallsiteMetadata(MDNode *A, MDNode *B);
static MDNode *getMergedCalleeTypeMetadata(LLVMContext &Ctx, MDNode *A,
MDNode *B);
};

/// Tuple of metadata.
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/MC/MCObjectFileInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class MCObjectFileInfo {
/// Language Specific Data Area information is emitted to.
MCSection *LSDASection = nullptr;

/// Section containing call graph metadata.
MCSection *CallGraphSection = nullptr;

/// If exception handling is supported by the target and the target can
/// support a compact representation of the CIE and FDE, this is the section
/// to emit them into.
Expand Down Expand Up @@ -360,6 +363,8 @@ class MCObjectFileInfo {
MCSection *getFaultMapSection() const { return FaultMapSection; }
MCSection *getRemarksSection() const { return RemarksSection; }

MCSection *getCallGraphSection(const MCSection &TextSec) const;

MCSection *getStackSizesSection(const MCSection &TextSec) const;

MCSection *getBBAddrMapSection(const MCSection &TextSec) const;
Expand Down
12 changes: 8 additions & 4 deletions llvm/include/llvm/Target/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ namespace llvm {
EmitStackSizeSection(false), EnableMachineOutliner(false),
EnableMachineFunctionSplitter(false),
EnableStaticDataPartitioning(false), SupportsDefaultOutlining(false),
EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
EmitAddrsig(false), BBAddrMap(false), EmitCallGraphSection(false),
EmitCallSiteInfo(false), SupportsDebugEntryValues(false),
EnableDebugEntryValues(false), ValueTrackingVariableLocations(false),
ForceDwarfFrameSection(false), XRayFunctionIndex(true),
DebugStrictDwarf(false), Hotpatch(false),
PPCGenScalarMASSEntries(false), JMCInstrument(false),
EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
VerifyArgABICompliance(true),
Expand Down Expand Up @@ -333,6 +334,9 @@ namespace llvm {
/// to selectively generate basic block sections.
std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;

/// Emit section containing call graph metadata.
unsigned EmitCallGraphSection : 1;

/// The flag enables call site info production. It is used only for debug
/// info, and it is restricted only to optimized code. This can be used for
/// something else, so that should be controlled in the frontend.
Expand Down
Loading
Loading