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.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_UTILS_TABLEGEN_COMMON_CODEGENINSTALIAS_H
14#define LLVM_UTILS_TABLEGEN_COMMON_CODEGENINSTALIAS_H
15
16#include "llvm/ADT/StringRef.h"
17#include <cassert>
18#include <cstdint>
19#include <string>
20#include <utility>
21#include <vector>
22
23namespace llvm {
24
25template <typename T> class ArrayRef;
26class CodeGenInstruction;
27class CodeGenTarget;
28class DagInit;
29class SMLoc;
30class Record;
31
32/// CodeGenInstAlias - This represents an InstAlias definition.
33class CodeGenInstAlias {
34public:
35 const Record *TheDef; // The actual record defining this InstAlias.
36
37 /// AsmString - The format string used to emit a .s file for the
38 /// instruction.
39 std::string AsmString;
40
41 /// Result - The result instruction.
42 const DagInit *Result;
43
44 /// ResultInst - The instruction generated by the alias (decoded from
45 /// Result).
46 CodeGenInstruction *ResultInst;
47
48 struct ResultOperand {
49 private:
50 std::string Name;
51 const Record *R = nullptr;
52 int64_t Imm = 0;
53
54 public:
55 enum { K_Record, K_Imm, K_Reg } Kind;
56
57 ResultOperand(std::string N, const Record *R)
58 : Name(std::move(N)), R(R), Kind(K_Record) {}
59 ResultOperand(int64_t I) : Imm(I), Kind(K_Imm) {}
60 ResultOperand(const Record *R) : R(R), Kind(K_Reg) {}
61
62 bool isRecord() const { return Kind == K_Record; }
63 bool isImm() const { return Kind == K_Imm; }
64 bool isReg() const { return Kind == K_Reg; }
65
66 StringRef getName() const {
67 assert(isRecord());
68 return Name;
69 }
70 const Record *getRecord() const {
71 assert(isRecord());
72 return R;
73 }
74 int64_t getImm() const {
75 assert(isImm());
76 return Imm;
77 }
78 const Record *getRegister() const {
79 assert(isReg());
80 return R;
81 }
82
83 unsigned getMINumOperands() const;
84 };
85
86 /// ResultOperands - The decoded operands for the result instruction.
87 std::vector<ResultOperand> ResultOperands;
88
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;
95
96 CodeGenInstAlias(const Record *R, const CodeGenTarget &T);
97
98 bool tryAliasOpMatch(const DagInit *Result, unsigned AliasOpNo,
99 const Record *InstOpRec, bool hasSubOps,
100 ArrayRef<SMLoc> Loc, const CodeGenTarget &T,
101 ResultOperand &ResOp);
102};
103
104} // namespace llvm
105
106#endif // LLVM_UTILS_TABLEGEN_COMMON_CODEGENINSTALIAS_H
107