Path: blob/main/contrib/llvm-project/llvm/lib/Target/VE/MCTargetDesc/VEInstPrinter.cpp
35294 views
//===-- VEInstPrinter.cpp - Convert VE MCInst to assembly syntax -----------==//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//8// This class prints an VE MCInst to a .s file.9//10//===----------------------------------------------------------------------===//1112#include "VEInstPrinter.h"13#include "VE.h"14#include "llvm/MC/MCExpr.h"15#include "llvm/MC/MCInst.h"16#include "llvm/MC/MCRegisterInfo.h"17#include "llvm/MC/MCSubtargetInfo.h"18#include "llvm/MC/MCSymbol.h"19#include "llvm/Support/raw_ostream.h"2021using namespace llvm;2223#define DEBUG_TYPE "ve-asmprinter"2425#define GET_INSTRUCTION_NAME26#define PRINT_ALIAS_INSTR27#include "VEGenAsmWriter.inc"2829void VEInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const {30// Generic registers have identical register name among register classes.31unsigned AltIdx = VE::AsmName;32// Misc registers have each own name, so no use alt-names.33if (MRI.getRegClass(VE::MISCRegClassID).contains(Reg))34AltIdx = VE::NoRegAltName;35OS << '%' << getRegisterName(Reg, AltIdx);36}3738void VEInstPrinter::printInst(const MCInst *MI, uint64_t Address,39StringRef Annot, const MCSubtargetInfo &STI,40raw_ostream &OS) {41if (!printAliasInstr(MI, Address, STI, OS))42printInstruction(MI, Address, STI, OS);43printAnnotation(OS, Annot);44}4546void VEInstPrinter::printOperand(const MCInst *MI, int OpNum,47const MCSubtargetInfo &STI, raw_ostream &O) {48const MCOperand &MO = MI->getOperand(OpNum);4950if (MO.isReg()) {51printRegName(O, MO.getReg());52return;53}5455if (MO.isImm()) {56// Expects signed 32bit literals.57int32_t TruncatedImm = static_cast<int32_t>(MO.getImm());58O << TruncatedImm;59return;60}6162assert(MO.isExpr() && "Unknown operand kind in printOperand");63MO.getExpr()->print(O, &MAI);64}6566void VEInstPrinter::printMemASXOperand(const MCInst *MI, int OpNum,67const MCSubtargetInfo &STI,68raw_ostream &O, const char *Modifier) {69// If this is an ADD operand, emit it like normal operands.70if (Modifier && !strcmp(Modifier, "arith")) {71printOperand(MI, OpNum, STI, O);72O << ", ";73printOperand(MI, OpNum + 1, STI, O);74return;75}7677if (MI->getOperand(OpNum + 2).isImm() &&78MI->getOperand(OpNum + 2).getImm() == 0) {79// don't print "+0"80} else {81printOperand(MI, OpNum + 2, STI, O);82}83if (MI->getOperand(OpNum + 1).isImm() &&84MI->getOperand(OpNum + 1).getImm() == 0 &&85MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {86if (MI->getOperand(OpNum + 2).isImm() &&87MI->getOperand(OpNum + 2).getImm() == 0) {88O << "0";89} else {90// don't print "+0,+0"91}92} else {93O << "(";94if (MI->getOperand(OpNum + 1).isImm() &&95MI->getOperand(OpNum + 1).getImm() == 0) {96// don't print "+0"97} else {98printOperand(MI, OpNum + 1, STI, O);99}100if (MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {101// don't print "+0"102} else {103O << ", ";104printOperand(MI, OpNum, STI, O);105}106O << ")";107}108}109110void VEInstPrinter::printMemASOperandASX(const MCInst *MI, int OpNum,111const MCSubtargetInfo &STI,112raw_ostream &O, const char *Modifier) {113// If this is an ADD operand, emit it like normal operands.114if (Modifier && !strcmp(Modifier, "arith")) {115printOperand(MI, OpNum, STI, O);116O << ", ";117printOperand(MI, OpNum + 1, STI, O);118return;119}120121if (MI->getOperand(OpNum + 1).isImm() &&122MI->getOperand(OpNum + 1).getImm() == 0) {123// don't print "+0"124} else {125printOperand(MI, OpNum + 1, STI, O);126}127if (MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {128if (MI->getOperand(OpNum + 1).isImm() &&129MI->getOperand(OpNum + 1).getImm() == 0) {130O << "0";131} else {132// don't print "(0)"133}134} else {135O << "(, ";136printOperand(MI, OpNum, STI, O);137O << ")";138}139}140141void VEInstPrinter::printMemASOperandRRM(const MCInst *MI, int OpNum,142const MCSubtargetInfo &STI,143raw_ostream &O, const char *Modifier) {144// If this is an ADD operand, emit it like normal operands.145if (Modifier && !strcmp(Modifier, "arith")) {146printOperand(MI, OpNum, STI, O);147O << ", ";148printOperand(MI, OpNum + 1, STI, O);149return;150}151152if (MI->getOperand(OpNum + 1).isImm() &&153MI->getOperand(OpNum + 1).getImm() == 0) {154// don't print "+0"155} else {156printOperand(MI, OpNum + 1, STI, O);157}158if (MI->getOperand(OpNum).isImm() && MI->getOperand(OpNum).getImm() == 0) {159if (MI->getOperand(OpNum + 1).isImm() &&160MI->getOperand(OpNum + 1).getImm() == 0) {161O << "0";162} else {163// don't print "(0)"164}165} else {166O << "(";167printOperand(MI, OpNum, STI, O);168O << ")";169}170}171172void VEInstPrinter::printMemASOperandHM(const MCInst *MI, int OpNum,173const MCSubtargetInfo &STI,174raw_ostream &O, const char *Modifier) {175// If this is an ADD operand, emit it like normal operands.176if (Modifier && !strcmp(Modifier, "arith")) {177printOperand(MI, OpNum, STI, O);178O << ", ";179printOperand(MI, OpNum + 1, STI, O);180return;181}182183if (MI->getOperand(OpNum + 1).isImm() &&184MI->getOperand(OpNum + 1).getImm() == 0) {185// don't print "+0"186} else {187printOperand(MI, OpNum + 1, STI, O);188}189O << "(";190if (MI->getOperand(OpNum).isReg())191printOperand(MI, OpNum, STI, O);192O << ")";193}194195void VEInstPrinter::printMImmOperand(const MCInst *MI, int OpNum,196const MCSubtargetInfo &STI,197raw_ostream &O) {198int MImm = (int)MI->getOperand(OpNum).getImm() & 0x7f;199if (MImm > 63)200O << "(" << MImm - 64 << ")0";201else202O << "(" << MImm << ")1";203}204205void VEInstPrinter::printCCOperand(const MCInst *MI, int OpNum,206const MCSubtargetInfo &STI, raw_ostream &O) {207int CC = (int)MI->getOperand(OpNum).getImm();208O << VECondCodeToString((VECC::CondCode)CC);209}210211void VEInstPrinter::printRDOperand(const MCInst *MI, int OpNum,212const MCSubtargetInfo &STI, raw_ostream &O) {213int RD = (int)MI->getOperand(OpNum).getImm();214O << VERDToString((VERD::RoundingMode)RD);215}216217218