LLVM 20.0.0git
MCInst.cpp
Go to the documentation of this file.
1//===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===//
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#include "llvm/MC/MCInst.h"
10#include "llvm/Config/llvm-config.h"
11#include "llvm/MC/MCExpr.h"
16#include "llvm/Support/Debug.h"
18
19using namespace llvm;
20
21void MCOperand::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
22 OS << "<MCOperand ";
23 if (!isValid())
24 OS << "INVALID";
25 else if (isReg()) {
26 OS << "Reg:";
27 if (RegInfo)
28 OS << RegInfo->getName(getReg());
29 else
30 OS << getReg();
31 } else if (isImm())
32 OS << "Imm:" << getImm();
33 else if (isSFPImm())
34 OS << "SFPImm:" << bit_cast<float>(getSFPImm());
35 else if (isDFPImm())
36 OS << "DFPImm:" << bit_cast<double>(getDFPImm());
37 else if (isExpr()) {
38 OS << "Expr:(" << *getExpr() << ")";
39 } else if (isInst()) {
40 OS << "Inst:(";
41 if (const auto *Inst = getInst())
42 Inst->print(OS, RegInfo);
43 else
44 OS << "NULL";
45 OS << ")";
46 } else
47 OS << "UNDEFINED";
48 OS << ">";
49}
50
51bool MCOperand::evaluateAsConstantImm(int64_t &Imm) const {
52 if (isImm()) {
53 Imm = getImm();
54 return true;
55 }
56 return false;
57}
58
60 assert(isExpr() &&
61 "isBareSymbolRef expects only expressions");
62 const MCExpr *Expr = getExpr();
64 return Kind == MCExpr::SymbolRef &&
65 cast<MCSymbolRefExpr>(Expr)->getKind() == MCSymbolRefExpr::VK_None;
66}
67
68#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
70 print(dbgs());
71 dbgs() << "\n";
72}
73#endif
74
75void MCInst::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
76 OS << "<MCInst " << getOpcode();
77 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
78 OS << " ";
79 getOperand(i).print(OS, RegInfo);
80 }
81 OS << ">";
82}
83
85 StringRef Separator,
86 const MCRegisterInfo *RegInfo) const {
87 StringRef InstName = Printer ? Printer->getOpcodeName(getOpcode()) : "";
88 dump_pretty(OS, InstName, Separator, RegInfo);
89}
90
92 const MCRegisterInfo *RegInfo) const {
93 OS << "<MCInst #" << getOpcode();
94
95 // Show the instruction opcode name if we have it.
96 if (!Name.empty())
97 OS << ' ' << Name;
98
99 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
100 OS << Separator;
101 getOperand(i).print(OS, RegInfo);
102 }
103 OS << ">";
104}
105
106#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
108 print(dbgs());
109 dbgs() << "\n";
110}
111#endif
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:537
dxil pretty DXIL Metadata Pretty Printer
std::string Name
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:39
ExprKind getKind() const
Definition: MCExpr.h:78
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:45
void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ", const MCRegisterInfo *RegInfo=nullptr) const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
Definition: MCInst.cpp:84
unsigned getNumOperands() const
Definition: MCInst.h:208
void print(raw_ostream &OS, const MCRegisterInfo *RegInfo=nullptr) const
Definition: MCInst.cpp:75
unsigned getOpcode() const
Definition: MCInst.h:198
void dump() const
Definition: MCInst.cpp:107
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
bool isSFPImm() const
Definition: MCInst.h:63
bool isBareSymbolRef() const
Definition: MCInst.cpp:59
int64_t getImm() const
Definition: MCInst.h:80
bool isImm() const
Definition: MCInst.h:62
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:69
bool isInst() const
Definition: MCInst.h:66
bool isReg() const
Definition: MCInst.h:61
bool evaluateAsConstantImm(int64_t &Imm) const
Definition: MCInst.cpp:51
bool isDFPImm() const
Definition: MCInst.h:64
void dump() const
Definition: MCInst.cpp:69
const MCInst * getInst() const
Definition: MCInst.h:124
void print(raw_ostream &OS, const MCRegisterInfo *RegInfo=nullptr) const
Definition: MCInst.cpp:21
bool isValid() const
Definition: MCInst.h:60
const MCExpr * getExpr() const
Definition: MCInst.h:114
uint32_t getSFPImm() const
Definition: MCInst.h:90
uint64_t getDFPImm() const
Definition: MCInst.h:100
bool isExpr() const
Definition: MCInst.h:65
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163