2010-10-09 01:28:40 +08:00
|
|
|
//===-- ARM/ARMCodeEmitter.cpp - Convert ARM code to machine code ---------===//
|
2007-07-06 05:15:40 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-06 05:15:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the pass that transforms the ARM machine instructions into
|
|
|
|
// relocatable machine code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-10-30 07:55:43 +08:00
|
|
|
#define DEBUG_TYPE "jit"
|
2008-09-02 14:52:38 +08:00
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMAddressingModes.h"
|
2008-10-30 07:55:43 +08:00
|
|
|
#include "ARMConstantPoolValue.h"
|
2007-07-06 05:15:40 +08:00
|
|
|
#include "ARMInstrInfo.h"
|
2008-09-02 14:52:38 +08:00
|
|
|
#include "ARMRelocations.h"
|
2007-07-06 05:15:40 +08:00
|
|
|
#include "ARMSubtarget.h"
|
|
|
|
#include "ARMTargetMachine.h"
|
2008-10-29 02:25:49 +08:00
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-09-13 09:15:21 +08:00
|
|
|
#include "llvm/Function.h"
|
2007-07-06 05:15:40 +08:00
|
|
|
#include "llvm/PassManager.h"
|
2009-05-31 04:51:52 +08:00
|
|
|
#include "llvm/CodeGen/JITCodeEmitter.h"
|
2008-09-18 15:28:19 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2007-07-06 05:15:40 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2008-11-07 17:06:08 +08:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2009-09-21 13:58:35 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2007-07-06 05:15:40 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
2008-09-13 09:15:21 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 02:01:40 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-11-07 17:06:08 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#include <iomanip>
|
|
|
|
#endif
|
2007-07-06 05:15:40 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
STATISTIC(NumEmitted, "Number of machine instructions emitted");
|
|
|
|
|
|
|
|
namespace {
|
2009-05-31 04:51:52 +08:00
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
class ARMCodeEmitter : public MachineFunctionPass {
|
2008-09-18 15:28:19 +08:00
|
|
|
ARMJITInfo *JTI;
|
|
|
|
const ARMInstrInfo *II;
|
|
|
|
const TargetData *TD;
|
2009-09-10 09:23:53 +08:00
|
|
|
const ARMSubtarget *Subtarget;
|
2008-09-18 15:28:19 +08:00
|
|
|
TargetMachine &TM;
|
2010-02-03 05:48:51 +08:00
|
|
|
JITCodeEmitter &MCE;
|
2010-03-14 09:41:15 +08:00
|
|
|
MachineModuleInfo *MMI;
|
2008-11-01 03:55:13 +08:00
|
|
|
const std::vector<MachineConstantPoolEntry> *MCPEs;
|
2008-11-07 17:06:08 +08:00
|
|
|
const std::vector<MachineJumpTableEntry> *MJTEs;
|
|
|
|
bool IsPIC;
|
2010-06-29 06:23:17 +08:00
|
|
|
bool IsThumb;
|
2010-03-18 05:16:45 +08:00
|
|
|
|
2009-09-21 13:58:35 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<MachineModuleInfo>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
2010-03-18 05:16:45 +08:00
|
|
|
|
2007-07-06 05:15:40 +08:00
|
|
|
static char ID;
|
2010-02-03 05:48:51 +08:00
|
|
|
public:
|
|
|
|
ARMCodeEmitter(TargetMachine &tm, JITCodeEmitter &mce)
|
2010-08-07 02:33:48 +08:00
|
|
|
: MachineFunctionPass(ID), JTI(0),
|
2010-04-18 01:42:52 +08:00
|
|
|
II((const ARMInstrInfo *)tm.getInstrInfo()),
|
2010-02-03 05:48:51 +08:00
|
|
|
TD(tm.getTargetData()), TM(tm),
|
2010-06-29 06:23:17 +08:00
|
|
|
MCE(mce), MCPEs(0), MJTEs(0),
|
|
|
|
IsPIC(TM.getRelocationModel() == Reloc::PIC_), IsThumb(false) {}
|
2010-03-18 05:16:45 +08:00
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
/// getBinaryCodeForInstr - This function, generated by the
|
|
|
|
/// CodeEmitterGenerator using TableGen, produces the binary encoding for
|
|
|
|
/// machine instructions.
|
2010-10-08 08:21:28 +08:00
|
|
|
unsigned getBinaryCodeForInstr(const MachineInstr &MI) const;
|
2007-07-06 05:15:40 +08:00
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "ARM Machine Code Emitter";
|
|
|
|
}
|
|
|
|
|
|
|
|
void emitInstruction(const MachineInstr &MI);
|
2008-09-02 14:52:38 +08:00
|
|
|
|
|
|
|
private:
|
2008-09-18 15:28:19 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
void emitWordLE(unsigned Binary);
|
2008-11-12 06:19:31 +08:00
|
|
|
void emitDWordLE(uint64_t Binary);
|
2008-09-18 15:28:19 +08:00
|
|
|
void emitConstPoolInstruction(const MachineInstr &MI);
|
2010-05-25 16:42:45 +08:00
|
|
|
void emitMOVi32immInstruction(const MachineInstr &MI);
|
2008-11-06 10:25:39 +08:00
|
|
|
void emitMOVi2piecesInstruction(const MachineInstr &MI);
|
2008-11-07 17:06:08 +08:00
|
|
|
void emitLEApcrelJTInstruction(const MachineInstr &MI);
|
2008-11-15 04:09:11 +08:00
|
|
|
void emitPseudoMoveInstruction(const MachineInstr &MI);
|
2008-11-06 07:22:34 +08:00
|
|
|
void addPCLabel(unsigned LabelID);
|
2008-09-18 15:28:19 +08:00
|
|
|
void emitPseudoInstruction(const MachineInstr &MI);
|
2008-09-13 06:01:15 +08:00
|
|
|
unsigned getMachineSoRegOpValue(const MachineInstr &MI,
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID,
|
2008-11-01 03:10:44 +08:00
|
|
|
const MachineOperand &MO,
|
2008-09-13 06:01:15 +08:00
|
|
|
unsigned OpIdx);
|
|
|
|
|
2008-11-06 10:25:39 +08:00
|
|
|
unsigned getMachineSoImmOpValue(unsigned SoImm);
|
2008-11-04 02:38:31 +08:00
|
|
|
unsigned getAddrModeSBit(const MachineInstr &MI,
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID) const;
|
2008-09-13 06:45:55 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
void emitDataProcessingInstruction(const MachineInstr &MI,
|
2008-11-08 06:30:53 +08:00
|
|
|
unsigned ImplicitRd = 0,
|
2008-11-06 07:22:34 +08:00
|
|
|
unsigned ImplicitRn = 0);
|
2008-11-06 02:35:52 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
void emitLoadStoreInstruction(const MachineInstr &MI,
|
2008-11-07 17:06:08 +08:00
|
|
|
unsigned ImplicitRd = 0,
|
2008-11-06 07:22:34 +08:00
|
|
|
unsigned ImplicitRn = 0);
|
2008-11-06 02:35:52 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
void emitMiscLoadStoreInstruction(const MachineInstr &MI,
|
|
|
|
unsigned ImplicitRn = 0);
|
2008-11-06 02:35:52 +08:00
|
|
|
|
|
|
|
void emitLoadStoreMultipleInstruction(const MachineInstr &MI);
|
|
|
|
|
2008-11-06 09:21:28 +08:00
|
|
|
void emitMulFrmInstruction(const MachineInstr &MI);
|
2008-11-06 02:35:52 +08:00
|
|
|
|
2008-11-07 06:15:19 +08:00
|
|
|
void emitExtendInstruction(const MachineInstr &MI);
|
|
|
|
|
2008-11-07 09:41:35 +08:00
|
|
|
void emitMiscArithInstruction(const MachineInstr &MI);
|
|
|
|
|
2010-08-11 08:01:18 +08:00
|
|
|
void emitSaturateInstruction(const MachineInstr &MI);
|
|
|
|
|
2008-11-06 02:35:52 +08:00
|
|
|
void emitBranchInstruction(const MachineInstr &MI);
|
|
|
|
|
2008-11-08 06:30:53 +08:00
|
|
|
void emitInlineJumpTable(unsigned JTIndex);
|
2008-11-07 17:06:08 +08:00
|
|
|
|
2008-11-06 02:35:52 +08:00
|
|
|
void emitMiscBranchInstruction(const MachineInstr &MI);
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-11-11 10:11:05 +08:00
|
|
|
void emitVFPArithInstruction(const MachineInstr &MI);
|
|
|
|
|
2008-11-12 03:40:26 +08:00
|
|
|
void emitVFPConversionInstruction(const MachineInstr &MI);
|
|
|
|
|
2008-11-12 05:48:44 +08:00
|
|
|
void emitVFPLoadStoreInstruction(const MachineInstr &MI);
|
|
|
|
|
|
|
|
void emitVFPLoadStoreMultipleInstruction(const MachineInstr &MI);
|
|
|
|
|
2010-06-30 01:34:07 +08:00
|
|
|
void emitNEONLaneInstruction(const MachineInstr &MI);
|
2010-06-30 04:13:29 +08:00
|
|
|
void emitNEONDupInstruction(const MachineInstr &MI);
|
2010-06-26 05:17:19 +08:00
|
|
|
void emitNEON1RegModImmInstruction(const MachineInstr &MI);
|
|
|
|
void emitNEON2RegInstruction(const MachineInstr &MI);
|
2010-06-26 06:40:46 +08:00
|
|
|
void emitNEON3RegInstruction(const MachineInstr &MI);
|
2010-06-12 05:34:50 +08:00
|
|
|
|
2008-09-02 14:52:38 +08:00
|
|
|
/// getMachineOpValue - Return binary encoding of operand. If the machine
|
|
|
|
/// operand requires relocation, record the relocation and return zero.
|
2010-10-09 01:45:54 +08:00
|
|
|
unsigned getMachineOpValue(const MachineInstr &MI,
|
|
|
|
const MachineOperand &MO) const;
|
|
|
|
unsigned getMachineOpValue(const MachineInstr &MI, unsigned OpIdx) const {
|
2008-09-02 14:52:38 +08:00
|
|
|
return getMachineOpValue(MI, MI.getOperand(OpIdx));
|
|
|
|
}
|
|
|
|
|
2010-10-13 07:00:24 +08:00
|
|
|
// FIXME: The legacy JIT ARMCodeEmitter doesn't rely on the the
|
|
|
|
// TableGen'erated getBinaryCodeForInstr() function to encode any
|
|
|
|
// operand values, instead querying getMachineOpValue() directly for
|
|
|
|
// each operand it needs to encode. Thus, any of the new encoder
|
|
|
|
// helper functions can simply return 0 as the values the return
|
|
|
|
// are already handled elsewhere. They are placeholders to allow this
|
|
|
|
// encoder to continue to function until the MC encoder is sufficiently
|
|
|
|
// far along that this one can be eliminated entirely.
|
2010-11-12 03:07:48 +08:00
|
|
|
unsigned NEONThumb2DataIPostEncoder(const MachineInstr &MI, unsigned Val)
|
|
|
|
const { return 0; }
|
2010-11-12 05:36:43 +08:00
|
|
|
unsigned NEONThumb2LoadStorePostEncoder(const MachineInstr &MI,unsigned Val)
|
|
|
|
const { return 0; }
|
2010-11-12 07:12:55 +08:00
|
|
|
unsigned NEONThumb2DupPostEncoder(const MachineInstr &MI,unsigned Val)
|
|
|
|
const { return 0; }
|
2010-12-02 05:54:50 +08:00
|
|
|
unsigned VFPThumb2PostEncoder(const MachineInstr&MI, unsigned Val)
|
|
|
|
const { return 0; }
|
2010-12-02 03:47:31 +08:00
|
|
|
unsigned getAdrLabelOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-15 06:28:03 +08:00
|
|
|
unsigned getThumbAdrLabelOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-07 07:57:07 +08:00
|
|
|
unsigned getThumbBLTargetOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-09 08:39:08 +08:00
|
|
|
unsigned getThumbBLXTargetOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-11 02:21:33 +08:00
|
|
|
unsigned getThumbBRTargetOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-11 01:13:40 +08:00
|
|
|
unsigned getThumbBCCTargetOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-10 03:04:53 +08:00
|
|
|
unsigned getThumbCBTargetOpValue(const MachineInstr &MI, unsigned Op)
|
2010-12-09 07:01:43 +08:00
|
|
|
const { return 0; }
|
2010-11-12 02:04:49 +08:00
|
|
|
unsigned getBranchTargetOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-14 03:31:11 +08:00
|
|
|
unsigned getUnconditionalBranchTargetOpValue(const MachineInstr &MI,
|
|
|
|
unsigned Op) const { return 0; }
|
2011-02-05 03:47:15 +08:00
|
|
|
unsigned getARMBranchTargetOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-10-13 07:00:24 +08:00
|
|
|
unsigned getCCOutOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-10-13 07:18:08 +08:00
|
|
|
unsigned getSOImmOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-13 05:12:40 +08:00
|
|
|
unsigned getT2SOImmOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-10-13 07:53:58 +08:00
|
|
|
unsigned getSORegOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-14 11:36:38 +08:00
|
|
|
unsigned getThumbAddrModeRegRegOpValue(const MachineInstr &MI, unsigned Op)
|
2010-12-11 06:11:13 +08:00
|
|
|
const { return 0; }
|
2010-11-30 06:44:32 +08:00
|
|
|
unsigned getT2AddrModeImm12OpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
|
|
|
unsigned getT2AddrModeImm8OpValue(const MachineInstr &MI, unsigned Op)
|
2010-11-30 08:14:31 +08:00
|
|
|
const { return 0; }
|
2010-12-02 03:18:46 +08:00
|
|
|
unsigned getT2AddrModeImm8s4OpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-30 08:14:31 +08:00
|
|
|
unsigned getT2AddrModeImm8OffsetOpValue(const MachineInstr &MI, unsigned Op)
|
2010-11-30 06:44:32 +08:00
|
|
|
const { return 0; }
|
2010-12-01 03:19:31 +08:00
|
|
|
unsigned getT2AddrModeImm12OffsetOpValue(const MachineInstr &MI,unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-30 06:44:32 +08:00
|
|
|
unsigned getT2AddrModeSORegOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-13 05:12:40 +08:00
|
|
|
unsigned getT2SORegOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-10-14 03:56:10 +08:00
|
|
|
unsigned getRotImmOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-10-16 01:15:16 +08:00
|
|
|
unsigned getImmMinusOneOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-14 08:36:49 +08:00
|
|
|
unsigned getT2AdrLabelOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-03 06:28:01 +08:00
|
|
|
unsigned getAddrMode6AddressOpValue(const MachineInstr &MI, unsigned Op)
|
2010-11-02 08:05:05 +08:00
|
|
|
const { return 0; }
|
2011-05-10 01:47:27 +08:00
|
|
|
unsigned getAddrMode6OneLane32AddressOpValue(const MachineInstr &MI,
|
|
|
|
unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-30 08:00:42 +08:00
|
|
|
unsigned getAddrMode6DupAddressOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-03 06:28:01 +08:00
|
|
|
unsigned getAddrMode6OffsetOpValue(const MachineInstr &MI, unsigned Op)
|
2010-11-02 09:24:55 +08:00
|
|
|
const { return 0; }
|
2010-10-22 06:03:21 +08:00
|
|
|
unsigned getBitfieldInvertedMaskOpValue(const MachineInstr &MI,
|
|
|
|
unsigned Op) const { return 0; }
|
2011-01-19 04:45:56 +08:00
|
|
|
unsigned getMsbOpValue(const MachineInstr &MI,
|
|
|
|
unsigned Op) const { return 0; }
|
2011-05-31 11:33:27 +08:00
|
|
|
unsigned getSsatBitPosValue(const MachineInstr &MI,
|
|
|
|
unsigned Op) const { return 0; }
|
2010-11-11 07:38:36 +08:00
|
|
|
uint32_t getLdStmModeOpValue(const MachineInstr &MI, unsigned OpIdx)
|
|
|
|
const {return 0; }
|
2010-11-10 01:20:53 +08:00
|
|
|
uint32_t getLdStSORegOpValue(const MachineInstr &MI, unsigned OpIdx)
|
|
|
|
const { return 0; }
|
2010-11-03 09:49:29 +08:00
|
|
|
|
|
|
|
unsigned getAddrModeImm12OpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const {
|
|
|
|
// {17-13} = reg
|
|
|
|
// {12} = (U)nsigned (add == '1', sub == '0')
|
|
|
|
// {11-0} = imm12
|
2010-11-03 06:31:46 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(Op);
|
|
|
|
const MachineOperand &MO1 = MI.getOperand(Op + 1);
|
|
|
|
if (!MO.isReg()) {
|
|
|
|
emitConstPoolAddress(MO.getIndex(), ARM::reloc_arm_cp_entry);
|
|
|
|
return 0;
|
2010-10-28 03:55:59 +08:00
|
|
|
}
|
2010-11-03 06:31:46 +08:00
|
|
|
unsigned Reg = getARMRegisterNumbering(MO.getReg());
|
2010-11-03 09:49:29 +08:00
|
|
|
int32_t Imm12 = MO1.getImm();
|
2010-11-03 06:31:46 +08:00
|
|
|
uint32_t Binary;
|
2010-11-03 09:49:29 +08:00
|
|
|
Binary = Imm12 & 0xfff;
|
|
|
|
if (Imm12 >= 0)
|
|
|
|
Binary |= (1 << 12);
|
|
|
|
Binary |= (Reg << 13);
|
|
|
|
return Binary;
|
|
|
|
}
|
2010-11-19 07:37:15 +08:00
|
|
|
|
2011-01-13 15:58:56 +08:00
|
|
|
unsigned getHiLo16ImmOpValue(const MachineInstr &MI, unsigned Op) const {
|
2010-11-19 07:37:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-16 04:47:07 +08:00
|
|
|
uint32_t getAddrMode2OpValue(const MachineInstr &MI, unsigned OpIdx)
|
|
|
|
const { return 0;}
|
|
|
|
uint32_t getAddrMode2OffsetOpValue(const MachineInstr &MI, unsigned OpIdx)
|
|
|
|
const { return 0;}
|
2010-11-12 00:55:29 +08:00
|
|
|
uint32_t getAddrMode3OffsetOpValue(const MachineInstr &MI, unsigned OpIdx)
|
|
|
|
const { return 0;}
|
2010-11-30 15:44:32 +08:00
|
|
|
uint32_t getAddrMode3OpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-08 05:50:47 +08:00
|
|
|
uint32_t getAddrModeThumbSPOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-10 05:49:07 +08:00
|
|
|
uint32_t getAddrModeSOpValue(const MachineInstr &MI, unsigned Op)
|
2010-12-01 06:57:21 +08:00
|
|
|
const { return 0; }
|
2010-12-14 11:36:38 +08:00
|
|
|
uint32_t getAddrModeISOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-12-08 09:57:09 +08:00
|
|
|
uint32_t getAddrModePCOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-11-03 09:49:29 +08:00
|
|
|
uint32_t getAddrMode5OpValue(const MachineInstr &MI, unsigned Op) const {
|
2010-11-20 08:26:37 +08:00
|
|
|
// {17-13} = reg
|
|
|
|
// {12} = (U)nsigned (add == '1', sub == '0')
|
|
|
|
// {11-0} = imm12
|
2010-11-03 09:49:29 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(Op);
|
|
|
|
const MachineOperand &MO1 = MI.getOperand(Op + 1);
|
|
|
|
if (!MO.isReg()) {
|
|
|
|
emitConstPoolAddress(MO.getIndex(), ARM::reloc_arm_cp_entry);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
unsigned Reg = getARMRegisterNumbering(MO.getReg());
|
2010-11-20 08:26:37 +08:00
|
|
|
int32_t Imm12 = MO1.getImm();
|
|
|
|
|
|
|
|
// Special value for #-0
|
|
|
|
if (Imm12 == INT32_MIN)
|
|
|
|
Imm12 = 0;
|
|
|
|
|
|
|
|
// Immediate is always encoded as positive. The 'U' bit controls add vs
|
|
|
|
// sub.
|
|
|
|
bool isAdd = true;
|
|
|
|
if (Imm12 < 0) {
|
|
|
|
Imm12 = -Imm12;
|
|
|
|
isAdd = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Binary = Imm12 & 0xfff;
|
|
|
|
if (isAdd)
|
|
|
|
Binary |= (1 << 12);
|
|
|
|
Binary |= (Reg << 13);
|
2010-11-03 06:31:46 +08:00
|
|
|
return Binary;
|
|
|
|
}
|
2010-10-30 07:21:57 +08:00
|
|
|
unsigned getNEONVcvtImm32OpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
2010-10-13 07:00:24 +08:00
|
|
|
|
2010-10-30 08:37:59 +08:00
|
|
|
unsigned getRegisterListOpValue(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
|
|
|
|
2011-03-08 07:38:41 +08:00
|
|
|
unsigned getShiftRight8Imm(const MachineInstr &MI, unsigned Op)
|
2011-03-01 09:00:59 +08:00
|
|
|
const { return 0; }
|
2011-03-08 07:38:41 +08:00
|
|
|
unsigned getShiftRight16Imm(const MachineInstr &MI, unsigned Op)
|
2011-03-01 09:00:59 +08:00
|
|
|
const { return 0; }
|
2011-03-08 07:38:41 +08:00
|
|
|
unsigned getShiftRight32Imm(const MachineInstr &MI, unsigned Op)
|
|
|
|
const { return 0; }
|
|
|
|
unsigned getShiftRight64Imm(const MachineInstr &MI, unsigned Op)
|
2011-03-01 09:00:59 +08:00
|
|
|
const { return 0; }
|
|
|
|
|
2010-05-26 08:02:28 +08:00
|
|
|
/// getMovi32Value - Return binary encoding of operand for movw/movt. If the
|
2010-06-03 05:53:11 +08:00
|
|
|
/// machine operand requires relocation, record the relocation and return
|
|
|
|
/// zero.
|
2010-05-26 08:02:28 +08:00
|
|
|
unsigned getMovi32Value(const MachineInstr &MI,const MachineOperand &MO,
|
2010-05-25 16:42:45 +08:00
|
|
|
unsigned Reloc);
|
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
/// getShiftOp - Return the shift opcode (bit[6:5]) of the immediate value.
|
2008-09-02 14:52:38 +08:00
|
|
|
///
|
2008-11-06 07:22:34 +08:00
|
|
|
unsigned getShiftOp(unsigned Imm) const ;
|
2008-09-02 14:52:38 +08:00
|
|
|
|
|
|
|
/// Routines that handle operands which add machine relocations which are
|
2008-11-08 06:30:53 +08:00
|
|
|
/// fixed up by the relocation stage.
|
2010-04-15 09:51:59 +08:00
|
|
|
void emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
|
2009-11-07 16:51:52 +08:00
|
|
|
bool MayNeedFarStub, bool Indirect,
|
2010-10-09 01:45:54 +08:00
|
|
|
intptr_t ACPV = 0) const;
|
|
|
|
void emitExternalSymbolAddress(const char *ES, unsigned Reloc) const;
|
|
|
|
void emitConstPoolAddress(unsigned CPI, unsigned Reloc) const;
|
|
|
|
void emitJumpTableAddress(unsigned JTIndex, unsigned Reloc) const;
|
2008-11-08 06:30:53 +08:00
|
|
|
void emitMachineBasicBlock(MachineBasicBlock *BB, unsigned Reloc,
|
2010-10-09 01:45:54 +08:00
|
|
|
intptr_t JTBase = 0) const;
|
2007-07-06 05:15:40 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
char ARMCodeEmitter::ID = 0;
|
|
|
|
|
2010-03-18 05:16:45 +08:00
|
|
|
/// createARMJITCodeEmitterPass - Return a pass that emits the collected ARM
|
2010-02-03 05:38:59 +08:00
|
|
|
/// code to the specified MCE object.
|
2009-07-06 13:09:34 +08:00
|
|
|
FunctionPass *llvm::createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM,
|
|
|
|
JITCodeEmitter &JCE) {
|
2010-02-03 05:48:51 +08:00
|
|
|
return new ARMCodeEmitter(TM, JCE);
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|
2009-05-31 04:51:52 +08:00
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
bool ARMCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
|
2007-07-06 05:15:40 +08:00
|
|
|
assert((MF.getTarget().getRelocationModel() != Reloc::Default ||
|
|
|
|
MF.getTarget().getRelocationModel() != Reloc::Static) &&
|
|
|
|
"JIT relocation model must be set to static or default!");
|
2010-04-18 01:42:52 +08:00
|
|
|
JTI = ((ARMTargetMachine &)MF.getTarget()).getJITInfo();
|
|
|
|
II = ((const ARMTargetMachine &)MF.getTarget()).getInstrInfo();
|
|
|
|
TD = ((const ARMTargetMachine &)MF.getTarget()).getTargetData();
|
2009-09-10 09:23:53 +08:00
|
|
|
Subtarget = &TM.getSubtarget<ARMSubtarget>();
|
2008-11-01 03:55:13 +08:00
|
|
|
MCPEs = &MF.getConstantPool()->getConstants();
|
2010-01-26 07:22:00 +08:00
|
|
|
MJTEs = 0;
|
|
|
|
if (MF.getJumpTableInfo()) MJTEs = &MF.getJumpTableInfo()->getJumpTables();
|
2008-11-07 17:06:08 +08:00
|
|
|
IsPIC = TM.getRelocationModel() == Reloc::PIC_;
|
2010-06-29 06:23:17 +08:00
|
|
|
IsThumb = MF.getInfo<ARMFunctionInfo>()->isThumbFunction();
|
2008-11-08 15:38:22 +08:00
|
|
|
JTI->Initialize(MF, IsPIC);
|
2010-03-14 09:41:15 +08:00
|
|
|
MMI = &getAnalysis<MachineModuleInfo>();
|
|
|
|
MCE.setModuleInfo(MMI);
|
2007-07-06 05:15:40 +08:00
|
|
|
|
|
|
|
do {
|
2009-08-11 23:33:49 +08:00
|
|
|
DEBUG(errs() << "JITTing function '"
|
2009-07-25 08:23:56 +08:00
|
|
|
<< MF.getFunction()->getName() << "'\n");
|
2007-07-06 05:15:40 +08:00
|
|
|
MCE.startFunction(MF);
|
2009-08-11 23:33:49 +08:00
|
|
|
for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
|
2007-07-06 05:15:40 +08:00
|
|
|
MBB != E; ++MBB) {
|
|
|
|
MCE.StartMachineBasicBlock(MBB);
|
|
|
|
for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end();
|
|
|
|
I != E; ++I)
|
|
|
|
emitInstruction(*I);
|
|
|
|
}
|
|
|
|
} while (MCE.finishFunction(MF));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
/// getShiftOp - Return the shift opcode (bit[6:5]) of the immediate value.
|
2008-09-02 14:52:38 +08:00
|
|
|
///
|
2010-02-03 05:48:51 +08:00
|
|
|
unsigned ARMCodeEmitter::getShiftOp(unsigned Imm) const {
|
2008-11-06 07:22:34 +08:00
|
|
|
switch (ARM_AM::getAM2ShiftOpc(Imm)) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Unknown shift opc!");
|
2008-09-02 14:52:38 +08:00
|
|
|
case ARM_AM::asr: return 2;
|
|
|
|
case ARM_AM::lsl: return 0;
|
|
|
|
case ARM_AM::lsr: return 1;
|
2007-08-07 09:37:15 +08:00
|
|
|
case ARM_AM::ror:
|
2008-09-02 14:52:38 +08:00
|
|
|
case ARM_AM::rrx: return 3;
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
2008-09-02 14:52:38 +08:00
|
|
|
return 0;
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
2010-05-26 08:02:28 +08:00
|
|
|
/// getMovi32Value - Return binary encoding of operand for movw/movt. If the
|
2010-05-25 16:42:45 +08:00
|
|
|
/// machine operand requires relocation, record the relocation and return zero.
|
|
|
|
unsigned ARMCodeEmitter::getMovi32Value(const MachineInstr &MI,
|
2010-05-26 08:02:28 +08:00
|
|
|
const MachineOperand &MO,
|
2010-05-25 16:42:45 +08:00
|
|
|
unsigned Reloc) {
|
2010-05-26 08:02:28 +08:00
|
|
|
assert(((Reloc == ARM::reloc_arm_movt) || (Reloc == ARM::reloc_arm_movw))
|
2010-05-25 16:42:45 +08:00
|
|
|
&& "Relocation to this function should be for movt or movw");
|
|
|
|
|
|
|
|
if (MO.isImm())
|
|
|
|
return static_cast<unsigned>(MO.getImm());
|
|
|
|
else if (MO.isGlobal())
|
|
|
|
emitGlobalAddress(MO.getGlobal(), Reloc, true, false);
|
|
|
|
else if (MO.isSymbol())
|
|
|
|
emitExternalSymbolAddress(MO.getSymbolName(), Reloc);
|
|
|
|
else if (MO.isMBB())
|
|
|
|
emitMachineBasicBlock(MO.getMBB(), Reloc);
|
|
|
|
else {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
errs() << MO;
|
|
|
|
#endif
|
|
|
|
llvm_unreachable("Unsupported operand type for movw/movt");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-02 14:52:38 +08:00
|
|
|
/// getMachineOpValue - Return binary encoding of operand. If the machine
|
|
|
|
/// operand requires relocation, record the relocation and return zero.
|
2010-02-03 05:48:51 +08:00
|
|
|
unsigned ARMCodeEmitter::getMachineOpValue(const MachineInstr &MI,
|
2010-10-09 01:45:54 +08:00
|
|
|
const MachineOperand &MO) const {
|
2008-10-03 23:45:36 +08:00
|
|
|
if (MO.isReg())
|
2010-09-16 04:26:25 +08:00
|
|
|
return getARMRegisterNumbering(MO.getReg());
|
2008-10-03 23:45:36 +08:00
|
|
|
else if (MO.isImm())
|
2008-09-02 14:52:38 +08:00
|
|
|
return static_cast<unsigned>(MO.getImm());
|
2008-10-03 23:45:36 +08:00
|
|
|
else if (MO.isGlobal())
|
2009-09-10 09:23:53 +08:00
|
|
|
emitGlobalAddress(MO.getGlobal(), ARM::reloc_arm_branch, true, false);
|
2008-10-03 23:45:36 +08:00
|
|
|
else if (MO.isSymbol())
|
2008-11-08 15:22:33 +08:00
|
|
|
emitExternalSymbolAddress(MO.getSymbolName(), ARM::reloc_arm_branch);
|
2008-11-12 09:02:24 +08:00
|
|
|
else if (MO.isCPI()) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-12 09:02:24 +08:00
|
|
|
// For VFP load, the immediate offset is multiplied by 4.
|
2011-06-29 03:10:37 +08:00
|
|
|
unsigned Reloc = ((MCID.TSFlags & ARMII::FormMask) == ARMII::VFPLdStFrm)
|
2008-11-12 09:02:24 +08:00
|
|
|
? ARM::reloc_arm_vfp_cp_entry : ARM::reloc_arm_cp_entry;
|
|
|
|
emitConstPoolAddress(MO.getIndex(), Reloc);
|
|
|
|
} else if (MO.isJTI())
|
2007-12-31 07:10:15 +08:00
|
|
|
emitJumpTableAddress(MO.getIndex(), ARM::reloc_arm_relative);
|
2008-10-03 23:45:36 +08:00
|
|
|
else if (MO.isMBB())
|
2008-11-07 17:06:08 +08:00
|
|
|
emitMachineBasicBlock(MO.getMBB(), ARM::reloc_arm_branch);
|
2010-11-19 08:27:09 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("Unable to encode MachineOperand!");
|
2008-09-02 14:52:38 +08:00
|
|
|
return 0;
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
2008-09-18 15:28:19 +08:00
|
|
|
/// emitGlobalAddress - Emit the specified address to the code stream.
|
2007-08-07 09:37:15 +08:00
|
|
|
///
|
2010-04-15 09:51:59 +08:00
|
|
|
void ARMCodeEmitter::emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
|
2010-02-03 05:48:51 +08:00
|
|
|
bool MayNeedFarStub, bool Indirect,
|
2010-10-09 01:45:54 +08:00
|
|
|
intptr_t ACPV) const {
|
2009-09-10 09:23:53 +08:00
|
|
|
MachineRelocation MR = Indirect
|
|
|
|
? MachineRelocation::getIndirectSymbol(MCE.getCurrentPCOffset(), Reloc,
|
2010-04-15 09:51:59 +08:00
|
|
|
const_cast<GlobalValue *>(GV),
|
|
|
|
ACPV, MayNeedFarStub)
|
2009-09-10 09:23:53 +08:00
|
|
|
: MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
|
2010-04-15 09:51:59 +08:00
|
|
|
const_cast<GlobalValue *>(GV), ACPV,
|
|
|
|
MayNeedFarStub);
|
2009-09-10 09:23:53 +08:00
|
|
|
MCE.addRelocation(MR);
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// emitExternalSymbolAddress - Arrange for the address of an external symbol to
|
|
|
|
/// be emitted to the current location in the function, and allow it to be PC
|
|
|
|
/// relative.
|
2010-10-09 01:45:54 +08:00
|
|
|
void ARMCodeEmitter::
|
|
|
|
emitExternalSymbolAddress(const char *ES, unsigned Reloc) const {
|
2007-08-07 09:37:15 +08:00
|
|
|
MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
|
|
|
|
Reloc, ES));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// emitConstPoolAddress - Arrange for the address of an constant pool
|
|
|
|
/// to be emitted to the current location in the function, and allow it to be PC
|
|
|
|
/// relative.
|
2010-10-09 01:45:54 +08:00
|
|
|
void ARMCodeEmitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc) const {
|
2008-10-30 07:55:43 +08:00
|
|
|
// Tell JIT emitter we'll resolve the address.
|
2007-08-07 09:37:15 +08:00
|
|
|
MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
|
2008-11-08 06:30:53 +08:00
|
|
|
Reloc, CPI, 0, true));
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// emitJumpTableAddress - Arrange for the address of a jump table to
|
|
|
|
/// be emitted to the current location in the function, and allow it to be PC
|
|
|
|
/// relative.
|
2010-10-09 01:45:54 +08:00
|
|
|
void ARMCodeEmitter::
|
|
|
|
emitJumpTableAddress(unsigned JTIndex, unsigned Reloc) const {
|
2007-08-07 09:37:15 +08:00
|
|
|
MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
|
2008-11-08 06:30:53 +08:00
|
|
|
Reloc, JTIndex, 0, true));
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
2007-08-31 07:29:26 +08:00
|
|
|
/// emitMachineBasicBlock - Emit the specified address basic block.
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitMachineBasicBlock(MachineBasicBlock *BB,
|
2010-10-09 01:45:54 +08:00
|
|
|
unsigned Reloc,
|
|
|
|
intptr_t JTBase) const {
|
2007-08-31 07:29:26 +08:00
|
|
|
MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
|
2008-11-08 06:30:53 +08:00
|
|
|
Reloc, BB, JTBase));
|
2007-08-31 07:29:26 +08:00
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitWordLE(unsigned Binary) {
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << " 0x";
|
|
|
|
errs().write_hex(Binary) << "\n");
|
2008-11-06 07:22:34 +08:00
|
|
|
MCE.emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitDWordLE(uint64_t Binary) {
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << " 0x";
|
|
|
|
errs().write_hex(Binary) << "\n");
|
2008-11-12 06:19:31 +08:00
|
|
|
MCE.emitDWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitInstruction(const MachineInstr &MI) {
|
2009-08-23 11:41:05 +08:00
|
|
|
DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI);
|
2008-09-13 09:15:21 +08:00
|
|
|
|
2009-10-06 10:19:11 +08:00
|
|
|
MCE.processDebugLoc(MI.getDebugLoc(), true);
|
2009-07-18 02:49:39 +08:00
|
|
|
|
2010-06-22 23:08:57 +08:00
|
|
|
++NumEmitted; // Keep track of the # of mi's emitted
|
2008-11-06 02:35:52 +08:00
|
|
|
switch (MI.getDesc().TSFlags & ARMII::FormMask) {
|
2008-11-14 07:36:57 +08:00
|
|
|
default: {
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("Unhandled instruction encoding format!");
|
2008-11-06 02:35:52 +08:00
|
|
|
break;
|
2008-11-14 07:36:57 +08:00
|
|
|
}
|
2010-11-18 07:33:14 +08:00
|
|
|
case ARMII::MiscFrm:
|
|
|
|
if (MI.getOpcode() == ARM::LEApcrelJT) {
|
|
|
|
// Materialize jumptable address.
|
|
|
|
emitLEApcrelJTInstruction(MI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unhandled instruction encoding!");
|
|
|
|
break;
|
2008-11-06 02:35:52 +08:00
|
|
|
case ARMII::Pseudo:
|
2008-09-18 15:28:19 +08:00
|
|
|
emitPseudoInstruction(MI);
|
2008-11-06 02:35:52 +08:00
|
|
|
break;
|
|
|
|
case ARMII::DPFrm:
|
|
|
|
case ARMII::DPSoRegFrm:
|
|
|
|
emitDataProcessingInstruction(MI);
|
|
|
|
break;
|
2008-11-13 15:34:59 +08:00
|
|
|
case ARMII::LdFrm:
|
|
|
|
case ARMII::StFrm:
|
2008-11-06 02:35:52 +08:00
|
|
|
emitLoadStoreInstruction(MI);
|
|
|
|
break;
|
2008-11-13 15:34:59 +08:00
|
|
|
case ARMII::LdMiscFrm:
|
|
|
|
case ARMII::StMiscFrm:
|
2008-11-06 02:35:52 +08:00
|
|
|
emitMiscLoadStoreInstruction(MI);
|
|
|
|
break;
|
2008-11-12 15:18:38 +08:00
|
|
|
case ARMII::LdStMulFrm:
|
2008-11-06 02:35:52 +08:00
|
|
|
emitLoadStoreMultipleInstruction(MI);
|
|
|
|
break;
|
2008-11-06 09:21:28 +08:00
|
|
|
case ARMII::MulFrm:
|
|
|
|
emitMulFrmInstruction(MI);
|
2008-11-06 02:35:52 +08:00
|
|
|
break;
|
2008-11-07 06:15:19 +08:00
|
|
|
case ARMII::ExtFrm:
|
|
|
|
emitExtendInstruction(MI);
|
|
|
|
break;
|
2008-11-07 09:41:35 +08:00
|
|
|
case ARMII::ArithMiscFrm:
|
|
|
|
emitMiscArithInstruction(MI);
|
|
|
|
break;
|
2010-08-11 08:01:18 +08:00
|
|
|
case ARMII::SatFrm:
|
|
|
|
emitSaturateInstruction(MI);
|
|
|
|
break;
|
2008-11-07 01:48:05 +08:00
|
|
|
case ARMII::BrFrm:
|
2008-11-06 02:35:52 +08:00
|
|
|
emitBranchInstruction(MI);
|
|
|
|
break;
|
2008-11-07 01:48:05 +08:00
|
|
|
case ARMII::BrMiscFrm:
|
2008-11-06 02:35:52 +08:00
|
|
|
emitMiscBranchInstruction(MI);
|
|
|
|
break;
|
2008-11-11 10:11:05 +08:00
|
|
|
// VFP instructions.
|
|
|
|
case ARMII::VFPUnaryFrm:
|
|
|
|
case ARMII::VFPBinaryFrm:
|
|
|
|
emitVFPArithInstruction(MI);
|
|
|
|
break;
|
2008-11-12 03:40:26 +08:00
|
|
|
case ARMII::VFPConv1Frm:
|
|
|
|
case ARMII::VFPConv2Frm:
|
2008-11-12 06:46:12 +08:00
|
|
|
case ARMII::VFPConv3Frm:
|
2008-11-12 14:41:41 +08:00
|
|
|
case ARMII::VFPConv4Frm:
|
|
|
|
case ARMII::VFPConv5Frm:
|
2008-11-12 03:40:26 +08:00
|
|
|
emitVFPConversionInstruction(MI);
|
|
|
|
break;
|
2008-11-12 05:48:44 +08:00
|
|
|
case ARMII::VFPLdStFrm:
|
|
|
|
emitVFPLoadStoreInstruction(MI);
|
|
|
|
break;
|
|
|
|
case ARMII::VFPLdStMulFrm:
|
|
|
|
emitVFPLoadStoreMultipleInstruction(MI);
|
|
|
|
break;
|
2010-10-16 07:35:12 +08:00
|
|
|
|
2010-06-12 05:34:50 +08:00
|
|
|
// NEON instructions.
|
2010-06-26 12:07:15 +08:00
|
|
|
case ARMII::NGetLnFrm:
|
2010-06-30 01:34:07 +08:00
|
|
|
case ARMII::NSetLnFrm:
|
|
|
|
emitNEONLaneInstruction(MI);
|
2010-06-26 12:07:15 +08:00
|
|
|
break;
|
2010-06-30 04:13:29 +08:00
|
|
|
case ARMII::NDupFrm:
|
|
|
|
emitNEONDupInstruction(MI);
|
|
|
|
break;
|
2010-06-12 05:34:50 +08:00
|
|
|
case ARMII::N1RegModImmFrm:
|
2010-06-26 05:17:19 +08:00
|
|
|
emitNEON1RegModImmInstruction(MI);
|
|
|
|
break;
|
|
|
|
case ARMII::N2RegFrm:
|
|
|
|
emitNEON2RegInstruction(MI);
|
2010-06-12 05:34:50 +08:00
|
|
|
break;
|
2010-06-26 06:40:46 +08:00
|
|
|
case ARMII::N3RegFrm:
|
|
|
|
emitNEON3RegInstruction(MI);
|
|
|
|
break;
|
2008-11-06 02:35:52 +08:00
|
|
|
}
|
2009-10-06 10:19:11 +08:00
|
|
|
MCE.processDebugLoc(MI.getDebugLoc(), false);
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitConstPoolInstruction(const MachineInstr &MI) {
|
2008-11-08 06:30:53 +08:00
|
|
|
unsigned CPI = MI.getOperand(0).getImm(); // CP instruction index.
|
|
|
|
unsigned CPIndex = MI.getOperand(1).getIndex(); // Actual cp entry index.
|
2008-11-01 03:55:13 +08:00
|
|
|
const MachineConstantPoolEntry &MCPE = (*MCPEs)[CPIndex];
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2008-11-01 03:10:44 +08:00
|
|
|
// Remember the CONSTPOOL_ENTRY address for later relocation.
|
|
|
|
JTI->addConstantPoolEntryAddr(CPI, MCE.getCurrentPCValue());
|
|
|
|
|
|
|
|
// Emit constpool island entry. In most cases, the actual values will be
|
|
|
|
// resolved and relocated after code emission.
|
|
|
|
if (MCPE.isMachineConstantPoolEntry()) {
|
|
|
|
ARMConstantPoolValue *ACPV =
|
|
|
|
static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal);
|
|
|
|
|
2009-08-23 11:41:05 +08:00
|
|
|
DEBUG(errs() << " ** ARM constant pool #" << CPI << " @ "
|
|
|
|
<< (void*)MCE.getCurrentPCValue() << " " << *ACPV << '\n');
|
2008-11-01 03:10:44 +08:00
|
|
|
|
2009-11-03 00:59:06 +08:00
|
|
|
assert(ACPV->isGlobalValue() && "unsupported constant pool value");
|
2010-04-15 09:51:59 +08:00
|
|
|
const GlobalValue *GV = ACPV->getGV();
|
2008-11-01 03:10:44 +08:00
|
|
|
if (GV) {
|
2009-09-10 09:23:53 +08:00
|
|
|
Reloc::Model RelocM = TM.getRelocationModel();
|
2009-08-29 07:18:09 +08:00
|
|
|
emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
|
2009-09-10 09:23:53 +08:00
|
|
|
isa<Function>(GV),
|
|
|
|
Subtarget->GVIsIndirectSymbol(GV, RelocM),
|
|
|
|
(intptr_t)ACPV);
|
2008-11-04 08:50:32 +08:00
|
|
|
} else {
|
2008-11-01 03:10:44 +08:00
|
|
|
emitExternalSymbolAddress(ACPV->getSymbol(), ARM::reloc_arm_absolute);
|
|
|
|
}
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(0);
|
2008-11-01 03:10:44 +08:00
|
|
|
} else {
|
2010-04-15 09:51:59 +08:00
|
|
|
const Constant *CV = MCPE.Val.ConstVal;
|
2008-11-01 03:10:44 +08:00
|
|
|
|
2009-07-25 08:23:56 +08:00
|
|
|
DEBUG({
|
|
|
|
errs() << " ** Constant pool #" << CPI << " @ "
|
|
|
|
<< (void*)MCE.getCurrentPCValue() << " ";
|
|
|
|
if (const Function *F = dyn_cast<Function>(CV))
|
|
|
|
errs() << F->getName();
|
|
|
|
else
|
|
|
|
errs() << *CV;
|
|
|
|
errs() << '\n';
|
|
|
|
});
|
2008-11-01 03:10:44 +08:00
|
|
|
|
2010-04-15 09:51:59 +08:00
|
|
|
if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
|
2009-09-10 09:23:53 +08:00
|
|
|
emitGlobalAddress(GV, ARM::reloc_arm_absolute, isa<Function>(GV), false);
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(0);
|
2008-11-12 06:19:31 +08:00
|
|
|
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
2010-10-23 07:16:11 +08:00
|
|
|
uint32_t Val = uint32_t(*CI->getValue().getRawData());
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Val);
|
2008-11-12 06:19:31 +08:00
|
|
|
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
|
2009-10-05 13:54:46 +08:00
|
|
|
if (CFP->getType()->isFloatTy())
|
2008-11-12 06:19:31 +08:00
|
|
|
emitWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
|
2009-10-05 13:54:46 +08:00
|
|
|
else if (CFP->getType()->isDoubleTy())
|
2008-11-12 06:19:31 +08:00
|
|
|
emitDWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
|
|
|
|
else {
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("Unable to handle this constantpool entry!");
|
2008-11-12 06:19:31 +08:00
|
|
|
}
|
|
|
|
} else {
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("Unable to handle this constantpool entry!");
|
2008-11-01 03:10:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 16:42:45 +08:00
|
|
|
void ARMCodeEmitter::emitMOVi32immInstruction(const MachineInstr &MI) {
|
|
|
|
const MachineOperand &MO0 = MI.getOperand(0);
|
|
|
|
const MachineOperand &MO1 = MI.getOperand(1);
|
|
|
|
|
|
|
|
// Emit the 'movw' instruction.
|
|
|
|
unsigned Binary = 0x30 << 20; // mov: Insts{27-20} = 0b00110000
|
|
|
|
|
|
|
|
unsigned Lo16 = getMovi32Value(MI, MO1, ARM::reloc_arm_movw) & 0xFFFF;
|
|
|
|
|
|
|
|
// Set the conditional execution predicate.
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
// Encode Rd.
|
|
|
|
Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
// Encode imm16 as imm4:imm12
|
|
|
|
Binary |= Lo16 & 0xFFF; // Insts{11-0} = imm12
|
|
|
|
Binary |= ((Lo16 >> 12) & 0xF) << 16; // Insts{19-16} = imm4
|
|
|
|
emitWordLE(Binary);
|
|
|
|
|
|
|
|
unsigned Hi16 = getMovi32Value(MI, MO1, ARM::reloc_arm_movt) >> 16;
|
|
|
|
// Emit the 'movt' instruction.
|
|
|
|
Binary = 0x34 << 20; // movt: Insts{27-20} = 0b00110100
|
|
|
|
|
|
|
|
// Set the conditional execution predicate.
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
// Encode Rd.
|
|
|
|
Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
// Encode imm16 as imm4:imm1, same as movw above.
|
|
|
|
Binary |= Hi16 & 0xFFF;
|
|
|
|
Binary |= ((Hi16 >> 12) & 0xF) << 16;
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitMOVi2piecesInstruction(const MachineInstr &MI) {
|
2008-11-06 10:25:39 +08:00
|
|
|
const MachineOperand &MO0 = MI.getOperand(0);
|
|
|
|
const MachineOperand &MO1 = MI.getOperand(1);
|
2010-03-11 08:46:22 +08:00
|
|
|
assert(MO1.isImm() && ARM_AM::isSOImmTwoPartVal(MO1.getImm()) &&
|
|
|
|
"Not a valid so_imm value!");
|
2008-11-06 10:25:39 +08:00
|
|
|
unsigned V1 = ARM_AM::getSOImmTwoPartFirst(MO1.getImm());
|
|
|
|
unsigned V2 = ARM_AM::getSOImmTwoPartSecond(MO1.getImm());
|
|
|
|
|
|
|
|
// Emit the 'mov' instruction.
|
|
|
|
unsigned Binary = 0xd << 21; // mov: Insts{24-21} = 0b1101
|
|
|
|
|
|
|
|
// Set the conditional execution predicate.
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2008-11-06 10:25:39 +08:00
|
|
|
|
|
|
|
// Encode Rd.
|
|
|
|
Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
// Encode so_imm.
|
|
|
|
// Set bit I(25) to identify this is the immediate form of <shifter_op>
|
|
|
|
Binary |= 1 << ARMII::I_BitShift;
|
2009-07-09 05:03:57 +08:00
|
|
|
Binary |= getMachineSoImmOpValue(V1);
|
2008-11-06 10:25:39 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
|
|
|
|
// Now the 'orr' instruction.
|
|
|
|
Binary = 0xc << 21; // orr: Insts{24-21} = 0b1100
|
|
|
|
|
|
|
|
// Set the conditional execution predicate.
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2008-11-06 10:25:39 +08:00
|
|
|
|
|
|
|
// Encode Rd.
|
|
|
|
Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
// Encode Rn.
|
|
|
|
Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRnShift;
|
|
|
|
|
|
|
|
// Encode so_imm.
|
|
|
|
// Set bit I(25) to identify this is the immediate form of <shifter_op>
|
|
|
|
Binary |= 1 << ARMII::I_BitShift;
|
2009-07-09 05:03:57 +08:00
|
|
|
Binary |= getMachineSoImmOpValue(V2);
|
2008-11-06 10:25:39 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitLEApcrelJTInstruction(const MachineInstr &MI) {
|
2008-11-07 17:06:08 +08:00
|
|
|
// It's basically add r, pc, (LJTI - $+8)
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-07 17:06:08 +08:00
|
|
|
|
|
|
|
// Emit the 'add' instruction.
|
2010-11-18 05:57:51 +08:00
|
|
|
unsigned Binary = 0x4 << 21; // add: Insts{24-21} = 0b0100
|
2008-11-07 17:06:08 +08:00
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
// Encode S bit if MI modifies CPSR.
|
2011-06-29 03:10:37 +08:00
|
|
|
Binary |= getAddrModeSBit(MI, MCID);
|
2008-11-07 17:06:08 +08:00
|
|
|
|
|
|
|
// Encode Rd.
|
|
|
|
Binary |= getMachineOpValue(MI, 0) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
// Encode Rn which is PC.
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= getARMRegisterNumbering(ARM::PC) << ARMII::RegRnShift;
|
2008-11-07 17:06:08 +08:00
|
|
|
|
|
|
|
// Encode the displacement.
|
|
|
|
Binary |= 1 << ARMII::I_BitShift;
|
|
|
|
emitJumpTableAddress(MI.getOperand(1).getIndex(), ARM::reloc_arm_jt_base);
|
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitPseudoMoveInstruction(const MachineInstr &MI) {
|
2008-11-15 04:09:11 +08:00
|
|
|
unsigned Opcode = MI.getDesc().Opcode;
|
|
|
|
|
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
// Encode S bit if MI modifies CPSR.
|
|
|
|
if (Opcode == ARM::MOVsrl_flag || Opcode == ARM::MOVsra_flag)
|
|
|
|
Binary |= 1 << ARMII::S_BitShift;
|
|
|
|
|
|
|
|
// Encode register def if there is one.
|
|
|
|
Binary |= getMachineOpValue(MI, 0) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
// Encode the shift operation.
|
|
|
|
switch (Opcode) {
|
|
|
|
default: break;
|
2010-10-15 04:43:44 +08:00
|
|
|
case ARM::RRX:
|
2008-11-15 04:09:11 +08:00
|
|
|
// rrx
|
|
|
|
Binary |= 0x6 << 4;
|
|
|
|
break;
|
|
|
|
case ARM::MOVsrl_flag:
|
|
|
|
// lsr #1
|
|
|
|
Binary |= (0x2 << 4) | (1 << 7);
|
|
|
|
break;
|
|
|
|
case ARM::MOVsra_flag:
|
|
|
|
// asr #1
|
|
|
|
Binary |= (0x4 << 4) | (1 << 7);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode register Rm.
|
|
|
|
Binary |= getMachineOpValue(MI, 1);
|
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::addPCLabel(unsigned LabelID) {
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << " ** LPC" << LabelID << " @ "
|
|
|
|
<< (void*)MCE.getCurrentPCValue() << '\n');
|
2008-11-06 07:22:34 +08:00
|
|
|
JTI->addPCLabelAddr(LabelID, MCE.getCurrentPCValue());
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitPseudoInstruction(const MachineInstr &MI) {
|
2008-11-01 03:10:44 +08:00
|
|
|
unsigned Opcode = MI.getDesc().Opcode;
|
|
|
|
switch (Opcode) {
|
|
|
|
default:
|
2009-09-28 17:14:39 +08:00
|
|
|
llvm_unreachable("ARMCodeEmitter::emitPseudoInstruction");
|
2010-11-30 08:24:05 +08:00
|
|
|
case ARM::BX_CALL:
|
|
|
|
case ARM::BMOVPCRX_CALL:
|
|
|
|
case ARM::BXr9_CALL:
|
|
|
|
case ARM::BMOVPCRXr9_CALL: {
|
2010-07-23 01:28:34 +08:00
|
|
|
// First emit mov lr, pc
|
|
|
|
unsigned Binary = 0x01a0e00f;
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
emitWordLE(Binary);
|
|
|
|
|
|
|
|
// and then emit the branch.
|
|
|
|
emitMiscBranchInstruction(MI);
|
|
|
|
break;
|
|
|
|
}
|
2010-02-10 03:54:29 +08:00
|
|
|
case TargetOpcode::INLINEASM: {
|
2008-11-20 07:21:33 +08:00
|
|
|
// We allow inline assembler nodes with empty bodies - they can
|
|
|
|
// implicitly define registers, which is ok for JIT.
|
|
|
|
if (MI.getOperand(0).getSymbolName()[0]) {
|
2010-04-08 06:58:41 +08:00
|
|
|
report_fatal_error("JIT does not support inline asm!");
|
2008-11-20 07:21:33 +08:00
|
|
|
}
|
2008-11-14 07:36:57 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-07-17 06:20:36 +08:00
|
|
|
case TargetOpcode::PROLOG_LABEL:
|
2010-03-14 10:33:54 +08:00
|
|
|
case TargetOpcode::EH_LABEL:
|
|
|
|
MCE.emitLabel(MI.getOperand(0).getMCSymbol());
|
|
|
|
break;
|
2010-02-10 03:54:29 +08:00
|
|
|
case TargetOpcode::IMPLICIT_DEF:
|
|
|
|
case TargetOpcode::KILL:
|
2008-11-14 07:36:57 +08:00
|
|
|
// Do nothing.
|
|
|
|
break;
|
2008-11-01 03:10:44 +08:00
|
|
|
case ARM::CONSTPOOL_ENTRY:
|
|
|
|
emitConstPoolInstruction(MI);
|
|
|
|
break;
|
|
|
|
case ARM::PICADD: {
|
2008-11-04 08:50:32 +08:00
|
|
|
// Remember of the address of the PC label for relocation later.
|
2008-11-06 07:22:34 +08:00
|
|
|
addPCLabel(MI.getOperand(2).getImm());
|
2008-11-01 03:10:44 +08:00
|
|
|
// PICADD is just an add instruction that implicitly read pc.
|
2008-11-08 06:30:53 +08:00
|
|
|
emitDataProcessingInstruction(MI, 0, ARM::PC);
|
2008-11-06 07:22:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARM::PICLDR:
|
|
|
|
case ARM::PICLDRB:
|
|
|
|
case ARM::PICSTR:
|
|
|
|
case ARM::PICSTRB: {
|
|
|
|
// Remember of the address of the PC label for relocation later.
|
|
|
|
addPCLabel(MI.getOperand(2).getImm());
|
|
|
|
// These are just load / store instructions that implicitly read pc.
|
2008-11-07 17:06:08 +08:00
|
|
|
emitLoadStoreInstruction(MI, 0, ARM::PC);
|
2008-11-06 07:22:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARM::PICLDRH:
|
|
|
|
case ARM::PICLDRSH:
|
|
|
|
case ARM::PICLDRSB:
|
|
|
|
case ARM::PICSTRH: {
|
|
|
|
// Remember of the address of the PC label for relocation later.
|
|
|
|
addPCLabel(MI.getOperand(2).getImm());
|
|
|
|
// These are just load / store instructions that implicitly read pc.
|
|
|
|
emitMiscLoadStoreInstruction(MI, ARM::PC);
|
2008-11-01 03:10:44 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-05-25 16:42:45 +08:00
|
|
|
|
|
|
|
case ARM::MOVi32imm:
|
2008-11-06 10:25:39 +08:00
|
|
|
// Two instructions to materialize a constant.
|
2010-11-13 07:03:38 +08:00
|
|
|
if (Subtarget->hasV6T2Ops())
|
|
|
|
emitMOVi32immInstruction(MI);
|
|
|
|
else
|
|
|
|
emitMOVi2piecesInstruction(MI);
|
2008-11-06 10:25:39 +08:00
|
|
|
break;
|
2010-11-13 07:03:38 +08:00
|
|
|
|
2008-11-07 17:06:08 +08:00
|
|
|
case ARM::LEApcrelJT:
|
|
|
|
// Materialize jumptable address.
|
|
|
|
emitLEApcrelJTInstruction(MI);
|
|
|
|
break;
|
2010-10-15 04:43:44 +08:00
|
|
|
case ARM::RRX:
|
2008-11-15 04:09:11 +08:00
|
|
|
case ARM::MOVsrl_flag:
|
|
|
|
case ARM::MOVsra_flag:
|
|
|
|
emitPseudoMoveInstruction(MI);
|
|
|
|
break;
|
2008-11-01 03:10:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 05:16:45 +08:00
|
|
|
unsigned ARMCodeEmitter::getMachineSoRegOpValue(const MachineInstr &MI,
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID,
|
2008-11-01 03:10:44 +08:00
|
|
|
const MachineOperand &MO,
|
2008-09-13 06:01:15 +08:00
|
|
|
unsigned OpIdx) {
|
2008-11-01 03:10:44 +08:00
|
|
|
unsigned Binary = getMachineOpValue(MI, MO);
|
2008-09-13 06:01:15 +08:00
|
|
|
|
|
|
|
const MachineOperand &MO1 = MI.getOperand(OpIdx + 1);
|
|
|
|
const MachineOperand &MO2 = MI.getOperand(OpIdx + 2);
|
|
|
|
ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(MO2.getImm());
|
|
|
|
|
|
|
|
// Encode the shift opcode.
|
|
|
|
unsigned SBits = 0;
|
|
|
|
unsigned Rs = MO1.getReg();
|
|
|
|
if (Rs) {
|
|
|
|
// Set shift operand (bit[7:4]).
|
|
|
|
// LSL - 0001
|
|
|
|
// LSR - 0011
|
|
|
|
// ASR - 0101
|
|
|
|
// ROR - 0111
|
|
|
|
// RRX - 0110 and bit[11:8] clear.
|
|
|
|
switch (SOpc) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Unknown shift opc!");
|
2008-09-13 06:01:15 +08:00
|
|
|
case ARM_AM::lsl: SBits = 0x1; break;
|
|
|
|
case ARM_AM::lsr: SBits = 0x3; break;
|
|
|
|
case ARM_AM::asr: SBits = 0x5; break;
|
|
|
|
case ARM_AM::ror: SBits = 0x7; break;
|
|
|
|
case ARM_AM::rrx: SBits = 0x6; break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Set shift operand (bit[6:4]).
|
|
|
|
// LSL - 000
|
|
|
|
// LSR - 010
|
|
|
|
// ASR - 100
|
|
|
|
// ROR - 110
|
|
|
|
switch (SOpc) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Unknown shift opc!");
|
2008-09-13 06:01:15 +08:00
|
|
|
case ARM_AM::lsl: SBits = 0x0; break;
|
|
|
|
case ARM_AM::lsr: SBits = 0x2; break;
|
|
|
|
case ARM_AM::asr: SBits = 0x4; break;
|
|
|
|
case ARM_AM::ror: SBits = 0x6; break;
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-13 06:01:15 +08:00
|
|
|
Binary |= SBits << 4;
|
|
|
|
if (SOpc == ARM_AM::rrx)
|
|
|
|
return Binary;
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2008-09-13 06:01:15 +08:00
|
|
|
// Encode the shift operation Rs or shift_imm (except rrx).
|
|
|
|
if (Rs) {
|
|
|
|
// Encode Rs bit[11:8].
|
|
|
|
assert(ARM_AM::getSORegOffset(MO2.getImm()) == 0);
|
2010-09-16 04:26:25 +08:00
|
|
|
return Binary | (getARMRegisterNumbering(Rs) << ARMII::RegRsShift);
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2008-09-13 06:01:15 +08:00
|
|
|
// Encode shift_imm bit[11:7].
|
|
|
|
return Binary | ARM_AM::getSORegOffset(MO2.getImm()) << 7;
|
|
|
|
}
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
unsigned ARMCodeEmitter::getMachineSoImmOpValue(unsigned SoImm) {
|
2009-07-09 05:03:57 +08:00
|
|
|
int SoImmVal = ARM_AM::getSOImmVal(SoImm);
|
|
|
|
assert(SoImmVal != -1 && "Not a valid so_imm value!");
|
|
|
|
|
2008-11-01 03:10:44 +08:00
|
|
|
// Encode rotate_imm.
|
2009-07-09 05:03:57 +08:00
|
|
|
unsigned Binary = (ARM_AM::getSOImmValRot((unsigned)SoImmVal) >> 1)
|
2008-11-07 06:15:19 +08:00
|
|
|
<< ARMII::SoRotImmShift;
|
|
|
|
|
2008-11-01 03:10:44 +08:00
|
|
|
// Encode immed_8.
|
2009-07-09 05:03:57 +08:00
|
|
|
Binary |= ARM_AM::getSOImmValImm((unsigned)SoImmVal);
|
2008-11-01 03:10:44 +08:00
|
|
|
return Binary;
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
unsigned ARMCodeEmitter::getAddrModeSBit(const MachineInstr &MI,
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID) const {
|
|
|
|
for (unsigned i = MI.getNumOperands(), e = MCID.getNumOperands(); i >= e; --i){
|
2008-09-13 06:45:55 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(i-1);
|
2008-10-03 23:45:36 +08:00
|
|
|
if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR)
|
2008-09-13 06:45:55 +08:00
|
|
|
return 1 << ARMII::S_BitShift;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 05:16:45 +08:00
|
|
|
void ARMCodeEmitter::emitDataProcessingInstruction(const MachineInstr &MI,
|
2008-11-08 06:30:53 +08:00
|
|
|
unsigned ImplicitRd,
|
2008-11-06 07:22:34 +08:00
|
|
|
unsigned ImplicitRn) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-06 02:35:52 +08:00
|
|
|
|
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
2008-10-08 03:05:35 +08:00
|
|
|
// Set the conditional execution predicate
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2008-09-13 06:45:55 +08:00
|
|
|
// Encode S bit if MI modifies CPSR.
|
2011-06-29 03:10:37 +08:00
|
|
|
Binary |= getAddrModeSBit(MI, MCID);
|
2008-09-13 06:45:55 +08:00
|
|
|
|
2008-09-13 06:01:15 +08:00
|
|
|
// Encode register def if there is one.
|
2011-06-29 03:10:37 +08:00
|
|
|
unsigned NumDefs = MCID.getNumDefs();
|
2008-09-13 07:15:39 +08:00
|
|
|
unsigned OpIdx = 0;
|
2008-11-08 06:30:53 +08:00
|
|
|
if (NumDefs)
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
|
|
|
|
else if (ImplicitRd)
|
|
|
|
// Special handling for implicit use (e.g. PC).
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= (getARMRegisterNumbering(ImplicitRd) << ARMII::RegRdShift);
|
2008-09-13 06:01:15 +08:00
|
|
|
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::MOVi16) {
|
2010-05-25 16:42:45 +08:00
|
|
|
// Get immediate from MI.
|
|
|
|
unsigned Lo16 = getMovi32Value(MI, MI.getOperand(OpIdx),
|
|
|
|
ARM::reloc_arm_movw);
|
|
|
|
// Encode imm which is the same as in emitMOVi32immInstruction().
|
|
|
|
Binary |= Lo16 & 0xFFF;
|
|
|
|
Binary |= ((Lo16 >> 12) & 0xF) << 16;
|
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
2011-06-29 03:10:37 +08:00
|
|
|
} else if(MCID.Opcode == ARM::MOVTi16) {
|
2010-05-25 16:42:45 +08:00
|
|
|
unsigned Hi16 = (getMovi32Value(MI, MI.getOperand(OpIdx),
|
|
|
|
ARM::reloc_arm_movt) >> 16);
|
|
|
|
Binary |= Hi16 & 0xFFF;
|
|
|
|
Binary |= ((Hi16 >> 12) & 0xF) << 16;
|
2010-05-26 08:25:05 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
2011-06-29 03:10:37 +08:00
|
|
|
} else if ((MCID.Opcode == ARM::BFC) || (MCID.Opcode == ARM::BFI)) {
|
2010-05-26 08:25:05 +08:00
|
|
|
uint32_t v = ~MI.getOperand(2).getImm();
|
|
|
|
int32_t lsb = CountTrailingZeros_32(v);
|
|
|
|
int32_t msb = (32 - CountLeadingZeros_32(v)) - 1;
|
2010-05-26 11:21:39 +08:00
|
|
|
// Instr{20-16} = msb, Instr{11-7} = lsb
|
2010-05-26 08:25:05 +08:00
|
|
|
Binary |= (msb & 0x1F) << 16;
|
|
|
|
Binary |= (lsb & 0x1F) << 7;
|
2010-05-26 11:21:39 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
2011-06-29 03:10:37 +08:00
|
|
|
} else if ((MCID.Opcode == ARM::UBFX) || (MCID.Opcode == ARM::SBFX)) {
|
2010-05-26 11:21:39 +08:00
|
|
|
// Encode Rn in Instr{0-3}
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++);
|
|
|
|
|
|
|
|
uint32_t lsb = MI.getOperand(OpIdx++).getImm();
|
|
|
|
uint32_t widthm1 = MI.getOperand(OpIdx++).getImm() - 1;
|
|
|
|
|
|
|
|
// Instr{20-16} = widthm1, Instr{11-7} = lsb
|
|
|
|
Binary |= (widthm1 & 0x1F) << 16;
|
|
|
|
Binary |= (lsb & 0x1F) << 7;
|
2010-05-25 16:42:45 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-06 16:47:38 +08:00
|
|
|
// If this is a two-address operand, skip it. e.g. MOVCCr operand 1.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getOperandConstraint(OpIdx, MCOI::TIED_TO) != -1)
|
2008-11-06 16:47:38 +08:00
|
|
|
++OpIdx;
|
|
|
|
|
2008-10-02 02:16:49 +08:00
|
|
|
// Encode first non-shifter register operand if there is one.
|
2011-06-29 03:10:37 +08:00
|
|
|
bool isUnary = MCID.TSFlags & ARMII::UnaryDP;
|
2008-11-06 02:35:52 +08:00
|
|
|
if (!isUnary) {
|
2008-11-06 07:22:34 +08:00
|
|
|
if (ImplicitRn)
|
|
|
|
// Special handling for implicit use (e.g. PC).
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= (getARMRegisterNumbering(ImplicitRn) << ARMII::RegRnShift);
|
2008-11-01 03:10:44 +08:00
|
|
|
else {
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx) << ARMII::RegRnShift;
|
|
|
|
++OpIdx;
|
|
|
|
}
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2008-09-13 06:01:15 +08:00
|
|
|
// Encode shifter operand.
|
2008-11-01 03:10:44 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(OpIdx);
|
2011-06-29 03:10:37 +08:00
|
|
|
if ((MCID.TSFlags & ARMII::FormMask) == ARMII::DPSoRegFrm) {
|
2008-09-13 06:01:15 +08:00
|
|
|
// Encode SoReg.
|
2011-06-29 03:10:37 +08:00
|
|
|
emitWordLE(Binary | getMachineSoRegOpValue(MI, MCID, MO, OpIdx));
|
2008-11-06 02:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-09-13 06:01:15 +08:00
|
|
|
|
2008-11-06 02:35:52 +08:00
|
|
|
if (MO.isReg()) {
|
2008-09-13 06:01:15 +08:00
|
|
|
// Encode register Rm.
|
2010-09-16 04:26:25 +08:00
|
|
|
emitWordLE(Binary | getARMRegisterNumbering(MO.getReg()));
|
2008-11-06 02:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-09-13 06:01:15 +08:00
|
|
|
|
|
|
|
// Encode so_imm.
|
2009-07-09 05:03:57 +08:00
|
|
|
Binary |= getMachineSoImmOpValue((unsigned)MO.getImm());
|
2008-11-06 02:35:52 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2010-03-18 05:16:45 +08:00
|
|
|
void ARMCodeEmitter::emitLoadStoreInstruction(const MachineInstr &MI,
|
2008-11-07 17:06:08 +08:00
|
|
|
unsigned ImplicitRd,
|
2008-11-06 07:22:34 +08:00
|
|
|
unsigned ImplicitRn) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
unsigned Form = MCID.TSFlags & ARMII::FormMask;
|
|
|
|
bool IsPrePost = (MCID.TSFlags & ARMII::IndexModeMask) != 0;
|
2008-11-08 09:44:13 +08:00
|
|
|
|
2008-11-06 02:35:52 +08:00
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
2010-10-28 07:12:14 +08:00
|
|
|
// If this is an LDRi12, STRi12 or LDRcp, nothing more needs be done.
|
|
|
|
if (MI.getOpcode() == ARM::LDRi12 || MI.getOpcode() == ARM::LDRcp ||
|
|
|
|
MI.getOpcode() == ARM::STRi12) {
|
2010-10-28 01:52:51 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-08 03:05:35 +08:00
|
|
|
// Set the conditional execution predicate
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2008-09-18 15:28:19 +08:00
|
|
|
|
2008-11-07 17:06:08 +08:00
|
|
|
unsigned OpIdx = 0;
|
2008-11-13 15:34:59 +08:00
|
|
|
|
|
|
|
// Operand 0 of a pre- and post-indexed store is the address base
|
|
|
|
// writeback. Skip it.
|
|
|
|
bool Skipped = false;
|
|
|
|
if (IsPrePost && Form == ARMII::StFrm) {
|
|
|
|
++OpIdx;
|
|
|
|
Skipped = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set first operand
|
2008-11-07 17:06:08 +08:00
|
|
|
if (ImplicitRd)
|
|
|
|
// Special handling for implicit use (e.g. PC).
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= (getARMRegisterNumbering(ImplicitRd) << ARMII::RegRdShift);
|
2008-11-07 17:06:08 +08:00
|
|
|
else
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
|
2008-09-02 14:52:38 +08:00
|
|
|
|
|
|
|
// Set second operand
|
2008-11-06 07:22:34 +08:00
|
|
|
if (ImplicitRn)
|
|
|
|
// Special handling for implicit use (e.g. PC).
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= (getARMRegisterNumbering(ImplicitRn) << ARMII::RegRnShift);
|
2008-11-07 17:06:08 +08:00
|
|
|
else
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-11-08 09:44:13 +08:00
|
|
|
// If this is a two-address operand, skip it. e.g. LDR_PRE.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (!Skipped && MCID.getOperandConstraint(OpIdx, MCOI::TIED_TO) != -1)
|
2008-11-08 09:44:13 +08:00
|
|
|
++OpIdx;
|
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
const MachineOperand &MO2 = MI.getOperand(OpIdx);
|
2008-11-06 16:47:38 +08:00
|
|
|
unsigned AM2Opc = (ImplicitRn == ARM::PC)
|
2008-11-06 07:22:34 +08:00
|
|
|
? 0 : MI.getOperand(OpIdx+1).getImm();
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-09-13 09:44:01 +08:00
|
|
|
// Set bit U(23) according to sign of immed value (positive or negative).
|
2008-11-06 07:22:34 +08:00
|
|
|
Binary |= ((ARM_AM::getAM2Op(AM2Opc) == ARM_AM::add ? 1 : 0) <<
|
2008-09-13 09:44:01 +08:00
|
|
|
ARMII::U_BitShift);
|
2008-09-02 14:52:38 +08:00
|
|
|
if (!MO2.getReg()) { // is immediate
|
2008-11-06 07:22:34 +08:00
|
|
|
if (ARM_AM::getAM2Offset(AM2Opc))
|
2008-09-02 14:52:38 +08:00
|
|
|
// Set the value of offset_12 field
|
2008-11-06 07:22:34 +08:00
|
|
|
Binary |= ARM_AM::getAM2Offset(AM2Opc);
|
|
|
|
emitWordLE(Binary);
|
2008-11-06 02:35:52 +08:00
|
|
|
return;
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
2010-10-21 06:44:54 +08:00
|
|
|
// Set bit I(25), because this is not in immediate encoding.
|
2008-09-02 14:52:38 +08:00
|
|
|
Binary |= 1 << ARMII::I_BitShift;
|
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(MO2.getReg()));
|
|
|
|
// Set bit[3:0] to the corresponding Rm register
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= getARMRegisterNumbering(MO2.getReg());
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-11-12 15:34:37 +08:00
|
|
|
// If this instr is in scaled register offset/index instruction, set
|
2008-09-02 14:52:38 +08:00
|
|
|
// shift_immed(bit[11:7]) and shift(bit[6:5]) fields.
|
2008-11-06 07:22:34 +08:00
|
|
|
if (unsigned ShImm = ARM_AM::getAM2Offset(AM2Opc)) {
|
2008-11-12 15:34:37 +08:00
|
|
|
Binary |= getShiftOp(AM2Opc) << ARMII::ShiftImmShift; // shift
|
|
|
|
Binary |= ShImm << ARMII::ShiftShift; // shift_immed
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitMiscLoadStoreInstruction(const MachineInstr &MI,
|
2010-03-18 05:16:45 +08:00
|
|
|
unsigned ImplicitRn) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
unsigned Form = MCID.TSFlags & ARMII::FormMask;
|
|
|
|
bool IsPrePost = (MCID.TSFlags & ARMII::IndexModeMask) != 0;
|
2008-11-08 09:44:13 +08:00
|
|
|
|
2008-11-06 02:35:52 +08:00
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
2008-10-08 03:05:35 +08:00
|
|
|
// Set the conditional execution predicate
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2008-09-18 15:28:19 +08:00
|
|
|
|
2008-11-13 15:34:59 +08:00
|
|
|
unsigned OpIdx = 0;
|
|
|
|
|
|
|
|
// Operand 0 of a pre- and post-indexed store is the address base
|
|
|
|
// writeback. Skip it.
|
|
|
|
bool Skipped = false;
|
|
|
|
if (IsPrePost && Form == ARMII::StMiscFrm) {
|
|
|
|
++OpIdx;
|
|
|
|
Skipped = true;
|
|
|
|
}
|
|
|
|
|
2008-09-02 14:52:38 +08:00
|
|
|
// Set first operand
|
2008-11-13 15:34:59 +08:00
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2009-06-15 16:28:29 +08:00
|
|
|
// Skip LDRD and STRD's second operand.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::LDRD || MCID.Opcode == ARM::STRD)
|
2009-06-15 16:28:29 +08:00
|
|
|
++OpIdx;
|
|
|
|
|
2008-09-02 14:52:38 +08:00
|
|
|
// Set second operand
|
2008-11-06 07:22:34 +08:00
|
|
|
if (ImplicitRn)
|
|
|
|
// Special handling for implicit use (e.g. PC).
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= (getARMRegisterNumbering(ImplicitRn) << ARMII::RegRnShift);
|
2008-11-07 17:06:08 +08:00
|
|
|
else
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-11-08 09:44:13 +08:00
|
|
|
// If this is a two-address operand, skip it. e.g. LDRH_POST.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (!Skipped && MCID.getOperandConstraint(OpIdx, MCOI::TIED_TO) != -1)
|
2008-11-08 09:44:13 +08:00
|
|
|
++OpIdx;
|
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
const MachineOperand &MO2 = MI.getOperand(OpIdx);
|
2008-11-06 16:47:38 +08:00
|
|
|
unsigned AM3Opc = (ImplicitRn == ARM::PC)
|
2008-11-06 07:22:34 +08:00
|
|
|
? 0 : MI.getOperand(OpIdx+1).getImm();
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-09-13 09:44:01 +08:00
|
|
|
// Set bit U(23) according to sign of immed value (positive or negative)
|
2008-11-06 07:22:34 +08:00
|
|
|
Binary |= ((ARM_AM::getAM3Op(AM3Opc) == ARM_AM::add ? 1 : 0) <<
|
2008-09-02 14:52:38 +08:00
|
|
|
ARMII::U_BitShift);
|
|
|
|
|
|
|
|
// If this instr is in register offset/index encoding, set bit[3:0]
|
|
|
|
// to the corresponding Rm register.
|
|
|
|
if (MO2.getReg()) {
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= getARMRegisterNumbering(MO2.getReg());
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2008-11-06 02:35:52 +08:00
|
|
|
return;
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
|
2008-11-06 16:47:38 +08:00
|
|
|
// This instr is in immediate offset/index encoding, set bit 22 to 1.
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= 1 << ARMII::AM3_I_BitShift;
|
2008-11-06 07:22:34 +08:00
|
|
|
if (unsigned ImmOffs = ARM_AM::getAM3Offset(AM3Opc)) {
|
2008-09-02 14:52:38 +08:00
|
|
|
// Set operands
|
2008-11-12 15:34:37 +08:00
|
|
|
Binary |= (ImmOffs >> 4) << ARMII::ImmHiShift; // immedH
|
|
|
|
Binary |= (ImmOffs & 0xF); // immedL
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
|
|
|
|
2008-11-12 05:48:44 +08:00
|
|
|
static unsigned getAddrModeUPBits(unsigned Mode) {
|
|
|
|
unsigned Binary = 0;
|
2008-09-02 14:52:38 +08:00
|
|
|
|
|
|
|
// Set addressing mode by modifying bits U(23) and P(24)
|
|
|
|
// IA - Increment after - bit U = 1 and bit P = 0
|
|
|
|
// IB - Increment before - bit U = 1 and bit P = 1
|
|
|
|
// DA - Decrement after - bit U = 0 and bit P = 0
|
|
|
|
// DB - Decrement before - bit U = 0 and bit P = 1
|
|
|
|
switch (Mode) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Unknown addressing sub-mode!");
|
2009-09-10 07:55:03 +08:00
|
|
|
case ARM_AM::da: break;
|
2008-11-07 06:15:19 +08:00
|
|
|
case ARM_AM::db: Binary |= 0x1 << ARMII::P_BitShift; break;
|
|
|
|
case ARM_AM::ia: Binary |= 0x1 << ARMII::U_BitShift; break;
|
|
|
|
case ARM_AM::ib: Binary |= 0x3 << ARMII::U_BitShift; break;
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-11-12 05:48:44 +08:00
|
|
|
return Binary;
|
|
|
|
}
|
|
|
|
|
2010-03-13 15:34:35 +08:00
|
|
|
void ARMCodeEmitter::emitLoadStoreMultipleInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
bool IsUpdating = (MCID.TSFlags & ARMII::IndexModeMask) != 0;
|
2010-03-13 15:34:35 +08:00
|
|
|
|
2008-11-12 05:48:44 +08:00
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
2010-03-13 15:34:35 +08:00
|
|
|
// Skip operand 0 of an instruction with base register update.
|
|
|
|
unsigned OpIdx = 0;
|
|
|
|
if (IsUpdating)
|
|
|
|
++OpIdx;
|
|
|
|
|
2008-11-12 05:48:44 +08:00
|
|
|
// Set base address operand
|
2010-03-13 15:34:35 +08:00
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
|
2008-11-12 05:48:44 +08:00
|
|
|
|
|
|
|
// Set addressing mode by modifying bits U(23) and P(24)
|
2010-11-17 13:31:09 +08:00
|
|
|
ARM_AM::AMSubMode Mode = ARM_AM::getLoadStoreMultipleSubMode(MI.getOpcode());
|
|
|
|
Binary |= getAddrModeUPBits(ARM_AM::getAM4SubMode(Mode));
|
2008-11-12 05:48:44 +08:00
|
|
|
|
2008-09-02 14:52:38 +08:00
|
|
|
// Set bit W(21)
|
2010-03-17 01:46:45 +08:00
|
|
|
if (IsUpdating)
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= 0x1 << ARMII::W_BitShift;
|
2008-09-02 14:52:38 +08:00
|
|
|
|
|
|
|
// Set registers
|
2010-03-13 15:34:35 +08:00
|
|
|
for (unsigned i = OpIdx+2, e = MI.getNumOperands(); i != e; ++i) {
|
2008-09-02 14:52:38 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(i);
|
2008-11-12 05:48:44 +08:00
|
|
|
if (!MO.isReg() || MO.isImplicit())
|
|
|
|
break;
|
2010-09-16 04:26:25 +08:00
|
|
|
unsigned RegNum = getARMRegisterNumbering(MO.getReg());
|
2008-09-02 14:52:38 +08:00
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
|
|
|
|
RegNum < 16);
|
|
|
|
Binary |= 0x1 << RegNum;
|
|
|
|
}
|
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2008-09-02 14:52:38 +08:00
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitMulFrmInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-06 02:35:52 +08:00
|
|
|
|
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
2008-11-04 02:38:31 +08:00
|
|
|
// Set the conditional execution predicate
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2008-11-04 02:38:31 +08:00
|
|
|
|
|
|
|
// Encode S bit if MI modifies CPSR.
|
2011-06-29 03:10:37 +08:00
|
|
|
Binary |= getAddrModeSBit(MI, MCID);
|
2008-11-04 02:38:31 +08:00
|
|
|
|
|
|
|
// 32x32->64bit operations have two destination registers. The number
|
|
|
|
// of register definitions will tell us if that's what we're dealing with.
|
2008-11-07 06:15:19 +08:00
|
|
|
unsigned OpIdx = 0;
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getNumDefs() == 2)
|
2008-11-04 02:38:31 +08:00
|
|
|
Binary |= getMachineOpValue (MI, OpIdx++) << ARMII::RegRdLoShift;
|
|
|
|
|
|
|
|
// Encode Rd
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdHiShift;
|
|
|
|
|
|
|
|
// Encode Rm
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++);
|
|
|
|
|
|
|
|
// Encode Rs
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRsShift;
|
|
|
|
|
2008-11-06 09:21:28 +08:00
|
|
|
// Many multiple instructions (e.g. MLA) have three src operands. Encode
|
|
|
|
// it as Rn (for multiply, that's in the same offset as RdLo.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getNumOperands() > OpIdx &&
|
|
|
|
!MCID.OpInfo[OpIdx].isPredicate() &&
|
|
|
|
!MCID.OpInfo[OpIdx].isOptionalDef())
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= getMachineOpValue(MI, OpIdx) << ARMII::RegRdLoShift;
|
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitExtendInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-07 06:15:19 +08:00
|
|
|
|
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
unsigned OpIdx = 0;
|
|
|
|
|
|
|
|
// Encode Rd
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
const MachineOperand &MO1 = MI.getOperand(OpIdx++);
|
|
|
|
const MachineOperand &MO2 = MI.getOperand(OpIdx);
|
|
|
|
if (MO2.isReg()) {
|
|
|
|
// Two register operand form.
|
|
|
|
// Encode Rn.
|
|
|
|
Binary |= getMachineOpValue(MI, MO1) << ARMII::RegRnShift;
|
|
|
|
|
|
|
|
// Encode Rm.
|
|
|
|
Binary |= getMachineOpValue(MI, MO2);
|
|
|
|
++OpIdx;
|
|
|
|
} else {
|
|
|
|
Binary |= getMachineOpValue(MI, MO1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode rot imm (0, 8, 16, or 24) if it has a rotate immediate operand.
|
|
|
|
if (MI.getOperand(OpIdx).isImm() &&
|
2011-06-29 03:10:37 +08:00
|
|
|
!MCID.OpInfo[OpIdx].isPredicate() &&
|
|
|
|
!MCID.OpInfo[OpIdx].isOptionalDef())
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= (getMachineOpValue(MI, OpIdx) / 8) << ARMII::ExtRotImmShift;
|
2008-11-06 09:21:28 +08:00
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2008-11-04 02:38:31 +08:00
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitMiscArithInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-07 09:41:35 +08:00
|
|
|
|
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
2011-05-07 12:37:27 +08:00
|
|
|
// PKH instructions are finished at this point
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::PKHBT || MCID.Opcode == ARM::PKHTB) {
|
2011-05-07 12:37:27 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-07 09:41:35 +08:00
|
|
|
unsigned OpIdx = 0;
|
|
|
|
|
|
|
|
// Encode Rd
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
const MachineOperand &MO = MI.getOperand(OpIdx++);
|
2011-06-29 03:10:37 +08:00
|
|
|
if (OpIdx == MCID.getNumOperands() ||
|
|
|
|
MCID.OpInfo[OpIdx].isPredicate() ||
|
|
|
|
MCID.OpInfo[OpIdx].isOptionalDef()) {
|
2008-11-07 09:41:35 +08:00
|
|
|
// Encode Rm and it's done.
|
|
|
|
Binary |= getMachineOpValue(MI, MO);
|
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode Rn.
|
|
|
|
Binary |= getMachineOpValue(MI, MO) << ARMII::RegRnShift;
|
|
|
|
|
|
|
|
// Encode Rm.
|
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++);
|
|
|
|
|
|
|
|
// Encode shift_imm.
|
|
|
|
unsigned ShiftAmt = MI.getOperand(OpIdx).getImm();
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::PKHTB) {
|
2010-08-18 01:23:19 +08:00
|
|
|
assert(ShiftAmt != 0 && "PKHTB shift_imm is 0!");
|
|
|
|
if (ShiftAmt == 32)
|
|
|
|
ShiftAmt = 0;
|
|
|
|
}
|
2008-11-07 09:41:35 +08:00
|
|
|
assert(ShiftAmt < 32 && "shift_imm range is 0 to 31!");
|
|
|
|
Binary |= ShiftAmt << ARMII::ShiftShift;
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2008-11-07 09:41:35 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-08-11 08:01:18 +08:00
|
|
|
void ARMCodeEmitter::emitSaturateInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2010-08-11 08:01:18 +08:00
|
|
|
|
|
|
|
// Part of binary is determined by TableGen.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
// Encode Rd
|
|
|
|
Binary |= getMachineOpValue(MI, 0) << ARMII::RegRdShift;
|
|
|
|
|
|
|
|
// Encode saturate bit position.
|
|
|
|
unsigned Pos = MI.getOperand(1).getImm();
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::SSAT || MCID.Opcode == ARM::SSAT16)
|
2010-08-11 08:01:18 +08:00
|
|
|
Pos -= 1;
|
|
|
|
assert((Pos < 16 || (Pos < 32 &&
|
2011-06-29 03:10:37 +08:00
|
|
|
MCID.Opcode != ARM::SSAT16 &&
|
|
|
|
MCID.Opcode != ARM::USAT16)) &&
|
2010-08-11 08:01:18 +08:00
|
|
|
"saturate bit position out of range");
|
|
|
|
Binary |= Pos << 16;
|
|
|
|
|
|
|
|
// Encode Rm
|
|
|
|
Binary |= getMachineOpValue(MI, 2);
|
|
|
|
|
|
|
|
// Encode shift_imm.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getNumOperands() == 4) {
|
2010-08-12 07:10:46 +08:00
|
|
|
unsigned ShiftOp = MI.getOperand(3).getImm();
|
|
|
|
ARM_AM::ShiftOpc Opc = ARM_AM::getSORegShOp(ShiftOp);
|
|
|
|
if (Opc == ARM_AM::asr)
|
|
|
|
Binary |= (1 << 6);
|
2010-08-11 08:01:18 +08:00
|
|
|
unsigned ShiftAmt = MI.getOperand(3).getImm();
|
2010-08-12 07:10:46 +08:00
|
|
|
if (ShiftAmt == 32 && Opc == ARM_AM::asr)
|
2010-08-11 08:01:18 +08:00
|
|
|
ShiftAmt = 0;
|
|
|
|
assert(ShiftAmt < 32 && "shift_imm range is 0 to 31!");
|
|
|
|
Binary |= ShiftAmt << ARMII::ShiftShift;
|
|
|
|
}
|
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitBranchInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-06 02:35:52 +08:00
|
|
|
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::TPsoft) {
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("ARM::TPsoft FIXME"); // FIXME
|
2009-07-09 04:53:28 +08:00
|
|
|
}
|
2008-11-07 01:48:05 +08:00
|
|
|
|
2008-09-02 14:52:38 +08:00
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
2008-11-06 02:35:52 +08:00
|
|
|
// Set the conditional execution predicate
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2008-11-06 02:35:52 +08:00
|
|
|
|
|
|
|
// Set signed_immed_24 field
|
|
|
|
Binary |= getMachineOpValue(MI, 0);
|
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2008-11-06 02:35:52 +08:00
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitInlineJumpTable(unsigned JTIndex) {
|
2008-11-07 17:06:08 +08:00
|
|
|
// Remember the base address of the inline jump table.
|
2008-12-10 10:32:19 +08:00
|
|
|
uintptr_t JTBase = MCE.getCurrentPCValue();
|
2008-11-08 06:30:53 +08:00
|
|
|
JTI->addJumpTableBaseAddr(JTIndex, JTBase);
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << " ** Jump Table #" << JTIndex << " @ " << (void*)JTBase
|
|
|
|
<< '\n');
|
2008-11-07 17:06:08 +08:00
|
|
|
|
|
|
|
// Now emit the jump table entries.
|
|
|
|
const std::vector<MachineBasicBlock*> &MBBs = (*MJTEs)[JTIndex].MBBs;
|
|
|
|
for (unsigned i = 0, e = MBBs.size(); i != e; ++i) {
|
|
|
|
if (IsPIC)
|
|
|
|
// DestBB address - JT base.
|
2008-11-08 06:30:53 +08:00
|
|
|
emitMachineBasicBlock(MBBs[i], ARM::reloc_arm_pic_jt, JTBase);
|
2008-11-07 17:06:08 +08:00
|
|
|
else
|
|
|
|
// Absolute DestBB address.
|
|
|
|
emitMachineBasicBlock(MBBs[i], ARM::reloc_arm_absolute);
|
|
|
|
emitWordLE(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitMiscBranchInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-06 02:35:52 +08:00
|
|
|
|
2008-11-08 06:30:53 +08:00
|
|
|
// Handle jump tables.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::BR_JTr || MCID.Opcode == ARM::BR_JTadd) {
|
2008-11-08 06:30:53 +08:00
|
|
|
// First emit a ldr pc, [] instruction.
|
|
|
|
emitDataProcessingInstruction(MI, ARM::PC);
|
|
|
|
|
|
|
|
// Then emit the inline jump table.
|
2009-07-08 08:05:05 +08:00
|
|
|
unsigned JTIndex =
|
2011-06-29 03:10:37 +08:00
|
|
|
(MCID.Opcode == ARM::BR_JTr)
|
2008-11-08 06:30:53 +08:00
|
|
|
? MI.getOperand(1).getIndex() : MI.getOperand(2).getIndex();
|
|
|
|
emitInlineJumpTable(JTIndex);
|
|
|
|
return;
|
2011-06-29 03:10:37 +08:00
|
|
|
} else if (MCID.Opcode == ARM::BR_JTm) {
|
2008-11-07 17:06:08 +08:00
|
|
|
// First emit a ldr pc, [] instruction.
|
|
|
|
emitLoadStoreInstruction(MI, ARM::PC);
|
|
|
|
|
|
|
|
// Then emit the inline jump table.
|
2008-11-08 06:30:53 +08:00
|
|
|
emitInlineJumpTable(MI.getOperand(3).getIndex());
|
2008-11-07 17:06:08 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-06 02:35:52 +08:00
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
2008-11-07 06:15:19 +08:00
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
2008-11-06 02:35:52 +08:00
|
|
|
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.Opcode == ARM::BX_RET || MCID.Opcode == ARM::MOVPCLR)
|
2008-11-06 02:35:52 +08:00
|
|
|
// The return register is LR.
|
2010-09-16 04:26:25 +08:00
|
|
|
Binary |= getARMRegisterNumbering(ARM::LR);
|
2009-08-11 23:33:49 +08:00
|
|
|
else
|
2008-11-06 02:35:52 +08:00
|
|
|
// otherwise, set the return register
|
|
|
|
Binary |= getMachineOpValue(MI, 0);
|
|
|
|
|
2008-11-06 07:22:34 +08:00
|
|
|
emitWordLE(Binary);
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|
2008-09-02 14:52:38 +08:00
|
|
|
|
2008-11-12 14:41:41 +08:00
|
|
|
static unsigned encodeVFPRd(const MachineInstr &MI, unsigned OpIdx) {
|
2008-11-12 10:19:38 +08:00
|
|
|
unsigned RegD = MI.getOperand(OpIdx).getReg();
|
2008-11-12 14:41:41 +08:00
|
|
|
unsigned Binary = 0;
|
2010-09-16 03:44:57 +08:00
|
|
|
bool isSPVFP = ARM::SPRRegisterClass->contains(RegD);
|
2010-09-16 04:26:25 +08:00
|
|
|
RegD = getARMRegisterNumbering(RegD);
|
2008-11-12 10:19:38 +08:00
|
|
|
if (!isSPVFP)
|
|
|
|
Binary |= RegD << ARMII::RegRdShift;
|
|
|
|
else {
|
|
|
|
Binary |= ((RegD & 0x1E) >> 1) << ARMII::RegRdShift;
|
|
|
|
Binary |= (RegD & 0x01) << ARMII::D_BitShift;
|
|
|
|
}
|
2008-11-12 14:41:41 +08:00
|
|
|
return Binary;
|
|
|
|
}
|
2008-11-12 10:19:38 +08:00
|
|
|
|
2008-11-12 14:41:41 +08:00
|
|
|
static unsigned encodeVFPRn(const MachineInstr &MI, unsigned OpIdx) {
|
2008-11-12 10:19:38 +08:00
|
|
|
unsigned RegN = MI.getOperand(OpIdx).getReg();
|
2008-11-12 14:41:41 +08:00
|
|
|
unsigned Binary = 0;
|
2010-09-16 03:44:57 +08:00
|
|
|
bool isSPVFP = ARM::SPRRegisterClass->contains(RegN);
|
2010-09-16 04:26:25 +08:00
|
|
|
RegN = getARMRegisterNumbering(RegN);
|
2008-11-12 10:19:38 +08:00
|
|
|
if (!isSPVFP)
|
|
|
|
Binary |= RegN << ARMII::RegRnShift;
|
|
|
|
else {
|
|
|
|
Binary |= ((RegN & 0x1E) >> 1) << ARMII::RegRnShift;
|
|
|
|
Binary |= (RegN & 0x01) << ARMII::N_BitShift;
|
|
|
|
}
|
2008-11-12 14:41:41 +08:00
|
|
|
return Binary;
|
|
|
|
}
|
2008-11-12 03:40:26 +08:00
|
|
|
|
2008-11-12 14:41:41 +08:00
|
|
|
static unsigned encodeVFPRm(const MachineInstr &MI, unsigned OpIdx) {
|
|
|
|
unsigned RegM = MI.getOperand(OpIdx).getReg();
|
|
|
|
unsigned Binary = 0;
|
2010-09-16 03:44:57 +08:00
|
|
|
bool isSPVFP = ARM::SPRRegisterClass->contains(RegM);
|
2010-09-16 04:26:25 +08:00
|
|
|
RegM = getARMRegisterNumbering(RegM);
|
2008-11-12 14:41:41 +08:00
|
|
|
if (!isSPVFP)
|
|
|
|
Binary |= RegM;
|
|
|
|
else {
|
|
|
|
Binary |= ((RegM & 0x1E) >> 1);
|
|
|
|
Binary |= (RegM & 0x01) << ARMII::M_BitShift;
|
2008-11-12 03:40:26 +08:00
|
|
|
}
|
2008-11-12 14:41:41 +08:00
|
|
|
return Binary;
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitVFPArithInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2008-11-12 15:18:38 +08:00
|
|
|
|
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
unsigned OpIdx = 0;
|
|
|
|
assert((Binary & ARMII::D_BitShift) == 0 &&
|
|
|
|
(Binary & ARMII::N_BitShift) == 0 &&
|
|
|
|
(Binary & ARMII::M_BitShift) == 0 && "VFP encoding bug!");
|
|
|
|
|
|
|
|
// Encode Dd / Sd.
|
|
|
|
Binary |= encodeVFPRd(MI, OpIdx++);
|
|
|
|
|
|
|
|
// If this is a two-address operand, skip it, e.g. FMACD.
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getOperandConstraint(OpIdx, MCOI::TIED_TO) != -1)
|
2008-11-12 15:18:38 +08:00
|
|
|
++OpIdx;
|
|
|
|
|
|
|
|
// Encode Dn / Sn.
|
2011-06-29 03:10:37 +08:00
|
|
|
if ((MCID.TSFlags & ARMII::FormMask) == ARMII::VFPBinaryFrm)
|
2008-11-12 16:14:21 +08:00
|
|
|
Binary |= encodeVFPRn(MI, OpIdx++);
|
2008-11-12 15:18:38 +08:00
|
|
|
|
2011-06-29 03:10:37 +08:00
|
|
|
if (OpIdx == MCID.getNumOperands() ||
|
|
|
|
MCID.OpInfo[OpIdx].isPredicate() ||
|
|
|
|
MCID.OpInfo[OpIdx].isOptionalDef()) {
|
2008-11-12 15:18:38 +08:00
|
|
|
// FCMPEZD etc. has only one operand.
|
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode Dm / Sm.
|
|
|
|
Binary |= encodeVFPRm(MI, OpIdx);
|
2009-08-11 23:33:49 +08:00
|
|
|
|
2008-11-12 15:18:38 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-03-18 05:16:45 +08:00
|
|
|
void ARMCodeEmitter::emitVFPConversionInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
unsigned Form = MCID.TSFlags & ARMII::FormMask;
|
2008-11-12 14:41:41 +08:00
|
|
|
|
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
switch (Form) {
|
|
|
|
default: break;
|
|
|
|
case ARMII::VFPConv1Frm:
|
|
|
|
case ARMII::VFPConv2Frm:
|
|
|
|
case ARMII::VFPConv3Frm:
|
|
|
|
// Encode Dd / Sd.
|
|
|
|
Binary |= encodeVFPRd(MI, 0);
|
|
|
|
break;
|
|
|
|
case ARMII::VFPConv4Frm:
|
|
|
|
// Encode Dn / Sn.
|
|
|
|
Binary |= encodeVFPRn(MI, 0);
|
|
|
|
break;
|
|
|
|
case ARMII::VFPConv5Frm:
|
|
|
|
// Encode Dm / Sm.
|
|
|
|
Binary |= encodeVFPRm(MI, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Form) {
|
|
|
|
default: break;
|
|
|
|
case ARMII::VFPConv1Frm:
|
|
|
|
// Encode Dm / Sm.
|
|
|
|
Binary |= encodeVFPRm(MI, 1);
|
2008-11-13 15:46:59 +08:00
|
|
|
break;
|
2008-11-12 14:41:41 +08:00
|
|
|
case ARMII::VFPConv2Frm:
|
|
|
|
case ARMII::VFPConv3Frm:
|
|
|
|
// Encode Dn / Sn.
|
|
|
|
Binary |= encodeVFPRn(MI, 1);
|
|
|
|
break;
|
|
|
|
case ARMII::VFPConv4Frm:
|
|
|
|
case ARMII::VFPConv5Frm:
|
|
|
|
// Encode Dd / Sd.
|
|
|
|
Binary |= encodeVFPRd(MI, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Form == ARMII::VFPConv5Frm)
|
|
|
|
// Encode Dn / Sn.
|
|
|
|
Binary |= encodeVFPRn(MI, 2);
|
|
|
|
else if (Form == ARMII::VFPConv3Frm)
|
|
|
|
// Encode Dm / Sm.
|
|
|
|
Binary |= encodeVFPRm(MI, 2);
|
2008-11-12 03:40:26 +08:00
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-02-03 05:48:51 +08:00
|
|
|
void ARMCodeEmitter::emitVFPLoadStoreInstruction(const MachineInstr &MI) {
|
2008-11-12 05:48:44 +08:00
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
|
|
|
unsigned OpIdx = 0;
|
|
|
|
|
|
|
|
// Encode Dd / Sd.
|
2008-11-12 15:18:38 +08:00
|
|
|
Binary |= encodeVFPRd(MI, OpIdx++);
|
2008-11-12 05:48:44 +08:00
|
|
|
|
|
|
|
// Encode address base.
|
|
|
|
const MachineOperand &Base = MI.getOperand(OpIdx++);
|
|
|
|
Binary |= getMachineOpValue(MI, Base) << ARMII::RegRnShift;
|
|
|
|
|
|
|
|
// If there is a non-zero immediate offset, encode it.
|
|
|
|
if (Base.isReg()) {
|
|
|
|
const MachineOperand &Offset = MI.getOperand(OpIdx);
|
|
|
|
if (unsigned ImmOffs = ARM_AM::getAM5Offset(Offset.getImm())) {
|
|
|
|
if (ARM_AM::getAM5Op(Offset.getImm()) == ARM_AM::add)
|
|
|
|
Binary |= 1 << ARMII::U_BitShift;
|
2008-11-12 16:21:12 +08:00
|
|
|
Binary |= ImmOffs;
|
2008-11-12 05:48:44 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If immediate offset is omitted, default to +0.
|
|
|
|
Binary |= 1 << ARMII::U_BitShift;
|
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-03-18 05:16:45 +08:00
|
|
|
void
|
|
|
|
ARMCodeEmitter::emitVFPLoadStoreMultipleInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
bool IsUpdating = (MCID.TSFlags & ARMII::IndexModeMask) != 0;
|
2010-03-13 15:34:35 +08:00
|
|
|
|
2008-11-12 05:48:44 +08:00
|
|
|
// Part of binary is determined by TableGn.
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= II->getPredicate(&MI) << ARMII::CondShift;
|
|
|
|
|
2010-03-13 15:34:35 +08:00
|
|
|
// Skip operand 0 of an instruction with base register update.
|
|
|
|
unsigned OpIdx = 0;
|
|
|
|
if (IsUpdating)
|
|
|
|
++OpIdx;
|
|
|
|
|
2008-11-12 05:48:44 +08:00
|
|
|
// Set base address operand
|
2010-03-13 15:34:35 +08:00
|
|
|
Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
|
2008-11-12 05:48:44 +08:00
|
|
|
|
|
|
|
// Set addressing mode by modifying bits U(23) and P(24)
|
2010-11-17 13:31:09 +08:00
|
|
|
ARM_AM::AMSubMode Mode = ARM_AM::getLoadStoreMultipleSubMode(MI.getOpcode());
|
|
|
|
Binary |= getAddrModeUPBits(ARM_AM::getAM4SubMode(Mode));
|
2008-11-12 05:48:44 +08:00
|
|
|
|
|
|
|
// Set bit W(21)
|
2010-03-17 02:38:09 +08:00
|
|
|
if (IsUpdating)
|
2008-11-12 05:48:44 +08:00
|
|
|
Binary |= 0x1 << ARMII::W_BitShift;
|
|
|
|
|
|
|
|
// First register is encoded in Dd.
|
2010-03-13 15:34:35 +08:00
|
|
|
Binary |= encodeVFPRd(MI, OpIdx+2);
|
2008-11-12 05:48:44 +08:00
|
|
|
|
2010-08-28 07:18:17 +08:00
|
|
|
// Count the number of registers.
|
2008-11-12 05:48:44 +08:00
|
|
|
unsigned NumRegs = 1;
|
2010-03-13 15:34:35 +08:00
|
|
|
for (unsigned i = OpIdx+3, e = MI.getNumOperands(); i != e; ++i) {
|
2008-11-12 05:48:44 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(i);
|
|
|
|
if (!MO.isReg() || MO.isImplicit())
|
|
|
|
break;
|
|
|
|
++NumRegs;
|
|
|
|
}
|
2010-05-26 08:02:28 +08:00
|
|
|
// Bit 8 will be set if <list> is consecutive 64-bit registers (e.g., D0)
|
|
|
|
// Otherwise, it will be 0, in the case of 32-bit registers.
|
|
|
|
if(Binary & 0x100)
|
|
|
|
Binary |= NumRegs * 2;
|
|
|
|
else
|
|
|
|
Binary |= NumRegs;
|
2008-11-12 05:48:44 +08:00
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-06-12 05:34:50 +08:00
|
|
|
static unsigned encodeNEONRd(const MachineInstr &MI, unsigned OpIdx) {
|
|
|
|
unsigned RegD = MI.getOperand(OpIdx).getReg();
|
|
|
|
unsigned Binary = 0;
|
2010-09-16 04:26:25 +08:00
|
|
|
RegD = getARMRegisterNumbering(RegD);
|
2010-06-12 05:34:50 +08:00
|
|
|
Binary |= (RegD & 0xf) << ARMII::RegRdShift;
|
|
|
|
Binary |= ((RegD >> 4) & 1) << ARMII::D_BitShift;
|
|
|
|
return Binary;
|
|
|
|
}
|
|
|
|
|
2010-06-26 06:40:46 +08:00
|
|
|
static unsigned encodeNEONRn(const MachineInstr &MI, unsigned OpIdx) {
|
|
|
|
unsigned RegN = MI.getOperand(OpIdx).getReg();
|
|
|
|
unsigned Binary = 0;
|
2010-09-16 04:26:25 +08:00
|
|
|
RegN = getARMRegisterNumbering(RegN);
|
2010-06-26 06:40:46 +08:00
|
|
|
Binary |= (RegN & 0xf) << ARMII::RegRnShift;
|
|
|
|
Binary |= ((RegN >> 4) & 1) << ARMII::N_BitShift;
|
|
|
|
return Binary;
|
|
|
|
}
|
|
|
|
|
2010-06-26 05:17:19 +08:00
|
|
|
static unsigned encodeNEONRm(const MachineInstr &MI, unsigned OpIdx) {
|
|
|
|
unsigned RegM = MI.getOperand(OpIdx).getReg();
|
|
|
|
unsigned Binary = 0;
|
2010-09-16 04:26:25 +08:00
|
|
|
RegM = getARMRegisterNumbering(RegM);
|
2010-06-26 05:17:19 +08:00
|
|
|
Binary |= (RegM & 0xf);
|
|
|
|
Binary |= ((RegM >> 4) & 1) << ARMII::M_BitShift;
|
|
|
|
return Binary;
|
|
|
|
}
|
|
|
|
|
2010-06-29 05:12:19 +08:00
|
|
|
/// convertNEONDataProcToThumb - Convert the ARM mode encoding for a NEON
|
|
|
|
/// data-processing instruction to the corresponding Thumb encoding.
|
|
|
|
static unsigned convertNEONDataProcToThumb(unsigned Binary) {
|
|
|
|
assert((Binary & 0xfe000000) == 0xf2000000 &&
|
|
|
|
"not an ARM NEON data-processing instruction");
|
|
|
|
unsigned UBit = (Binary >> 24) & 1;
|
|
|
|
return 0xef000000 | (UBit << 28) | (Binary & 0xffffff);
|
|
|
|
}
|
|
|
|
|
2010-06-30 01:34:07 +08:00
|
|
|
void ARMCodeEmitter::emitNEONLaneInstruction(const MachineInstr &MI) {
|
2010-06-26 12:07:15 +08:00
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
2010-06-30 01:34:07 +08:00
|
|
|
unsigned RegTOpIdx, RegNOpIdx, LnOpIdx;
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
|
|
|
if ((MCID.TSFlags & ARMII::FormMask) == ARMII::NGetLnFrm) {
|
2010-06-30 01:34:07 +08:00
|
|
|
RegTOpIdx = 0;
|
|
|
|
RegNOpIdx = 1;
|
|
|
|
LnOpIdx = 2;
|
|
|
|
} else { // ARMII::NSetLnFrm
|
|
|
|
RegTOpIdx = 2;
|
|
|
|
RegNOpIdx = 0;
|
|
|
|
LnOpIdx = 3;
|
|
|
|
}
|
|
|
|
|
2010-06-26 12:07:15 +08:00
|
|
|
// Set the conditional execution predicate
|
2010-06-29 08:26:13 +08:00
|
|
|
Binary |= (IsThumb ? ARMCC::AL : II->getPredicate(&MI)) << ARMII::CondShift;
|
2010-06-26 12:07:15 +08:00
|
|
|
|
2010-06-30 01:34:07 +08:00
|
|
|
unsigned RegT = MI.getOperand(RegTOpIdx).getReg();
|
2010-09-16 04:26:25 +08:00
|
|
|
RegT = getARMRegisterNumbering(RegT);
|
2010-06-26 12:07:15 +08:00
|
|
|
Binary |= (RegT << ARMII::RegRdShift);
|
2010-06-30 01:34:07 +08:00
|
|
|
Binary |= encodeNEONRn(MI, RegNOpIdx);
|
2010-06-26 12:07:15 +08:00
|
|
|
|
|
|
|
unsigned LaneShift;
|
|
|
|
if ((Binary & (1 << 22)) != 0)
|
|
|
|
LaneShift = 0; // 8-bit elements
|
|
|
|
else if ((Binary & (1 << 5)) != 0)
|
|
|
|
LaneShift = 1; // 16-bit elements
|
|
|
|
else
|
|
|
|
LaneShift = 2; // 32-bit elements
|
|
|
|
|
2010-06-30 01:34:07 +08:00
|
|
|
unsigned Lane = MI.getOperand(LnOpIdx).getImm() << LaneShift;
|
2010-06-26 12:07:15 +08:00
|
|
|
unsigned Opc1 = Lane >> 2;
|
|
|
|
unsigned Opc2 = Lane & 3;
|
|
|
|
assert((Opc1 & 3) == 0 && "out-of-range lane number operand");
|
|
|
|
Binary |= (Opc1 << 21);
|
|
|
|
Binary |= (Opc2 << 5);
|
|
|
|
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-06-30 04:13:29 +08:00
|
|
|
void ARMCodeEmitter::emitNEONDupInstruction(const MachineInstr &MI) {
|
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
|
|
|
|
// Set the conditional execution predicate
|
|
|
|
Binary |= (IsThumb ? ARMCC::AL : II->getPredicate(&MI)) << ARMII::CondShift;
|
|
|
|
|
|
|
|
unsigned RegT = MI.getOperand(1).getReg();
|
2010-09-16 04:26:25 +08:00
|
|
|
RegT = getARMRegisterNumbering(RegT);
|
2010-06-30 04:13:29 +08:00
|
|
|
Binary |= (RegT << ARMII::RegRdShift);
|
|
|
|
Binary |= encodeNEONRn(MI, 0);
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-06-26 05:17:19 +08:00
|
|
|
void ARMCodeEmitter::emitNEON1RegModImmInstruction(const MachineInstr &MI) {
|
2010-06-12 05:34:50 +08:00
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
// Destination register is encoded in Dd.
|
|
|
|
Binary |= encodeNEONRd(MI, 0);
|
|
|
|
// Immediate fields: Op, Cmode, I, Imm3, Imm4
|
|
|
|
unsigned Imm = MI.getOperand(1).getImm();
|
|
|
|
unsigned Op = (Imm >> 12) & 1;
|
|
|
|
unsigned Cmode = (Imm >> 8) & 0xf;
|
|
|
|
unsigned I = (Imm >> 7) & 1;
|
|
|
|
unsigned Imm3 = (Imm >> 4) & 0x7;
|
|
|
|
unsigned Imm4 = Imm & 0xf;
|
2010-06-29 05:16:30 +08:00
|
|
|
Binary |= (I << 24) | (Imm3 << 16) | (Cmode << 8) | (Op << 5) | Imm4;
|
2010-06-29 06:23:17 +08:00
|
|
|
if (IsThumb)
|
2010-06-29 05:12:19 +08:00
|
|
|
Binary = convertNEONDataProcToThumb(Binary);
|
2010-06-12 05:34:50 +08:00
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-06-26 05:17:19 +08:00
|
|
|
void ARMCodeEmitter::emitNEON2RegInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2010-06-26 05:17:19 +08:00
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
2010-06-26 06:40:46 +08:00
|
|
|
// Destination register is encoded in Dd; source register in Dm.
|
|
|
|
unsigned OpIdx = 0;
|
|
|
|
Binary |= encodeNEONRd(MI, OpIdx++);
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getOperandConstraint(OpIdx, MCOI::TIED_TO) != -1)
|
2010-06-26 06:40:46 +08:00
|
|
|
++OpIdx;
|
|
|
|
Binary |= encodeNEONRm(MI, OpIdx);
|
2010-06-29 06:23:17 +08:00
|
|
|
if (IsThumb)
|
2010-06-29 05:12:19 +08:00
|
|
|
Binary = convertNEONDataProcToThumb(Binary);
|
2010-06-26 05:17:19 +08:00
|
|
|
// FIXME: This does not handle VDUPfdf or VDUPfqf.
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2010-06-26 06:40:46 +08:00
|
|
|
void ARMCodeEmitter::emitNEON3RegInstruction(const MachineInstr &MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI.getDesc();
|
2010-06-26 06:40:46 +08:00
|
|
|
unsigned Binary = getBinaryCodeForInstr(MI);
|
|
|
|
// Destination register is encoded in Dd; source registers in Dn and Dm.
|
|
|
|
unsigned OpIdx = 0;
|
|
|
|
Binary |= encodeNEONRd(MI, OpIdx++);
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getOperandConstraint(OpIdx, MCOI::TIED_TO) != -1)
|
2010-06-26 06:40:46 +08:00
|
|
|
++OpIdx;
|
|
|
|
Binary |= encodeNEONRn(MI, OpIdx++);
|
2011-06-29 03:10:37 +08:00
|
|
|
if (MCID.getOperandConstraint(OpIdx, MCOI::TIED_TO) != -1)
|
2010-06-26 06:40:46 +08:00
|
|
|
++OpIdx;
|
|
|
|
Binary |= encodeNEONRm(MI, OpIdx);
|
2010-06-29 06:23:17 +08:00
|
|
|
if (IsThumb)
|
2010-06-29 05:12:19 +08:00
|
|
|
Binary = convertNEONDataProcToThumb(Binary);
|
2010-06-26 06:40:46 +08:00
|
|
|
// FIXME: This does not handle VMOVDneon or VMOVQ.
|
|
|
|
emitWordLE(Binary);
|
|
|
|
}
|
|
|
|
|
2008-09-02 14:52:38 +08:00
|
|
|
#include "ARMGenCodeEmitter.inc"
|