mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Remove redundancy and a level of indirection when creating machine operands
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28107 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
02597f3b88
commit
943b5e117f
@ -85,40 +85,7 @@ private:
|
|||||||
/// MO_GlobalAddress, MO_ExternalSym and MO_ConstantPoolIndex
|
/// MO_GlobalAddress, MO_ExternalSym and MO_ConstantPoolIndex
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
MachineOperand(int64_t ImmVal) : flags(0), opType(MO_Immediate) {
|
MachineOperand() {}
|
||||||
contents.immedVal = ImmVal;
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MachineOperand(unsigned Idx, MachineOperandType OpTy): flags(0), opType(OpTy){
|
|
||||||
contents.immedVal = Idx;
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MachineOperand(int Reg, MachineOperandType OpTy, UseType UseTy)
|
|
||||||
: flags(UseTy), opType(OpTy) {
|
|
||||||
contents.RegNo = Reg;
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MachineOperand(GlobalValue *V, int Offset = 0)
|
|
||||||
: flags(MachineOperand::Use), opType(MachineOperand::MO_GlobalAddress) {
|
|
||||||
contents.GV = V;
|
|
||||||
offset = Offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
MachineOperand(MachineBasicBlock *mbb)
|
|
||||||
: flags(0), opType(MO_MachineBasicBlock) {
|
|
||||||
contents.MBB = mbb;
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MachineOperand(const char *SymName, int Offset)
|
|
||||||
: flags(0), opType(MO_ExternalSymbol) {
|
|
||||||
contents.SymbolName = SymName;
|
|
||||||
offset = Offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MachineOperand(const MachineOperand &M) {
|
MachineOperand(const MachineOperand &M) {
|
||||||
*this = M;
|
*this = M;
|
||||||
@ -252,7 +219,7 @@ public:
|
|||||||
///
|
///
|
||||||
class MachineInstr {
|
class MachineInstr {
|
||||||
short Opcode; // the opcode
|
short Opcode; // the opcode
|
||||||
std::vector<MachineOperand> operands; // the operands
|
std::vector<MachineOperand> Operands; // the operands
|
||||||
MachineInstr* prev, *next; // links for our intrusive list
|
MachineInstr* prev, *next; // links for our intrusive list
|
||||||
MachineBasicBlock* parent; // pointer to the owning basic block
|
MachineBasicBlock* parent; // pointer to the owning basic block
|
||||||
|
|
||||||
@ -288,21 +255,21 @@ public:
|
|||||||
|
|
||||||
/// Access to explicit operands of the instruction.
|
/// Access to explicit operands of the instruction.
|
||||||
///
|
///
|
||||||
unsigned getNumOperands() const { return operands.size(); }
|
unsigned getNumOperands() const { return Operands.size(); }
|
||||||
|
|
||||||
const MachineOperand& getOperand(unsigned i) const {
|
const MachineOperand& getOperand(unsigned i) const {
|
||||||
assert(i < getNumOperands() && "getOperand() out of range!");
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
||||||
return operands[i];
|
return Operands[i];
|
||||||
}
|
}
|
||||||
MachineOperand& getOperand(unsigned i) {
|
MachineOperand& getOperand(unsigned i) {
|
||||||
assert(i < getNumOperands() && "getOperand() out of range!");
|
assert(i < getNumOperands() && "getOperand() out of range!");
|
||||||
return operands[i];
|
return Operands[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// clone - Create a copy of 'this' instruction that is identical in
|
/// clone - Create a copy of 'this' instruction that is identical in
|
||||||
/// all ways except the the instruction has no parent, prev, or next.
|
/// all ways except the the instruction has no parent, prev, or next.
|
||||||
MachineInstr* clone() const;
|
MachineInstr* clone() const { return new MachineInstr(*this); }
|
||||||
|
|
||||||
/// removeFromParent - This method unlinks 'this' from the containing basic
|
/// removeFromParent - This method unlinks 'this' from the containing basic
|
||||||
/// block, and returns it, but does not delete it.
|
/// block, and returns it, but does not delete it.
|
||||||
@ -322,70 +289,87 @@ public:
|
|||||||
friend std::ostream& operator<<(std::ostream& os, const MachineInstr& minstr);
|
friend std::ostream& operator<<(std::ostream& os, const MachineInstr& minstr);
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Accessors to add operands when building up machine instructions
|
// Accessors to add operands when building up machine instructions.
|
||||||
//
|
//
|
||||||
|
|
||||||
/// addRegOperand - Add a symbolic virtual register reference...
|
/// addRegOperand - Add a register operand.
|
||||||
///
|
///
|
||||||
void addRegOperand(int reg,
|
void addRegOperand(unsigned Reg,
|
||||||
MachineOperand::UseType UTy = MachineOperand::Use) {
|
MachineOperand::UseType UTy = MachineOperand::Use) {
|
||||||
assert(!OperandsComplete() &&
|
MachineOperand &Op = AddNewOperand();
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
Op.opType = MachineOperand::MO_Register;
|
||||||
operands.push_back(
|
Op.flags = UTy;
|
||||||
MachineOperand(reg, MachineOperand::MO_Register, UTy));
|
Op.contents.RegNo = Reg;
|
||||||
|
Op.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// addImmOperand - Add a zero extended constant argument to the
|
/// addImmOperand - Add a zero extended constant argument to the
|
||||||
/// machine instruction.
|
/// machine instruction.
|
||||||
///
|
///
|
||||||
void addImmOperand(int64_t Val) {
|
void addImmOperand(int64_t Val) {
|
||||||
assert(!OperandsComplete() &&
|
MachineOperand &Op = AddNewOperand();
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
Op.opType = MachineOperand::MO_Immediate;
|
||||||
operands.push_back(MachineOperand(Val));
|
Op.flags = 0;
|
||||||
|
Op.contents.immedVal = Val;
|
||||||
|
Op.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMachineBasicBlockOperand(MachineBasicBlock *MBB) {
|
void addMachineBasicBlockOperand(MachineBasicBlock *MBB) {
|
||||||
assert(!OperandsComplete() &&
|
MachineOperand &Op = AddNewOperand();
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
Op.opType = MachineOperand::MO_MachineBasicBlock;
|
||||||
operands.push_back(MachineOperand(MBB));
|
Op.flags = 0;
|
||||||
|
Op.contents.MBB = MBB;
|
||||||
|
Op.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// addFrameIndexOperand - Add an abstract frame index to the instruction
|
/// addFrameIndexOperand - Add an abstract frame index to the instruction
|
||||||
///
|
///
|
||||||
void addFrameIndexOperand(unsigned Idx) {
|
void addFrameIndexOperand(unsigned Idx) {
|
||||||
assert(!OperandsComplete() &&
|
MachineOperand &Op = AddNewOperand();
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
Op.opType = MachineOperand::MO_FrameIndex;
|
||||||
operands.push_back(MachineOperand(Idx, MachineOperand::MO_FrameIndex));
|
Op.flags = 0;
|
||||||
|
Op.contents.immedVal = Idx;
|
||||||
|
Op.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// addConstantPoolndexOperand - Add a constant pool object index to the
|
/// addConstantPoolndexOperand - Add a constant pool object index to the
|
||||||
/// instruction.
|
/// instruction.
|
||||||
///
|
///
|
||||||
void addConstantPoolIndexOperand(unsigned I, int Offset=0) {
|
void addConstantPoolIndexOperand(unsigned Idx, int Offset) {
|
||||||
assert(!OperandsComplete() &&
|
MachineOperand &Op = AddNewOperand();
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
Op.opType = MachineOperand::MO_ConstantPoolIndex;
|
||||||
operands.push_back(MachineOperand(I, MachineOperand::MO_ConstantPoolIndex));
|
Op.flags = 0;
|
||||||
|
Op.contents.immedVal = Idx;
|
||||||
|
Op.offset = Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// addJumpTableIndexOperand - Add a jump table object index to the
|
/// addJumpTableIndexOperand - Add a jump table object index to the
|
||||||
/// instruction.
|
/// instruction.
|
||||||
///
|
///
|
||||||
void addJumpTableIndexOperand(unsigned I) {
|
void addJumpTableIndexOperand(unsigned Idx) {
|
||||||
assert(!OperandsComplete() &&
|
MachineOperand &Op = AddNewOperand();
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
Op.opType = MachineOperand::MO_JumpTableIndex;
|
||||||
operands.push_back(MachineOperand(I, MachineOperand::MO_JumpTableIndex));
|
Op.flags = 0;
|
||||||
|
Op.contents.immedVal = Idx;
|
||||||
|
Op.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addGlobalAddressOperand(GlobalValue *GV, int Offset) {
|
void addGlobalAddressOperand(GlobalValue *GV, int Offset) {
|
||||||
assert(!OperandsComplete() &&
|
MachineOperand &Op = AddNewOperand();
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
Op.opType = MachineOperand::MO_GlobalAddress;
|
||||||
operands.push_back(MachineOperand(GV, Offset));
|
Op.flags = 0;
|
||||||
|
Op.contents.GV = GV;
|
||||||
|
Op.offset = Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// addExternalSymbolOperand - Add an external symbol operand to this instr
|
/// addExternalSymbolOperand - Add an external symbol operand to this instr
|
||||||
///
|
///
|
||||||
void addExternalSymbolOperand(const char *SymName) {
|
void addExternalSymbolOperand(const char *SymName) {
|
||||||
operands.push_back(MachineOperand(SymName, 0));
|
MachineOperand &Op = AddNewOperand();
|
||||||
|
Op.opType = MachineOperand::MO_ExternalSymbol;
|
||||||
|
Op.flags = 0;
|
||||||
|
Op.contents.SymbolName = SymName;
|
||||||
|
Op.offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
@ -400,7 +384,14 @@ public:
|
|||||||
/// fewer operand than it started with.
|
/// fewer operand than it started with.
|
||||||
///
|
///
|
||||||
void RemoveOperand(unsigned i) {
|
void RemoveOperand(unsigned i) {
|
||||||
operands.erase(operands.begin()+i);
|
Operands.erase(Operands.begin()+i);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
MachineOperand &AddNewOperand() {
|
||||||
|
assert(!OperandsComplete() &&
|
||||||
|
"Trying to add an operand to a machine instr that is already done!");
|
||||||
|
Operands.push_back(MachineOperand());
|
||||||
|
return Operands.back();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
MachineInstr::MachineInstr(short opcode, unsigned numOperands)
|
MachineInstr::MachineInstr(short opcode, unsigned numOperands)
|
||||||
: Opcode(opcode), parent(0) {
|
: Opcode(opcode), parent(0) {
|
||||||
operands.reserve(numOperands);
|
Operands.reserve(numOperands);
|
||||||
// Make sure that we get added to a machine basicblock
|
// Make sure that we get added to a machine basicblock
|
||||||
LeakDetector::addGarbageObject(this);
|
LeakDetector::addGarbageObject(this);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ MachineInstr::MachineInstr(MachineBasicBlock *MBB, short opcode,
|
|||||||
unsigned numOperands)
|
unsigned numOperands)
|
||||||
: Opcode(opcode), parent(0) {
|
: Opcode(opcode), parent(0) {
|
||||||
assert(MBB && "Cannot use inserting ctor with null basic block!");
|
assert(MBB && "Cannot use inserting ctor with null basic block!");
|
||||||
operands.reserve(numOperands);
|
Operands.reserve(numOperands);
|
||||||
// Make sure that we get added to a machine basicblock
|
// Make sure that we get added to a machine basicblock
|
||||||
LeakDetector::addGarbageObject(this);
|
LeakDetector::addGarbageObject(this);
|
||||||
MBB->push_back(this); // Add instruction to end of basic block!
|
MBB->push_back(this); // Add instruction to end of basic block!
|
||||||
@ -65,11 +65,11 @@ MachineInstr::MachineInstr(MachineBasicBlock *MBB, short opcode,
|
|||||||
///
|
///
|
||||||
MachineInstr::MachineInstr(const MachineInstr &MI) {
|
MachineInstr::MachineInstr(const MachineInstr &MI) {
|
||||||
Opcode = MI.getOpcode();
|
Opcode = MI.getOpcode();
|
||||||
operands.reserve(MI.getNumOperands());
|
Operands.reserve(MI.getNumOperands());
|
||||||
|
|
||||||
// Add operands
|
// Add operands
|
||||||
for (unsigned i = 0; i < MI.getNumOperands(); ++i)
|
for (unsigned i = 0; i != MI.getNumOperands(); ++i)
|
||||||
operands.push_back(MachineOperand(MI.getOperand(i)));
|
Operands.push_back(MI.getOperand(i));
|
||||||
|
|
||||||
// Set parent, next, and prev to null
|
// Set parent, next, and prev to null
|
||||||
parent = 0;
|
parent = 0;
|
||||||
@ -82,13 +82,6 @@ MachineInstr::~MachineInstr() {
|
|||||||
LeakDetector::removeGarbageObject(this);
|
LeakDetector::removeGarbageObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// clone - Create a copy of 'this' instruction that is identical in all ways
|
|
||||||
/// except the following: the new instruction has no parent and it has no name
|
|
||||||
///
|
|
||||||
MachineInstr* MachineInstr::clone() const {
|
|
||||||
return new MachineInstr(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// removeFromParent - This method unlinks 'this' from the containing basic
|
/// removeFromParent - This method unlinks 'this' from the containing basic
|
||||||
/// block, and returns it, but does not delete it.
|
/// block, and returns it, but does not delete it.
|
||||||
MachineInstr *MachineInstr::removeFromParent() {
|
MachineInstr *MachineInstr::removeFromParent() {
|
||||||
@ -111,15 +104,6 @@ void MachineInstr::dump() const {
|
|||||||
std::cerr << " " << *this;
|
std::cerr << " " << *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::ostream& OutputValue(std::ostream &os, const Value* val) {
|
|
||||||
os << "(val ";
|
|
||||||
os << (void*) val; // print address always
|
|
||||||
if (val && val->hasName())
|
|
||||||
os << " " << val->getName(); // print name also, if available
|
|
||||||
os << ")";
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void OutputReg(std::ostream &os, unsigned RegNo,
|
static inline void OutputReg(std::ostream &os, unsigned RegNo,
|
||||||
const MRegisterInfo *MRI = 0) {
|
const MRegisterInfo *MRI = 0) {
|
||||||
if (!RegNo || MRegisterInfo::isPhysicalRegister(RegNo)) {
|
if (!RegNo || MRegisterInfo::isPhysicalRegister(RegNo)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user