~pali/+junk/llvm-toolchain-3.7

« back to all changes in this revision

Viewing changes to include/llvm/IR/ModuleSlotTracker.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2015-07-15 17:51:08 UTC
  • Revision ID: package-import@ubuntu.com-20150715175108-l8mynwovkx4zx697
Tags: upstream-3.7~+rc2
ImportĀ upstreamĀ versionĀ 3.7~+rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
29
class ModuleSlotTracker {
 
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.
 
53
  ~ModuleSlotTracker();
 
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