1//===- GIMatchDagPredicate.cpp - Represent a predicate to check -----------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#include "GIMatchDagPredicate.h" 10 11#include "llvm/TableGen/Record.h" 12 13#include "GIMatchDagOperands.h" 14#include "../CodeGenInstruction.h" 15 16using namespace llvm; 17 18void GIMatchDagPredicate::print(raw_ostream &OS) const { 19 OS << "<<"; 20 printDescription(OS); 21 OS << ">>:$" << Name; 22} 23 24void GIMatchDagPredicate::printDescription(raw_ostream &OS) const { OS << ""; } 25 26GIMatchDagOpcodePredicate::GIMatchDagOpcodePredicate( 27 GIMatchDagContext &Ctx, StringRef Name, const CodeGenInstruction &Instr) 28 : GIMatchDagPredicate(GIMatchDagPredicateKind_Opcode, Name, 29 Ctx.makeMIPredicateOperandList()), 30 Instr(Instr) {} 31 32void GIMatchDagOpcodePredicate::printDescription(raw_ostream &OS) const { 33 OS << "$mi.getOpcode() == " << Instr.TheDef->getName(); 34} 35 36GIMatchDagOneOfOpcodesPredicate::GIMatchDagOneOfOpcodesPredicate( 37 GIMatchDagContext &Ctx, StringRef Name) 38 : GIMatchDagPredicate(GIMatchDagPredicateKind_OneOfOpcodes, Name, 39 Ctx.makeMIPredicateOperandList()) {} 40 41void GIMatchDagOneOfOpcodesPredicate::printDescription(raw_ostream &OS) const { 42 OS << "$mi.getOpcode() == oneof("; 43 StringRef Separator = ""; 44 for (const CodeGenInstruction *Instr : Instrs) { 45 OS << Separator << Instr->TheDef->getName(); 46 Separator = ","; 47 } 48 OS << ")"; 49} 50 51GIMatchDagSameMOPredicate::GIMatchDagSameMOPredicate(GIMatchDagContext &Ctx, 52 StringRef Name) 53 : GIMatchDagPredicate(GIMatchDagPredicateKind_SameMO, Name, 54 Ctx.makeTwoMOPredicateOperandList()) {} 55 56void GIMatchDagSameMOPredicate::printDescription(raw_ostream &OS) const { 57 OS << "$mi0 == $mi1"; 58} 59 60raw_ostream &llvm::operator<<(raw_ostream &OS, const GIMatchDagPredicate &N) { 61 N.print(OS); 62 return OS; 63} 64 65raw_ostream &llvm::operator<<(raw_ostream &OS, 66 const GIMatchDagOpcodePredicate &N) { 67 N.print(OS); 68 return OS; 69} 70