xref: /freebsd-src/contrib/llvm-project/llvm/utils/TableGen/Common/PredicateExpander.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1*0fca6ea1SDimitry Andric //===--------------------- PredicateExpander.h ----------------------------===//
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 /// \file
9*0fca6ea1SDimitry Andric /// Functionalities used by the Tablegen backends to expand machine predicates.
10*0fca6ea1SDimitry Andric ///
11*0fca6ea1SDimitry Andric /// See file llvm/Target/TargetInstrPredicate.td for a full list and description
12*0fca6ea1SDimitry Andric /// of all the supported MCInstPredicate classes.
13*0fca6ea1SDimitry Andric //
14*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
15*0fca6ea1SDimitry Andric 
16*0fca6ea1SDimitry Andric #ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
17*0fca6ea1SDimitry Andric #define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
18*0fca6ea1SDimitry Andric 
19*0fca6ea1SDimitry Andric #include "llvm/ADT/StringRef.h"
20*0fca6ea1SDimitry Andric #include <vector>
21*0fca6ea1SDimitry Andric 
22*0fca6ea1SDimitry Andric namespace llvm {
23*0fca6ea1SDimitry Andric 
24*0fca6ea1SDimitry Andric class raw_ostream;
25*0fca6ea1SDimitry Andric class Record;
26*0fca6ea1SDimitry Andric 
27*0fca6ea1SDimitry Andric class PredicateExpander {
28*0fca6ea1SDimitry Andric   bool EmitCallsByRef;
29*0fca6ea1SDimitry Andric   bool NegatePredicate;
30*0fca6ea1SDimitry Andric   bool ExpandForMC;
31*0fca6ea1SDimitry Andric   unsigned IndentLevel;
32*0fca6ea1SDimitry Andric   StringRef TargetName;
33*0fca6ea1SDimitry Andric 
34*0fca6ea1SDimitry Andric   PredicateExpander(const PredicateExpander &) = delete;
35*0fca6ea1SDimitry Andric   PredicateExpander &operator=(const PredicateExpander &) = delete;
36*0fca6ea1SDimitry Andric 
37*0fca6ea1SDimitry Andric public:
38*0fca6ea1SDimitry Andric   PredicateExpander(StringRef Target)
39*0fca6ea1SDimitry Andric       : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
40*0fca6ea1SDimitry Andric         IndentLevel(1U), TargetName(Target) {}
41*0fca6ea1SDimitry Andric   bool isByRef() const { return EmitCallsByRef; }
42*0fca6ea1SDimitry Andric   bool shouldNegate() const { return NegatePredicate; }
43*0fca6ea1SDimitry Andric   bool shouldExpandForMC() const { return ExpandForMC; }
44*0fca6ea1SDimitry Andric   unsigned getIndentLevel() const { return IndentLevel; }
45*0fca6ea1SDimitry Andric   StringRef getTargetName() const { return TargetName; }
46*0fca6ea1SDimitry Andric 
47*0fca6ea1SDimitry Andric   void setByRef(bool Value) { EmitCallsByRef = Value; }
48*0fca6ea1SDimitry Andric   void flipNegatePredicate() { NegatePredicate = !NegatePredicate; }
49*0fca6ea1SDimitry Andric   void setNegatePredicate(bool Value) { NegatePredicate = Value; }
50*0fca6ea1SDimitry Andric   void setExpandForMC(bool Value) { ExpandForMC = Value; }
51*0fca6ea1SDimitry Andric   void setIndentLevel(unsigned Level) { IndentLevel = Level; }
52*0fca6ea1SDimitry Andric   void increaseIndentLevel() { ++IndentLevel; }
53*0fca6ea1SDimitry Andric   void decreaseIndentLevel() { --IndentLevel; }
54*0fca6ea1SDimitry Andric 
55*0fca6ea1SDimitry Andric   using RecVec = std::vector<Record *>;
56*0fca6ea1SDimitry Andric   void expandTrue(raw_ostream &OS);
57*0fca6ea1SDimitry Andric   void expandFalse(raw_ostream &OS);
58*0fca6ea1SDimitry Andric   void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
59*0fca6ea1SDimitry Andric                              StringRef FunctionMapper);
60*0fca6ea1SDimitry Andric   void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal,
61*0fca6ea1SDimitry Andric                              StringRef FunctionMapperer);
62*0fca6ea1SDimitry Andric   void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex,
63*0fca6ea1SDimitry Andric                                    StringRef FunctionMapper);
64*0fca6ea1SDimitry Andric   void expandCheckImmOperandLT(raw_ostream &OS, int OpIndex, int ImmVal,
65*0fca6ea1SDimitry Andric                                StringRef FunctionMapper);
66*0fca6ea1SDimitry Andric   void expandCheckImmOperandGT(raw_ostream &OS, int OpIndex, int ImmVal,
67*0fca6ea1SDimitry Andric                                StringRef FunctionMapper);
68*0fca6ea1SDimitry Andric   void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg,
69*0fca6ea1SDimitry Andric                              StringRef FunctionMapper);
70*0fca6ea1SDimitry Andric   void expandCheckRegOperandSimple(raw_ostream &OS, int OpIndex,
71*0fca6ea1SDimitry Andric                                    StringRef FunctionMapper);
72*0fca6ea1SDimitry Andric   void expandCheckSameRegOperand(raw_ostream &OS, int First, int Second);
73*0fca6ea1SDimitry Andric   void expandCheckNumOperands(raw_ostream &OS, int NumOps);
74*0fca6ea1SDimitry Andric   void expandCheckOpcode(raw_ostream &OS, const Record *Inst);
75*0fca6ea1SDimitry Andric 
76*0fca6ea1SDimitry Andric   void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);
77*0fca6ea1SDimitry Andric   void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);
78*0fca6ea1SDimitry Andric   void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
79*0fca6ea1SDimitry Andric                                bool IsCheckAll);
80*0fca6ea1SDimitry Andric   void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);
81*0fca6ea1SDimitry Andric   void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);
82*0fca6ea1SDimitry Andric   void expandCheckIsVRegOperand(raw_ostream &OS, int OpIndex);
83*0fca6ea1SDimitry Andric   void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex);
84*0fca6ea1SDimitry Andric   void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex);
85*0fca6ea1SDimitry Andric   void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
86*0fca6ea1SDimitry Andric                                     StringRef MachineInstrFn);
87*0fca6ea1SDimitry Andric   void expandCheckFunctionPredicateWithTII(raw_ostream &OS, StringRef MCInstFn,
88*0fca6ea1SDimitry Andric                                            StringRef MachineInstrFn,
89*0fca6ea1SDimitry Andric                                            StringRef TIIPtr);
90*0fca6ea1SDimitry Andric   void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock);
91*0fca6ea1SDimitry Andric   void expandPredicate(raw_ostream &OS, const Record *Rec);
92*0fca6ea1SDimitry Andric   void expandReturnStatement(raw_ostream &OS, const Record *Rec);
93*0fca6ea1SDimitry Andric   void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);
94*0fca6ea1SDimitry Andric   void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
95*0fca6ea1SDimitry Andric                                    const Record *Default);
96*0fca6ea1SDimitry Andric   void expandStatement(raw_ostream &OS, const Record *Rec);
97*0fca6ea1SDimitry Andric };
98*0fca6ea1SDimitry Andric 
99*0fca6ea1SDimitry Andric // Forward declarations.
100*0fca6ea1SDimitry Andric class STIPredicateFunction;
101*0fca6ea1SDimitry Andric class OpcodeGroup;
102*0fca6ea1SDimitry Andric 
103*0fca6ea1SDimitry Andric class STIPredicateExpander : public PredicateExpander {
104*0fca6ea1SDimitry Andric   StringRef ClassPrefix;
105*0fca6ea1SDimitry Andric   bool ExpandDefinition;
106*0fca6ea1SDimitry Andric 
107*0fca6ea1SDimitry Andric   STIPredicateExpander(const PredicateExpander &) = delete;
108*0fca6ea1SDimitry Andric   STIPredicateExpander &operator=(const PredicateExpander &) = delete;
109*0fca6ea1SDimitry Andric 
110*0fca6ea1SDimitry Andric   void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn);
111*0fca6ea1SDimitry Andric   void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn);
112*0fca6ea1SDimitry Andric   void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
113*0fca6ea1SDimitry Andric                          bool ShouldUpdateOpcodeMask);
114*0fca6ea1SDimitry Andric   void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn);
115*0fca6ea1SDimitry Andric   void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn);
116*0fca6ea1SDimitry Andric 
117*0fca6ea1SDimitry Andric public:
118*0fca6ea1SDimitry Andric   STIPredicateExpander(StringRef Target)
119*0fca6ea1SDimitry Andric       : PredicateExpander(Target), ExpandDefinition(false) {}
120*0fca6ea1SDimitry Andric 
121*0fca6ea1SDimitry Andric   bool shouldExpandDefinition() const { return ExpandDefinition; }
122*0fca6ea1SDimitry Andric   StringRef getClassPrefix() const { return ClassPrefix; }
123*0fca6ea1SDimitry Andric   void setClassPrefix(StringRef S) { ClassPrefix = S; }
124*0fca6ea1SDimitry Andric   void setExpandDefinition(bool Value) { ExpandDefinition = Value; }
125*0fca6ea1SDimitry Andric 
126*0fca6ea1SDimitry Andric   void expandSTIPredicate(raw_ostream &OS, const STIPredicateFunction &Fn);
127*0fca6ea1SDimitry Andric };
128*0fca6ea1SDimitry Andric 
129*0fca6ea1SDimitry Andric } // namespace llvm
130*0fca6ea1SDimitry Andric 
131*0fca6ea1SDimitry Andric #endif
132