TargetInstrInfo.h revision 1ee29257428960fede862fcfdbe80d5d007927e9
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"
186c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng#include "llvm/CodeGen/MachineFunction.h"
19551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer#include "llvm/Support/DataTypes.h"
202cc214c06cbb94f95928636981c9805d6300cff1Chris Lattner#include <vector>
21be67780f31958b05ad3c510ca3a973d327517e86Chris Lattner#include <cassert>
22a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
24d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
255684c4e2b41f1d6ddf70b116a84f438040f66297Vikram S. Adveclass MachineInstr;
26f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattnerclass TargetMachine;
275684c4e2b41f1d6ddf70b116a84f438040f66297Vikram S. Adveclass Value;
28588668d4681bf928e09534c373b1bcf86757f899Vikram S. Adveclass Type;
295684c4e2b41f1d6ddf70b116a84f438040f66297Vikram S. Adveclass Instruction;
302cc214c06cbb94f95928636981c9805d6300cff1Chris Lattnerclass Constant;
31e7506a366e8bd56c97d10beb68e4db953aebaecaChris Lattnerclass Function;
32c864fde15c68fe56d2af48ddeaddfd4e13006f4aVikram S. Adveclass MachineCodeForInstruction;
33ae72f4a642192abab5a2d10592200a94fcba61deChris Lattnerclass TargetRegisterClass;
346c14147d934bd644fc9d24a3b36f3c38799a3401Evan Chengclass LiveVariables;
35a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
36f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattner//---------------------------------------------------------------------------
37f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattner// Data types used to define information about a single machine instruction
38f3aaadf48277acddc3f6fdc4cc8d18b13d313595Chris Lattner//---------------------------------------------------------------------------
39a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
40ab8672c8bb83e722b856eac67863542ea7e0cbb2Alkis Evlogimenostypedef short MachineOpCode;
41c188b733babbcdb0ff51613d0bb133e0496963b6Chris Lattnertypedef unsigned InstrSchedClass;
42a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
43a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve//---------------------------------------------------------------------------
443501feab811c86c9659248a4875fc31a3165f84dChris Lattner// struct TargetInstrDescriptor:
4500876a2808f1a8061f7e0852c7949fc5074ecb04Misha Brukman//  Predefined information about each machine instruction.
4600876a2808f1a8061f7e0852c7949fc5074ecb04Misha Brukman//  Designed to initialized statically.
473501feab811c86c9659248a4875fc31a3165f84dChris Lattner//
48a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
49f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_BRANCH_FLAG           = 1 << 0;
50f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_CALL_FLAG             = 1 << 1;
51f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_RET_FLAG              = 1 << 2;
52f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_BARRIER_FLAG          = 1 << 3;
53f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_DELAY_SLOT_FLAG       = 1 << 4;
54f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_LOAD_FLAG             = 1 << 5;
55f7fb31ea33c78f1bc46c23d9edbf9580b7756bbeChris Lattnerconst unsigned M_STORE_FLAG            = 1 << 6;
5615f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner
57a1fd6504aaf62b87530e8230517957bad3facc96Evan Cheng// M_CONVERTIBLE_TO_3_ADDR - This is a 2-address instruction which can be
5815f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// changed into a 3-address instruction if the first two operands cannot be
5915f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// assigned to the same register.  The target must implement the
6015f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// TargetInstrInfo::convertToThreeAddress method for this instruction.
61a1fd6504aaf62b87530e8230517957bad3facc96Evan Chengconst unsigned M_CONVERTIBLE_TO_3_ADDR = 1 << 7;
6215f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner
6315f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// This M_COMMUTABLE - is a 2- or 3-address instruction (of the form X = op Y,
6415f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner// Z), which produces the same result if Y and Z are exchanged.
65a1fd6504aaf62b87530e8230517957bad3facc96Evan Chengconst unsigned M_COMMUTABLE            = 1 << 8;
66a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
67075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// M_TERMINATOR_FLAG - Is this instruction part of the terminator for a basic
68075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// block?  Typically this is things like return and branch instructions.
69075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// Various passes use this to insert code into the bottom of a basic block, but
70075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner// before control flow occurs.
71a1fd6504aaf62b87530e8230517957bad3facc96Evan Chengconst unsigned M_TERMINATOR_FLAG       = 1 << 9;
72075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner
7309321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner// M_USES_CUSTOM_DAG_SCHED_INSERTION - Set if this instruction requires custom
7409321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner// insertion support when the DAG scheduler is inserting it into a machine basic
7509321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner// block.
76a1fd6504aaf62b87530e8230517957bad3facc96Evan Chengconst unsigned M_USES_CUSTOM_DAG_SCHED_INSERTION = 1 << 10;
7709321dcf5a3d8acb89dfcad2191c630a54938458Chris Lattner
788d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng// M_VARIABLE_OPS - Set if this instruction can have a variable number of extra
798d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng// operands in addition to the minimum number operands specified.
80a1fd6504aaf62b87530e8230517957bad3facc96Evan Chengconst unsigned M_VARIABLE_OPS = 1 << 11;
818d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng
821b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner// M_PREDICATED - Set if this instruction has a predicate that controls its
831b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner// execution.
84a1fd6504aaf62b87530e8230517957bad3facc96Evan Chengconst unsigned M_PREDICATED = 1 << 12;
851b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner
861b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner
8721d03f2de0087d60dbf575d95924404a97852879Evan Cheng// Machine operand flags
8821d03f2de0087d60dbf575d95924404a97852879Evan Cheng// M_LOOK_UP_PTR_REG_CLASS - Set if this operand is a pointer value and it
8921d03f2de0087d60dbf575d95924404a97852879Evan Cheng// requires a callback to look up its register class.
9021d03f2de0087d60dbf575d95924404a97852879Evan Chengconst unsigned M_LOOK_UP_PTR_REG_CLASS = 1 << 0;
9121d03f2de0087d60dbf575d95924404a97852879Evan Cheng
92f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner/// M_PREDICATE_OPERAND - Set if this is the first operand of a predicate
93f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner/// operand that controls an M_PREDICATED instruction.
94f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattnerconst unsigned M_PREDICATE_OPERAND = 1 << 1;
95f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner
966c14147d934bd644fc9d24a3b36f3c38799a3401Evan Chengnamespace TOI {
976c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  // Operand constraints: only "tied_to" for now.
986c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  enum OperandConstraint {
996c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng    TIED_TO = 0  // Must be allocated the same register as.
1006c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  };
1016c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng}
102f6e8e6bace845cbbb6c1f6d859ffd8a3a154222bChris Lattner
103ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner/// TargetOperandInfo - This holds information about one operand of a machine
104ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner/// instruction, indicating the register class for register operands, etc.
105ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner///
106ae72f4a642192abab5a2d10592200a94fcba61deChris Lattnerclass TargetOperandInfo {
107ae72f4a642192abab5a2d10592200a94fcba61deChris Lattnerpublic:
10860f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  /// RegClass - This specifies the register class enumeration of the operand
10960f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  /// if the operand is a register.  If not, this contains 0.
11060f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  unsigned short RegClass;
11160f09928a0d22d5927ff0a40fe9163cf1ba1014aJim Laskey  unsigned short Flags;
112e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// Lower 16 bits are used to specify which constraints are set. The higher 16
113e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// bits are used to specify the value of constraints (4 bits each).
114e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  unsigned int Constraints;
115ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner  /// Currently no other information.
116ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner};
117ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner
118ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner
1191fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerclass TargetInstrDescriptor {
1201fca5ff62bb2ecb5bfc8974f4dbfc56e9d3ca721Chris Lattnerpublic:
12133247d537ddce29e65bc324bf8d40a15d2d88c01Evan Cheng  MachineOpCode   Opcode;        // The opcode.
12233247d537ddce29e65bc324bf8d40a15d2d88c01Evan Cheng  unsigned short  numOperands;   // Num of args (may be more if variable_ops).
1234683f9bfb4dc2f5557e8a7a229912e7f2ed366caChris Lattner  const char *    Name;          // Assembly language mnemonic for the opcode.
12475e961ae6b2e2801160e560057ad97ece4443986Chris Lattner  InstrSchedClass schedClass;    // enum  identifying instr sched class
12575e961ae6b2e2801160e560057ad97ece4443986Chris Lattner  unsigned        Flags;         // flags identifying machine instr class
12675e961ae6b2e2801160e560057ad97ece4443986Chris Lattner  unsigned        TSFlags;       // Target Specific Flag values
127f6d12fbd9cc0355978a739f5ab213eff85b75a19Chris Lattner  const unsigned *ImplicitUses;  // Registers implicitly read by this instr
128f6d12fbd9cc0355978a739f5ab213eff85b75a19Chris Lattner  const unsigned *ImplicitDefs;  // Registers implicitly defined by this instr
129ae72f4a642192abab5a2d10592200a94fcba61deChris Lattner  const TargetOperandInfo *OpInfo; // 'numOperands' entries about operands.
1306c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng
1316c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  /// getOperandConstraint - Returns the value of the specific constraint if
1326c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  /// it is set. Returns -1 if it is not set.
1336c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  int getOperandConstraint(unsigned OpNum,
1346c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng                           TOI::OperandConstraint Constraint) const {
135f2f6a1baf78f3bdf375b258996abd567c20496bcEvan Cheng    assert((OpNum < numOperands || (Flags & M_VARIABLE_OPS)) &&
136f2f6a1baf78f3bdf375b258996abd567c20496bcEvan Cheng           "Invalid operand # of TargetInstrInfo");
137f2f6a1baf78f3bdf375b258996abd567c20496bcEvan Cheng    if (OpNum < numOperands &&
138f2f6a1baf78f3bdf375b258996abd567c20496bcEvan Cheng        (OpInfo[OpNum].Constraints & (1 << Constraint))) {
1396c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng      unsigned Pos = 16 + Constraint * 4;
1406c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng      return (int)(OpInfo[OpNum].Constraints >> Pos) & 0xf;
1416c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng    }
1426c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng    return -1;
1436c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  }
144cc22a7a2adfea3fc318a6d8ca0c692a8e892105bEvan Cheng
145cc22a7a2adfea3fc318a6d8ca0c692a8e892105bEvan Cheng  /// findTiedToSrcOperand - Returns the operand that is tied to the specified
146cc22a7a2adfea3fc318a6d8ca0c692a8e892105bEvan Cheng  /// dest operand. Returns -1 if there isn't one.
147cc22a7a2adfea3fc318a6d8ca0c692a8e892105bEvan Cheng  int findTiedToSrcOperand(unsigned OpNum) const;
148a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve};
149a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
150a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
1513501feab811c86c9659248a4875fc31a3165f84dChris Lattner//---------------------------------------------------------------------------
15234695381d626485a560594f162701088079589dfMisha Brukman///
1533501feab811c86c9659248a4875fc31a3165f84dChris Lattner/// TargetInstrInfo - Interface to description of machine instructions
15434695381d626485a560594f162701088079589dfMisha Brukman///
155075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattnerclass TargetInstrInfo {
156075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  const TargetInstrDescriptor* desc;    // raw array to allow static init'n
157bceb68807fdb86c794bc8d8f8aef0940f12c2cebChris Lattner  unsigned NumOpcodes;                  // number of entries in the desc array
158075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  unsigned numRealOpCodes;              // number of non-dummy op codes
15934695381d626485a560594f162701088079589dfMisha Brukman
160075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  TargetInstrInfo(const TargetInstrInfo &);  // DO NOT IMPLEMENT
161075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  void operator=(const TargetInstrInfo &);   // DO NOT IMPLEMENT
162a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Advepublic:
163bceb68807fdb86c794bc8d8f8aef0940f12c2cebChris Lattner  TargetInstrInfo(const TargetInstrDescriptor *desc, unsigned NumOpcodes);
164075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  virtual ~TargetInstrInfo();
16570535c608d88ce25fb992dba3b6d3d0176153a09Chris Lattner
1664ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner  // Invariant opcodes: All instruction sets have these as their low opcodes.
1674ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner  enum {
1684ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner    PHI = 0,
1691ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    INLINEASM = 1,
1701ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    LABEL = 2
1714ed88eb8229848cd6add06a1ec90e497e382306fChris Lattner  };
17234695381d626485a560594f162701088079589dfMisha Brukman
173bceb68807fdb86c794bc8d8f8aef0940f12c2cebChris Lattner  unsigned getNumOpcodes() const { return NumOpcodes; }
17434695381d626485a560594f162701088079589dfMisha Brukman
175e30eeaaf72b461aebf3dfcdd7c119eea76458561Chris Lattner  /// get - Return the machine instruction descriptor that corresponds to the
176e30eeaaf72b461aebf3dfcdd7c119eea76458561Chris Lattner  /// specified instruction opcode.
177e30eeaaf72b461aebf3dfcdd7c119eea76458561Chris Lattner  ///
1782441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const TargetInstrDescriptor& get(MachineOpCode Opcode) const {
1792441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    assert((unsigned)Opcode < NumOpcodes);
1802441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return desc[Opcode];
181a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
1824683f9bfb4dc2f5557e8a7a229912e7f2ed366caChris Lattner
1832441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const char *getName(MachineOpCode Opcode) const {
1842441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).Name;
1854683f9bfb4dc2f5557e8a7a229912e7f2ed366caChris Lattner  }
18634695381d626485a560594f162701088079589dfMisha Brukman
1872441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  int getNumOperands(MachineOpCode Opcode) const {
1882441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).numOperands;
189a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
190450b6d29988fa01e828e5b7917a47726a4dd46ecChris Lattner
1912441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  InstrSchedClass getSchedClass(MachineOpCode Opcode) const {
1922441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).schedClass;
193a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
194d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke
1952441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const unsigned *getImplicitUses(MachineOpCode Opcode) const {
1962441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).ImplicitUses;
197d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke  }
198d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke
1992441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  const unsigned *getImplicitDefs(MachineOpCode Opcode) const {
2002441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).ImplicitDefs;
201d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke  }
202d7908f679eeadc108e09e2aca5faba0b5410ea4aBrian Gaeke
203450b6d29988fa01e828e5b7917a47726a4dd46ecChris Lattner
204a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  //
205a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  // Query instruction class flags according to the machine-independent
206a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  // flags listed above.
20734695381d626485a560594f162701088079589dfMisha Brukman  //
2082441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner  bool isReturn(MachineOpCode Opcode) const {
2092441d6a895c1aad171bfbdc84cd6e246171b101dChris Lattner    return get(Opcode).Flags & M_RET_FLAG;
210a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve  }
211450b6d29988fa01e828e5b7917a47726a4dd46ecChris Lattner
2121b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner  bool isPredicated(MachineOpCode Opcode) const {
2131b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner    return get(Opcode).Flags & M_PREDICATED;
2141b1b737d7dc7b3330331cf65514719d719f88a43Chris Lattner  }
21513d41b9d721f98372b97d2ec119e6c91932ab0aeEvan Cheng  bool isCommutableInstr(MachineOpCode Opcode) const {
21613d41b9d721f98372b97d2ec119e6c91932ab0aeEvan Cheng    return get(Opcode).Flags & M_COMMUTABLE;
21713d41b9d721f98372b97d2ec119e6c91932ab0aeEvan Cheng  }
218075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  bool isTerminatorInstr(unsigned Opcode) const {
219075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner    return get(Opcode).Flags & M_TERMINATOR_FLAG;
220075b4a066db31f48e0f6daec34b1ff463523cd3fChris Lattner  }
2210271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
2220271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isBranch(MachineOpCode Opcode) const {
2230271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_BRANCH_FLAG;
2240271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2250271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
2260271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// isBarrier - Returns true if the specified instruction stops control flow
2270271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// from executing the instruction immediately following it.  Examples include
2280271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// unconditional branches and return instructions.
2290271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isBarrier(MachineOpCode Opcode) const {
2300271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_BARRIER_FLAG;
2310271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2320271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
2330271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isCall(MachineOpCode Opcode) const {
2340271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_CALL_FLAG;
2350271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2360271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isLoad(MachineOpCode Opcode) const {
2370271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_LOAD_FLAG;
2380271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2390271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool isStore(MachineOpCode Opcode) const {
2400271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_STORE_FLAG;
2410271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
2420271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
243b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// hasDelaySlot - Returns true if the specified instruction has a delay slot
244b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// which must be filled by the code generator.
245b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  bool hasDelaySlot(unsigned Opcode) const {
246b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner    return get(Opcode).Flags & M_DELAY_SLOT_FLAG;
247b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  }
248b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
2490271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// usesCustomDAGSchedInsertionHook - Return true if this instruction requires
2500271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// custom insertion support when the DAG scheduler is inserting it into a
2510271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  /// machine basic block.
2520271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  bool usesCustomDAGSchedInsertionHook(unsigned Opcode) const {
2530271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner    return get(Opcode).Flags & M_USES_CUSTOM_DAG_SCHED_INSERTION;
2540271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner  }
255d55697cf136150b697b9bbddce9088e87a1be963Vikram S. Adve
2568d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng  bool hasVariableOperands(MachineOpCode Opcode) const {
2578d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng    return get(Opcode).Flags & M_VARIABLE_OPS;
2588d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng  }
2598d3af5e7d082dbd029c3987ceadbdcf9e49af6d7Evan Cheng
260e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// getOperandConstraint - Returns the value of the specific constraint if
261e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  /// it is set. Returns -1 if it is not set.
262e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  int getOperandConstraint(MachineOpCode Opcode, unsigned OpNum,
2636c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng                           TOI::OperandConstraint Constraint) const {
2646c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng    return get(Opcode).getOperandConstraint(OpNum, Constraint);
265e2ba8975883874633a1035c245af3b948b940b25Evan Cheng  }
266e2ba8975883874633a1035c245af3b948b940b25Evan Cheng
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
2956c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  /// may be able to convert a two-address instruction into one or moretrue
2966c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  /// three-address instructions 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
3016c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  /// performed, otherwise it returns the last new instruction.
30215f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  ///
3036c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  virtual MachineInstr *
3046c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng  convertToThreeAddress(MachineFunction::iterator &MFI,
3056c14147d934bd644fc9d24a3b36f3c38799a3401Evan Cheng                   MachineBasicBlock::iterator &MBBI, LiveVariables &LV) const {
30615f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner    return 0;
30715f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner  }
30815f63ad2e59998f0bf1a3a23547582074391f650Chris Lattner
309d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// commuteInstruction - If a target has any instructions that are commutable,
310d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// but require converting to a different instruction or making non-trivial
311d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// changes to commute them, this method can overloaded to do this.  The
312d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// default implementation of this method simply swaps the first two operands
313d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// of MI and returns it.
314d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  ///
315d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// If a target wants to make more aggressive changes, they can construct and
316d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// return a new machine instruction.  If an instruction cannot commute, it
317d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  /// can also return null.
318d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  ///
319d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner  virtual MachineInstr *commuteInstruction(MachineInstr *MI) const;
320d7e2fe40e42dffa04a770191c3414446d5e8c30aChris Lattner
321b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// AnalyzeBranch - Analyze the branching code at the end of MBB, returning
322b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
323b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// implemented for a target).  Upon success, this returns false and returns
324b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// with the following information in various cases:
325b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///
32672dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  /// 1. If this block ends with no branches (it just falls through to its succ)
32772dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  ///    just return false, leaving TBB/FBB null.
32872dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  /// 2. If this block ends with only an unconditional branch, it sets TBB to be
329b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    the destination block.
33072dc5852684bd56af68b3f344b295d9ff5c3a13fChris Lattner  /// 3. If this block ends with an conditional branch, it returns the 'true'
331b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    destination in TBB, the 'false' destination in FBB, and a list of
332b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    operands that evaluate the condition.  These operands can be passed to
333b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///    other TargetInstrInfo methods to create new branches.
334b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///
335b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// Note that RemoveBranch and InsertBranch must be implemented to support
336b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// cases where this method returns success.
337b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  ///
338b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
339b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner                             MachineBasicBlock *&FBB,
340b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner                             std::vector<MachineOperand> &Cond) const {
341b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner    return true;
342905f7af59cb85ea71b6c011f1e79f24f8db16efcAlkis Evlogimenos  }
343b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
344b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// RemoveBranch - Remove the branching code at the end of the specific MBB.
345b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// this is only invoked in cases where AnalyzeBranch returns success.
346d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner  virtual void RemoveBranch(MachineBasicBlock &MBB) const {
347b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner    assert(0 && "Target didn't implement TargetInstrInfo::RemoveBranch!");
348b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  }
349b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
350b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// InsertBranch - Insert a branch into the end of the specified
351b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  /// MachineBasicBlock.  This operands to this method are the same as those
35233644ba8d22a91b8fe0f0da3d73fc7cf38a46b06Chris Lattner  /// returned by AnalyzeBranch.  This is invoked in cases where AnalyzeBranch
35333644ba8d22a91b8fe0f0da3d73fc7cf38a46b06Chris Lattner  /// returns success and when an unconditional branch (TBB is non-null, FBB is
35433644ba8d22a91b8fe0f0da3d73fc7cf38a46b06Chris Lattner  /// null, Cond is empty) needs to be inserted.
355d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner  virtual void InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
356d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner                            MachineBasicBlock *FBB,
357d51c87f22f9b666204b27b301af771bc5badc142Chris Lattner                            const std::vector<MachineOperand> &Cond) const {
35824321d7e23a482cbd0b7502f43e9026f87a3684dRafael Espindola    assert(0 && "Target didn't implement TargetInstrInfo::InsertBranch!");
359b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner  }
360b2cd26127973b97c3ed8d74a063e70a259369e44Chris Lattner
361c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// BlockHasNoFallThrough - Return true if the specified block does not
362c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// fall-through into its successor block.  This is primarily used when a
363c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// branch is unanalyzable.  It is useful for things like unconditional
364c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  /// indirect branches (jump tables).
365c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const {
366c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner    return false;
367c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner  }
368c24ff8ed12d01a1b1d2fac57876fc7580024ec49Chris Lattner
3695f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  /// ReverseBranchCondition - Reverses the branch condition of the specified
3705f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  /// condition list, returning false on success and true if it cannot be
3715f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  /// reversed.
3725f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner  virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
3735f1e4dbdf77de6887441af20857967a3d24c01abChris Lattner    return true;
374905f7af59cb85ea71b6c011f1e79f24f8db16efcAlkis Evlogimenos  }
3750271077eba5f62796f4c725baa8e7fc88bf97650Chris Lattner
37665e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  /// insertNoop - Insert a noop into the instruction stream at the specified
37765e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  /// point.
37865e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  virtual void insertNoop(MachineBasicBlock &MBB,
37965e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner                          MachineBasicBlock::iterator MI) const {
38065e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner    assert(0 && "Target didn't implement insertNoop!");
38165e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner    abort();
38265e9f3969bec427f14d41f0aaef12ed689ca85b5Chris Lattner  }
38321d03f2de0087d60dbf575d95924404a97852879Evan Cheng
38421d03f2de0087d60dbf575d95924404a97852879Evan Cheng  /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
38521d03f2de0087d60dbf575d95924404a97852879Evan Cheng  /// values.
38621d03f2de0087d60dbf575d95924404a97852879Evan Cheng  virtual const TargetRegisterClass *getPointerRegClass() const {
38721d03f2de0087d60dbf575d95924404a97852879Evan Cheng    assert(0 && "Target didn't implement getPointerRegClass!");
38821d03f2de0087d60dbf575d95924404a97852879Evan Cheng    abort();
38921d03f2de0087d60dbf575d95924404a97852879Evan Cheng  }
390a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve};
391a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve
392d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
393d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
394a578a6d054e8219c730840700d8d5fd29f15a962Vikram S. Adve#endif
395