[llvm-exegesis] Fix wrong index type.
[llvm-core.git] / utils / TableGen / PredicateExpander.h
blob255e40c499889fdecf2acdcfd64486909b161277
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.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
18 #define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/TableGen/Record.h"
24 namespace llvm {
26 class raw_ostream;
28 class PredicateExpander {
29 bool EmitCallsByRef;
30 bool NegatePredicate;
31 bool ExpandForMC;
32 unsigned IndentLevel;
33 StringRef TargetName;
35 PredicateExpander(const PredicateExpander &) = delete;
36 PredicateExpander &operator=(const PredicateExpander &) = delete;
38 public:
39 PredicateExpander(StringRef Target)
40 : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
41 IndentLevel(1U), TargetName(Target) {}
42 bool isByRef() const { return EmitCallsByRef; }
43 bool shouldNegate() const { return NegatePredicate; }
44 bool shouldExpandForMC() const { return ExpandForMC; }
45 unsigned getIndentLevel() const { return IndentLevel; }
46 StringRef getTargetName() const { return TargetName; }
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 void setIndentLevel(unsigned Level) { IndentLevel = Level; }
53 void increaseIndentLevel() { ++IndentLevel; }
54 void decreaseIndentLevel() { --IndentLevel; }
56 using RecVec = std::vector<Record *>;
57 void expandTrue(raw_ostream &OS);
58 void expandFalse(raw_ostream &OS);
59 void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal);
60 void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal);
61 void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg);
62 void expandCheckSameRegOperand(raw_ostream &OS, int First, int Second);
63 void expandCheckNumOperands(raw_ostream &OS, int NumOps);
64 void expandCheckOpcode(raw_ostream &OS, const Record *Inst);
66 void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);
67 void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);
68 void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
69 bool IsCheckAll);
70 void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);
71 void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);
72 void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex);
73 void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex);
74 void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
75 StringRef MachineInstrFn);
76 void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock);
77 void expandPredicate(raw_ostream &OS, const Record *Rec);
78 void expandReturnStatement(raw_ostream &OS, const Record *Rec);
79 void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);
80 void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
81 const Record *Default);
82 void expandStatement(raw_ostream &OS, const Record *Rec);
85 // Forward declarations.
86 class STIPredicateFunction;
87 class OpcodeGroup;
89 class STIPredicateExpander : public PredicateExpander {
90 StringRef ClassPrefix;
91 bool ExpandDefinition;
93 STIPredicateExpander(const PredicateExpander &) = delete;
94 STIPredicateExpander &operator=(const PredicateExpander &) = delete;
96 void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn);
97 void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn);
98 void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
99 bool ShouldUpdateOpcodeMask);
100 void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn);
101 void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn);
103 public:
104 STIPredicateExpander(StringRef Target)
105 : PredicateExpander(Target), ClassPrefix(), ExpandDefinition(false) {}
107 bool shouldExpandDefinition() const { return ExpandDefinition; }
108 StringRef getClassPrefix() const { return ClassPrefix; }
109 void setClassPrefix(StringRef S) { ClassPrefix = S; }
110 void setExpandDefinition(bool Value) { ExpandDefinition = Value; }
112 void expandSTIPredicate(raw_ostream &OS, const STIPredicateFunction &Fn);
115 } // namespace llvm
117 #endif