~ubuntu-branches/ubuntu/maverick/clamav/maverick-updates

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Target/X86/X86InstrInfo.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-17 12:30:20 UTC
  • mfrom: (97.1.1 maverick-proposed)
  • Revision ID: james.westby@ubuntu.com-20101217123020-o02fhyzykv5z98ri
Tags: 0.96.5+dfsg-1ubuntu1.10.10.1
* Microversion update for Maverick (LP: #691414)
  - Improved database login times
  - Expanded use of new bytecode signatures
  - Other bugfixes/improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
  class X86TargetMachine;
25
25
 
26
26
namespace X86 {
 
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.
 
31
  enum {
 
32
    AddrBaseReg = 0,
 
33
    AddrScaleAmt = 1,
 
34
    AddrIndexReg = 2,
 
35
    AddrDisp = 3,
 
36
    
 
37
    /// AddrSegmentReg - The operand # of the segment in the memory operand.
 
38
    AddrSegmentReg = 4,
 
39
 
 
40
    /// AddrNumOperands - Total number of operands in a memory reference.
 
41
    AddrNumOperands = 5
 
42
  };
 
43
  
 
44
  
27
45
  // X86 specific condition code. These correspond to X86_*_COND in
28
46
  // X86InstrInfo.td. They must be kept in synch.
29
47
  enum CondCode {
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
175
193
    /// stub.
176
 
    MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE
 
194
    MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE,
 
195
    
 
196
    /// MO_TLVP - On a symbol operand this indicates that the immediate is
 
197
    /// some TLS offset.
 
198
    ///
 
199
    /// This is the TLS offset for the Darwin TLS mechanism.
 
200
    MO_TLVP,
 
201
    
 
202
    /// MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate
 
203
    /// is some TLS offset from the picbase.
 
204
    ///
 
205
    /// This is the 32-bit TLS offset for Darwin TLS in PIC mode.
 
206
    MO_TLVP_PIC_BASE
177
207
  };
178
208
}
179
209
 
203
233
  case X86II::MO_PIC_BASE_OFFSET:                // Darwin local global.
204
234
  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:        // Darwin/32 external global.
205
235
  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global.
 
236
  case X86II::MO_TLVP:                           // ??? Pretty sure..
206
237
    return true;
207
238
  default:
208
239
    return false;
280
311
    MRM_F0 = 40,
281
312
    MRM_F8 = 41,
282
313
    MRM_F9 = 42,
 
314
    
 
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
 
319
    RawFrmImm16 = 43,
283
320
 
284
321
    FormMask       = 63,
285
322
 
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,
353
391
 
354
392
    //===------------------------------------------------------------------===//
355
393
    // FP Instruction Classification...  Zero is non-fp instruction.
398
436
    FS          = 1 << SegOvrShift,
399
437
    GS          = 2 << SegOvrShift,
400
438
 
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.
 
441
    SSEDomainShift = 22,
 
442
 
402
443
    OpcodeShift   = 24,
403
 
    OpcodeMask    = 0xFF << OpcodeShift
 
444
    OpcodeMask    = 0xFF << OpcodeShift,
 
445
 
 
446
    //===------------------------------------------------------------------===//
 
447
    // VEX - The opcode prefix used by AVX instructions
 
448
    VEX         = 1U << 0,
 
449
 
 
450
    // VEX_W - Has a opcode specific functionality, but is used in the same
 
451
    // way as REX_W is for regular SSE instructions.
 
452
    VEX_W       = 1U << 1,
 
453
 
 
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.
 
457
    VEX_4V      = 1U << 2,
 
458
 
 
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.
 
462
    VEX_I8IMM   = 1U << 3,
 
463
 
 
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.
 
468
    VEX_L       = 1U << 4
404
469
  };
405
470
  
406
471
  // getBaseOpcodeFor - This function returns the "base" X86 opcode for the
407
472
  // specified machine instruction.
408
473
  //
409
 
  static inline unsigned char getBaseOpcodeFor(unsigned TSFlags) {
 
474
  static inline unsigned char getBaseOpcodeFor(uint64_t TSFlags) {
410
475
    return TSFlags >> X86II::OpcodeShift;
411
476
  }
412
477
  
413
 
  static inline bool hasImm(unsigned TSFlags) {
 
478
  static inline bool hasImm(uint64_t TSFlags) {
414
479
    return (TSFlags & X86II::ImmMask) != 0;
415
480
  }
416
481
  
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;
 
489
    case X86II::Imm16:
 
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;
430
496
  
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:
438
 
        return true;
439
 
      case X86II::Imm8:
440
 
      case X86II::Imm16:
441
 
      case X86II::Imm32:
442
 
      case X86II::Imm64:
443
 
        return false;
444
 
    }
445
 
  }    
 
501
    default: assert(0 && "Unknown immediate size");
 
502
    case X86II::Imm8PCRel:
 
503
    case X86II::Imm16PCRel:
 
504
    case X86II::Imm32PCRel:
 
505
      return true;
 
506
    case X86II::Imm8:
 
507
    case X86II::Imm16:
 
508
    case X86II::Imm32:
 
509
    case X86II::Imm64:
 
510
      return false;
 
511
    }
 
512
  }
 
513
  
 
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.
 
517
  ///
 
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.
 
521
  ///
 
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!");
 
526
    case X86II::Pseudo:
 
527
    case X86II::RawFrm:
 
528
    case X86II::AddRegFrm:
 
529
    case X86II::MRMDestReg:
 
530
    case X86II::MRMSrcReg:
 
531
    case X86II::RawFrmImm16:
 
532
       return -1;
 
533
    case X86II::MRMDestMem:
 
534
      return 0;
 
535
    case X86II::MRMSrcMem: {
 
536
      bool HasVEX_4V = (TSFlags >> 32) & X86II::VEX_4V;
 
537
      unsigned FirstMemOp = 1;
 
538
      if (HasVEX_4V)
 
539
        ++FirstMemOp;// Skip the register source (which is encoded in VEX_VVVV).
 
540
      
 
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)
 
544
      return FirstMemOp;
 
545
    }
 
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:
 
550
      return -1;
 
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:
 
555
      return 0;
 
556
    case X86II::MRM_C1:
 
557
    case X86II::MRM_C2:
 
558
    case X86II::MRM_C3:
 
559
    case X86II::MRM_C4:
 
560
    case X86II::MRM_C8:
 
561
    case X86II::MRM_C9:
 
562
    case X86II::MRM_E8:
 
563
    case X86II::MRM_F0:
 
564
    case X86II::MRM_F8:
 
565
    case X86II::MRM_F9:
 
566
      return -1;
 
567
    }
 
568
  }
446
569
}
447
570
 
448
 
const int X86AddrNumOperands = 5;
449
 
 
450
571
inline static bool isScale(const MachineOperand &MO) {
451
572
  return MO.isImm() &&
452
573
    (MO.getImm() == 1 || MO.getImm() == 2 ||
486
607
  /// MemOp2RegOpTable - Load / store unfolding opcode map.
487
608
  ///
488
609
  DenseMap<unsigned*, std::pair<unsigned, unsigned> > MemOp2RegOpTable;
489
 
  
 
610
 
490
611
public:
491
612
  explicit X86InstrInfo(X86TargetMachine &tm);
492
613
 
496
617
  ///
497
618
  virtual const X86RegisterInfo &getRegisterInfo() const { return RI; }
498
619
 
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;
504
 
 
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;
556
671
 
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,
 
701
                                DebugLoc DL) const;
 
702
  virtual void copyPhysReg(MachineBasicBlock &MBB,
 
703
                           MachineBasicBlock::iterator MI, DebugLoc DL,
 
704
                           unsigned DestReg, unsigned SrcReg,
 
705
                           bool KillSrc) const;
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;
595
711
 
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;
607
724
 
608
725
  virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
609
726
                               SmallVectorImpl<MachineOperand> &Addr,
614
731
  
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;
618
736
 
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;
622
741
  
 
742
  virtual
 
743
  MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
 
744
                                         int FrameIx, uint64_t Offset,
 
745
                                         const MDNode *MDPtr,
 
746
                                         DebugLoc DL) const;
 
747
 
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
684
809
                                       int64_t Offset1, int64_t Offset2,
685
810
                                       unsigned NumLoads) const;
686
811
 
 
812
  virtual void getNoopForMachoTarget(MCInst &NopInst) const;
 
813
 
687
814
  virtual
688
815
  bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
689
816
 
700
827
    if (!MO.isReg()) return false;
701
828
    return isX86_64ExtendedReg(MO.getReg());
702
829
  }
703
 
  static unsigned determineREX(const MachineInstr &MI);
704
830
 
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);
708
834
 
709
 
  /// GetInstSize - Returns the size of the specified MachineInstr.
710
 
  ///
711
 
  virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
712
 
 
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.
716
838
  ///
717
839
  unsigned getGlobalBaseReg(MachineFunction *MF) const;
718
840
 
 
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;
 
844
 
 
845
  /// SetSSEDomain - Set the SSEDomain of MI.
 
846
  void SetSSEDomain(MachineInstr *MI, unsigned Domain) const;
 
847
 
719
848
private:
720
849
  MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
721
850
                                              MachineFunction::iterator &MFI,