[llvm-commits] [llvm] r171599 - in /llvm/trunk: include/llvm/CodeGen/MachineInstr.h lib/CodeGen/MachineFunction.cpp lib/CodeGen/MachineInstr.cpp lib/CodeGen/MachineRegisterInfo.cpp
Rafael EspĂndola
rafael.espindola at gmail.com
Tue Jan 8 11:33:59 PST 2013
> Don't call destructors on MachineInstr and MachineOperand.
>
> The series of patches leading up to this one makes llc -O0 run 8% faster.
Awesome!
> When deallocating a MachineFunction, there is no need to visit all
> MachineInstr and MachineOperand objects to deallocate them. All their
> memory come from a BumpPtrAllocator that is about to be purged, and they
> have empty destructors anyway.
>
> This only applies when deallocating the MachineFunction.
> DeleteMachineInstr() should still be used to recycle MI memory during
> the codegen passes.
>
> Remove the LeakDetector support for MachineInstr. I've never seen it
> used before, and now it definitely doesn't work. With this patch, leaked
> MachineInstrs would be much less of a problem since all of their memory
> will be reclaimed by ~MachineFunction().
>
> Modified:
> llvm/trunk/include/llvm/CodeGen/MachineInstr.h
> llvm/trunk/lib/CodeGen/MachineFunction.cpp
> llvm/trunk/lib/CodeGen/MachineInstr.cpp
> llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=171599&r1=171598&r2=171599&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Fri Jan 4 23:05:51 2013
> @@ -43,6 +43,10 @@
> //===----------------------------------------------------------------------===//
> /// MachineInstr - Representation of each machine instruction.
> ///
> +/// This class isn't a POD type, but it must have a trivial destructor. When a
> +/// MachineFunction is deleted, all the contained MachineInstrs are deallocated
> +/// without having their destructor called.
> +///
> class MachineInstr : public ilist_node<MachineInstr> {
> public:
> typedef MachineMemOperand **mmo_iterator;
> @@ -90,6 +94,8 @@
>
> MachineInstr(const MachineInstr&) LLVM_DELETED_FUNCTION;
> void operator=(const MachineInstr&) LLVM_DELETED_FUNCTION;
> + // Use MachineFunction::DeleteMachineInstr() instead.
> + ~MachineInstr() LLVM_DELETED_FUNCTION;
>
> // Intrusive list support
> friend struct ilist_traits<MachineInstr>;
> @@ -106,8 +112,6 @@
> MachineInstr(MachineFunction&, const MCInstrDesc &MCID,
> const DebugLoc dl, bool NoImp = false);
>
> - ~MachineInstr();
> -
> // MachineInstrs are pool-allocated and owned by MachineFunction.
> friend class MachineFunction;
>
>
> Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=171599&r1=171598&r2=171599&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Fri Jan 4 23:05:51 2013
> @@ -76,7 +76,13 @@
> }
>
> MachineFunction::~MachineFunction() {
> - BasicBlocks.clear();
> + // Don't call destructors on MachineInstr and MachineOperand. All of their
> + // memory comes from the BumpPtrAllocator which is about to be purged.
> + //
> + // Do call MachineBasicBlock destructors, it contains std::vectors.
> + for (iterator I = begin(), E = end(); I != E; I = BasicBlocks.erase(I))
> + I->Insts.clearAndLeakNodesUnsafely();
> +
> InstructionRecycler.clear(Allocator);
> OperandRecycler.clear(Allocator);
> BasicBlockRecycler.clear(Allocator);
> @@ -176,15 +182,17 @@
>
> /// DeleteMachineInstr - Delete the given MachineInstr.
> ///
> +/// This function also serves as the MachineInstr destructor - the real
> +/// ~MachineInstr() destructor must be empty.
> void
> MachineFunction::DeleteMachineInstr(MachineInstr *MI) {
> // Strip it for parts. The operand array and the MI object itself are
> // independently recyclable.
> if (MI->Operands)
> deallocateOperandArray(MI->CapOperands, MI->Operands);
> - MI->Operands = 0;
> - MI->NumOperands = 0;
> - MI->~MachineInstr();
> + // Don't call ~MachineInstr() which must be trivial anyway because
> + // ~MachineFunction drops whole lists of MachineInstrs wihout calling their
> + // destructors.
> InstructionRecycler.Deallocate(Allocator, MI);
> }
>
>
> Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=171599&r1=171598&r2=171599&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Fri Jan 4 23:05:51 2013
> @@ -35,7 +35,6 @@
> #include "llvm/MC/MCSymbol.h"
> #include "llvm/Support/Debug.h"
> #include "llvm/Support/ErrorHandling.h"
> -#include "llvm/Support/LeakDetector.h"
> #include "llvm/Support/MathExtras.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/Target/TargetInstrInfo.h"
> @@ -544,8 +543,6 @@
>
> if (!NoImp)
> addImplicitDefUseOperands(MF);
> - // Make sure that we get added to a machine basicblock
> - LeakDetector::addGarbageObject(this);
> }
>
> /// MachineInstr ctor - Copies MachineInstr arg exactly
> @@ -558,28 +555,12 @@
> CapOperands = OperandCapacity::get(MI.getNumOperands());
> Operands = MF.allocateOperandArray(CapOperands);
>
> - // Add operands
> + // Copy operands.
> for (unsigned i = 0; i != MI.getNumOperands(); ++i)
> addOperand(MF, MI.getOperand(i));
>
> // Copy all the sensible flags.
> setFlags(MI.Flags);
> -
> - // Set parent to null.
> - Parent = 0;
> -
> - LeakDetector::addGarbageObject(this);
> -}
> -
> -MachineInstr::~MachineInstr() {
> - LeakDetector::removeGarbageObject(this);
> -#ifndef NDEBUG
> - for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
> - assert(Operands[i].ParentMI == this && "ParentMI mismatch!");
> - assert((!Operands[i].isReg() || !Operands[i].isOnRegUseList()) &&
> - "Reg operand def/use list corrupted");
> - }
> -#endif
> }
>
> /// getRegInfo - If this instruction is embedded into a MachineFunction,
>
> Modified: llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp?rev=171599&r1=171598&r2=171599&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp Fri Jan 4 23:05:51 2013
> @@ -30,12 +30,6 @@
> }
>
> MachineRegisterInfo::~MachineRegisterInfo() {
> -#ifndef NDEBUG
> - clearVirtRegs();
> - for (unsigned i = 0, e = TRI->getNumRegs(); i != e; ++i)
> - assert(!PhysRegUseDefLists[i] &&
> - "PhysRegUseDefLists has entries after all instructions are deleted");
> -#endif
> delete [] PhysRegUseDefLists;
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list