mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
1. Make a static MachineOperand::create* method for every
operand type. 2. Move these create methods below the accessors. 3. Simplify all the MachineInstr::add* methods to use these. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45430 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -94,47 +94,6 @@ public:
|
|||||||
|
|
||||||
~MachineOperand() {}
|
~MachineOperand() {}
|
||||||
|
|
||||||
static MachineOperand CreateImm(int64_t Val) {
|
|
||||||
MachineOperand Op;
|
|
||||||
Op.opType = MachineOperand::MO_Immediate;
|
|
||||||
Op.contents.immedVal = Val;
|
|
||||||
Op.auxInfo.offset = 0;
|
|
||||||
return Op;
|
|
||||||
}
|
|
||||||
|
|
||||||
static MachineOperand CreateFrameIndex(unsigned Idx) {
|
|
||||||
MachineOperand Op;
|
|
||||||
Op.opType = MachineOperand::MO_FrameIndex;
|
|
||||||
Op.contents.immedVal = Idx;
|
|
||||||
Op.auxInfo.offset = 0;
|
|
||||||
return Op;
|
|
||||||
}
|
|
||||||
|
|
||||||
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
|
|
||||||
bool isKill = false, bool isDead = false,
|
|
||||||
unsigned SubReg = 0) {
|
|
||||||
MachineOperand Op;
|
|
||||||
Op.opType = MachineOperand::MO_Register;
|
|
||||||
Op.IsDef = isDef;
|
|
||||||
Op.IsImp = isImp;
|
|
||||||
Op.IsKill = isKill;
|
|
||||||
Op.IsDead = isDead;
|
|
||||||
Op.contents.RegNo = Reg;
|
|
||||||
Op.auxInfo.subReg = SubReg;
|
|
||||||
return Op;
|
|
||||||
}
|
|
||||||
|
|
||||||
const MachineOperand &operator=(const MachineOperand &MO) {
|
|
||||||
contents = MO.contents;
|
|
||||||
IsDef = MO.IsDef;
|
|
||||||
IsImp = MO.IsImp;
|
|
||||||
IsKill = MO.IsKill;
|
|
||||||
IsDead = MO.IsDead;
|
|
||||||
opType = MO.opType;
|
|
||||||
auxInfo = MO.auxInfo;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getType - Returns the MachineOperandType for this operand.
|
/// getType - Returns the MachineOperandType for this operand.
|
||||||
///
|
///
|
||||||
MachineOperandType getType() const { return opType; }
|
MachineOperandType getType() const { return opType; }
|
||||||
@@ -318,6 +277,79 @@ public:
|
|||||||
IsKill = isKill;
|
IsKill = isKill;
|
||||||
IsDead = isDead;
|
IsDead = isDead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MachineOperand CreateImm(int64_t Val) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_Immediate;
|
||||||
|
Op.contents.immedVal = Val;
|
||||||
|
Op.auxInfo.offset = 0;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
|
||||||
|
bool isKill = false, bool isDead = false,
|
||||||
|
unsigned SubReg = 0) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_Register;
|
||||||
|
Op.IsDef = isDef;
|
||||||
|
Op.IsImp = isImp;
|
||||||
|
Op.IsKill = isKill;
|
||||||
|
Op.IsDead = isDead;
|
||||||
|
Op.contents.RegNo = Reg;
|
||||||
|
Op.auxInfo.subReg = SubReg;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
static MachineOperand CreateBasicBlock(MachineBasicBlock *MBB) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_MachineBasicBlock;
|
||||||
|
Op.contents.MBB = MBB;
|
||||||
|
Op.auxInfo.offset = 0;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
static MachineOperand CreateFrameIndex(unsigned Idx) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_FrameIndex;
|
||||||
|
Op.contents.immedVal = Idx;
|
||||||
|
Op.auxInfo.offset = 0;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
static MachineOperand CreateConstantPoolIndex(unsigned Idx, int Offset) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_ConstantPoolIndex;
|
||||||
|
Op.contents.immedVal = Idx;
|
||||||
|
Op.auxInfo.offset = Offset;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
static MachineOperand CreateJumpTableIndex(unsigned Idx) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_JumpTableIndex;
|
||||||
|
Op.contents.immedVal = Idx;
|
||||||
|
Op.auxInfo.offset = 0;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
static MachineOperand CreateGlobalAddress(GlobalValue *GV, int Offset) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_GlobalAddress;
|
||||||
|
Op.contents.GV = GV;
|
||||||
|
Op.auxInfo.offset = Offset;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
static MachineOperand CreateExternalSymbol(const char *SymName, int Offset) {
|
||||||
|
MachineOperand Op;
|
||||||
|
Op.opType = MachineOperand::MO_ExternalSymbol;
|
||||||
|
Op.contents.SymbolName = SymName;
|
||||||
|
Op.auxInfo.offset = Offset;
|
||||||
|
return Op;
|
||||||
|
}
|
||||||
|
const MachineOperand &operator=(const MachineOperand &MO) {
|
||||||
|
contents = MO.contents;
|
||||||
|
IsDef = MO.IsDef;
|
||||||
|
IsImp = MO.IsImp;
|
||||||
|
IsKill = MO.IsKill;
|
||||||
|
IsDead = MO.IsDead;
|
||||||
|
opType = MO.opType;
|
||||||
|
auxInfo = MO.auxInfo;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, const MachineOperand& mop) {
|
friend std::ostream& operator<<(std::ostream& os, const MachineOperand& mop) {
|
||||||
mop.print(os);
|
mop.print(os);
|
||||||
@@ -464,73 +496,65 @@ public:
|
|||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Accessors to add operands when building up machine instructions.
|
// Accessors to add operands when building up machine instructions.
|
||||||
//
|
//
|
||||||
|
void addOperand(const MachineOperand &Op) {
|
||||||
|
bool isImpReg = Op.isRegister() && Op.isImplicit();
|
||||||
|
assert((isImpReg || !OperandsComplete()) &&
|
||||||
|
"Trying to add an operand to a machine instr that is already done!");
|
||||||
|
if (isImpReg || NumImplicitOps == 0) // This is true most of the time.
|
||||||
|
Operands.push_back(Op);
|
||||||
|
else
|
||||||
|
// Insert a real operand before any implicit ones.
|
||||||
|
Operands.insert(Operands.begin()+Operands.size()-NumImplicitOps, Op);
|
||||||
|
}
|
||||||
|
|
||||||
/// addRegOperand - Add a register operand.
|
/// addRegOperand - Add a register operand.
|
||||||
///
|
///
|
||||||
void addRegOperand(unsigned Reg, bool IsDef, bool IsImp = false,
|
void addRegOperand(unsigned Reg, bool IsDef, bool IsImp = false,
|
||||||
bool IsKill = false, bool IsDead = false,
|
bool IsKill = false, bool IsDead = false,
|
||||||
unsigned SubReg = 0) {
|
unsigned SubReg = 0) {
|
||||||
// FIXME: Make the AddNewOperand api sane.
|
addOperand(MachineOperand::CreateReg(Reg, IsDef, IsImp, IsKill,
|
||||||
AddNewOperand(IsImp) = MachineOperand::CreateReg(Reg, IsDef, IsImp, IsKill,
|
IsDead, SubReg));
|
||||||
IsDead, SubReg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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) {
|
||||||
// FIXME: Make the AddNewOperand api sane.
|
addOperand(MachineOperand::CreateImm(Val));
|
||||||
AddNewOperand() = MachineOperand::CreateImm(Val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMachineBasicBlockOperand(MachineBasicBlock *MBB) {
|
void addMachineBasicBlockOperand(MachineBasicBlock *MBB) {
|
||||||
MachineOperand &Op = AddNewOperand();
|
addOperand(MachineOperand::CreateBasicBlock(MBB));
|
||||||
Op.opType = MachineOperand::MO_MachineBasicBlock;
|
|
||||||
Op.contents.MBB = MBB;
|
|
||||||
Op.auxInfo.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) {
|
||||||
// FIXME: Make the AddNewOperand api sane.
|
addOperand(MachineOperand::CreateFrameIndex(Idx));
|
||||||
AddNewOperand() = MachineOperand::CreateFrameIndex(Idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// addConstantPoolndexOperand - Add a constant pool object index to the
|
/// addConstantPoolndexOperand - Add a constant pool object index to the
|
||||||
/// instruction.
|
/// instruction.
|
||||||
///
|
///
|
||||||
void addConstantPoolIndexOperand(unsigned Idx, int Offset) {
|
void addConstantPoolIndexOperand(unsigned Idx, int Offset) {
|
||||||
MachineOperand &Op = AddNewOperand();
|
addOperand(MachineOperand::CreateConstantPoolIndex(Idx, Offset));
|
||||||
Op.opType = MachineOperand::MO_ConstantPoolIndex;
|
|
||||||
Op.contents.immedVal = Idx;
|
|
||||||
Op.auxInfo.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 Idx) {
|
void addJumpTableIndexOperand(unsigned Idx) {
|
||||||
MachineOperand &Op = AddNewOperand();
|
addOperand(MachineOperand::CreateJumpTableIndex(Idx));
|
||||||
Op.opType = MachineOperand::MO_JumpTableIndex;
|
|
||||||
Op.contents.immedVal = Idx;
|
|
||||||
Op.auxInfo.offset = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addGlobalAddressOperand(GlobalValue *GV, int Offset) {
|
void addGlobalAddressOperand(GlobalValue *GV, int Offset) {
|
||||||
MachineOperand &Op = AddNewOperand();
|
addOperand(MachineOperand::CreateGlobalAddress(GV, Offset));
|
||||||
Op.opType = MachineOperand::MO_GlobalAddress;
|
|
||||||
Op.contents.GV = GV;
|
|
||||||
Op.auxInfo.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, int Offset = 0) {
|
||||||
MachineOperand &Op = AddNewOperand();
|
addOperand(MachineOperand::CreateExternalSymbol(SymName, Offset));
|
||||||
Op.opType = MachineOperand::MO_ExternalSymbol;
|
|
||||||
Op.contents.SymbolName = SymName;
|
|
||||||
Op.auxInfo.offset = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
@@ -549,16 +573,6 @@ public:
|
|||||||
Operands.erase(Operands.begin()+i);
|
Operands.erase(Operands.begin()+i);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
MachineOperand &AddNewOperand(bool IsImp = false) {
|
|
||||||
assert((IsImp || !OperandsComplete()) &&
|
|
||||||
"Trying to add an operand to a machine instr that is already done!");
|
|
||||||
if (IsImp || NumImplicitOps == 0) { // This is true most of the time.
|
|
||||||
Operands.push_back(MachineOperand());
|
|
||||||
return Operands.back();
|
|
||||||
}
|
|
||||||
return *Operands.insert(Operands.begin()+Operands.size()-NumImplicitOps,
|
|
||||||
MachineOperand());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// addImplicitDefUseOperands - Add all implicit def and use operands to
|
/// addImplicitDefUseOperands - Add all implicit def and use operands to
|
||||||
/// this instruction.
|
/// this instruction.
|
||||||
|
Reference in New Issue
Block a user