Teach tblgen about instruction operands that have multiple MachineInstr
[oota-llvm.git] / utils / TableGen / CodeGenInstruction.h
1 //===- CodeGenInstruction.h - Instruction Class Wrapper ---------*- C++ -*-===//
2 //
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.
7 //
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
17 #include "llvm/CodeGen/ValueTypes.h"
18 #include <string>
19 #include <vector>
20 #include <utility>
21
22 namespace llvm {
23   class Record;
24   class DagInit;
25
26   struct CodeGenInstruction {
27     Record *TheDef;            // The actual record defining this instruction.
28     std::string Name;          // Contents of the 'Name' field.
29     std::string Namespace;     // The namespace the instruction is in.
30
31     /// AsmString - The format string used to emit a .s file for the
32     /// instruction.
33     std::string AsmString;
34
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;
41
42       /// Ty - The MachineValueType of the operand.
43       ///
44       MVT::ValueType Ty;
45
46       /// Name - If this operand was assigned a symbolic name, this is it,
47       /// otherwise, it's empty.
48       std::string Name;
49
50       /// PrinterMethodName - The method used to print operands of this type in
51       /// the asmprinter.
52       std::string PrinterMethodName;
53
54       /// MIOperandNo - Currently (this is meant to be phased out), some logical
55       /// operands correspond to multiple MachineInstr operands.  In the X86
56       /// target for example, one address operand is represented as 4
57       /// MachineOperands.  Because of this, the operand number in the
58       /// OperandList may not match the MachineInstr operand num.  Until it
59       /// does, this contains the MI operand index of this operand.
60       unsigned MIOperandNo;
61       unsigned MINumOperands;   // The number of operands.
62
63       /// MIOperandInfo - Default MI operand type. Note an operand may be made up
64       /// of multiple MI operands.
65       DagInit *MIOperandInfo;
66
67       OperandInfo(Record *R, MVT::ValueType T, const std::string &N,
68                   const std::string &PMN, unsigned MION, unsigned MINO,
69                   DagInit *MIOI)
70
71         : Rec(R), Ty(T), Name(N), PrinterMethodName(PMN), MIOperandNo(MION),
72           MINumOperands(MINO), MIOperandInfo(MIOI) {}
73     };
74
75     /// OperandList - The list of declared operands, along with their declared
76     /// type (which is a record).
77     std::vector<OperandInfo> OperandList;
78
79     // Various boolean values we track for the instruction.
80     bool isReturn;
81     bool isBranch;
82     bool isBarrier;
83     bool isCall;
84     bool isLoad;
85     bool isStore;
86     bool isTwoAddress;
87     bool isConvertibleToThreeAddress;
88     bool isCommutable;
89     bool isTerminator;
90     bool hasDelaySlot;
91     bool usesCustomDAGSchedInserter;
92     bool hasVariableNumberOfOperands;
93
94     CodeGenInstruction(Record *R, const std::string &AsmStr);
95
96     /// getOperandNamed - Return the index of the operand with the specified
97     /// non-empty name.  If the instruction does not have an operand with the
98     /// specified name, throw an exception.
99     unsigned getOperandNamed(const std::string &Name) const;
100   };
101 }
102
103 #endif