LLVM  3.7.0
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 
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 
33  const Module *M = nullptr;
34  const Function *F = nullptr;
35  SlotTracker *Machine = nullptr;
36 
37 public:
38  /// Wrap a preinitialized SlotTracker.
39  ModuleSlotTracker(SlotTracker &Machine, const Module *M,
40  const Function *F = nullptr);
41 
42  /// Construct a slot tracker from a module.
43  ///
44  /// If \a M is \c nullptr, uses a null slot tracker. Otherwise, initializes
45  /// a slot tracker, and initializes all metadata slots. \c
46  /// ShouldInitializeAllMetadata defaults to true because this is expected to
47  /// be shared between multiple callers, and otherwise MDNode references will
48  /// not match up.
49  explicit ModuleSlotTracker(const Module *M,
50  bool ShouldInitializeAllMetadata = true);
51 
52  /// Destructor to clean up storage.
54 
55  SlotTracker *getMachine() const { return Machine; }
56  const Module *getModule() const { return M; }
57  const Function *getCurrentFunction() const { return F; }
58 
59  /// Incorporate the given function.
60  ///
61  /// Purge the currently incorporated function and incorporate \c F. If \c F
62  /// is currently incorporated, this is a no-op.
63  void incorporateFunction(const Function &F);
64 };
65 
66 } // end namespace llvm
67 
68 #endif
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
Manage lifetime of a slot tracker for printing IR.
SlotTracker * getMachine() const
This class provides computation of slot numbers for LLVM Assembly writing.
Definition: AsmWriter.cpp:554
void incorporateFunction(const Function &F)
Incorporate the given function.
Definition: AsmWriter.cpp:681
ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)
Wrap a preinitialized SlotTracker.
Definition: AsmWriter.cpp:669
~ModuleSlotTracker()
Destructor to clean up storage.
Definition: AsmWriter.cpp:679
const Module * getModule() const
const Function * getCurrentFunction() const