summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2010-04-03 01:09:47 +0000
committerJohnny Chen <johnny.chen@apple.com>2010-04-03 01:09:47 +0000
commit58e83eb50d28d5da86f76eade4fa577324d4f3e3 (patch)
treea99e2ac5728a02685abc068fd728a8da293317d6
parentebc6f147662a42af345adf6055371a5e20252430 (diff)
downloadbcm5719-llvm-58e83eb50d28d5da86f76eade4fa577324d4f3e3.tar.gz
bcm5719-llvm-58e83eb50d28d5da86f76eade4fa577324d4f3e3.zip
Register ARMAlgorithm::DoCleanup() to be called on exit to free the memory
occuplied by the cached ARMAlgorithm objects. llvm-svn: 100258
-rw-r--r--llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.cpp11
-rw-r--r--llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.h3
2 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.cpp b/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.cpp
index 41c8c228914..9f41455797c 100644
--- a/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.cpp
+++ b/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.cpp
@@ -3130,6 +3130,13 @@ static const DisassembleFP FuncPtrs[] = {
/// Algorithms - Algorithms stores a map from Format to ARMAlgorithm*.
static std::vector<ARMAlgorithm*> Algorithms;
+/// DoCleanup - Do cleanup of Algorithms upon exit.
+void ARMAlgorithm::DoCleanup() {
+ for (unsigned i = 0; i < array_lengthof(FuncPtrs); ++i)
+ if (Algorithms[i])
+ delete Algorithms[i];
+}
+
/// GetInstance - GetInstance returns an instance of ARMAlgorithm given the
/// encoding Format. API clients should not free up the returned instance.
ARMAlgorithm *ARMAlgorithm::GetInstance(ARMFormat Format) {
@@ -3141,11 +3148,13 @@ ARMAlgorithm *ARMAlgorithm::GetInstance(ARMFormat Format) {
Algorithms[i] = new ARMAlgorithm(FuncPtrs[i]);
else
Algorithms[i] = NULL;
+
+ // Register cleanup routine.
+ atexit(DoCleanup);
}
return Algorithms[Format];
}
-
/// BuildIt - BuildIt performs the build step for this ARM Basic MC Builder.
/// The general idea is to set the Opcode for the MCInst, followed by adding
/// the appropriate MCOperands to the MCInst. ARM Basic MC Builder delegates
diff --git a/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.h b/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.h
index 1409a120e48..6d742512f83 100644
--- a/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.h
+++ b/llvm/lib/Target/ARM/Disassembler/ARMDisassemblerCore.h
@@ -181,6 +181,9 @@ public:
/// encoding Format. API clients should not free up the returned instance.
static ARMAlgorithm *GetInstance(ARMFormat Format);
+ /// DoCleanup - DoCleanup is meant to be called upon exit as an exit handler.
+ static void DoCleanup();
+
/// Return true if this algorithm successfully disassembles the instruction.
/// NumOpsAdded is updated to reflect the number of operands added by the
/// algorithm. NumOpsAdded may be less than NumOps, in which case, there are
OpenPOWER on IntegriCloud