| 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 | // | 
 | 5 | // This file was developed by the LLVM research group and is distributed under | 
 | 6 | // the University of Illinois Open Source 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 | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 25 |  | 
| Jeff Cohen | d41b30d | 2006-11-05 19:31:28 +0000 | [diff] [blame] | 26 |   class CodeGenInstruction { | 
 | 27 |   public: | 
| Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 28 |     Record *TheDef;            // The actual record defining this instruction. | 
 | 29 |     std::string Name;          // Contents of the 'Name' field. | 
 | 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; | 
| Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 35 |  | 
| Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 36 |     /// OperandInfo - The information we keep track of for each operand in the | 
 | 37 |     /// operand list for a tablegen instruction. | 
| Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 38 |     struct OperandInfo { | 
| Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 39 |       /// Rec - The definition this operand is declared as. | 
| Chris Lattner | 0e384b6 | 2005-08-19 16:57:28 +0000 | [diff] [blame] | 40 |       /// | 
| Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 41 |       Record *Rec; | 
| Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 42 |  | 
| Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 43 |       /// Name - If this operand was assigned a symbolic name, this is it, | 
 | 44 |       /// otherwise, it's empty. | 
| Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 45 |       std::string Name; | 
| Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 46 |  | 
 | 47 |       /// PrinterMethodName - The method used to print operands of this type in | 
 | 48 |       /// the asmprinter. | 
 | 49 |       std::string PrinterMethodName; | 
 | 50 |  | 
 | 51 |       /// MIOperandNo - Currently (this is meant to be phased out), some logical | 
 | 52 |       /// operands correspond to multiple MachineInstr operands.  In the X86 | 
 | 53 |       /// target for example, one address operand is represented as 4 | 
 | 54 |       /// MachineOperands.  Because of this, the operand number in the | 
 | 55 |       /// OperandList may not match the MachineInstr operand num.  Until it | 
 | 56 |       /// does, this contains the MI operand index of this operand. | 
 | 57 |       unsigned MIOperandNo; | 
| Chris Lattner | cfbf96a | 2005-08-18 23:38:41 +0000 | [diff] [blame] | 58 |       unsigned MINumOperands;   // The number of operands. | 
| Chris Lattner | cf03da0 | 2004-08-11 02:22:39 +0000 | [diff] [blame] | 59 |  | 
| Chris Lattner | f64f9a4 | 2006-11-15 23:23:02 +0000 | [diff] [blame] | 60 |       /// DoNotEncode - Bools are set to true in this vector for each operand in | 
 | 61 |       /// the DisableEncoding list.  These should not be emitted by the code | 
 | 62 |       /// emitter. | 
 | 63 |       std::vector<bool> DoNotEncode; | 
 | 64 |        | 
| Nate Begeman | 8ef9d16 | 2005-11-30 23:58:18 +0000 | [diff] [blame] | 65 |       /// MIOperandInfo - Default MI operand type. Note an operand may be made | 
 | 66 |       /// up of multiple MI operands. | 
| Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 67 |       DagInit *MIOperandInfo; | 
| Chris Lattner | a0cca4a | 2006-11-06 23:49:51 +0000 | [diff] [blame] | 68 |        | 
| Chris Lattner | 0bb7500 | 2006-11-15 02:38:17 +0000 | [diff] [blame] | 69 |       /// Constraint info for this operand.  This operand can have pieces, so we | 
 | 70 |       /// track constraint info for each. | 
 | 71 |       std::vector<std::string> Constraints; | 
| Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 72 |  | 
| Nate Begeman | 86193d1 | 2005-12-01 00:12:04 +0000 | [diff] [blame] | 73 |       OperandInfo(Record *R, const std::string &N, const std::string &PMN,  | 
 | 74 |                   unsigned MION, unsigned MINO, DagInit *MIOI) | 
 | 75 |         : Rec(R), Name(N), PrinterMethodName(PMN), MIOperandNo(MION), | 
| Chris Lattner | 65303d6 | 2005-11-19 07:05:57 +0000 | [diff] [blame] | 76 |           MINumOperands(MINO), MIOperandInfo(MIOI) {} | 
| Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 77 |     }; | 
| Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 78 |  | 
| Evan Cheng | 64d80e3 | 2007-07-19 01:14:50 +0000 | [diff] [blame] | 79 |     /// NumDefs - Number of def operands declared. | 
 | 80 |     /// | 
 | 81 |     unsigned NumDefs; | 
 | 82 |  | 
| Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 83 |     /// OperandList - The list of declared operands, along with their declared | 
 | 84 |     /// type (which is a record). | 
| Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 85 |     std::vector<OperandInfo> OperandList; | 
| Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 86 |  | 
 | 87 |     // Various boolean values we track for the instruction. | 
 | 88 |     bool isReturn; | 
 | 89 |     bool isBranch; | 
 | 90 |     bool isBarrier; | 
 | 91 |     bool isCall; | 
| Nate Begeman | cdd66b5 | 2004-09-28 21:01:45 +0000 | [diff] [blame] | 92 |     bool isLoad; | 
 | 93 |     bool isStore; | 
| Evan Cheng | 5127ce0 | 2007-05-16 20:45:24 +0000 | [diff] [blame] | 94 |     bool isPredicable; | 
| Chris Lattner | aad75aa | 2005-01-02 02:29:04 +0000 | [diff] [blame] | 95 |     bool isConvertibleToThreeAddress; | 
 | 96 |     bool isCommutable; | 
| Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 97 |     bool isTerminator; | 
| Dan Gohman | d45eddd | 2007-06-26 00:48:07 +0000 | [diff] [blame] | 98 |     bool isReMaterializable; | 
| Chris Lattner | 5b71d3a | 2004-09-28 18:38:01 +0000 | [diff] [blame] | 99 |     bool hasDelaySlot; | 
| Chris Lattner | 5f89bf0 | 2005-08-26 20:42:52 +0000 | [diff] [blame] | 100 |     bool usesCustomDAGSchedInserter; | 
| Chris Lattner | cfbf96a | 2005-08-18 23:38:41 +0000 | [diff] [blame] | 101 |     bool hasVariableNumberOfOperands; | 
| Evan Cheng | 1c3d19e | 2005-12-04 08:18:16 +0000 | [diff] [blame] | 102 |     bool hasCtrlDep; | 
| Evan Cheng | eaa91b0 | 2007-06-19 01:26:51 +0000 | [diff] [blame] | 103 |     bool isNotDuplicable; | 
| Evan Cheng | 88cc092 | 2007-07-10 18:05:01 +0000 | [diff] [blame] | 104 |     bool hasOptionalDef; | 
| Chris Lattner | 0bb7500 | 2006-11-15 02:38:17 +0000 | [diff] [blame] | 105 |      | 
 | 106 |     /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar", | 
 | 107 |     /// where $foo is a whole operand and $foo.bar refers to a suboperand. | 
 | 108 |     /// This throws an exception if the name is invalid.  If AllowWholeOp is | 
 | 109 |     /// true, references to operands with suboperands are allowed, otherwise | 
 | 110 |     /// not. | 
 | 111 |     std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op, | 
 | 112 |                                                   bool AllowWholeOp = true); | 
 | 113 |      | 
 | 114 |     /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a | 
 | 115 |     /// flat machineinstr operand #. | 
 | 116 |     unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const { | 
 | 117 |       return OperandList[Op.first].MIOperandNo + Op.second; | 
 | 118 |     } | 
 | 119 |      | 
| Chris Lattner | f64f9a4 | 2006-11-15 23:23:02 +0000 | [diff] [blame] | 120 |     /// getSubOperandNumber - Unflatten a operand number into an | 
 | 121 |     /// operand/suboperand pair. | 
 | 122 |     std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const { | 
 | 123 |       for (unsigned i = 0; ; ++i) { | 
 | 124 |         assert(i < OperandList.size() && "Invalid flat operand #"); | 
 | 125 |         if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op) | 
 | 126 |           return std::make_pair(i, Op-OperandList[i].MIOperandNo); | 
 | 127 |       } | 
 | 128 |     } | 
 | 129 |      | 
 | 130 |      | 
 | 131 |     /// isFlatOperandNotEmitted - Return true if the specified flat operand # | 
 | 132 |     /// should not be emitted with the code emitter. | 
 | 133 |     bool isFlatOperandNotEmitted(unsigned FlatOpNo) const { | 
 | 134 |       std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo); | 
 | 135 |       if (OperandList[Op.first].DoNotEncode.size() > Op.second) | 
 | 136 |         return OperandList[Op.first].DoNotEncode[Op.second]; | 
 | 137 |       return false; | 
 | 138 |     } | 
| Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 139 |  | 
| Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 140 |     CodeGenInstruction(Record *R, const std::string &AsmStr); | 
| Chris Lattner | 87c5905 | 2004-08-01 07:42:39 +0000 | [diff] [blame] | 141 |  | 
 | 142 |     /// getOperandNamed - Return the index of the operand with the specified | 
 | 143 |     /// non-empty name.  If the instruction does not have an operand with the | 
 | 144 |     /// specified name, throw an exception. | 
 | 145 |     unsigned getOperandNamed(const std::string &Name) const; | 
| Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 146 |   }; | 
 | 147 | } | 
 | 148 |  | 
 | 149 | #endif |