LLVM 20.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#include "llvm/IR/Module.h"
13
14using namespace llvm;
15
16void MachineModuleSlotTracker::processMachineFunctionMetadata(
18 // Create metadata created within the backend.
19 for (const MachineBasicBlock &MBB : MF)
20 for (const MachineInstr &MI : MBB.instrs())
21 for (const MachineMemOperand *MMO : MI.memoperands()) {
22 AAMDNodes AAInfo = MMO->getAAInfo();
23 if (AAInfo.TBAA)
24 AST->createMetadataSlot(AAInfo.TBAA);
25 if (AAInfo.TBAAStruct)
26 AST->createMetadataSlot(AAInfo.TBAAStruct);
27 if (AAInfo.Scope)
28 AST->createMetadataSlot(AAInfo.Scope);
29 if (AAInfo.NoAlias)
30 AST->createMetadataSlot(AAInfo.NoAlias);
31 }
32}
33
34void MachineModuleSlotTracker::processMachineModule(
36 bool ShouldInitializeAllMetadata) {
37 if (ShouldInitializeAllMetadata) {
38 for (const Function &F : *M) {
39 if (&F != &TheFunction)
40 continue;
41 MDNStartSlot = AST->getNextMetadataSlot();
42 if (auto *MF = TheMMI.getMachineFunction(F))
43 processMachineFunctionMetadata(AST, *MF);
44 MDNEndSlot = AST->getNextMetadataSlot();
45 break;
46 }
47 }
48}
49
50void MachineModuleSlotTracker::processMachineFunction(
52 bool ShouldInitializeAllMetadata) {
53 if (!ShouldInitializeAllMetadata && F == &TheFunction) {
54 MDNStartSlot = AST->getNextMetadataSlot();
55 if (auto *MF = TheMMI.getMachineFunction(*F))
56 processMachineFunctionMetadata(AST, *MF);
57 MDNEndSlot = AST->getNextMetadataSlot();
58 }
59}
60
62 MachineMDNodeListType &L) const {
63 collectMDNodes(L, MDNStartSlot, MDNEndSlot);
64}
65
67 const MachineModuleInfo &MMI, const MachineFunction *MF,
68 bool ShouldInitializeAllMetadata)
70 ShouldInitializeAllMetadata),
71 TheFunction(MF->getFunction()), TheMMI(MMI) {
73 bool ShouldInitializeAllMetadata) {
74 this->processMachineModule(AST, M, ShouldInitializeAllMetadata);
75 });
77 bool ShouldInitializeAllMetadata) {
78 this->processMachineFunction(AST, F, ShouldInitializeAllMetadata);
79 });
80}
81
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
Module.h This file contains the declarations for the Module class.
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.
This class contains meta information specific to a module.
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
void collectMachineMDNodes(MachineMDNodeListType &L) const
MachineModuleSlotTracker(const MachineModuleInfo &MMI, const MachineFunction *MF, bool ShouldInitializeAllMetadata=true)
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:5252
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
Definition: AsmWriter.cpp:922
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