[MachineScheduler] Fix physreg dependencies of ExitSU (#123541)
[llvm-project.git] / llvm / lib / CodeGen / MachineModuleSlotTracker.cpp
blob8f10435e7998e3805c1c673925a09cd91236bef6
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 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/MachineModuleSlotTracker.h"
10 #include "llvm/CodeGen/MachineFunction.h"
11 #include "llvm/CodeGen/MachineModuleInfo.h"
12 #include "llvm/IR/Module.h"
14 using namespace llvm;
16 void MachineModuleSlotTracker::processMachineFunctionMetadata(
17 AbstractSlotTrackerStorage *AST, const MachineFunction &MF) {
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);
34 void MachineModuleSlotTracker::processMachineModule(
35 AbstractSlotTrackerStorage *AST, const Module *M,
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;
50 void MachineModuleSlotTracker::processMachineFunction(
51 AbstractSlotTrackerStorage *AST, const Function *F,
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();
61 void MachineModuleSlotTracker::collectMachineMDNodes(
62 MachineMDNodeListType &L) const {
63 collectMDNodes(L, MDNStartSlot, MDNEndSlot);
66 MachineModuleSlotTracker::MachineModuleSlotTracker(
67 const MachineModuleInfo &MMI, const MachineFunction *MF,
68 bool ShouldInitializeAllMetadata)
69 : ModuleSlotTracker(MF->getFunction().getParent(),
70 ShouldInitializeAllMetadata),
71 TheFunction(MF->getFunction()), TheMMI(MMI) {
72 setProcessHook([this](AbstractSlotTrackerStorage *AST, const Module *M,
73 bool ShouldInitializeAllMetadata) {
74 this->processMachineModule(AST, M, ShouldInitializeAllMetadata);
75 });
76 setProcessHook([this](AbstractSlotTrackerStorage *AST, const Function *F,
77 bool ShouldInitializeAllMetadata) {
78 this->processMachineFunction(AST, F, ShouldInitializeAllMetadata);
79 });
82 MachineModuleSlotTracker::~MachineModuleSlotTracker() = default;