LLVM 19.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
12
13using namespace llvm;
14
15void MachineModuleSlotTracker::processMachineFunctionMetadata(
17 // Create metadata created within the backend.
18 for (const MachineBasicBlock &MBB : MF)
19 for (const MachineInstr &MI : MBB.instrs())
20 for (const MachineMemOperand *MMO : MI.memoperands()) {
21 AAMDNodes AAInfo = MMO->getAAInfo();
22 if (AAInfo.TBAA)
23 AST->createMetadataSlot(AAInfo.TBAA);
24 if (AAInfo.TBAAStruct)
25 AST->createMetadataSlot(AAInfo.TBAAStruct);
26 if (AAInfo.Scope)
27 AST->createMetadataSlot(AAInfo.Scope);
28 if (AAInfo.NoAlias)
29 AST->createMetadataSlot(AAInfo.NoAlias);
30 }
31}
32
33void MachineModuleSlotTracker::processMachineModule(
35 bool ShouldInitializeAllMetadata) {
36 if (ShouldInitializeAllMetadata) {
37 for (const Function &F : *M) {
38 if (&F != &TheFunction)
39 continue;
40 MDNStartSlot = AST->getNextMetadataSlot();
41 if (auto *MF = TheMMI.getMachineFunction(F))
42 processMachineFunctionMetadata(AST, *MF);
43 MDNEndSlot = AST->getNextMetadataSlot();
44 break;
45 }
46 }
47}
48
49void MachineModuleSlotTracker::processMachineFunction(
51 bool ShouldInitializeAllMetadata) {
52 if (!ShouldInitializeAllMetadata && F == &TheFunction) {
53 MDNStartSlot = AST->getNextMetadataSlot();
54 if (auto *MF = TheMMI.getMachineFunction(*F))
55 processMachineFunctionMetadata(AST, *MF);
56 MDNEndSlot = AST->getNextMetadataSlot();
57 }
58}
59
61 MachineMDNodeListType &L) const {
62 collectMDNodes(L, MDNStartSlot, MDNEndSlot);
63}
64
66 const MachineFunction *MF, bool ShouldInitializeAllMetadata)
68 ShouldInitializeAllMetadata),
69 TheFunction(MF->getFunction()), TheMMI(MF->getMMI()) {
71 bool ShouldInitializeAllMetadata) {
72 this->processMachineModule(AST, M, ShouldInitializeAllMetadata);
73 });
75 bool ShouldInitializeAllMetadata) {
76 this->processMachineFunction(AST, F, ShouldInitializeAllMetadata);
77 });
78}
79
MachineBasicBlock & MBB
static const Function * getParent(const Value *V)
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:236
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
Abstract interface of slot tracker storage.
virtual unsigned getNextMetadataSlot()=0
virtual void createMetadataSlot(const MDNode *)=0
Representation of each machine instruction.
Definition: MachineInstr.h:69
A description of a memory reference used in the backend.
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
MachineModuleSlotTracker(const MachineFunction *MF, bool ShouldInitializeAllMetadata=true)
void collectMachineMDNodes(MachineMDNodeListType &L) const
Manage lifetime of a slot tracker for printing IR.
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const
Definition: AsmWriter.cpp:5225
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
Definition: AsmWriter.cpp:918
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:760
MDNode * TBAAStruct
The tag for type-based alias analysis (tbaa struct).
Definition: Metadata.h:780
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition: Metadata.h:783
MDNode * TBAA
The tag for type-based alias analysis.
Definition: Metadata.h:777
MDNode * NoAlias
The tag specifying the noalias scope.
Definition: Metadata.h:786