1 //===--------------------- PredicateExpander.h ----------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// Functionalities used by the Tablegen backends to expand machine predicates.
11 /// See file llvm/Target/TargetInstrPredicate.td for a full list and description
12 /// of all the supported MCInstPredicate classes.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
17 #define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/TableGen/Record.h"
27 class PredicateExpander
{
34 PredicateExpander(const PredicateExpander
&) = delete;
35 PredicateExpander
&operator=(const PredicateExpander
&) = delete;
38 PredicateExpander(StringRef Target
)
39 : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
40 IndentLevel(1U), TargetName(Target
) {}
41 bool isByRef() const { return EmitCallsByRef
; }
42 bool shouldNegate() const { return NegatePredicate
; }
43 bool shouldExpandForMC() const { return ExpandForMC
; }
44 unsigned getIndentLevel() const { return IndentLevel
; }
45 StringRef
getTargetName() const { return TargetName
; }
47 void setByRef(bool Value
) { EmitCallsByRef
= Value
; }
48 void flipNegatePredicate() { NegatePredicate
= !NegatePredicate
; }
49 void setNegatePredicate(bool Value
) { NegatePredicate
= Value
; }
50 void setExpandForMC(bool Value
) { ExpandForMC
= Value
; }
51 void setIndentLevel(unsigned Level
) { IndentLevel
= Level
; }
52 void increaseIndentLevel() { ++IndentLevel
; }
53 void decreaseIndentLevel() { --IndentLevel
; }
55 using RecVec
= std::vector
<Record
*>;
56 void expandTrue(raw_ostream
&OS
);
57 void expandFalse(raw_ostream
&OS
);
58 void expandCheckImmOperand(raw_ostream
&OS
, int OpIndex
, int ImmVal
,
59 StringRef FunctionMapper
);
60 void expandCheckImmOperand(raw_ostream
&OS
, int OpIndex
, StringRef ImmVal
,
61 StringRef FunctionMapperer
);
62 void expandCheckImmOperandSimple(raw_ostream
&OS
, int OpIndex
,
63 StringRef FunctionMapper
);
64 void expandCheckRegOperand(raw_ostream
&OS
, int OpIndex
, const Record
*Reg
,
65 StringRef FunctionMapper
);
66 void expandCheckRegOperandSimple(raw_ostream
&OS
, int OpIndex
,
67 StringRef FunctionMapper
);
68 void expandCheckSameRegOperand(raw_ostream
&OS
, int First
, int Second
);
69 void expandCheckNumOperands(raw_ostream
&OS
, int NumOps
);
70 void expandCheckOpcode(raw_ostream
&OS
, const Record
*Inst
);
72 void expandCheckPseudo(raw_ostream
&OS
, const RecVec
&Opcodes
);
73 void expandCheckOpcode(raw_ostream
&OS
, const RecVec
&Opcodes
);
74 void expandPredicateSequence(raw_ostream
&OS
, const RecVec
&Sequence
,
76 void expandTIIFunctionCall(raw_ostream
&OS
, StringRef MethodName
);
77 void expandCheckIsRegOperand(raw_ostream
&OS
, int OpIndex
);
78 void expandCheckIsImmOperand(raw_ostream
&OS
, int OpIndex
);
79 void expandCheckInvalidRegOperand(raw_ostream
&OS
, int OpIndex
);
80 void expandCheckFunctionPredicate(raw_ostream
&OS
, StringRef MCInstFn
,
81 StringRef MachineInstrFn
);
82 void expandCheckNonPortable(raw_ostream
&OS
, StringRef CodeBlock
);
83 void expandPredicate(raw_ostream
&OS
, const Record
*Rec
);
84 void expandReturnStatement(raw_ostream
&OS
, const Record
*Rec
);
85 void expandOpcodeSwitchCase(raw_ostream
&OS
, const Record
*Rec
);
86 void expandOpcodeSwitchStatement(raw_ostream
&OS
, const RecVec
&Cases
,
87 const Record
*Default
);
88 void expandStatement(raw_ostream
&OS
, const Record
*Rec
);
91 // Forward declarations.
92 class STIPredicateFunction
;
95 class STIPredicateExpander
: public PredicateExpander
{
96 StringRef ClassPrefix
;
97 bool ExpandDefinition
;
99 STIPredicateExpander(const PredicateExpander
&) = delete;
100 STIPredicateExpander
&operator=(const PredicateExpander
&) = delete;
102 void expandHeader(raw_ostream
&OS
, const STIPredicateFunction
&Fn
);
103 void expandPrologue(raw_ostream
&OS
, const STIPredicateFunction
&Fn
);
104 void expandOpcodeGroup(raw_ostream
&OS
, const OpcodeGroup
&Group
,
105 bool ShouldUpdateOpcodeMask
);
106 void expandBody(raw_ostream
&OS
, const STIPredicateFunction
&Fn
);
107 void expandEpilogue(raw_ostream
&OS
, const STIPredicateFunction
&Fn
);
110 STIPredicateExpander(StringRef Target
)
111 : PredicateExpander(Target
), ClassPrefix(), ExpandDefinition(false) {}
113 bool shouldExpandDefinition() const { return ExpandDefinition
; }
114 StringRef
getClassPrefix() const { return ClassPrefix
; }
115 void setClassPrefix(StringRef S
) { ClassPrefix
= S
; }
116 void setExpandDefinition(bool Value
) { ExpandDefinition
= Value
; }
118 void expandSTIPredicate(raw_ostream
&OS
, const STIPredicateFunction
&Fn
);