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