OLD | NEW |
1 //===-- ARMMCInstLower.cpp - Convert ARM MachineInstr to an MCInst --------===// | 1 //===-- ARMMCInstLower.cpp - Convert ARM MachineInstr to an MCInst --------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file contains code to lower ARM MachineInstrs to their corresponding | 10 // This file contains code to lower ARM MachineInstrs to their corresponding |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 OutMI.setOpcode(MI->getOpcode()); | 120 OutMI.setOpcode(MI->getOpcode()); |
121 | 121 |
122 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { | 122 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
123 const MachineOperand &MO = MI->getOperand(i); | 123 const MachineOperand &MO = MI->getOperand(i); |
124 | 124 |
125 MCOperand MCOp; | 125 MCOperand MCOp; |
126 if (AP.lowerOperand(MO, MCOp)) | 126 if (AP.lowerOperand(MO, MCOp)) |
127 OutMI.addOperand(MCOp); | 127 OutMI.addOperand(MCOp); |
128 } | 128 } |
129 } | 129 } |
| 130 |
| 131 // @LOCALMOD-BEGIN |
| 132 // Unlike LowerARMMachineInstrToMCInst, the opcode has already been set. |
| 133 // Otherwise, this is like LowerARMMachineInstrToMCInst, but with special |
| 134 // handling where the "immediate" is PC Relative |
| 135 // (used for MOVi16PIC / MOVTi16PIC, etc. -- see .td file) |
| 136 void llvm::LowerARMMachineInstrToMCInstPCRel(const MachineInstr *MI, |
| 137 MCInst &OutMI, |
| 138 ARMAsmPrinter &AP, |
| 139 unsigned ImmIndex, |
| 140 unsigned PCIndex, |
| 141 MCSymbol *PCLabel, |
| 142 unsigned PCAdjustment) { |
| 143 |
| 144 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 145 if (i == ImmIndex) { |
| 146 MCContext &Ctx = AP.OutContext; |
| 147 const MCExpr *PCRelExpr = MCSymbolRefExpr::Create(PCLabel, Ctx); |
| 148 if (PCAdjustment) { |
| 149 const MCExpr *AdjExpr = MCConstantExpr::Create(PCAdjustment, Ctx); |
| 150 PCRelExpr = MCBinaryExpr::CreateAdd(PCRelExpr, AdjExpr, Ctx); |
| 151 } |
| 152 |
| 153 // Get the usual symbol operand, then subtract the PCRelExpr. |
| 154 const MachineOperand &MOImm = MI->getOperand(ImmIndex); |
| 155 MCOperand SymOp; |
| 156 bool DidLower = AP.lowerOperand(MOImm, SymOp); |
| 157 assert (DidLower && "Immediate-like operand should have been lowered"); |
| 158 |
| 159 const MCExpr *Expr = SymOp.getExpr(); |
| 160 ARMMCExpr::VariantKind TargetKind = ARMMCExpr::VK_ARM_None; |
| 161 /* Unwrap and rewrap the ARMMCExpr */ |
| 162 if (Expr->getKind() == MCExpr::Target) { |
| 163 const ARMMCExpr *TargetExpr = cast<ARMMCExpr>(Expr); |
| 164 TargetKind = TargetExpr->getKind(); |
| 165 Expr = TargetExpr->getSubExpr(); |
| 166 } |
| 167 Expr = MCBinaryExpr::CreateSub(Expr, PCRelExpr, Ctx); |
| 168 if (TargetKind != ARMMCExpr::VK_ARM_None) { |
| 169 Expr = ARMMCExpr::Create(TargetKind, Expr, Ctx); |
| 170 } |
| 171 MCOperand MCOp = MCOperand::CreateExpr(Expr); |
| 172 OutMI.addOperand(MCOp); |
| 173 } else if (i == PCIndex) { // dummy index already handled as PCLabel |
| 174 continue; |
| 175 } else { |
| 176 MCOperand MCOp; |
| 177 if (AP.lowerOperand(MI->getOperand(i), MCOp)) { |
| 178 OutMI.addOperand(MCOp); |
| 179 } |
| 180 } |
| 181 } |
| 182 } |
| 183 // @LOCALMOD-END |
OLD | NEW |