LLVM  14.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 
13 using namespace llvm;
14 
15 void 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 
33 void MachineModuleSlotTracker::processMachineModule(
34  AbstractSlotTrackerStorage *AST, const Module *M,
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 
49 void 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()), MDNStartSlot(0),
70  MDNEndSlot(0) {
72  bool ShouldInitializeAllMetadata) {
73  this->processMachineModule(AST, M, ShouldInitializeAllMetadata);
74  });
76  bool ShouldInitializeAllMetadata) {
77  this->processMachineFunction(AST, F, ShouldInitializeAllMetadata);
78  });
79 }
80 
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Function
Definition: Function.h:62
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:255
llvm::MachineBasicBlock::instrs
instr_range instrs()
Definition: MachineBasicBlock.h:263
MachineModuleSlotTracker.h
llvm::AAMDNodes
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:651
llvm::AAMDNodes::TBAAStruct
MDNode * TBAAStruct
The tag for type-based alias analysis (tbaa struct).
Definition: Metadata.h:671
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition: MachineMemOperand.h:128
llvm::AAMDNodes::Scope
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition: Metadata.h:674
llvm::ModuleSlotTracker
Manage lifetime of a slot tracker for printing IR.
Definition: ModuleSlotTracker.h:44
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::AbstractSlotTrackerStorage::getNextMetadataSlot
virtual unsigned getNextMetadataSlot()=0
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::ModuleSlotTracker::collectMDNodes
void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const
Definition: AsmWriter.cpp:4823
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
MachineModuleInfo.h
llvm::MachineModuleSlotTracker::~MachineModuleSlotTracker
~MachineModuleSlotTracker()
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineModuleSlotTracker::MachineModuleSlotTracker
MachineModuleSlotTracker(const MachineFunction *MF, bool ShouldInitializeAllMetadata=true)
Definition: MachineModuleSlotTracker.cpp:65
llvm::ModuleSlotTracker::setProcessHook
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
Definition: AsmWriter.cpp:875
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::AbstractSlotTrackerStorage::createMetadataSlot
virtual void createMetadataSlot(const MDNode *)=0
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:890
llvm::ModuleSlotTracker::MachineMDNodeListType
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
Definition: ModuleSlotTracker.h:102
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::AAMDNodes::NoAlias
MDNode * NoAlias
The tag specifying the noalias scope.
Definition: Metadata.h:677
llvm::MachineModuleInfo::getMachineFunction
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
Definition: MachineModuleInfo.cpp:286
llvm::AAMDNodes::TBAA
MDNode * TBAA
The tag for type-based alias analysis.
Definition: Metadata.h:668
llvm::AbstractSlotTrackerStorage
Abstract interface of slot tracker storage.
Definition: ModuleSlotTracker.h:26
MachineFunction.h
llvm::MachineModuleSlotTracker::collectMachineMDNodes
void collectMachineMDNodes(MachineMDNodeListType &L) const
Definition: MachineModuleSlotTracker.cpp:60