LLVM  7.0.0svn
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 
32  MCInstrInfo const &MII,
33  MCRegisterInfo const &MRI)
34  : MCInstPrinter(MAI, MII, MRI), MII(MII), HasExtender(false) {
35 }
36 
38  return MII.getName(Opcode);
39 }
40 
41 void HexagonInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
42  O << getRegName(RegNo);
43 }
44 
46  return getRegisterName(RegNo);
47 }
48 
49 void HexagonInstPrinter::setExtender(MCInst const &MCI) {
50  HasExtender = HexagonMCInstrInfo::isImmext(MCI);
51 }
52 
54  StringRef Annot, const MCSubtargetInfo &STI) {
58  HasExtender = false;
59  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(*MI)) {
60  MCInst const &MCI = *I.getInst();
61  if (HexagonMCInstrInfo::isDuplex(MII, MCI)) {
62  printInstruction(MCI.getOperand(1).getInst(), OS);
63  OS << '\v';
64  HasExtender = false;
65  printInstruction(MCI.getOperand(0).getInst(), OS);
66  } else
67  printInstruction(&MCI, OS);
68  setExtender(MCI);
69  OS << "\n";
70  }
71 
72  bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(*MI);
73  bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(*MI);
74  if (IsLoop0) {
75  OS << (IsLoop1 ? " :endloop01" : " :endloop0");
76  } else if (IsLoop1) {
77  OS << " :endloop1";
78  }
79 }
80 
81 void HexagonInstPrinter::printOperand(MCInst const *MI, unsigned OpNo,
82  raw_ostream &O) const {
83  if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo &&
84  (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI)))
85  O << "#";
86  MCOperand const &MO = MI->getOperand(OpNo);
87  if (MO.isReg()) {
88  O << getRegisterName(MO.getReg());
89  } else if (MO.isExpr()) {
90  int64_t Value;
91  if (MO.getExpr()->evaluateAsAbsolute(Value))
92  O << formatImm(Value);
93  else
94  O << *MO.getExpr();
95  } else {
96  llvm_unreachable("Unknown operand");
97  }
98 }
99 
100 void HexagonInstPrinter::printExtOperand(MCInst const *MI, unsigned OpNo,
101  raw_ostream &O) const {
102  printOperand(MI, OpNo, O);
103 }
104 
106  unsigned OpNo,
107  raw_ostream &O) const {
108  O << MI->getOperand(OpNo).getImm();
109 }
110 
112  raw_ostream &O) const {
113  O << -MI->getOperand(OpNo).getImm();
114 }
115 
117  raw_ostream &O) const {
118  O << -1;
119 }
120 
122  raw_ostream &O) const {
123  printOperand(MI, OpNo, O);
124 }
125 
126 void HexagonInstPrinter::printJumpTable(MCInst const *MI, unsigned OpNo,
127  raw_ostream &O) const {
128  assert(MI->getOperand(OpNo).isExpr() && "Expecting expression");
129 
130  printOperand(MI, OpNo, O);
131 }
132 
134  raw_ostream &O) const {
135  assert(MI->getOperand(OpNo).isExpr() && "Expecting expression");
136 
137  printOperand(MI, OpNo, O);
138 }
139 
141  raw_ostream &O) const {
142  // Branches can take an immediate operand. This is used by the branch
143  // selection pass to print $+8, an eight byte displacement from the PC.
144  llvm_unreachable("Unknown branch operand.");
145 }
146 
147 void HexagonInstPrinter::printCallOperand(MCInst const *MI, unsigned OpNo,
148  raw_ostream &O) const {}
149 
151  raw_ostream &O) const {}
152 
154  raw_ostream &O) const {}
155 
156 void HexagonInstPrinter::printSymbol(MCInst const *MI, unsigned OpNo,
157  raw_ostream &O, bool hi) const {
158  assert(MI->getOperand(OpNo).isImm() && "Unknown symbol operand");
159 
160  O << '#' << (hi ? "HI" : "LO") << '(';
161  O << '#';
162  printOperand(MI, OpNo, O);
163  O << ')';
164 }
165 
166 void HexagonInstPrinter::printBrtarget(MCInst const *MI, unsigned OpNo,
167  raw_ostream &O) const {
168  MCOperand const &MO = MI->getOperand(OpNo);
169  assert (MO.isExpr());
170  MCExpr const &Expr = *MO.getExpr();
171  int64_t Value;
172  if (Expr.evaluateAsAbsolute(Value))
173  O << format("0x%" PRIx64, Value);
174  else {
175  if (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI))
176  if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo)
177  O << "##";
178  O << Expr;
179  }
180 }
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
bool isImm() const
Definition: MCInst.h:59
void printRegName(raw_ostream &O, unsigned RegNo) const override
Print the assembler register name.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void printBrtarget(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
void printNegImmOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
void printUnsignedImmOperand(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)
void printGlobalOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
bool isReg() const
Definition: MCInst.h:58
void printConstantPool(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
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.
StringRef getRegName(unsigned RegNo) const
void printCallOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
bool isImmext(MCInst const &MCI)
#define HEXAGON_PACKET_SIZE
Definition: Hexagon.h:33
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)
void printAbsAddrOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
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:97
const MCInst * getInst() const
Definition: MCInst.h:106
const MCExpr * getExpr() const
Definition: MCInst.h:96
virtual StringRef getOpcodeName(unsigned Opcode) const
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
int64_t getImm() const
Definition: MCInst.h:76
void printJumpTable(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
unsigned const MachineRegisterInfo * MRI
void printExtOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
void printSymbol(MCInst const *MI, unsigned OpNo, raw_ostream &O, bool hi) const
void printPredicateOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
bool isExpr() const
Definition: MCInst.h:61
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
Definition: MCInstrInfo.h:51
#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)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
HexagonInstPrinter(MCAsmInfo const &MAI, MCInstrInfo const &MII, MCRegisterInfo const &MRI)
#define I(x, y, z)
Definition: MD5.cpp:58
Generic base class for all target subtargets.
void printNOneImmOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
size_t bundleSize(MCInst const &MCI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInnerLoop(MCInst const &MCI)
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:44
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
void printBranchOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const