mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-13 08:26:02 +00:00
Don't leak memory like a seive
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2185 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -136,7 +136,10 @@ public:
|
|||||||
LeftChild = RightChild = Parent = 0;
|
LeftChild = RightChild = Parent = 0;
|
||||||
opLabel = InvalidOp;
|
opLabel = InvalidOp;
|
||||||
}
|
}
|
||||||
virtual ~InstrTreeNode() {}
|
virtual ~InstrTreeNode() {
|
||||||
|
delete LeftChild;
|
||||||
|
delete RightChild;
|
||||||
|
}
|
||||||
|
|
||||||
InstrTreeNodeType getNodeType () const { return treeNodeType; }
|
InstrTreeNodeType getNodeType () const { return treeNodeType; }
|
||||||
|
|
||||||
|
@@ -17,9 +17,6 @@
|
|||||||
// and (2) O and I are part of the same basic block,
|
// and (2) O and I are part of the same basic block,
|
||||||
// and (3) O has only a single use, viz., I.
|
// and (3) O has only a single use, viz., I.
|
||||||
//
|
//
|
||||||
// History:
|
|
||||||
// 6/28/01 - Vikram Adve - Created
|
|
||||||
//
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "llvm/CodeGen/InstrForest.h"
|
#include "llvm/CodeGen/InstrForest.h"
|
||||||
@@ -27,7 +24,6 @@
|
|||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/iTerminators.h"
|
#include "llvm/iTerminators.h"
|
||||||
#include "llvm/iMemory.h"
|
#include "llvm/iMemory.h"
|
||||||
#include "llvm/iPHINode.h"
|
|
||||||
#include "llvm/ConstantVals.h"
|
#include "llvm/ConstantVals.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.h"
|
#include "llvm/CodeGen/MachineInstr.h"
|
||||||
@@ -192,16 +188,14 @@ InstrForest::InstrForest(Function *F)
|
|||||||
{
|
{
|
||||||
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
|
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
|
||||||
BasicBlock *BB = *FI;
|
BasicBlock *BB = *FI;
|
||||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
|
for_each(BB->begin(), BB->end(),
|
||||||
buildTreeForInstruction(*I);
|
bind_obj(this, &InstrForest::buildTreeForInstruction));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InstrForest::~InstrForest()
|
InstrForest::~InstrForest()
|
||||||
{
|
{
|
||||||
for (std::hash_map<const Instruction*,InstructionNode*>::iterator I=begin();
|
for_each(treeRoots.begin(), treeRoots.end(), deleter<InstructionNode>);
|
||||||
I != end(); ++I)
|
|
||||||
delete I->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -282,11 +276,8 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
|
|||||||
// if a fixed array is too small.
|
// if a fixed array is too small.
|
||||||
//
|
//
|
||||||
int numChildren = 0;
|
int numChildren = 0;
|
||||||
const unsigned int MAX_CHILD = 8;
|
|
||||||
static InstrTreeNode *fixedChildArray[MAX_CHILD];
|
|
||||||
InstrTreeNode **childArray =
|
InstrTreeNode **childArray =
|
||||||
(instr->getNumOperands() > MAX_CHILD)
|
(InstrTreeNode **)alloca(instr->getNumOperands()*sizeof(InstrTreeNode *));
|
||||||
? new (InstrTreeNode*)[instr->getNumOperands()] : fixedChildArray;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Walk the operands of the instruction
|
// Walk the operands of the instruction
|
||||||
@@ -329,7 +320,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
|
|||||||
InstrTreeNode* opTreeNode;
|
InstrTreeNode* opTreeNode;
|
||||||
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
|
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
|
||||||
cast<Instruction>(operand)->getParent() == instr->getParent() &&
|
cast<Instruction>(operand)->getParent() == instr->getParent() &&
|
||||||
!isa<PHINode>(instr) &&
|
instr->getOpcode() != Instruction::PHINode &&
|
||||||
instr->getOpcode() != Instruction::Call)
|
instr->getOpcode() != Instruction::Call)
|
||||||
{
|
{
|
||||||
// Recursively create a treeNode for it.
|
// Recursively create a treeNode for it.
|
||||||
@@ -394,9 +385,5 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
|
|||||||
setRightChild(parent, childArray[numChildren - 1]);
|
setRightChild(parent, childArray[numChildren - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (childArray != fixedChildArray)
|
|
||||||
delete [] childArray;
|
|
||||||
|
|
||||||
return treeNode;
|
return treeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,9 +17,6 @@
|
|||||||
// and (2) O and I are part of the same basic block,
|
// and (2) O and I are part of the same basic block,
|
||||||
// and (3) O has only a single use, viz., I.
|
// and (3) O has only a single use, viz., I.
|
||||||
//
|
//
|
||||||
// History:
|
|
||||||
// 6/28/01 - Vikram Adve - Created
|
|
||||||
//
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "llvm/CodeGen/InstrForest.h"
|
#include "llvm/CodeGen/InstrForest.h"
|
||||||
@@ -27,7 +24,6 @@
|
|||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/iTerminators.h"
|
#include "llvm/iTerminators.h"
|
||||||
#include "llvm/iMemory.h"
|
#include "llvm/iMemory.h"
|
||||||
#include "llvm/iPHINode.h"
|
|
||||||
#include "llvm/ConstantVals.h"
|
#include "llvm/ConstantVals.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.h"
|
#include "llvm/CodeGen/MachineInstr.h"
|
||||||
@@ -192,16 +188,14 @@ InstrForest::InstrForest(Function *F)
|
|||||||
{
|
{
|
||||||
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
|
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
|
||||||
BasicBlock *BB = *FI;
|
BasicBlock *BB = *FI;
|
||||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
|
for_each(BB->begin(), BB->end(),
|
||||||
buildTreeForInstruction(*I);
|
bind_obj(this, &InstrForest::buildTreeForInstruction));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InstrForest::~InstrForest()
|
InstrForest::~InstrForest()
|
||||||
{
|
{
|
||||||
for (std::hash_map<const Instruction*,InstructionNode*>::iterator I=begin();
|
for_each(treeRoots.begin(), treeRoots.end(), deleter<InstructionNode>);
|
||||||
I != end(); ++I)
|
|
||||||
delete I->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -282,11 +276,8 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
|
|||||||
// if a fixed array is too small.
|
// if a fixed array is too small.
|
||||||
//
|
//
|
||||||
int numChildren = 0;
|
int numChildren = 0;
|
||||||
const unsigned int MAX_CHILD = 8;
|
|
||||||
static InstrTreeNode *fixedChildArray[MAX_CHILD];
|
|
||||||
InstrTreeNode **childArray =
|
InstrTreeNode **childArray =
|
||||||
(instr->getNumOperands() > MAX_CHILD)
|
(InstrTreeNode **)alloca(instr->getNumOperands()*sizeof(InstrTreeNode *));
|
||||||
? new (InstrTreeNode*)[instr->getNumOperands()] : fixedChildArray;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Walk the operands of the instruction
|
// Walk the operands of the instruction
|
||||||
@@ -329,7 +320,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
|
|||||||
InstrTreeNode* opTreeNode;
|
InstrTreeNode* opTreeNode;
|
||||||
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
|
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
|
||||||
cast<Instruction>(operand)->getParent() == instr->getParent() &&
|
cast<Instruction>(operand)->getParent() == instr->getParent() &&
|
||||||
!isa<PHINode>(instr) &&
|
instr->getOpcode() != Instruction::PHINode &&
|
||||||
instr->getOpcode() != Instruction::Call)
|
instr->getOpcode() != Instruction::Call)
|
||||||
{
|
{
|
||||||
// Recursively create a treeNode for it.
|
// Recursively create a treeNode for it.
|
||||||
@@ -394,9 +385,5 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
|
|||||||
setRightChild(parent, childArray[numChildren - 1]);
|
setRightChild(parent, childArray[numChildren - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (childArray != fixedChildArray)
|
|
||||||
delete [] childArray;
|
|
||||||
|
|
||||||
return treeNode;
|
return treeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user