mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
Added MachineFunction parent* to MachineBasicBlock. Customized ilist template
to set the parent when a MachineBasicBlock is added to a MachineFunction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -64,10 +64,11 @@ public:
|
|||||||
std::vector<MachineBasicBlock *> Predecessors;
|
std::vector<MachineBasicBlock *> Predecessors;
|
||||||
std::vector<MachineBasicBlock *> Successors;
|
std::vector<MachineBasicBlock *> Successors;
|
||||||
int Number;
|
int Number;
|
||||||
|
MachineFunction *Parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb),
|
MachineBasicBlock(const BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb),
|
||||||
Number(-1) {
|
Number(-1), Parent(0) {
|
||||||
Insts.parent = this;
|
Insts.parent = this;
|
||||||
}
|
}
|
||||||
~MachineBasicBlock() {}
|
~MachineBasicBlock() {}
|
||||||
@ -79,8 +80,8 @@ public:
|
|||||||
|
|
||||||
/// getParent - Return the MachineFunction containing this basic block.
|
/// getParent - Return the MachineFunction containing this basic block.
|
||||||
///
|
///
|
||||||
const MachineFunction *getParent() const;
|
const MachineFunction *getParent() const { return Parent; }
|
||||||
MachineFunction *getParent();
|
MachineFunction *getParent() { return Parent; }
|
||||||
|
|
||||||
typedef ilist<MachineInstr>::iterator iterator;
|
typedef ilist<MachineInstr>::iterator iterator;
|
||||||
typedef ilist<MachineInstr>::const_iterator const_iterator;
|
typedef ilist<MachineInstr>::const_iterator const_iterator;
|
||||||
|
@ -23,6 +23,39 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
// ilist_traits
|
||||||
|
template <>
|
||||||
|
class ilist_traits<MachineBasicBlock> {
|
||||||
|
// this is only set by the MachineFunction owning the ilist
|
||||||
|
friend class MachineFunction;
|
||||||
|
MachineFunction* parent;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ilist_traits<MachineBasicBlock>() : parent(0) { }
|
||||||
|
|
||||||
|
static MachineBasicBlock* getPrev(MachineBasicBlock* N) { return N->Prev; }
|
||||||
|
static MachineBasicBlock* getNext(MachineBasicBlock* N) { return N->Next; }
|
||||||
|
|
||||||
|
static const MachineBasicBlock*
|
||||||
|
getPrev(const MachineBasicBlock* N) { return N->Prev; }
|
||||||
|
|
||||||
|
static const MachineBasicBlock*
|
||||||
|
getNext(const MachineBasicBlock* N) { return N->Next; }
|
||||||
|
|
||||||
|
static void setPrev(MachineBasicBlock* N, MachineBasicBlock* prev) { N->Prev = prev; }
|
||||||
|
static void setNext(MachineBasicBlock* N, MachineBasicBlock* next) { N->Next = next; }
|
||||||
|
|
||||||
|
static MachineBasicBlock* createNode();
|
||||||
|
void addNodeToList(MachineBasicBlock* N);
|
||||||
|
void removeNodeFromList(MachineBasicBlock* N);
|
||||||
|
void transferNodesFromList(
|
||||||
|
iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
|
||||||
|
ilist_iterator<MachineBasicBlock> first,
|
||||||
|
ilist_iterator<MachineBasicBlock> last);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Function;
|
class Function;
|
||||||
class TargetMachine;
|
class TargetMachine;
|
||||||
class SSARegMap;
|
class SSARegMap;
|
||||||
|
@ -20,29 +20,25 @@
|
|||||||
#include "Support/LeakDetector.h"
|
#include "Support/LeakDetector.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
const MachineFunction *MachineBasicBlock::getParent() const {
|
|
||||||
// Get the parent by getting the Function parent of the basic block, and
|
|
||||||
// getting the MachineFunction from it.
|
|
||||||
return &MachineFunction::get(getBasicBlock()->getParent());
|
|
||||||
}
|
|
||||||
|
|
||||||
MachineFunction *MachineBasicBlock::getParent() {
|
|
||||||
// Get the parent by getting the Function parent of the basic block, and
|
|
||||||
// getting the MachineFunction from it.
|
|
||||||
return &MachineFunction::get(getBasicBlock()->getParent());
|
|
||||||
}
|
|
||||||
|
|
||||||
// MBBs start out as #-1. When a MBB is added to a MachineFunction, it
|
// MBBs start out as #-1. When a MBB is added to a MachineFunction, it
|
||||||
// gets the next available unique MBB number. If it is removed from a
|
// gets the next available unique MBB number. If it is removed from a
|
||||||
// MachineFunction, it goes back to being #-1.
|
// MachineFunction, it goes back to being #-1.
|
||||||
void ilist_traits<MachineBasicBlock>::addNodeToList (MachineBasicBlock* N)
|
void ilist_traits<MachineBasicBlock>::addNodeToList (MachineBasicBlock* N)
|
||||||
{
|
{
|
||||||
N->Number = N->getParent ()->getNextMBBNumber ();
|
assert(N->Parent == 0 && "machine instruction already in a basic block");
|
||||||
|
N->Parent = parent;
|
||||||
|
N->Number = parent->getNextMBBNumber();
|
||||||
|
LeakDetector::removeGarbageObject(N);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ilist_traits<MachineBasicBlock>::removeNodeFromList (MachineBasicBlock* N)
|
void ilist_traits<MachineBasicBlock>::removeNodeFromList (MachineBasicBlock* N)
|
||||||
{
|
{
|
||||||
|
assert(N->Parent != 0 && "machine instruction not in a basic block");
|
||||||
|
N->Parent = 0;
|
||||||
N->Number = -1;
|
N->Number = -1;
|
||||||
|
LeakDetector::addGarbageObject(N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,7 +89,12 @@ void MachineBasicBlock::dump() const
|
|||||||
|
|
||||||
void MachineBasicBlock::print(std::ostream &OS) const
|
void MachineBasicBlock::print(std::ostream &OS) const
|
||||||
{
|
{
|
||||||
|
if(!getParent()) {
|
||||||
|
OS << "Can't print out MachineBasicBlock because parent MachineFunction is null\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
const BasicBlock *LBB = getBasicBlock();
|
const BasicBlock *LBB = getBasicBlock();
|
||||||
|
if(LBB)
|
||||||
OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
|
OS << "\n" << LBB->getName() << " (" << (const void*)LBB << "):\n";
|
||||||
for (const_iterator I = begin(); I != end(); ++I) {
|
for (const_iterator I = begin(); I != end(); ++I) {
|
||||||
OS << "\t";
|
OS << "\t";
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "llvm/Target/TargetFrameInfo.h"
|
#include "llvm/Target/TargetFrameInfo.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/iOther.h"
|
#include "llvm/iOther.h"
|
||||||
|
#include "Support/LeakDetector.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static AnnotationID MF_AID(
|
static AnnotationID MF_AID(
|
||||||
@ -84,6 +86,22 @@ FunctionPass *llvm::createMachineCodeDeleter() {
|
|||||||
//===---------------------------------------------------------------------===//
|
//===---------------------------------------------------------------------===//
|
||||||
// MachineFunction implementation
|
// MachineFunction implementation
|
||||||
//===---------------------------------------------------------------------===//
|
//===---------------------------------------------------------------------===//
|
||||||
|
MachineBasicBlock* ilist_traits<MachineBasicBlock>::createNode()
|
||||||
|
{
|
||||||
|
MachineBasicBlock* dummy = new MachineBasicBlock();
|
||||||
|
LeakDetector::removeGarbageObject(dummy);
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ilist_traits<MachineBasicBlock>::transferNodesFromList(
|
||||||
|
iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
|
||||||
|
ilist_iterator<MachineBasicBlock> first,
|
||||||
|
ilist_iterator<MachineBasicBlock> last)
|
||||||
|
{
|
||||||
|
if (parent != toList.parent)
|
||||||
|
for (; first != last; ++first)
|
||||||
|
first->Parent = toList.parent;
|
||||||
|
}
|
||||||
|
|
||||||
MachineFunction::MachineFunction(const Function *F,
|
MachineFunction::MachineFunction(const Function *F,
|
||||||
const TargetMachine &TM)
|
const TargetMachine &TM)
|
||||||
@ -92,6 +110,7 @@ MachineFunction::MachineFunction(const Function *F,
|
|||||||
MFInfo = new MachineFunctionInfo(*this);
|
MFInfo = new MachineFunctionInfo(*this);
|
||||||
FrameInfo = new MachineFrameInfo();
|
FrameInfo = new MachineFrameInfo();
|
||||||
ConstantPool = new MachineConstantPool();
|
ConstantPool = new MachineConstantPool();
|
||||||
|
BasicBlocks.parent = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
MachineFunction::~MachineFunction() {
|
MachineFunction::~MachineFunction() {
|
||||||
|
Reference in New Issue
Block a user