LLVM  6.0.0svn
ModuleSlotTracker.h
Go to the documentation of this file.
1 //===-- llvm/IR/ModuleSlotTracker.h -----------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_IR_MODULESLOTTRACKER_H
11 #define LLVM_IR_MODULESLOTTRACKER_H
12 
13 #include <memory>
14 
15 namespace llvm {
16 
17 class Module;
18 class Function;
19 class SlotTracker;
20 class Value;
21 
22 /// Manage lifetime of a slot tracker for printing IR.
23 ///
24 /// Wrapper around the \a SlotTracker used internally by \a AsmWriter. This
25 /// class allows callers to share the cost of incorporating the metadata in a
26 /// module or a function.
27 ///
28 /// If the IR changes from underneath \a ModuleSlotTracker, strings like
29 /// "<badref>" will be printed, or, worse, the wrong slots entirely.
31  /// Storage for a slot tracker.
32  std::unique_ptr<SlotTracker> MachineStorage;
33  bool ShouldCreateStorage = false;
34  bool ShouldInitializeAllMetadata = false;
35 
36  const Module *M = nullptr;
37  const Function *F = nullptr;
38  SlotTracker *Machine = nullptr;
39 
40 public:
41  /// Wrap a preinitialized SlotTracker.
42  ModuleSlotTracker(SlotTracker &Machine, const Module *M,
43  const Function *F = nullptr);
44 
45  /// Construct a slot tracker from a module.
46  ///
47  /// If \a M is \c nullptr, uses a null slot tracker. Otherwise, initializes
48  /// a slot tracker, and initializes all metadata slots. \c
49  /// ShouldInitializeAllMetadata defaults to true because this is expected to
50  /// be shared between multiple callers, and otherwise MDNode references will
51  /// not match up.
52  explicit ModuleSlotTracker(const Module *M,
53  bool ShouldInitializeAllMetadata = true);
54 
55  /// Destructor to clean up storage.
57 
58  /// Lazily creates a slot tracker.
60 
61  const Module *getModule() const { return M; }
62  const Function *getCurrentFunction() const { return F; }
63 
64  /// Incorporate the given function.
65  ///
66  /// Purge the currently incorporated function and incorporate \c F. If \c F
67  /// is currently incorporated, this is a no-op.
68  void incorporateFunction(const Function &F);
69 
70  /// Return the slot number of the specified local value.
71  ///
72  /// A function that defines this value should be incorporated prior to calling
73  /// this method.
74  /// Return -1 if the value is not in the function's SlotTracker.
75  int getLocalSlot(const Value *V);
76 };
77 
78 } // end namespace llvm
79 
80 #endif
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
const Function * getCurrentFunction() const
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
Definition: AsmWriter.cpp:785
Manage lifetime of a slot tracker for printing IR.
SlotTracker * getMachine()
Lazily creates a slot tracker.
Definition: AsmWriter.cpp:760
const Module * getModule() const
This class provides computation of slot numbers for LLVM Assembly writing.
Definition: AsmWriter.cpp:626
void incorporateFunction(const Function &F)
Incorporate the given function.
Definition: AsmWriter.cpp:771
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
Definition: AsmWriter.cpp:749
~ModuleSlotTracker()
Destructor to clean up storage.
LLVM Value Representation.
Definition: Value.h:73