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"
26
class CodeGenInstruction {
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
33
std::string AsmString;
35
class ConstraintInfo {
36
enum { None, EarlyClobber, Tied } Kind;
37
unsigned OtherTiedOperand;
39
ConstraintInfo() : Kind(None) {}
41
static ConstraintInfo getEarlyClobber() {
43
I.Kind = EarlyClobber;
44
I.OtherTiedOperand = 0;
48
static ConstraintInfo getTied(unsigned Op) {
51
I.OtherTiedOperand = Op;
55
bool isNone() const { return Kind == None; }
56
bool isEarlyClobber() const { return Kind == EarlyClobber; }
57
bool isTied() const { return Kind == Tied; }
59
unsigned getTiedOperand() const {
61
return OtherTiedOperand;
65
/// OperandInfo - The information we keep track of for each operand in the
66
/// operand list for a tablegen instruction.
68
/// Rec - The definition this operand is declared as.
72
/// Name - If this operand was assigned a symbolic name, this is it,
73
/// otherwise, it's empty.
76
/// PrinterMethodName - The method used to print operands of this type in
78
std::string PrinterMethodName;
80
/// MIOperandNo - Currently (this is meant to be phased out), some logical
81
/// operands correspond to multiple MachineInstr operands. In the X86
82
/// target for example, one address operand is represented as 4
83
/// MachineOperands. Because of this, the operand number in the
84
/// OperandList may not match the MachineInstr operand num. Until it
85
/// does, this contains the MI operand index of this operand.
87
unsigned MINumOperands; // The number of operands.
89
/// DoNotEncode - Bools are set to true in this vector for each operand in
90
/// the DisableEncoding list. These should not be emitted by the code
92
std::vector<bool> DoNotEncode;
94
/// MIOperandInfo - Default MI operand type. Note an operand may be made
95
/// up of multiple MI operands.
96
DagInit *MIOperandInfo;
98
/// Constraint info for this operand. This operand can have pieces, so we
99
/// track constraint info for each.
100
std::vector<ConstraintInfo> Constraints;
102
OperandInfo(Record *R, const std::string &N, const std::string &PMN,
103
unsigned MION, unsigned MINO, DagInit *MIOI)
104
: Rec(R), Name(N), PrinterMethodName(PMN), MIOperandNo(MION),
105
MINumOperands(MINO), MIOperandInfo(MIOI) {}
108
/// NumDefs - Number of def operands declared.
112
/// OperandList - The list of declared operands, along with their declared
113
/// type (which is a record).
114
std::vector<OperandInfo> OperandList;
116
// Various boolean values we track for the instruction.
119
bool isIndirectBranch;
123
bool mayLoad, mayStore;
125
bool isConvertibleToThreeAddress;
128
bool isReMaterializable;
130
bool usesCustomInserter;
133
bool isNotDuplicable;
136
bool neverHasSideEffects;
137
bool isAsCheapAsAMove;
138
bool hasExtraSrcRegAllocReq;
139
bool hasExtraDefRegAllocReq;
141
/// ParseOperandName - Parse an operand name like "$foo" or "$foo.bar",
142
/// where $foo is a whole operand and $foo.bar refers to a suboperand.
143
/// This throws an exception if the name is invalid. If AllowWholeOp is
144
/// true, references to operands with suboperands are allowed, otherwise
146
std::pair<unsigned,unsigned> ParseOperandName(const std::string &Op,
147
bool AllowWholeOp = true);
149
/// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a
150
/// flat machineinstr operand #.
151
unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const {
152
return OperandList[Op.first].MIOperandNo + Op.second;
155
/// getSubOperandNumber - Unflatten a operand number into an
156
/// operand/suboperand pair.
157
std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const {
158
for (unsigned i = 0; ; ++i) {
159
assert(i < OperandList.size() && "Invalid flat operand #");
160
if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op)
161
return std::make_pair(i, Op-OperandList[i].MIOperandNo);
166
/// isFlatOperandNotEmitted - Return true if the specified flat operand #
167
/// should not be emitted with the code emitter.
168
bool isFlatOperandNotEmitted(unsigned FlatOpNo) const {
169
std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo);
170
if (OperandList[Op.first].DoNotEncode.size() > Op.second)
171
return OperandList[Op.first].DoNotEncode[Op.second];
175
CodeGenInstruction(Record *R, const std::string &AsmStr);
177
/// getOperandNamed - Return the index of the operand with the specified
178
/// non-empty name. If the instruction does not have an operand with the
179
/// specified name, throw an exception.
180
unsigned getOperandNamed(const std::string &Name) const;