class ModuleSlotTracker {
/// Storage for a slot tracker.
std::unique_ptr<SlotTracker> MachineStorage;
+ bool ShouldCreateStorage = false;
+ bool ShouldInitializeAllMetadata = false;
const Module *M = nullptr;
const Function *F = nullptr;
/// Destructor to clean up storage.
~ModuleSlotTracker();
- SlotTracker *getMachine() const { return Machine; }
+ /// Lazily creates a slot tracker.
+ SlotTracker *getMachine();
+
const Module *getModule() const { return M; }
const Function *getCurrentFunction() const { return F; }
ModuleSlotTracker::ModuleSlotTracker(const Module *M,
bool ShouldInitializeAllMetadata)
- : MachineStorage(M ? new SlotTracker(M, ShouldInitializeAllMetadata)
- : nullptr),
- M(M), Machine(MachineStorage.get()) {}
+ : ShouldCreateStorage(M),
+ ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
ModuleSlotTracker::~ModuleSlotTracker() {}
+SlotTracker *ModuleSlotTracker::getMachine() {
+ if (!ShouldCreateStorage)
+ return Machine;
+
+ ShouldCreateStorage = false;
+ MachineStorage =
+ llvm::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
+ Machine = MachineStorage.get();
+ return Machine;
+}
+
void ModuleSlotTracker::incorporateFunction(const Function &F) {
- if (!Machine)
+ // Using getMachine() may lazily create the slot tracker.
+ if (!getMachine())
return;
// Nothing to do if this is the right function already.