Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 1 | //===--------------------- PredicateExpander.h ----------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// Functionalities used by the Tablegen backends to expand machine predicates. |
| 11 | /// |
| 12 | /// See file llvm/Target/TargetInstrPredicate.td for a full list and description |
| 13 | /// of all the supported MCInstPredicate classes. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H |
| 18 | #define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H |
| 19 | |
| 20 | #include "llvm/ADT/StringRef.h" |
Andrea Di Biagio | 87972c4 | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 22 | #include "llvm/TableGen/Record.h" |
| 23 | |
| 24 | namespace llvm { |
| 25 | |
Andrea Di Biagio | 87972c4 | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 26 | class raw_ostream; |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 27 | |
| 28 | class PredicateExpander { |
| 29 | bool EmitCallsByRef; |
| 30 | bool NegatePredicate; |
| 31 | bool ExpandForMC; |
| 32 | unsigned IndentLevel; |
Andrea Di Biagio | e9759dd | 2018-08-14 18:36:54 +0000 | [diff] [blame] | 33 | StringRef TargetName; |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 34 | |
| 35 | PredicateExpander(const PredicateExpander &) = delete; |
| 36 | PredicateExpander &operator=(const PredicateExpander &) = delete; |
| 37 | |
| 38 | public: |
Andrea Di Biagio | e9759dd | 2018-08-14 18:36:54 +0000 | [diff] [blame] | 39 | PredicateExpander(StringRef Target) |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 40 | : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false), |
Andrea Di Biagio | e9759dd | 2018-08-14 18:36:54 +0000 | [diff] [blame] | 41 | IndentLevel(1U), TargetName(Target) {} |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 42 | bool isByRef() const { return EmitCallsByRef; } |
| 43 | bool shouldNegate() const { return NegatePredicate; } |
| 44 | bool shouldExpandForMC() const { return ExpandForMC; } |
| 45 | unsigned getIndentLevel() const { return IndentLevel; } |
Andrea Di Biagio | a9c15c1 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 46 | StringRef getTargetName() const { return TargetName; } |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 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; } |
Andrea Di Biagio | a9c15c1 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 52 | void setIndentLevel(unsigned Level) { IndentLevel = Level; } |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 53 | void increaseIndentLevel() { ++IndentLevel; } |
| 54 | void decreaseIndentLevel() { --IndentLevel; } |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 55 | |
| 56 | using RecVec = std::vector<Record *>; |
Andrea Di Biagio | 87972c4 | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 57 | void expandTrue(raw_ostream &OS); |
| 58 | void expandFalse(raw_ostream &OS); |
Andrea Di Biagio | cf7570b | 2018-10-31 12:28:05 +0000 | [diff] [blame] | 59 | void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal, |
| 60 | StringRef FunctionMapper); |
| 61 | void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal, |
| 62 | StringRef FunctionMapperer); |
| 63 | void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex, |
| 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); |
Andrea Di Biagio | 87972c4 | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 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); |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 72 | |
Andrea Di Biagio | 87972c4 | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 73 | void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes); |
| 74 | void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes); |
| 75 | void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence, |
| 76 | bool IsCheckAll); |
Andrea Di Biagio | e9759dd | 2018-08-14 18:36:54 +0000 | [diff] [blame] | 77 | void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName); |
Andrea Di Biagio | 87972c4 | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 78 | void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex); |
| 79 | void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex); |
| 80 | void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex); |
| 81 | void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn, |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 82 | StringRef MachineInstrFn); |
Andrea Di Biagio | 87972c4 | 2018-08-13 15:13:35 +0000 | [diff] [blame] | 83 | void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock); |
| 84 | void expandPredicate(raw_ostream &OS, const Record *Rec); |
| 85 | void expandReturnStatement(raw_ostream &OS, const Record *Rec); |
| 86 | void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec); |
| 87 | void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases, |
| 88 | const Record *Default); |
| 89 | void expandStatement(raw_ostream &OS, const Record *Rec); |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Andrea Di Biagio | a9c15c1 | 2018-09-19 15:57:45 +0000 | [diff] [blame] | 92 | // Forward declarations. |
| 93 | class STIPredicateFunction; |
| 94 | class OpcodeGroup; |
| 95 | |
| 96 | class STIPredicateExpander : public PredicateExpander { |
| 97 | StringRef ClassPrefix; |
| 98 | bool ExpandDefinition; |
| 99 | |
| 100 | STIPredicateExpander(const PredicateExpander &) = delete; |
| 101 | STIPredicateExpander &operator=(const PredicateExpander &) = delete; |
| 102 | |
| 103 | void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn); |
| 104 | void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn); |
| 105 | void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group, |
| 106 | bool ShouldUpdateOpcodeMask); |
| 107 | void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn); |
| 108 | void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn); |
| 109 | |
| 110 | public: |
| 111 | STIPredicateExpander(StringRef Target) |
| 112 | : PredicateExpander(Target), ClassPrefix(), ExpandDefinition(false) {} |
| 113 | |
| 114 | bool shouldExpandDefinition() const { return ExpandDefinition; } |
| 115 | StringRef getClassPrefix() const { return ClassPrefix; } |
| 116 | void setClassPrefix(StringRef S) { ClassPrefix = S; } |
| 117 | void setExpandDefinition(bool Value) { ExpandDefinition = Value; } |
| 118 | |
| 119 | void expandSTIPredicate(raw_ostream &OS, const STIPredicateFunction &Fn); |
| 120 | }; |
| 121 | |
Andrea Di Biagio | e68d92b | 2018-05-25 15:55:37 +0000 | [diff] [blame] | 122 | } // namespace llvm |
| 123 | |
| 124 | #endif |