blob: 9337a0f3d2c5da82992b56a7dbad9d6fd0f98e01 [file] [log] [blame]
Andrea Di Biagio95140022018-05-25 15:55:37 +00001//===--------------------- 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 Biagio2c6cbc8b2018-08-13 15:13:35 +000021#include "llvm/Support/raw_ostream.h"
Andrea Di Biagio95140022018-05-25 15:55:37 +000022#include "llvm/TableGen/Record.h"
23
24namespace llvm {
25
Andrea Di Biagio2c6cbc8b2018-08-13 15:13:35 +000026class raw_ostream;
Andrea Di Biagio95140022018-05-25 15:55:37 +000027
28class PredicateExpander {
29 bool EmitCallsByRef;
30 bool NegatePredicate;
31 bool ExpandForMC;
32 unsigned IndentLevel;
Andrea Di Biagio9eaf5aa2018-08-14 18:36:54 +000033 StringRef TargetName;
Andrea Di Biagio95140022018-05-25 15:55:37 +000034
35 PredicateExpander(const PredicateExpander &) = delete;
36 PredicateExpander &operator=(const PredicateExpander &) = delete;
37
38public:
Andrea Di Biagio9eaf5aa2018-08-14 18:36:54 +000039 PredicateExpander(StringRef Target)
Andrea Di Biagio95140022018-05-25 15:55:37 +000040 : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
Andrea Di Biagio9eaf5aa2018-08-14 18:36:54 +000041 IndentLevel(1U), TargetName(Target) {}
Andrea Di Biagio95140022018-05-25 15:55:37 +000042 bool isByRef() const { return EmitCallsByRef; }
43 bool shouldNegate() const { return NegatePredicate; }
44 bool shouldExpandForMC() const { return ExpandForMC; }
45 unsigned getIndentLevel() const { return IndentLevel; }
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 increaseIndentLevel() { ++IndentLevel; }
52 void decreaseIndentLevel() { --IndentLevel; }
53 void setIndentLevel(unsigned Level) { IndentLevel = Level; }
54
55 using RecVec = std::vector<Record *>;
Andrea Di Biagio2c6cbc8b2018-08-13 15:13:35 +000056 void expandTrue(raw_ostream &OS);
57 void expandFalse(raw_ostream &OS);
58 void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal);
59 void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal);
60 void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg);
61 void expandCheckSameRegOperand(raw_ostream &OS, int First, int Second);
62 void expandCheckNumOperands(raw_ostream &OS, int NumOps);
63 void expandCheckOpcode(raw_ostream &OS, const Record *Inst);
Andrea Di Biagio95140022018-05-25 15:55:37 +000064
Andrea Di Biagio2c6cbc8b2018-08-13 15:13:35 +000065 void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);
66 void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);
67 void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
68 bool IsCheckAll);
Andrea Di Biagio9eaf5aa2018-08-14 18:36:54 +000069 void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);
Andrea Di Biagio2c6cbc8b2018-08-13 15:13:35 +000070 void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);
71 void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex);
72 void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex);
73 void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
Andrea Di Biagio95140022018-05-25 15:55:37 +000074 StringRef MachineInstrFn);
Andrea Di Biagio2c6cbc8b2018-08-13 15:13:35 +000075 void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock);
76 void expandPredicate(raw_ostream &OS, const Record *Rec);
77 void expandReturnStatement(raw_ostream &OS, const Record *Rec);
78 void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);
79 void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
80 const Record *Default);
81 void expandStatement(raw_ostream &OS, const Record *Rec);
Andrea Di Biagio95140022018-05-25 15:55:37 +000082};
83
84} // namespace llvm
85
86#endif