• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 using namespace llvm;
17 
print(raw_ostream & OS) const18 void GIMatchDagPredicate::print(raw_ostream &OS) const {
19   OS << "<<";
20   printDescription(OS);
21   OS << ">>:$" << Name;
22 }
23 
printDescription(raw_ostream & OS) const24 void GIMatchDagPredicate::printDescription(raw_ostream &OS) const { OS << ""; }
25 
GIMatchDagOpcodePredicate(GIMatchDagContext & Ctx,StringRef Name,const CodeGenInstruction & Instr)26 GIMatchDagOpcodePredicate::GIMatchDagOpcodePredicate(
27     GIMatchDagContext &Ctx, StringRef Name, const CodeGenInstruction &Instr)
28     : GIMatchDagPredicate(GIMatchDagPredicateKind_Opcode, Name,
29                           Ctx.makeMIPredicateOperandList()),
30       Instr(Instr) {}
31 
printDescription(raw_ostream & OS) const32 void GIMatchDagOpcodePredicate::printDescription(raw_ostream &OS) const {
33   OS << "$mi.getOpcode() == " << Instr.TheDef->getName();
34 }
35 
GIMatchDagOneOfOpcodesPredicate(GIMatchDagContext & Ctx,StringRef Name)36 GIMatchDagOneOfOpcodesPredicate::GIMatchDagOneOfOpcodesPredicate(
37     GIMatchDagContext &Ctx, StringRef Name)
38     : GIMatchDagPredicate(GIMatchDagPredicateKind_OneOfOpcodes, Name,
39                           Ctx.makeMIPredicateOperandList()) {}
40 
printDescription(raw_ostream & OS) const41 void 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 
GIMatchDagSameMOPredicate(GIMatchDagContext & Ctx,StringRef Name)51 GIMatchDagSameMOPredicate::GIMatchDagSameMOPredicate(GIMatchDagContext &Ctx,
52                                                      StringRef Name)
53     : GIMatchDagPredicate(GIMatchDagPredicateKind_SameMO, Name,
54                           Ctx.makeTwoMOPredicateOperandList()) {}
55 
printDescription(raw_ostream & OS) const56 void GIMatchDagSameMOPredicate::printDescription(raw_ostream &OS) const {
57   OS << "$mi0 == $mi1";
58 }
59 
operator <<(raw_ostream & OS,const GIMatchDagPredicate & N)60 raw_ostream &llvm::operator<<(raw_ostream &OS, const GIMatchDagPredicate &N) {
61   N.print(OS);
62   return OS;
63 }
64 
operator <<(raw_ostream & OS,const GIMatchDagOpcodePredicate & N)65 raw_ostream &llvm::operator<<(raw_ostream &OS,
66                               const GIMatchDagOpcodePredicate &N) {
67   N.print(OS);
68   return OS;
69 }
70