LLVM  10.0.0
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/MCExpr.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCRegisterInfo.h"
19 #include "llvm/MC/MCSymbol.h"
21 
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "ve-asmprinter"
25 
26 // The generated AsmMatcher VEGenAsmWriter uses "VE" as the target
27 // namespace.
28 namespace llvm {
29 namespace VE {
30 using namespace VE;
31 }
32 } // namespace llvm
33 
34 #define GET_INSTRUCTION_NAME
35 #define PRINT_ALIAS_INSTR
36 #include "VEGenAsmWriter.inc"
37 
38 void VEInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
39  OS << '%' << StringRef(getRegisterName(RegNo)).lower();
40 }
41 
42 void VEInstPrinter::printInst(const MCInst *MI, uint64_t Address,
43  StringRef Annot, const MCSubtargetInfo &STI,
44  raw_ostream &OS) {
45  if (!printAliasInstr(MI, STI, OS))
46  printInstruction(MI, Address, STI, OS);
47  printAnnotation(OS, Annot);
48 }
49 
50 void VEInstPrinter::printOperand(const MCInst *MI, int opNum,
51  const MCSubtargetInfo &STI, raw_ostream &O) {
52  const MCOperand &MO = MI->getOperand(opNum);
53 
54  if (MO.isReg()) {
55  printRegName(O, MO.getReg());
56  return;
57  }
58 
59  if (MO.isImm()) {
60  switch (MI->getOpcode()) {
61  default:
62  // Expects signed 32bit literals
63  assert(isInt<32>(MO.getImm()) && "Immediate too large");
64  int32_t TruncatedImm = static_cast<int32_t>(MO.getImm());
65  O << TruncatedImm;
66  return;
67  }
68  }
69 
70  assert(MO.isExpr() && "Unknown operand kind in printOperand");
71  MO.getExpr()->print(O, &MAI);
72 }
73 
75  const MCSubtargetInfo &STI,
76  raw_ostream &O, const char *Modifier) {
77  // If this is an ADD operand, emit it like normal operands.
78  if (Modifier && !strcmp(Modifier, "arith")) {
79  printOperand(MI, opNum, STI, O);
80  O << ", ";
81  printOperand(MI, opNum + 1, STI, O);
82  return;
83  }
84 
85  const MCOperand &MO = MI->getOperand(opNum + 1);
86  if (!MO.isImm() || MO.getImm() != 0) {
87  printOperand(MI, opNum + 1, STI, O);
88  }
89  O << "(,";
90  printOperand(MI, opNum, STI, O);
91  O << ")";
92 }
93 
95  const MCSubtargetInfo &STI,
96  raw_ostream &O, const char *Modifier) {
97  // If this is an ADD operand, emit it like normal operands.
98  if (Modifier && !strcmp(Modifier, "arith")) {
99  printOperand(MI, opNum, STI, O);
100  O << ", ";
101  printOperand(MI, opNum + 1, STI, O);
102  return;
103  }
104 
105  const MCOperand &MO = MI->getOperand(opNum + 1);
106  if (!MO.isImm() || MO.getImm() != 0) {
107  printOperand(MI, opNum + 1, STI, O);
108  }
109  O << "(";
110  printOperand(MI, opNum, STI, O);
111  O << ")";
112 }
113 
114 void VEInstPrinter::printCCOperand(const MCInst *MI, int opNum,
115  const MCSubtargetInfo &STI, raw_ostream &O) {
116  int CC = (int)MI->getOperand(opNum).getImm();
118 }
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.
bool isImm() const
Definition: MCInst.h:58
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void printMemASOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &OS, const char *Modifier=nullptr)
void printMemASXOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &OS, const char *Modifier=nullptr)
bool isReg() const
Definition: MCInst.h:57
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:64
static std::string getRegisterName(const TargetRegisterInfo *TRI, unsigned Reg)
Definition: MIParser.cpp:1125
const MCExpr * getExpr() const
Definition: MCInst.h:95
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
void printCCOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &OS)
int64_t getImm() const
Definition: MCInst.h:75
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
bool isExpr() const
Definition: MCInst.h:60
constexpr bool isInt< 32 >(int64_t x)
Definition: MathExtras.h:345
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:180
CondCodes
Definition: VE.h:40
static const char * VECondCodeToString(VECC::CondCodes CC)
Definition: VE.h:69
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
void printOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, raw_ostream &OS)
Generic base class for all target subtargets.
LLVM_NODISCARD std::string lower() const
Definition: StringRef.cpp:108
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
unsigned getOpcode() const
Definition: MCInst.h:172
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:34
void printRegName(raw_ostream &OS, unsigned RegNo) const override
Print the assembler register name.