LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ARMMCInstLower.cpp
Go to the documentation of this file.
1 //===-- ARMMCInstLower.cpp - Convert ARM 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 ARM MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "ARM.h"
16 #include "ARMAsmPrinter.h"
17 #include "MCTargetDesc/ARMMCExpr.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/MC/MCExpr.h"
21 #include "llvm/MC/MCInst.h"
22 #include "llvm/Target/Mangler.h"
23 using namespace llvm;
24 
25 
26 MCOperand ARMAsmPrinter::GetSymbolRef(const MachineOperand &MO,
27  const MCSymbol *Symbol) {
28  const MCExpr *Expr;
29  switch (MO.getTargetFlags()) {
30  default: {
32  OutContext);
33  switch (MO.getTargetFlags()) {
34  default: llvm_unreachable("Unknown target flag on symbol operand");
35  case 0:
36  break;
37  case ARMII::MO_LO16:
39  OutContext);
41  break;
42  case ARMII::MO_HI16:
44  OutContext);
46  break;
47  }
48  break;
49  }
50 
51  case ARMII::MO_PLT:
53  OutContext);
54  break;
55  }
56 
57  if (!MO.isJTI() && MO.getOffset())
58  Expr = MCBinaryExpr::CreateAdd(Expr,
60  OutContext),
61  OutContext);
62  return MCOperand::CreateExpr(Expr);
63 
64 }
65 
67  MCOperand &MCOp) {
68  switch (MO.getType()) {
69  default: llvm_unreachable("unknown operand type");
71  // Ignore all non-CPSR implicit register operands.
72  if (MO.isImplicit() && MO.getReg() != ARM::CPSR)
73  return false;
74  assert(!MO.getSubReg() && "Subregs should be eliminated!");
75  MCOp = MCOperand::CreateReg(MO.getReg());
76  break;
78  MCOp = MCOperand::CreateImm(MO.getImm());
79  break;
82  MO.getMBB()->getSymbol(), OutContext));
83  break;
85  MCOp = GetSymbolRef(MO, getSymbol(MO.getGlobal()));
86  break;
88  MCOp = GetSymbolRef(MO,
90  break;
92  MCOp = GetSymbolRef(MO, GetJTISymbol(MO.getIndex()));
93  break;
95  MCOp = GetSymbolRef(MO, GetCPISymbol(MO.getIndex()));
96  break;
98  MCOp = GetSymbolRef(MO, GetBlockAddressSymbol(MO.getBlockAddress()));
99  break;
101  APFloat Val = MO.getFPImm()->getValueAPF();
102  bool ignored;
105  break;
106  }
108  // Ignore call clobbers.
109  return false;
110  }
111  return true;
112 }
113 
115  ARMAsmPrinter &AP) {
116  OutMI.setOpcode(MI->getOpcode());
117 
118  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
119  const MachineOperand &MO = MI->getOperand(i);
120 
121  MCOperand MCOp;
122  if (AP.lowerOperand(MO, MCOp))
123  OutMI.addOperand(MCOp);
124  }
125 }
bool isImplicit() const
const GlobalValue * getGlobal() const
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp)
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:277
static MCOperand CreateReg(unsigned Reg)
Definition: MCInst.h:111
static const fltSemantics IEEEdouble
Definition: APFloat.h:133
const ConstantFP * getFPImm() const
MachineBasicBlock * getMBB() const
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:152
MCContext & OutContext
Definition: AsmPrinter.h:72
static MCOperand CreateExpr(const MCExpr *Val)
Definition: MCInst.h:129
const char * getSymbolName() const
static const ARMMCExpr * CreateLower16(const MCExpr *Expr, MCContext &Ctx)
Definition: ARMMCExpr.h:43
Address of indexed Jump Table for switch.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
#define llvm_unreachable(msg)
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
GetJTISymbol - Return the symbol for the specified jump table entry.
unsigned getNumOperands() const
Definition: MachineInstr.h:265
int getOpcode() const
Definition: MachineInstr.h:261
double convertToDouble() const
Definition: APFloat.cpp:3082
int64_t getImm() const
Address of indexed Constant in Constant Pool.
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:270
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:122
unsigned getTargetFlags() const
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
opStatus convert(const fltSemantics &, roundingMode, bool *)
Definition: APFloat.cpp:1938
int64_t getOffset() const
Floating-point immediate operand.
unsigned getSubReg() const
MCSymbol * getSymbol() const
void setOpcode(unsigned Op)
Definition: MCInst.h:157
void LowerARMMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, ARMAsmPrinter &AP)
static const ARMMCExpr * CreateUpper16(const MCExpr *Expr, MCContext &Ctx)
Definition: ARMMCExpr.h:39
static const MCBinaryExpr * CreateAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:396
MachineOperandType getType() const
static MCOperand CreateImm(int64_t Val)
Definition: MCInst.h:117
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
static MCOperand CreateFPImm(double Val)
Definition: MCInst.h:123
Mask of preserved registers.
MCSymbol * GetCPISymbol(unsigned CPID) const
GetCPISymbol - Return the symbol for the specified constant pool entry.
const APFloat & getValueAPF() const
Definition: Constants.h:263
unsigned getReg() const
getReg - Returns the register number.
Address of a basic block.
void addOperand(const MCOperand &Op)
Definition: MCInst.h:167
const BlockAddress * getBlockAddress() const
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
MachineBasicBlock reference.
Address of a global value.
Name of external global symbol.