summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-20 19:05:59 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-20 19:05:59 +0000
commitaf0fdc2ab8fddfe125c8369194c3867808292557 (patch)
tree0ea24b8e7d570ed73b4e3a1edb3759128ff6e11c
parentbf4df85ba7d8c690680da2b8a61e35f4f3fe7cee (diff)
downloadbcm5719-llvm-af0fdc2ab8fddfe125c8369194c3867808292557.tar.gz
bcm5719-llvm-af0fdc2ab8fddfe125c8369194c3867808292557.zip
IR: Avoid mallocs in constructor of ModuleSlotTracker
A ModuleSlotTracker can be created without actually being used (e.g., r266889 added one to the Verifier). Create the SlotTracker within it lazily on the first call to ModuleSlotTracker::getMachine. llvm-svn: 266902
-rw-r--r--llvm/include/llvm/IR/ModuleSlotTracker.h6
-rw-r--r--llvm/lib/IR/AsmWriter.cpp19
2 files changed, 20 insertions, 5 deletions
diff --git a/llvm/include/llvm/IR/ModuleSlotTracker.h b/llvm/include/llvm/IR/ModuleSlotTracker.h
index 49730a66bdf..eb26fba906e 100644
--- a/llvm/include/llvm/IR/ModuleSlotTracker.h
+++ b/llvm/include/llvm/IR/ModuleSlotTracker.h
@@ -30,6 +30,8 @@ class Value;
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;
@@ -53,7 +55,9 @@ public:
/// 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; }
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 916f90fd598..43165bf65ed 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -697,14 +697,25 @@ ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
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.
OpenPOWER on IntegriCloud