LLVM  14.0.0git
ModuleSlotTracker.h
Go to the documentation of this file.
1 //===-- llvm/IR/ModuleSlotTracker.h -----------------------------*- 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 
9 #ifndef LLVM_IR_MODULESLOTTRACKER_H
10 #define LLVM_IR_MODULESLOTTRACKER_H
11 
12 #include <functional>
13 #include <memory>
14 #include <utility>
15 #include <vector>
16 
17 namespace llvm {
18 
19 class Module;
20 class Function;
21 class SlotTracker;
22 class Value;
23 class MDNode;
24 
25 /// Abstract interface of slot tracker storage.
27 public:
29 
30  virtual unsigned getNextMetadataSlot() = 0;
31 
32  virtual void createMetadataSlot(const MDNode *) = 0;
33  virtual int getMetadataSlot(const MDNode *) = 0;
34 };
35 
36 /// Manage lifetime of a slot tracker for printing IR.
37 ///
38 /// Wrapper around the \a SlotTracker used internally by \a AsmWriter. This
39 /// class allows callers to share the cost of incorporating the metadata in a
40 /// module or a function.
41 ///
42 /// If the IR changes from underneath \a ModuleSlotTracker, strings like
43 /// "<badref>" will be printed, or, worse, the wrong slots entirely.
45  /// Storage for a slot tracker.
46  std::unique_ptr<SlotTracker> MachineStorage;
47  bool ShouldCreateStorage = false;
48  bool ShouldInitializeAllMetadata = false;
49 
50  const Module *M = nullptr;
51  const Function *F = nullptr;
52  SlotTracker *Machine = nullptr;
53 
54  std::function<void(AbstractSlotTrackerStorage *, const Module *, bool)>
55  ProcessModuleHookFn;
56  std::function<void(AbstractSlotTrackerStorage *, const Function *, bool)>
57  ProcessFunctionHookFn;
58 
59 public:
60  /// Wrap a preinitialized SlotTracker.
61  ModuleSlotTracker(SlotTracker &Machine, const Module *M,
62  const Function *F = nullptr);
63 
64  /// Construct a slot tracker from a module.
65  ///
66  /// If \a M is \c nullptr, uses a null slot tracker. Otherwise, initializes
67  /// a slot tracker, and initializes all metadata slots. \c
68  /// ShouldInitializeAllMetadata defaults to true because this is expected to
69  /// be shared between multiple callers, and otherwise MDNode references will
70  /// not match up.
71  explicit ModuleSlotTracker(const Module *M,
72  bool ShouldInitializeAllMetadata = true);
73 
74  /// Destructor to clean up storage.
75  virtual ~ModuleSlotTracker();
76 
77  /// Lazily creates a slot tracker.
79 
80  const Module *getModule() const { return M; }
81  const Function *getCurrentFunction() const { return F; }
82 
83  /// Incorporate the given function.
84  ///
85  /// Purge the currently incorporated function and incorporate \c F. If \c F
86  /// is currently incorporated, this is a no-op.
87  void incorporateFunction(const Function &F);
88 
89  /// Return the slot number of the specified local value.
90  ///
91  /// A function that defines this value should be incorporated prior to calling
92  /// this method.
93  /// Return -1 if the value is not in the function's SlotTracker.
94  int getLocalSlot(const Value *V);
95 
96  void setProcessHook(
97  std::function<void(AbstractSlotTrackerStorage *, const Module *, bool)>);
99  const Function *, bool)>);
100 
101  using MachineMDNodeListType =
102  std::vector<std::pair<unsigned, const MDNode *>>;
103 
104  void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const;
105 };
106 
107 } // end namespace llvm
108 
109 #endif
llvm::ModuleSlotTracker::~ModuleSlotTracker
virtual ~ModuleSlotTracker()
Destructor to clean up storage.
llvm::ModuleSlotTracker::getLocalSlot
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
Definition: AsmWriter.cpp:870
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::ModuleSlotTracker::getModule
const Module * getModule() const
Definition: ModuleSlotTracker.h:80
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
llvm::ModuleSlotTracker::getCurrentFunction
const Function * getCurrentFunction() const
Definition: ModuleSlotTracker.h:81
llvm::ModuleSlotTracker::incorporateFunction
void incorporateFunction(const Function &F)
Incorporate the given function.
Definition: AsmWriter.cpp:856
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::ModuleSlotTracker::ModuleSlotTracker
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
Definition: AsmWriter.cpp:830
llvm::AbstractSlotTrackerStorage::getNextMetadataSlot
virtual unsigned getNextMetadataSlot()=0
llvm::AbstractSlotTrackerStorage::~AbstractSlotTrackerStorage
virtual ~AbstractSlotTrackerStorage()
Definition: AsmWriter.cpp:651
llvm::ModuleSlotTracker::collectMDNodes
void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const
Definition: AsmWriter.cpp:4823
llvm::ModuleSlotTracker::getMachine
SlotTracker * getMachine()
Lazily creates a slot tracker.
Definition: AsmWriter.cpp:841
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:906
llvm::ModuleSlotTracker::setProcessHook
void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)
Definition: AsmWriter.cpp:875
llvm::ReplayInlineScope::Function
@ Function
llvm::AbstractSlotTrackerStorage::createMetadataSlot
virtual void createMetadataSlot(const MDNode *)=0
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::ModuleSlotTracker::MachineMDNodeListType
std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType
Definition: ModuleSlotTracker.h:102
llvm::AbstractSlotTrackerStorage::getMetadataSlot
virtual int getMetadataSlot(const MDNode *)=0
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::SlotTracker
This class provides computation of slot numbers for LLVM Assembly writing.
Definition: AsmWriter.cpp:660
llvm::AbstractSlotTrackerStorage
Abstract interface of slot tracker storage.
Definition: ModuleSlotTracker.h:26
llvm::Value
LLVM Value Representation.
Definition: Value.h:74