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