LLVM  8.0.1
HexagonInstPrinter.cpp
Go to the documentation of this file.
1 //===- HexagonInstPrinter.cpp - Convert Hexagon MCInst to assembly syntax -===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class prints an Hexagon MCInst to a .s file.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "HexagonInstPrinter.h"
15 #include "HexagonAsmPrinter.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/Support/Debug.h"
23 
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "asm-printer"
27 
28 #define GET_INSTRUCTION_NAME
29 #include "HexagonGenAsmWriter.inc"
30 
31 void HexagonInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
32  O << getRegisterName(RegNo);
33 }
34 
36  StringRef Annot, const MCSubtargetInfo &STI) {
40  HasExtender = false;
41  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(*MI)) {
42  MCInst const &MCI = *I.getInst();
43  if (HexagonMCInstrInfo::isDuplex(MII, MCI)) {
44  printInstruction(MCI.getOperand(1).getInst(), OS);
45  OS << '\v';
46  HasExtender = false;
47  printInstruction(MCI.getOperand(0).getInst(), OS);
48  } else
49  printInstruction(&MCI, OS);
50  HasExtender = HexagonMCInstrInfo::isImmext(MCI);
51  OS << "\n";
52  }
53 
54  bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(*MI);
55  bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(*MI);
56  if (IsLoop0) {
57  OS << (IsLoop1 ? " :endloop01" : " :endloop0");
58  } else if (IsLoop1) {
59  OS << " :endloop1";
60  }
61 }
62 
63 void HexagonInstPrinter::printOperand(MCInst const *MI, unsigned OpNo,
64  raw_ostream &O) const {
65  if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo &&
66  (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI)))
67  O << "#";
68  MCOperand const &MO = MI->getOperand(OpNo);
69  if (MO.isReg()) {
70  O << getRegisterName(MO.getReg());
71  } else if (MO.isExpr()) {
72  int64_t Value;
73  if (MO.getExpr()->evaluateAsAbsolute(Value))
74  O << formatImm(Value);
75  else
76  O << *MO.getExpr();
77  } else {
78  llvm_unreachable("Unknown operand");
79  }
80 }
81 
82 void HexagonInstPrinter::printBrtarget(MCInst const *MI, unsigned OpNo,
83  raw_ostream &O) const {
84  MCOperand const &MO = MI->getOperand(OpNo);
85  assert (MO.isExpr());
86  MCExpr const &Expr = *MO.getExpr();
87  int64_t Value;
88  if (Expr.evaluateAsAbsolute(Value))
89  O << format("0x%" PRIx64, Value);
90  else {
91  if (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI))
92  if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo)
93  O << "##";
94  O << Expr;
95  }
96 }
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
void printRegName(raw_ostream &O, unsigned RegNo) const override
Print the assembler register name.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void printBrtarget(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
bool isBundle(MCInst const &MCI)
bool isReg() const
Definition: MCInst.h:58
bool isOuterLoop(MCInst const &MCI)
void printInst(MCInst const *MI, raw_ostream &O, StringRef Annot, const MCSubtargetInfo &STI) override
Print the specified MCInst to the specified raw_ostream.
bool isImmext(MCInst const &MCI)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:65
format_object< int64_t > formatImm(int64_t Value) const
Utility function to print immediates in decimal or hex.
Definition: MCInstPrinter.h:96
const MCInst * getInst() const
Definition: MCInst.h:106
const MCExpr * getExpr() const
Definition: MCInst.h:96
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
bool isExpr() const
Definition: MCInst.h:61
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
void printInstruction(MCInst const *MI, raw_ostream &O)
#define I(x, y, z)
Definition: MD5.cpp:58
Generic base class for all target subtargets.
size_t bundleSize(MCInst const &MCI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInnerLoop(MCInst const &MCI)
#define HEXAGON_PACKET_SIZE
LLVM Value Representation.
Definition: Value.h:73
static char const * getRegisterName(unsigned RegNo)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI)
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
void printOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const