[llvm-commits] [llvm] r95344 - in /llvm/trunk/lib/Target/X86: X86CodeEmitter.cpp X86MCCodeEmitter.cpp
Chris Lattner
sabre at nondot.org
Thu Feb 4 17:53:19 PST 2010
Author: lattner
Date: Thu Feb 4 19:53:19 2010
New Revision: 95344
URL: http://llvm.org/viewvc/llvm-project?rev=95344&view=rev
Log:
Add a few more encodings, we can now encode all of:
pushl %ebp
movl %esp, %ebp
movl $42, %eax
popl %ebp
ret
Modified:
llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp
llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
Modified: llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp?rev=95344&r1=95343&r2=95344&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86CodeEmitter.cpp Thu Feb 4 19:53:19 2010
@@ -249,7 +249,7 @@
template<class CodeEmitter>
unsigned Emitter<CodeEmitter>::getX86RegNum(unsigned RegNo) const {
- return II->getRegisterInfo().getX86RegNum(RegNo);
+ return X86RegisterInfo::getX86RegNum(RegNo);
}
inline static unsigned char ModRMByte(unsigned Mod, unsigned RegOpcode,
Modified: llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp?rev=95344&r1=95343&r2=95344&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp Thu Feb 4 19:53:19 2010
@@ -32,10 +32,34 @@
~X86MCCodeEmitter() {}
+ static unsigned GetX86RegNum(const MCOperand &MO) {
+ return X86RegisterInfo::getX86RegNum(MO.getReg());
+ }
+
void EmitByte(unsigned char C, raw_ostream &OS) const {
OS << (char)C;
}
+ void EmitConstant(uint64_t Val, unsigned Size, raw_ostream &OS) const {
+ // Output the constant in little endian byte order.
+ for (unsigned i = 0; i != Size; ++i) {
+ EmitByte(Val & 255, OS);
+ Val >>= 8;
+ }
+ }
+
+ inline static unsigned char ModRMByte(unsigned Mod, unsigned RegOpcode,
+ unsigned RM) {
+ assert(Mod < 4 && RegOpcode < 8 && RM < 8 && "ModRM Fields out of range!");
+ return RM | (RegOpcode << 3) | (Mod << 6);
+ }
+
+ void EmitRegModRMByte(const MCOperand &ModRMReg, unsigned RegOpcodeFld,
+ raw_ostream &OS) const {
+ EmitByte(ModRMByte(3, RegOpcodeFld, GetX86RegNum(ModRMReg)), OS);
+ }
+
+
void EncodeInstruction(const MCInst &MI, raw_ostream &OS) const;
};
@@ -160,42 +184,43 @@
if (CurOp == NumOps)
break;
- assert(0 && "Unimpl");
-#if 0
- const MachineOperand &MO = MI.getOperand(CurOp++);
-
- DEBUG(dbgs() << "RawFrm CurOp " << CurOp << "\n");
- DEBUG(dbgs() << "isMBB " << MO.isMBB() << "\n");
- DEBUG(dbgs() << "isGlobal " << MO.isGlobal() << "\n");
- DEBUG(dbgs() << "isSymbol " << MO.isSymbol() << "\n");
- DEBUG(dbgs() << "isImm " << MO.isImm() << "\n");
-
- if (MO.isMBB()) {
- emitPCRelativeBlockAddress(MO.getMBB());
- break;
- }
-
- if (MO.isGlobal()) {
- emitGlobalAddress(MO.getGlobal(), X86::reloc_pcrel_word,
- MO.getOffset(), 0);
+ assert(0 && "Unimpl RawFrm expr");
+ break;
+ }
+
+ case X86II::AddRegFrm: {
+ EmitByte(BaseOpcode + GetX86RegNum(MI.getOperand(CurOp++)),OS);
+ if (CurOp == NumOps)
break;
- }
-
- if (MO.isSymbol()) {
- emitExternalSymbolAddress(MO.getSymbolName(), X86::reloc_pcrel_word);
+
+ const MCOperand &MO1 = MI.getOperand(CurOp++);
+ if (MO1.isImm()) {
+ unsigned Size = X86InstrInfo::sizeOfImm(&Desc);
+ EmitConstant(MO1.getImm(), Size, OS);
break;
}
-
- assert(MO.isImm() && "Unknown RawFrm operand!");
- if (Opcode == X86::CALLpcrel32 || Opcode == X86::CALL64pcrel32) {
- // Fix up immediate operand for pc relative calls.
- intptr_t Imm = (intptr_t)MO.getImm();
- Imm = Imm - MCE.getCurrentPCValue() - 4;
- emitConstant(Imm, X86InstrInfo::sizeOfImm(Desc));
- } else
- emitConstant(MO.getImm(), X86InstrInfo::sizeOfImm(Desc));
+
+ assert(0 && "Unimpl AddRegFrm expr");
break;
-#endif
}
+
+ case X86II::MRMDestReg:
+ EmitByte(BaseOpcode, OS);
+ EmitRegModRMByte(MI.getOperand(CurOp),
+ GetX86RegNum(MI.getOperand(CurOp+1)), OS);
+ CurOp += 2;
+ if (CurOp != NumOps)
+ EmitConstant(MI.getOperand(CurOp++).getImm(),
+ X86InstrInfo::sizeOfImm(&Desc), OS);
+ break;
}
+
+#ifndef NDEBUG
+ if (!Desc.isVariadic() && CurOp != NumOps) {
+ errs() << "Cannot encode all operands of: ";
+ MI.dump();
+ errs() << '\n';
+ abort();
+ }
+#endif
}
More information about the llvm-commits
mailing list