blob: 249c1df75c835d2c3cc7c76eec47b4cc8613a490 [file] [log] [blame]
Chris Lattnerec352402004-08-01 05:04:00 +00001//===- CodeGenInstruction.h - Instruction Class Wrapper ---------*- C++ -*-===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
Chris Lattnerec352402004-08-01 05:04:00 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
Chris Lattnerec352402004-08-01 05:04:00 +00008//===----------------------------------------------------------------------===//
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 Lattner87c59052004-08-01 07:42:39 +000017#include "llvm/CodeGen/ValueTypes.h"
Chris Lattnerec352402004-08-01 05:04:00 +000018#include <string>
19#include <vector>
20#include <utility>
21
22namespace llvm {
23 class Record;
Chris Lattner65303d62005-11-19 07:05:57 +000024 class DagInit;
Chris Lattnerec352402004-08-01 05:04:00 +000025
Jeff Cohend41b30d2006-11-05 19:31:28 +000026 class CodeGenInstruction {
27 public:
Chris Lattnerec352402004-08-01 05:04:00 +000028 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 Lattner87c59052004-08-01 07:42:39 +000035
Chris Lattnercf03da02004-08-11 02:22:39 +000036 /// OperandInfo - The information we keep track of for each operand in the
37 /// operand list for a tablegen instruction.
Chris Lattner87c59052004-08-01 07:42:39 +000038 struct OperandInfo {
Chris Lattnercf03da02004-08-11 02:22:39 +000039 /// Rec - The definition this operand is declared as.
Chris Lattner0e384b62005-08-19 16:57:28 +000040 ///
Chris Lattner87c59052004-08-01 07:42:39 +000041 Record *Rec;
Chris Lattnercf03da02004-08-11 02:22:39 +000042
Chris Lattnercf03da02004-08-11 02:22:39 +000043 /// Name - If this operand was assigned a symbolic name, this is it,
44 /// otherwise, it's empty.
Chris Lattner87c59052004-08-01 07:42:39 +000045 std::string Name;
Chris Lattnercf03da02004-08-11 02:22:39 +000046
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 Lattnercfbf96a2005-08-18 23:38:41 +000058 unsigned MINumOperands; // The number of operands.
Chris Lattnercf03da02004-08-11 02:22:39 +000059
Chris Lattnerf64f9a42006-11-15 23:23:02 +000060 /// 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 Begeman8ef9d162005-11-30 23:58:18 +000065 /// MIOperandInfo - Default MI operand type. Note an operand may be made
66 /// up of multiple MI operands.
Chris Lattner65303d62005-11-19 07:05:57 +000067 DagInit *MIOperandInfo;
Chris Lattnera0cca4a2006-11-06 23:49:51 +000068
Chris Lattner0bb75002006-11-15 02:38:17 +000069 /// 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 Lattner65303d62005-11-19 07:05:57 +000072
Nate Begeman86193d12005-12-01 00:12:04 +000073 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 Lattner65303d62005-11-19 07:05:57 +000076 MINumOperands(MINO), MIOperandInfo(MIOI) {}
Chris Lattner87c59052004-08-01 07:42:39 +000077 };
Misha Brukman3da94ae2005-04-22 00:00:37 +000078
Evan Cheng64d80e32007-07-19 01:14:50 +000079 /// NumDefs - Number of def operands declared.
80 ///
81 unsigned NumDefs;
82
Chris Lattnerec352402004-08-01 05:04:00 +000083 /// OperandList - The list of declared operands, along with their declared
84 /// type (which is a record).
Chris Lattner87c59052004-08-01 07:42:39 +000085 std::vector<OperandInfo> OperandList;
Chris Lattnerec352402004-08-01 05:04:00 +000086
87 // Various boolean values we track for the instruction.
88 bool isReturn;
89 bool isBranch;
Owen Anderson20ab2902007-11-12 07:39:39 +000090 bool isIndirectBranch;
Chris Lattnerec352402004-08-01 05:04:00 +000091 bool isBarrier;
92 bool isCall;
Nate Begemancdd66b52004-09-28 21:01:45 +000093 bool isLoad;
94 bool isStore;
Evan Cheng3dd298f2007-12-13 00:42:35 +000095 bool isImplicitDef;
Evan Cheng5127ce02007-05-16 20:45:24 +000096 bool isPredicable;
Chris Lattneraad75aa2005-01-02 02:29:04 +000097 bool isConvertibleToThreeAddress;
98 bool isCommutable;
Chris Lattnerec352402004-08-01 05:04:00 +000099 bool isTerminator;
Dan Gohmand45eddd2007-06-26 00:48:07 +0000100 bool isReMaterializable;
Chris Lattner5b71d3a2004-09-28 18:38:01 +0000101 bool hasDelaySlot;
Chris Lattner5f89bf02005-08-26 20:42:52 +0000102 bool usesCustomDAGSchedInserter;
Chris Lattnercfbf96a2005-08-18 23:38:41 +0000103 bool hasVariableNumberOfOperands;
Evan Cheng1c3d19e2005-12-04 08:18:16 +0000104 bool hasCtrlDep;
Evan Chengeaa91b02007-06-19 01:26:51 +0000105 bool isNotDuplicable;
Evan Cheng88cc0922007-07-10 18:05:01 +0000106 bool hasOptionalDef;
Bill Wendling6b1da9c2007-12-14 01:48:59 +0000107 bool mayHaveSideEffects;
108 bool neverHasSideEffects;
Chris Lattner0bb75002006-11-15 02:38:17 +0000109
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);
117
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;
122 }
123
Chris Lattnerf64f9a42006-11-15 23:23:02 +0000124 /// 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);
131 }
132 }
133
134
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;
142 }
Chris Lattnerec352402004-08-01 05:04:00 +0000143
Chris Lattner175580c2004-08-14 22:50:53 +0000144 CodeGenInstruction(Record *R, const std::string &AsmStr);
Chris Lattner87c59052004-08-01 07:42:39 +0000145
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;
Chris Lattnerec352402004-08-01 05:04:00 +0000150 };
151}
152
153#endif