Add ability to override segment (mostly for code emitter purposes).
authorAnton Korobeynikov <asl@math.spbu.ru>
Sat, 11 Oct 2008 19:09:15 +0000 (19:09 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Sat, 11 Oct 2008 19:09:15 +0000 (19:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57380 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86.td
lib/Target/X86/X86CodeEmitter.cpp
lib/Target/X86/X86InstrFormats.td
lib/Target/X86/X86InstrInfo.h

index 39ba093be743be4e1b4605bd20124f70ec00d25d..779d0b4ce4c14b699093a37731f4218c36e5c929 100644 (file)
@@ -116,6 +116,7 @@ def X86InstrInfo : InstrInfo {
                        "ImmTypeBits",
                        "FPFormBits",
                        "hasLockPrefix",
+                       "SegOvrBits",
                        "Opcode"];
   let TSFlagsShifts = [0,
                        6,
@@ -125,6 +126,7 @@ def X86InstrInfo : InstrInfo {
                        13,
                        16,
                        19,
+                       20,
                        24];
 }
 
index 37c1e99aeb1eac283c7cabc62435fee353df3ad0..16124fa8a85934ccd7a7f20161ad7dade1b6f848 100644 (file)
@@ -412,6 +412,16 @@ void Emitter::emitInstruction(const MachineInstr &MI,
   // Emit the lock opcode prefix as needed.
   if (Desc->TSFlags & X86II::LOCK) MCE.emitByte(0xF0);
 
+  // Emit segment overrid opcode prefix as needed.
+  switch (Desc->TSFlags & X86II::SegOvrMask) {
+  case X86II::FS:
+    MCE.emitByte(0x64);
+    break;
+  case X86II::GS:
+    MCE.emitByte(0x65);
+    break;
+  }
+
   // Emit the repeat opcode prefix as needed.
   if ((Desc->TSFlags & X86II::Op0Mask) == X86II::REP) MCE.emitByte(0xF3);
 
index c26ea01dc65eb52478ac5e7c4dc1d55fe4bded5e..eeed5bd27ff3ca106d4dddcca0874c23ffd6e5de 100644 (file)
@@ -63,6 +63,8 @@ class OpSize { bit hasOpSizePrefix = 1; }
 class AdSize { bit hasAdSizePrefix = 1; }
 class REX_W  { bit hasREX_WPrefix = 1; }
 class LOCK   { bit hasLockPrefix = 1; }
+class SegFS  { bits<2> SegOvrBits = 1; }
+class SegGS  { bits<2> SegOvrBits = 2; }
 class TB     { bits<4> Prefix = 1; }
 class REP    { bits<4> Prefix = 2; }
 class D8     { bits<4> Prefix = 3; }
@@ -104,6 +106,7 @@ class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
   FPFormat FPForm;          // What flavor of FP instruction is this?
   bits<3> FPFormBits = 0;
   bit hasLockPrefix = 0;    // Does this inst have a 0xF0 prefix?
+  bits<2> SegOvrBits = 0;   // Segment override prefix.
 }
 
 class I<bits<8> o, Format f, dag outs, dag ins, string asm, list<dag> pattern>
index b2de31051cf57ff6961aa024d2a6033c9bfe7b13..1413310b3c0c7848e513b8ca3e0bdb20823962c1 100644 (file)
@@ -221,7 +221,14 @@ namespace X86II {
     LOCKShift = 19,
     LOCK = 1 << LOCKShift,
 
-    // Bits 20 -> 23 are unused
+    // Segment override prefixes. Currently we just need ability to address
+    // stuff in gs and fs segments.
+    SegOvrShift = 20,
+    SegOvrMask  = 3 << SegOvrShift,
+    FS          = 1 << SegOvrShift,
+    GS          = 2 << SegOvrShift,
+
+    // Bits 22 -> 23 are unused
     OpcodeShift   = 24,
     OpcodeMask    = 0xFF << OpcodeShift
   };