we don't want people to override printBasicBlockLabel.
[llvm/avr.git] / utils / TableGen / CodeGenInstruction.h
blobf4afd5e45ba3ead9e5d63dbfe338a1dd9b4808e1
1 //===- CodeGenInstruction.h - Instruction Class Wrapper ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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"
18 #include <string>
19 #include <vector>
20 #include <utility>
22 namespace llvm {
23 class Record;
24 class DagInit;
26 class CodeGenInstruction {
27 public:
28 Record *TheDef; // The actual record defining this instruction.
29 std::string Namespace; // The namespace the instruction is in.
31 /// AsmString - The format string used to emit a .s file for the
32 /// instruction.
33 std::string AsmString;
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;
42 /// Name - If this operand was assigned a symbolic name, this is it,
43 /// otherwise, it's empty.
44 std::string Name;
46 /// PrinterMethodName - The method used to print operands of this type in
47 /// the asmprinter.
48 std::string PrinterMethodName;
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.
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;
64 /// MIOperandInfo - Default MI operand type. Note an operand may be made
65 /// up of multiple MI operands.
66 DagInit *MIOperandInfo;
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;
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) {}
78 /// NumDefs - Number of def operands declared.
79 ///
80 unsigned NumDefs;
82 /// OperandList - The list of declared operands, along with their declared
83 /// type (which is a record).
84 std::vector<OperandInfo> OperandList;
86 // Various boolean values we track for the instruction.
87 bool isReturn;
88 bool isBranch;
89 bool isIndirectBranch;
90 bool isBarrier;
91 bool isCall;
92 bool canFoldAsLoad;
93 bool mayLoad, mayStore;
94 bool isPredicable;
95 bool isConvertibleToThreeAddress;
96 bool isCommutable;
97 bool isTerminator;
98 bool isReMaterializable;
99 bool hasDelaySlot;
100 bool usesCustomDAGSchedInserter;
101 bool isVariadic;
102 bool hasCtrlDep;
103 bool isNotDuplicable;
104 bool hasOptionalDef;
105 bool hasSideEffects;
106 bool mayHaveSideEffects;
107 bool neverHasSideEffects;
108 bool isAsCheapAsAMove;
110 /// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar",
111 /// where $foo is a whole operand and $foo.bar refers to a suboperand.
112 /// This throws an exception if the name is invalid. If AllowWholeOp is
113 /// true, references to operands with suboperands are allowed, otherwise
114 /// not.
115 std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op,
116 bool AllowWholeOp = true);
118 /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a
119 /// flat machineinstr operand #.
120 unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const {
121 return OperandList[Op.first].MIOperandNo + Op.second;
124 /// getSubOperandNumber - Unflatten a operand number into an
125 /// operand/suboperand pair.
126 std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const {
127 for (unsigned i = 0; ; ++i) {
128 assert(i < OperandList.size() && "Invalid flat operand #");
129 if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op)
130 return std::make_pair(i, Op-OperandList[i].MIOperandNo);
135 /// isFlatOperandNotEmitted - Return true if the specified flat operand #
136 /// should not be emitted with the code emitter.
137 bool isFlatOperandNotEmitted(unsigned FlatOpNo) const {
138 std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo);
139 if (OperandList[Op.first].DoNotEncode.size() > Op.second)
140 return OperandList[Op.first].DoNotEncode[Op.second];
141 return false;
144 CodeGenInstruction(Record *R, const std::string &AsmStr);
146 /// getOperandNamed - Return the index of the operand with the specified
147 /// non-empty name. If the instruction does not have an operand with the
148 /// specified name, throw an exception.
149 unsigned getOperandNamed(const std::string &Name) const;
153 #endif