26423d02ffc2dc69a3dfd1f3e77d6cf63e06080b
[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   class CodeGenInstruction {
27   public:
28     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;
35
36     /// OperandInfo - The information we keep track of for each operand in the
37     /// operand list for a tablegen instruction.
38     struct OperandInfo {
39       /// Rec - The definition this operand is declared as.
40       ///
41       Record *Rec;
42
43       /// Name - If this operand was assigned a symbolic name, this is it,
44       /// otherwise, it's empty.
45       std::string Name;
46
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;
58       unsigned MINumOperands;   // The number of operands.
59
60       /// MIOperandInfo - Default MI operand type. Note an operand may be made
61       /// up of multiple MI operands.
62       DagInit *MIOperandInfo;
63
64       OperandInfo(Record *R, const std::string &N, const std::string &PMN, 
65                   unsigned MION, unsigned MINO, DagInit *MIOI)
66         : Rec(R), Name(N), PrinterMethodName(PMN), MIOperandNo(MION),
67           MINumOperands(MINO), MIOperandInfo(MIOI) {}
68     };
69
70     /// OperandList - The list of declared operands, along with their declared
71     /// type (which is a record).
72     std::vector<OperandInfo> OperandList;
73
74     /// ConstraintStr - The operand constraints string.
75     ///
76     std::string ConstraintStr;
77
78     /// ConstraintsList - List of constraints, encoded into one unsigned int per
79     /// operand.
80     std::vector<unsigned> ConstraintsList;
81
82     // Various boolean values we track for the instruction.
83     bool isReturn;
84     bool isBranch;
85     bool isBarrier;
86     bool isCall;
87     bool isLoad;
88     bool isStore;
89     bool isTwoAddress;
90     bool isPredicated;
91     bool isConvertibleToThreeAddress;
92     bool isCommutable;
93     bool isTerminator;
94     bool hasDelaySlot;
95     bool usesCustomDAGSchedInserter;
96     bool hasVariableNumberOfOperands;
97     bool hasCtrlDep;
98     bool noResults;
99
100     CodeGenInstruction(Record *R, const std::string &AsmStr);
101
102     /// getOperandNamed - Return the index of the operand with the specified
103     /// non-empty name.  If the instruction does not have an operand with the
104     /// specified name, throw an exception.
105     unsigned getOperandNamed(const std::string &Name) const;
106   };
107 }
108
109 #endif