Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 1 | //===- CodeGenInstruction.h - Instruction Class Wrapper ---------*- C++ -*-===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 3060910 | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a wrapper class for the 'Instruction' TableGen class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_INSTRUCTION_H |
| 15 | #define CODEGEN_INSTRUCTION_H |
| 16 | |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/ValueTypes.h" |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <vector> |
| 20 | #include <utility> |
| 21 | |
| 22 | namespace llvm { |
| 23 | class Record; |
Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 24 | class DagInit; |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 25 | class CodeGenTarget; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 26 | |
Jeff Cohen | d41b30d | 2006-11-05 19:31:28 +0000 | [diff] [blame] | 27 | class CodeGenInstruction { |
| 28 | public: |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 29 | Record *TheDef; // The actual record defining this instruction. |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 30 | std::string Namespace; // The namespace the instruction is in. |
| 31 | |
| 32 | /// AsmString - The format string used to emit a .s file for the |
| 33 | /// instruction. |
| 34 | std::string AsmString; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 35 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 36 | class ConstraintInfo { |
| 37 | enum { None, EarlyClobber, Tied } Kind; |
| 38 | unsigned OtherTiedOperand; |
| 39 | public: |
| 40 | ConstraintInfo() : Kind(None) {} |
| 41 | |
| 42 | static ConstraintInfo getEarlyClobber() { |
| 43 | ConstraintInfo I; |
| 44 | I.Kind = EarlyClobber; |
Chris Lattner | e555c9f | 2010-02-10 21:22:51 +0000 | [diff] [blame] | 45 | I.OtherTiedOperand = 0; |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 46 | return I; |
| 47 | } |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 48 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 49 | static ConstraintInfo getTied(unsigned Op) { |
| 50 | ConstraintInfo I; |
| 51 | I.Kind = Tied; |
| 52 | I.OtherTiedOperand = Op; |
| 53 | return I; |
| 54 | } |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 55 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 56 | bool isNone() const { return Kind == None; } |
| 57 | bool isEarlyClobber() const { return Kind == EarlyClobber; } |
| 58 | bool isTied() const { return Kind == Tied; } |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 59 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 60 | unsigned getTiedOperand() const { |
| 61 | assert(isTied()); |
| 62 | return OtherTiedOperand; |
| 63 | } |
| 64 | }; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 65 | |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 66 | /// OperandInfo - The information we keep track of for each operand in the |
| 67 | /// operand list for a tablegen instruction. |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 68 | struct OperandInfo { |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 69 | /// Rec - The definition this operand is declared as. |
Chris Lattner | 0e384b6 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 70 | /// |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 71 | Record *Rec; |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 72 | |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 73 | /// Name - If this operand was assigned a symbolic name, this is it, |
| 74 | /// otherwise, it's empty. |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 75 | std::string Name; |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 76 | |
| 77 | /// PrinterMethodName - The method used to print operands of this type in |
| 78 | /// the asmprinter. |
| 79 | std::string PrinterMethodName; |
| 80 | |
Jim Grosbach | 5013f74 | 2010-10-12 22:21:57 +0000 | [diff] [blame^] | 81 | /// EncoderMethodName - The method used to get the machine operand value |
| 82 | /// for binary encoding. "getMachineOpValue" by default. |
| 83 | std::string EncoderMethodName; |
| 84 | |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 85 | /// MIOperandNo - Currently (this is meant to be phased out), some logical |
| 86 | /// operands correspond to multiple MachineInstr operands. In the X86 |
| 87 | /// target for example, one address operand is represented as 4 |
| 88 | /// MachineOperands. Because of this, the operand number in the |
| 89 | /// OperandList may not match the MachineInstr operand num. Until it |
| 90 | /// does, this contains the MI operand index of this operand. |
| 91 | unsigned MIOperandNo; |
Chris Lattner | cfbf96a | 2005-08-18 23:38:41 +0000 | [diff] [blame] | 92 | unsigned MINumOperands; // The number of operands. |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 93 | |
Chris Lattner | f64f9a4 | 2006-11-15 23:23:02 +0000 | [diff] [blame] | 94 | /// DoNotEncode - Bools are set to true in this vector for each operand in |
| 95 | /// the DisableEncoding list. These should not be emitted by the code |
| 96 | /// emitter. |
| 97 | std::vector<bool> DoNotEncode; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 98 | |
Nate Begeman | 8ef9d16 | 2005-11-30 23:58:18 +0000 | [diff] [blame] | 99 | /// MIOperandInfo - Default MI operand type. Note an operand may be made |
| 100 | /// up of multiple MI operands. |
Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 101 | DagInit *MIOperandInfo; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 0bb7500 | 2006-11-15 02:38:17 +0000 | [diff] [blame] | 103 | /// Constraint info for this operand. This operand can have pieces, so we |
| 104 | /// track constraint info for each. |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 105 | std::vector<ConstraintInfo> Constraints; |
Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 106 | |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 107 | OperandInfo(Record *R, const std::string &N, const std::string &PMN, |
Jim Grosbach | 5013f74 | 2010-10-12 22:21:57 +0000 | [diff] [blame^] | 108 | const std::string &EMN, unsigned MION, unsigned MINO, |
| 109 | DagInit *MIOI) |
| 110 | : Rec(R), Name(N), PrinterMethodName(PMN), EncoderMethodName(EMN), |
| 111 | MIOperandNo(MION), MINumOperands(MINO), MIOperandInfo(MIOI) {} |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 112 | }; |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 113 | |
Chris Lattner | cedef1c | 2010-03-18 20:50:52 +0000 | [diff] [blame] | 114 | /// NumDefs - Number of def operands declared, this is the number of |
| 115 | /// elements in the instruction's (outs) list. |
Evan Cheng | 64d80e3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 116 | /// |
| 117 | unsigned NumDefs; |
| 118 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 119 | /// OperandList - The list of declared operands, along with their declared |
| 120 | /// type (which is a record). |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 121 | std::vector<OperandInfo> OperandList; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 122 | |
Chris Lattner | f506b6b | 2010-03-18 21:42:03 +0000 | [diff] [blame] | 123 | /// ImplicitDefs/ImplicitUses - These are lists of registers that are |
| 124 | /// implicitly defined and used by the instruction. |
| 125 | std::vector<Record*> ImplicitDefs, ImplicitUses; |
| 126 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 127 | // Various boolean values we track for the instruction. |
| 128 | bool isReturn; |
| 129 | bool isBranch; |
Owen Anderson | 20ab290 | 2007-11-12 07:39:39 +0000 | [diff] [blame] | 130 | bool isIndirectBranch; |
Bill Wendling | 73739d0 | 2010-08-08 01:49:35 +0000 | [diff] [blame] | 131 | bool isCompare; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 132 | bool isBarrier; |
| 133 | bool isCall; |
Dan Gohman | 15511cf | 2008-12-03 18:15:48 +0000 | [diff] [blame] | 134 | bool canFoldAsLoad; |
Chris Lattner | dcc8b4f | 2008-01-08 18:05:21 +0000 | [diff] [blame] | 135 | bool mayLoad, mayStore; |
Evan Cheng | 5127ce0 | 2007-05-16 20:45:24 +0000 | [diff] [blame] | 136 | bool isPredicable; |
Chris Lattner | aad75aa | 2005-01-02 02:29:04 +0000 | [diff] [blame] | 137 | bool isConvertibleToThreeAddress; |
| 138 | bool isCommutable; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 139 | bool isTerminator; |
Dan Gohman | d45eddd | 2007-06-26 00:48:07 +0000 | [diff] [blame] | 140 | bool isReMaterializable; |
Chris Lattner | 5b71d3a | 2004-09-28 18:38:01 +0000 | [diff] [blame] | 141 | bool hasDelaySlot; |
Dan Gohman | 533297b | 2009-10-29 18:10:34 +0000 | [diff] [blame] | 142 | bool usesCustomInserter; |
Chris Lattner | 8f707e1 | 2008-01-07 05:19:29 +0000 | [diff] [blame] | 143 | bool isVariadic; |
Evan Cheng | 1c3d19e | 2005-12-04 08:18:16 +0000 | [diff] [blame] | 144 | bool hasCtrlDep; |
Evan Cheng | eaa91b0 | 2007-06-19 01:26:51 +0000 | [diff] [blame] | 145 | bool isNotDuplicable; |
Evan Cheng | 88cc092 | 2007-07-10 18:05:01 +0000 | [diff] [blame] | 146 | bool hasOptionalDef; |
Bill Wendling | 8370d38 | 2008-05-28 22:54:52 +0000 | [diff] [blame] | 147 | bool hasSideEffects; |
Bill Wendling | 8370d38 | 2008-05-28 22:54:52 +0000 | [diff] [blame] | 148 | bool neverHasSideEffects; |
| 149 | bool isAsCheapAsAMove; |
Evan Cheng | 799d697 | 2009-10-01 08:21:18 +0000 | [diff] [blame] | 150 | bool hasExtraSrcRegAllocReq; |
| 151 | bool hasExtraDefRegAllocReq; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 152 | |
Chris Lattner | 0bb7500 | 2006-11-15 02:38:17 +0000 | [diff] [blame] | 153 | /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar", |
| 154 | /// where $foo is a whole operand and $foo.bar refers to a suboperand. |
| 155 | /// This throws an exception if the name is invalid. If AllowWholeOp is |
| 156 | /// true, references to operands with suboperands are allowed, otherwise |
| 157 | /// not. |
| 158 | std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op, |
| 159 | bool AllowWholeOp = true); |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 160 | |
Chris Lattner | 0bb7500 | 2006-11-15 02:38:17 +0000 | [diff] [blame] | 161 | /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a |
| 162 | /// flat machineinstr operand #. |
| 163 | unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const { |
| 164 | return OperandList[Op.first].MIOperandNo + Op.second; |
| 165 | } |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 166 | |
Chris Lattner | f64f9a4 | 2006-11-15 23:23:02 +0000 | [diff] [blame] | 167 | /// getSubOperandNumber - Unflatten a operand number into an |
| 168 | /// operand/suboperand pair. |
| 169 | std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const { |
| 170 | for (unsigned i = 0; ; ++i) { |
| 171 | assert(i < OperandList.size() && "Invalid flat operand #"); |
| 172 | if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op) |
| 173 | return std::make_pair(i, Op-OperandList[i].MIOperandNo); |
| 174 | } |
| 175 | } |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 176 | |
| 177 | |
Chris Lattner | f64f9a4 | 2006-11-15 23:23:02 +0000 | [diff] [blame] | 178 | /// isFlatOperandNotEmitted - Return true if the specified flat operand # |
| 179 | /// should not be emitted with the code emitter. |
| 180 | bool isFlatOperandNotEmitted(unsigned FlatOpNo) const { |
| 181 | std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo); |
| 182 | if (OperandList[Op.first].DoNotEncode.size() > Op.second) |
| 183 | return OperandList[Op.first].DoNotEncode[Op.second]; |
| 184 | return false; |
| 185 | } |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 186 | |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 187 | CodeGenInstruction(Record *R, const std::string &AsmStr); |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 188 | |
| 189 | /// getOperandNamed - Return the index of the operand with the specified |
| 190 | /// non-empty name. If the instruction does not have an operand with the |
| 191 | /// specified name, throw an exception. |
| 192 | unsigned getOperandNamed(const std::string &Name) const; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 193 | |
Jim Grosbach | 0185507 | 2010-10-11 18:25:51 +0000 | [diff] [blame] | 194 | /// hasOperandNamed - Query whether the instruction has an operand of the |
| 195 | /// given name. If so, return true and set OpIdx to the index of the |
| 196 | /// operand. Otherwise, return false. |
| 197 | bool hasOperandNamed(const std::string &Name, unsigned &OpIdx) const; |
| 198 | |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 199 | /// HasOneImplicitDefWithKnownVT - If the instruction has at least one |
| 200 | /// implicit def and it has a known VT, return the VT, otherwise return |
| 201 | /// MVT::Other. |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 202 | MVT::SimpleValueType |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 203 | HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 204 | }; |
| 205 | } |
| 206 | |
| 207 | #endif |