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;
34 const Module *M = nullptr;
35 const Function *F = nullptr;
36 SlotTracker *Machine = nullptr;
39 /// Wrap a preinitialized SlotTracker.
40 ModuleSlotTracker(SlotTracker &Machine, const Module *M,
41 const Function *F = nullptr);
43 /// Construct a slot tracker from a module.
45 /// If \a M is \c nullptr, uses a null slot tracker. Otherwise, initializes
46 /// a slot tracker, and initializes all metadata slots. \c
47 /// ShouldInitializeAllMetadata defaults to true because this is expected to
48 /// be shared between multiple callers, and otherwise MDNode references will
50 explicit ModuleSlotTracker(const Module *M,
51 bool ShouldInitializeAllMetadata = true);
53 /// Destructor to clean up storage.
56 SlotTracker *getMachine() const { return Machine; }
57 const Module *getModule() const { return M; }
58 const Function *getCurrentFunction() const { return F; }
60 /// Incorporate the given function.
62 /// Purge the currently incorporated function and incorporate \c F. If \c F
63 /// is currently incorporated, this is a no-op.
64 void incorporateFunction(const Function &F);
66 /// Return the slot number of the specified local value.
68 /// A function that defines this value should be incorporated prior to calling
70 /// Return -1 if the value is not in the function's SlotTracker.
71 int getLocalSlot(const Value *V);
74 } // end namespace llvm