LLVM  13.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 <memory>
13 
14 namespace llvm {
15 
16 class Module;
17 class Function;
18 class SlotTracker;
19 class Value;
20 
21 /// Manage lifetime of a slot tracker for printing IR.
22 ///
23 /// Wrapper around the \a SlotTracker used internally by \a AsmWriter. This
24 /// class allows callers to share the cost of incorporating the metadata in a
25 /// module or a function.
26 ///
27 /// If the IR changes from underneath \a ModuleSlotTracker, strings like
28 /// "<badref>" will be printed, or, worse, the wrong slots entirely.
30  /// Storage for a slot tracker.
31  std::unique_ptr<SlotTracker> MachineStorage;
32  bool ShouldCreateStorage = false;
33  bool ShouldInitializeAllMetadata = false;
34 
35  const Module *M = nullptr;
36  const Function *F = nullptr;
37  SlotTracker *Machine = nullptr;
38 
39 public:
40  /// Wrap a preinitialized SlotTracker.
41  ModuleSlotTracker(SlotTracker &Machine, const Module *M,
42  const Function *F = nullptr);
43 
44  /// Construct a slot tracker from a module.
45  ///
46  /// If \a M is \c nullptr, uses a null slot tracker. Otherwise, initializes
47  /// a slot tracker, and initializes all metadata slots. \c
48  /// ShouldInitializeAllMetadata defaults to true because this is expected to
49  /// be shared between multiple callers, and otherwise MDNode references will
50  /// not match up.
51  explicit ModuleSlotTracker(const Module *M,
52  bool ShouldInitializeAllMetadata = true);
53 
54  /// Destructor to clean up storage.
56 
57  /// Lazily creates a slot tracker.
59 
60  const Module *getModule() const { return M; }
61  const Function *getCurrentFunction() const { return F; }
62 
63  /// Incorporate the given function.
64  ///
65  /// Purge the currently incorporated function and incorporate \c F. If \c F
66  /// is currently incorporated, this is a no-op.
67  void incorporateFunction(const Function &F);
68 
69  /// Return the slot number of the specified local value.
70  ///
71  /// A function that defines this value should be incorporated prior to calling
72  /// this method.
73  /// Return -1 if the value is not in the function's SlotTracker.
74  int getLocalSlot(const Value *V);
75 };
76 
77 } // end namespace llvm
78 
79 #endif
llvm::ModuleSlotTracker::~ModuleSlotTracker
~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:906
llvm
Definition: AllocatorList.h:23
llvm::ModuleSlotTracker::getModule
const Module * getModule() const
Definition: ModuleSlotTracker.h:60
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:61
llvm::ModuleSlotTracker::getCurrentFunction
const Function * getCurrentFunction() const
Definition: ModuleSlotTracker.h:61
llvm::ModuleSlotTracker::incorporateFunction
void incorporateFunction(const Function &F)
Incorporate the given function.
Definition: AsmWriter.cpp:892
llvm::ModuleSlotTracker
Manage lifetime of a slot tracker for printing IR.
Definition: ModuleSlotTracker.h:29
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:870
llvm::ModuleSlotTracker::getMachine
SlotTracker * getMachine()
Lazily creates a slot tracker.
Definition: AsmWriter.cpp:881
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::SlotTracker
This class provides computation of slot numbers for LLVM Assembly writing.
Definition: AsmWriter.cpp:716
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::codeview::PublicSymFlags::Function
@ Function