1 //===-- llvm/IR/ModuleSlotTracker.h -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_IR_MODULESLOTTRACKER_H
11 #define LLVM_IR_MODULESLOTTRACKER_H
22 /// Manage lifetime of a slot tracker for printing IR.
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.
28 /// If the IR changes from underneath \a ModuleSlotTracker, strings like
29 /// "<badref>" will be printed, or, worse, the wrong slots entirely.
30 class ModuleSlotTracker {
31 /// Storage for a slot tracker.
32 std::unique_ptr<SlotTracker> MachineStorage;
33 bool ShouldCreateStorage = false;
34 bool ShouldInitializeAllMetadata = false;
36 const Module *M = nullptr;
37 const Function *F = nullptr;
38 SlotTracker *Machine = nullptr;
41 /// Wrap a preinitialized SlotTracker.
42 ModuleSlotTracker(SlotTracker &Machine, const Module *M,
43 const Function *F = nullptr);
45 /// Construct a slot tracker from a module.
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
52 explicit ModuleSlotTracker(const Module *M,
53 bool ShouldInitializeAllMetadata = true);
55 /// Destructor to clean up storage.
58 /// Lazily creates a slot tracker.
59 SlotTracker *getMachine();
61 const Module *getModule() const { return M; }
62 const Function *getCurrentFunction() const { return F; }
64 /// Incorporate the given function.
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);
70 /// Return the slot number of the specified local value.
72 /// A function that defines this value should be incorporated prior to calling
74 /// Return -1 if the value is not in the function's SlotTracker.
75 int getLocalSlot(const Value *V);
78 } // end namespace llvm