Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/PredicateExpander.h
35290 views
//===--------------------- PredicateExpander.h ----------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8/// Functionalities used by the Tablegen backends to expand machine predicates.9///10/// See file llvm/Target/TargetInstrPredicate.td for a full list and description11/// of all the supported MCInstPredicate classes.12//13//===----------------------------------------------------------------------===//1415#ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H16#define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H1718#include "llvm/ADT/StringRef.h"19#include <vector>2021namespace llvm {2223class raw_ostream;24class Record;2526class PredicateExpander {27bool EmitCallsByRef;28bool NegatePredicate;29bool ExpandForMC;30unsigned IndentLevel;31StringRef TargetName;3233PredicateExpander(const PredicateExpander &) = delete;34PredicateExpander &operator=(const PredicateExpander &) = delete;3536public:37PredicateExpander(StringRef Target)38: EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),39IndentLevel(1U), TargetName(Target) {}40bool isByRef() const { return EmitCallsByRef; }41bool shouldNegate() const { return NegatePredicate; }42bool shouldExpandForMC() const { return ExpandForMC; }43unsigned getIndentLevel() const { return IndentLevel; }44StringRef getTargetName() const { return TargetName; }4546void setByRef(bool Value) { EmitCallsByRef = Value; }47void flipNegatePredicate() { NegatePredicate = !NegatePredicate; }48void setNegatePredicate(bool Value) { NegatePredicate = Value; }49void setExpandForMC(bool Value) { ExpandForMC = Value; }50void setIndentLevel(unsigned Level) { IndentLevel = Level; }51void increaseIndentLevel() { ++IndentLevel; }52void decreaseIndentLevel() { --IndentLevel; }5354using RecVec = std::vector<Record *>;55void expandTrue(raw_ostream &OS);56void expandFalse(raw_ostream &OS);57void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,58StringRef FunctionMapper);59void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal,60StringRef FunctionMapperer);61void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex,62StringRef FunctionMapper);63void expandCheckImmOperandLT(raw_ostream &OS, int OpIndex, int ImmVal,64StringRef FunctionMapper);65void expandCheckImmOperandGT(raw_ostream &OS, int OpIndex, int ImmVal,66StringRef FunctionMapper);67void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg,68StringRef FunctionMapper);69void expandCheckRegOperandSimple(raw_ostream &OS, int OpIndex,70StringRef FunctionMapper);71void expandCheckSameRegOperand(raw_ostream &OS, int First, int Second);72void expandCheckNumOperands(raw_ostream &OS, int NumOps);73void expandCheckOpcode(raw_ostream &OS, const Record *Inst);7475void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);76void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);77void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,78bool IsCheckAll);79void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);80void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);81void expandCheckIsVRegOperand(raw_ostream &OS, int OpIndex);82void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex);83void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex);84void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,85StringRef MachineInstrFn);86void expandCheckFunctionPredicateWithTII(raw_ostream &OS, StringRef MCInstFn,87StringRef MachineInstrFn,88StringRef TIIPtr);89void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock);90void expandPredicate(raw_ostream &OS, const Record *Rec);91void expandReturnStatement(raw_ostream &OS, const Record *Rec);92void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);93void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,94const Record *Default);95void expandStatement(raw_ostream &OS, const Record *Rec);96};9798// Forward declarations.99class STIPredicateFunction;100class OpcodeGroup;101102class STIPredicateExpander : public PredicateExpander {103StringRef ClassPrefix;104bool ExpandDefinition;105106STIPredicateExpander(const PredicateExpander &) = delete;107STIPredicateExpander &operator=(const PredicateExpander &) = delete;108109void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn);110void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn);111void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,112bool ShouldUpdateOpcodeMask);113void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn);114void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn);115116public:117STIPredicateExpander(StringRef Target)118: PredicateExpander(Target), ExpandDefinition(false) {}119120bool shouldExpandDefinition() const { return ExpandDefinition; }121StringRef getClassPrefix() const { return ClassPrefix; }122void setClassPrefix(StringRef S) { ClassPrefix = S; }123void setExpandDefinition(bool Value) { ExpandDefinition = Value; }124125void expandSTIPredicate(raw_ostream &OS, const STIPredicateFunction &Fn);126};127128} // namespace llvm129130#endif131132133