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 | 225549f | 2010-11-06 06:39:47 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringRef.h" |
Bob Wilson | a49c7df | 2011-01-26 19:44:55 +0000 | [diff] [blame] | 19 | #include "llvm/Support/SourceMgr.h" |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | #include <utility> |
| 23 | |
| 24 | namespace llvm { |
| 25 | class Record; |
Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 26 | class DagInit; |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 27 | class CodeGenTarget; |
Chris Lattner | 4d43d0f | 2010-11-01 01:07:14 +0000 | [diff] [blame] | 28 | class StringRef; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 29 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 30 | class CGIOperandList { |
Jeff Cohen | d41b30d | 2006-11-05 19:31:28 +0000 | [diff] [blame] | 31 | public: |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 32 | class ConstraintInfo { |
| 33 | enum { None, EarlyClobber, Tied } Kind; |
| 34 | unsigned OtherTiedOperand; |
| 35 | public: |
| 36 | ConstraintInfo() : Kind(None) {} |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 37 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 38 | static ConstraintInfo getEarlyClobber() { |
| 39 | ConstraintInfo I; |
| 40 | I.Kind = EarlyClobber; |
Chris Lattner | e555c9f | 2010-02-10 21:22:51 +0000 | [diff] [blame] | 41 | I.OtherTiedOperand = 0; |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 42 | return I; |
| 43 | } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 44 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 45 | static ConstraintInfo getTied(unsigned Op) { |
| 46 | ConstraintInfo I; |
| 47 | I.Kind = Tied; |
| 48 | I.OtherTiedOperand = Op; |
| 49 | return I; |
| 50 | } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 51 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 52 | bool isNone() const { return Kind == None; } |
| 53 | bool isEarlyClobber() const { return Kind == EarlyClobber; } |
| 54 | bool isTied() const { return Kind == Tied; } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 55 | |
Chris Lattner | a7d479c | 2010-02-10 01:45:28 +0000 | [diff] [blame] | 56 | unsigned getTiedOperand() const { |
| 57 | assert(isTied()); |
| 58 | return OtherTiedOperand; |
| 59 | } |
| 60 | }; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 61 | |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 62 | /// OperandInfo - The information we keep track of for each operand in the |
| 63 | /// operand list for a tablegen instruction. |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 64 | struct OperandInfo { |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 65 | /// Rec - The definition this operand is declared as. |
Chris Lattner | 0e384b6 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 66 | /// |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 67 | Record *Rec; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 68 | |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 69 | /// Name - If this operand was assigned a symbolic name, this is it, |
| 70 | /// otherwise, it's empty. |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 71 | std::string Name; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 72 | |
Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 73 | /// PrinterMethodName - The method used to print operands of this type in |
| 74 | /// the asmprinter. |
| 75 | std::string PrinterMethodName; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 76 | |
Jim Grosbach | 5013f74 | 2010-10-12 22:21:57 +0000 | [diff] [blame] | 77 | /// EncoderMethodName - The method used to get the machine operand value |
| 78 | /// for binary encoding. "getMachineOpValue" by default. |
| 79 | std::string EncoderMethodName; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 80 | |
Benjamin Kramer | 5196c12 | 2011-07-14 21:47:18 +0000 | [diff] [blame] | 81 | /// OperandType - A value from MCOI::OperandType representing the type of |
| 82 | /// the operand. |
| 83 | std::string OperandType; |
| 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. |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +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 | 0c4d44a | 2011-03-14 17:32:49 +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. |
David Greene | 05bce0b | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 101 | DagInit *MIOperandInfo; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +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; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +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, |
Benjamin Kramer | 5196c12 | 2011-07-14 21:47:18 +0000 | [diff] [blame] | 108 | const std::string &EMN, const std::string &OT, unsigned MION, |
David Greene | 05bce0b | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 109 | unsigned MINO, DagInit *MIOI) |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 110 | : Rec(R), Name(N), PrinterMethodName(PMN), EncoderMethodName(EMN), |
Benjamin Kramer | 5196c12 | 2011-07-14 21:47:18 +0000 | [diff] [blame] | 111 | OperandType(OT), MIOperandNo(MION), MINumOperands(MINO), |
| 112 | MIOperandInfo(MIOI) {} |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 113 | |
| 114 | |
Chris Lattner | 9b0d4bf | 2010-11-02 22:55:03 +0000 | [diff] [blame] | 115 | /// getTiedOperand - If this operand is tied to another one, return the |
| 116 | /// other operand number. Otherwise, return -1. |
| 117 | int getTiedRegister() const { |
| 118 | for (unsigned j = 0, e = Constraints.size(); j != e; ++j) { |
| 119 | const CGIOperandList::ConstraintInfo &CI = Constraints[j]; |
| 120 | if (CI.isTied()) return CI.getTiedOperand(); |
| 121 | } |
| 122 | return -1; |
| 123 | } |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 124 | }; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 125 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 126 | CGIOperandList(Record *D); |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 127 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 128 | Record *TheDef; // The actual record containing this OperandList. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 129 | |
Chris Lattner | cedef1c | 2010-03-18 20:50:52 +0000 | [diff] [blame] | 130 | /// NumDefs - Number of def operands declared, this is the number of |
| 131 | /// elements in the instruction's (outs) list. |
Evan Cheng | 64d80e3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 132 | /// |
| 133 | unsigned NumDefs; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 134 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 135 | /// OperandList - The list of declared operands, along with their declared |
| 136 | /// type (which is a record). |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 137 | std::vector<OperandInfo> OperandList; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 138 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 139 | // Information gleaned from the operand list. |
| 140 | bool isPredicable; |
| 141 | bool hasOptionalDef; |
| 142 | bool isVariadic; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 143 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 144 | // Provide transparent accessors to the operand list. |
Chris Lattner | a90dbc1 | 2011-04-17 22:24:13 +0000 | [diff] [blame] | 145 | bool empty() const { return OperandList.empty(); } |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 146 | unsigned size() const { return OperandList.size(); } |
| 147 | const OperandInfo &operator[](unsigned i) const { return OperandList[i]; } |
| 148 | OperandInfo &operator[](unsigned i) { return OperandList[i]; } |
| 149 | OperandInfo &back() { return OperandList.back(); } |
| 150 | const OperandInfo &back() const { return OperandList.back(); } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 151 | |
| 152 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 153 | /// getOperandNamed - Return the index of the operand with the specified |
| 154 | /// non-empty name. If the instruction does not have an operand with the |
| 155 | /// specified name, throw an exception. |
| 156 | unsigned getOperandNamed(StringRef Name) const; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 157 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 158 | /// hasOperandNamed - Query whether the instruction has an operand of the |
| 159 | /// given name. If so, return true and set OpIdx to the index of the |
| 160 | /// operand. Otherwise, return false. |
| 161 | bool hasOperandNamed(StringRef Name, unsigned &OpIdx) const; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 162 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 163 | /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar", |
| 164 | /// where $foo is a whole operand and $foo.bar refers to a suboperand. |
| 165 | /// This throws an exception if the name is invalid. If AllowWholeOp is |
| 166 | /// true, references to operands with suboperands are allowed, otherwise |
| 167 | /// not. |
| 168 | std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op, |
| 169 | bool AllowWholeOp = true); |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 170 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 171 | /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a |
| 172 | /// flat machineinstr operand #. |
| 173 | unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const { |
| 174 | return OperandList[Op.first].MIOperandNo + Op.second; |
| 175 | } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 176 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 177 | /// getSubOperandNumber - Unflatten a operand number into an |
| 178 | /// operand/suboperand pair. |
| 179 | std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const { |
| 180 | for (unsigned i = 0; ; ++i) { |
| 181 | assert(i < OperandList.size() && "Invalid flat operand #"); |
| 182 | if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op) |
| 183 | return std::make_pair(i, Op-OperandList[i].MIOperandNo); |
| 184 | } |
| 185 | } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 186 | |
| 187 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 188 | /// isFlatOperandNotEmitted - Return true if the specified flat operand # |
| 189 | /// should not be emitted with the code emitter. |
| 190 | bool isFlatOperandNotEmitted(unsigned FlatOpNo) const { |
| 191 | std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo); |
| 192 | if (OperandList[Op.first].DoNotEncode.size() > Op.second) |
| 193 | return OperandList[Op.first].DoNotEncode[Op.second]; |
| 194 | return false; |
| 195 | } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 196 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 197 | void ProcessDisableEncoding(std::string Value); |
| 198 | }; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 199 | |
Chris Lattner | c240bb0 | 2010-11-01 04:03:32 +0000 | [diff] [blame] | 200 | |
| 201 | class CodeGenInstruction { |
| 202 | public: |
| 203 | Record *TheDef; // The actual record defining this instruction. |
| 204 | std::string Namespace; // The namespace the instruction is in. |
| 205 | |
| 206 | /// AsmString - The format string used to emit a .s file for the |
| 207 | /// instruction. |
| 208 | std::string AsmString; |
| 209 | |
| 210 | /// Operands - This is information about the (ins) and (outs) list specified |
| 211 | /// to the instruction. |
| 212 | CGIOperandList Operands; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 213 | |
Chris Lattner | f506b6b | 2010-03-18 21:42:03 +0000 | [diff] [blame] | 214 | /// ImplicitDefs/ImplicitUses - These are lists of registers that are |
| 215 | /// implicitly defined and used by the instruction. |
| 216 | std::vector<Record*> ImplicitDefs, ImplicitUses; |
| 217 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 218 | // Various boolean values we track for the instruction. |
| 219 | bool isReturn; |
| 220 | bool isBranch; |
Owen Anderson | 20ab290 | 2007-11-12 07:39:39 +0000 | [diff] [blame] | 221 | bool isIndirectBranch; |
Bill Wendling | 73739d0 | 2010-08-08 01:49:35 +0000 | [diff] [blame] | 222 | bool isCompare; |
Evan Cheng | c4af463 | 2010-11-17 20:13:28 +0000 | [diff] [blame] | 223 | bool isMoveImm; |
Evan Cheng | 0f040a2 | 2011-03-15 05:09:26 +0000 | [diff] [blame] | 224 | bool isBitcast; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 225 | bool isBarrier; |
| 226 | bool isCall; |
Dan Gohman | 15511cf | 2008-12-03 18:15:48 +0000 | [diff] [blame] | 227 | bool canFoldAsLoad; |
Chris Lattner | dcc8b4f | 2008-01-08 18:05:21 +0000 | [diff] [blame] | 228 | bool mayLoad, mayStore; |
Evan Cheng | 5127ce0 | 2007-05-16 20:45:24 +0000 | [diff] [blame] | 229 | bool isPredicable; |
Chris Lattner | aad75aa | 2005-01-02 02:29:04 +0000 | [diff] [blame] | 230 | bool isConvertibleToThreeAddress; |
| 231 | bool isCommutable; |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 232 | bool isTerminator; |
Dan Gohman | d45eddd | 2007-06-26 00:48:07 +0000 | [diff] [blame] | 233 | bool isReMaterializable; |
Chris Lattner | 5b71d3a | 2004-09-28 18:38:01 +0000 | [diff] [blame] | 234 | bool hasDelaySlot; |
Dan Gohman | 533297b | 2009-10-29 18:10:34 +0000 | [diff] [blame] | 235 | bool usesCustomInserter; |
Andrew Trick | 83a8031 | 2011-09-20 18:22:31 +0000 | [diff] [blame] | 236 | bool hasPostISelHook; |
Evan Cheng | 1c3d19e | 2005-12-04 08:18:16 +0000 | [diff] [blame] | 237 | bool hasCtrlDep; |
Evan Cheng | eaa91b0 | 2007-06-19 01:26:51 +0000 | [diff] [blame] | 238 | bool isNotDuplicable; |
Bill Wendling | 8370d38 | 2008-05-28 22:54:52 +0000 | [diff] [blame] | 239 | bool hasSideEffects; |
Bill Wendling | 8370d38 | 2008-05-28 22:54:52 +0000 | [diff] [blame] | 240 | bool neverHasSideEffects; |
| 241 | bool isAsCheapAsAMove; |
Evan Cheng | 799d697 | 2009-10-01 08:21:18 +0000 | [diff] [blame] | 242 | bool hasExtraSrcRegAllocReq; |
| 243 | bool hasExtraDefRegAllocReq; |
Jim Grosbach | e727d67 | 2011-07-07 00:48:02 +0000 | [diff] [blame] | 244 | bool isCodeGenOnly; |
Jim Grosbach | 806fcc0 | 2011-07-06 21:33:38 +0000 | [diff] [blame] | 245 | bool isPseudo; |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 246 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 247 | |
Chris Lattner | f780811 | 2010-11-01 02:15:23 +0000 | [diff] [blame] | 248 | CodeGenInstruction(Record *R); |
Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 249 | |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 250 | /// HasOneImplicitDefWithKnownVT - If the instruction has at least one |
| 251 | /// implicit def and it has a known VT, return the VT, otherwise return |
| 252 | /// MVT::Other. |
Jim Grosbach | 9ed2cee | 2010-10-08 18:09:59 +0000 | [diff] [blame] | 253 | MVT::SimpleValueType |
Chris Lattner | 9414ae5 | 2010-03-27 20:09:24 +0000 | [diff] [blame] | 254 | HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 255 | |
| 256 | |
Chris Lattner | 4d43d0f | 2010-11-01 01:07:14 +0000 | [diff] [blame] | 257 | /// FlattenAsmStringVariants - Flatten the specified AsmString to only |
| 258 | /// include text from the specified variant, returning the new string. |
| 259 | static std::string FlattenAsmStringVariants(StringRef AsmString, |
| 260 | unsigned Variant); |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 261 | }; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 262 | |
| 263 | |
Chris Lattner | c76e80d | 2010-11-01 04:05:41 +0000 | [diff] [blame] | 264 | /// CodeGenInstAlias - This represents an InstAlias definition. |
| 265 | class CodeGenInstAlias { |
| 266 | public: |
| 267 | Record *TheDef; // The actual record defining this InstAlias. |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 268 | |
Chris Lattner | c76e80d | 2010-11-01 04:05:41 +0000 | [diff] [blame] | 269 | /// AsmString - The format string used to emit a .s file for the |
| 270 | /// instruction. |
| 271 | std::string AsmString; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 272 | |
Chris Lattner | b501d4f | 2010-11-01 05:34:34 +0000 | [diff] [blame] | 273 | /// Result - The result instruction. |
David Greene | 05bce0b | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 274 | DagInit *Result; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 275 | |
Chris Lattner | 225549f | 2010-11-06 06:39:47 +0000 | [diff] [blame] | 276 | /// ResultInst - The instruction generated by the alias (decoded from |
| 277 | /// Result). |
| 278 | CodeGenInstruction *ResultInst; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 279 | |
| 280 | |
Chris Lattner | 225549f | 2010-11-06 06:39:47 +0000 | [diff] [blame] | 281 | struct ResultOperand { |
Chris Lattner | 98c870f | 2010-11-06 19:25:43 +0000 | [diff] [blame] | 282 | private: |
Owen Anderson | 7e8921b | 2012-06-08 00:25:03 +0000 | [diff] [blame] | 283 | std::string Name; |
Chris Lattner | 225549f | 2010-11-06 06:39:47 +0000 | [diff] [blame] | 284 | Record *R; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 285 | |
Chris Lattner | 98c870f | 2010-11-06 19:25:43 +0000 | [diff] [blame] | 286 | int64_t Imm; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 287 | public: |
Chris Lattner | 98c870f | 2010-11-06 19:25:43 +0000 | [diff] [blame] | 288 | enum { |
| 289 | K_Record, |
Chris Lattner | 90fd797 | 2010-11-06 19:57:21 +0000 | [diff] [blame] | 290 | K_Imm, |
| 291 | K_Reg |
Chris Lattner | 98c870f | 2010-11-06 19:25:43 +0000 | [diff] [blame] | 292 | } Kind; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 293 | |
Owen Anderson | 7e8921b | 2012-06-08 00:25:03 +0000 | [diff] [blame] | 294 | ResultOperand(std::string N, Record *r) : Name(N), R(r), Kind(K_Record) {} |
Chris Lattner | 98c870f | 2010-11-06 19:25:43 +0000 | [diff] [blame] | 295 | ResultOperand(int64_t I) : Imm(I), Kind(K_Imm) {} |
Chris Lattner | 90fd797 | 2010-11-06 19:57:21 +0000 | [diff] [blame] | 296 | ResultOperand(Record *r) : R(r), Kind(K_Reg) {} |
Chris Lattner | 98c870f | 2010-11-06 19:25:43 +0000 | [diff] [blame] | 297 | |
| 298 | bool isRecord() const { return Kind == K_Record; } |
| 299 | bool isImm() const { return Kind == K_Imm; } |
Chris Lattner | 90fd797 | 2010-11-06 19:57:21 +0000 | [diff] [blame] | 300 | bool isReg() const { return Kind == K_Reg; } |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 301 | |
Chris Lattner | 98c870f | 2010-11-06 19:25:43 +0000 | [diff] [blame] | 302 | StringRef getName() const { assert(isRecord()); return Name; } |
| 303 | Record *getRecord() const { assert(isRecord()); return R; } |
| 304 | int64_t getImm() const { assert(isImm()); return Imm; } |
Chris Lattner | 90fd797 | 2010-11-06 19:57:21 +0000 | [diff] [blame] | 305 | Record *getRegister() const { assert(isReg()); return R; } |
Chris Lattner | 225549f | 2010-11-06 06:39:47 +0000 | [diff] [blame] | 306 | }; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 307 | |
Chris Lattner | 225549f | 2010-11-06 06:39:47 +0000 | [diff] [blame] | 308 | /// ResultOperands - The decoded operands for the result instruction. |
| 309 | std::vector<ResultOperand> ResultOperands; |
Bob Wilson | 5e8f2a6 | 2011-01-20 18:38:02 +0000 | [diff] [blame] | 310 | |
Bob Wilson | a49c7df | 2011-01-26 19:44:55 +0000 | [diff] [blame] | 311 | /// ResultInstOperandIndex - For each operand, this vector holds a pair of |
| 312 | /// indices to identify the corresponding operand in the result |
| 313 | /// instruction. The first index specifies the operand and the second |
| 314 | /// index specifies the suboperand. If there are no suboperands or if all |
| 315 | /// of them are matched by the operand, the second value should be -1. |
| 316 | std::vector<std::pair<unsigned, int> > ResultInstOperandIndex; |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 317 | |
Chris Lattner | 225549f | 2010-11-06 06:39:47 +0000 | [diff] [blame] | 318 | CodeGenInstAlias(Record *R, CodeGenTarget &T); |
Bob Wilson | a49c7df | 2011-01-26 19:44:55 +0000 | [diff] [blame] | 319 | |
David Greene | 05bce0b | 2011-07-29 22:43:06 +0000 | [diff] [blame] | 320 | bool tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo, |
Bob Wilson | a49c7df | 2011-01-26 19:44:55 +0000 | [diff] [blame] | 321 | Record *InstOpRec, bool hasSubOps, SMLoc Loc, |
| 322 | CodeGenTarget &T, ResultOperand &ResOp); |
Jim Grosbach | 0c4d44a | 2011-03-14 17:32:49 +0000 | [diff] [blame] | 323 | }; |
Chris Lattner | c76e80d | 2010-11-01 04:05:41 +0000 | [diff] [blame] | 324 | } |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 325 | |
| 326 | #endif |