Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- CodeGenInstruction.h - Instruction Class Wrapper ---------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | fd6c2f0 | 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. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 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 | |
| 17 | #include "llvm/CodeGen/ValueTypes.h" |
| 18 | #include <string> |
| 19 | #include <vector> |
| 20 | #include <utility> |
| 21 | |
| 22 | namespace llvm { |
| 23 | class Record; |
| 24 | class DagInit; |
| 25 | |
| 26 | class CodeGenInstruction { |
| 27 | public: |
| 28 | Record *TheDef; // The actual record defining this instruction. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 29 | std::string Namespace; // The namespace the instruction is in. |
| 30 | |
| 31 | /// AsmString - The format string used to emit a .s file for the |
| 32 | /// instruction. |
| 33 | std::string AsmString; |
Chris Lattner | 4a7bcdc | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 34 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 35 | /// OperandInfo - The information we keep track of for each operand in the |
| 36 | /// operand list for a tablegen instruction. |
| 37 | struct OperandInfo { |
| 38 | /// Rec - The definition this operand is declared as. |
| 39 | /// |
| 40 | Record *Rec; |
| 41 | |
| 42 | /// Name - If this operand was assigned a symbolic name, this is it, |
| 43 | /// otherwise, it's empty. |
| 44 | std::string Name; |
| 45 | |
| 46 | /// PrinterMethodName - The method used to print operands of this type in |
| 47 | /// the asmprinter. |
| 48 | std::string PrinterMethodName; |
| 49 | |
| 50 | /// MIOperandNo - Currently (this is meant to be phased out), some logical |
| 51 | /// operands correspond to multiple MachineInstr operands. In the X86 |
| 52 | /// target for example, one address operand is represented as 4 |
| 53 | /// MachineOperands. Because of this, the operand number in the |
| 54 | /// OperandList may not match the MachineInstr operand num. Until it |
| 55 | /// does, this contains the MI operand index of this operand. |
| 56 | unsigned MIOperandNo; |
| 57 | unsigned MINumOperands; // The number of operands. |
| 58 | |
| 59 | /// DoNotEncode - Bools are set to true in this vector for each operand in |
| 60 | /// the DisableEncoding list. These should not be emitted by the code |
| 61 | /// emitter. |
| 62 | std::vector<bool> DoNotEncode; |
| 63 | |
| 64 | /// MIOperandInfo - Default MI operand type. Note an operand may be made |
| 65 | /// up of multiple MI operands. |
| 66 | DagInit *MIOperandInfo; |
| 67 | |
| 68 | /// Constraint info for this operand. This operand can have pieces, so we |
| 69 | /// track constraint info for each. |
| 70 | std::vector<std::string> Constraints; |
| 71 | |
| 72 | OperandInfo(Record *R, const std::string &N, const std::string &PMN, |
| 73 | unsigned MION, unsigned MINO, DagInit *MIOI) |
| 74 | : Rec(R), Name(N), PrinterMethodName(PMN), MIOperandNo(MION), |
| 75 | MINumOperands(MINO), MIOperandInfo(MIOI) {} |
| 76 | }; |
| 77 | |
Evan Cheng | b783fa3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 78 | /// NumDefs - Number of def operands declared. |
| 79 | /// |
| 80 | unsigned NumDefs; |
| 81 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 82 | /// OperandList - The list of declared operands, along with their declared |
| 83 | /// type (which is a record). |
| 84 | std::vector<OperandInfo> OperandList; |
| 85 | |
| 86 | // Various boolean values we track for the instruction. |
| 87 | bool isReturn; |
| 88 | bool isBranch; |
Owen Anderson | f805308 | 2007-11-12 07:39:39 +0000 | [diff] [blame] | 89 | bool isIndirectBranch; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 90 | bool isBarrier; |
| 91 | bool isCall; |
Chris Lattner | 1a1932c | 2008-01-06 23:38:27 +0000 | [diff] [blame] | 92 | bool isSimpleLoad; |
Chris Lattner | 6887b14 | 2008-01-06 08:36:04 +0000 | [diff] [blame] | 93 | bool mayStore; |
Evan Cheng | 6782f7f | 2007-12-13 00:42:35 +0000 | [diff] [blame] | 94 | bool isImplicitDef; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 95 | bool isPredicable; |
| 96 | bool isConvertibleToThreeAddress; |
| 97 | bool isCommutable; |
| 98 | bool isTerminator; |
| 99 | bool isReMaterializable; |
| 100 | bool hasDelaySlot; |
| 101 | bool usesCustomDAGSchedInserter; |
Chris Lattner | 2fb37c0 | 2008-01-07 05:19:29 +0000 | [diff] [blame^] | 102 | bool isVariadic; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 103 | bool hasCtrlDep; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 104 | bool isNotDuplicable; |
| 105 | bool hasOptionalDef; |
Bill Wendling | af109da | 2007-12-14 01:48:59 +0000 | [diff] [blame] | 106 | bool mayHaveSideEffects; |
| 107 | bool neverHasSideEffects; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 108 | |
| 109 | /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar", |
| 110 | /// where $foo is a whole operand and $foo.bar refers to a suboperand. |
| 111 | /// This throws an exception if the name is invalid. If AllowWholeOp is |
| 112 | /// true, references to operands with suboperands are allowed, otherwise |
| 113 | /// not. |
| 114 | std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op, |
| 115 | bool AllowWholeOp = true); |
| 116 | |
| 117 | /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a |
| 118 | /// flat machineinstr operand #. |
| 119 | unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const { |
| 120 | return OperandList[Op.first].MIOperandNo + Op.second; |
| 121 | } |
| 122 | |
| 123 | /// getSubOperandNumber - Unflatten a operand number into an |
| 124 | /// operand/suboperand pair. |
| 125 | std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const { |
| 126 | for (unsigned i = 0; ; ++i) { |
| 127 | assert(i < OperandList.size() && "Invalid flat operand #"); |
| 128 | if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op) |
| 129 | return std::make_pair(i, Op-OperandList[i].MIOperandNo); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /// isFlatOperandNotEmitted - Return true if the specified flat operand # |
| 135 | /// should not be emitted with the code emitter. |
| 136 | bool isFlatOperandNotEmitted(unsigned FlatOpNo) const { |
| 137 | std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo); |
| 138 | if (OperandList[Op.first].DoNotEncode.size() > Op.second) |
| 139 | return OperandList[Op.first].DoNotEncode[Op.second]; |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | CodeGenInstruction(Record *R, const std::string &AsmStr); |
| 144 | |
| 145 | /// getOperandNamed - Return the index of the operand with the specified |
| 146 | /// non-empty name. If the instruction does not have an operand with the |
| 147 | /// specified name, throw an exception. |
| 148 | unsigned getOperandNamed(const std::string &Name) const; |
| 149 | }; |
| 150 | } |
| 151 | |
| 152 | #endif |