llvm-mirror/utils/TableGen/PredicateExpander.h
Andrea Di Biagio 6413a2dd47 [MC][PredicateExpander] Extend the grammar to support simple switch and return statements.
This patch introduces tablegen class MCStatement.

Currently, an MCStatement can be either a return statement, or a switch
statement.

```
MCStatement:
   MCReturnStatement
   MCOpcodeSwitchStatement
```

A MCReturnStatement expands to a return statement, and the boolean expression
associated with the return statement is described by a MCInstPredicate.

An MCOpcodeSwitchStatement is a switch statement where the condition is a check
on the machine opcode. It allows the definition of multiple checks, as well as a
default case. More details on the grammar implemented by these two new
constructs can be found in the diff for TargetInstrPredicates.td.

This patch makes it easier to read the body of auto-generated TargetInstrInfo
predicates.

In future, I plan to reuse/extend the MCStatement grammar to describe more
complex target hooks. For now, this is just a first step (mostly a minor
cosmetic change to polish the new predicates framework).

Differential Revision: https://reviews.llvm.org/D50457

llvm-svn: 339352
2018-08-09 15:32:48 +00:00

92 lines
3.9 KiB
C++

//===--------------------- PredicateExpander.h ----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
/// Functionalities used by the Tablegen backends to expand machine predicates.
///
/// See file llvm/Target/TargetInstrPredicate.td for a full list and description
/// of all the supported MCInstPredicate classes.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
#define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/TableGen/Record.h"
namespace llvm {
class formatted_raw_ostream;
class PredicateExpander {
bool EmitCallsByRef;
bool NegatePredicate;
bool ExpandForMC;
unsigned IndentLevel;
PredicateExpander(const PredicateExpander &) = delete;
PredicateExpander &operator=(const PredicateExpander &) = delete;
public:
PredicateExpander()
: EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
IndentLevel(1U) {}
bool isByRef() const { return EmitCallsByRef; }
bool shouldNegate() const { return NegatePredicate; }
bool shouldExpandForMC() const { return ExpandForMC; }
unsigned getIndentLevel() const { return IndentLevel; }
void setByRef(bool Value) { EmitCallsByRef = Value; }
void flipNegatePredicate() { NegatePredicate = !NegatePredicate; }
void setNegatePredicate(bool Value) { NegatePredicate = Value; }
void setExpandForMC(bool Value) { ExpandForMC = Value; }
void increaseIndentLevel() { ++IndentLevel; }
void decreaseIndentLevel() { --IndentLevel; }
void setIndentLevel(unsigned Level) { IndentLevel = Level; }
using RecVec = std::vector<Record *>;
void expandTrue(formatted_raw_ostream &OS);
void expandFalse(formatted_raw_ostream &OS);
void expandCheckImmOperand(formatted_raw_ostream &OS, int OpIndex,
int ImmVal);
void expandCheckImmOperand(formatted_raw_ostream &OS, int OpIndex,
StringRef ImmVal);
void expandCheckRegOperand(formatted_raw_ostream &OS, int OpIndex,
const Record *Reg);
void expandCheckSameRegOperand(formatted_raw_ostream &OS, int First,
int Second);
void expandCheckNumOperands(formatted_raw_ostream &OS, int NumOps);
void expandCheckOpcode(formatted_raw_ostream &OS, const Record *Inst);
void expandCheckPseudo(formatted_raw_ostream &OS, const RecVec &Opcodes);
void expandCheckOpcode(formatted_raw_ostream &OS, const RecVec &Opcodes);
void expandPredicateSequence(formatted_raw_ostream &OS,
const RecVec &Sequence, bool IsCheckAll);
void expandTIIFunctionCall(formatted_raw_ostream &OS, StringRef TargetName,
StringRef MethodName);
void expandCheckIsRegOperand(formatted_raw_ostream &OS, int OpIndex);
void expandCheckIsImmOperand(formatted_raw_ostream &OS, int OpIndex);
void expandCheckInvalidRegOperand(formatted_raw_ostream &OS, int OpIndex);
void expandCheckFunctionPredicate(formatted_raw_ostream &OS,
StringRef MCInstFn,
StringRef MachineInstrFn);
void expandCheckNonPortable(formatted_raw_ostream &OS, StringRef CodeBlock);
void expandPredicate(formatted_raw_ostream &OS, const Record *Rec);
void expandReturnStatement(formatted_raw_ostream &OS, const Record *Rec);
void expandOpcodeSwitchCase(formatted_raw_ostream &OS, const Record *Rec);
void expandOpcodeSwitchStatement(formatted_raw_ostream &OS,
const RecVec &Cases, const Record *Default);
void expandStatement(formatted_raw_ostream &OS, const Record *Rec);
};
} // namespace llvm
#endif