LLVM 24.0.0git
VEInstPrinter.cpp
Go to the documentation of this file.
1//===-- VEInstPrinter.cpp - Convert VE MCInst to assembly syntax -----------==//
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// This class prints an VE MCInst to a .s file.
10//
11//===----------------------------------------------------------------------===//
12
13#include "VEInstPrinter.h"
14#include "VE.h"
15#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCExpr.h"
17#include "llvm/MC/MCInst.h"
20#include "llvm/MC/MCSymbol.h"
22
23using namespace llvm;
24
25#define DEBUG_TYPE "ve-asmprinter"
26
27#define GET_INSTRUCTION_NAME
28#define PRINT_ALIAS_INSTR
29#include "VEGenAsmWriter.inc"
30
32 OS << '%' << getRegisterName(Reg);
33}
34
36 StringRef Annot, const MCSubtargetInfo &STI,
37 raw_ostream &OS) {
38 if (!printAliasInstr(MI, Address, STI, OS))
39 printInstruction(MI, Address, STI, OS);
40 printAnnotation(OS, Annot);
41}
42
43void VEInstPrinter::printOperand(const MCInst *MI, int OpNum,
44 const MCSubtargetInfo &STI, raw_ostream &O) {
45 const MCOperand &MO = MI->getOperand(OpNum);
46
47 if (MO.isReg()) {
48 printRegName(O, MO.getReg());
49 return;
50 }
51
52 if (MO.isImm()) {
53 // Expects signed 32bit literals.
54 int32_t TruncatedImm = static_cast<int32_t>(MO.getImm());
55 O << TruncatedImm;
56 return;
57 }
58
59 assert(MO.isExpr() && "Unknown operand kind in printOperand");
60 MAI.printExpr(O, *MO.getExpr());
61}
62
64 const MCSubtargetInfo &STI,
65 raw_ostream &O) {
66 if (MI->getOperand(OpNum + 2).isImm() &&
67 MI->getOperand(OpNum + 2).getImm() == 0) {
68 // don't print "+0"
69 } else {
70 printOperand(MI, OpNum + 2, STI, O);
71 }
72 if (MI->getOperand(OpNum + 1).isImm() &&
73 MI->getOperand(OpNum + 1).getImm() == 0 &&
74 MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {
75 if (MI->getOperand(OpNum + 2).isImm() &&
76 MI->getOperand(OpNum + 2).getImm() == 0) {
77 O << "0";
78 } else {
79 // don't print "+0,+0"
80 }
81 } else {
82 O << "(";
83 if (MI->getOperand(OpNum + 1).isImm() &&
84 MI->getOperand(OpNum + 1).getImm() == 0) {
85 // don't print "+0"
86 } else {
87 printOperand(MI, OpNum + 1, STI, O);
88 }
89 if (MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {
90 // don't print "+0"
91 } else {
92 O << ", ";
93 printOperand(MI, OpNum, STI, O);
94 }
95 O << ")";
96 }
97}
98
100 const MCSubtargetInfo &STI,
101 raw_ostream &O) {
102 if (MI->getOperand(OpNum + 1).isImm() &&
103 MI->getOperand(OpNum + 1).getImm() == 0) {
104 // don't print "+0"
105 } else {
106 printOperand(MI, OpNum + 1, STI, O);
107 }
108 if (MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {
109 if (MI->getOperand(OpNum + 1).isImm() &&
110 MI->getOperand(OpNum + 1).getImm() == 0) {
111 O << "0";
112 } else {
113 // don't print "(0)"
114 }
115 } else {
116 O << "(, ";
117 printOperand(MI, OpNum, STI, O);
118 O << ")";
119 }
120}
121
123 const MCSubtargetInfo &STI,
124 raw_ostream &O) {
125 if (MI->getOperand(OpNum + 1).isImm() &&
126 MI->getOperand(OpNum + 1).getImm() == 0) {
127 // don't print "+0"
128 } else {
129 printOperand(MI, OpNum + 1, STI, O);
130 }
131 if (MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {
132 if (MI->getOperand(OpNum + 1).isImm() &&
133 MI->getOperand(OpNum + 1).getImm() == 0) {
134 O << "0";
135 } else {
136 // don't print "(0)"
137 }
138 } else {
139 O << "(";
140 printOperand(MI, OpNum, STI, O);
141 O << ")";
142 }
143}
144
146 const MCSubtargetInfo &STI,
147 raw_ostream &O) {
148 if (MI->getOperand(OpNum + 1).isImm() &&
149 MI->getOperand(OpNum + 1).getImm() == 0) {
150 // don't print "+0"
151 } else {
152 printOperand(MI, OpNum + 1, STI, O);
153 }
154 O << "(";
155 if (MI->getOperand(OpNum).isReg())
156 printOperand(MI, OpNum, STI, O);
157 O << ")";
158}
159
161 const MCSubtargetInfo &STI,
162 raw_ostream &O) {
163 int MImm = (int)MI->getOperand(OpNum).getImm() & 0x7f;
164 if (MImm > 63)
165 O << "(" << MImm - 64 << ")0";
166 else
167 O << "(" << MImm << ")1";
168}
169
171 const MCSubtargetInfo &STI, raw_ostream &O) {
172 int CC = (int)MI->getOperand(OpNum).getImm();
174}
175
177 const MCSubtargetInfo &STI, raw_ostream &O) {
178 int RD = (int)MI->getOperand(OpNum).getImm();
180}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
IRTranslator LLVM IR MI
RISCVCC::CondCode CC
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
const MCAsmInfo & MAI
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:187
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:39
int64_t getImm() const
Definition MCInst.h:83
bool isImm() const
Definition MCInst.h:65
bool isReg() const
Definition MCInst.h:64
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:72
const MCExpr * getExpr() const
Definition MCInst.h:117
bool isExpr() const
Definition MCInst.h:68
Wrapper class representing physical registers and target specific virtual registers.
Definition MCRegister.h:42
Generic base class for all target subtargets.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static const char * getRegisterName(MCRegister Reg)
void printMemASOperandHM(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printMImmOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printRegName(raw_ostream &OS, MCRegister Reg) override
Print the assembler register name.
bool printAliasInstr(const MCInst *, uint64_t Address, const MCSubtargetInfo &, raw_ostream &)
void printOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printMemASOperandASX(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printRDOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printMemASOperandRRM(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printCCOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printMemASXOperand(const MCInst *MI, int OpNum, const MCSubtargetInfo &STI, raw_ostream &OS)
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) override
Print the specified MCInst to the specified raw_ostream.
void printInstruction(const MCInst *, uint64_t, const MCSubtargetInfo &, raw_ostream &)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
CondCode
Definition VE.h:60
RoundingMode
Definition VE.h:92
This is an optimization pass for GlobalISel generic memory operations.
static const char * VECondCodeToString(VECC::CondCode CC)
Definition VE.h:103
static const char * VERDToString(VERD::RoundingMode R)
Definition VE.h:282