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
19void MachineModuleSlotTracker::processMachineFunctionMetadata(
21 // Create metadata created within the backend.
22 for (const MachineBasicBlock &MBB : MF)
23 for (const MachineInstr &MI : MBB.instrs()) {
24 if (MDNode *N = MI.getHeapAllocMarker())
26 if (MDNode *N = MI.getPCSections())
28 if (MDNode *N = MI.getMMRAMetadata())
30
31 for (const MachineOperand &MO : MI.operands())
32 if (MO.isMetadata())
33 AST->createMetadataSlot(MO.getMetadata());
34
35 for (const MachineMemOperand *MMO : MI.memoperands()) {
36 AAMDNodes AAInfo = MMO->getAAInfo();
37 if (AAInfo.TBAA)
38 AST->createMetadataSlot(AAInfo.TBAA);
39 if (AAInfo.TBAAStruct)
40 AST->createMetadataSlot(AAInfo.TBAAStruct);
41 if (AAInfo.Scope)
42 AST->createMetadataSlot(AAInfo.Scope);
43 if (AAInfo.NoAlias)
44 AST->createMetadataSlot(AAInfo.NoAlias);
45 if (AAInfo.NoAliasAddrSpace)
47 if (const MDNode *N = MMO->getRanges())
49 if (const MDNode *N = MMO->getMemCacheHint())
51 }
52 }
53
54 for (const MachineFunction::VariableDbgInfo &DebugVar :
55 MF.getVariableDbgInfo()) {
56 AST->createMetadataSlot(DebugVar.Var);
57 }
58}
59
60void MachineModuleSlotTracker::processMachineModule(
62 bool ShouldInitializeAllMetadata) {
63 if (ShouldInitializeAllMetadata) {
64 for (const Function &F : *M) {
65 if (&F != &TheFunction)
66 continue;
67 MDNStartSlot = AST->getNextMetadataSlot();
68 if (TheMF)
69 processMachineFunctionMetadata(AST, *TheMF);
70 MDNEndSlot = AST->getNextMetadataSlot();
71 break;
72 }
73 }
74}
75
76void MachineModuleSlotTracker::processMachineFunction(
78 bool ShouldInitializeAllMetadata) {
79 if (!ShouldInitializeAllMetadata && F == &TheFunction) {
80 MDNStartSlot = AST->getNextMetadataSlot();
81 if (TheMF)
82 processMachineFunctionMetadata(AST, *TheMF);
83 MDNEndSlot = AST->getNextMetadataSlot();
84 }
85}
86
88 MachineMDNodeListType &L) const {
89 collectMDNodes(L, MDNStartSlot, MDNEndSlot);
90}
91
93 MFGetterFnT Fn, const MachineFunction *MF, bool ShouldInitializeAllMetadata)
95 ShouldInitializeAllMetadata),
96 TheFunction(MF->getFunction()), TheMF(Fn(MF->getFunction())) {
98 bool ShouldInitializeAllMetadata) {
99 this->processMachineModule(AST, M, ShouldInitializeAllMetadata);
100 });
102 bool ShouldInitializeAllMetadata) {
103 this->processMachineFunction(AST, F, ShouldInitializeAllMetadata);
104 });
105}
106
MachineBasicBlock & MBB
static const Function * getParent(const Value *V)
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
Abstract interface of slot tracker storage.
virtual unsigned getNextMetadataSlot()=0
virtual void createMetadataSlot(const MDNode *)=0
void collectMachineMDNodes(MachineMDNodeListType &L) const
MachineModuleSlotTracker(MFGetterFnT Fn, const MachineFunction *MF, bool ShouldInitializeAllMetadata=true)
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
This is an optimization pass for GlobalISel generic memory operations.
function_ref< MachineFunction *(const Function &)> MFGetterFnT
#define N
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