X86InstrInfo.h revision a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2
11e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//===- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*- ===//
20e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman//
3856ba76200ec2302f2fe500bc507f426c7d566c8John Criswell//                     The LLVM Compiler Infrastructure
4856ba76200ec2302f2fe500bc507f426c7d566c8John Criswell//
54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source
64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details.
70e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman//
8856ba76200ec2302f2fe500bc507f426c7d566c8John Criswell//===----------------------------------------------------------------------===//
9726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner//
103501feab811c86c9659248a4875fc31a3165f84dChris Lattner// This file contains the X86 implementation of the TargetInstrInfo class.
11726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner//
12726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner//===----------------------------------------------------------------------===//
13726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
14726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner#ifndef X86INSTRUCTIONINFO_H
15726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner#define X86INSTRUCTIONINFO_H
16726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
173501feab811c86c9659248a4875fc31a3165f84dChris Lattner#include "llvm/Target/TargetInstrInfo.h"
1852e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray#include "X86.h"
19726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner#include "X86RegisterInfo.h"
20d68a07650cdb2e18f18f362ba533459aa10e01b6Dan Gohman#include "llvm/ADT/DenseMap.h"
216f0d024a534af18d9e60b3ea757376cd8a3a980eDan Gohman#include "llvm/Target/TargetRegisterInfo.h"
22726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
2425ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng  class X86RegisterInfo;
25aa3c1410b427909da350f2b5e8d4ec3db62a3618Evan Cheng  class X86TargetMachine;
26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
277fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattnernamespace X86 {
287fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  // X86 specific condition code. These correspond to X86_*_COND in
297fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  // X86InstrInfo.td. They must be kept in synch.
307fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  enum CondCode {
317fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_A  = 0,
327fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_AE = 1,
337fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_B  = 2,
347fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_BE = 3,
357fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_E  = 4,
367fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_G  = 5,
377fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_GE = 6,
387fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_L  = 7,
397fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_LE = 8,
407fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_NE = 9,
417fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_NO = 10,
427fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_NP = 11,
437fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_NS = 12,
44653456c351d9bf908ebd982f6ae9df3449c5f34bDan Gohman    COND_O  = 13,
45653456c351d9bf908ebd982f6ae9df3449c5f34bDan Gohman    COND_P  = 14,
46653456c351d9bf908ebd982f6ae9df3449c5f34bDan Gohman    COND_S  = 15,
47279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman
48279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman    // Artificial condition codes. These are used by AnalyzeBranch
49279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman    // to indicate a block terminated with two conditional branches to
50279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman    // the same location. This occurs in code using FCMP_OEQ or FCMP_UNE,
51279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman    // which can't be represented on x86 with a single condition. These
52279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman    // are never used in MachineInstrs.
53279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman    COND_NE_OR_P,
54279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman    COND_NP_OR_E,
55279c22e6da2612f024b70e5509ffb0cad32f38b2Dan Gohman
567fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner    COND_INVALID
577fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  };
586634e26aa11b0e2eabde8b3b463bb943364f8d9dChristopher Lamb
597fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  // Turn condition code into conditional branch opcode.
607fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  unsigned GetCondBranchFromCond(CondCode CC);
619cd68759178f9fe25c72253d338e78e414f1d770Chris Lattner
629cd68759178f9fe25c72253d338e78e414f1d770Chris Lattner  /// GetOppositeBranchCondition - Return the inverse of the specified cond,
639cd68759178f9fe25c72253d338e78e414f1d770Chris Lattner  /// e.g. turning COND_E to COND_NE.
649cd68759178f9fe25c72253d338e78e414f1d770Chris Lattner  CondCode GetOppositeBranchCondition(X86::CondCode CC);
659cd68759178f9fe25c72253d338e78e414f1d770Chris Lattner
667fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner}
677fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner
689d17740295838f94120646ef619b2e187f2d71bdChris Lattner/// X86II - This namespace holds all of the target specific flags that
699d17740295838f94120646ef619b2e187f2d71bdChris Lattner/// instruction info tracks.
709d17740295838f94120646ef619b2e187f2d71bdChris Lattner///
719d17740295838f94120646ef619b2e187f2d71bdChris Lattnernamespace X86II {
723b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattner  /// Target Operand Flag enum.
733b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattner  enum TOF {
746aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    //===------------------------------------------------------------------===//
75ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    // X86 Specific MachineOperand flags.
76ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner
7701a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_NO_FLAG,
78ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner
79ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    /// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a
80ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    /// relocation of:
8155e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner    ///    SYMBOL_LABEL + [. - PICBASELABEL]
8201a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_GOT_ABSOLUTE_ADDRESS,
83ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner
8455e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner    /// MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the
8555e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner    /// immediate should get the value of the symbol minus the PIC base label:
8655e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner    ///    SYMBOL_LABEL - PICBASELABEL
8701a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_PIC_BASE_OFFSET,
8855e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner
89b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_GOT - On a symbol operand this indicates that the immediate is the
90b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// offset to the GOT entry for the symbol name from the base of the GOT.
91b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
92b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See the X86-64 ELF ABI supplement for more details.
93b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @GOT
9401a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_GOT,
95b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner
96b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_GOTOFF - On a symbol operand this indicates that the immediate is
97b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// the offset to the location of the symbol name from the base of the GOT.
98b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
99b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See the X86-64 ELF ABI supplement for more details.
10055e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner    ///    SYMBOL_LABEL @GOTOFF
10101a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_GOTOFF,
102b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner
103b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_GOTPCREL - On a symbol operand this indicates that the immediate is
104b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// offset to the GOT entry for the symbol name from the current code
105b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// location.
106b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
107b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See the X86-64 ELF ABI supplement for more details.
108b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @GOTPCREL
10901a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_GOTPCREL,
110b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner
111b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_PLT - On a symbol operand this indicates that the immediate is
112b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// offset to the PLT entry of symbol name from the current code location.
113b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
114b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See the X86-64 ELF ABI supplement for more details.
115b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @PLT
11601a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_PLT,
117b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner
118b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_TLSGD - On a symbol operand this indicates that the immediate is
119b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// some TLS offset.
120b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
121b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See 'ELF Handling for Thread-Local Storage' for more details.
122b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @TLSGD
12301a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_TLSGD,
124b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner
125b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is
126b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// some TLS offset.
127b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
128b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See 'ELF Handling for Thread-Local Storage' for more details.
129b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @GOTTPOFF
13001a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_GOTTPOFF,
131b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner
132b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_INDNTPOFF - On a symbol operand this indicates that the immediate is
133b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// some TLS offset.
134b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
135b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See 'ELF Handling for Thread-Local Storage' for more details.
136b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @INDNTPOFF
13701a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_INDNTPOFF,
138b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner
139b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_TPOFF - On a symbol operand this indicates that the immediate is
140b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// some TLS offset.
141b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
142b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See 'ELF Handling for Thread-Local Storage' for more details.
143b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @TPOFF
14401a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_TPOFF,
14555e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner
146b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// MO_NTPOFF - On a symbol operand this indicates that the immediate is
147b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// some TLS offset.
148b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///
149b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    /// See 'ELF Handling for Thread-Local Storage' for more details.
150b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    ///    SYMBOL_LABEL @NTPOFF
15101a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_NTPOFF,
152ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner
1534aa21aa6d13b8ea00eb0817e53f24e5416ed3038Chris Lattner    /// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the
1544aa21aa6d13b8ea00eb0817e53f24e5416ed3038Chris Lattner    /// reference is actually to the "__imp_FOO" symbol.  This is used for
1554aa21aa6d13b8ea00eb0817e53f24e5416ed3038Chris Lattner    /// dllimport linkage on windows.
15601a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_DLLIMPORT,
1574aa21aa6d13b8ea00eb0817e53f24e5416ed3038Chris Lattner
15874e726e3270c99169cc90fb3c676eeaae273f48cChris Lattner    /// MO_DARWIN_STUB - On a symbol operand "FOO", this indicates that the
15974e726e3270c99169cc90fb3c676eeaae273f48cChris Lattner    /// reference is actually to the "FOO$stub" symbol.  This is used for calls
16074e726e3270c99169cc90fb3c676eeaae273f48cChris Lattner    /// and jumps to external functions on Tiger and before.
16101a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_DARWIN_STUB,
16274e726e3270c99169cc90fb3c676eeaae273f48cChris Lattner
16375cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the
16475cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a
16575cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub.
16601a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_DARWIN_NONLAZY,
16775cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner
16875cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates
16975cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is
17075cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub.
17101a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_DARWIN_NONLAZY_PIC_BASE,
17275cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner
17375cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this
17475cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE",
17575cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// which is a PIC-base-relative reference to a hidden dyld lazy pointer
17675cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// stub.
17701a76ce8d910c0ffee89beaa3819d3448791950fDan Gohman    MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE
178281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  };
179281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner}
180281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner
1813b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattner/// isGlobalStubReference - Return true if the specified TargetFlag operand is
182281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner/// a reference to a stub for a global, not the global itself.
1833b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattnerinline static bool isGlobalStubReference(unsigned char TargetFlag) {
1843b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattner  switch (TargetFlag) {
185281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DLLIMPORT: // dllimport stub.
186281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_GOTPCREL:  // rip-relative GOT reference.
187281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_GOT:       // normal GOT reference.
188281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:        // Normal $non_lazy_ptr ref.
189281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DARWIN_NONLAZY:                 // Normal $non_lazy_ptr ref.
190281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Hidden $non_lazy_ptr ref.
191281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner    return true;
192281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  default:
193281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner    return false;
194281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  }
195281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner}
1967478ab8502a52815413d8b388898f719484ab1a9Chris Lattner
1977478ab8502a52815413d8b388898f719484ab1a9Chris Lattner/// isGlobalRelativeToPICBase - Return true if the specified global value
1987478ab8502a52815413d8b388898f719484ab1a9Chris Lattner/// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg).  If this
1997478ab8502a52815413d8b388898f719484ab1a9Chris Lattner/// is true, the addressing mode has the PIC base register added in (e.g. EBX).
2007478ab8502a52815413d8b388898f719484ab1a9Chris Lattnerinline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
2017478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  switch (TargetFlag) {
2027478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_GOTOFF:                         // isPICStyleGOT: local global.
2037478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_GOT:                            // isPICStyleGOT: other global.
2047478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_PIC_BASE_OFFSET:                // Darwin local global.
2057478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:        // Darwin/32 external global.
2067478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global.
2077478ab8502a52815413d8b388898f719484ab1a9Chris Lattner    return true;
2087478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  default:
2097478ab8502a52815413d8b388898f719484ab1a9Chris Lattner    return false;
2107478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  }
2117478ab8502a52815413d8b388898f719484ab1a9Chris Lattner}
212281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner
213281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner/// X86II - This namespace holds all of the target specific flags that
214281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner/// instruction info tracks.
215281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner///
216281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattnernamespace X86II {
217281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  enum {
218ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    //===------------------------------------------------------------------===//
219ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    // Instruction encodings.  These are the standard/most common forms for X86
2206aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    // instructions.
2216aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    //
2226aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2234c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // PseudoFrm - This represents an instruction that is a pseudo instruction
2244c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // or one that has not been implemented yet.  It is illegal to code generate
2254c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // it, but tolerated for intermediate implementation stages.
2264c299f5da1013cd36563a82f188c731b2758074dChris Lattner    Pseudo         = 0,
2274c299f5da1013cd36563a82f188c731b2758074dChris Lattner
2286aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// Raw - This form is for instructions that don't have any operands, so
2296aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// they are just a fixed opcode value, like 'leave'.
2304c299f5da1013cd36563a82f188c731b2758074dChris Lattner    RawFrm         = 1,
2310e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman
2326aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// AddRegFrm - This form is used for instructions like 'push r32' that have
2336aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// their one register operand added to their opcode.
2344c299f5da1013cd36563a82f188c731b2758074dChris Lattner    AddRegFrm      = 2,
2356aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2366aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMDestReg - This form is used for instructions that use the Mod/RM byte
2376aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a destination, which in this case is a register.
2386aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2394c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMDestReg     = 3,
2406aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2416aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMDestMem - This form is used for instructions that use the Mod/RM byte
2426aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a destination, which in this case is memory.
2436aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2444c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMDestMem     = 4,
2456aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2466aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMSrcReg - This form is used for instructions that use the Mod/RM byte
2476aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a source, which in this case is a register.
2486aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2494c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMSrcReg      = 5,
2506aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2516aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMSrcMem - This form is used for instructions that use the Mod/RM byte
2526aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a source, which in this case is memory.
2536aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2544c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMSrcMem      = 6,
2550e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman
256169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    /// MRM[0-7][rm] - These forms are used to represent instructions that use
25785b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    /// a Mod/RM byte, and use the middle field to hold extended opcode
25885b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    /// information.  In the intel manual these are represented as /0, /1, ...
25985b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    ///
26085b39f229f3146e57d059f1c774400e4bde23987Chris Lattner
26185b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    // First, instructions that operate on a register r/m operand...
262169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM0r = 16,  MRM1r = 17,  MRM2r = 18,  MRM3r = 19, // Format /0 /1 /2 /3
263169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM4r = 20,  MRM5r = 21,  MRM6r = 22,  MRM7r = 23, // Format /4 /5 /6 /7
26485b39f229f3146e57d059f1c774400e4bde23987Chris Lattner
26585b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    // Next, instructions that operate on a memory r/m operand...
266169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM0m = 24,  MRM1m = 25,  MRM2m = 26,  MRM3m = 27, // Format /0 /1 /2 /3
267169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM4m = 28,  MRM5m = 29,  MRM6m = 30,  MRM7m = 31, // Format /4 /5 /6 /7
2686aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2693c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    // MRMInitReg - This form is used for instructions whose source and
2703c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    // destinations are the same register.
2713c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    MRMInitReg = 32,
2723c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng
2733c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    FormMask       = 63,
2746aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2756aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    //===------------------------------------------------------------------===//
2766aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    // Actual flags...
2776aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
27811e53e3c384e9e25f53a0aec3acf0a725efafeabChris Lattner    // OpSize - Set if this instruction requires an operand size prefix (0x66),
27911e53e3c384e9e25f53a0aec3acf0a725efafeabChris Lattner    // which most often indicates that the instruction operates on 16 bit data
28011e53e3c384e9e25f53a0aec3acf0a725efafeabChris Lattner    // instead of 32 bit data.
2813c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    OpSize      = 1 << 6,
2824c299f5da1013cd36563a82f188c731b2758074dChris Lattner
28325ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // AsSize - Set if this instruction requires an operand size prefix (0x67),
28425ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // which most often indicates that the instruction address 16 bit address
28525ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // instead of 32 bit address (or 32 bit address in 64 bit mode).
28625ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    AdSize      = 1 << 7,
28725ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng
28825ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    //===------------------------------------------------------------------===//
2894c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // Op0Mask - There are several prefix bytes that are used to form two byte
290915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // opcodes.  These are currently 0x0F, 0xF3, and 0xD8-0xDF.  This mask is
291915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // used to obtain the setting of this field.  If no bits in this field is
292915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // set, there is no prefix byte for obtaining a multibyte opcode.
2934c299f5da1013cd36563a82f188c731b2758074dChris Lattner    //
29425ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    Op0Shift    = 8,
2952959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    Op0Mask     = 0xF << Op0Shift,
2964c299f5da1013cd36563a82f188c731b2758074dChris Lattner
2974c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // TB - TwoByte - Set if this instruction has a two byte opcode, which
2984c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // starts with a 0x0F byte before the real opcode.
2992959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    TB          = 1 << Op0Shift,
3004c299f5da1013cd36563a82f188c731b2758074dChris Lattner
301915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // REP - The 0xF3 prefix byte indicating repetition of the following
302915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // instruction.
303915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    REP         = 2 << Op0Shift,
304915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner
3054c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // D8-DF - These escape opcodes are used by the floating point unit.  These
3064c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // values must remain sequential.
307915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    D8 = 3 << Op0Shift,   D9 = 4 << Op0Shift,
308915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    DA = 5 << Op0Shift,   DB = 6 << Op0Shift,
309915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    DC = 7 << Op0Shift,   DD = 8 << Op0Shift,
310915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    DE = 9 << Op0Shift,   DF = 10 << Op0Shift,
3119eb59ec548b861d6ede05b4e6dc22aabf645e665Jeff Cohen
312f63be7d3959939b2ffaf0bba5519b71216ec9ee6Nate Begeman    // XS, XD - These prefix codes are for single and double precision scalar
313f63be7d3959939b2ffaf0bba5519b71216ec9ee6Nate Begeman    // floating point operations performed in the SSE registers.
314bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling    XD = 11 << Op0Shift,  XS = 12 << Op0Shift,
315bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling
316bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling    // T8, TA - Prefix after the 0x0F prefix.
317bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling    T8 = 13 << Op0Shift,  TA = 14 << Op0Shift,
318b4dc13cab7ef894d3bb17657fa993b9f09af476bEric Christopher
319b4dc13cab7ef894d3bb17657fa993b9f09af476bEric Christopher    // TF - Prefix before and after 0x0F
320b4dc13cab7ef894d3bb17657fa993b9f09af476bEric Christopher    TF = 15 << Op0Shift,
3214c299f5da1013cd36563a82f188c731b2758074dChris Lattner
3220c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    //===------------------------------------------------------------------===//
32325ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // REX_W - REX prefixes are instruction prefixes used in 64-bit mode.
32425ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // They are used to specify GPRs and SSE registers, 64-bit operand size,
32525ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // etc. We only cares about REX.W and REX.R bits and only the former is
32625ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // statically determined.
32725ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    //
32825ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    REXShift    = 12,
32925ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    REX_W       = 1 << REXShift,
33025ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng
33125ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    //===------------------------------------------------------------------===//
33225ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // This three-bit field describes the size of an immediate operand.  Zero is
3335ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    // unused so that we can tell if we forgot to set a value.
33425ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    ImmShift = 13,
33525ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    ImmMask  = 7 << ImmShift,
3365ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    Imm8     = 1 << ImmShift,
3375ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    Imm16    = 2 << ImmShift,
3385ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    Imm32    = 3 << ImmShift,
33925ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    Imm64    = 4 << ImmShift,
3404c299f5da1013cd36563a82f188c731b2758074dChris Lattner
3410c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    //===------------------------------------------------------------------===//
3420c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // FP Instruction Classification...  Zero is non-fp instruction.
3430c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3442959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    // FPTypeMask - Mask for all of the FP types...
34525ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    FPTypeShift = 16,
3462959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    FPTypeMask  = 7 << FPTypeShift,
3472959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner
34879b13735adcc034a6869f1fd5670051c6dd0a28aChris Lattner    // NotFP - The default, set for instructions that do not use FP registers.
34979b13735adcc034a6869f1fd5670051c6dd0a28aChris Lattner    NotFP      = 0 << FPTypeShift,
35079b13735adcc034a6869f1fd5670051c6dd0a28aChris Lattner
3510c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0
3522959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    ZeroArgFP  = 1 << FPTypeShift,
3530c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3540c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst
3552959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    OneArgFP   = 2 << FPTypeShift,
3560c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3570c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a
3580c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // result back to ST(0).  For example, fcos, fsqrt, etc.
3590c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    //
3602959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    OneArgFPRW = 3 << FPTypeShift,
3610c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3620c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an
3630c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // explicit argument, storing the result to either ST(0) or the implicit
3640c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // argument.  For example: fadd, fsub, fmul, etc...
3652959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    TwoArgFP   = 4 << FPTypeShift,
3660c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
367ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    // CompareFP - 2 arg FP instructions which implicitly read ST(0) and an
368ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    // explicit argument, but have no destination.  Example: fucom, fucomi, ...
369ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    CompareFP  = 5 << FPTypeShift,
370ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner
3711c54a8544788156d6864430182a3a79b8839b7daChris Lattner    // CondMovFP - "2 operand" floating point conditional move instructions.
372ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    CondMovFP  = 6 << FPTypeShift,
3731c54a8544788156d6864430182a3a79b8839b7daChris Lattner
3740c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // SpecialFP - Special instruction forms.  Dispatch by opcode explicitly.
375ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    SpecialFP  = 7 << FPTypeShift,
3761c54a8544788156d6864430182a3a79b8839b7daChris Lattner
377ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth    // Lock prefix
378ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth    LOCKShift = 19,
379ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth    LOCK = 1 << LOCKShift,
380ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth
381ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    // Segment override prefixes. Currently we just need ability to address
382ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    // stuff in gs and fs segments.
383ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    SegOvrShift = 20,
384ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    SegOvrMask  = 3 << SegOvrShift,
385ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    FS          = 1 << SegOvrShift,
386ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    GS          = 2 << SegOvrShift,
387ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov
388ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    // Bits 22 -> 23 are unused
38925ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    OpcodeShift   = 24,
390d74ea2bbd8bb630331f35ead42d385249bd42af8Chris Lattner    OpcodeMask    = 0xFF << OpcodeShift
3919d17740295838f94120646ef619b2e187f2d71bdChris Lattner  };
3929d17740295838f94120646ef619b2e187f2d71bdChris Lattner}
3939d17740295838f94120646ef619b2e187f2d71bdChris Lattner
394094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindolaconst int X86AddrNumOperands = 5;
395da945e3bb2069c1a7194bcd10579a03ff925a031Rafael Espindola
3961c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikovinline static bool isScale(const MachineOperand &MO) {
397d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman  return MO.isImm() &&
3981c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov    (MO.getImm() == 1 || MO.getImm() == 2 ||
3991c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov     MO.getImm() == 4 || MO.getImm() == 8);
4001c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov}
4011c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov
402094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindolainline static bool isLeaMem(const MachineInstr *MI, unsigned Op) {
403d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman  if (MI->getOperand(Op).isFI()) return true;
4041c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov  return Op+4 <= MI->getNumOperands() &&
405d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman    MI->getOperand(Op  ).isReg() && isScale(MI->getOperand(Op+1)) &&
406d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman    MI->getOperand(Op+2).isReg() &&
407d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman    (MI->getOperand(Op+3).isImm() ||
408d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman     MI->getOperand(Op+3).isGlobal() ||
409d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman     MI->getOperand(Op+3).isCPI() ||
410d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman     MI->getOperand(Op+3).isJTI());
4111c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov}
4121c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov
413094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindolainline static bool isMem(const MachineInstr *MI, unsigned Op) {
414094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola  if (MI->getOperand(Op).isFI()) return true;
415094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola  return Op+5 <= MI->getNumOperands() &&
416094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola    MI->getOperand(Op+4).isReg() &&
417094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola    isLeaMem(MI, Op);
418094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola}
419094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola
420641055225092833197efe8e5bce01d50bcf1daaeChris Lattnerclass X86InstrInfo : public TargetInstrInfoImpl {
421aa3c1410b427909da350f2b5e8d4ec3db62a3618Evan Cheng  X86TargetMachine &TM;
422726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  const X86RegisterInfo RI;
42343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
42443dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// RegOp2MemOpTable2Addr, RegOp2MemOpTable0, RegOp2MemOpTable1,
42543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// RegOp2MemOpTable2 - Load / store folding opcode maps.
42643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  ///
427f9b36f08efbc66670910a8a85dd89f03d36196d4Evan Cheng  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable2Addr;
428f9b36f08efbc66670910a8a85dd89f03d36196d4Evan Cheng  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable0;
429f9b36f08efbc66670910a8a85dd89f03d36196d4Evan Cheng  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable1;
430f9b36f08efbc66670910a8a85dd89f03d36196d4Evan Cheng  DenseMap<unsigned*, std::pair<unsigned,unsigned> > RegOp2MemOpTable2;
43143dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
43243dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// MemOp2RegOpTable - Load / store unfolding opcode map.
43343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  ///
43443dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  DenseMap<unsigned*, std::pair<unsigned, unsigned> > MemOp2RegOpTable;
43543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
436726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattnerpublic:
437950a4c40b823cd4f09dc71be635229246dfd6cacDan Gohman  explicit X86InstrInfo(X86TargetMachine &tm);
438726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
4393501feab811c86c9659248a4875fc31a3165f84dChris Lattner  /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
440726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  /// such, whenever a client has an instance of instruction info, it should
441726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  /// always be able to get register info as well (through this method).
442726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  ///
443c9f5f3f64f896d0a8c8fa35a1dd98bc57b8960f6Dan Gohman  virtual const X86RegisterInfo &getRegisterInfo() const { return RI; }
444726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
44504ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng  /// Return true if the instruction is a register to register move and return
44604ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng  /// the source and dest operands and their sub-register indices by reference.
44704ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng  virtual bool isMoveInstr(const MachineInstr &MI,
44804ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng                           unsigned &SrcReg, unsigned &DstReg,
44904ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng                           unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
45004ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng
451a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng  /// isCoalescableInstr - Return true if the instruction is "coalescable". That
452a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng  /// is, it's like a copy where it's legal for the source to overlap the
453a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng  /// destination. e.g. X86::MOVSX64rr32.
454a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng  virtual bool isCoalescableInstr(const MachineInstr &MI, bool &isCopy,
455a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng                                unsigned &SrcReg, unsigned &DstReg,
456a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng                                unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
457a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng
458a5a81d70720a4ce6ac7538927c2a874b0dfa8bd2Evan Cheng
459cbad42cfd1cc93a41ff26ea2e8895bfbc09f54f2Dan Gohman  unsigned isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const;
460dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
461dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  /// stack locations as well.  This uses a heuristic so it isn't
462dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  /// reliable for correctness.
463dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
464dda3978d7877d2d60390833c73ed24857295e89cDavid Greene                                     int &FrameIndex) const;
465b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene
466b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// hasLoadFromStackSlot - If the specified machine instruction has
467b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// a load from a stack slot, return true along with the FrameIndex
46829dbf50b180bb3342af84ff042a3ff06405c5071David Greene  /// of the loaded stack slot and the machine mem operand containing
46929dbf50b180bb3342af84ff042a3ff06405c5071David Greene  /// the reference.  If not, return false.  Unlike
470b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// isLoadFromStackSlot, this returns true for any instructions that
471b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// loads from the stack.  This is a hint only and may not catch all
472b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// cases.
47329dbf50b180bb3342af84ff042a3ff06405c5071David Greene  bool hasLoadFromStackSlot(const MachineInstr *MI,
47429dbf50b180bb3342af84ff042a3ff06405c5071David Greene                            const MachineMemOperand *&MMO,
47529dbf50b180bb3342af84ff042a3ff06405c5071David Greene                            int &FrameIndex) const;
476b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene
477cbad42cfd1cc93a41ff26ea2e8895bfbc09f54f2Dan Gohman  unsigned isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const;
478dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
479dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  /// stack locations as well.  This uses a heuristic so it isn't
480dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  /// reliable for correctness.
481dda3978d7877d2d60390833c73ed24857295e89cDavid Greene  unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
482dda3978d7877d2d60390833c73ed24857295e89cDavid Greene                                    int &FrameIndex) const;
483ca1267c02b025cc719190b05f9e1a5d174a9caf7Evan Cheng
484b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// hasStoreToStackSlot - If the specified machine instruction has a
485b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// store to a stack slot, return true along with the FrameIndex of
48629dbf50b180bb3342af84ff042a3ff06405c5071David Greene  /// the loaded stack slot and the machine mem operand containing the
48729dbf50b180bb3342af84ff042a3ff06405c5071David Greene  /// reference.  If not, return false.  Unlike isStoreToStackSlot,
48829dbf50b180bb3342af84ff042a3ff06405c5071David Greene  /// this returns true for any instructions that loads from the
48929dbf50b180bb3342af84ff042a3ff06405c5071David Greene  /// stack.  This is a hint only and may not catch all cases.
49029dbf50b180bb3342af84ff042a3ff06405c5071David Greene  bool hasStoreToStackSlot(const MachineInstr *MI,
49129dbf50b180bb3342af84ff042a3ff06405c5071David Greene                           const MachineMemOperand *&MMO,
49229dbf50b180bb3342af84ff042a3ff06405c5071David Greene                           int &FrameIndex) const;
493b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene
4943731bc026cc6c4fb7deb7ac67e2c3be0c22498beDan Gohman  bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
4953731bc026cc6c4fb7deb7ac67e2c3be0c22498beDan Gohman                                         AliasAnalysis *AA) const;
496ca1267c02b025cc719190b05f9e1a5d174a9caf7Evan Cheng  void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
497378445303b10b092a898a75131141a8259cff50bEvan Cheng                     unsigned DestReg, unsigned SubIdx,
498d57cdd5683ea926e489067364fb7ffe5fd5d35eeEvan Cheng                     const MachineInstr *Orig,
499d57cdd5683ea926e489067364fb7ffe5fd5d35eeEvan Cheng                     const TargetRegisterInfo *TRI) const;
500ca1267c02b025cc719190b05f9e1a5d174a9caf7Evan Cheng
501bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// convertToThreeAddress - This method must be implemented by targets that
502bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
503bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// may be able to convert a two-address instruction into a true
504bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// three-address instruction on demand.  This allows the X86 target (for
505bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// example) to convert ADD and SHL instructions into LEA instructions if they
506bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// would require register copies due to two-addressness.
507bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  ///
508bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// This method returns a null pointer if the transformation cannot be
509bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// performed, otherwise it returns the new instruction.
510bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  ///
511ba59a1e453e110f7b84233f07613f9c5d9a39b87Evan Cheng  virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
512ba59a1e453e110f7b84233f07613f9c5d9a39b87Evan Cheng                                              MachineBasicBlock::iterator &MBBI,
513f660c171c838793b87b7e58e91609cecf256378dOwen Anderson                                              LiveVariables *LV) const;
514bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner
51541e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner  /// commuteInstruction - We have a few instructions that must be hacked on to
51641e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner  /// commute them.
51741e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner  ///
51858dcb0e0cd3fa973b5fd005aecab1df6aeea5cd6Evan Cheng  virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const;
51941e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner
5207fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  // Branch analysis.
521318093b6f8d21ac8eab34573b0526984895fe941Dale Johannesen  virtual bool isUnpredicatedTerminator(const MachineInstr* MI) const;
5227fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
5237fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner                             MachineBasicBlock *&FBB,
524dc54d317e7a381ef8e4aca80d54ad1466bb85ddaEvan Cheng                             SmallVectorImpl<MachineOperand> &Cond,
525dc54d317e7a381ef8e4aca80d54ad1466bb85ddaEvan Cheng                             bool AllowModify) const;
5266ae3626a4fda14e6250ac8d8ff487efb8952cdf7Evan Cheng  virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
5276ae3626a4fda14e6250ac8d8ff487efb8952cdf7Evan Cheng  virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
5286ae3626a4fda14e6250ac8d8ff487efb8952cdf7Evan Cheng                                MachineBasicBlock *FBB,
52944eb65cf58e3ab9b5621ce72256d1621a18aeed7Owen Anderson                            const SmallVectorImpl<MachineOperand> &Cond) const;
530940f83e772ca2007d62faffc83094bd7e8da6401Owen Anderson  virtual bool copyRegToReg(MachineBasicBlock &MBB,
531d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            MachineBasicBlock::iterator MI,
532d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            unsigned DestReg, unsigned SrcReg,
533d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            const TargetRegisterClass *DestRC,
534d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            const TargetRegisterClass *SrcRC) const;
535f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
536f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                   MachineBasicBlock::iterator MI,
537f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                   unsigned SrcReg, bool isKill, int FrameIndex,
538f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                   const TargetRegisterClass *RC) const;
539f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson
540f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
541f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                              SmallVectorImpl<MachineOperand> &Addr,
542f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                              const TargetRegisterClass *RC,
54391e69c37153eb7d8cd149d9c2484c3115027b90fDan Gohman                              MachineInstr::mmo_iterator MMOBegin,
54491e69c37153eb7d8cd149d9c2484c3115027b90fDan Gohman                              MachineInstr::mmo_iterator MMOEnd,
545f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                              SmallVectorImpl<MachineInstr*> &NewMIs) const;
546f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson
547f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
548f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                    MachineBasicBlock::iterator MI,
549f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                    unsigned DestReg, int FrameIndex,
550f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                    const TargetRegisterClass *RC) const;
551f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson
552f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
553f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                               SmallVectorImpl<MachineOperand> &Addr,
554f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                               const TargetRegisterClass *RC,
55591e69c37153eb7d8cd149d9c2484c3115027b90fDan Gohman                               MachineInstr::mmo_iterator MMOBegin,
55691e69c37153eb7d8cd149d9c2484c3115027b90fDan Gohman                               MachineInstr::mmo_iterator MMOEnd,
557f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
558d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson
559d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson  virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
560d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                         MachineBasicBlock::iterator MI,
561d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                 const std::vector<CalleeSavedInfo> &CSI) const;
562d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson
563d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson  virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
564d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                           MachineBasicBlock::iterator MI,
565d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                 const std::vector<CalleeSavedInfo> &CSI) const;
566d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson
56743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// foldMemoryOperand - If this target supports it, fold a load or store of
56843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// the specified stack slot into the specified machine instruction for the
56943dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// specified operand(s).  If this is possible, the target should perform the
57043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// folding and return true, otherwise it should return false.  If it folds
57143dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// the instruction, it is likely that the MachineInstruction the iterator
57243dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// references has been changed.
573c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman  virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
574c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              MachineInstr* MI,
575c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                           const SmallVectorImpl<unsigned> &Ops,
576c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              int FrameIndex) const;
57743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
57843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// foldMemoryOperand - Same as the previous version except it allows folding
57943dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// of any load and store from / to any address, not just from a specific
58043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// stack slot.
581c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman  virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
582c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              MachineInstr* MI,
583c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                           const SmallVectorImpl<unsigned> &Ops,
584c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              MachineInstr* LoadMI) const;
58543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
58643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// canFoldMemoryOperand - Returns true if the specified load / store is
58743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// folding is possible.
5888e8b8a223c2b0e69f44c0639f846260c8011668fDan Gohman  virtual bool canFoldMemoryOperand(const MachineInstr*,
5898e8b8a223c2b0e69f44c0639f846260c8011668fDan Gohman                                    const SmallVectorImpl<unsigned> &) const;
59043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
59143dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// unfoldMemoryOperand - Separate a single instruction which folded a load or
59243dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// a store or a load and a store into two or more instruction. If this is
59343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// possible, returns true as well as the new instructions by reference.
59443dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
59543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson                           unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
59643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson                           SmallVectorImpl<MachineInstr*> &NewMIs) const;
59743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
59843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
59943dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson                           SmallVectorImpl<SDNode*> &NewNodes) const;
60043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
60143dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
60243dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// instruction after load / store are unfolded from an instruction of the
60343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// specified opcode. It returns zero if the specified unfolding is not
6040115e164bad632572e2cfbaf72f0f0882d5319deDan Gohman  /// possible. If LoadRegIndex is non-null, it is filled in with the operand
6050115e164bad632572e2cfbaf72f0f0882d5319deDan Gohman  /// index of the operand which will hold the register holding the loaded
6060115e164bad632572e2cfbaf72f0f0882d5319deDan Gohman  /// value.
60743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
6080115e164bad632572e2cfbaf72f0f0882d5319deDan Gohman                                      bool UnfoldLoad, bool UnfoldStore,
6090115e164bad632572e2cfbaf72f0f0882d5319deDan Gohman                                      unsigned *LoadRegIndex = 0) const;
61043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
61144eb65cf58e3ab9b5621ce72256d1621a18aeed7Owen Anderson  virtual
61244eb65cf58e3ab9b5621ce72256d1621a18aeed7Owen Anderson  bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
61341e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner
6144350eb86a7cdc83fa6a5f4819a7f0534ace5cd58Evan Cheng  /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
6154350eb86a7cdc83fa6a5f4819a7f0534ace5cd58Evan Cheng  /// instruction that defines the specified register class.
6164350eb86a7cdc83fa6a5f4819a7f0534ace5cd58Evan Cheng  bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const;
61723066288fdf4867f53f208f9aaf2952b1c049394Evan Cheng
618f21dfcddcf199444440004bfa74bb222e2d3ce9eChris Lattner  // getBaseOpcodeFor - This function returns the "base" X86 opcode for the
619ee465749313579ccd91575ca8acf70b75c221a2cDuncan Sands  // specified machine instruction.
620f21dfcddcf199444440004bfa74bb222e2d3ce9eChris Lattner  //
621749c6f6b5ed301c84aac562e414486549d7b98ebChris Lattner  unsigned char getBaseOpcodeFor(const TargetInstrDesc *TID) const {
62219f2ffce4598c4c70f32eed7c6740b43185200b1Evan Cheng    return TID->TSFlags >> X86II::OpcodeShift;
6234d18d5ce1e62779e7736ca0811e2e1cb06e4ea36Chris Lattner  }
624cc8cd0cbf12c12916d4b38ef0de5be5501c8270eChris Lattner  unsigned char getBaseOpcodeFor(unsigned Opcode) const {
625ee465749313579ccd91575ca8acf70b75c221a2cDuncan Sands    return getBaseOpcodeFor(&get(Opcode));
626ee465749313579ccd91575ca8acf70b75c221a2cDuncan Sands  }
62752e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray
62852e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static bool isX86_64NonExtLowByteReg(unsigned reg) {
62952e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray    return (reg == X86::SPL || reg == X86::BPL ||
63052e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray          reg == X86::SIL || reg == X86::DIL);
63152e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  }
63252e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray
63352e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static unsigned sizeOfImm(const TargetInstrDesc *Desc);
63452e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static bool isX86_64ExtendedReg(const MachineOperand &MO);
63552e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static unsigned determineREX(const MachineInstr &MI);
63652e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray
63752e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  /// GetInstSize - Returns the size of the specified MachineInstr.
63852e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  ///
63952e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
64043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
64157c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  /// getGlobalBaseReg - Return a virtual register initialized with the
64257c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  /// the global base register value. Output instructions required to
64357c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  /// initialize the register in the function entry block, if necessary.
6448b746969baee26237e4c52de9862d06795eabcdaDan Gohman  ///
64557c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  unsigned getGlobalBaseReg(MachineFunction *MF) const;
6468b746969baee26237e4c52de9862d06795eabcdaDan Gohman
64743dbe05279b753aabda571d9c83eaeb36987001aOwen Andersonprivate:
648656e51454ac70f5d500565fd33c883f6dea549f2Evan Cheng  MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
649656e51454ac70f5d500565fd33c883f6dea549f2Evan Cheng                                              MachineFunction::iterator &MFI,
650656e51454ac70f5d500565fd33c883f6dea549f2Evan Cheng                                              MachineBasicBlock::iterator &MBBI,
651656e51454ac70f5d500565fd33c883f6dea549f2Evan Cheng                                              LiveVariables *LV) const;
652656e51454ac70f5d500565fd33c883f6dea549f2Evan Cheng
653c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman  MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
654f9b36f08efbc66670910a8a85dd89f03d36196d4Evan Cheng                                     MachineInstr* MI,
655f9b36f08efbc66670910a8a85dd89f03d36196d4Evan Cheng                                     unsigned OpNum,
656f9b36f08efbc66670910a8a85dd89f03d36196d4Evan Cheng                                     const SmallVectorImpl<MachineOperand> &MOs,
6579cef48eae9a4776ef2f42687072e7c61cb33e10dEvan Cheng                                     unsigned Size, unsigned Alignment) const;
658b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene
659b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// isFrameOperand - Return true and the FrameIndex if the specified
660b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  /// operand and follow operands form a reference to the stack frame.
661b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene  bool isFrameOperand(const MachineInstr *MI, unsigned int Op,
662b87bc95db075dae3033a3c541b55b4cb711c332cDavid Greene                      int &FrameIndex) const;
663726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner};
664726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
665d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
666d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
667726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner#endif
668