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