2012-04-14 09:54:10 -04:00
|
|
|
//===-- ARMInstrInfo.cpp - ARM Instruction Information --------------------===//
|
2009-06-02 13:52:33 -04:00
|
|
|
//
|
2019-08-20 16:50:12 -04:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-06-02 13:52:33 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// This file contains the ARM implementation of the TargetInstrInfo class.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "ARMInstrInfo.h"
|
|
|
|
|
#include "ARM.h"
|
2012-12-02 08:10:19 -05:00
|
|
|
#include "ARMConstantPoolValue.h"
|
2009-06-02 13:52:33 -04:00
|
|
|
#include "ARMMachineFunctionInfo.h"
|
2012-12-02 08:10:19 -05:00
|
|
|
#include "ARMTargetMachine.h"
|
2011-10-20 17:10:27 -04:00
|
|
|
#include "MCTargetDesc/ARMAddressingModes.h"
|
2009-06-02 13:52:33 -04:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
#include "llvm/CodeGen/LiveVariables.h"
|
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2013-12-21 19:04:03 -05:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2013-04-08 14:41:23 -04:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
2009-10-14 13:57:32 -04:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2012-04-14 09:54:10 -04:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-06-02 13:52:33 -04:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
2009-06-27 06:44:33 -04:00
|
|
|
ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
|
2015-05-27 14:44:32 -04:00
|
|
|
: ARMBaseInstrInfo(STI), RI() {}
|
2009-06-02 13:52:33 -04:00
|
|
|
|
2017-04-26 15:45:00 -04:00
|
|
|
/// Return the noop instruction to use for a noop.
|
|
|
|
|
void ARMInstrInfo::getNoop(MCInst &NopInst) const {
|
2012-04-14 09:54:10 -04:00
|
|
|
if (hasNOP()) {
|
2012-08-15 15:34:23 -04:00
|
|
|
NopInst.setOpcode(ARM::HINT);
|
2015-05-27 14:44:32 -04:00
|
|
|
NopInst.addOperand(MCOperand::createImm(0));
|
|
|
|
|
NopInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
|
NopInst.addOperand(MCOperand::createReg(0));
|
2012-04-14 09:54:10 -04:00
|
|
|
} else {
|
|
|
|
|
NopInst.setOpcode(ARM::MOVr);
|
2015-05-27 14:44:32 -04:00
|
|
|
NopInst.addOperand(MCOperand::createReg(ARM::R0));
|
|
|
|
|
NopInst.addOperand(MCOperand::createReg(ARM::R0));
|
|
|
|
|
NopInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
|
NopInst.addOperand(MCOperand::createReg(0));
|
|
|
|
|
NopInst.addOperand(MCOperand::createReg(0));
|
2012-04-14 09:54:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-14 13:57:32 -04:00
|
|
|
unsigned ARMInstrInfo::getUnindexedOpcode(unsigned Opc) const {
|
2009-06-02 13:52:33 -04:00
|
|
|
switch (Opc) {
|
2015-12-30 06:46:15 -05:00
|
|
|
default:
|
|
|
|
|
break;
|
2011-10-20 17:10:27 -04:00
|
|
|
case ARM::LDR_PRE_IMM:
|
|
|
|
|
case ARM::LDR_PRE_REG:
|
|
|
|
|
case ARM::LDR_POST_IMM:
|
|
|
|
|
case ARM::LDR_POST_REG:
|
2011-02-20 07:57:14 -05:00
|
|
|
return ARM::LDRi12;
|
2009-06-02 13:52:33 -04:00
|
|
|
case ARM::LDRH_PRE:
|
|
|
|
|
case ARM::LDRH_POST:
|
|
|
|
|
return ARM::LDRH;
|
2011-10-20 17:10:27 -04:00
|
|
|
case ARM::LDRB_PRE_IMM:
|
|
|
|
|
case ARM::LDRB_PRE_REG:
|
|
|
|
|
case ARM::LDRB_POST_IMM:
|
|
|
|
|
case ARM::LDRB_POST_REG:
|
2011-02-20 07:57:14 -05:00
|
|
|
return ARM::LDRBi12;
|
2009-06-02 13:52:33 -04:00
|
|
|
case ARM::LDRSH_PRE:
|
|
|
|
|
case ARM::LDRSH_POST:
|
|
|
|
|
return ARM::LDRSH;
|
|
|
|
|
case ARM::LDRSB_PRE:
|
|
|
|
|
case ARM::LDRSB_POST:
|
|
|
|
|
return ARM::LDRSB;
|
2011-10-20 17:10:27 -04:00
|
|
|
case ARM::STR_PRE_IMM:
|
|
|
|
|
case ARM::STR_PRE_REG:
|
|
|
|
|
case ARM::STR_POST_IMM:
|
|
|
|
|
case ARM::STR_POST_REG:
|
2011-02-20 07:57:14 -05:00
|
|
|
return ARM::STRi12;
|
2009-06-02 13:52:33 -04:00
|
|
|
case ARM::STRH_PRE:
|
|
|
|
|
case ARM::STRH_POST:
|
|
|
|
|
return ARM::STRH;
|
2011-10-20 17:10:27 -04:00
|
|
|
case ARM::STRB_PRE_IMM:
|
|
|
|
|
case ARM::STRB_PRE_REG:
|
|
|
|
|
case ARM::STRB_POST_IMM:
|
|
|
|
|
case ARM::STRB_POST_REG:
|
2011-02-20 07:57:14 -05:00
|
|
|
return ARM::STRBi12;
|
2009-06-02 13:52:33 -04:00
|
|
|
}
|
2009-06-27 06:44:33 -04:00
|
|
|
|
2009-10-14 13:57:32 -04:00
|
|
|
return 0;
|
2009-06-02 13:52:33 -04:00
|
|
|
}
|
2012-12-02 08:10:19 -05:00
|
|
|
|
2016-07-23 16:41:05 -04:00
|
|
|
void ARMInstrInfo::expandLoadStackGuard(MachineBasicBlock::iterator MI) const {
|
2015-01-18 11:17:27 -05:00
|
|
|
MachineFunction &MF = *MI->getParent()->getParent();
|
2015-05-27 14:44:32 -04:00
|
|
|
const ARMSubtarget &Subtarget = MF.getSubtarget<ARMSubtarget>();
|
2016-07-23 16:41:05 -04:00
|
|
|
const TargetMachine &TM = MF.getTarget();
|
2015-01-18 11:17:27 -05:00
|
|
|
|
2019-08-20 16:50:12 -04:00
|
|
|
if (!Subtarget.useMovt()) {
|
2016-07-23 16:41:05 -04:00
|
|
|
if (TM.isPositionIndependent())
|
|
|
|
|
expandLoadStackGuardBase(MI, ARM::LDRLIT_ga_pcrel, ARM::LDRi12);
|
2015-01-18 11:17:27 -05:00
|
|
|
else
|
2016-07-23 16:41:05 -04:00
|
|
|
expandLoadStackGuardBase(MI, ARM::LDRLIT_ga_abs, ARM::LDRi12);
|
2015-01-18 11:17:27 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 16:41:05 -04:00
|
|
|
if (!TM.isPositionIndependent()) {
|
|
|
|
|
expandLoadStackGuardBase(MI, ARM::MOVi32imm, ARM::LDRi12);
|
2015-01-18 11:17:27 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const GlobalValue *GV =
|
|
|
|
|
cast<GlobalValue>((*MI->memoperands_begin())->getValue());
|
|
|
|
|
|
2016-07-23 16:41:05 -04:00
|
|
|
if (!Subtarget.isGVIndirectSymbol(GV)) {
|
|
|
|
|
expandLoadStackGuardBase(MI, ARM::MOV_ga_pcrel, ARM::LDRi12);
|
2015-01-18 11:17:27 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MachineBasicBlock &MBB = *MI->getParent();
|
|
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
2019-10-23 13:51:42 -04:00
|
|
|
Register Reg = MI->getOperand(0).getReg();
|
2015-01-18 11:17:27 -05:00
|
|
|
MachineInstrBuilder MIB;
|
|
|
|
|
|
|
|
|
|
MIB = BuildMI(MBB, MI, DL, get(ARM::MOV_ga_pcrel_ldr), Reg)
|
|
|
|
|
.addGlobalAddress(GV, 0, ARMII::MO_NONLAZY);
|
2017-01-02 14:17:04 -05:00
|
|
|
auto Flags = MachineMemOperand::MOLoad |
|
|
|
|
|
MachineMemOperand::MODereferenceable |
|
|
|
|
|
MachineMemOperand::MOInvariant;
|
2015-01-18 11:17:27 -05:00
|
|
|
MachineMemOperand *MMO = MBB.getParent()->getMachineMemOperand(
|
2020-07-26 15:36:28 -04:00
|
|
|
MachinePointerInfo::getGOT(*MBB.getParent()), Flags, 4, Align(4));
|
2015-01-18 11:17:27 -05:00
|
|
|
MIB.addMemOperand(MMO);
|
2017-04-16 12:01:22 -04:00
|
|
|
BuildMI(MBB, MI, DL, get(ARM::LDRi12), Reg)
|
|
|
|
|
.addReg(Reg, RegState::Kill)
|
|
|
|
|
.addImm(0)
|
2019-01-19 05:01:25 -05:00
|
|
|
.cloneMemRefs(*MI)
|
2017-04-16 12:01:22 -04:00
|
|
|
.add(predOps(ARMCC::AL));
|
2015-01-18 11:17:27 -05:00
|
|
|
}
|