LLVM  3.7.0
HexagonMCInstLower.cpp
Go to the documentation of this file.
1 //===- HexagonMCInstLower.cpp - Convert Hexagon 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 Hexagon MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "Hexagon.h"
16 #include "HexagonAsmPrinter.h"
19 
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/Mangler.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCInst.h"
26 
27 using namespace llvm;
28 
31  MCContext &MC = Printer.OutContext;
32  const MCExpr *ME;
33 
35 
36  if (!MO.isJTI() && MO.getOffset())
38  MC);
39 
40  return (MCOperand::createExpr(ME));
41 }
42 
43 // Create an MCInst from a MachineInstr
45  HexagonAsmPrinter& AP) {
46  if(MI->getOpcode() == Hexagon::ENDLOOP0){
48  return;
49  }
50  if(MI->getOpcode() == Hexagon::ENDLOOP1){
52  return;
53  }
54  MCInst* MCI = new (AP.OutContext) MCInst;
55  MCI->setOpcode(MI->getOpcode());
56  assert(MCI->getOpcode() == static_cast<unsigned>(MI->getOpcode()) &&
57  "MCI opcode should have been set on construction");
58 
59  for (unsigned i = 0, e = MI->getNumOperands(); i < e; i++) {
60  const MachineOperand &MO = MI->getOperand(i);
61  MCOperand MCO;
62 
63  switch (MO.getType()) {
64  default:
65  MI->dump();
66  llvm_unreachable("unknown operand type");
68  // Ignore all implicit register operands.
69  if (MO.isImplicit()) continue;
70  MCO = MCOperand::createReg(MO.getReg());
71  break;
73  APFloat Val = MO.getFPImm()->getValueAPF();
74  // FP immediates are used only when setting GPRs, so they may be dealt
75  // with like regular immediates from this point on.
77  break;
78  }
80  MCO = MCOperand::createImm(MO.getImm());
81  break;
85  AP.OutContext));
86  break;
88  MCO = GetSymbolRef(MO, AP.getSymbol(MO.getGlobal()), AP);
89  break;
92  AP);
93  break;
95  MCO = GetSymbolRef(MO, AP.GetJTISymbol(MO.getIndex()), AP);
96  break;
98  MCO = GetSymbolRef(MO, AP.GetCPISymbol(MO.getIndex()), AP);
99  break;
101  MCO = GetSymbolRef(MO, AP.GetBlockAddressSymbol(MO.getBlockAddress()),AP);
102  break;
103  }
104 
105  MCI->addOperand(MCO);
106  }
108 }
bool isImplicit() const
const GlobalValue * getGlobal() const
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:339
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:315
const ConstantFP * getFPImm() const
MachineBasicBlock * getMBB() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:78
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:129
static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, HexagonAsmPrinter &Printer)
Address of indexed Jump Table for switch.
void HexagonLowerToMC(const MachineInstr *MI, MCInst &MCI, HexagonAsmPrinter &AP)
MachineBasicBlock reference.
const char * getSymbolName() const
print alias Alias Set Printer
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:111
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Name of external global symbol.
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:271
Context object for machine code objects.
Definition: MCContext.h:48
int64_t getImm() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:446
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:267
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:122
Address of a global value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:273
Address of a basic block.
int64_t getOffset() const
Return the offset from the symbol in this operand.
MCSymbol * getSymbol() const
getSymbol - Return the MCSymbol for this basic block.
void setOpcode(unsigned Op)
Definition: MCInst.h:158
MachineOperand class - Representation of each machine instruction operand.
void dump() const
unsigned getOpcode() const
Definition: MCInst.h:159
APInt bitcastToAPInt() const
Definition: APFloat.cpp:3084
static MCOperand createInst(const MCInst *Val)
Definition: MCInst.h:135
Representation of each machine instruction.
Definition: MachineInstr.h:51
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:573
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
const APFloat & getValueAPF() const
Definition: Constants.h:270
unsigned getReg() const
getReg - Returns the register number.
Floating-point immediate operand.
void addOperand(const MCOperand &Op)
Definition: MCInst.h:168
const BlockAddress * getBlockAddress() const
Address of indexed Constant in Constant Pool.
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:33
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:117
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:150