Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / TableGen / CodeGenInstAlias.h
blob2a05273e7270180429e4319ca54e97319724b08f
1 //===- CodeGenInstAlias.h - InstAlias Class Wrapper -------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a wrapper class for the 'InstAlias' TableGen class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_UTILS_TABLEGEN_CODEGENINSTALIAS_H
14 #define LLVM_UTILS_TABLEGEN_CODEGENINSTALIAS_H
16 #include "llvm/ADT/StringRef.h"
17 #include <cassert>
18 #include <cstdint>
19 #include <string>
20 #include <utility>
21 #include <vector>
23 namespace llvm {
25 template <typename T> class ArrayRef;
26 class CodeGenInstruction;
27 class CodeGenTarget;
28 class DagInit;
29 class SMLoc;
30 class Record;
32 /// CodeGenInstAlias - This represents an InstAlias definition.
33 class CodeGenInstAlias {
34 public:
35 Record *TheDef; // The actual record defining this InstAlias.
37 /// AsmString - The format string used to emit a .s file for the
38 /// instruction.
39 std::string AsmString;
41 /// Result - The result instruction.
42 DagInit *Result;
44 /// ResultInst - The instruction generated by the alias (decoded from
45 /// Result).
46 CodeGenInstruction *ResultInst;
48 struct ResultOperand {
49 private:
50 std::string Name;
51 Record *R = nullptr;
52 int64_t Imm = 0;
54 public:
55 enum { K_Record, K_Imm, K_Reg } Kind;
57 ResultOperand(std::string N, Record *r)
58 : Name(std::move(N)), R(r), Kind(K_Record) {}
59 ResultOperand(int64_t I) : Imm(I), Kind(K_Imm) {}
60 ResultOperand(Record *r) : R(r), Kind(K_Reg) {}
62 bool isRecord() const { return Kind == K_Record; }
63 bool isImm() const { return Kind == K_Imm; }
64 bool isReg() const { return Kind == K_Reg; }
66 StringRef getName() const {
67 assert(isRecord());
68 return Name;
70 Record *getRecord() const {
71 assert(isRecord());
72 return R;
74 int64_t getImm() const {
75 assert(isImm());
76 return Imm;
78 Record *getRegister() const {
79 assert(isReg());
80 return R;
83 unsigned getMINumOperands() const;
86 /// ResultOperands - The decoded operands for the result instruction.
87 std::vector<ResultOperand> ResultOperands;
89 /// ResultInstOperandIndex - For each operand, this vector holds a pair of
90 /// indices to identify the corresponding operand in the result
91 /// instruction. The first index specifies the operand and the second
92 /// index specifies the suboperand. If there are no suboperands or if all
93 /// of them are matched by the operand, the second value should be -1.
94 std::vector<std::pair<unsigned, int>> ResultInstOperandIndex;
96 CodeGenInstAlias(Record *R, CodeGenTarget &T);
98 bool tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo, Record *InstOpRec,
99 bool hasSubOps, ArrayRef<SMLoc> Loc, CodeGenTarget &T,
100 ResultOperand &ResOp);
103 } // namespace llvm
105 #endif // LLVM_UTILS_TABLEGEN_CODEGENINSTALIAS_H