blob: cb55d45c186be56a8e1af820639a7aa03cf45ec2 [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//
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.
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
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;
Chris Lattner87c59052004-08-01 07:42:39 +000034
Chris Lattnercf03da02004-08-11 02:22:39 +000035 /// OperandInfo - The information we keep track of for each operand in the
36 /// operand list for a tablegen instruction.
Chris Lattner87c59052004-08-01 07:42:39 +000037 struct OperandInfo {
Chris Lattnercf03da02004-08-11 02:22:39 +000038 /// Rec - The definition this operand is declared as.
Chris Lattner0e384b62005-08-19 16:57:28 +000039 ///
Chris Lattner87c59052004-08-01 07:42:39 +000040 Record *Rec;
Chris Lattnercf03da02004-08-11 02:22:39 +000041
42 /// Ty - The MachineValueType of the operand.
43 ///
Chris Lattner87c59052004-08-01 07:42:39 +000044 MVT::ValueType Ty;
Chris Lattnercf03da02004-08-11 02:22:39 +000045
46 /// Name - If this operand was assigned a symbolic name, this is it,
47 /// otherwise, it's empty.
Chris Lattner87c59052004-08-01 07:42:39 +000048 std::string Name;
Chris Lattnercf03da02004-08-11 02:22:39 +000049
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;
Chris Lattnercfbf96a2005-08-18 23:38:41 +000061 unsigned MINumOperands; // The number of operands.
Chris Lattnercf03da02004-08-11 02:22:39 +000062
Nate Begeman8ef9d162005-11-30 23:58:18 +000063 /// MIOperandInfo - Default MI operand type. Note an operand may be made
64 /// up of multiple MI operands.
Chris Lattner65303d62005-11-19 07:05:57 +000065 DagInit *MIOperandInfo;
66
Chris Lattnercf03da02004-08-11 02:22:39 +000067 OperandInfo(Record *R, MVT::ValueType T, const std::string &N,
Chris Lattner65303d62005-11-19 07:05:57 +000068 const std::string &PMN, unsigned MION, unsigned MINO,
69 DagInit *MIOI)
70
Chris Lattnercfbf96a2005-08-18 23:38:41 +000071 : Rec(R), Ty(T), Name(N), PrinterMethodName(PMN), MIOperandNo(MION),
Chris Lattner65303d62005-11-19 07:05:57 +000072 MINumOperands(MINO), MIOperandInfo(MIOI) {}
Chris Lattner87c59052004-08-01 07:42:39 +000073 };
Misha Brukman3da94ae2005-04-22 00:00:37 +000074
Chris Lattnerec352402004-08-01 05:04:00 +000075 /// OperandList - The list of declared operands, along with their declared
76 /// type (which is a record).
Chris Lattner87c59052004-08-01 07:42:39 +000077 std::vector<OperandInfo> OperandList;
Chris Lattnerec352402004-08-01 05:04:00 +000078
79 // Various boolean values we track for the instruction.
80 bool isReturn;
81 bool isBranch;
82 bool isBarrier;
83 bool isCall;
Nate Begemancdd66b52004-09-28 21:01:45 +000084 bool isLoad;
85 bool isStore;
Chris Lattnerec352402004-08-01 05:04:00 +000086 bool isTwoAddress;
Chris Lattneraad75aa2005-01-02 02:29:04 +000087 bool isConvertibleToThreeAddress;
88 bool isCommutable;
Chris Lattnerec352402004-08-01 05:04:00 +000089 bool isTerminator;
Chris Lattner5b71d3a2004-09-28 18:38:01 +000090 bool hasDelaySlot;
Chris Lattner5f89bf02005-08-26 20:42:52 +000091 bool usesCustomDAGSchedInserter;
Chris Lattnercfbf96a2005-08-18 23:38:41 +000092 bool hasVariableNumberOfOperands;
Chris Lattnerec352402004-08-01 05:04:00 +000093
Chris Lattner175580c2004-08-14 22:50:53 +000094 CodeGenInstruction(Record *R, const std::string &AsmStr);
Chris Lattner87c59052004-08-01 07:42:39 +000095
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;
Chris Lattnerec352402004-08-01 05:04:00 +0000100 };
101}
102
103#endif