TargetInstrInfo.h revision f6e8e6bace845cbbb6c1f6d859ffd8a3a154222b
1075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner//===-- llvm/Target/TargetInstrInfo.h - Instruction Info --------*- C++ -*-===//
234695381d626485a560594f162701088079589dfMisha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
56fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// This file was developed by the LLVM research group and is distributed under
66fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details.
734695381d626485a560594f162701088079589dfMisha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve//
10a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve// This file describes the target machine instructions to the code generator.
11a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve//
12f6d12fbd9cc0355978a739f5ab213eff85b75a19Chris Lattner//===----------------------------------------------------------------------===//
13a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
143501feab811c86c9659248a4875fc31a3165f84dChris Lattner#ifndef LLVM_TARGET_TARGETINSTRINFO_H
153501feab811c86c9659248a4875fc31a3165f84dChris Lattner#define LLVM_TARGET_TARGETINSTRINFO_H
16a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
17905f7af59cb85ea71b6c011f1e79f24f8db16efcAlkis Evlogimenos#include "llvm/CodeGen/MachineBasicBlock.h"
18551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer#include "llvm/Support/DataTypes.h"
192cc214c06cbb94f95928636981c9805d6300cff1Chris Lattner#include <vector>
20be67780f31958b05ad3c510ca3a973d327517e86Chris Lattner#include <cassert>
21a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
22d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
245684c4e2b41f1d6ddf70b116a84f438040f66297Vikram S. Adveclass MachineInstr;
25f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattnerclass TargetMachine;
265684c4e2b41f1d6ddf70b116a84f438040f66297Vikram S. Adveclass Value;
27588668d4681bf928e09534c373b1bcf86757f899Vikram S. Adveclass Type;
285684c4e2b41f1d6ddf70b116a84f438040f66297Vikram S. Adveclass Instruction;
292cc214c06cbb94f95928636981c9805d6300cff1Chris Lattnerclass Constant;
30e7506a366e8bd56c97d10beb68e4db953aebaecaChris Lattnerclass Function;
31c864fde15c68fe56d2af48ddeaddfd4e13006f4aVikram S. Adveclass MachineCodeForInstruction;
32ae72f4a642192abab5a2d10592200a94fcba61deChris Lattnerclass TargetRegisterClass;
33a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
34f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattner//---------------------------------------------------------------------------
35f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattner// Data types used to define information about a single machine instruction
36f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattner//---------------------------------------------------------------------------
37a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
38ab8672c8bb83e722b856eac67863542ea7e0cbb2Alkis Evlogimenostypedef short MachineOpCode;
39c188b733babbcdb0ff51613d0bb133e0496963b6Chris Lattnertypedef unsigned InstrSchedClass;
40a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
41a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve//---------------------------------------------------------------------------
423501feab811c86c9659248a4875fc31a3165f84dChris Lattner// struct TargetInstrDescriptor:
4300876a2808f1a8061f7e0852c7949fc5074ecb04Misha Brukman//  Predefined information about each machine instruction.
4400876a2808f1a8061f7e0852c7949fc5074ecb04Misha Brukman//  Designed to initialized statically.
453501feab811c86c9659248a4875fc31a3165f84dChris Lattner//
46a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
47f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_BRANCH_FLAG           = 1 << 0;
48f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_CALL_FLAG             = 1 << 1;
49f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_RET_FLAG              = 1 << 2;
50f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_BARRIER_FLAG          = 1 << 3;
51f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_DELAY_SLOT_FLAG       = 1 << 4;
52f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_LOAD_FLAG             = 1 << 5;
53f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_STORE_FLAG            = 1 << 6;
5415f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner
5515f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// M_2_ADDR_FLAG - 3-addr instructions which really work like 2-addr ones.
56f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_2_ADDR_FLAG           = 1 << 7;
5715f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner
5815f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// M_CONVERTIBLE_TO_3_ADDR - This is a M_2_ADDR_FLAG instruction which can be
5915f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// changed into a 3-address instruction if the first two operands cannot be
6015f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// assigned to the same register.  The target must implement the
6115f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// TargetInstrInfo::convertToThreeAddress method for this instruction.
62f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_CONVERTIBLE_TO_3_ADDR = 1 << 8;
6315f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner
6415f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// This M_COMMUTABLE - is a 2- or 3-address instruction (of the form X = op Y,
6515f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// Z), which produces the same result if Y and Z are exchanged.
66f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_COMMUTABLE            = 1 << 9;
67a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
68075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// M_TERMINATOR_FLAG - Is this instruction part of the terminator for a basic
69075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// block?  Typically this is things like return and branch instructions.
70075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// Various passes use this to insert code into the bottom of a basic block, but
71075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// before control flow occurs.
72f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_TERMINATOR_FLAG       = 1 << 10;
73075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner
7409321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner// M_USES_CUSTOM_DAG_SCHED_INSERTION - Set if this instruction requires custom
7509321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner// insertion support when the DAG scheduler is inserting it into a machine basic
7609321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner// block.
77f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_USES_CUSTOM_DAG_SCHED_INSERTION = 1 << 11;
7809321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner
798d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng// M_VARIABLE_OPS - Set if this instruction can have a variable number of extra
808d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng// operands in addition to the minimum number operands specified.
818d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Chengconst unsigned M_VARIABLE_OPS = 1 << 12;
828d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng
831b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner// M_PREDICATED - Set if this instruction has a predicate that controls its
841b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner// execution.
851b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattnerconst unsigned M_PREDICATED = 1 << 13;
861b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner
871b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner
8821d03f2de0087d60dbf575d95924404a97852879Evan Cheng// Machine operand flags
8921d03f2de0087d60dbf575d95924404a97852879Evan Cheng// M_LOOK_UP_PTR_REG_CLASS - Set if this operand is a pointer value and it
9021d03f2de0087d60dbf575d95924404a97852879Evan Cheng// requires a callback to look up its register class.
9121d03f2de0087d60dbf575d95924404a97852879Evan Chengconst unsigned M_LOOK_UP_PTR_REG_CLASS = 1 << 0;
9221d03f2de0087d60dbf575d95924404a97852879Evan Cheng
93f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner/// M_PREDICATE_OPERAND - Set if this is the first operand of a predicate
94f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner/// operand that controls an M_PREDICATED instruction.
95f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattnerconst unsigned M_PREDICATE_OPERAND = 1 << 1;
96f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner
97f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner
98ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner/// TargetOperandInfo - This holds information about one operand of a machine
99ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner/// instruction, indicating the register class for register operands, etc.
100ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner///
101ae72f4a642192abab5a2d10592200a94fcba61deChris Lattnerclass TargetOperandInfo {
102ae72f4a642192abab5a2d10592200a94fcba61deChris Lattnerpublic:
10360f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  /// RegClass - This specifies the register class enumeration of the operand
10460f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  /// if the operand is a register.  If not, this contains 0.
10560f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  unsigned short RegClass;
10660f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  unsigned short Flags;
107e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// Lower 16 bits are used to specify which constraints are set. The higher 16
108e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// bits are used to specify the value of constraints (4 bits each).
109e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  unsigned int Constraints;
110ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner  /// Currently no other information.
111ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner};
112ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner
113ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner
1141fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerclass TargetInstrDescriptor {
1151fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerpublic:
1164683f9bfb4dc2f5557e8a7a229912e7f2ed366caChris Lattner  const char *    Name;          // Assembly language mnemonic for the opcode.
1178d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng  unsigned        numOperands;   // Num of args (may be more if variable_ops).
11875e961ae6b2e2801160e560057ad97ece4443986Chris Lattner  InstrSchedClass schedClass;    // enum  identifying instr sched class
11975e961ae6b2e2801160e560057ad97ece4443986Chris Lattner  unsigned        Flags;         // flags identifying machine instr class
12075e961ae6b2e2801160e560057ad97ece4443986Chris Lattner  unsigned        TSFlags;       // Target Specific Flag values
121f6d12fbd9cc0355978a739f5ab213eff85b75a19Chris Lattner  const unsigned *ImplicitUses;  // Registers implicitly read by this instr
122f6d12fbd9cc0355978a739f5ab213eff85b75a19Chris Lattner  const unsigned *ImplicitDefs;  // Registers implicitly defined by this instr
123ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner  const TargetOperandInfo *OpInfo; // 'numOperands' entries about operands.
124a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve};
125a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
126a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
1273501feab811c86c9659248a4875fc31a3165f84dChris Lattner//---------------------------------------------------------------------------
12834695381d626485a560594f162701088079589dfMisha Brukman///
1293501feab811c86c9659248a4875fc31a3165f84dChris Lattner/// TargetInstrInfo - Interface to description of machine instructions
13034695381d626485a560594f162701088079589dfMisha Brukman///
131075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattnerclass TargetInstrInfo {
132075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  const TargetInstrDescriptor* desc;    // raw array to allow static init'n
133bceb68807fdb86c794bc8d8f8aef0940f12c2cebChris Lattner  unsigned NumOpcodes;                  // number of entries in the desc array
134075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  unsigned numRealOpCodes;              // number of non-dummy op codes
13534695381d626485a560594f162701088079589dfMisha Brukman
136075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  TargetInstrInfo(const TargetInstrInfo &);  // DO NOT IMPLEMENT
137075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  void operator=(const TargetInstrInfo &);   // DO NOT IMPLEMENT
138a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Advepublic:
139bceb68807fdb86c794bc8d8f8aef0940f12c2cebChris Lattner  TargetInstrInfo(const TargetInstrDescriptor *desc, unsigned NumOpcodes);
140075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  virtual ~TargetInstrInfo();
14170535c608d88ce25fb992dba3b6d3d0176153a09Chris Lattner
1424ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner  // Invariant opcodes: All instruction sets have these as their low opcodes.
1434ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner  enum {
1444ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner    PHI = 0,
1454ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner    INLINEASM = 1
1464ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner  };
14734695381d626485a560594f162701088079589dfMisha Brukman
148bceb68807fdb86c794bc8d8f8aef0940f12c2cebChris Lattner  unsigned getNumOpcodes() const { return NumOpcodes; }
14934695381d626485a560594f162701088079589dfMisha Brukman
150e30eeaaf72b461aebf3dfcdd7c119eea76458561Chris Lattner  /// get - Return the machine instruction descriptor that corresponds to the
151e30eeaaf72b461aebf3dfcdd7c119eea76458561Chris Lattner  /// specified instruction opcode.
152e30eeaaf72b461aebf3dfcdd7c119eea76458561Chris Lattner  ///
1532441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const TargetInstrDescriptor& get(MachineOpCode Opcode) const {
1542441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    assert((unsigned)Opcode < NumOpcodes);
1552441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return desc[Opcode];
156a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
1574683f9bfb4dc2f5557e8a7a229912e7f2ed366caChris Lattner
1582441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const char *getName(MachineOpCode Opcode) const {
1592441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).Name;
1604683f9bfb4dc2f5557e8a7a229912e7f2ed366caChris Lattner  }
16134695381d626485a560594f162701088079589dfMisha Brukman
1622441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  int getNumOperands(MachineOpCode Opcode) const {
1632441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).numOperands;
164a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
165450b6d29988fa01e828e5b7917a47726a4dd46ecChris Lattner
1662441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  InstrSchedClass getSchedClass(MachineOpCode Opcode) const {
1672441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).schedClass;
168a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
169d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke
1702441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const unsigned *getImplicitUses(MachineOpCode Opcode) const {
1712441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).ImplicitUses;
172d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke  }
173d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke
1742441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const unsigned *getImplicitDefs(MachineOpCode Opcode) const {
1752441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).ImplicitDefs;
176d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke  }
177d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke
178450b6d29988fa01e828e5b7917a47726a4dd46ecChris Lattner
179a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  //
180a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  // Query instruction class flags according to the machine-independent
181a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  // flags listed above.
18234695381d626485a560594f162701088079589dfMisha Brukman  //
1832441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  bool isReturn(MachineOpCode Opcode) const {
1842441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).Flags & M_RET_FLAG;
185a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
186450b6d29988fa01e828e5b7917a47726a4dd46ecChris Lattner
1872441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  bool isTwoAddrInstr(MachineOpCode Opcode) const {
1882441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).Flags & M_2_ADDR_FLAG;
1899ada014ec09579a7dd3833f779a1de82bd71bce1Misha Brukman  }
1901b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner  bool isPredicated(MachineOpCode Opcode) const {
1911b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner    return get(Opcode).Flags & M_PREDICATED;
1921b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner  }
19313d41b9d721f98372b97d2ec119e6c91932ab0aeEvan Cheng  bool isCommutableInstr(MachineOpCode Opcode) const {
19413d41b9d721f98372b97d2ec119e6c91932ab0aeEvan Cheng    return get(Opcode).Flags & M_COMMUTABLE;
19513d41b9d721f98372b97d2ec119e6c91932ab0aeEvan Cheng  }
196075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  bool isTerminatorInstr(unsigned Opcode) const {
197075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner    return get(Opcode).Flags & M_TERMINATOR_FLAG;
198075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  }
1990271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
2000271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isBranch(MachineOpCode Opcode) const {
2010271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_BRANCH_FLAG;
2020271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2030271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
2040271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// isBarrier - Returns true if the specified instruction stops control flow
2050271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// from executing the instruction immediately following it.  Examples include
2060271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// unconditional branches and return instructions.
2070271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isBarrier(MachineOpCode Opcode) const {
2080271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_BARRIER_FLAG;
2090271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2100271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
2110271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isCall(MachineOpCode Opcode) const {
2120271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_CALL_FLAG;
2130271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2140271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isLoad(MachineOpCode Opcode) const {
2150271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_LOAD_FLAG;
2160271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2170271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isStore(MachineOpCode Opcode) const {
2180271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_STORE_FLAG;
2190271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2200271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
221b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// hasDelaySlot - Returns true if the specified instruction has a delay slot
222b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// which must be filled by the code generator.
223b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  bool hasDelaySlot(unsigned Opcode) const {
224b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner    return get(Opcode).Flags & M_DELAY_SLOT_FLAG;
225b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  }
226b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
2270271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// usesCustomDAGSchedInsertionHook - Return true if this instruction requires
2280271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// custom insertion support when the DAG scheduler is inserting it into a
2290271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// machine basic block.
2300271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool usesCustomDAGSchedInsertionHook(unsigned Opcode) const {
2310271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_USES_CUSTOM_DAG_SCHED_INSERTION;
2320271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
233d55697cf136150b697b9bbddce9088e87a1be963Vikram S. Adve
2348d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng  bool hasVariableOperands(MachineOpCode Opcode) const {
2358d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng    return get(Opcode).Flags & M_VARIABLE_OPS;
2368d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng  }
2378d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng
238e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  // Operand constraints: only "tied_to" for now.
239e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  enum OperandConstraint {
240e2ba8975883874633a1035c245af3b948b940b25Evan Cheng    TIED_TO = 0  // Must be allocated the same register as.
241e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  };
242e2ba8975883874633a1035c245af3b948b940b25Evan Cheng
243e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// getOperandConstraint - Returns the value of the specific constraint if
244e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// it is set. Returns -1 if it is not set.
245e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  int getOperandConstraint(MachineOpCode Opcode, unsigned OpNum,
246981b5bd7080db6dbbac6931863d8a2e6d1fc5a0cEvan Cheng                           OperandConstraint Constraint) const {
247e2ba8975883874633a1035c245af3b948b940b25Evan Cheng    assert(OpNum < get(Opcode).numOperands &&
248e2ba8975883874633a1035c245af3b948b940b25Evan Cheng           "Invalid operand # of TargetInstrInfo");
249e2ba8975883874633a1035c245af3b948b940b25Evan Cheng    if (get(Opcode).OpInfo[OpNum].Constraints & (1 << Constraint)) {
250e2ba8975883874633a1035c245af3b948b940b25Evan Cheng      unsigned Pos = 16 + Constraint * 4;
251e2ba8975883874633a1035c245af3b948b940b25Evan Cheng      return (int)(get(Opcode).OpInfo[OpNum].Constraints >> Pos) & 0xf;
252e2ba8975883874633a1035c245af3b948b940b25Evan Cheng    }
253e2ba8975883874633a1035c245af3b948b940b25Evan Cheng    return -1;
254e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  }
255e2ba8975883874633a1035c245af3b948b940b25Evan Cheng
256e6ae14e1f413987f3de31a7cad1b20a7893f8caeEvan Cheng  /// findTiedToSrcOperand - Returns the operand that is tied to the specified
257981b5bd7080db6dbbac6931863d8a2e6d1fc5a0cEvan Cheng  /// dest operand. Returns -1 if there isn't one.
258e6ae14e1f413987f3de31a7cad1b20a7893f8caeEvan Cheng  int findTiedToSrcOperand(MachineOpCode Opcode, unsigned OpNum) const;
259981b5bd7080db6dbbac6931863d8a2e6d1fc5a0cEvan Cheng
260ae1dc403274d3a64bcee31f15e2d25e4b7178811Chris Lattner  /// getDWARF_LABELOpcode - Return the opcode of the target's DWARF_LABEL
261ae1dc403274d3a64bcee31f15e2d25e4b7178811Chris Lattner  /// instruction if it has one.  This is used by codegen passes that update
262ae1dc403274d3a64bcee31f15e2d25e4b7178811Chris Lattner  /// DWARF line number info as they modify the code.
263ae1dc403274d3a64bcee31f15e2d25e4b7178811Chris Lattner  virtual unsigned getDWARF_LABELOpcode() const {
264ae1dc403274d3a64bcee31f15e2d25e4b7178811Chris Lattner    return 0;
265ae1dc403274d3a64bcee31f15e2d25e4b7178811Chris Lattner  }
266ae1dc403274d3a64bcee31f15e2d25e4b7178811Chris Lattner
2670cad9f53b15b7308e977864d681f710646e7d376Alkis Evlogimenos  /// Return true if the instruction is a register to register move
2680cad9f53b15b7308e977864d681f710646e7d376Alkis Evlogimenos  /// and leave the source and dest operands in the passed parameters.
2695e30002af70ef09a42cac155d9196f7f0f3b1695Alkis Evlogimenos  virtual bool isMoveInstr(const MachineInstr& MI,
2705e30002af70ef09a42cac155d9196f7f0f3b1695Alkis Evlogimenos                           unsigned& sourceReg,
2715e30002af70ef09a42cac155d9196f7f0f3b1695Alkis Evlogimenos                           unsigned& destReg) const {
2725e30002af70ef09a42cac155d9196f7f0f3b1695Alkis Evlogimenos    return false;
2735e30002af70ef09a42cac155d9196f7f0f3b1695Alkis Evlogimenos  }
274af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner
275af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// isLoadFromStackSlot - If the specified machine instruction is a direct
276af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// load from a stack slot, return the virtual or physical register number of
277af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// the destination along with the FrameIndex of the loaded stack slot.  If
278af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// not, return 0.  This predicate must return 0 if the instruction has
279af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// any side effects other than loading from the stack slot.
280af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const{
281af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner    return 0;
282af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  }
283af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner
284af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// isStoreToStackSlot - If the specified machine instruction is a direct
285af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// store to a stack slot, return the virtual or physical register number of
286af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// the source reg along with the FrameIndex of the loaded stack slot.  If
287af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// not, return 0.  This predicate must return 0 if the instruction has
288af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  /// any side effects other than storing to the stack slot.
289af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const {
290af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner    return 0;
291af9fa2bd0c1ee25f3adda96b3e5d7129fbab393aChris Lattner  }
2925e30002af70ef09a42cac155d9196f7f0f3b1695Alkis Evlogimenos
29315f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// convertToThreeAddress - This method must be implemented by targets that
29415f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
29515f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// may be able to convert a two-address instruction into a true
29615f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// three-address instruction on demand.  This allows the X86 target (for
29715f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// example) to convert ADD and SHL instructions into LEA instructions if they
29815f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// would require register copies due to two-addressness.
29915f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  ///
30015f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// This method returns a null pointer if the transformation cannot be
30115f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  /// performed, otherwise it returns the new instruction.
30215f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  ///
30315f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  virtual MachineInstr *convertToThreeAddress(MachineInstr *TA) const {
30415f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner    return 0;
30515f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  }
30615f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner
307d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// commuteInstruction - If a target has any instructions that are commutable,
308d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// but require converting to a different instruction or making non-trivial
309d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// changes to commute them, this method can overloaded to do this.  The
310d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// default implementation of this method simply swaps the first two operands
311d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// of MI and returns it.
312d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  ///
313d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// If a target wants to make more aggressive changes, they can construct and
314d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// return a new machine instruction.  If an instruction cannot commute, it
315d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// can also return null.
316d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  ///
317d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  virtual MachineInstr *commuteInstruction(MachineInstr *MI) const;
318d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner
319b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// AnalyzeBranch - Analyze the branching code at the end of MBB, returning
320b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
321b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// implemented for a target).  Upon success, this returns false and returns
322b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// with the following information in various cases:
323b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///
32472dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  /// 1. If this block ends with no branches (it just falls through to its succ)
32572dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  ///    just return false, leaving TBB/FBB null.
32672dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  /// 2. If this block ends with only an unconditional branch, it sets TBB to be
327b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    the destination block.
32872dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  /// 3. If this block ends with an conditional branch, it returns the 'true'
329b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    destination in TBB, the 'false' destination in FBB, and a list of
330b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    operands that evaluate the condition.  These operands can be passed to
331b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    other TargetInstrInfo methods to create new branches.
332b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///
333b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// Note that RemoveBranch and InsertBranch must be implemented to support
334b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// cases where this method returns success.
335b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///
336b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
337b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner                             MachineBasicBlock *&FBB,
338b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner                             std::vector<MachineOperand> &Cond) const {
339b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner    return true;
340905f7af59cb85ea71b6c011f1e79f24f8db16efcAlkis Evlogimenos  }
341b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
342b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// RemoveBranch - Remove the branching code at the end of the specific MBB.
343b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// this is only invoked in cases where AnalyzeBranch returns success.
344d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner  virtual void RemoveBranch(MachineBasicBlock &MBB) const {
345b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner    assert(0 && "Target didn't implement TargetInstrInfo::RemoveBranch!");
346b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  }
347b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
348b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// InsertBranch - Insert a branch into the end of the specified
349b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// MachineBasicBlock.  This operands to this method are the same as those
35033644ba8d22a91b8fe0f0da3d73fc7cf38a46b06Chris Lattner  /// returned by AnalyzeBranch.  This is invoked in cases where AnalyzeBranch
35133644ba8d22a91b8fe0f0da3d73fc7cf38a46b06Chris Lattner  /// returns success and when an unconditional branch (TBB is non-null, FBB is
35233644ba8d22a91b8fe0f0da3d73fc7cf38a46b06Chris Lattner  /// null, Cond is empty) needs to be inserted.
353d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner  virtual void InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
354d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner                            MachineBasicBlock *FBB,
355d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner                            const std::vector<MachineOperand> &Cond) const {
35624321d7e23a482cbd0b7502f43e9026f87a3684dRafael Espindola    assert(0 && "Target didn't implement TargetInstrInfo::InsertBranch!");
357b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  }
358b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
359c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// BlockHasNoFallThrough - Return true if the specified block does not
360c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// fall-through into its successor block.  This is primarily used when a
361c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// branch is unanalyzable.  It is useful for things like unconditional
362c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// indirect branches (jump tables).
363c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const {
364c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner    return false;
365c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  }
366c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner
3675f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  /// ReverseBranchCondition - Reverses the branch condition of the specified
3685f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  /// condition list, returning false on success and true if it cannot be
3695f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  /// reversed.
3705f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
3715f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner    return true;
372905f7af59cb85ea71b6c011f1e79f24f8db16efcAlkis Evlogimenos  }
3730271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
37465e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  /// insertNoop - Insert a noop into the instruction stream at the specified
37565e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  /// point.
37665e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  virtual void insertNoop(MachineBasicBlock &MBB,
37765e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner                          MachineBasicBlock::iterator MI) const {
37865e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner    assert(0 && "Target didn't implement insertNoop!");
37965e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner    abort();
38065e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  }
38121d03f2de0087d60dbf575d95924404a97852879Evan Cheng
38221d03f2de0087d60dbf575d95924404a97852879Evan Cheng  /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
38321d03f2de0087d60dbf575d95924404a97852879Evan Cheng  /// values.
38421d03f2de0087d60dbf575d95924404a97852879Evan Cheng  virtual const TargetRegisterClass *getPointerRegClass() const {
38521d03f2de0087d60dbf575d95924404a97852879Evan Cheng    assert(0 && "Target didn't implement getPointerRegClass!");
38621d03f2de0087d60dbf575d95924404a97852879Evan Cheng    abort();
38721d03f2de0087d60dbf575d95924404a97852879Evan Cheng  }
388a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve};
389a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
390d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
391d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
392a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve#endif
393