move functions for decoding X86II values into the X86II namespace.

llvm-svn: 95410
This commit is contained in:
Chris Lattner 2010-02-05 19:24:13 +00:00
parent 4739e41ce9
commit 503243559a
4 changed files with 48 additions and 45 deletions

View File

@ -566,7 +566,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
// Skip the last source operand that is tied_to the dest reg. e.g. LXADD32
--NumOps;
unsigned char BaseOpcode = X86InstrInfo::getBaseOpcodeFor(Desc->TSFlags);
unsigned char BaseOpcode = X86II::getBaseOpcodeFor(Desc->TSFlags);
switch (Desc->TSFlags & X86II::FormMask) {
default:
llvm_unreachable("Unknown FormMask value in X86 MachineCodeEmitter!");
@ -596,7 +596,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
case X86::MOVPC32r: {
// This emits the "call" portion of this pseudo instruction.
MCE.emitByte(BaseOpcode);
emitConstant(0, X86InstrInfo::getSizeOfImm(Desc->TSFlags));
emitConstant(0, X86II::getSizeOfImm(Desc->TSFlags));
// Remember PIC base.
PICBaseOffset = (intptr_t) MCE.getCurrentPCOffset();
X86JITInfo *JTI = TM.getJITInfo();
@ -641,9 +641,9 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
// Fix up immediate operand for pc relative calls.
intptr_t Imm = (intptr_t)MO.getImm();
Imm = Imm - MCE.getCurrentPCValue() - 4;
emitConstant(Imm, X86InstrInfo::getSizeOfImm(Desc->TSFlags));
emitConstant(Imm, X86II::getSizeOfImm(Desc->TSFlags));
} else
emitConstant(MO.getImm(), X86InstrInfo::getSizeOfImm(Desc->TSFlags));
emitConstant(MO.getImm(), X86II::getSizeOfImm(Desc->TSFlags));
break;
}
@ -654,7 +654,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
break;
const MachineOperand &MO1 = MI.getOperand(CurOp++);
unsigned Size = X86InstrInfo::getSizeOfImm(Desc->TSFlags);
unsigned Size = X86II::getSizeOfImm(Desc->TSFlags);
if (MO1.isImm()) {
emitConstant(MO1.getImm(), Size);
break;
@ -687,7 +687,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
CurOp += 2;
if (CurOp != NumOps)
emitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(Desc->TSFlags));
X86II::getSizeOfImm(Desc->TSFlags));
break;
}
case X86II::MRMDestMem: {
@ -698,7 +698,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
CurOp += X86AddrNumOperands + 1;
if (CurOp != NumOps)
emitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(Desc->TSFlags));
X86II::getSizeOfImm(Desc->TSFlags));
break;
}
@ -709,7 +709,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
CurOp += 2;
if (CurOp != NumOps)
emitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(Desc->TSFlags));
X86II::getSizeOfImm(Desc->TSFlags));
break;
case X86II::MRMSrcMem: {
@ -722,7 +722,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
AddrOperands = X86AddrNumOperands;
intptr_t PCAdj = (CurOp + AddrOperands + 1 != NumOps) ?
X86InstrInfo::getSizeOfImm(Desc->TSFlags) : 0;
X86II::getSizeOfImm(Desc->TSFlags) : 0;
MCE.emitByte(BaseOpcode);
emitMemModRMByte(MI, CurOp+1, getX86RegNum(MI.getOperand(CurOp).getReg()),
@ -730,7 +730,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
CurOp += AddrOperands + 1;
if (CurOp != NumOps)
emitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(Desc->TSFlags));
X86II::getSizeOfImm(Desc->TSFlags));
break;
}
@ -765,7 +765,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
break;
const MachineOperand &MO1 = MI.getOperand(CurOp++);
unsigned Size = X86InstrInfo::getSizeOfImm(Desc->TSFlags);
unsigned Size = X86II::getSizeOfImm(Desc->TSFlags);
if (MO1.isImm()) {
emitConstant(MO1.getImm(), Size);
break;
@ -794,7 +794,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
case X86II::MRM6m: case X86II::MRM7m: {
intptr_t PCAdj = (CurOp + X86AddrNumOperands != NumOps) ?
(MI.getOperand(CurOp+X86AddrNumOperands).isImm() ?
X86InstrInfo::getSizeOfImm(Desc->TSFlags) : 4) : 0;
X86II::getSizeOfImm(Desc->TSFlags) : 4) : 0;
MCE.emitByte(BaseOpcode);
emitMemModRMByte(MI, CurOp, (Desc->TSFlags & X86II::FormMask)-X86II::MRM0m,
@ -805,7 +805,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
break;
const MachineOperand &MO = MI.getOperand(CurOp++);
unsigned Size = X86InstrInfo::getSizeOfImm(Desc->TSFlags);
unsigned Size = X86II::getSizeOfImm(Desc->TSFlags);
if (MO.isImm()) {
emitConstant(MO.getImm(), Size);
break;

View File

@ -3390,7 +3390,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
case X86::MOVPC32r: {
// This emits the "call" portion of this pseudo instruction.
++FinalSize;
FinalSize += sizeConstant(X86InstrInfo::getSizeOfImm(Desc->TSFlags));
FinalSize += sizeConstant(X86II::getSizeOfImm(Desc->TSFlags));
break;
}
}
@ -3408,7 +3408,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
} else if (MO.isSymbol()) {
FinalSize += sizeExternalSymbolAddress(false);
} else if (MO.isImm()) {
FinalSize += sizeConstant(X86InstrInfo::getSizeOfImm(Desc->TSFlags));
FinalSize += sizeConstant(X86II::getSizeOfImm(Desc->TSFlags));
} else {
llvm_unreachable("Unknown RawFrm operand!");
}
@ -3421,7 +3421,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
if (CurOp != NumOps) {
const MachineOperand &MO1 = MI.getOperand(CurOp++);
unsigned Size = X86InstrInfo::getSizeOfImm(Desc->TSFlags);
unsigned Size = X86II::getSizeOfImm(Desc->TSFlags);
if (MO1.isImm())
FinalSize += sizeConstant(Size);
else {
@ -3446,7 +3446,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
CurOp += 2;
if (CurOp != NumOps) {
++CurOp;
FinalSize += sizeConstant(X86InstrInfo::getSizeOfImm(Desc->TSFlags));
FinalSize += sizeConstant(X86II::getSizeOfImm(Desc->TSFlags));
}
break;
}
@ -3456,7 +3456,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
CurOp += X86AddrNumOperands + 1;
if (CurOp != NumOps) {
++CurOp;
FinalSize += sizeConstant(X86InstrInfo::getSizeOfImm(Desc->TSFlags));
FinalSize += sizeConstant(X86II::getSizeOfImm(Desc->TSFlags));
}
break;
}
@ -3467,7 +3467,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
CurOp += 2;
if (CurOp != NumOps) {
++CurOp;
FinalSize += sizeConstant(X86InstrInfo::getSizeOfImm(Desc->TSFlags));
FinalSize += sizeConstant(X86II::getSizeOfImm(Desc->TSFlags));
}
break;
@ -3484,7 +3484,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
CurOp += AddrOperands + 1;
if (CurOp != NumOps) {
++CurOp;
FinalSize += sizeConstant(X86InstrInfo::getSizeOfImm(Desc->TSFlags));
FinalSize += sizeConstant(X86II::getSizeOfImm(Desc->TSFlags));
}
break;
}
@ -3509,7 +3509,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
if (CurOp != NumOps) {
const MachineOperand &MO1 = MI.getOperand(CurOp++);
unsigned Size = X86InstrInfo::getSizeOfImm(Desc->TSFlags);
unsigned Size = X86II::getSizeOfImm(Desc->TSFlags);
if (MO1.isImm())
FinalSize += sizeConstant(Size);
else {
@ -3539,7 +3539,7 @@ static unsigned GetInstSizeWithDesc(const MachineInstr &MI,
if (CurOp != NumOps) {
const MachineOperand &MO = MI.getOperand(CurOp++);
unsigned Size = X86InstrInfo::getSizeOfImm(Desc->TSFlags);
unsigned Size = X86II::getSizeOfImm(Desc->TSFlags);
if (MO.isImm())
FinalSize += sizeConstant(Size);
else {

View File

@ -389,6 +389,25 @@ namespace X86II {
OpcodeShift = 24,
OpcodeMask = 0xFF << OpcodeShift
};
// getBaseOpcodeFor - This function returns the "base" X86 opcode for the
// specified machine instruction.
//
static inline unsigned char getBaseOpcodeFor(unsigned TSFlags) {
return TSFlags >> X86II::OpcodeShift;
}
/// getSizeOfImm - Decode the "size of immediate" field from the TSFlags field
/// of the specified instruction.
static inline unsigned getSizeOfImm(unsigned TSFlags) {
switch (TSFlags & X86II::ImmMask) {
default: assert(0 && "Unknown immediate size");
case X86II::Imm8: return 1;
case X86II::Imm16: return 2;
case X86II::Imm32: return 4;
case X86II::Imm64: return 8;
}
}
}
const int X86AddrNumOperands = 5;
@ -637,27 +656,11 @@ public:
/// instruction that defines the specified register class.
bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const;
// getBaseOpcodeFor - This function returns the "base" X86 opcode for the
// specified machine instruction.
//
static unsigned char getBaseOpcodeFor(unsigned TSFlags) {
return TSFlags >> X86II::OpcodeShift;
}
static bool isX86_64NonExtLowByteReg(unsigned reg) {
return (reg == X86::SPL || reg == X86::BPL ||
reg == X86::SIL || reg == X86::DIL);
}
static unsigned getSizeOfImm(unsigned TSFlags) {
switch (TSFlags & X86II::ImmMask) {
default: assert(0 && "Unknown immediate size");
case X86II::Imm8: return 1;
case X86II::Imm16: return 2;
case X86II::Imm32: return 4;
case X86II::Imm64: return 8;
}
}
static bool isX86_64ExtendedReg(const MachineOperand &MO);
static unsigned determineREX(const MachineInstr &MI);

View File

@ -366,7 +366,7 @@ EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
// FIXME: Can we kill off MRMInitReg??
unsigned char BaseOpcode = X86InstrInfo::getBaseOpcodeFor(TSFlags);
unsigned char BaseOpcode = X86II::getBaseOpcodeFor(TSFlags);
switch (TSFlags & X86II::FormMask) {
default: errs() << "FORM: " << (TSFlags & X86II::FormMask) << "\n";
assert(0 && "Unknown FormMask value in X86MCCodeEmitter!");
@ -387,7 +387,7 @@ EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
const MCOperand &MO1 = MI.getOperand(CurOp++);
if (MO1.isImm()) {
unsigned Size = X86InstrInfo::getSizeOfImm(TSFlags);
unsigned Size = X86II::getSizeOfImm(TSFlags);
EmitConstant(MO1.getImm(), Size, OS);
break;
}
@ -403,7 +403,7 @@ EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
CurOp += 2;
if (CurOp != NumOps)
EmitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(TSFlags), OS);
X86II::getSizeOfImm(TSFlags), OS);
break;
case X86II::MRMDestMem:
@ -414,7 +414,7 @@ EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
CurOp += X86AddrNumOperands + 1;
if (CurOp != NumOps)
EmitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(TSFlags), OS);
X86II::getSizeOfImm(TSFlags), OS);
break;
case X86II::MRMSrcReg:
@ -424,7 +424,7 @@ EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
CurOp += 2;
if (CurOp != NumOps)
EmitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(TSFlags), OS);
X86II::getSizeOfImm(TSFlags), OS);
break;
case X86II::MRMSrcMem: {
@ -440,14 +440,14 @@ EncodeInstruction(const MCInst &MI, raw_ostream &OS) const {
// FIXME: What is this actually doing?
intptr_t PCAdj = (CurOp + AddrOperands + 1 != NumOps) ?
X86InstrInfo::getSizeOfImm(TSFlags) : 0;
X86II::getSizeOfImm(TSFlags) : 0;
EmitMemModRMByte(MI, CurOp+1, GetX86RegNum(MI.getOperand(CurOp)),
PCAdj, OS);
CurOp += AddrOperands + 1;
if (CurOp != NumOps)
EmitConstant(MI.getOperand(CurOp++).getImm(),
X86InstrInfo::getSizeOfImm(TSFlags), OS);
X86II::getSizeOfImm(TSFlags), OS);
break;
}