[llvm] r206244 - Use unique_ptr to own MCFunctions within MCModule.
David Blaikie
dblaikie at gmail.com
Mon Apr 14 22:15:20 PDT 2014
Author: dblaikie
Date: Tue Apr 15 00:15:19 2014
New Revision: 206244
URL: http://llvm.org/viewvc/llvm-project?rev=206244&view=rev
Log:
Use unique_ptr to own MCFunctions within MCModule.
MCModule's ctor had to be moved out of line so the definition of
MCFunction was available. (ctor requires the dtor of members (in case
the ctor throws) which required access to the dtor of MCFunction)
Modified:
llvm/trunk/include/llvm/MC/MCModule.h
llvm/trunk/lib/MC/MCModule.cpp
llvm/trunk/lib/MC/MCModuleYAML.cpp
llvm/trunk/lib/MC/MCObjectDisassembler.cpp
Modified: llvm/trunk/include/llvm/MC/MCModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCModule.h?rev=206244&r1=206243&r2=206244&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCModule.h (original)
+++ llvm/trunk/include/llvm/MC/MCModule.h Tue Apr 15 00:15:19 2014
@@ -73,7 +73,7 @@ class MCModule {
/// \name Function tracking
/// @{
- typedef std::vector<MCFunction*> FunctionListTy;
+ typedef std::vector<std::unique_ptr<MCFunction>> FunctionListTy;
FunctionListTy Functions;
/// @}
@@ -87,7 +87,7 @@ class MCModule {
friend class MCObjectDisassembler;
public:
- MCModule() : Entrypoint(0) { }
+ MCModule();
~MCModule();
/// \name Create a new MCAtom covering the specified offset range.
Modified: llvm/trunk/lib/MC/MCModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCModule.cpp?rev=206244&r1=206243&r2=206244&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCModule.cpp (original)
+++ llvm/trunk/lib/MC/MCModule.cpp Tue Apr 15 00:15:19 2014
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/STLExtras.h"
#include "llvm/MC/MCModule.h"
#include "llvm/MC/MCAtom.h"
#include "llvm/MC/MCFunction.h"
@@ -99,8 +100,9 @@ MCAtom *MCModule::findFirstAtomAfter(uin
}
MCFunction *MCModule::createFunction(StringRef Name) {
- Functions.push_back(new MCFunction(Name, this));
- return Functions.back();
+ std::unique_ptr<MCFunction> MCF(new MCFunction(Name, this));
+ Functions.push_back(std::move(MCF));
+ return Functions.back().get();
}
static bool CompBBToAtom(MCBasicBlock *BB, const MCTextAtom *Atom) {
@@ -130,13 +132,11 @@ void MCModule::trackBBForAtom(const MCTe
BBsByAtom.insert(I, BB);
}
+MCModule::MCModule() : Entrypoint(0) { }
+
MCModule::~MCModule() {
for (AtomListTy::iterator AI = atom_begin(),
AE = atom_end();
AI != AE; ++AI)
delete *AI;
- for (FunctionListTy::iterator FI = func_begin(),
- FE = func_end();
- FI != FE; ++FI)
- delete *FI;
}
Modified: llvm/trunk/lib/MC/MCModuleYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCModuleYAML.cpp?rev=206244&r1=206243&r2=206244&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCModuleYAML.cpp (original)
+++ llvm/trunk/lib/MC/MCModuleYAML.cpp Tue Apr 15 00:15:19 2014
@@ -278,7 +278,7 @@ class MCModule2YAML {
const MCModule &MCM;
MCModuleYAML::Module YAMLModule;
void dumpAtom(const MCAtom *MCA);
- void dumpFunction(const MCFunction *MCF);
+ void dumpFunction(const MCFunction &MCF);
void dumpBasicBlock(const MCBasicBlock *MCBB);
public:
@@ -302,7 +302,7 @@ MCModule2YAML::MCModule2YAML(const MCMod
dumpAtom(*AI);
for (MCModule::const_func_iterator FI = MCM.func_begin(), FE = MCM.func_end();
FI != FE; ++FI)
- dumpFunction(*FI);
+ dumpFunction(**FI);
}
void MCModule2YAML::dumpAtom(const MCAtom *MCA) {
@@ -330,11 +330,11 @@ void MCModule2YAML::dumpAtom(const MCAto
}
}
-void MCModule2YAML::dumpFunction(const MCFunction *MCF) {
+void MCModule2YAML::dumpFunction(const MCFunction &MCF) {
YAMLModule.Functions.resize(YAMLModule.Functions.size() + 1);
MCModuleYAML::Function &F = YAMLModule.Functions.back();
- F.Name = MCF->getName();
- for (MCFunction::const_iterator BBI = MCF->begin(), BBE = MCF->end();
+ F.Name = MCF.getName();
+ for (MCFunction::const_iterator BBI = MCF.begin(), BBE = MCF.end();
BBI != BBE; ++BBI) {
const MCBasicBlock &MCBB = **BBI;
F.BasicBlocks.resize(F.BasicBlocks.size() + 1);
Modified: llvm/trunk/lib/MC/MCObjectDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectDisassembler.cpp?rev=206244&r1=206243&r2=206244&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectDisassembler.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectDisassembler.cpp Tue Apr 15 00:15:19 2014
@@ -480,7 +480,7 @@ MCObjectDisassembler::createFunction(MCM
continue;
// FIXME: MCModule should provide a findFunctionByAddr()
if ((*FI)->getEntryBlock()->getInsts()->getBeginAddr() == BeginAddr)
- return *FI;
+ return FI->get();
}
// Finally, just create a new one.
More information about the llvm-commits
mailing list