Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMInstrInfo.cpp - ARM Instruction Information --------------------===// |
Rafael Espindola | ffdc24b | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Rafael Espindola | ffdc24b | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains the ARM implementation of the TargetInstrInfo class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "ARMInstrInfo.h" |
| 14 | #include "ARM.h" |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 15 | #include "ARMConstantPoolValue.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 16 | #include "ARMMachineFunctionInfo.h" |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 17 | #include "ARMTargetMachine.h" |
Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 18 | #include "MCTargetDesc/ARMAddressingModes.h" |
Owen Anderson | e2f23a3 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/LiveVariables.h" |
Owen Anderson | 6bb0c52 | 2008-01-04 23:57:37 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Evan Cheng | 760c68b | 2007-01-29 23:45:17 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 23 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Jim Grosbach | 08aa534 | 2013-08-26 20:07:25 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Function.h" |
| 26 | #include "llvm/IR/GlobalVariable.h" |
Chris Lattner | 7b26fce | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCAsmInfo.h" |
Jim Grosbach | 617f84dd | 2012-02-28 23:53:30 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCInst.h" |
Rafael Espindola | ffdc24b | 2006-05-14 22:18:28 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Anton Korobeynikov | 99152f3 | 2009-06-26 21:28:53 +0000 | [diff] [blame] | 31 | ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI) |
Eric Christopher | 3408583 | 2015-03-12 05:12:31 +0000 | [diff] [blame] | 32 | : ARMBaseInstrInfo(STI), RI() {} |
Rafael Espindola | 8c41f99 | 2006-08-08 20:35:03 +0000 | [diff] [blame] | 33 | |
Hans Wennborg | 9b9a535 | 2017-04-21 21:48:41 +0000 | [diff] [blame] | 34 | /// Return the noop instruction to use for a noop. |
| 35 | void ARMInstrInfo::getNoop(MCInst &NopInst) const { |
Jim Grosbach | 617f84dd | 2012-02-28 23:53:30 +0000 | [diff] [blame] | 36 | if (hasNOP()) { |
Jim Grosbach | cb540f5 | 2012-06-18 19:45:50 +0000 | [diff] [blame] | 37 | NopInst.setOpcode(ARM::HINT); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 38 | NopInst.addOperand(MCOperand::createImm(0)); |
| 39 | NopInst.addOperand(MCOperand::createImm(ARMCC::AL)); |
| 40 | NopInst.addOperand(MCOperand::createReg(0)); |
Jim Grosbach | 617f84dd | 2012-02-28 23:53:30 +0000 | [diff] [blame] | 41 | } else { |
| 42 | NopInst.setOpcode(ARM::MOVr); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 43 | NopInst.addOperand(MCOperand::createReg(ARM::R0)); |
| 44 | NopInst.addOperand(MCOperand::createReg(ARM::R0)); |
| 45 | NopInst.addOperand(MCOperand::createImm(ARMCC::AL)); |
| 46 | NopInst.addOperand(MCOperand::createReg(0)); |
| 47 | NopInst.addOperand(MCOperand::createReg(0)); |
Jim Grosbach | 617f84dd | 2012-02-28 23:53:30 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Chris Lattner | e98a3c3 | 2009-08-02 05:20:37 +0000 | [diff] [blame] | 51 | unsigned ARMInstrInfo::getUnindexedOpcode(unsigned Opc) const { |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 52 | switch (Opc) { |
NAKAMURA Takumi | 59a16a7 | 2015-09-22 11:10:17 +0000 | [diff] [blame] | 53 | default: |
| 54 | break; |
Owen Anderson | 16d33f3 | 2011-08-26 20:43:14 +0000 | [diff] [blame] | 55 | case ARM::LDR_PRE_IMM: |
| 56 | case ARM::LDR_PRE_REG: |
Owen Anderson | 2aedba6 | 2011-07-26 20:54:26 +0000 | [diff] [blame] | 57 | case ARM::LDR_POST_IMM: |
| 58 | case ARM::LDR_POST_REG: |
Jim Grosbach | 1e4d9a1 | 2010-10-26 22:37:02 +0000 | [diff] [blame] | 59 | return ARM::LDRi12; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 60 | case ARM::LDRH_PRE: |
| 61 | case ARM::LDRH_POST: |
| 62 | return ARM::LDRH; |
Owen Anderson | 16d33f3 | 2011-08-26 20:43:14 +0000 | [diff] [blame] | 63 | case ARM::LDRB_PRE_IMM: |
| 64 | case ARM::LDRB_PRE_REG: |
Owen Anderson | 2aedba6 | 2011-07-26 20:54:26 +0000 | [diff] [blame] | 65 | case ARM::LDRB_POST_IMM: |
| 66 | case ARM::LDRB_POST_REG: |
Jim Grosbach | 5a7c715 | 2010-10-27 00:19:44 +0000 | [diff] [blame] | 67 | return ARM::LDRBi12; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 68 | case ARM::LDRSH_PRE: |
| 69 | case ARM::LDRSH_POST: |
| 70 | return ARM::LDRSH; |
| 71 | case ARM::LDRSB_PRE: |
| 72 | case ARM::LDRSB_POST: |
| 73 | return ARM::LDRSB; |
Owen Anderson | 2aedba6 | 2011-07-26 20:54:26 +0000 | [diff] [blame] | 74 | case ARM::STR_PRE_IMM: |
| 75 | case ARM::STR_PRE_REG: |
| 76 | case ARM::STR_POST_IMM: |
| 77 | case ARM::STR_POST_REG: |
Jim Grosbach | 338de3e | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 78 | return ARM::STRi12; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 79 | case ARM::STRH_PRE: |
| 80 | case ARM::STRH_POST: |
| 81 | return ARM::STRH; |
Owen Anderson | 2aedba6 | 2011-07-26 20:54:26 +0000 | [diff] [blame] | 82 | case ARM::STRB_PRE_IMM: |
| 83 | case ARM::STRB_PRE_REG: |
| 84 | case ARM::STRB_POST_IMM: |
| 85 | case ARM::STRB_POST_REG: |
Jim Grosbach | 338de3e | 2010-10-27 23:12:14 +0000 | [diff] [blame] | 86 | return ARM::STRBi12; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 87 | } |
David Goodwin | af7451b | 2009-07-08 16:09:28 +0000 | [diff] [blame] | 88 | |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 89 | return 0; |
| 90 | } |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 91 | |
Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 92 | void ARMInstrInfo::expandLoadStackGuard(MachineBasicBlock::iterator MI) const { |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 93 | MachineFunction &MF = *MI->getParent()->getParent(); |
Eric Christopher | 22b2ad2 | 2015-02-20 08:24:37 +0000 | [diff] [blame] | 94 | const ARMSubtarget &Subtarget = MF.getSubtarget<ARMSubtarget>(); |
Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 95 | const TargetMachine &TM = MF.getTarget(); |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 96 | |
Sam Parker | 5b09834 | 2019-02-08 07:57:42 +0000 | [diff] [blame] | 97 | if (!Subtarget.useMovt()) { |
Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 98 | if (TM.isPositionIndependent()) |
| 99 | expandLoadStackGuardBase(MI, ARM::LDRLIT_ga_pcrel, ARM::LDRi12); |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 100 | else |
Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 101 | expandLoadStackGuardBase(MI, ARM::LDRLIT_ga_abs, ARM::LDRi12); |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 102 | return; |
| 103 | } |
| 104 | |
Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 105 | if (!TM.isPositionIndependent()) { |
| 106 | expandLoadStackGuardBase(MI, ARM::MOVi32imm, ARM::LDRi12); |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | |
| 110 | const GlobalValue *GV = |
| 111 | cast<GlobalValue>((*MI->memoperands_begin())->getValue()); |
| 112 | |
Rafael Espindola | 5ac8f5c | 2016-06-28 15:38:13 +0000 | [diff] [blame] | 113 | if (!Subtarget.isGVIndirectSymbol(GV)) { |
Rafael Espindola | 82f4631 | 2016-06-28 15:18:26 +0000 | [diff] [blame] | 114 | expandLoadStackGuardBase(MI, ARM::MOV_ga_pcrel, ARM::LDRi12); |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | |
| 118 | MachineBasicBlock &MBB = *MI->getParent(); |
| 119 | DebugLoc DL = MI->getDebugLoc(); |
| 120 | unsigned Reg = MI->getOperand(0).getReg(); |
| 121 | MachineInstrBuilder MIB; |
| 122 | |
| 123 | MIB = BuildMI(MBB, MI, DL, get(ARM::MOV_ga_pcrel_ldr), Reg) |
| 124 | .addGlobalAddress(GV, 0, ARMII::MO_NONLAZY); |
Justin Lebar | adbf09e | 2016-09-11 01:38:58 +0000 | [diff] [blame] | 125 | auto Flags = MachineMemOperand::MOLoad | |
| 126 | MachineMemOperand::MODereferenceable | |
| 127 | MachineMemOperand::MOInvariant; |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 128 | MachineMemOperand *MMO = MBB.getParent()->getMachineMemOperand( |
Justin Lebar | 0af80cd | 2016-07-15 18:26:59 +0000 | [diff] [blame] | 129 | MachinePointerInfo::getGOT(*MBB.getParent()), Flags, 4, 4); |
Akira Hatanaka | 2ee0e9e | 2014-10-23 04:17:05 +0000 | [diff] [blame] | 130 | MIB.addMemOperand(MMO); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 131 | BuildMI(MBB, MI, DL, get(ARM::LDRi12), Reg) |
| 132 | .addReg(Reg, RegState::Kill) |
| 133 | .addImm(0) |
Chandler Carruth | c73c030 | 2018-08-16 21:30:05 +0000 | [diff] [blame] | 134 | .cloneMemRefs(*MI) |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 135 | .add(predOps(ARMCC::AL)); |
Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 136 | } |