X86InstrInfo.h revision 7478ab8502a52815413d8b388898f719484ab1a9
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
77ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    MO_NO_FLAG = 0,
78ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner
79ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    /// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a
80ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    /// relocation of:
8155e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner    ///    SYMBOL_LABEL + [. - PICBASELABEL]
82ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    MO_GOT_ABSOLUTE_ADDRESS = 1,
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
8755e7c827301da0e5e03b26835bff259c320b3bf7Chris Lattner    MO_PIC_BASE_OFFSET = 2,
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
94b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_GOT = 3,
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
101b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_GOTOFF = 4,
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
109b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_GOTPCREL = 5,
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
116b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_PLT = 6,
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
123b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_TLSGD = 7,
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
130b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_GOTTPOFF = 8,
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
137b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_INDNTPOFF = 9,
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
144b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_TPOFF = 10,
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
151b903bed0feaa35a2b5e404923db724a62b433787Chris Lattner    MO_NTPOFF = 11,
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.
1564aa21aa6d13b8ea00eb0817e53f24e5416ed3038Chris Lattner    MO_DLLIMPORT = 12,
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.
16174e726e3270c99169cc90fb3c676eeaae273f48cChris Lattner    MO_DARWIN_STUB = 13,
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.
16675cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    MO_DARWIN_NONLAZY = 14,
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.
17175cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    MO_DARWIN_NONLAZY_PIC_BASE = 15,
17275cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner
17375cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// MO_DARWIN_HIDDEN_NONLAZY - On a symbol operand "FOO", this indicates
17475cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// that the reference is actually to the "FOO$non_lazy_ptr" symbol, which
17575cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// is a non-PIC-base-relative reference to a hidden dyld lazy pointer stub.
17675cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    MO_DARWIN_HIDDEN_NONLAZY = 16,
17775cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner
17875cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this
17975cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE",
18075cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// which is a PIC-base-relative reference to a hidden dyld lazy pointer
18175cdf27f48f0b81f778b6aa50efcefa0497a9daeChris Lattner    /// stub.
182281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner    MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE = 17
183281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  };
184281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner}
185281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner
1863b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattner/// isGlobalStubReference - Return true if the specified TargetFlag operand is
187281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner/// a reference to a stub for a global, not the global itself.
1883b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattnerinline static bool isGlobalStubReference(unsigned char TargetFlag) {
1893b6b36d6f54e780a2947cb1b9efe4eed7c40dc11Chris Lattner  switch (TargetFlag) {
190281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DLLIMPORT: // dllimport stub.
191281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_GOTPCREL:  // rip-relative GOT reference.
192281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_GOT:       // normal GOT reference.
193281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:        // Normal $non_lazy_ptr ref.
194281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DARWIN_NONLAZY:                 // Normal $non_lazy_ptr ref.
195281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Hidden $non_lazy_ptr ref.
196281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  case X86II::MO_DARWIN_HIDDEN_NONLAZY:          // Hidden $non_lazy_ptr ref.
197281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner    return true;
198281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  default:
199281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner    return false;
200281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  }
201281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner}
2027478ab8502a52815413d8b388898f719484ab1a9Chris Lattner
2037478ab8502a52815413d8b388898f719484ab1a9Chris Lattner/// isGlobalRelativeToPICBase - Return true if the specified global value
2047478ab8502a52815413d8b388898f719484ab1a9Chris Lattner/// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg).  If this
2057478ab8502a52815413d8b388898f719484ab1a9Chris Lattner/// is true, the addressing mode has the PIC base register added in (e.g. EBX).
2067478ab8502a52815413d8b388898f719484ab1a9Chris Lattnerinline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
2077478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  switch (TargetFlag) {
2087478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_GOTOFF:                         // isPICStyleGOT: local global.
2097478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_GOT:                            // isPICStyleGOT: other global.
2107478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_PIC_BASE_OFFSET:                // Darwin local global.
2117478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_DARWIN_NONLAZY_PIC_BASE:        // Darwin/32 external global.
2127478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global.
2137478ab8502a52815413d8b388898f719484ab1a9Chris Lattner    return true;
2147478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  default:
2157478ab8502a52815413d8b388898f719484ab1a9Chris Lattner    return false;
2167478ab8502a52815413d8b388898f719484ab1a9Chris Lattner  }
2177478ab8502a52815413d8b388898f719484ab1a9Chris Lattner}
218281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner
219281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner/// X86II - This namespace holds all of the target specific flags that
220281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner/// instruction info tracks.
221281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner///
222281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattnernamespace X86II {
223281bada3b03b97dad0ac9890706a057ab31a5dd3Chris Lattner  enum {
224ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    //===------------------------------------------------------------------===//
225ac5e887a6cf0a6182664d8c11beb0d2270272b02Chris Lattner    // Instruction encodings.  These are the standard/most common forms for X86
2266aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    // instructions.
2276aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    //
2286aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2294c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // PseudoFrm - This represents an instruction that is a pseudo instruction
2304c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // or one that has not been implemented yet.  It is illegal to code generate
2314c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // it, but tolerated for intermediate implementation stages.
2324c299f5da1013cd36563a82f188c731b2758074dChris Lattner    Pseudo         = 0,
2334c299f5da1013cd36563a82f188c731b2758074dChris Lattner
2346aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// Raw - This form is for instructions that don't have any operands, so
2356aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// they are just a fixed opcode value, like 'leave'.
2364c299f5da1013cd36563a82f188c731b2758074dChris Lattner    RawFrm         = 1,
2370e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman
2386aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// AddRegFrm - This form is used for instructions like 'push r32' that have
2396aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// their one register operand added to their opcode.
2404c299f5da1013cd36563a82f188c731b2758074dChris Lattner    AddRegFrm      = 2,
2416aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2426aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMDestReg - This form is used for instructions that use the Mod/RM byte
2436aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a destination, which in this case is a register.
2446aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2454c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMDestReg     = 3,
2466aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2476aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMDestMem - This form is used for instructions that use the Mod/RM byte
2486aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a destination, which in this case is memory.
2496aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2504c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMDestMem     = 4,
2516aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2526aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMSrcReg - This form is used for instructions that use the Mod/RM byte
2536aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a source, which in this case is a register.
2546aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2554c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMSrcReg      = 5,
2566aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2576aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// MRMSrcMem - This form is used for instructions that use the Mod/RM byte
2586aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    /// to specify a source, which in this case is memory.
2596aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    ///
2604c299f5da1013cd36563a82f188c731b2758074dChris Lattner    MRMSrcMem      = 6,
2610e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman
262169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    /// MRM[0-7][rm] - These forms are used to represent instructions that use
26385b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    /// a Mod/RM byte, and use the middle field to hold extended opcode
26485b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    /// information.  In the intel manual these are represented as /0, /1, ...
26585b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    ///
26685b39f229f3146e57d059f1c774400e4bde23987Chris Lattner
26785b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    // First, instructions that operate on a register r/m operand...
268169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM0r = 16,  MRM1r = 17,  MRM2r = 18,  MRM3r = 19, // Format /0 /1 /2 /3
269169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM4r = 20,  MRM5r = 21,  MRM6r = 22,  MRM7r = 23, // Format /4 /5 /6 /7
27085b39f229f3146e57d059f1c774400e4bde23987Chris Lattner
27185b39f229f3146e57d059f1c774400e4bde23987Chris Lattner    // Next, instructions that operate on a memory r/m operand...
272169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM0m = 24,  MRM1m = 25,  MRM2m = 26,  MRM3m = 27, // Format /0 /1 /2 /3
273169584ed45f62f91599bed3d019640e168d815eaAlkis Evlogimenos    MRM4m = 28,  MRM5m = 29,  MRM6m = 30,  MRM7m = 31, // Format /4 /5 /6 /7
2746aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2753c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    // MRMInitReg - This form is used for instructions whose source and
2763c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    // destinations are the same register.
2773c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    MRMInitReg = 32,
2783c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng
2793c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    FormMask       = 63,
2806aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
2816aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    //===------------------------------------------------------------------===//
2826aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner    // Actual flags...
2836aab9cf65cd1e96f9d0fa99f8453da454648bba1Chris Lattner
28411e53e3c384e9e25f53a0aec3acf0a725efafeabChris Lattner    // OpSize - Set if this instruction requires an operand size prefix (0x66),
28511e53e3c384e9e25f53a0aec3acf0a725efafeabChris Lattner    // which most often indicates that the instruction operates on 16 bit data
28611e53e3c384e9e25f53a0aec3acf0a725efafeabChris Lattner    // instead of 32 bit data.
2873c55c54a877b3e5a79053df8f6080f505c9d1ff4Evan Cheng    OpSize      = 1 << 6,
2884c299f5da1013cd36563a82f188c731b2758074dChris Lattner
28925ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // AsSize - Set if this instruction requires an operand size prefix (0x67),
29025ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // which most often indicates that the instruction address 16 bit address
29125ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // instead of 32 bit address (or 32 bit address in 64 bit mode).
29225ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    AdSize      = 1 << 7,
29325ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng
29425ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    //===------------------------------------------------------------------===//
2954c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // Op0Mask - There are several prefix bytes that are used to form two byte
296915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // opcodes.  These are currently 0x0F, 0xF3, and 0xD8-0xDF.  This mask is
297915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // used to obtain the setting of this field.  If no bits in this field is
298915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // set, there is no prefix byte for obtaining a multibyte opcode.
2994c299f5da1013cd36563a82f188c731b2758074dChris Lattner    //
30025ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    Op0Shift    = 8,
3012959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    Op0Mask     = 0xF << Op0Shift,
3024c299f5da1013cd36563a82f188c731b2758074dChris Lattner
3034c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // TB - TwoByte - Set if this instruction has a two byte opcode, which
3044c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // starts with a 0x0F byte before the real opcode.
3052959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    TB          = 1 << Op0Shift,
3064c299f5da1013cd36563a82f188c731b2758074dChris Lattner
307915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // REP - The 0xF3 prefix byte indicating repetition of the following
308915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    // instruction.
309915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    REP         = 2 << Op0Shift,
310915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner
3114c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // D8-DF - These escape opcodes are used by the floating point unit.  These
3124c299f5da1013cd36563a82f188c731b2758074dChris Lattner    // values must remain sequential.
313915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    D8 = 3 << Op0Shift,   D9 = 4 << Op0Shift,
314915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    DA = 5 << Op0Shift,   DB = 6 << Op0Shift,
315915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    DC = 7 << Op0Shift,   DD = 8 << Op0Shift,
316915e5e56d7cc8e140d33202eed6244ed0356ed1fChris Lattner    DE = 9 << Op0Shift,   DF = 10 << Op0Shift,
3179eb59ec548b861d6ede05b4e6dc22aabf645e665Jeff Cohen
318f63be7d3959939b2ffaf0bba5519b71216ec9ee6Nate Begeman    // XS, XD - These prefix codes are for single and double precision scalar
319f63be7d3959939b2ffaf0bba5519b71216ec9ee6Nate Begeman    // floating point operations performed in the SSE registers.
320bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling    XD = 11 << Op0Shift,  XS = 12 << Op0Shift,
321bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling
322bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling    // T8, TA - Prefix after the 0x0F prefix.
323bb1ee05253d965e0944351a21e9970c02b1aebfeBill Wendling    T8 = 13 << Op0Shift,  TA = 14 << Op0Shift,
3244c299f5da1013cd36563a82f188c731b2758074dChris Lattner
3250c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    //===------------------------------------------------------------------===//
32625ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // REX_W - REX prefixes are instruction prefixes used in 64-bit mode.
32725ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // They are used to specify GPRs and SSE registers, 64-bit operand size,
32825ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // etc. We only cares about REX.W and REX.R bits and only the former is
32925ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // statically determined.
33025ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    //
33125ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    REXShift    = 12,
33225ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    REX_W       = 1 << REXShift,
33325ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng
33425ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    //===------------------------------------------------------------------===//
33525ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    // This three-bit field describes the size of an immediate operand.  Zero is
3365ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    // unused so that we can tell if we forgot to set a value.
33725ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    ImmShift = 13,
33825ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    ImmMask  = 7 << ImmShift,
3395ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    Imm8     = 1 << ImmShift,
3405ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    Imm16    = 2 << ImmShift,
3415ab29b504d49d3fa84d76f79e73704260f900682Alkis Evlogimenos    Imm32    = 3 << ImmShift,
34225ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    Imm64    = 4 << ImmShift,
3434c299f5da1013cd36563a82f188c731b2758074dChris Lattner
3440c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    //===------------------------------------------------------------------===//
3450c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // FP Instruction Classification...  Zero is non-fp instruction.
3460c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3472959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    // FPTypeMask - Mask for all of the FP types...
34825ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    FPTypeShift = 16,
3492959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    FPTypeMask  = 7 << FPTypeShift,
3502959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner
35179b13735adcc034a6869f1fd5670051c6dd0a28aChris Lattner    // NotFP - The default, set for instructions that do not use FP registers.
35279b13735adcc034a6869f1fd5670051c6dd0a28aChris Lattner    NotFP      = 0 << FPTypeShift,
35379b13735adcc034a6869f1fd5670051c6dd0a28aChris Lattner
3540c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0
3552959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    ZeroArgFP  = 1 << FPTypeShift,
3560c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3570c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst
3582959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    OneArgFP   = 2 << FPTypeShift,
3590c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3600c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a
3610c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // result back to ST(0).  For example, fcos, fsqrt, etc.
3620c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    //
3632959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    OneArgFPRW = 3 << FPTypeShift,
3640c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
3650c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an
3660c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // explicit argument, storing the result to either ST(0) or the implicit
3670c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // argument.  For example: fadd, fsub, fmul, etc...
3682959b6ec49be09096cf0a5e7504d2a1ec15ef2b3Chris Lattner    TwoArgFP   = 4 << FPTypeShift,
3690c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner
370ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    // CompareFP - 2 arg FP instructions which implicitly read ST(0) and an
371ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    // explicit argument, but have no destination.  Example: fucom, fucomi, ...
372ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    CompareFP  = 5 << FPTypeShift,
373ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner
3741c54a8544788156d6864430182a3a79b8839b7daChris Lattner    // CondMovFP - "2 operand" floating point conditional move instructions.
375ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    CondMovFP  = 6 << FPTypeShift,
3761c54a8544788156d6864430182a3a79b8839b7daChris Lattner
3770c514f4e2711ab57bf75f26806f7b8584dfbee6fChris Lattner    // SpecialFP - Special instruction forms.  Dispatch by opcode explicitly.
378ab8deccb82460527562d1c36a787537e4edaa9ddChris Lattner    SpecialFP  = 7 << FPTypeShift,
3791c54a8544788156d6864430182a3a79b8839b7daChris Lattner
380ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth    // Lock prefix
381ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth    LOCKShift = 19,
382ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth    LOCK = 1 << LOCKShift,
383ea7da50e5a7f291295c10d91fc3fdba76d339579Andrew Lenharth
384ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    // Segment override prefixes. Currently we just need ability to address
385ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    // stuff in gs and fs segments.
386ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    SegOvrShift = 20,
387ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    SegOvrMask  = 3 << SegOvrShift,
388ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    FS          = 1 << SegOvrShift,
389ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    GS          = 2 << SegOvrShift,
390ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov
391ef93cecd80ebdecb0ea2b2c316370998151308e2Anton Korobeynikov    // Bits 22 -> 23 are unused
39225ab690a43cbbb591b76d49e3595b019c32f4b3fEvan Cheng    OpcodeShift   = 24,
393d74ea2bbd8bb630331f35ead42d385249bd42af8Chris Lattner    OpcodeMask    = 0xFF << OpcodeShift
3949d17740295838f94120646ef619b2e187f2d71bdChris Lattner  };
3959d17740295838f94120646ef619b2e187f2d71bdChris Lattner}
3969d17740295838f94120646ef619b2e187f2d71bdChris Lattner
397094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindolaconst int X86AddrNumOperands = 5;
398da945e3bb2069c1a7194bcd10579a03ff925a031Rafael Espindola
3991c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikovinline static bool isScale(const MachineOperand &MO) {
400d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman  return MO.isImm() &&
4011c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov    (MO.getImm() == 1 || MO.getImm() == 2 ||
4021c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov     MO.getImm() == 4 || MO.getImm() == 8);
4031c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov}
4041c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov
405094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindolainline static bool isLeaMem(const MachineInstr *MI, unsigned Op) {
406d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman  if (MI->getOperand(Op).isFI()) return true;
4071c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov  return Op+4 <= MI->getNumOperands() &&
408d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman    MI->getOperand(Op  ).isReg() && isScale(MI->getOperand(Op+1)) &&
409d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman    MI->getOperand(Op+2).isReg() &&
410d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman    (MI->getOperand(Op+3).isImm() ||
411d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman     MI->getOperand(Op+3).isGlobal() ||
412d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman     MI->getOperand(Op+3).isCPI() ||
413d735b8019b0f297d7c14b55adcd887af24d8e602Dan Gohman     MI->getOperand(Op+3).isJTI());
4141c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov}
4151c4b5eaa4628935c4db3e422aa10f2031e6d1679Anton Korobeynikov
416094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindolainline static bool isMem(const MachineInstr *MI, unsigned Op) {
417094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola  if (MI->getOperand(Op).isFI()) return true;
418094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola  return Op+5 <= MI->getNumOperands() &&
419094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola    MI->getOperand(Op+4).isReg() &&
420094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola    isLeaMem(MI, Op);
421094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola}
422094fad37b90946c91a09eb9270a0dbe800f49d87Rafael Espindola
423641055225092833197efe8e5bce01d50bcf1daaeChris Lattnerclass X86InstrInfo : public TargetInstrInfoImpl {
424aa3c1410b427909da350f2b5e8d4ec3db62a3618Evan Cheng  X86TargetMachine &TM;
425726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  const X86RegisterInfo RI;
42643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
42743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// RegOp2MemOpTable2Addr, RegOp2MemOpTable0, RegOp2MemOpTable1,
42843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// RegOp2MemOpTable2 - Load / store folding opcode maps.
42943dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  ///
43043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  DenseMap<unsigned*, unsigned> RegOp2MemOpTable2Addr;
43143dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  DenseMap<unsigned*, unsigned> RegOp2MemOpTable0;
43243dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  DenseMap<unsigned*, unsigned> RegOp2MemOpTable1;
43343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  DenseMap<unsigned*, unsigned> RegOp2MemOpTable2;
43443dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
43543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// MemOp2RegOpTable - Load / store unfolding opcode map.
43643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  ///
43743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  DenseMap<unsigned*, std::pair<unsigned, unsigned> > MemOp2RegOpTable;
43843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
439726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattnerpublic:
440950a4c40b823cd4f09dc71be635229246dfd6cacDan Gohman  explicit X86InstrInfo(X86TargetMachine &tm);
441726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
4423501feab811c86c9659248a4875fc31a3165f84dChris Lattner  /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
443726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  /// such, whenever a client has an instance of instruction info, it should
444726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  /// always be able to get register info as well (through this method).
445726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner  ///
446c9f5f3f64f896d0a8c8fa35a1dd98bc57b8960f6Dan Gohman  virtual const X86RegisterInfo &getRegisterInfo() const { return RI; }
447726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
44804ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng  /// Return true if the instruction is a register to register move and return
44904ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng  /// the source and dest operands and their sub-register indices by reference.
45004ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng  virtual bool isMoveInstr(const MachineInstr &MI,
45104ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng                           unsigned &SrcReg, unsigned &DstReg,
45204ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng                           unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
45304ee5a1d9267e5e6fab8f088095fcb83c3c5cbd1Evan Cheng
454cbad42cfd1cc93a41ff26ea2e8895bfbc09f54f2Dan Gohman  unsigned isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const;
455cbad42cfd1cc93a41ff26ea2e8895bfbc09f54f2Dan Gohman  unsigned isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const;
456ca1267c02b025cc719190b05f9e1a5d174a9caf7Evan Cheng
4579f8fea3531f8f8d04d1e183ff570be37d41d13f5Bill Wendling  bool isReallyTriviallyReMaterializable(const MachineInstr *MI) const;
458ca1267c02b025cc719190b05f9e1a5d174a9caf7Evan Cheng  void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
459ca1267c02b025cc719190b05f9e1a5d174a9caf7Evan Cheng                     unsigned DestReg, const MachineInstr *Orig) const;
460ca1267c02b025cc719190b05f9e1a5d174a9caf7Evan Cheng
461cbad42cfd1cc93a41ff26ea2e8895bfbc09f54f2Dan Gohman  bool isInvariantLoad(const MachineInstr *MI) const;
462627c00b663f881600b4af1ae135af6ee2cb19c1aBill Wendling
463bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// convertToThreeAddress - This method must be implemented by targets that
464bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
465bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// may be able to convert a two-address instruction into a true
466bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// three-address instruction on demand.  This allows the X86 target (for
467bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// example) to convert ADD and SHL instructions into LEA instructions if they
468bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// would require register copies due to two-addressness.
469bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  ///
470bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// This method returns a null pointer if the transformation cannot be
471bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  /// performed, otherwise it returns the new instruction.
472bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner  ///
473ba59a1e453e110f7b84233f07613f9c5d9a39b87Evan Cheng  virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
474ba59a1e453e110f7b84233f07613f9c5d9a39b87Evan Cheng                                              MachineBasicBlock::iterator &MBBI,
475f660c171c838793b87b7e58e91609cecf256378dOwen Anderson                                              LiveVariables *LV) const;
476bcea4d6f283a5ae6f93dc8e10898311fe53d23a3Chris Lattner
47741e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner  /// commuteInstruction - We have a few instructions that must be hacked on to
47841e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner  /// commute them.
47941e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner  ///
48058dcb0e0cd3fa973b5fd005aecab1df6aeea5cd6Evan Cheng  virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const;
48141e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner
4827fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  // Branch analysis.
483318093b6f8d21ac8eab34573b0526984895fe941Dale Johannesen  virtual bool isUnpredicatedTerminator(const MachineInstr* MI) const;
4847fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner  virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
4857fbe9723e32ff35c4ad765c88209ef9321475a1bChris Lattner                             MachineBasicBlock *&FBB,
486dc54d317e7a381ef8e4aca80d54ad1466bb85ddaEvan Cheng                             SmallVectorImpl<MachineOperand> &Cond,
487dc54d317e7a381ef8e4aca80d54ad1466bb85ddaEvan Cheng                             bool AllowModify) const;
4886ae3626a4fda14e6250ac8d8ff487efb8952cdf7Evan Cheng  virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
4896ae3626a4fda14e6250ac8d8ff487efb8952cdf7Evan Cheng  virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
4906ae3626a4fda14e6250ac8d8ff487efb8952cdf7Evan Cheng                                MachineBasicBlock *FBB,
49144eb65cf58e3ab9b5621ce72256d1621a18aeed7Owen Anderson                            const SmallVectorImpl<MachineOperand> &Cond) const;
492940f83e772ca2007d62faffc83094bd7e8da6401Owen Anderson  virtual bool copyRegToReg(MachineBasicBlock &MBB,
493d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            MachineBasicBlock::iterator MI,
494d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            unsigned DestReg, unsigned SrcReg,
495d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            const TargetRegisterClass *DestRC,
496d10fd9791c20fd8368fa0ce94b626b769c6c8ba0Owen Anderson                            const TargetRegisterClass *SrcRC) const;
497f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
498f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                   MachineBasicBlock::iterator MI,
499f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                   unsigned SrcReg, bool isKill, int FrameIndex,
500f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                   const TargetRegisterClass *RC) const;
501f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson
502f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
503f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                              SmallVectorImpl<MachineOperand> &Addr,
504f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                              const TargetRegisterClass *RC,
505f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                              SmallVectorImpl<MachineInstr*> &NewMIs) const;
506f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson
507f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
508f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                    MachineBasicBlock::iterator MI,
509f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                    unsigned DestReg, int FrameIndex,
510f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                                    const TargetRegisterClass *RC) const;
511f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson
512f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson  virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
513f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                               SmallVectorImpl<MachineOperand> &Addr,
514f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                               const TargetRegisterClass *RC,
515f6372aa1cc568df19da7c5023e83c75aa9404a07Owen Anderson                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
516d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson
517d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson  virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
518d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                         MachineBasicBlock::iterator MI,
519d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                 const std::vector<CalleeSavedInfo> &CSI) const;
520d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson
521d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson  virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
522d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                           MachineBasicBlock::iterator MI,
523d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson                                 const std::vector<CalleeSavedInfo> &CSI) const;
524d94b6a16fec7d5021e3922b0e34f9ddb268d54b1Owen Anderson
52543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// foldMemoryOperand - If this target supports it, fold a load or store of
52643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// the specified stack slot into the specified machine instruction for the
52743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// specified operand(s).  If this is possible, the target should perform the
52843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// folding and return true, otherwise it should return false.  If it folds
52943dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// the instruction, it is likely that the MachineInstruction the iterator
53043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// references has been changed.
531c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman  virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
532c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              MachineInstr* MI,
533c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                           const SmallVectorImpl<unsigned> &Ops,
534c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              int FrameIndex) const;
53543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
53643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// foldMemoryOperand - Same as the previous version except it allows folding
53743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// of any load and store from / to any address, not just from a specific
53843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// stack slot.
539c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman  virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
540c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              MachineInstr* MI,
541c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                           const SmallVectorImpl<unsigned> &Ops,
542c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                              MachineInstr* LoadMI) const;
54343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
54443dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// canFoldMemoryOperand - Returns true if the specified load / store is
54543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// folding is possible.
5468e8b8a223c2b0e69f44c0639f846260c8011668fDan Gohman  virtual bool canFoldMemoryOperand(const MachineInstr*,
5478e8b8a223c2b0e69f44c0639f846260c8011668fDan Gohman                                    const SmallVectorImpl<unsigned> &) const;
54843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
54943dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// unfoldMemoryOperand - Separate a single instruction which folded a load or
55043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// a store or a load and a store into two or more instruction. If this is
55143dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// possible, returns true as well as the new instructions by reference.
55243dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
55343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson                           unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
55443dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson                           SmallVectorImpl<MachineInstr*> &NewMIs) const;
55543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
55643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
55743dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson                           SmallVectorImpl<SDNode*> &NewNodes) const;
55843dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
55943dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
56043dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// instruction after load / store are unfolded from an instruction of the
56143dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// specified opcode. It returns zero if the specified unfolding is not
56243dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  /// possible.
56343dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson  virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
56443dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson                                      bool UnfoldLoad, bool UnfoldStore) const;
56543dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
5668e8b8a223c2b0e69f44c0639f846260c8011668fDan Gohman  virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
56744eb65cf58e3ab9b5621ce72256d1621a18aeed7Owen Anderson  virtual
56844eb65cf58e3ab9b5621ce72256d1621a18aeed7Owen Anderson  bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
56941e431ba045eb317ebf0ec45b563a5d96c212f5cChris Lattner
5704350eb86a7cdc83fa6a5f4819a7f0534ace5cd58Evan Cheng  /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
5714350eb86a7cdc83fa6a5f4819a7f0534ace5cd58Evan Cheng  /// instruction that defines the specified register class.
5724350eb86a7cdc83fa6a5f4819a7f0534ace5cd58Evan Cheng  bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const;
57323066288fdf4867f53f208f9aaf2952b1c049394Evan Cheng
574f21dfcddcf199444440004bfa74bb222e2d3ce9eChris Lattner  // getBaseOpcodeFor - This function returns the "base" X86 opcode for the
575ee465749313579ccd91575ca8acf70b75c221a2cDuncan Sands  // specified machine instruction.
576f21dfcddcf199444440004bfa74bb222e2d3ce9eChris Lattner  //
577749c6f6b5ed301c84aac562e414486549d7b98ebChris Lattner  unsigned char getBaseOpcodeFor(const TargetInstrDesc *TID) const {
57819f2ffce4598c4c70f32eed7c6740b43185200b1Evan Cheng    return TID->TSFlags >> X86II::OpcodeShift;
5794d18d5ce1e62779e7736ca0811e2e1cb06e4ea36Chris Lattner  }
580cc8cd0cbf12c12916d4b38ef0de5be5501c8270eChris Lattner  unsigned char getBaseOpcodeFor(unsigned Opcode) const {
581ee465749313579ccd91575ca8acf70b75c221a2cDuncan Sands    return getBaseOpcodeFor(&get(Opcode));
582ee465749313579ccd91575ca8acf70b75c221a2cDuncan Sands  }
58352e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray
58452e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static bool isX86_64NonExtLowByteReg(unsigned reg) {
58552e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray    return (reg == X86::SPL || reg == X86::BPL ||
58652e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray          reg == X86::SIL || reg == X86::DIL);
58752e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  }
58852e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray
58952e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static unsigned sizeOfImm(const TargetInstrDesc *Desc);
59052e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static bool isX86_64ExtendedReg(const MachineOperand &MO);
59152e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  static unsigned determineREX(const MachineInstr &MI);
59252e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray
59352e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  /// GetInstSize - Returns the size of the specified MachineInstr.
59452e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  ///
59552e724ad7e679ee590f4bd763d55280586a8f1bcNicolas Geoffray  virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
59643dbe05279b753aabda571d9c83eaeb36987001aOwen Anderson
59757c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  /// getGlobalBaseReg - Return a virtual register initialized with the
59857c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  /// the global base register value. Output instructions required to
59957c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  /// initialize the register in the function entry block, if necessary.
6008b746969baee26237e4c52de9862d06795eabcdaDan Gohman  ///
60157c3dac0df7ac1b53ae7c0e5d2adc459fc7bd37cDan Gohman  unsigned getGlobalBaseReg(MachineFunction *MF) const;
6028b746969baee26237e4c52de9862d06795eabcdaDan Gohman
60343dbe05279b753aabda571d9c83eaeb36987001aOwen Andersonprivate:
604c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman  MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
605c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                      MachineInstr* MI,
606c54baa2d43730f1804acfb4f4e738fba72f966bdDan Gohman                                      unsigned OpNum,
607d68a07650cdb2e18f18f362ba533459aa10e01b6Dan Gohman                                      const SmallVectorImpl<MachineOperand> &MOs) const;
608726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner};
609726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner
610d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
611d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
612726140821f96e3472a8eccef0c67c0b5ad65a1d9Chris Lattner#endif
613