LLVM  14.0.0git
HexagonInstPrinter.cpp
Go to the documentation of this file.
1 //===- HexagonInstPrinter.cpp - Convert Hexagon 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 Hexagon MCInst to a .s file.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "HexagonInstPrinter.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/Support/Debug.h"
21 
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "asm-printer"
25 
26 #define GET_INSTRUCTION_NAME
27 #include "HexagonGenAsmWriter.inc"
28 
29 void HexagonInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
30  O << getRegisterName(RegNo);
31 }
32 
34  StringRef Annot, const MCSubtargetInfo &STI,
35  raw_ostream &OS) {
39  HasExtender = false;
40  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(*MI)) {
41  MCInst const &MCI = *I.getInst();
42  if (HexagonMCInstrInfo::isDuplex(MII, MCI)) {
44  OS << '\v';
45  HasExtender = false;
47  } else
48  printInstruction(&MCI, Address, OS);
49  HasExtender = HexagonMCInstrInfo::isImmext(MCI);
50  OS << "\n";
51  }
52 
53  bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(*MI);
54  bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(*MI);
55  if (IsLoop0) {
56  OS << (IsLoop1 ? " :endloop01" : " :endloop0");
57  } else if (IsLoop1) {
58  OS << " :endloop1";
59  }
60 }
61 
62 void HexagonInstPrinter::printOperand(MCInst const *MI, unsigned OpNo,
63  raw_ostream &O) const {
64  if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo &&
65  (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI)))
66  O << "#";
67  MCOperand const &MO = MI->getOperand(OpNo);
68  if (MO.isReg()) {
69  O << getRegisterName(MO.getReg());
70  } else if (MO.isExpr()) {
71  int64_t Value;
72  if (MO.getExpr()->evaluateAsAbsolute(Value))
73  O << formatImm(Value);
74  else
75  O << *MO.getExpr();
76  } else {
77  llvm_unreachable("Unknown operand");
78  }
79 }
80 
81 void HexagonInstPrinter::printBrtarget(MCInst const *MI, unsigned OpNo,
82  raw_ostream &O) const {
83  MCOperand const &MO = MI->getOperand(OpNo);
84  assert (MO.isExpr());
85  MCExpr const &Expr = *MO.getExpr();
86  int64_t Value;
87  if (Expr.evaluateAsAbsolute(Value))
88  O << format("0x%" PRIx64, Value);
89  else {
90  if (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI))
91  if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo)
92  O << "##";
93  O << Expr;
94  }
95 }
HexagonInstPrinter.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCOperand::isReg
bool isReg() const
Definition: MCInst.h:61
llvm::HexagonInstPrinter::printRegName
void printRegName(raw_ostream &O, unsigned RegNo) const override
Print the assembler register name.
Definition: HexagonInstPrinter.cpp:29
llvm::HexagonMCInstrInfo::isImmext
bool isImmext(MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:635
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
HexagonBaseInfo.h
llvm::HexagonInstPrinter::getRegisterName
static const char * getRegisterName(unsigned RegNo)
llvm::HexagonInstPrinter::printOperand
void printOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
Definition: HexagonInstPrinter.cpp:62
HexagonMCInstrInfo.h
llvm::MCOperand::getInst
const MCInst * getInst() const
Definition: MCInst.h:124
llvm::HexagonMCInstrInfo::isBundle
bool isBundle(MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:532
MCInst.h
llvm::HexagonMCInstrInfo::bundleInstructions
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:103
llvm::HexagonInstPrinter::printInstruction
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O)
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::HexagonMCInstrInfo::isConstExtended
bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:538
llvm::HexagonMCInstrInfo::bundleSize
size_t bundleSize(MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:116
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:192
uint64_t
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::HexagonMCInstrInfo::isDuplex
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:609
llvm::HighlightColor::Address
@ Address
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCInstPrinter::formatImm
format_object< int64_t > formatImm(int64_t Value) const
Utility function to print immediates in decimal or hex.
Definition: MCInstPrinter.h:134
llvm::HexagonInstPrinter::printInst
void printInst(MCInst const *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override
Print the specified MCInst to the specified raw_ostream.
Definition: HexagonInstPrinter.cpp:33
llvm::HexagonMCInstrInfo::isOuterLoop
bool isOuterLoop(MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:673
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::HexagonMCInstrInfo::getExtendableOp
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:309
llvm::MCOperand::getExpr
const MCExpr * getExpr() const
Definition: MCInst.h:114
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::MCOperand::isExpr
bool isExpr() const
Definition: MCInst.h:65
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
raw_ostream.h
HEXAGON_PACKET_SIZE
#define HEXAGON_PACKET_SIZE
Definition: HexagonMCTargetDesc.h:36
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Debug.h
llvm::HexagonInstPrinter::printBrtarget
void printBrtarget(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
Definition: HexagonInstPrinter.cpp:81
llvm::MCOperand::getReg
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:69
llvm::HexagonMCInstrInfo::isInnerLoop
bool isInnerLoop(MCInst const &MCI)
Definition: HexagonMCInstrInfo.cpp:639