LLVM 24.0.0git
MachineModuleSlotTracker.cpp
Go to the documentation of this file.
1//===-- llvm/CodeGen/MachineModuleInfo.cpp ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
15#include "llvm/IR/Module.h"
16
17using namespace llvm;
18
20 const DILocation *DL) const {
21 return InlineDebugLocations.contains(DL);
22}
23
24void MachineModuleSlotTracker::collectMachineFunctionMetadata(
26 SmallVectorImpl<const MDNode *> *DebugLocations) const {
27 for (const MachineBasicBlock &MBB : MF)
28 for (const MachineInstr &MI : MBB.instrs()) {
29 if (DebugLocations)
30 if (DebugLoc DL = MI.getDebugLoc())
31 DebugLocations->push_back(DL.getAsMDNode());
32
33 if (MDNode *N = MI.getHeapAllocMarker())
34 Metadata.push_back(N);
35 if (MDNode *N = MI.getPCSections())
36 Metadata.push_back(N);
37 if (MDNode *N = MI.getMMRAMetadata())
38 Metadata.push_back(N);
39
40 for (const MachineOperand &MO : MI.operands())
41 if (MO.isMetadata())
42 Metadata.push_back(MO.getMetadata());
43
44 for (const MachineMemOperand *MMO : MI.memoperands()) {
45 AAMDNodes AAInfo = MMO->getAAInfo();
46 if (AAInfo.TBAA)
47 Metadata.push_back(AAInfo.TBAA);
48 if (AAInfo.TBAAStruct)
49 Metadata.push_back(AAInfo.TBAAStruct);
50 if (AAInfo.Scope)
51 Metadata.push_back(AAInfo.Scope);
52 if (AAInfo.NoAlias)
53 Metadata.push_back(AAInfo.NoAlias);
54 if (AAInfo.NoAliasAddrSpace)
55 Metadata.push_back(AAInfo.NoAliasAddrSpace);
56 if (const MDNode *N = MMO->getRanges())
57 Metadata.push_back(N);
58 if (const MDNode *N = MMO->getMemCacheHint())
59 Metadata.push_back(N);
60 }
61 }
62
63 for (const MachineFunction::VariableDbgInfo &DebugVar :
64 MF.getVariableDbgInfo()) {
65 Metadata.push_back(DebugVar.Var);
66 if (DebugLocations)
67 DebugLocations->push_back(DebugVar.Loc);
68 }
69}
70
72 MachineMDNodeListType &L) const {
73 L.insert(L.end(), MachineMDNodes.begin(), MachineMDNodes.end());
74}
75
77 if (!TheMF)
78 return;
79
81 collectMachineFunctionMetadata(Metadata, *TheMF);
82 MachineMDNodes.clear();
84}
85
87 const MachineFunction *MF)
89 TheMF(Fn(MF->getFunction())) {
90 if (!TheMF)
91 return;
92
95 collectMachineFunctionMetadata(Metadata, *TheMF, &DebugLocations);
96 collectAdditionalMetadata(Metadata, MachineMDNodes);
97
98 if (DebugLocations.empty())
99 return;
100
101 MachineMDNodeListType DebugMetadataNodes;
102 collectAdditionalMetadata(DebugLocations, DebugMetadataNodes);
103 SmallPtrSet<const MDNode *, 16> MachineMetadata;
104 for (const auto &Entry : MachineMDNodes)
105 MachineMetadata.insert(Entry.second);
106
107 for (const auto &Entry : DebugMetadataNodes)
108 if (isa<DILocation>(Entry.second) &&
109 !MachineMetadata.contains(Entry.second))
110 InlineDebugLocations.insert(cast<DILocation>(Entry.second));
111}
112
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
dxil translate DXIL Translate Metadata
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
A debug info location.
Definition DebugLoc.h:126
Metadata node.
Definition Metadata.h:1069
Representation of each machine instruction.
A description of a memory reference used in the backend.
MachineModuleSlotTracker(MFGetterFnT Fn, const MachineFunction *MF)
bool shouldPrintDebugLocationInline(const DILocation *DL) const override
Return whether a debug location should be printed inline instead of by ID.
void collectMachineMDNodes(MachineMDNodeListType &L) const
void renumberMetadataForAssembly()
Renumber module and machine metadata for canonical MIR output.
MachineOperand class - Representation of each machine instruction operand.
Root of the metadata hierarchy.
Definition Metadata.h:64
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
void renumberMetadataForAssembly(ArrayRef< const MDNode * > AdditionalMetadata, MachineMDNodeListType *AdditionalMetadataNodes=nullptr) const
Renumber module metadata and then additional metadata for canonical assembly output.
void collectAdditionalMetadata(ArrayRef< const MDNode * > AdditionalMetadata, MachineMDNodeListType &AdditionalMetadataNodes) const
Collect metadata reachable from AdditionalMetadata but not from the module.
SmallVector< std::pair< unsigned, const MDNode * >, 0 > MachineMDNodeListType
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
function_ref< MachineFunction *(const Function &)> MFGetterFnT
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:763
MDNode * NoAliasAddrSpace
The tag specifying the noalias address spaces.
Definition Metadata.h:792
MDNode * TBAAStruct
The tag for type-based alias analysis (tbaa struct).
Definition Metadata.h:783
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition Metadata.h:786
MDNode * TBAA
The tag for type-based alias analysis.
Definition Metadata.h:780
MDNode * NoAlias
The tag specifying the noalias scope.
Definition Metadata.h:789