24
24
class X86TargetMachine;
27
// Enums for memory operand decoding. Each memory operand is represented with
28
// a 5 operand sequence in the form:
29
// [BaseReg, ScaleAmt, IndexReg, Disp, Segment]
30
// These enums help decode this.
37
/// AddrSegmentReg - The operand # of the segment in the memory operand.
40
/// AddrNumOperands - Total number of operands in a memory reference.
27
45
// X86 specific condition code. These correspond to X86_*_COND in
28
46
// X86InstrInfo.td. They must be kept in synch.
173
191
/// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE",
174
192
/// which is a PIC-base-relative reference to a hidden dyld lazy pointer
176
MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE
194
MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE,
196
/// MO_TLVP - On a symbol operand this indicates that the immediate is
199
/// This is the TLS offset for the Darwin TLS mechanism.
202
/// MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate
203
/// is some TLS offset from the picbase.
205
/// This is the 32-bit TLS offset for Darwin TLS in PIC mode.
315
/// RawFrmImm16 - This is used for CALL FAR instructions, which have two
316
/// immediates, the first of which is a 16 or 32-bit immediate (specified by
317
/// the imm encoding) and the second is a 16-bit fixed value. In the AMD
318
/// manual, this operand is described as pntr16:32 and pntr16:16
347
384
Imm8 = 1 << ImmShift,
348
385
Imm8PCRel = 2 << ImmShift,
349
386
Imm16 = 3 << ImmShift,
350
Imm32 = 4 << ImmShift,
351
Imm32PCRel = 5 << ImmShift,
352
Imm64 = 6 << ImmShift,
387
Imm16PCRel = 4 << ImmShift,
388
Imm32 = 5 << ImmShift,
389
Imm32PCRel = 6 << ImmShift,
390
Imm64 = 7 << ImmShift,
354
392
//===------------------------------------------------------------------===//
355
393
// FP Instruction Classification... Zero is non-fp instruction.
398
436
FS = 1 << SegOvrShift,
399
437
GS = 2 << SegOvrShift,
401
// Bits 22 -> 23 are unused
439
// Execution domain for SSE instructions in bits 22, 23.
440
// 0 in bits 22-23 means normal, non-SSE instruction.
402
443
OpcodeShift = 24,
403
OpcodeMask = 0xFF << OpcodeShift
444
OpcodeMask = 0xFF << OpcodeShift,
446
//===------------------------------------------------------------------===//
447
// VEX - The opcode prefix used by AVX instructions
450
// VEX_W - Has a opcode specific functionality, but is used in the same
451
// way as REX_W is for regular SSE instructions.
454
// VEX_4V - Used to specify an additional AVX/SSE register. Several 2
455
// address instructions in SSE are represented as 3 address ones in AVX
456
// and the additional register is encoded in VEX_VVVV prefix.
459
// VEX_I8IMM - Specifies that the last register used in a AVX instruction,
460
// must be encoded in the i8 immediate field. This usually happens in
461
// instructions with 4 operands.
464
// VEX_L - Stands for a bit in the VEX opcode prefix meaning the current
465
// instruction uses 256-bit wide registers. This is usually auto detected if
466
// a VR256 register is used, but some AVX instructions also have this field
467
// marked when using a f256 memory references.
406
471
// getBaseOpcodeFor - This function returns the "base" X86 opcode for the
407
472
// specified machine instruction.
409
static inline unsigned char getBaseOpcodeFor(unsigned TSFlags) {
474
static inline unsigned char getBaseOpcodeFor(uint64_t TSFlags) {
410
475
return TSFlags >> X86II::OpcodeShift;
413
static inline bool hasImm(unsigned TSFlags) {
478
static inline bool hasImm(uint64_t TSFlags) {
414
479
return (TSFlags & X86II::ImmMask) != 0;
417
482
/// getSizeOfImm - Decode the "size of immediate" field from the TSFlags field
418
483
/// of the specified instruction.
419
static inline unsigned getSizeOfImm(unsigned TSFlags) {
484
static inline unsigned getSizeOfImm(uint64_t TSFlags) {
420
485
switch (TSFlags & X86II::ImmMask) {
421
486
default: assert(0 && "Unknown immediate size");
422
487
case X86II::Imm8:
423
488
case X86II::Imm8PCRel: return 1;
424
case X86II::Imm16: return 2;
490
case X86II::Imm16PCRel: return 2;
425
491
case X86II::Imm32:
426
492
case X86II::Imm32PCRel: return 4;
427
493
case X86II::Imm64: return 8;
431
497
/// isImmPCRel - Return true if the immediate of the specified instruction's
432
498
/// TSFlags indicates that it is pc relative.
433
static inline unsigned isImmPCRel(unsigned TSFlags) {
499
static inline unsigned isImmPCRel(uint64_t TSFlags) {
434
500
switch (TSFlags & X86II::ImmMask) {
435
default: assert(0 && "Unknown immediate size");
436
case X86II::Imm8PCRel:
437
case X86II::Imm32PCRel:
501
default: assert(0 && "Unknown immediate size");
502
case X86II::Imm8PCRel:
503
case X86II::Imm16PCRel:
504
case X86II::Imm32PCRel:
514
/// getMemoryOperandNo - The function returns the MCInst operand # for the
515
/// first field of the memory operand. If the instruction doesn't have a
516
/// memory operand, this returns -1.
518
/// Note that this ignores tied operands. If there is a tied register which
519
/// is duplicated in the MCInst (e.g. "EAX = addl EAX, [mem]") it is only
520
/// counted as one operand.
522
static inline int getMemoryOperandNo(uint64_t TSFlags) {
523
switch (TSFlags & X86II::FormMask) {
524
case X86II::MRMInitReg: assert(0 && "FIXME: Remove this form");
525
default: assert(0 && "Unknown FormMask value in getMemoryOperandNo!");
528
case X86II::AddRegFrm:
529
case X86II::MRMDestReg:
530
case X86II::MRMSrcReg:
531
case X86II::RawFrmImm16:
533
case X86II::MRMDestMem:
535
case X86II::MRMSrcMem: {
536
bool HasVEX_4V = (TSFlags >> 32) & X86II::VEX_4V;
537
unsigned FirstMemOp = 1;
539
++FirstMemOp;// Skip the register source (which is encoded in VEX_VVVV).
541
// FIXME: Maybe lea should have its own form? This is a horrible hack.
542
//if (Opcode == X86::LEA64r || Opcode == X86::LEA64_32r ||
543
// Opcode == X86::LEA16r || Opcode == X86::LEA32r)
546
case X86II::MRM0r: case X86II::MRM1r:
547
case X86II::MRM2r: case X86II::MRM3r:
548
case X86II::MRM4r: case X86II::MRM5r:
549
case X86II::MRM6r: case X86II::MRM7r:
551
case X86II::MRM0m: case X86II::MRM1m:
552
case X86II::MRM2m: case X86II::MRM3m:
553
case X86II::MRM4m: case X86II::MRM5m:
554
case X86II::MRM6m: case X86II::MRM7m:
448
const int X86AddrNumOperands = 5;
450
571
inline static bool isScale(const MachineOperand &MO) {
451
572
return MO.isImm() &&
452
573
(MO.getImm() == 1 || MO.getImm() == 2 ||
497
618
virtual const X86RegisterInfo &getRegisterInfo() const { return RI; }
499
/// Return true if the instruction is a register to register move and return
500
/// the source and dest operands and their sub-register indices by reference.
501
virtual bool isMoveInstr(const MachineInstr &MI,
502
unsigned &SrcReg, unsigned &DstReg,
503
unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
505
620
/// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
506
621
/// extension instruction. That is, it's like a copy where it's legal for the
507
622
/// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
552
667
void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
553
668
unsigned DestReg, unsigned SubIdx,
554
669
const MachineInstr *Orig,
555
const TargetRegisterInfo *TRI) const;
670
const TargetRegisterInfo &TRI) const;
557
672
/// convertToThreeAddress - This method must be implemented by targets that
558
673
/// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
582
697
virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
583
698
virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
584
699
MachineBasicBlock *FBB,
585
const SmallVectorImpl<MachineOperand> &Cond) const;
586
virtual bool copyRegToReg(MachineBasicBlock &MBB,
587
MachineBasicBlock::iterator MI,
588
unsigned DestReg, unsigned SrcReg,
589
const TargetRegisterClass *DestRC,
590
const TargetRegisterClass *SrcRC) const;
700
const SmallVectorImpl<MachineOperand> &Cond,
702
virtual void copyPhysReg(MachineBasicBlock &MBB,
703
MachineBasicBlock::iterator MI, DebugLoc DL,
704
unsigned DestReg, unsigned SrcReg,
591
706
virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
592
707
MachineBasicBlock::iterator MI,
593
708
unsigned SrcReg, bool isKill, int FrameIndex,
594
const TargetRegisterClass *RC) const;
709
const TargetRegisterClass *RC,
710
const TargetRegisterInfo *TRI) const;
596
712
virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
597
713
SmallVectorImpl<MachineOperand> &Addr,
603
719
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
604
720
MachineBasicBlock::iterator MI,
605
721
unsigned DestReg, int FrameIndex,
606
const TargetRegisterClass *RC) const;
722
const TargetRegisterClass *RC,
723
const TargetRegisterInfo *TRI) const;
608
725
virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
609
726
SmallVectorImpl<MachineOperand> &Addr,
615
732
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
616
733
MachineBasicBlock::iterator MI,
617
const std::vector<CalleeSavedInfo> &CSI) const;
734
const std::vector<CalleeSavedInfo> &CSI,
735
const TargetRegisterInfo *TRI) const;
619
737
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
620
738
MachineBasicBlock::iterator MI,
621
const std::vector<CalleeSavedInfo> &CSI) const;
739
const std::vector<CalleeSavedInfo> &CSI,
740
const TargetRegisterInfo *TRI) const;
743
MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
744
int FrameIx, uint64_t Offset,
623
748
/// foldMemoryOperand - If this target supports it, fold a load or store of
624
749
/// the specified stack slot into the specified machine instruction for the
625
750
/// specified operand(s). If this is possible, the target should perform the
700
827
if (!MO.isReg()) return false;
701
828
return isX86_64ExtendedReg(MO.getReg());
703
static unsigned determineREX(const MachineInstr &MI);
705
831
/// isX86_64ExtendedReg - Is the MachineOperand a x86-64 extended (r8 or
706
832
/// higher) register? e.g. r8, xmm8, xmm13, etc.
707
833
static bool isX86_64ExtendedReg(unsigned RegNo);
709
/// GetInstSize - Returns the size of the specified MachineInstr.
711
virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
713
835
/// getGlobalBaseReg - Return a virtual register initialized with the
714
836
/// the global base register value. Output instructions required to
715
837
/// initialize the register in the function entry block, if necessary.
717
839
unsigned getGlobalBaseReg(MachineFunction *MF) const;
841
/// GetSSEDomain - Return the SSE execution domain of MI as the first element,
842
/// and a bitmask of possible arguments to SetSSEDomain ase the second.
843
std::pair<uint16_t, uint16_t> GetSSEDomain(const MachineInstr *MI) const;
845
/// SetSSEDomain - Set the SSEDomain of MI.
846
void SetSSEDomain(MachineInstr *MI, unsigned Domain) const;
720
849
MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
721
850
MachineFunction::iterator &MFI,