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
21
/// Manage lifetime of a slot tracker for printing IR.
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.
27
/// If the IR changes from underneath \a ModuleSlotTracker, strings like
28
/// "<badref>" will be printed, or, worse, the wrong slots entirely.
29
class ModuleSlotTracker {
30
/// Storage for a slot tracker.
31
std::unique_ptr<SlotTracker> MachineStorage;
33
const Module *M = nullptr;
34
const Function *F = nullptr;
35
SlotTracker *Machine = nullptr;
38
/// Wrap a preinitialized SlotTracker.
39
ModuleSlotTracker(SlotTracker &Machine, const Module *M,
40
const Function *F = nullptr);
42
/// Construct a slot tracker from a module.
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
49
explicit ModuleSlotTracker(const Module *M,
50
bool ShouldInitializeAllMetadata = true);
52
/// Destructor to clean up storage.
55
SlotTracker *getMachine() const { return Machine; }
56
const Module *getModule() const { return M; }
57
const Function *getCurrentFunction() const { return F; }
59
/// Incorporate the given function.
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);
66
} // end namespace llvm