[llvm] r188875 - MC CFG: Keep pointer to parent MCModule in created MCFunctions.

Ahmed Bougacha ahmed.bougacha at gmail.com
Wed Aug 21 00:27:55 PDT 2013


Author: ab
Date: Wed Aug 21 02:27:55 2013
New Revision: 188875

URL: http://llvm.org/viewvc/llvm-project?rev=188875&view=rev
Log:
MC CFG: Keep pointer to parent MCModule in created MCFunctions.

Also, drive-by cleaning around createFunction.

Modified:
    llvm/trunk/include/llvm/MC/MCFunction.h
    llvm/trunk/include/llvm/MC/MCModule.h
    llvm/trunk/lib/MC/MCFunction.cpp
    llvm/trunk/lib/MC/MCModule.cpp

Modified: llvm/trunk/include/llvm/MC/MCFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCFunction.h?rev=188875&r1=188874&r2=188875&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCFunction.h (original)
+++ llvm/trunk/include/llvm/MC/MCFunction.h Wed Aug 21 02:27:55 2013
@@ -74,21 +74,22 @@ public:
 };
 
 /// \brief Represents a function in machine code, containing MCBasicBlocks.
-/// MCFunctions are created using MCModule::createFunction.
+/// MCFunctions are created by MCModule.
 class MCFunction {
   MCFunction           (const MCFunction&) LLVM_DELETED_FUNCTION;
   MCFunction& operator=(const MCFunction&) LLVM_DELETED_FUNCTION;
 
   std::string Name;
+  MCModule *ParentModule;
   typedef std::vector<MCBasicBlock*> BasicBlockListTy;
   BasicBlockListTy Blocks;
 
   // MCModule owns the function.
   friend class MCModule;
-  MCFunction(StringRef Name);
-public:
+  MCFunction(StringRef Name, MCModule *Parent);
   ~MCFunction();
 
+public:
   /// \brief Create an MCBasicBlock backed by Insts and add it to this function.
   /// \param Insts Sequence of straight-line code backing the basic block.
   /// \returns The newly created basic block.

Modified: llvm/trunk/include/llvm/MC/MCModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCModule.h?rev=188875&r1=188874&r2=188875&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCModule.h (original)
+++ llvm/trunk/include/llvm/MC/MCModule.h Wed Aug 21 02:27:55 2013
@@ -23,6 +23,7 @@
 namespace llvm {
 
 class MCAtom;
+class MCBasicBlock;
 class MCDataAtom;
 class MCFunction;
 class MCObjectDisassembler;
@@ -88,8 +89,8 @@ public:
         atom_iterator atom_end()         { return Atoms.end(); }
   /// @}
 
-  /// \name Create a new MCFunction.
-  MCFunction *createFunction(const StringRef &Name);
+  /// \brief Create a new MCFunction.
+  MCFunction *createFunction(StringRef Name);
 
   /// \name Access to the owned function list.
   /// @{

Modified: llvm/trunk/lib/MC/MCFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCFunction.cpp?rev=188875&r1=188874&r2=188875&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCFunction.cpp (original)
+++ llvm/trunk/lib/MC/MCFunction.cpp Wed Aug 21 02:27:55 2013
@@ -9,15 +9,15 @@
 
 #include "llvm/MC/MCFunction.h"
 #include "llvm/MC/MCAtom.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/MC/MCModule.h"
 #include <algorithm>
 
 using namespace llvm;
 
 // MCFunction
 
-MCFunction::MCFunction(StringRef Name)
-  : Name(Name)
+MCFunction::MCFunction(StringRef Name, MCModule *Parent)
+  : Name(Name), ParentModule(Parent)
 {}
 
 MCFunction::~MCFunction() {

Modified: llvm/trunk/lib/MC/MCModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCModule.cpp?rev=188875&r1=188874&r2=188875&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCModule.cpp (original)
+++ llvm/trunk/lib/MC/MCModule.cpp Wed Aug 21 02:27:55 2013
@@ -54,9 +54,13 @@ void MCModule::remap(MCAtom *Atom, uint6
   assert(*I == Atom && "Previous atom mapping was invalid!");
   Atoms.erase(I);
 
+  // FIXME: special case NewBegin == Atom->Begin
+
   // Insert the new mapping.
   AtomListTy::iterator NewI = std::lower_bound(atom_begin(), atom_end(),
                                                NewBegin, AtomComp);
+  assert((NewI == atom_end() || (*NewI)->getBeginAddr() > Atom->End)
+         && "Offset range already occupied!");
   Atoms.insert(NewI, Atom);
 
   // Update the atom internal bounds.
@@ -80,8 +84,8 @@ MCAtom *MCModule::findAtomContaining(uin
   return 0;
 }
 
-MCFunction *MCModule::createFunction(const StringRef &Name) {
-  Functions.push_back(new MCFunction(Name));
+MCFunction *MCModule::createFunction(StringRef Name) {
+  Functions.push_back(new MCFunction(Name, this));
   return Functions.back();
 }
 





More information about the llvm-commits mailing list