LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
20 #include "llvm/IR/Constants.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/Target/Mangler.h"
24 
25 using namespace llvm;
26 
29  MCContext &MC = Printer.OutContext;
30  const MCExpr *ME;
31 
33 
34  if (!MO.isJTI() && MO.getOffset())
36  MC);
37 
38  return (MCOperand::CreateExpr(ME));
39 }
40 
41 // Create an MCInst from a MachineInstr
43  HexagonAsmPrinter& AP) {
44  MCI.setOpcode(MI->getOpcode());
45  MCI.setDesc(MI->getDesc());
46 
47  for (unsigned i = 0, e = MI->getNumOperands(); i < e; i++) {
48  const MachineOperand &MO = MI->getOperand(i);
49  MCOperand MCO;
50 
51  switch (MO.getType()) {
52  default:
53  MI->dump();
54  llvm_unreachable("unknown operand type");
56  // Ignore all implicit register operands.
57  if (MO.isImplicit()) continue;
58  MCO = MCOperand::CreateReg(MO.getReg());
59  break;
61  APFloat Val = MO.getFPImm()->getValueAPF();
62  // FP immediates are used only when setting GPRs, so they may be dealt
63  // with like regular immediates from this point on.
65  break;
66  }
68  MCO = MCOperand::CreateImm(MO.getImm());
69  break;
73  AP.OutContext));
74  break;
76  MCO = GetSymbolRef(MO, AP.getSymbol(MO.getGlobal()), AP);
77  break;
80  AP);
81  break;
83  MCO = GetSymbolRef(MO, AP.GetJTISymbol(MO.getIndex()), AP);
84  break;
86  MCO = GetSymbolRef(MO, AP.GetCPISymbol(MO.getIndex()), AP);
87  break;
89  MCO = GetSymbolRef(MO, AP.GetBlockAddressSymbol(MO.getBlockAddress()),AP);
90  break;
91  }
92 
93  MCI.addOperand(MCO);
94  }
95 }
bool isImplicit() const
const GlobalValue * getGlobal() const
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:277
static MCOperand CreateReg(unsigned Reg)
Definition: MCInst.h:111
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 GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, HexagonAsmPrinter &Printer)
static MCOperand CreateExpr(const MCExpr *Val)
Definition: MCInst.h:129
void HexagonLowerToMC(const MachineInstr *MI, HexagonMCInst &MCI, HexagonAsmPrinter &AP)
const MCInstrDesc & getDesc() const
Definition: MachineInstr.h:257
const char * getSymbolName() const
print alias Alias Set Printer
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.
void setDesc(const MCInstrDesc &mcid)
Definition: HexagonMCInst.h:50
unsigned getNumOperands() const
Definition: MachineInstr.h:265
int getOpcode() const
Definition: MachineInstr.h:261
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
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
int64_t getOffset() const
Floating-point immediate operand.
MCSymbol * getSymbol() const
void setOpcode(unsigned Op)
Definition: MCInst.h:157
void dump() const
APInt bitcastToAPInt() const
Definition: APFloat.cpp:3050
static const MCBinaryExpr * CreateAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:396
MachineOperandType getType() const
const uint64_t * getRawData() const
Definition: APInt.h:570
static MCOperand CreateImm(int64_t Val)
Definition: MCInst.h:117
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
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.