aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-04-08 23:09:07 +0000
committerChris Lattner <sabre@nondot.org>2002-04-08 23:09:07 +0000
commit7884cd17aa830bc8d4af1c082cc2d1f7460ccf34 (patch)
tree5ab1e1ab72bca8ab373b3a46eb1ebb212bca6ebb
parent69a34cddaf00ebd4ffdcbda15db0333134298703 (diff)
Don't leak memory like a seive
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2185 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/InstrForest.h5
-rw-r--r--lib/CodeGen/InstrSelection/InstrForest.cpp23
-rw-r--r--lib/Target/SparcV9/InstrSelection/InstrForest.cpp23
3 files changed, 14 insertions, 37 deletions
diff --git a/include/llvm/CodeGen/InstrForest.h b/include/llvm/CodeGen/InstrForest.h
index ef5e2f9a06..86b59a6d4f 100644
--- a/include/llvm/CodeGen/InstrForest.h
+++ b/include/llvm/CodeGen/InstrForest.h
@@ -136,7 +136,10 @@ public:
LeftChild = RightChild = Parent = 0;
opLabel = InvalidOp;
}
- virtual ~InstrTreeNode() {}
+ virtual ~InstrTreeNode() {
+ delete LeftChild;
+ delete RightChild;
+ }
InstrTreeNodeType getNodeType () const { return treeNodeType; }
diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp
index 8fa8638a02..0934e7bbd5 100644
--- a/lib/CodeGen/InstrSelection/InstrForest.cpp
+++ b/lib/CodeGen/InstrSelection/InstrForest.cpp
@@ -17,9 +17,6 @@
// and (2) O and I are part of the same basic block,
// and (3) O has only a single use, viz., I.
//
-// History:
-// 6/28/01 - Vikram Adve - Created
-//
//---------------------------------------------------------------------------
#include "llvm/CodeGen/InstrForest.h"
@@ -27,7 +24,6 @@
#include "llvm/Function.h"
#include "llvm/iTerminators.h"
#include "llvm/iMemory.h"
-#include "llvm/iPHINode.h"
#include "llvm/ConstantVals.h"
#include "llvm/BasicBlock.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) {
BasicBlock *BB = *FI;
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
- buildTreeForInstruction(*I);
+ for_each(BB->begin(), BB->end(),
+ bind_obj(this, &InstrForest::buildTreeForInstruction));
}
}
InstrForest::~InstrForest()
{
- for (std::hash_map<const Instruction*,InstructionNode*>::iterator I=begin();
- I != end(); ++I)
- delete I->second;
+ for_each(treeRoots.begin(), treeRoots.end(), deleter<InstructionNode>);
}
void
@@ -282,11 +276,8 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
// if a fixed array is too small.
//
int numChildren = 0;
- const unsigned int MAX_CHILD = 8;
- static InstrTreeNode *fixedChildArray[MAX_CHILD];
InstrTreeNode **childArray =
- (instr->getNumOperands() > MAX_CHILD)
- ? new (InstrTreeNode*)[instr->getNumOperands()] : fixedChildArray;
+ (InstrTreeNode **)alloca(instr->getNumOperands()*sizeof(InstrTreeNode *));
//
// Walk the operands of the instruction
@@ -329,7 +320,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
InstrTreeNode* opTreeNode;
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
cast<Instruction>(operand)->getParent() == instr->getParent() &&
- !isa<PHINode>(instr) &&
+ instr->getOpcode() != Instruction::PHINode &&
instr->getOpcode() != Instruction::Call)
{
// Recursively create a treeNode for it.
@@ -394,9 +385,5 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
setRightChild(parent, childArray[numChildren - 1]);
}
- if (childArray != fixedChildArray)
- delete [] childArray;
-
return treeNode;
}
-
diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
index 8fa8638a02..0934e7bbd5 100644
--- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
+++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp
@@ -17,9 +17,6 @@
// and (2) O and I are part of the same basic block,
// and (3) O has only a single use, viz., I.
//
-// History:
-// 6/28/01 - Vikram Adve - Created
-//
//---------------------------------------------------------------------------
#include "llvm/CodeGen/InstrForest.h"
@@ -27,7 +24,6 @@
#include "llvm/Function.h"
#include "llvm/iTerminators.h"
#include "llvm/iMemory.h"
-#include "llvm/iPHINode.h"
#include "llvm/ConstantVals.h"
#include "llvm/BasicBlock.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) {
BasicBlock *BB = *FI;
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
- buildTreeForInstruction(*I);
+ for_each(BB->begin(), BB->end(),
+ bind_obj(this, &InstrForest::buildTreeForInstruction));
}
}
InstrForest::~InstrForest()
{
- for (std::hash_map<const Instruction*,InstructionNode*>::iterator I=begin();
- I != end(); ++I)
- delete I->second;
+ for_each(treeRoots.begin(), treeRoots.end(), deleter<InstructionNode>);
}
void
@@ -282,11 +276,8 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
// if a fixed array is too small.
//
int numChildren = 0;
- const unsigned int MAX_CHILD = 8;
- static InstrTreeNode *fixedChildArray[MAX_CHILD];
InstrTreeNode **childArray =
- (instr->getNumOperands() > MAX_CHILD)
- ? new (InstrTreeNode*)[instr->getNumOperands()] : fixedChildArray;
+ (InstrTreeNode **)alloca(instr->getNumOperands()*sizeof(InstrTreeNode *));
//
// Walk the operands of the instruction
@@ -329,7 +320,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
InstrTreeNode* opTreeNode;
if (isa<Instruction>(operand) && operand->use_size() == 1 &&
cast<Instruction>(operand)->getParent() == instr->getParent() &&
- !isa<PHINode>(instr) &&
+ instr->getOpcode() != Instruction::PHINode &&
instr->getOpcode() != Instruction::Call)
{
// Recursively create a treeNode for it.
@@ -394,9 +385,5 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
setRightChild(parent, childArray[numChildren - 1]);
}
- if (childArray != fixedChildArray)
- delete [] childArray;
-
return treeNode;
}
-