Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 1 | //===--------------------- PredicateExpander.h ----------------------------===// |
| 2 | // |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 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 |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 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_PREDICATEEXPANDER_H |
| 17 | #define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H |
| 18 | |
| 19 | #include "llvm/ADT/StringRef.h" |
| 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | #include "llvm/TableGen/Record.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | class raw_ostream; |
| 26 | |
| 27 | class PredicateExpander { |
| 28 | bool EmitCallsByRef; |
| 29 | bool NegatePredicate; |
| 30 | bool ExpandForMC; |
| 31 | unsigned IndentLevel; |
| 32 | StringRef TargetName; |
| 33 | |
| 34 | PredicateExpander(const PredicateExpander &) = delete; |
| 35 | PredicateExpander &operator=(const PredicateExpander &) = delete; |
| 36 | |
| 37 | public: |
| 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; } |
| 46 | |
| 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; } |
| 54 | |
| 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); |
| 71 | |
| 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, |
| 75 | bool IsCheckAll); |
| 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); |
| 89 | }; |
| 90 | |
| 91 | // Forward declarations. |
| 92 | class STIPredicateFunction; |
| 93 | class OpcodeGroup; |
| 94 | |
| 95 | class STIPredicateExpander : public PredicateExpander { |
| 96 | StringRef ClassPrefix; |
| 97 | bool ExpandDefinition; |
| 98 | |
| 99 | STIPredicateExpander(const PredicateExpander &) = delete; |
| 100 | STIPredicateExpander &operator=(const PredicateExpander &) = delete; |
| 101 | |
| 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); |
| 108 | |
| 109 | public: |
| 110 | STIPredicateExpander(StringRef Target) |
| 111 | : PredicateExpander(Target), ClassPrefix(), ExpandDefinition(false) {} |
| 112 | |
| 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; } |
| 117 | |
| 118 | void expandSTIPredicate(raw_ostream &OS, const STIPredicateFunction &Fn); |
| 119 | }; |
| 120 | |
| 121 | } // namespace llvm |
| 122 | |
| 123 | #endif |