LLVM  10.0.0svn
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"
12 #include "llvm/MC/MCInstPrinter.h"
13 #include "llvm/Support/Casting.h"
14 #include "llvm/Support/Compiler.h"
15 #include "llvm/Support/Debug.h"
17 
18 using namespace llvm;
19 
20 void MCOperand::print(raw_ostream &OS) const {
21  OS << "<MCOperand ";
22  if (!isValid())
23  OS << "INVALID";
24  else if (isReg())
25  OS << "Reg:" << getReg();
26  else if (isImm())
27  OS << "Imm:" << getImm();
28  else if (isFPImm())
29  OS << "FPImm:" << getFPImm();
30  else if (isExpr()) {
31  OS << "Expr:(" << *getExpr() << ")";
32  } else if (isInst()) {
33  OS << "Inst:(" << *getInst() << ")";
34  } else
35  OS << "UNDEFINED";
36  OS << ">";
37 }
38 
39 bool MCOperand::evaluateAsConstantImm(int64_t &Imm) const {
40  if (isImm()) {
41  Imm = getImm();
42  return true;
43  }
44  return false;
45 }
46 
48  assert(isExpr() &&
49  "isBareSymbolRef expects only expressions");
50  const MCExpr *Expr = getExpr();
51  MCExpr::ExprKind Kind = getExpr()->getKind();
52  return Kind == MCExpr::SymbolRef &&
53  cast<MCSymbolRefExpr>(Expr)->getKind() == MCSymbolRefExpr::VK_None;
54 }
55 
56 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
58  print(dbgs());
59  dbgs() << "\n";
60 }
61 #endif
62 
63 void MCInst::print(raw_ostream &OS) const {
64  OS << "<MCInst " << getOpcode();
65  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
66  OS << " ";
67  getOperand(i).print(OS);
68  }
69  OS << ">";
70 }
71 
73  StringRef Separator) const {
74  StringRef InstName = Printer ? Printer->getOpcodeName(getOpcode()) : "";
75  dump_pretty(OS, InstName, Separator);
76 }
77 
79  StringRef Separator) const {
80  OS << "<MCInst #" << getOpcode();
81 
82  // Show the instruction opcode name if we have it.
83  if (!Name.empty())
84  OS << ' ' << Name;
85 
86  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
87  OS << Separator;
88  getOperand(i).print(OS);
89  }
90  OS << ">";
91 }
92 
93 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
95  print(dbgs());
96  dbgs() << "\n";
97 }
98 #endif
bool isImm() const
Definition: MCInst.h:58
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:484
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void print(raw_ostream &OS) const
Definition: MCInst.cpp:20
void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ") const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
Definition: MCInst.cpp:72
bool isReg() const
Definition: MCInst.h:57
print alias Alias Set Printer
bool isBareSymbolRef() const
Definition: MCInst.cpp:47
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:196
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
void dump() const
Definition: MCInst.cpp:57
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:140
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:64
const MCInst * getInst() const
Definition: MCInst.h:105
const MCExpr * getExpr() const
Definition: MCInst.h:95
int64_t getImm() const
Definition: MCInst.h:75
bool isInst() const
Definition: MCInst.h:61
bool isFPImm() const
Definition: MCInst.h:59
constexpr double e
Definition: MathExtras.h:57
bool isExpr() const
Definition: MCInst.h:60
void print(raw_ostream &OS) const
Definition: MCInst.cpp:63
void dump() const
Definition: MCInst.cpp:94
ExprKind getKind() const
Definition: MCExpr.h:68
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
bool evaluateAsConstantImm(int64_t &Imm) const
Definition: MCInst.cpp:39
StringRef getOpcodeName(unsigned Opcode) const
Return the name of the specified opcode enum (e.g.
References to labels and assigned expressions.
Definition: MCExpr.h:40
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:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
bool isValid() const
Definition: MCInst.h:56
double getFPImm() const
Definition: MCInst.h:85