1 //===- CodeGenInstruction.h - Instruction Class Wrapper ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a wrapper class for the 'Instruction' TableGen class.
12 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_INSTRUCTION_H
15 #define CODEGEN_INSTRUCTION_H
17 #include "llvm/CodeGen/ValueTypes.h"
27 class CodeGenInstruction {
29 Record *TheDef; // The actual record defining this instruction.
30 std::string Namespace; // The namespace the instruction is in.
32 /// AsmString - The format string used to emit a .s file for the
34 std::string AsmString;
36 class ConstraintInfo {
37 enum { None, EarlyClobber, Tied } Kind;
38 unsigned OtherTiedOperand;
40 ConstraintInfo() : Kind(None) {}
42 static ConstraintInfo getEarlyClobber() {
44 I.Kind = EarlyClobber;
45 I.OtherTiedOperand = 0;
49 static ConstraintInfo getTied(unsigned Op) {
52 I.OtherTiedOperand = Op;
56 bool isNone() const { return Kind == None; }
57 bool isEarlyClobber() const { return Kind == EarlyClobber; }
58 bool isTied() const { return Kind == Tied; }
60 unsigned getTiedOperand() const {
62 return OtherTiedOperand;
66 /// OperandInfo - The information we keep track of for each operand in the
67 /// operand list for a tablegen instruction.
69 /// Rec - The definition this operand is declared as.
73 /// Name - If this operand was assigned a symbolic name, this is it,
74 /// otherwise, it's empty.
77 /// PrinterMethodName - The method used to print operands of this type in
79 std::string PrinterMethodName;
81 /// MIOperandNo - Currently (this is meant to be phased out), some logical
82 /// operands correspond to multiple MachineInstr operands. In the X86
83 /// target for example, one address operand is represented as 4
84 /// MachineOperands. Because of this, the operand number in the
85 /// OperandList may not match the MachineInstr operand num. Until it
86 /// does, this contains the MI operand index of this operand.
88 unsigned MINumOperands; // The number of operands.
90 /// DoNotEncode - Bools are set to true in this vector for each operand in
91 /// the DisableEncoding list. These should not be emitted by the code
93 std::vector<bool> DoNotEncode;
95 /// MIOperandInfo - Default MI operand type. Note an operand may be made
96 /// up of multiple MI operands.
97 DagInit *MIOperandInfo;
99 /// Constraint info for this operand. This operand can have pieces, so we
100 /// track constraint info for each.
101 std::vector<ConstraintInfo> Constraints;
103 OperandInfo(Record *R, const std::string &N, const std::string &PMN,
104 unsigned MION, unsigned MINO, DagInit *MIOI)
105 : Rec(R), Name(N), PrinterMethodName(PMN), MIOperandNo(MION),
106 MINumOperands(MINO), MIOperandInfo(MIOI) {}
109 /// NumDefs - Number of def operands declared, this is the number of
110 /// elements in the instruction's (outs) list.
114 /// OperandList - The list of declared operands, along with their declared
115 /// type (which is a record).
116 std::vector<OperandInfo> OperandList;
118 /// ImplicitDefs/ImplicitUses - These are lists of registers that are
119 /// implicitly defined and used by the instruction.
120 std::vector<Record*> ImplicitDefs, ImplicitUses;
122 // Various boolean values we track for the instruction.
125 bool isIndirectBranch;
129 bool mayLoad, mayStore;
131 bool isConvertibleToThreeAddress;
134 bool isReMaterializable;
136 bool usesCustomInserter;
139 bool isNotDuplicable;
142 bool neverHasSideEffects;
143 bool isAsCheapAsAMove;
144 bool hasExtraSrcRegAllocReq;
145 bool hasExtraDefRegAllocReq;
147 /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar",
148 /// where $foo is a whole operand and $foo.bar refers to a suboperand.
149 /// This throws an exception if the name is invalid. If AllowWholeOp is
150 /// true, references to operands with suboperands are allowed, otherwise
152 std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op,
153 bool AllowWholeOp = true);
155 /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a
156 /// flat machineinstr operand #.
157 unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const {
158 return OperandList[Op.first].MIOperandNo + Op.second;
161 /// getSubOperandNumber - Unflatten a operand number into an
162 /// operand/suboperand pair.
163 std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const {
164 for (unsigned i = 0; ; ++i) {
165 assert(i < OperandList.size() && "Invalid flat operand #");
166 if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op)
167 return std::make_pair(i, Op-OperandList[i].MIOperandNo);
172 /// isFlatOperandNotEmitted - Return true if the specified flat operand #
173 /// should not be emitted with the code emitter.
174 bool isFlatOperandNotEmitted(unsigned FlatOpNo) const {
175 std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo);
176 if (OperandList[Op.first].DoNotEncode.size() > Op.second)
177 return OperandList[Op.first].DoNotEncode[Op.second];
181 CodeGenInstruction(Record *R, const std::string &AsmStr);
183 /// getOperandNamed - Return the index of the operand with the specified
184 /// non-empty name. If the instruction does not have an operand with the
185 /// specified name, throw an exception.
186 unsigned getOperandNamed(const std::string &Name) const;
188 /// HasOneImplicitDefWithKnownVT - If the instruction has at least one
189 /// implicit def and it has a known VT, return the VT, otherwise return
192 HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const;