LLVM  6.0.0svn
BPFMCInstLower.cpp
Go to the documentation of this file.
1 //=-- BPFMCInstLower.cpp - Convert BPF MachineInstr to an MCInst ------------=//
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 file contains code to lower BPF MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "BPFMCInstLower.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCInst.h"
25 using namespace llvm;
26 
27 MCSymbol *
29  return Printer.getSymbol(MO.getGlobal());
30 }
31 
32 MCSymbol *
34  return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
35 }
36 
38  MCSymbol *Sym) const {
39 
40  const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
41 
42  if (!MO.isJTI() && MO.getOffset())
43  llvm_unreachable("unknown symbol op");
44 
45  return MCOperand::createExpr(Expr);
46 }
47 
48 void BPFMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
49  OutMI.setOpcode(MI->getOpcode());
50 
51  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
52  const MachineOperand &MO = MI->getOperand(i);
53 
54  MCOperand MCOp;
55  switch (MO.getType()) {
56  default:
57  MI->print(errs());
58  llvm_unreachable("unknown operand type");
60  // Ignore all implicit register operands.
61  if (MO.isImplicit())
62  continue;
63  MCOp = MCOperand::createReg(MO.getReg());
64  break;
66  MCOp = MCOperand::createImm(MO.getImm());
67  break;
69  MCOp = MCOperand::createExpr(
71  break;
73  continue;
76  break;
79  break;
80  }
81 
82  OutMI.addOperand(MCOp);
83  }
84 }
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MachineBasicBlock * getMBB() const
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:305
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
unsigned getReg() const
getReg - Returns the register number.
MachineBasicBlock reference.
Mask of preserved registers.
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:293
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Name of external global symbol.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:290
const char * getSymbolName() const
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
Address of a global value.
const GlobalValue * getGlobal() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setOpcode(unsigned Op)
Definition: MCInst.h:171
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:433
void Lower(const MachineInstr *MI, MCInst &OutMI) const
MachineOperand class - Representation of each machine instruction operand.
MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const
int64_t getImm() const
MCSymbol * GetExternalSymbolSymbol(const MachineOperand &MO) const
MCSymbol * GetGlobalAddressSymbol(const MachineOperand &MO) const
Representation of each machine instruction.
Definition: MachineInstr.h:59
int64_t getOffset() const
Return the offset from the symbol in this operand.
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
void print(raw_ostream &OS, bool SkipOpers=false, bool SkipDebugLoc=false, const TargetInstrInfo *TII=nullptr) const
Debugging supportPrint this MI to OS.
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:184
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:295
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:123
bool isImplicit() const