PredicateExpander.h revision 341825
1238582Smm//===--------------------- PredicateExpander.h ----------------------------===// 2238582Smm// 3238582Smm// The LLVM Compiler Infrastructure 4238582Smm// 5238582Smm// This file is distributed under the University of Illinois Open Source 6238582Smm// License. See LICENSE.TXT for details. 7238582Smm// 8238582Smm//===----------------------------------------------------------------------===// 9238582Smm/// \file 10238582Smm/// Functionalities used by the Tablegen backends to expand machine predicates. 11238582Smm/// 12238582Smm/// See file llvm/Target/TargetInstrPredicate.td for a full list and description 13238582Smm/// of all the supported MCInstPredicate classes. 14238582Smm// 15238582Smm//===----------------------------------------------------------------------===// 16238582Smm 17238582Smm#ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H 18238582Smm#define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H 19238582Smm 20238582Smm#include "llvm/ADT/StringRef.h" 21238582Smm#include "llvm/Support/FormattedStream.h" 22238582Smm#include "llvm/TableGen/Record.h" 23256004Spfg 24238582Smmnamespace llvm { 25238582Smm 26238582Smmclass formatted_raw_ostream; 27238582Smm 28238582Smmclass PredicateExpander { 29238582Smm bool EmitCallsByRef; 30256004Spfg bool NegatePredicate; 31256004Spfg bool ExpandForMC; 32256004Spfg unsigned IndentLevel; 33256004Spfg 34256004Spfg PredicateExpander(const PredicateExpander &) = delete; 35 PredicateExpander &operator=(const PredicateExpander &) = delete; 36 37public: 38 PredicateExpander() 39 : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false), 40 IndentLevel(1U) {} 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 46 void setByRef(bool Value) { EmitCallsByRef = Value; } 47 void flipNegatePredicate() { NegatePredicate = !NegatePredicate; } 48 void setNegatePredicate(bool Value) { NegatePredicate = Value; } 49 void setExpandForMC(bool Value) { ExpandForMC = Value; } 50 void increaseIndentLevel() { ++IndentLevel; } 51 void decreaseIndentLevel() { --IndentLevel; } 52 void setIndentLevel(unsigned Level) { IndentLevel = Level; } 53 54 using RecVec = std::vector<Record *>; 55 void expandTrue(formatted_raw_ostream &OS); 56 void expandFalse(formatted_raw_ostream &OS); 57 void expandCheckImmOperand(formatted_raw_ostream &OS, int OpIndex, 58 int ImmVal); 59 void expandCheckImmOperand(formatted_raw_ostream &OS, int OpIndex, 60 StringRef ImmVal); 61 void expandCheckRegOperand(formatted_raw_ostream &OS, int OpIndex, 62 const Record *Reg); 63 void expandCheckSameRegOperand(formatted_raw_ostream &OS, int First, 64 int Second); 65 void expandCheckNumOperands(formatted_raw_ostream &OS, int NumOps); 66 void expandCheckOpcode(formatted_raw_ostream &OS, const Record *Inst); 67 68 void expandCheckPseudo(formatted_raw_ostream &OS, const RecVec &Opcodes); 69 void expandCheckOpcode(formatted_raw_ostream &OS, const RecVec &Opcodes); 70 void expandPredicateSequence(formatted_raw_ostream &OS, 71 const RecVec &Sequence, bool IsCheckAll); 72 void expandTIIFunctionCall(formatted_raw_ostream &OS, StringRef TargetName, 73 StringRef MethodName); 74 void expandCheckIsRegOperand(formatted_raw_ostream &OS, int OpIndex); 75 void expandCheckIsImmOperand(formatted_raw_ostream &OS, int OpIndex); 76 void expandCheckInvalidRegOperand(formatted_raw_ostream &OS, int OpIndex); 77 void expandCheckFunctionPredicate(formatted_raw_ostream &OS, 78 StringRef MCInstFn, 79 StringRef MachineInstrFn); 80 void expandCheckNonPortable(formatted_raw_ostream &OS, StringRef CodeBlock); 81 void expandPredicate(formatted_raw_ostream &OS, const Record *Rec); 82}; 83 84} // namespace llvm 85 86#endif 87