ARMInstrInfo.td revision 278709
112891Swpaul//===- ARMInstrInfo.td - Target Description for ARM Target -*- tablegen -*-===//
212891Swpaul//
312891Swpaul//                     The LLVM Compiler Infrastructure
412891Swpaul//
512891Swpaul// This file is distributed under the University of Illinois Open Source
612891Swpaul// License. See LICENSE.TXT for details.
712891Swpaul//
812891Swpaul//===----------------------------------------------------------------------===//
912891Swpaul//
1012891Swpaul// This file describes the ARM instructions in TableGen format.
1112891Swpaul//
1212891Swpaul//===----------------------------------------------------------------------===//
1312891Swpaul
1412891Swpaul//===----------------------------------------------------------------------===//
1512891Swpaul// ARM specific DAG Nodes.
1612891Swpaul//
1712891Swpaul
1812891Swpaul// Type profiles.
1912891Swpauldef SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
2012891Swpauldef SDT_ARMCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
2112891Swpauldef SDT_ARMStructByVal : SDTypeProfile<0, 4,
2212891Swpaul                                       [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
2312891Swpaul                                        SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
2412891Swpaul
2512891Swpauldef SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
2612891Swpaul
2712891Swpauldef SDT_ARMcall    : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
2812891Swpaul
2912891Swpauldef SDT_ARMCMov    : SDTypeProfile<1, 3,
3012891Swpaul                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
3112891Swpaul                                    SDTCisVT<3, i32>]>;
3212891Swpaul
3312891Swpauldef SDT_ARMBrcond  : SDTypeProfile<0, 2,
34114601Sobrien                                   [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
35114601Sobrien
3630827Scharnierdef SDT_ARMBrJT    : SDTypeProfile<0, 3,
3720818Swpaul                                  [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
3812891Swpaul                                   SDTCisVT<2, i32>]>;
3930827Scharnier
4030827Scharnierdef SDT_ARMBr2JT   : SDTypeProfile<0, 4,
4112891Swpaul                                  [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
4212891Swpaul                                   SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
4312891Swpaul
4412891Swpauldef SDT_ARMBCC_i64 : SDTypeProfile<0, 6,
4512891Swpaul                                  [SDTCisVT<0, i32>,
4612891Swpaul                                   SDTCisVT<1, i32>, SDTCisVT<2, i32>,
4712891Swpaul                                   SDTCisVT<3, i32>, SDTCisVT<4, i32>,
4812997Swpaul                                   SDTCisVT<5, OtherVT>]>;
4912891Swpaul
5012891Swpauldef SDT_ARMAnd     : SDTypeProfile<1, 2,
5112891Swpaul                                   [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
5228042Swpaul                                    SDTCisVT<2, i32>]>;
5328042Swpaul
5428042Swpauldef SDT_ARMCmp     : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
5528042Swpaul
5628042Swpauldef SDT_ARMPICAdd  : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
5790298Sdes                                          SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
5890298Sdes
5946186Swpauldef SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
6046186Swpauldef SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisPtrTy<1>,
6146186Swpaul                                                 SDTCisInt<2>]>;
6246186Swpauldef SDT_ARMEH_SJLJ_Longjmp: SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisInt<1>]>;
6346186Swpaul
6446186Swpauldef SDT_ARMMEMBARRIER     : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
6546186Swpaul
6646186Swpauldef SDT_ARMPREFETCH : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisSameAs<1, 2>,
6746186Swpaul                                           SDTCisInt<1>]>;
6846186Swpaul
6914262Swpauldef SDT_ARMTCRET : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
7014262Swpaul
7114262Swpauldef SDT_ARMBFI : SDTypeProfile<1, 3, [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
7214262Swpaul                                      SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
7312891Swpaul
7412891Swpauldef SDT_ARMVMAXNM : SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisFP<1>, SDTCisFP<2>]>;
7512891Swpauldef SDT_ARMVMINNM : SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisFP<1>, SDTCisFP<2>]>;
7612891Swpaul
7712891Swpauldef SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
7812891Swpaul                                            [SDTCisSameAs<0, 2>,
7919161Swpaul                                             SDTCisSameAs<0, 3>,
8019161Swpaul                                             SDTCisInt<0>, SDTCisVT<1, i32>]>;
8119161Swpaul
8212891Swpaul// SDTBinaryArithWithFlagsInOut - RES1, CPSR = op LHS, RHS, CPSR
8319161Swpauldef SDTBinaryArithWithFlagsInOut : SDTypeProfile<2, 3,
8412891Swpaul                                            [SDTCisSameAs<0, 2>,
8512891Swpaul                                             SDTCisSameAs<0, 3>,
8612891Swpaul                                             SDTCisInt<0>,
8712891Swpaul                                             SDTCisVT<1, i32>,
8812891Swpaul                                             SDTCisVT<4, i32>]>;
8912891Swpaul
9012891Swpauldef SDT_ARM64bitmlal : SDTypeProfile<2,4, [ SDTCisVT<0, i32>, SDTCisVT<1, i32>,
9112891Swpaul                                        SDTCisVT<2, i32>, SDTCisVT<3, i32>,
9212891Swpaul                                        SDTCisVT<4, i32>, SDTCisVT<5, i32> ] >;
9312891Swpauldef ARMUmlal         : SDNode<"ARMISD::UMLAL", SDT_ARM64bitmlal>;
9412891Swpauldef ARMSmlal         : SDNode<"ARMISD::SMLAL", SDT_ARM64bitmlal>;
9512891Swpaul
9619161Swpaul// Node definitions.
9719161Swpauldef ARMWrapper       : SDNode<"ARMISD::Wrapper",     SDTIntUnaryOp>;
9819161Swpauldef ARMWrapperDYN    : SDNode<"ARMISD::WrapperDYN",  SDTIntUnaryOp>;
9912891Swpauldef ARMWrapperPIC    : SDNode<"ARMISD::WrapperPIC",  SDTIntUnaryOp>;
10019161Swpauldef ARMWrapperJT     : SDNode<"ARMISD::WrapperJT",   SDTIntBinOp>;
10112891Swpaul
10212891Swpauldef ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
10312891Swpaul                              [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>;
10412891Swpauldef ARMcallseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeqEnd,
10512891Swpaul                              [SDNPHasChain, SDNPSideEffect,
10612891Swpaul                               SDNPOptInGlue, SDNPOutGlue]>;
10712891Swpauldef ARMcopystructbyval : SDNode<"ARMISD::COPY_STRUCT_BYVAL" ,
10812891Swpaul                                SDT_ARMStructByVal,
10912891Swpaul                                [SDNPHasChain, SDNPInGlue, SDNPOutGlue,
11012891Swpaul                                 SDNPMayStore, SDNPMayLoad]>;
11112891Swpaul
11212891Swpauldef ARMcall          : SDNode<"ARMISD::CALL", SDT_ARMcall,
11312891Swpaul                              [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
11412891Swpaul                               SDNPVariadic]>;
11512891Swpauldef ARMcall_pred    : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
11612891Swpaul                              [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
11712891Swpaul                               SDNPVariadic]>;
11819161Swpauldef ARMcall_nolink   : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
11919161Swpaul                              [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
12019161Swpaul                               SDNPVariadic]>;
12112891Swpaul
12219161Swpauldef ARMretflag       : SDNode<"ARMISD::RET_FLAG", SDTNone,
12312891Swpaul                              [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
12412891Swpauldef ARMintretflag    : SDNode<"ARMISD::INTRET_FLAG", SDT_ARMcall,
12512891Swpaul                              [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
12612891Swpauldef ARMcmov          : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
12712891Swpaul                              [SDNPInGlue]>;
12812891Swpaul
12912891Swpauldef ARMbrcond        : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
13012891Swpaul                              [SDNPHasChain, SDNPInGlue, SDNPOutGlue]>;
13112891Swpaul
13212891Swpauldef ARMbrjt          : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
13312891Swpaul                              [SDNPHasChain]>;
13412891Swpauldef ARMbr2jt         : SDNode<"ARMISD::BR2_JT", SDT_ARMBr2JT,
13512891Swpaul                              [SDNPHasChain]>;
13612891Swpaul
13712891Swpauldef ARMBcci64        : SDNode<"ARMISD::BCC_i64", SDT_ARMBCC_i64,
13814304Swpaul                              [SDNPHasChain]>;
13914304Swpaul
14019161Swpauldef ARMcmp           : SDNode<"ARMISD::CMP", SDT_ARMCmp,
14119161Swpaul                              [SDNPOutGlue]>;
14219161Swpaul
14319161Swpauldef ARMcmn           : SDNode<"ARMISD::CMN", SDT_ARMCmp,
14412891Swpaul                              [SDNPOutGlue]>;
14519161Swpaul
14612891Swpauldef ARMcmpZ          : SDNode<"ARMISD::CMPZ", SDT_ARMCmp,
14712891Swpaul                              [SDNPOutGlue, SDNPCommutative]>;
14812891Swpaul
14912891Swpauldef ARMpic_add       : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
15012891Swpaul
15112891Swpauldef ARMsrl_flag      : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutGlue]>;
15212891Swpauldef ARMsra_flag      : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutGlue]>;
15312891Swpauldef ARMrrx           : SDNode<"ARMISD::RRX"     , SDTIntUnaryOp, [SDNPInGlue ]>;
15412891Swpaul
15533250Swpauldef ARMaddc          : SDNode<"ARMISD::ADDC",  SDTBinaryArithWithFlags,
15620818Swpaul                              [SDNPCommutative]>;
15720818Swpauldef ARMsubc          : SDNode<"ARMISD::SUBC",  SDTBinaryArithWithFlags>;
15812891Swpauldef ARMadde          : SDNode<"ARMISD::ADDE",  SDTBinaryArithWithFlagsInOut>;
15912891Swpauldef ARMsube          : SDNode<"ARMISD::SUBE",  SDTBinaryArithWithFlagsInOut>;
16020818Swpaul
16120818Swpauldef ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
16212891Swpauldef ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP",
16312891Swpaul                               SDT_ARMEH_SJLJ_Setjmp,
16412891Swpaul                               [SDNPHasChain, SDNPSideEffect]>;
16512891Swpauldef ARMeh_sjlj_longjmp: SDNode<"ARMISD::EH_SJLJ_LONGJMP",
16619161Swpaul                               SDT_ARMEH_SJLJ_Longjmp,
167159461Smaxim                               [SDNPHasChain, SDNPSideEffect]>;
16819161Swpaul
169159461Smaximdef ARMMemBarrierMCR  : SDNode<"ARMISD::MEMBARRIER_MCR", SDT_ARMMEMBARRIER,
17019161Swpaul                               [SDNPHasChain, SDNPSideEffect]>;
171145792Sumedef ARMPreload        : SDNode<"ARMISD::PRELOAD", SDT_ARMPREFETCH,
172145793Sume                               [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
17319161Swpaul
17427589Swpauldef ARMrbit          : SDNode<"ARMISD::RBIT", SDTIntUnaryOp>;
17590297Sdes
17620818Swpauldef ARMtcret         : SDNode<"ARMISD::TC_RETURN", SDT_ARMTCRET,
17727589Swpaul                        [SDNPHasChain,  SDNPOptInGlue, SDNPVariadic]>;
17827589Swpaul
17912891Swpauldef ARMbfi           : SDNode<"ARMISD::BFI", SDT_ARMBFI>;
18012891Swpaul
18130827Scharnierdef ARMvmaxnm        : SDNode<"ARMISD::VMAXNM", SDT_ARMVMAXNM, []>;
18212891Swpauldef ARMvminnm        : SDNode<"ARMISD::VMINNM", SDT_ARMVMINNM, []>;
18312891Swpaul
184145792Sume//===----------------------------------------------------------------------===//
185145792Sume// ARM Instruction Predicate Definitions.
18612891Swpaul//
187145792Sumedef HasV4T           : Predicate<"Subtarget->hasV4TOps()">,
188145792Sume                                 AssemblerPredicate<"HasV4TOps", "armv4t">;
189145792Sumedef NoV4T            : Predicate<"!Subtarget->hasV4TOps()">;
190145792Sumedef HasV5T           : Predicate<"Subtarget->hasV5TOps()">;
191145792Sumedef HasV5TE          : Predicate<"Subtarget->hasV5TEOps()">,
192145792Sume                                 AssemblerPredicate<"HasV5TEOps", "armv5te">;
193145792Sumedef HasV6            : Predicate<"Subtarget->hasV6Ops()">,
194145792Sume                                 AssemblerPredicate<"HasV6Ops", "armv6">;
19512891Swpauldef NoV6             : Predicate<"!Subtarget->hasV6Ops()">;
19620818Swpauldef HasV6M           : Predicate<"Subtarget->hasV6MOps()">,
19720818Swpaul                                 AssemblerPredicate<"HasV6MOps",
19812891Swpaul                                                    "armv6m or armv6t2">;
19912891Swpauldef HasV6T2          : Predicate<"Subtarget->hasV6T2Ops()">,
20012891Swpaul                                 AssemblerPredicate<"HasV6T2Ops", "armv6t2">;
20112891Swpauldef NoV6T2           : Predicate<"!Subtarget->hasV6T2Ops()">;
20212891Swpauldef HasV7            : Predicate<"Subtarget->hasV7Ops()">,
20312891Swpaul                                 AssemblerPredicate<"HasV7Ops", "armv7">;
20412891Swpauldef HasV8            : Predicate<"Subtarget->hasV8Ops()">,
20512891Swpaul                                 AssemblerPredicate<"HasV8Ops", "armv8">;
20612891Swpauldef PreV8            : Predicate<"!Subtarget->hasV8Ops()">,
20712891Swpaul                                 AssemblerPredicate<"!HasV8Ops", "armv7 or earlier">;
20814304Swpauldef NoVFP            : Predicate<"!Subtarget->hasVFP2()">;
20914304Swpauldef HasVFP2          : Predicate<"Subtarget->hasVFP2()">,
21019161Swpaul                                 AssemblerPredicate<"FeatureVFP2", "VFP2">;
21119161Swpauldef HasVFP3          : Predicate<"Subtarget->hasVFP3()">,
21219161Swpaul                                 AssemblerPredicate<"FeatureVFP3", "VFP3">;
21319161Swpauldef HasVFP4          : Predicate<"Subtarget->hasVFP4()">,
21412891Swpaul                                 AssemblerPredicate<"FeatureVFP4", "VFP4">;
21519161Swpauldef HasDPVFP         : Predicate<"!Subtarget->isFPOnlySP()">,
21612891Swpaul                                 AssemblerPredicate<"!FeatureVFPOnlySP",
21712891Swpaul                                                    "double precision VFP">;
21812891Swpauldef HasFPARMv8       : Predicate<"Subtarget->hasFPARMv8()">,
21912891Swpaul                                 AssemblerPredicate<"FeatureFPARMv8", "FPARMv8">;
22012891Swpauldef HasNEON          : Predicate<"Subtarget->hasNEON()">,
22112891Swpaul                                 AssemblerPredicate<"FeatureNEON", "NEON">;
22212891Swpauldef HasCrypto        : Predicate<"Subtarget->hasCrypto()">,
22312891Swpaul                                 AssemblerPredicate<"FeatureCrypto", "crypto">;
22412891Swpauldef HasCRC           : Predicate<"Subtarget->hasCRC()">,
22533250Swpaul                                 AssemblerPredicate<"FeatureCRC", "crc">;
22612891Swpauldef HasFP16          : Predicate<"Subtarget->hasFP16()">,
22712891Swpaul                                 AssemblerPredicate<"FeatureFP16","half-float">;
22812891Swpauldef HasDivide        : Predicate<"Subtarget->hasDivide()">,
22912891Swpaul                                 AssemblerPredicate<"FeatureHWDiv", "divide in THUMB">;
23020818Swpauldef HasDivideInARM   : Predicate<"Subtarget->hasDivideInARMMode()">,
23112891Swpaul                                 AssemblerPredicate<"FeatureHWDivARM", "divide in ARM">;
23212891Swpauldef HasT2ExtractPack : Predicate<"Subtarget->hasT2ExtractPack()">,
23312891Swpaul                                 AssemblerPredicate<"FeatureT2XtPk",
23412891Swpaul                                                     "pack/extract">;
23512891Swpauldef HasThumb2DSP     : Predicate<"Subtarget->hasThumb2DSP()">,
23612891Swpaul                                 AssemblerPredicate<"FeatureDSPThumb2",
23712891Swpaul                                                    "thumb2-dsp">;
23812891Swpauldef HasDB            : Predicate<"Subtarget->hasDataBarrier()">,
23912891Swpaul                                 AssemblerPredicate<"FeatureDB",
24014304Swpaul                                                    "data-barriers">;
24114304Swpauldef HasMP            : Predicate<"Subtarget->hasMPExtension()">,
24215426Swpaul                                 AssemblerPredicate<"FeatureMP",
24319161Swpaul                                                    "mp-extensions">;
24419161Swpauldef HasTrustZone     : Predicate<"Subtarget->hasTrustZone()">,
24519161Swpaul                                 AssemblerPredicate<"FeatureTrustZone",
24612891Swpaul                                                    "TrustZone">;
24719161Swpauldef UseNEONForFP     : Predicate<"Subtarget->useNEONForSinglePrecisionFP()">;
24812891Swpauldef DontUseNEONForFP : Predicate<"!Subtarget->useNEONForSinglePrecisionFP()">;
24912891Swpauldef IsThumb          : Predicate<"Subtarget->isThumb()">,
25012891Swpaul                                 AssemblerPredicate<"ModeThumb", "thumb">;
25112891Swpauldef IsThumb1Only     : Predicate<"Subtarget->isThumb1Only()">;
25212891Swpauldef IsThumb2         : Predicate<"Subtarget->isThumb2()">,
25312891Swpaul                                 AssemblerPredicate<"ModeThumb,FeatureThumb2",
25412891Swpaul                                                    "thumb2">;
25512891Swpauldef IsMClass         : Predicate<"Subtarget->isMClass()">,
25612891Swpaul                                 AssemblerPredicate<"FeatureMClass", "armv*m">;
25720818Swpauldef IsNotMClass      : Predicate<"!Subtarget->isMClass()">,
25812891Swpaul                                 AssemblerPredicate<"!FeatureMClass",
25912891Swpaul                                                    "!armv*m">;
26012891Swpauldef IsARM            : Predicate<"!Subtarget->isThumb()">,
26112891Swpaul                                 AssemblerPredicate<"!ModeThumb", "arm-mode">;
26220818Swpauldef IsIOS            : Predicate<"Subtarget->isTargetIOS()">;
26320818Swpauldef IsNotIOS         : Predicate<"!Subtarget->isTargetIOS()">;
26412891Swpauldef IsNaCl           : Predicate<"Subtarget->isTargetNaCl()">;
26520818Swpauldef UseNaClTrap      : Predicate<"Subtarget->useNaClTrap()">,
26620818Swpaul                                 AssemblerPredicate<"FeatureNaClTrap", "NaCl">;
26712891Swpauldef DontUseNaClTrap  : Predicate<"!Subtarget->useNaClTrap()">;
26812891Swpaul
26912891Swpaul// FIXME: Eventually this will be just "hasV6T2Ops".
27090298Sdesdef UseMovt          : Predicate<"Subtarget->useMovt()">;
27190298Sdesdef DontUseMovt      : Predicate<"!Subtarget->useMovt()">;
27290298Sdesdef UseFPVMLx        : Predicate<"Subtarget->useFPVMLx()">;
27312997Swpauldef UseMulOps        : Predicate<"Subtarget->useMulOps()">;
27412997Swpaul
27512997Swpaul// Prefer fused MAC for fp mul + add over fp VMLA / VMLS if they are available.
27612997Swpaul// But only select them if more precision in FP computation is allowed.
27712997Swpaul// Do not use them for Darwin platforms.
27813375Swpauldef UseFusedMAC      : Predicate<"(TM.Options.AllowFPOpFusion =="
27912997Swpaul                                 " FPOpFusion::Fast) && "
28013375Swpaul                                 "!Subtarget->isTargetDarwin()">;
28112997Swpauldef DontUseFusedMAC  : Predicate<"!(TM.Options.AllowFPOpFusion =="
28212997Swpaul                                 " FPOpFusion::Fast &&"
28312997Swpaul                                 " Subtarget->hasVFP4()) || "
28419131Swpaul                                 "Subtarget->isTargetDarwin()">;
28519131Swpaul
28619161Swpaul// VGETLNi32 is microcoded on Swift - prefer VMOV.
28719131Swpauldef HasFastVGETLNi32 : Predicate<"!Subtarget->isSwift()">;
28819131Swpauldef HasSlowVGETLNi32 : Predicate<"Subtarget->isSwift()">;
28912997Swpaul
29012997Swpaul// VDUP.32 is microcoded on Swift - prefer VMOV.
29112997Swpauldef HasFastVDUP32 : Predicate<"!Subtarget->isSwift()">;
29212997Swpauldef HasSlowVDUP32 : Predicate<"Subtarget->isSwift()">;
29313375Swpaul
29413375Swpaul// Cortex-A9 prefers VMOVSR to VMOVDRR even when using NEON for scalar FP, as
29595658Sdes// this allows more effective execution domain optimization. See
29613375Swpaul// setExecutionDomain().
29712997Swpauldef UseVMOVSR : Predicate<"Subtarget->isCortexA9() || !Subtarget->useNEONForSinglePrecisionFP()">;
29813375Swpauldef DontUseVMOVSR : Predicate<"!Subtarget->isCortexA9() && Subtarget->useNEONForSinglePrecisionFP()">;
29913375Swpaul
30013375Swpauldef IsLE             : Predicate<"getTargetLowering()->isLittleEndian()">;
30113375Swpauldef IsBE             : Predicate<"getTargetLowering()->isBigEndian()">;
30213375Swpaul
30313375Swpaul//===----------------------------------------------------------------------===//
30413375Swpaul// ARM Flag Definitions.
30513375Swpaul
30612997Swpaulclass RegConstraint<string C> {
30712997Swpaul  string Constraints = C;
30812997Swpaul}
30912997Swpaul
31015426Swpaul//===----------------------------------------------------------------------===//
31115426Swpaul//  ARM specific transformation functions and pattern fragments.
31215426Swpaul//
31395658Sdes
31415426Swpaul// imm_neg_XFORM - Return the negation of an i32 immediate value.
31515426Swpauldef imm_neg_XFORM : SDNodeXForm<imm, [{
31615426Swpaul  return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
31715426Swpaul}]>;
31812891Swpaul
31912891Swpaul// imm_not_XFORM - Return the complement of a i32 immediate value.
32012891Swpauldef imm_not_XFORM : SDNodeXForm<imm, [{
32112891Swpaul  return CurDAG->getTargetConstant(~(int)N->getZExtValue(), MVT::i32);
32212997Swpaul}]>;
32324780Swpaul
32424780Swpaul/// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
32512891Swpauldef imm16_31 : ImmLeaf<i32, [{
32613375Swpaul  return (int32_t)Imm >= 16 && (int32_t)Imm < 32;
32713375Swpaul}]>;
32813375Swpaul
32919161Swpauldef so_imm_neg_asmoperand : AsmOperandClass { let Name = "ARMSOImmNeg"; }
33019161Swpauldef so_imm_neg : Operand<i32>, PatLeaf<(imm), [{
33119161Swpaul    unsigned Value = -(unsigned)N->getZExtValue();
33219161Swpaul    return Value && ARM_AM::getSOImmVal(Value) != -1;
33312891Swpaul  }], imm_neg_XFORM> {
33419161Swpaul  let ParserMatchClass = so_imm_neg_asmoperand;
33524780Swpaul}
33612891Swpaul
33712891Swpaul// Note: this pattern doesn't require an encoder method and such, as it's
33824780Swpaul// only used on aliases (Pat<> and InstAlias<>). The actual encoding
33912891Swpaul// is handled by the destination instructions, which use so_imm.
34024780Swpauldef so_imm_not_asmoperand : AsmOperandClass { let Name = "ARMSOImmNot"; }
34112891Swpauldef so_imm_not : Operand<i32>, PatLeaf<(imm), [{
34212891Swpaul    return ARM_AM::getSOImmVal(~(uint32_t)N->getZExtValue()) != -1;
34312891Swpaul  }], imm_not_XFORM> {
34424780Swpaul  let ParserMatchClass = so_imm_not_asmoperand;
34512891Swpaul}
34612891Swpaul
34724780Swpaul// sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
34824780Swpauldef sext_16_node : PatLeaf<(i32 GPR:$a), [{
34924780Swpaul  return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
35024780Swpaul}]>;
35124780Swpaul
35224780Swpaul/// Split a 32-bit immediate into two 16 bit parts.
35324780Swpauldef hi16 : SDNodeXForm<imm, [{
35424780Swpaul  return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
35524780Swpaul}]>;
35624780Swpaul
35724780Swpauldef lo16AllZero : PatLeaf<(i32 imm), [{
35824780Swpaul  // Returns true if all low 16-bits are 0.
35924780Swpaul  return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
36024780Swpaul}], hi16>;
36124780Swpaul
36224780Swpaulclass BinOpWithFlagFrag<dag res> :
36324780Swpaul      PatFrag<(ops node:$LHS, node:$RHS, node:$FLAG), res>;
36424780Swpaulclass BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
36524780Swpaulclass UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
36624780Swpaul
36724780Swpaul// An 'and' node with a single use.
36890297Sdesdef and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
36912891Swpaul  return N->hasOneUse();
37012891Swpaul}]>;
37112891Swpaul
37212891Swpaul// An 'xor' node with a single use.
37312891Swpauldef xor_su : PatFrag<(ops node:$lhs, node:$rhs), (xor node:$lhs, node:$rhs), [{
37480184Skris  return N->hasOneUse();
37580184Skris}]>;
37680184Skris
37780184Skris// An 'fmul' node with a single use.
37822321Swpauldef fmul_su : PatFrag<(ops node:$lhs, node:$rhs), (fmul node:$lhs, node:$rhs),[{
37912997Swpaul  return N->hasOneUse();
38022321Swpaul}]>;
38112997Swpaul
38214304Swpaul// An 'fadd' node which checks for single non-hazardous use.
38314304Swpauldef fadd_mlx : PatFrag<(ops node:$lhs, node:$rhs),(fadd node:$lhs, node:$rhs),[{
38424780Swpaul  return hasNoVMLxHazardUse(N);
38514304Swpaul}]>;
38614304Swpaul
38714304Swpaul// An 'fsub' node which checks for single non-hazardous use.
38895658Sdesdef fsub_mlx : PatFrag<(ops node:$lhs, node:$rhs),(fsub node:$lhs, node:$rhs),[{
38912997Swpaul  return hasNoVMLxHazardUse(N);
39014304Swpaul}]>;
39114304Swpaul
39224780Swpaul//===----------------------------------------------------------------------===//
39314304Swpaul// Operand Definitions.
39414304Swpaul//
39514304Swpaul
39695658Sdes// Immediate operands with a shared generic asm render method.
39712997Swpaulclass ImmAsmOperand : AsmOperandClass { let RenderMethod = "addImmOperands"; }
39815426Swpaul
39924780Swpaul// Branch target.
40046205Swpaul// FIXME: rename brtarget to t2_brtarget
40146205Swpauldef brtarget : Operand<OtherVT> {
40246205Swpaul  let EncoderMethod = "getBranchTargetOpValue";
40346205Swpaul  let OperandType = "OPERAND_PCREL";
40446205Swpaul  let DecoderMethod = "DecodeT2BROperand";
40546205Swpaul}
40646205Swpaul
40712997Swpaul// FIXME: get rid of this one?
40812891Swpauldef uncondbrtarget : Operand<OtherVT> {
40912891Swpaul  let EncoderMethod = "getUnconditionalBranchTargetOpValue";
41012891Swpaul  let OperandType = "OPERAND_PCREL";
41124780Swpaul}
41212891Swpaul
41312891Swpaul// Branch target for ARM. Handles conditional/unconditional
41413375Swpauldef br_target : Operand<OtherVT> {
41512997Swpaul  let EncoderMethod = "getARMBranchTargetOpValue";
41612891Swpaul  let OperandType = "OPERAND_PCREL";
41712891Swpaul}
41813375Swpaul
41913375Swpaul// Call target.
42012891Swpaul// FIXME: rename bltarget to t2_bl_target?
42115426Swpauldef bltarget : Operand<i32> {
42212891Swpaul  // Encoded the same as branch targets.
42312891Swpaul  let EncoderMethod = "getBranchTargetOpValue";
42412891Swpaul  let OperandType = "OPERAND_PCREL";
42512891Swpaul}
42612891Swpaul
42712891Swpaul// Call target for ARM. Handles conditional/unconditional
42812891Swpaul// FIXME: rename bl_target to t2_bltarget?
42919161Swpauldef bl_target : Operand<i32> {
43019161Swpaul  let EncoderMethod = "getARMBLTargetOpValue";
43119161Swpaul  let OperandType = "OPERAND_PCREL";
43212891Swpaul}
43319161Swpaul
43412891Swpauldef blx_target : Operand<i32> {
43515426Swpaul  let EncoderMethod = "getARMBLXTargetOpValue";
43615426Swpaul  let OperandType = "OPERAND_PCREL";
43715426Swpaul}
43815426Swpaul
43914240Swpaul// A list of registers separated by comma. Used by load/store multiple.
44014240Swpauldef RegListAsmOperand : AsmOperandClass { let Name = "RegList"; }
44114240Swpauldef reglist : Operand<i32> {
44212891Swpaul  let EncoderMethod = "getRegisterListOpValue";
44312891Swpaul  let ParserMatchClass = RegListAsmOperand;
44412891Swpaul  let PrintMethod = "printRegisterList";
44512891Swpaul  let DecoderMethod = "DecodeRegListOperand";
44612891Swpaul}
44712891Swpaul
44812891Swpauldef GPRPairOp : RegisterOperand<GPRPair, "printGPRPairOperand">;
44912891Swpaul
45012891Swpauldef DPRRegListAsmOperand : AsmOperandClass { let Name = "DPRRegList"; }
45112891Swpauldef dpr_reglist : Operand<i32> {
45212891Swpaul  let EncoderMethod = "getRegisterListOpValue";
45312891Swpaul  let ParserMatchClass = DPRRegListAsmOperand;
45412891Swpaul  let PrintMethod = "printRegisterList";
45512891Swpaul  let DecoderMethod = "DecodeDPRRegListOperand";
45612891Swpaul}
45712891Swpaul
45812891Swpauldef SPRRegListAsmOperand : AsmOperandClass { let Name = "SPRRegList"; }
45912891Swpauldef spr_reglist : Operand<i32> {
46020100Swpaul  let EncoderMethod = "getRegisterListOpValue";
46120100Swpaul  let ParserMatchClass = SPRRegListAsmOperand;
46220100Swpaul  let PrintMethod = "printRegisterList";
46312891Swpaul  let DecoderMethod = "DecodeSPRRegListOperand";
46412891Swpaul}
46512891Swpaul
46612891Swpaul// An operand for the CONSTPOOL_ENTRY pseudo-instruction.
46720100Swpauldef cpinst_operand : Operand<i32> {
46820100Swpaul  let PrintMethod = "printCPInstOperand";
46920100Swpaul}
47020818Swpaul
47120818Swpaul// Local PC labels.
47220100Swpauldef pclabel : Operand<i32> {
47320100Swpaul  let PrintMethod = "printPCLabel";
47420100Swpaul}
47520100Swpaul
47620100Swpaul// ADR instruction labels.
47720100Swpauldef AdrLabelAsmOperand : AsmOperandClass { let Name = "AdrLabel"; }
47820100Swpauldef adrlabel : Operand<i32> {
47920100Swpaul  let EncoderMethod = "getAdrLabelOpValue";
48020100Swpaul  let ParserMatchClass = AdrLabelAsmOperand;
48120100Swpaul  let PrintMethod = "printAdrLabelOperand<0>";
48220100Swpaul}
48312891Swpaul
48412891Swpauldef neon_vcvt_imm32 : Operand<i32> {
48512891Swpaul  let EncoderMethod = "getNEONVcvtImm32OpValue";
48612891Swpaul  let DecoderMethod = "DecodeVCVTImmOperand";
48712891Swpaul}
48812891Swpaul
48912891Swpaul// rot_imm: An integer that encodes a rotate amount. Must be 8, 16, or 24.
49012891Swpauldef rot_imm_XFORM: SDNodeXForm<imm, [{
49112891Swpaul  switch (N->getZExtValue()){
49212891Swpaul  default: assert(0);
49312891Swpaul  case 0:  return CurDAG->getTargetConstant(0, MVT::i32);
49412891Swpaul  case 8:  return CurDAG->getTargetConstant(1, MVT::i32);
49512891Swpaul  case 16: return CurDAG->getTargetConstant(2, MVT::i32);
49614304Swpaul  case 24: return CurDAG->getTargetConstant(3, MVT::i32);
49714304Swpaul  }
49812891Swpaul}]>;
49919161Swpauldef RotImmAsmOperand : AsmOperandClass {
50019161Swpaul  let Name = "RotImm";
50119161Swpaul  let ParserMethod = "parseRotImm";
50212891Swpaul}
50319161Swpauldef rot_imm : Operand<i32>, PatLeaf<(i32 imm), [{
50412891Swpaul    int32_t v = N->getZExtValue();
50512891Swpaul    return v == 8 || v == 16 || v == 24; }],
50612891Swpaul    rot_imm_XFORM> {
50712891Swpaul  let PrintMethod = "printRotImmOperand";
50812891Swpaul  let ParserMatchClass = RotImmAsmOperand;
50912891Swpaul}
51012891Swpaul
51112891Swpaul// shift_imm: An integer that encodes a shift amount and the type of shift
51212891Swpaul// (asr or lsl). The 6-bit immediate encodes as:
51320100Swpaul//    {5}     0 ==> lsl
51421389Swpaul//            1     asr
51521389Swpaul//    {4-0}   imm5 shift amount.
51621389Swpaul//            asr #32 encoded as imm5 == 0.
51721389Swpauldef ShifterImmAsmOperand : AsmOperandClass {
51821389Swpaul  let Name = "ShifterImm";
51921389Swpaul  let ParserMethod = "parseShifterImm";
52021389Swpaul}
52121389Swpauldef shift_imm : Operand<i32> {
52221389Swpaul  let PrintMethod = "printShiftImmOperand";
52321389Swpaul  let ParserMatchClass = ShifterImmAsmOperand;
52420100Swpaul}
52520100Swpaul
52620100Swpaul// shifter_operand operands: so_reg_reg, so_reg_imm, and so_imm.
52720100Swpauldef ShiftedRegAsmOperand : AsmOperandClass { let Name = "RegShiftedReg"; }
52820100Swpauldef so_reg_reg : Operand<i32>,  // reg reg imm
52943847Swpaul                 ComplexPattern<i32, 3, "SelectRegShifterOperand",
53090297Sdes                                [shl, srl, sra, rotr]> {
53143847Swpaul  let EncoderMethod = "getSORegRegOpValue";
53243847Swpaul  let PrintMethod = "printSORegRegOperand";
53343847Swpaul  let DecoderMethod = "DecodeSORegRegOperand";
53443847Swpaul  let ParserMatchClass = ShiftedRegAsmOperand;
53543847Swpaul  let MIOperandInfo = (ops GPRnopc, GPRnopc, i32imm);
53643847Swpaul}
53743847Swpaul
53843847Swpauldef ShiftedImmAsmOperand : AsmOperandClass { let Name = "RegShiftedImm"; }
53943847Swpauldef so_reg_imm : Operand<i32>, // reg imm
54043847Swpaul                 ComplexPattern<i32, 2, "SelectImmShifterOperand",
54143847Swpaul                                [shl, srl, sra, rotr]> {
54243847Swpaul  let EncoderMethod = "getSORegImmOpValue";
54320100Swpaul  let PrintMethod = "printSORegImmOperand";
54420100Swpaul  let DecoderMethod = "DecodeSORegImmOperand";
54546207Swpaul  let ParserMatchClass = ShiftedImmAsmOperand;
54646207Swpaul  let MIOperandInfo = (ops GPR, i32imm);
54746207Swpaul}
54846207Swpaul
54946207Swpaul// FIXME: Does this need to be distinct from so_reg?
55046207Swpauldef shift_so_reg_reg : Operand<i32>,    // reg reg imm
55146207Swpaul                   ComplexPattern<i32, 3, "SelectShiftRegShifterOperand",
55246207Swpaul                                  [shl,srl,sra,rotr]> {
55320818Swpaul  let EncoderMethod = "getSORegRegOpValue";
55420818Swpaul  let PrintMethod = "printSORegRegOperand";
55512891Swpaul  let DecoderMethod = "DecodeSORegRegOperand";
55612891Swpaul  let ParserMatchClass = ShiftedRegAsmOperand;
55712891Swpaul  let MIOperandInfo = (ops GPR, GPR, i32imm);
55812891Swpaul}
55912891Swpaul
56095658Sdes// FIXME: Does this need to be distinct from so_reg?
56120100Swpauldef shift_so_reg_imm : Operand<i32>,    // reg reg imm
56212891Swpaul                   ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
56346205Swpaul                                  [shl,srl,sra,rotr]> {
56446205Swpaul  let EncoderMethod = "getSORegImmOpValue";
56512891Swpaul  let PrintMethod = "printSORegImmOperand";
566200100Skuriyama  let DecoderMethod = "DecodeSORegImmOperand";
567200100Skuriyama  let ParserMatchClass = ShiftedImmAsmOperand;
568200100Skuriyama  let MIOperandInfo = (ops GPR, i32imm);
569200100Skuriyama}
57012891Swpaul
57112891Swpaul
57212891Swpaul// so_imm - Match a 32-bit shifter_operand immediate operand, which is an
57312891Swpaul// 8-bit immediate rotated by an arbitrary number of bits.
57412891Swpauldef SOImmAsmOperand: ImmAsmOperand { let Name = "ARMSOImm"; }
57512891Swpauldef so_imm : Operand<i32>, ImmLeaf<i32, [{
57615426Swpaul    return ARM_AM::getSOImmVal(Imm) != -1;
57728042Swpaul  }]> {
57820818Swpaul  let EncoderMethod = "getSOImmOpValue";
57912891Swpaul  let ParserMatchClass = SOImmAsmOperand;
58014303Swpaul  let DecoderMethod = "DecodeSOImmOperand";
58114303Swpaul}
58219161Swpaul
58319161Swpaul// Break so_imm's up into two pieces.  This handles immediates with up to 16
58419161Swpaul// bits set in them.  This uses so_imm2part to match and so_imm2part_[12] to
58519161Swpaul// get the first/second pieces.
58619161Swpauldef so_imm2part : PatLeaf<(imm), [{
58712891Swpaul      return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
58812891Swpaul}]>;
58912891Swpaul
59012891Swpaul/// arm_i32imm - True for +V6T2, or true only if so_imm2part is true.
59112891Swpaul///
59212891Swpauldef arm_i32imm : PatLeaf<(imm), [{
59312891Swpaul  if (Subtarget->hasV6T2Ops())
59412891Swpaul    return true;
59512891Swpaul  return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
59620818Swpaul}]>;
59720818Swpaul
59820818Swpaul/// imm0_1 predicate - Immediate in the range [0,1].
59920818Swpauldef Imm0_1AsmOperand: ImmAsmOperand { let Name = "Imm0_1"; }
60020818Swpauldef imm0_1 : Operand<i32> { let ParserMatchClass = Imm0_1AsmOperand; }
60115426Swpaul
60215426Swpaul/// imm0_3 predicate - Immediate in the range [0,3].
60315426Swpauldef Imm0_3AsmOperand: ImmAsmOperand { let Name = "Imm0_3"; }
60415426Swpauldef imm0_3 : Operand<i32> { let ParserMatchClass = Imm0_3AsmOperand; }
60515426Swpaul
60615426Swpaul/// imm0_7 predicate - Immediate in the range [0,7].
60715426Swpauldef Imm0_7AsmOperand: ImmAsmOperand { let Name = "Imm0_7"; }
60815426Swpauldef imm0_7 : Operand<i32>, ImmLeaf<i32, [{
60920818Swpaul  return Imm >= 0 && Imm < 8;
61020818Swpaul}]> {
61195658Sdes  let ParserMatchClass = Imm0_7AsmOperand;
61220818Swpaul}
61395658Sdes
61412891Swpaul/// imm8 predicate - Immediate is exactly 8.
61512891Swpauldef Imm8AsmOperand: ImmAsmOperand { let Name = "Imm8"; }
61612891Swpauldef imm8 : Operand<i32>, ImmLeaf<i32, [{ return Imm == 8; }]> {
61712891Swpaul  let ParserMatchClass = Imm8AsmOperand;
61812891Swpaul}
61912891Swpaul
62012891Swpaul/// imm16 predicate - Immediate is exactly 16.
62112891Swpauldef Imm16AsmOperand: ImmAsmOperand { let Name = "Imm16"; }
62212891Swpauldef imm16 : Operand<i32>, ImmLeaf<i32, [{ return Imm == 16; }]> {
62312891Swpaul  let ParserMatchClass = Imm16AsmOperand;
62428042Swpaul}
62520818Swpaul
62612891Swpaul/// imm32 predicate - Immediate is exactly 32.
62714304Swpauldef Imm32AsmOperand: ImmAsmOperand { let Name = "Imm32"; }
62814304Swpauldef imm32 : Operand<i32>, ImmLeaf<i32, [{ return Imm == 32; }]> {
62919161Swpaul  let ParserMatchClass = Imm32AsmOperand;
63019161Swpaul}
63119161Swpaul
63219161Swpaul/// imm1_7 predicate - Immediate in the range [1,7].
63319161Swpauldef Imm1_7AsmOperand: ImmAsmOperand { let Name = "Imm1_7"; }
63412891Swpauldef imm1_7 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm < 8; }]> {
63512891Swpaul  let ParserMatchClass = Imm1_7AsmOperand;
63612891Swpaul}
63712891Swpaul
63812891Swpaul/// imm1_15 predicate - Immediate in the range [1,15].
63912891Swpauldef Imm1_15AsmOperand: ImmAsmOperand { let Name = "Imm1_15"; }
64012891Swpauldef imm1_15 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm < 16; }]> {
64112891Swpaul  let ParserMatchClass = Imm1_15AsmOperand;
64290297Sdes}
64312891Swpaul
64412891Swpaul/// imm1_31 predicate - Immediate in the range [1,31].
64512891Swpauldef Imm1_31AsmOperand: ImmAsmOperand { let Name = "Imm1_31"; }
64612891Swpauldef imm1_31 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm < 32; }]> {
64712891Swpaul  let ParserMatchClass = Imm1_31AsmOperand;
64812891Swpaul}
64912891Swpaul
65020818Swpaul/// imm0_15 predicate - Immediate in the range [0,15].
65120818Swpauldef Imm0_15AsmOperand: ImmAsmOperand {
65220818Swpaul  let Name = "Imm0_15";
65320818Swpaul  let DiagnosticType = "ImmRange0_15";
65420818Swpaul}
65520818Swpauldef imm0_15 : Operand<i32>, ImmLeaf<i32, [{
65620818Swpaul  return Imm >= 0 && Imm < 16;
65720818Swpaul}]> {
65895658Sdes  let ParserMatchClass = Imm0_15AsmOperand;
65912891Swpaul}
66012891Swpaul
66112891Swpaul/// imm0_31 predicate - True if the 32-bit immediate is in the range [0,31].
66212891Swpauldef Imm0_31AsmOperand: ImmAsmOperand { let Name = "Imm0_31"; }
66312891Swpauldef imm0_31 : Operand<i32>, ImmLeaf<i32, [{
66412891Swpaul  return Imm >= 0 && Imm < 32;
66590298Sdes}]> {
66612891Swpaul  let ParserMatchClass = Imm0_31AsmOperand;
66712891Swpaul}
66812891Swpaul
66990297Sdes/// imm0_32 predicate - True if the 32-bit immediate is in the range [0,32].
67012891Swpauldef Imm0_32AsmOperand: ImmAsmOperand { let Name = "Imm0_32"; }
67112891Swpauldef imm0_32 : Operand<i32>, ImmLeaf<i32, [{
67212891Swpaul  return Imm >= 0 && Imm < 32;
67312891Swpaul}]> {
67412891Swpaul  let ParserMatchClass = Imm0_32AsmOperand;
67512891Swpaul}
67612891Swpaul
67712891Swpaul/// imm0_63 predicate - True if the 32-bit immediate is in the range [0,63].
67890298Sdesdef Imm0_63AsmOperand: ImmAsmOperand { let Name = "Imm0_63"; }
67990298Sdesdef imm0_63 : Operand<i32>, ImmLeaf<i32, [{
68012891Swpaul  return Imm >= 0 && Imm < 64;
68112891Swpaul}]> {
68212891Swpaul  let ParserMatchClass = Imm0_63AsmOperand;
68312891Swpaul}
68412891Swpaul
68512891Swpaul/// imm0_239 predicate - Immediate in the range [0,239].
68612891Swpauldef Imm0_239AsmOperand : ImmAsmOperand {
68712891Swpaul  let Name = "Imm0_239";
68812891Swpaul  let DiagnosticType = "ImmRange0_239";
68912891Swpaul}
69012891Swpauldef imm0_239 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 240; }]> {
69112891Swpaul  let ParserMatchClass = Imm0_239AsmOperand;
69213800Swpaul}
69312891Swpaul
69412891Swpaul/// imm0_255 predicate - Immediate in the range [0,255].
69512891Swpauldef Imm0_255AsmOperand : ImmAsmOperand { let Name = "Imm0_255"; }
69612891Swpauldef imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 256; }]> {
69712891Swpaul  let ParserMatchClass = Imm0_255AsmOperand;
69814304Swpaul}
69914304Swpaul
70014304Swpaul/// imm0_65535 - An immediate is in the range [0.65535].
70114304Swpauldef Imm0_65535AsmOperand: ImmAsmOperand { let Name = "Imm0_65535"; }
70212891Swpauldef imm0_65535 : Operand<i32>, ImmLeaf<i32, [{
70314304Swpaul  return Imm >= 0 && Imm < 65536;
70416044Swpaul}]> {
70530827Scharnier  let ParserMatchClass = Imm0_65535AsmOperand;
70612891Swpaul}
70712891Swpaul
70812891Swpaul// imm0_65535_neg - An immediate whose negative value is in the range [0.65535].
70912891Swpauldef imm0_65535_neg : Operand<i32>, ImmLeaf<i32, [{
71095658Sdes  return -Imm >= 0 && -Imm < 65536;
71114304Swpaul}]>;
71212891Swpaul
71312891Swpaul// imm0_65535_expr - For movt/movw - 16-bit immediate that can also reference
71412891Swpaul// a relocatable expression.
71512891Swpaul//
71612891Swpaul// FIXME: This really needs a Thumb version separate from the ARM version.
71712891Swpaul// While the range is the same, and can thus use the same match class,
71812891Swpaul// the encoding is different so it should have a different encoder method.
71912891Swpauldef Imm0_65535ExprAsmOperand: ImmAsmOperand { let Name = "Imm0_65535Expr"; }
72012891Swpauldef imm0_65535_expr : Operand<i32> {
72112891Swpaul  let EncoderMethod = "getHiLo16ImmOpValue";
72212891Swpaul  let ParserMatchClass = Imm0_65535ExprAsmOperand;
72312891Swpaul}
72412891Swpaul
72512891Swpauldef Imm256_65535ExprAsmOperand: ImmAsmOperand { let Name = "Imm256_65535Expr"; }
72612891Swpauldef imm256_65535_expr : Operand<i32> {
72712891Swpaul  let ParserMatchClass = Imm256_65535ExprAsmOperand;
72812891Swpaul}
72912891Swpaul
73015426Swpaul/// imm24b - True if the 32-bit immediate is encodable in 24 bits.
73112891Swpauldef Imm24bitAsmOperand: ImmAsmOperand { let Name = "Imm24bit"; }
73219161Swpauldef imm24b : Operand<i32>, ImmLeaf<i32, [{
73319161Swpaul  return Imm >= 0 && Imm <= 0xffffff;
73419161Swpaul}]> {
73512891Swpaul  let ParserMatchClass = Imm24bitAsmOperand;
73619161Swpaul}
73712891Swpaul
73812891Swpaul
73912891Swpaul/// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
74012891Swpaul/// e.g., 0xf000ffff
74112891Swpauldef BitfieldAsmOperand : AsmOperandClass {
74212891Swpaul  let Name = "Bitfield";
74312891Swpaul  let ParserMethod = "parseBitfield";
74412891Swpaul}
74590297Sdes
74612891Swpauldef bf_inv_mask_imm : Operand<i32>,
74712891Swpaul                      PatLeaf<(imm), [{
74812891Swpaul  return ARM::isBitFieldInvertedMask(N->getZExtValue());
74912891Swpaul}] > {
75012891Swpaul  let EncoderMethod = "getBitfieldInvertedMaskOpValue";
75112891Swpaul  let PrintMethod = "printBitfieldInvMaskImmOperand";
75212891Swpaul  let DecoderMethod = "DecodeBitfieldMaskOperand";
75312891Swpaul  let ParserMatchClass = BitfieldAsmOperand;
75412891Swpaul}
75512891Swpaul
75612891Swpauldef imm1_32_XFORM: SDNodeXForm<imm, [{
75712891Swpaul  return CurDAG->getTargetConstant((int)N->getZExtValue() - 1, MVT::i32);
75812891Swpaul}]>;
75912891Swpauldef Imm1_32AsmOperand: AsmOperandClass { let Name = "Imm1_32"; }
76012891Swpauldef imm1_32 : Operand<i32>, PatLeaf<(imm), [{
76112891Swpaul   uint64_t Imm = N->getZExtValue();
76212891Swpaul   return Imm > 0 && Imm <= 32;
76312891Swpaul }],
76412891Swpaul    imm1_32_XFORM> {
76512891Swpaul  let PrintMethod = "printImmPlusOneOperand";
76612891Swpaul  let ParserMatchClass = Imm1_32AsmOperand;
76712891Swpaul}
76812891Swpaul
76912891Swpauldef imm1_16_XFORM: SDNodeXForm<imm, [{
77012891Swpaul  return CurDAG->getTargetConstant((int)N->getZExtValue() - 1, MVT::i32);
77112891Swpaul}]>;
77214262Swpauldef Imm1_16AsmOperand: AsmOperandClass { let Name = "Imm1_16"; }
77314262Swpauldef imm1_16 : Operand<i32>, PatLeaf<(imm), [{ return Imm > 0 && Imm <= 16; }],
77414262Swpaul    imm1_16_XFORM> {
77514262Swpaul  let PrintMethod = "printImmPlusOneOperand";
77614262Swpaul  let ParserMatchClass = Imm1_16AsmOperand;
77714262Swpaul}
77814262Swpaul
77914262Swpaul// Define ARM specific addressing modes.
78014262Swpaul// addrmode_imm12 := reg +/- imm12
78114262Swpaul//
78214262Swpauldef MemImm12OffsetAsmOperand : AsmOperandClass { let Name = "MemImm12Offset"; }
78314262Swpaulclass AddrMode_Imm12 : Operand<i32>,
78414262Swpaul                     ComplexPattern<i32, 2, "SelectAddrModeImm12", []> {
78514262Swpaul  // 12-bit immediate operand. Note that instructions using this encode
78614262Swpaul  // #0 and #-0 differently. We flag #-0 as the magic value INT32_MIN. All other
78714262Swpaul  // immediate values are as normal.
78814262Swpaul
78914262Swpaul  let EncoderMethod = "getAddrModeImm12OpValue";
79014262Swpaul  let DecoderMethod = "DecodeAddrModeImm12Operand";
79114262Swpaul  let ParserMatchClass = MemImm12OffsetAsmOperand;
79214262Swpaul  let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
79314262Swpaul}
79414262Swpaul
79514262Swpauldef addrmode_imm12 : AddrMode_Imm12 {
79614262Swpaul  let PrintMethod = "printAddrModeImm12Operand<false>";
79714262Swpaul}
79814262Swpaul
79914262Swpauldef addrmode_imm12_pre : AddrMode_Imm12 {
80014262Swpaul  let PrintMethod = "printAddrModeImm12Operand<true>";
80114262Swpaul}
80214262Swpaul
80314262Swpaul// ldst_so_reg := reg +/- reg shop imm
80414262Swpaul//
80514262Swpauldef MemRegOffsetAsmOperand : AsmOperandClass { let Name = "MemRegOffset"; }
80614262Swpauldef ldst_so_reg : Operand<i32>,
80714262Swpaul                  ComplexPattern<i32, 3, "SelectLdStSOReg", []> {
80814304Swpaul  let EncoderMethod = "getLdStSORegOpValue";
80914304Swpaul  // FIXME: Simplify the printer
81014304Swpaul  let PrintMethod = "printAddrMode2Operand";
81114262Swpaul  let DecoderMethod = "DecodeSORegMemOperand";
81214262Swpaul  let ParserMatchClass = MemRegOffsetAsmOperand;
81314262Swpaul  let MIOperandInfo = (ops GPR:$base, GPRnopc:$offsreg, i32imm:$shift);
81414262Swpaul}
81514262Swpaul
81614262Swpaul// postidx_imm8 := +/- [0,255]
81714262Swpaul//
81814304Swpaul// 9 bit value:
81914304Swpaul//  {8}       1 is imm8 is non-negative. 0 otherwise.
82014262Swpaul//  {7-0}     [0,255] imm8 value.
82114262Swpauldef PostIdxImm8AsmOperand : AsmOperandClass { let Name = "PostIdxImm8"; }
82214262Swpauldef postidx_imm8 : Operand<i32> {
82314262Swpaul  let PrintMethod = "printPostIdxImm8Operand";
82414262Swpaul  let ParserMatchClass = PostIdxImm8AsmOperand;
82514262Swpaul  let MIOperandInfo = (ops i32imm);
82614262Swpaul}
82714262Swpaul
82814262Swpaul// postidx_imm8s4 := +/- [0,1020]
82914262Swpaul//
83095658Sdes// 9 bit value:
83114262Swpaul//  {8}       1 is imm8 is non-negative. 0 otherwise.
83214262Swpaul//  {7-0}     [0,255] imm8 value, scaled by 4.
83314262Swpauldef PostIdxImm8s4AsmOperand : AsmOperandClass { let Name = "PostIdxImm8s4"; }
83414262Swpauldef postidx_imm8s4 : Operand<i32> {
83514262Swpaul  let PrintMethod = "printPostIdxImm8s4Operand";
83614304Swpaul  let ParserMatchClass = PostIdxImm8s4AsmOperand;
83714304Swpaul  let MIOperandInfo = (ops i32imm);
83814304Swpaul}
83914262Swpaul
84014262Swpaul
84114262Swpaul// postidx_reg := +/- reg
84214262Swpaul//
84314262Swpauldef PostIdxRegAsmOperand : AsmOperandClass {
84414262Swpaul  let Name = "PostIdxReg";
84514262Swpaul  let ParserMethod = "parsePostIdxReg";
84614304Swpaul}
84714304Swpauldef postidx_reg : Operand<i32> {
84814304Swpaul  let EncoderMethod = "getPostIdxRegOpValue";
84914304Swpaul  let DecoderMethod = "DecodePostIdxReg";
85014262Swpaul  let PrintMethod = "printPostIdxRegOperand";
85114262Swpaul  let ParserMatchClass = PostIdxRegAsmOperand;
85214262Swpaul  let MIOperandInfo = (ops GPRnopc, i32imm);
85314262Swpaul}
85414262Swpaul
85514262Swpaul
85614262Swpaul// addrmode2 := reg +/- imm12
85714262Swpaul//           := reg +/- reg shop imm
85814262Swpaul//
85914262Swpaul// FIXME: addrmode2 should be refactored the rest of the way to always
86014262Swpaul// use explicit imm vs. reg versions above (addrmode_imm12 and ldst_so_reg).
86195658Sdesdef AddrMode2AsmOperand : AsmOperandClass { let Name = "AddrMode2"; }
86214262Swpauldef addrmode2 : Operand<i32>,
86314262Swpaul                ComplexPattern<i32, 3, "SelectAddrMode2", []> {
86414262Swpaul  let EncoderMethod = "getAddrMode2OpValue";
86514262Swpaul  let PrintMethod = "printAddrMode2Operand";
86614262Swpaul  let ParserMatchClass = AddrMode2AsmOperand;
86714304Swpaul  let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
86814304Swpaul}
86914304Swpaul
87014262Swpauldef PostIdxRegShiftedAsmOperand : AsmOperandClass {
87114262Swpaul  let Name = "PostIdxRegShifted";
87214262Swpaul  let ParserMethod = "parsePostIdxReg";
87314262Swpaul}
87414262Swpauldef am2offset_reg : Operand<i32>,
87514262Swpaul                ComplexPattern<i32, 2, "SelectAddrMode2OffsetReg",
87614262Swpaul                [], [SDNPWantRoot]> {
87714304Swpaul  let EncoderMethod = "getAddrMode2OffsetOpValue";
87814304Swpaul  let PrintMethod = "printAddrMode2OffsetOperand";
87914304Swpaul  // When using this for assembly, it's always as a post-index offset.
88014304Swpaul  let ParserMatchClass = PostIdxRegShiftedAsmOperand;
88114262Swpaul  let MIOperandInfo = (ops GPRnopc, i32imm);
88214262Swpaul}
88314262Swpaul
88414262Swpaul// FIXME: am2offset_imm should only need the immediate, not the GPR. Having
88514262Swpaul// the GPR is purely vestigal at this point.
88614262Swpauldef AM2OffsetImmAsmOperand : AsmOperandClass { let Name = "AM2OffsetImm"; }
88714262Swpauldef am2offset_imm : Operand<i32>,
88814262Swpaul                ComplexPattern<i32, 2, "SelectAddrMode2OffsetImm",
88914262Swpaul                [], [SDNPWantRoot]> {
89014262Swpaul  let EncoderMethod = "getAddrMode2OffsetOpValue";
89195658Sdes  let PrintMethod = "printAddrMode2OffsetOperand";
89214262Swpaul  let ParserMatchClass = AM2OffsetImmAsmOperand;
89314262Swpaul  let MIOperandInfo = (ops GPRnopc, i32imm);
89414262Swpaul}
89514262Swpaul
89614262Swpaul
89714304Swpaul// addrmode3 := reg +/- reg
89814304Swpaul// addrmode3 := reg +/- imm8
89914304Swpaul//
90014262Swpaul// FIXME: split into imm vs. reg versions.
90114262Swpauldef AddrMode3AsmOperand : AsmOperandClass { let Name = "AddrMode3"; }
90214262Swpaulclass AddrMode3 : Operand<i32>,
90314262Swpaul                  ComplexPattern<i32, 3, "SelectAddrMode3", []> {
90414262Swpaul  let EncoderMethod = "getAddrMode3OpValue";
90514262Swpaul  let ParserMatchClass = AddrMode3AsmOperand;
90614262Swpaul  let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
90714262Swpaul}
90814262Swpaul
90914262Swpauldef addrmode3 : AddrMode3
91014262Swpaul{
91114262Swpaul  let PrintMethod = "printAddrMode3Operand<false>";
91214262Swpaul}
91314262Swpaul
91414262Swpauldef addrmode3_pre : AddrMode3
91514262Swpaul{
91614262Swpaul  let PrintMethod = "printAddrMode3Operand<true>";
91714262Swpaul}
91814262Swpaul
91914262Swpaul// FIXME: split into imm vs. reg versions.
92014262Swpaul// FIXME: parser method to handle +/- register.
92114262Swpauldef AM3OffsetAsmOperand : AsmOperandClass {
92214262Swpaul  let Name = "AM3Offset";
92314262Swpaul  let ParserMethod = "parseAM3Offset";
92414262Swpaul}
92514262Swpauldef am3offset : Operand<i32>,
92614262Swpaul                ComplexPattern<i32, 2, "SelectAddrMode3Offset",
92714262Swpaul                               [], [SDNPWantRoot]> {
92814262Swpaul  let EncoderMethod = "getAddrMode3OffsetOpValue";
92914262Swpaul  let PrintMethod = "printAddrMode3OffsetOperand";
93014262Swpaul  let ParserMatchClass = AM3OffsetAsmOperand;
93114262Swpaul  let MIOperandInfo = (ops GPR, i32imm);
93214262Swpaul}
93314262Swpaul
93414262Swpaul// ldstm_mode := {ia, ib, da, db}
93514262Swpaul//
93614262Swpauldef ldstm_mode : OptionalDefOperand<OtherVT, (ops i32), (ops (i32 1))> {
93714262Swpaul  let EncoderMethod = "getLdStmModeOpValue";
93814262Swpaul  let PrintMethod = "printLdStmModeOperand";
93914262Swpaul}
94014262Swpaul
94114262Swpaul// addrmode5 := reg +/- imm8*4
94214262Swpaul//
94314262Swpauldef AddrMode5AsmOperand : AsmOperandClass { let Name = "AddrMode5"; }
94414262Swpaulclass AddrMode5 : Operand<i32>,
94514262Swpaul                  ComplexPattern<i32, 2, "SelectAddrMode5", []> {
94614262Swpaul  let EncoderMethod = "getAddrMode5OpValue";
94714262Swpaul  let DecoderMethod = "DecodeAddrMode5Operand";
94814262Swpaul  let ParserMatchClass = AddrMode5AsmOperand;
94914262Swpaul  let MIOperandInfo = (ops GPR:$base, i32imm);
95014262Swpaul}
95114262Swpaul
95214262Swpauldef addrmode5 : AddrMode5 {
95314262Swpaul   let PrintMethod = "printAddrMode5Operand<false>";
95414262Swpaul}
95514262Swpaul
95614262Swpauldef addrmode5_pre : AddrMode5 {
95714262Swpaul   let PrintMethod = "printAddrMode5Operand<true>";
95814262Swpaul}
95914262Swpaul
96014262Swpaul// addrmode6 := reg with optional alignment
96114262Swpaul//
96214262Swpauldef AddrMode6AsmOperand : AsmOperandClass { let Name = "AlignedMemory"; }
96314262Swpauldef addrmode6 : Operand<i32>,
96414262Swpaul                ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
96514262Swpaul  let PrintMethod = "printAddrMode6Operand";
96614262Swpaul  let MIOperandInfo = (ops GPR:$addr, i32imm:$align);
96714262Swpaul  let EncoderMethod = "getAddrMode6AddressOpValue";
96814262Swpaul  let DecoderMethod = "DecodeAddrMode6Operand";
96914262Swpaul  let ParserMatchClass = AddrMode6AsmOperand;
97014262Swpaul}
97114262Swpaul
97214262Swpauldef am6offset : Operand<i32>,
97314262Swpaul                ComplexPattern<i32, 1, "SelectAddrMode6Offset",
97414262Swpaul                               [], [SDNPWantRoot]> {
97514262Swpaul  let PrintMethod = "printAddrMode6OffsetOperand";
97614262Swpaul  let MIOperandInfo = (ops GPR);
97714262Swpaul  let EncoderMethod = "getAddrMode6OffsetOpValue";
97814262Swpaul  let DecoderMethod = "DecodeGPRRegisterClass";
97914262Swpaul}
98014262Swpaul
98114262Swpaul// Special version of addrmode6 to handle alignment encoding for VST1/VLD1
98214262Swpaul// (single element from one lane) for size 32.
98314262Swpauldef addrmode6oneL32 : Operand<i32>,
98414262Swpaul                ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
98514262Swpaul  let PrintMethod = "printAddrMode6Operand";
986  let MIOperandInfo = (ops GPR:$addr, i32imm);
987  let EncoderMethod = "getAddrMode6OneLane32AddressOpValue";
988}
989
990// Special version of addrmode6 to handle alignment encoding for VLD-dup
991// instructions, specifically VLD4-dup.
992def addrmode6dup : Operand<i32>,
993                ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
994  let PrintMethod = "printAddrMode6Operand";
995  let MIOperandInfo = (ops GPR:$addr, i32imm);
996  let EncoderMethod = "getAddrMode6DupAddressOpValue";
997  // FIXME: This is close, but not quite right. The alignment specifier is
998  // different.
999  let ParserMatchClass = AddrMode6AsmOperand;
1000}
1001
1002// addrmodepc := pc + reg
1003//
1004def addrmodepc : Operand<i32>,
1005                 ComplexPattern<i32, 2, "SelectAddrModePC", []> {
1006  let PrintMethod = "printAddrModePCOperand";
1007  let MIOperandInfo = (ops GPR, i32imm);
1008}
1009
1010// addr_offset_none := reg
1011//
1012def MemNoOffsetAsmOperand : AsmOperandClass { let Name = "MemNoOffset"; }
1013def addr_offset_none : Operand<i32>,
1014                       ComplexPattern<i32, 1, "SelectAddrOffsetNone", []> {
1015  let PrintMethod = "printAddrMode7Operand";
1016  let DecoderMethod = "DecodeAddrMode7Operand";
1017  let ParserMatchClass = MemNoOffsetAsmOperand;
1018  let MIOperandInfo = (ops GPR:$base);
1019}
1020
1021def nohash_imm : Operand<i32> {
1022  let PrintMethod = "printNoHashImmediate";
1023}
1024
1025def CoprocNumAsmOperand : AsmOperandClass {
1026  let Name = "CoprocNum";
1027  let ParserMethod = "parseCoprocNumOperand";
1028}
1029def p_imm : Operand<i32> {
1030  let PrintMethod = "printPImmediate";
1031  let ParserMatchClass = CoprocNumAsmOperand;
1032  let DecoderMethod = "DecodeCoprocessor";
1033}
1034
1035def CoprocRegAsmOperand : AsmOperandClass {
1036  let Name = "CoprocReg";
1037  let ParserMethod = "parseCoprocRegOperand";
1038}
1039def c_imm : Operand<i32> {
1040  let PrintMethod = "printCImmediate";
1041  let ParserMatchClass = CoprocRegAsmOperand;
1042}
1043def CoprocOptionAsmOperand : AsmOperandClass {
1044  let Name = "CoprocOption";
1045  let ParserMethod = "parseCoprocOptionOperand";
1046}
1047def coproc_option_imm : Operand<i32> {
1048  let PrintMethod = "printCoprocOptionImm";
1049  let ParserMatchClass = CoprocOptionAsmOperand;
1050}
1051
1052//===----------------------------------------------------------------------===//
1053
1054include "ARMInstrFormats.td"
1055
1056//===----------------------------------------------------------------------===//
1057// Multiclass helpers...
1058//
1059
1060/// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
1061/// binop that produces a value.
1062let TwoOperandAliasConstraint = "$Rn = $Rd" in
1063multiclass AsI1_bin_irs<bits<4> opcod, string opc,
1064                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1065                        PatFrag opnode, bit Commutable = 0> {
1066  // The register-immediate version is re-materializable. This is useful
1067  // in particular for taking the address of a local.
1068  let isReMaterializable = 1 in {
1069  def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
1070               iii, opc, "\t$Rd, $Rn, $imm",
1071               [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]>,
1072           Sched<[WriteALU, ReadALU]> {
1073    bits<4> Rd;
1074    bits<4> Rn;
1075    bits<12> imm;
1076    let Inst{25} = 1;
1077    let Inst{19-16} = Rn;
1078    let Inst{15-12} = Rd;
1079    let Inst{11-0} = imm;
1080  }
1081  }
1082  def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
1083               iir, opc, "\t$Rd, $Rn, $Rm",
1084               [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]>,
1085           Sched<[WriteALU, ReadALU, ReadALU]> {
1086    bits<4> Rd;
1087    bits<4> Rn;
1088    bits<4> Rm;
1089    let Inst{25} = 0;
1090    let isCommutable = Commutable;
1091    let Inst{19-16} = Rn;
1092    let Inst{15-12} = Rd;
1093    let Inst{11-4} = 0b00000000;
1094    let Inst{3-0} = Rm;
1095  }
1096
1097  def rsi : AsI1<opcod, (outs GPR:$Rd),
1098               (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm,
1099               iis, opc, "\t$Rd, $Rn, $shift",
1100               [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_imm:$shift))]>,
1101            Sched<[WriteALUsi, ReadALU]> {
1102    bits<4> Rd;
1103    bits<4> Rn;
1104    bits<12> shift;
1105    let Inst{25} = 0;
1106    let Inst{19-16} = Rn;
1107    let Inst{15-12} = Rd;
1108    let Inst{11-5} = shift{11-5};
1109    let Inst{4} = 0;
1110    let Inst{3-0} = shift{3-0};
1111  }
1112
1113  def rsr : AsI1<opcod, (outs GPR:$Rd),
1114               (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm,
1115               iis, opc, "\t$Rd, $Rn, $shift",
1116               [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_reg:$shift))]>,
1117            Sched<[WriteALUsr, ReadALUsr]> {
1118    bits<4> Rd;
1119    bits<4> Rn;
1120    bits<12> shift;
1121    let Inst{25} = 0;
1122    let Inst{19-16} = Rn;
1123    let Inst{15-12} = Rd;
1124    let Inst{11-8} = shift{11-8};
1125    let Inst{7} = 0;
1126    let Inst{6-5} = shift{6-5};
1127    let Inst{4} = 1;
1128    let Inst{3-0} = shift{3-0};
1129  }
1130}
1131
1132/// AsI1_rbin_irs - Same as AsI1_bin_irs except the order of operands are
1133/// reversed.  The 'rr' form is only defined for the disassembler; for codegen
1134/// it is equivalent to the AsI1_bin_irs counterpart.
1135let TwoOperandAliasConstraint = "$Rn = $Rd" in
1136multiclass AsI1_rbin_irs<bits<4> opcod, string opc,
1137                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1138                        PatFrag opnode, bit Commutable = 0> {
1139  // The register-immediate version is re-materializable. This is useful
1140  // in particular for taking the address of a local.
1141  let isReMaterializable = 1 in {
1142  def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
1143               iii, opc, "\t$Rd, $Rn, $imm",
1144               [(set GPR:$Rd, (opnode so_imm:$imm, GPR:$Rn))]>,
1145           Sched<[WriteALU, ReadALU]> {
1146    bits<4> Rd;
1147    bits<4> Rn;
1148    bits<12> imm;
1149    let Inst{25} = 1;
1150    let Inst{19-16} = Rn;
1151    let Inst{15-12} = Rd;
1152    let Inst{11-0} = imm;
1153  }
1154  }
1155  def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
1156               iir, opc, "\t$Rd, $Rn, $Rm",
1157               [/* pattern left blank */]>,
1158           Sched<[WriteALU, ReadALU, ReadALU]> {
1159    bits<4> Rd;
1160    bits<4> Rn;
1161    bits<4> Rm;
1162    let Inst{11-4} = 0b00000000;
1163    let Inst{25} = 0;
1164    let Inst{3-0} = Rm;
1165    let Inst{15-12} = Rd;
1166    let Inst{19-16} = Rn;
1167  }
1168
1169  def rsi : AsI1<opcod, (outs GPR:$Rd),
1170               (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm,
1171               iis, opc, "\t$Rd, $Rn, $shift",
1172               [(set GPR:$Rd, (opnode so_reg_imm:$shift, GPR:$Rn))]>,
1173            Sched<[WriteALUsi, ReadALU]> {
1174    bits<4> Rd;
1175    bits<4> Rn;
1176    bits<12> shift;
1177    let Inst{25} = 0;
1178    let Inst{19-16} = Rn;
1179    let Inst{15-12} = Rd;
1180    let Inst{11-5} = shift{11-5};
1181    let Inst{4} = 0;
1182    let Inst{3-0} = shift{3-0};
1183  }
1184
1185  def rsr : AsI1<opcod, (outs GPR:$Rd),
1186               (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm,
1187               iis, opc, "\t$Rd, $Rn, $shift",
1188               [(set GPR:$Rd, (opnode so_reg_reg:$shift, GPR:$Rn))]>,
1189            Sched<[WriteALUsr, ReadALUsr]> {
1190    bits<4> Rd;
1191    bits<4> Rn;
1192    bits<12> shift;
1193    let Inst{25} = 0;
1194    let Inst{19-16} = Rn;
1195    let Inst{15-12} = Rd;
1196    let Inst{11-8} = shift{11-8};
1197    let Inst{7} = 0;
1198    let Inst{6-5} = shift{6-5};
1199    let Inst{4} = 1;
1200    let Inst{3-0} = shift{3-0};
1201  }
1202}
1203
1204/// AsI1_bin_s_irs - Same as AsI1_bin_irs except it sets the 's' bit by default.
1205///
1206/// These opcodes will be converted to the real non-S opcodes by
1207/// AdjustInstrPostInstrSelection after giving them an optional CPSR operand.
1208let hasPostISelHook = 1, Defs = [CPSR] in {
1209multiclass AsI1_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
1210                          InstrItinClass iis, PatFrag opnode,
1211                          bit Commutable = 0> {
1212  def ri : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm, pred:$p),
1213                         4, iii,
1214                         [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, so_imm:$imm))]>,
1215                         Sched<[WriteALU, ReadALU]>;
1216
1217  def rr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, pred:$p),
1218                         4, iir,
1219                         [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, GPR:$Rm))]>,
1220                         Sched<[WriteALU, ReadALU, ReadALU]> {
1221    let isCommutable = Commutable;
1222  }
1223  def rsi : ARMPseudoInst<(outs GPR:$Rd),
1224                          (ins GPR:$Rn, so_reg_imm:$shift, pred:$p),
1225                          4, iis,
1226                          [(set GPR:$Rd, CPSR, (opnode GPR:$Rn,
1227                                                so_reg_imm:$shift))]>,
1228                          Sched<[WriteALUsi, ReadALU]>;
1229
1230  def rsr : ARMPseudoInst<(outs GPR:$Rd),
1231                          (ins GPR:$Rn, so_reg_reg:$shift, pred:$p),
1232                          4, iis,
1233                          [(set GPR:$Rd, CPSR, (opnode GPR:$Rn,
1234                                                so_reg_reg:$shift))]>,
1235                          Sched<[WriteALUSsr, ReadALUsr]>;
1236}
1237}
1238
1239/// AsI1_rbin_s_is - Same as AsI1_bin_s_irs, except selection DAG
1240/// operands are reversed.
1241let hasPostISelHook = 1, Defs = [CPSR] in {
1242multiclass AsI1_rbin_s_is<InstrItinClass iii, InstrItinClass iir,
1243                          InstrItinClass iis, PatFrag opnode,
1244                          bit Commutable = 0> {
1245  def ri : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm, pred:$p),
1246                         4, iii,
1247                         [(set GPR:$Rd, CPSR, (opnode so_imm:$imm, GPR:$Rn))]>,
1248           Sched<[WriteALU, ReadALU]>;
1249
1250  def rsi : ARMPseudoInst<(outs GPR:$Rd),
1251                          (ins GPR:$Rn, so_reg_imm:$shift, pred:$p),
1252                          4, iis,
1253                          [(set GPR:$Rd, CPSR, (opnode so_reg_imm:$shift,
1254                                             GPR:$Rn))]>,
1255            Sched<[WriteALUsi, ReadALU]>;
1256
1257  def rsr : ARMPseudoInst<(outs GPR:$Rd),
1258                          (ins GPR:$Rn, so_reg_reg:$shift, pred:$p),
1259                          4, iis,
1260                          [(set GPR:$Rd, CPSR, (opnode so_reg_reg:$shift,
1261                                             GPR:$Rn))]>,
1262            Sched<[WriteALUSsr, ReadALUsr]>;
1263}
1264}
1265
1266/// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
1267/// patterns. Similar to AsI1_bin_irs except the instruction does not produce
1268/// a explicit result, only implicitly set CPSR.
1269let isCompare = 1, Defs = [CPSR] in {
1270multiclass AI1_cmp_irs<bits<4> opcod, string opc,
1271                     InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1272                       PatFrag opnode, bit Commutable = 0> {
1273  def ri : AI1<opcod, (outs), (ins GPR:$Rn, so_imm:$imm), DPFrm, iii,
1274               opc, "\t$Rn, $imm",
1275               [(opnode GPR:$Rn, so_imm:$imm)]>,
1276           Sched<[WriteCMP, ReadALU]> {
1277    bits<4> Rn;
1278    bits<12> imm;
1279    let Inst{25} = 1;
1280    let Inst{20} = 1;
1281    let Inst{19-16} = Rn;
1282    let Inst{15-12} = 0b0000;
1283    let Inst{11-0} = imm;
1284
1285    let Unpredictable{15-12} = 0b1111;
1286  }
1287  def rr : AI1<opcod, (outs), (ins GPR:$Rn, GPR:$Rm), DPFrm, iir,
1288               opc, "\t$Rn, $Rm",
1289               [(opnode GPR:$Rn, GPR:$Rm)]>,
1290           Sched<[WriteCMP, ReadALU, ReadALU]> {
1291    bits<4> Rn;
1292    bits<4> Rm;
1293    let isCommutable = Commutable;
1294    let Inst{25} = 0;
1295    let Inst{20} = 1;
1296    let Inst{19-16} = Rn;
1297    let Inst{15-12} = 0b0000;
1298    let Inst{11-4} = 0b00000000;
1299    let Inst{3-0} = Rm;
1300
1301    let Unpredictable{15-12} = 0b1111;
1302  }
1303  def rsi : AI1<opcod, (outs),
1304               (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm, iis,
1305               opc, "\t$Rn, $shift",
1306               [(opnode GPR:$Rn, so_reg_imm:$shift)]>,
1307            Sched<[WriteCMPsi, ReadALU]> {
1308    bits<4> Rn;
1309    bits<12> shift;
1310    let Inst{25} = 0;
1311    let Inst{20} = 1;
1312    let Inst{19-16} = Rn;
1313    let Inst{15-12} = 0b0000;
1314    let Inst{11-5} = shift{11-5};
1315    let Inst{4} = 0;
1316    let Inst{3-0} = shift{3-0};
1317
1318    let Unpredictable{15-12} = 0b1111;
1319  }
1320  def rsr : AI1<opcod, (outs),
1321               (ins GPRnopc:$Rn, so_reg_reg:$shift), DPSoRegRegFrm, iis,
1322               opc, "\t$Rn, $shift",
1323               [(opnode GPRnopc:$Rn, so_reg_reg:$shift)]>,
1324            Sched<[WriteCMPsr, ReadALU]> {
1325    bits<4> Rn;
1326    bits<12> shift;
1327    let Inst{25} = 0;
1328    let Inst{20} = 1;
1329    let Inst{19-16} = Rn;
1330    let Inst{15-12} = 0b0000;
1331    let Inst{11-8} = shift{11-8};
1332    let Inst{7} = 0;
1333    let Inst{6-5} = shift{6-5};
1334    let Inst{4} = 1;
1335    let Inst{3-0} = shift{3-0};
1336
1337    let Unpredictable{15-12} = 0b1111;
1338  }
1339
1340}
1341}
1342
1343/// AI_ext_rrot - A unary operation with two forms: one whose operand is a
1344/// register and one whose operand is a register rotated by 8/16/24.
1345/// FIXME: Remove the 'r' variant. Its rot_imm is zero.
1346class AI_ext_rrot<bits<8> opcod, string opc, PatFrag opnode>
1347  : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPRnopc:$Rm, rot_imm:$rot),
1348          IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
1349          [(set GPRnopc:$Rd, (opnode (rotr GPRnopc:$Rm, rot_imm:$rot)))]>,
1350       Requires<[IsARM, HasV6]>, Sched<[WriteALUsi]> {
1351  bits<4> Rd;
1352  bits<4> Rm;
1353  bits<2> rot;
1354  let Inst{19-16} = 0b1111;
1355  let Inst{15-12} = Rd;
1356  let Inst{11-10} = rot;
1357  let Inst{3-0}   = Rm;
1358}
1359
1360class AI_ext_rrot_np<bits<8> opcod, string opc>
1361  : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPRnopc:$Rm, rot_imm:$rot),
1362          IIC_iEXTr, opc, "\t$Rd, $Rm$rot", []>,
1363       Requires<[IsARM, HasV6]>, Sched<[WriteALUsi]> {
1364  bits<2> rot;
1365  let Inst{19-16} = 0b1111;
1366  let Inst{11-10} = rot;
1367 }
1368
1369/// AI_exta_rrot - A binary operation with two forms: one whose operand is a
1370/// register and one whose operand is a register rotated by 8/16/24.
1371class AI_exta_rrot<bits<8> opcod, string opc, PatFrag opnode>
1372  : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPR:$Rn, GPRnopc:$Rm, rot_imm:$rot),
1373          IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm$rot",
1374          [(set GPRnopc:$Rd, (opnode GPR:$Rn,
1375                                     (rotr GPRnopc:$Rm, rot_imm:$rot)))]>,
1376        Requires<[IsARM, HasV6]>, Sched<[WriteALUsr]> {
1377  bits<4> Rd;
1378  bits<4> Rm;
1379  bits<4> Rn;
1380  bits<2> rot;
1381  let Inst{19-16} = Rn;
1382  let Inst{15-12} = Rd;
1383  let Inst{11-10} = rot;
1384  let Inst{9-4}   = 0b000111;
1385  let Inst{3-0}   = Rm;
1386}
1387
1388class AI_exta_rrot_np<bits<8> opcod, string opc>
1389  : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPR:$Rn, GPRnopc:$Rm, rot_imm:$rot),
1390          IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
1391       Requires<[IsARM, HasV6]>, Sched<[WriteALUsr]> {
1392  bits<4> Rn;
1393  bits<2> rot;
1394  let Inst{19-16} = Rn;
1395  let Inst{11-10} = rot;
1396}
1397
1398/// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.
1399let TwoOperandAliasConstraint = "$Rn = $Rd" in
1400multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
1401                             bit Commutable = 0> {
1402  let hasPostISelHook = 1, Defs = [CPSR], Uses = [CPSR] in {
1403  def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1404                DPFrm, IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
1405               [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, so_imm:$imm, CPSR))]>,
1406               Requires<[IsARM]>,
1407           Sched<[WriteALU, ReadALU]> {
1408    bits<4> Rd;
1409    bits<4> Rn;
1410    bits<12> imm;
1411    let Inst{25} = 1;
1412    let Inst{15-12} = Rd;
1413    let Inst{19-16} = Rn;
1414    let Inst{11-0} = imm;
1415  }
1416  def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1417                DPFrm, IIC_iALUr, opc, "\t$Rd, $Rn, $Rm",
1418               [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, GPR:$Rm, CPSR))]>,
1419               Requires<[IsARM]>,
1420           Sched<[WriteALU, ReadALU, ReadALU]> {
1421    bits<4> Rd;
1422    bits<4> Rn;
1423    bits<4> Rm;
1424    let Inst{11-4} = 0b00000000;
1425    let Inst{25} = 0;
1426    let isCommutable = Commutable;
1427    let Inst{3-0} = Rm;
1428    let Inst{15-12} = Rd;
1429    let Inst{19-16} = Rn;
1430  }
1431  def rsi : AsI1<opcod, (outs GPR:$Rd),
1432                (ins GPR:$Rn, so_reg_imm:$shift),
1433                DPSoRegImmFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1434              [(set GPR:$Rd, CPSR, (opnode GPR:$Rn, so_reg_imm:$shift, CPSR))]>,
1435               Requires<[IsARM]>,
1436            Sched<[WriteALUsi, ReadALU]> {
1437    bits<4> Rd;
1438    bits<4> Rn;
1439    bits<12> shift;
1440    let Inst{25} = 0;
1441    let Inst{19-16} = Rn;
1442    let Inst{15-12} = Rd;
1443    let Inst{11-5} = shift{11-5};
1444    let Inst{4} = 0;
1445    let Inst{3-0} = shift{3-0};
1446  }
1447  def rsr : AsI1<opcod, (outs GPRnopc:$Rd),
1448                (ins GPRnopc:$Rn, so_reg_reg:$shift),
1449                DPSoRegRegFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1450              [(set GPRnopc:$Rd, CPSR,
1451                    (opnode GPRnopc:$Rn, so_reg_reg:$shift, CPSR))]>,
1452               Requires<[IsARM]>,
1453            Sched<[WriteALUsr, ReadALUsr]> {
1454    bits<4> Rd;
1455    bits<4> Rn;
1456    bits<12> shift;
1457    let Inst{25} = 0;
1458    let Inst{19-16} = Rn;
1459    let Inst{15-12} = Rd;
1460    let Inst{11-8} = shift{11-8};
1461    let Inst{7} = 0;
1462    let Inst{6-5} = shift{6-5};
1463    let Inst{4} = 1;
1464    let Inst{3-0} = shift{3-0};
1465  }
1466  }
1467}
1468
1469/// AI1_rsc_irs - Define instructions and patterns for rsc
1470let TwoOperandAliasConstraint = "$Rn = $Rd" in
1471multiclass AI1_rsc_irs<bits<4> opcod, string opc, PatFrag opnode> {
1472  let hasPostISelHook = 1, Defs = [CPSR], Uses = [CPSR] in {
1473  def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1474                DPFrm, IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
1475               [(set GPR:$Rd, CPSR, (opnode so_imm:$imm, GPR:$Rn, CPSR))]>,
1476               Requires<[IsARM]>,
1477           Sched<[WriteALU, ReadALU]> {
1478    bits<4> Rd;
1479    bits<4> Rn;
1480    bits<12> imm;
1481    let Inst{25} = 1;
1482    let Inst{15-12} = Rd;
1483    let Inst{19-16} = Rn;
1484    let Inst{11-0} = imm;
1485  }
1486  def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1487                DPFrm, IIC_iALUr, opc, "\t$Rd, $Rn, $Rm",
1488               [/* pattern left blank */]>,
1489           Sched<[WriteALU, ReadALU, ReadALU]> {
1490    bits<4> Rd;
1491    bits<4> Rn;
1492    bits<4> Rm;
1493    let Inst{11-4} = 0b00000000;
1494    let Inst{25} = 0;
1495    let Inst{3-0} = Rm;
1496    let Inst{15-12} = Rd;
1497    let Inst{19-16} = Rn;
1498  }
1499  def rsi : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_imm:$shift),
1500                DPSoRegImmFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1501              [(set GPR:$Rd, CPSR, (opnode so_reg_imm:$shift, GPR:$Rn, CPSR))]>,
1502               Requires<[IsARM]>,
1503            Sched<[WriteALUsi, ReadALU]> {
1504    bits<4> Rd;
1505    bits<4> Rn;
1506    bits<12> shift;
1507    let Inst{25} = 0;
1508    let Inst{19-16} = Rn;
1509    let Inst{15-12} = Rd;
1510    let Inst{11-5} = shift{11-5};
1511    let Inst{4} = 0;
1512    let Inst{3-0} = shift{3-0};
1513  }
1514  def rsr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_reg:$shift),
1515                DPSoRegRegFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1516              [(set GPR:$Rd, CPSR, (opnode so_reg_reg:$shift, GPR:$Rn, CPSR))]>,
1517               Requires<[IsARM]>,
1518            Sched<[WriteALUsr, ReadALUsr]> {
1519    bits<4> Rd;
1520    bits<4> Rn;
1521    bits<12> shift;
1522    let Inst{25} = 0;
1523    let Inst{19-16} = Rn;
1524    let Inst{15-12} = Rd;
1525    let Inst{11-8} = shift{11-8};
1526    let Inst{7} = 0;
1527    let Inst{6-5} = shift{6-5};
1528    let Inst{4} = 1;
1529    let Inst{3-0} = shift{3-0};
1530  }
1531  }
1532}
1533
1534let canFoldAsLoad = 1, isReMaterializable = 1 in {
1535multiclass AI_ldr1<bit isByte, string opc, InstrItinClass iii,
1536           InstrItinClass iir, PatFrag opnode> {
1537  // Note: We use the complex addrmode_imm12 rather than just an input
1538  // GPR and a constrained immediate so that we can use this to match
1539  // frame index references and avoid matching constant pool references.
1540  def i12: AI2ldst<0b010, 1, isByte, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
1541                   AddrMode_i12, LdFrm, iii, opc, "\t$Rt, $addr",
1542                  [(set GPR:$Rt, (opnode addrmode_imm12:$addr))]> {
1543    bits<4>  Rt;
1544    bits<17> addr;
1545    let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1546    let Inst{19-16} = addr{16-13};  // Rn
1547    let Inst{15-12} = Rt;
1548    let Inst{11-0}  = addr{11-0};   // imm12
1549  }
1550  def rs : AI2ldst<0b011, 1, isByte, (outs GPR:$Rt), (ins ldst_so_reg:$shift),
1551                  AddrModeNone, LdFrm, iir, opc, "\t$Rt, $shift",
1552                 [(set GPR:$Rt, (opnode ldst_so_reg:$shift))]> {
1553    bits<4>  Rt;
1554    bits<17> shift;
1555    let shift{4}    = 0;            // Inst{4} = 0
1556    let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1557    let Inst{19-16} = shift{16-13}; // Rn
1558    let Inst{15-12} = Rt;
1559    let Inst{11-0}  = shift{11-0};
1560  }
1561}
1562}
1563
1564let canFoldAsLoad = 1, isReMaterializable = 1 in {
1565multiclass AI_ldr1nopc<bit isByte, string opc, InstrItinClass iii,
1566           InstrItinClass iir, PatFrag opnode> {
1567  // Note: We use the complex addrmode_imm12 rather than just an input
1568  // GPR and a constrained immediate so that we can use this to match
1569  // frame index references and avoid matching constant pool references.
1570  def i12: AI2ldst<0b010, 1, isByte, (outs GPRnopc:$Rt),
1571                   (ins addrmode_imm12:$addr),
1572                   AddrMode_i12, LdFrm, iii, opc, "\t$Rt, $addr",
1573                   [(set GPRnopc:$Rt, (opnode addrmode_imm12:$addr))]> {
1574    bits<4>  Rt;
1575    bits<17> addr;
1576    let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1577    let Inst{19-16} = addr{16-13};  // Rn
1578    let Inst{15-12} = Rt;
1579    let Inst{11-0}  = addr{11-0};   // imm12
1580  }
1581  def rs : AI2ldst<0b011, 1, isByte, (outs GPRnopc:$Rt),
1582                   (ins ldst_so_reg:$shift),
1583                   AddrModeNone, LdFrm, iir, opc, "\t$Rt, $shift",
1584                   [(set GPRnopc:$Rt, (opnode ldst_so_reg:$shift))]> {
1585    bits<4>  Rt;
1586    bits<17> shift;
1587    let shift{4}    = 0;            // Inst{4} = 0
1588    let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1589    let Inst{19-16} = shift{16-13}; // Rn
1590    let Inst{15-12} = Rt;
1591    let Inst{11-0}  = shift{11-0};
1592  }
1593}
1594}
1595
1596
1597multiclass AI_str1<bit isByte, string opc, InstrItinClass iii,
1598           InstrItinClass iir, PatFrag opnode> {
1599  // Note: We use the complex addrmode_imm12 rather than just an input
1600  // GPR and a constrained immediate so that we can use this to match
1601  // frame index references and avoid matching constant pool references.
1602  def i12 : AI2ldst<0b010, 0, isByte, (outs),
1603                   (ins GPR:$Rt, addrmode_imm12:$addr),
1604                   AddrMode_i12, StFrm, iii, opc, "\t$Rt, $addr",
1605                  [(opnode GPR:$Rt, addrmode_imm12:$addr)]> {
1606    bits<4> Rt;
1607    bits<17> addr;
1608    let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1609    let Inst{19-16} = addr{16-13};  // Rn
1610    let Inst{15-12} = Rt;
1611    let Inst{11-0}  = addr{11-0};   // imm12
1612  }
1613  def rs : AI2ldst<0b011, 0, isByte, (outs), (ins GPR:$Rt, ldst_so_reg:$shift),
1614                  AddrModeNone, StFrm, iir, opc, "\t$Rt, $shift",
1615                 [(opnode GPR:$Rt, ldst_so_reg:$shift)]> {
1616    bits<4> Rt;
1617    bits<17> shift;
1618    let shift{4}    = 0;            // Inst{4} = 0
1619    let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1620    let Inst{19-16} = shift{16-13}; // Rn
1621    let Inst{15-12} = Rt;
1622    let Inst{11-0}  = shift{11-0};
1623  }
1624}
1625
1626multiclass AI_str1nopc<bit isByte, string opc, InstrItinClass iii,
1627           InstrItinClass iir, PatFrag opnode> {
1628  // Note: We use the complex addrmode_imm12 rather than just an input
1629  // GPR and a constrained immediate so that we can use this to match
1630  // frame index references and avoid matching constant pool references.
1631  def i12 : AI2ldst<0b010, 0, isByte, (outs),
1632                   (ins GPRnopc:$Rt, addrmode_imm12:$addr),
1633                   AddrMode_i12, StFrm, iii, opc, "\t$Rt, $addr",
1634                  [(opnode GPRnopc:$Rt, addrmode_imm12:$addr)]> {
1635    bits<4> Rt;
1636    bits<17> addr;
1637    let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1638    let Inst{19-16} = addr{16-13};  // Rn
1639    let Inst{15-12} = Rt;
1640    let Inst{11-0}  = addr{11-0};   // imm12
1641  }
1642  def rs : AI2ldst<0b011, 0, isByte, (outs),
1643                   (ins GPRnopc:$Rt, ldst_so_reg:$shift),
1644                   AddrModeNone, StFrm, iir, opc, "\t$Rt, $shift",
1645                   [(opnode GPRnopc:$Rt, ldst_so_reg:$shift)]> {
1646    bits<4> Rt;
1647    bits<17> shift;
1648    let shift{4}    = 0;            // Inst{4} = 0
1649    let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1650    let Inst{19-16} = shift{16-13}; // Rn
1651    let Inst{15-12} = Rt;
1652    let Inst{11-0}  = shift{11-0};
1653  }
1654}
1655
1656
1657//===----------------------------------------------------------------------===//
1658// Instructions
1659//===----------------------------------------------------------------------===//
1660
1661//===----------------------------------------------------------------------===//
1662//  Miscellaneous Instructions.
1663//
1664
1665/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
1666/// the function.  The first operand is the ID# for this instruction, the second
1667/// is the index into the MachineConstantPool that this is, the third is the
1668/// size in bytes of this constant pool entry.
1669let neverHasSideEffects = 1, isNotDuplicable = 1 in
1670def CONSTPOOL_ENTRY :
1671PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
1672                    i32imm:$size), NoItinerary, []>;
1673
1674// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
1675// from removing one half of the matched pairs. That breaks PEI, which assumes
1676// these will always be in pairs, and asserts if it finds otherwise. Better way?
1677let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
1678def ADJCALLSTACKUP :
1679PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p), NoItinerary,
1680           [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
1681
1682def ADJCALLSTACKDOWN :
1683PseudoInst<(outs), (ins i32imm:$amt, pred:$p), NoItinerary,
1684           [(ARMcallseq_start timm:$amt)]>;
1685}
1686
1687def HINT : AI<(outs), (ins imm0_239:$imm), MiscFrm, NoItinerary,
1688              "hint", "\t$imm", []>, Requires<[IsARM, HasV6]> {
1689  bits<8> imm;
1690  let Inst{27-8} = 0b00110010000011110000;
1691  let Inst{7-0} = imm;
1692}
1693
1694def : InstAlias<"nop$p", (HINT 0, pred:$p)>, Requires<[IsARM, HasV6T2]>;
1695def : InstAlias<"yield$p", (HINT 1, pred:$p)>, Requires<[IsARM, HasV6T2]>;
1696def : InstAlias<"wfe$p", (HINT 2, pred:$p)>, Requires<[IsARM, HasV6T2]>;
1697def : InstAlias<"wfi$p", (HINT 3, pred:$p)>, Requires<[IsARM, HasV6T2]>;
1698def : InstAlias<"sev$p", (HINT 4, pred:$p)>, Requires<[IsARM, HasV6T2]>;
1699def : InstAlias<"sevl$p", (HINT 5, pred:$p)>, Requires<[IsARM, HasV8]>;
1700
1701def : Pat<(int_arm_sevl), (HINT 5)>;
1702
1703def SEL : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm, NoItinerary, "sel",
1704             "\t$Rd, $Rn, $Rm", []>, Requires<[IsARM, HasV6]> {
1705  bits<4> Rd;
1706  bits<4> Rn;
1707  bits<4> Rm;
1708  let Inst{3-0} = Rm;
1709  let Inst{15-12} = Rd;
1710  let Inst{19-16} = Rn;
1711  let Inst{27-20} = 0b01101000;
1712  let Inst{7-4} = 0b1011;
1713  let Inst{11-8} = 0b1111;
1714  let Unpredictable{11-8} = 0b1111;
1715}
1716
1717// The 16-bit operand $val can be used by a debugger to store more information
1718// about the breakpoint.
1719def BKPT : AInoP<(outs), (ins imm0_65535:$val), MiscFrm, NoItinerary,
1720                 "bkpt", "\t$val", []>, Requires<[IsARM]> {
1721  bits<16> val;
1722  let Inst{3-0} = val{3-0};
1723  let Inst{19-8} = val{15-4};
1724  let Inst{27-20} = 0b00010010;
1725  let Inst{31-28} = 0xe; // AL
1726  let Inst{7-4} = 0b0111;
1727}
1728
1729def HLT : AInoP<(outs), (ins imm0_65535:$val), MiscFrm, NoItinerary,
1730                 "hlt", "\t$val", []>, Requires<[IsARM, HasV8]> {
1731  bits<16> val;
1732  let Inst{3-0} = val{3-0};
1733  let Inst{19-8} = val{15-4};
1734  let Inst{27-20} = 0b00010000;
1735  let Inst{31-28} = 0xe; // AL
1736  let Inst{7-4} = 0b0111;
1737}
1738
1739// Change Processor State
1740// FIXME: We should use InstAlias to handle the optional operands.
1741class CPS<dag iops, string asm_ops>
1742  : AXI<(outs), iops, MiscFrm, NoItinerary, !strconcat("cps", asm_ops),
1743        []>, Requires<[IsARM]> {
1744  bits<2> imod;
1745  bits<3> iflags;
1746  bits<5> mode;
1747  bit M;
1748
1749  let Inst{31-28} = 0b1111;
1750  let Inst{27-20} = 0b00010000;
1751  let Inst{19-18} = imod;
1752  let Inst{17}    = M; // Enabled if mode is set;
1753  let Inst{16-9}  = 0b00000000;
1754  let Inst{8-6}   = iflags;
1755  let Inst{5}     = 0;
1756  let Inst{4-0}   = mode;
1757}
1758
1759let DecoderMethod = "DecodeCPSInstruction" in {
1760let M = 1 in
1761  def CPS3p : CPS<(ins imod_op:$imod, iflags_op:$iflags, imm0_31:$mode),
1762                  "$imod\t$iflags, $mode">;
1763let mode = 0, M = 0 in
1764  def CPS2p : CPS<(ins imod_op:$imod, iflags_op:$iflags), "$imod\t$iflags">;
1765
1766let imod = 0, iflags = 0, M = 1 in
1767  def CPS1p : CPS<(ins imm0_31:$mode), "\t$mode">;
1768}
1769
1770// Preload signals the memory system of possible future data/instruction access.
1771multiclass APreLoad<bits<1> read, bits<1> data, string opc> {
1772
1773  def i12 : AXI<(outs), (ins addrmode_imm12:$addr), MiscFrm, IIC_Preload,
1774                !strconcat(opc, "\t$addr"),
1775                [(ARMPreload addrmode_imm12:$addr, (i32 read), (i32 data))]>,
1776                Sched<[WritePreLd]> {
1777    bits<4> Rt;
1778    bits<17> addr;
1779    let Inst{31-26} = 0b111101;
1780    let Inst{25} = 0; // 0 for immediate form
1781    let Inst{24} = data;
1782    let Inst{23} = addr{12};        // U (add = ('U' == 1))
1783    let Inst{22} = read;
1784    let Inst{21-20} = 0b01;
1785    let Inst{19-16} = addr{16-13};  // Rn
1786    let Inst{15-12} = 0b1111;
1787    let Inst{11-0}  = addr{11-0};   // imm12
1788  }
1789
1790  def rs : AXI<(outs), (ins ldst_so_reg:$shift), MiscFrm, IIC_Preload,
1791               !strconcat(opc, "\t$shift"),
1792               [(ARMPreload ldst_so_reg:$shift, (i32 read), (i32 data))]>,
1793               Sched<[WritePreLd]> {
1794    bits<17> shift;
1795    let Inst{31-26} = 0b111101;
1796    let Inst{25} = 1; // 1 for register form
1797    let Inst{24} = data;
1798    let Inst{23} = shift{12};    // U (add = ('U' == 1))
1799    let Inst{22} = read;
1800    let Inst{21-20} = 0b01;
1801    let Inst{19-16} = shift{16-13}; // Rn
1802    let Inst{15-12} = 0b1111;
1803    let Inst{11-0}  = shift{11-0};
1804    let Inst{4} = 0;
1805  }
1806}
1807
1808defm PLD  : APreLoad<1, 1, "pld">,  Requires<[IsARM]>;
1809defm PLDW : APreLoad<0, 1, "pldw">, Requires<[IsARM,HasV7,HasMP]>;
1810defm PLI  : APreLoad<1, 0, "pli">,  Requires<[IsARM,HasV7]>;
1811
1812def SETEND : AXI<(outs), (ins setend_op:$end), MiscFrm, NoItinerary,
1813                 "setend\t$end", []>, Requires<[IsARM]>, Deprecated<HasV8Ops> {
1814  bits<1> end;
1815  let Inst{31-10} = 0b1111000100000001000000;
1816  let Inst{9} = end;
1817  let Inst{8-0} = 0;
1818}
1819
1820def DBG : AI<(outs), (ins imm0_15:$opt), MiscFrm, NoItinerary, "dbg", "\t$opt",
1821             []>, Requires<[IsARM, HasV7]> {
1822  bits<4> opt;
1823  let Inst{27-4} = 0b001100100000111100001111;
1824  let Inst{3-0} = opt;
1825}
1826
1827/*
1828 * A5.4 Permanently UNDEFINED instructions.
1829 *
1830 * For most targets use UDF #65006, for which the OS will generate SIGTRAP.
1831 * Other UDF encodings generate SIGILL.
1832 *
1833 * NaCl's OS instead chooses an ARM UDF encoding that's also a UDF in Thumb.
1834 * Encoding A1:
1835 *  1110 0111 1111 iiii iiii iiii 1111 iiii
1836 * Encoding T1:
1837 *  1101 1110 iiii iiii
1838 * It uses the following encoding:
1839 *  1110 0111 1111 1110 1101 1110 1111 0000
1840 *  - In ARM: UDF #60896;
1841 *  - In Thumb: UDF #254 followed by a branch-to-self.
1842 */
1843let isBarrier = 1, isTerminator = 1 in
1844def TRAPNaCl : AXI<(outs), (ins), MiscFrm, NoItinerary,
1845               "trap", [(trap)]>,
1846           Requires<[IsARM,UseNaClTrap]> {
1847  let Inst = 0xe7fedef0;
1848}
1849let isBarrier = 1, isTerminator = 1 in
1850def TRAP : AXI<(outs), (ins), MiscFrm, NoItinerary,
1851               "trap", [(trap)]>,
1852           Requires<[IsARM,DontUseNaClTrap]> {
1853  let Inst = 0xe7ffdefe;
1854}
1855
1856// Address computation and loads and stores in PIC mode.
1857let isNotDuplicable = 1 in {
1858def PICADD  : ARMPseudoInst<(outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
1859                            4, IIC_iALUr,
1860                            [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>,
1861                            Sched<[WriteALU, ReadALU]>;
1862
1863let AddedComplexity = 10 in {
1864def PICLDR  : ARMPseudoInst<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1865                            4, IIC_iLoad_r,
1866                            [(set GPR:$dst, (load addrmodepc:$addr))]>;
1867
1868def PICLDRH : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1869                            4, IIC_iLoad_bh_r,
1870                            [(set GPR:$Rt, (zextloadi16 addrmodepc:$addr))]>;
1871
1872def PICLDRB : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1873                            4, IIC_iLoad_bh_r,
1874                            [(set GPR:$Rt, (zextloadi8 addrmodepc:$addr))]>;
1875
1876def PICLDRSH : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1877                            4, IIC_iLoad_bh_r,
1878                            [(set GPR:$Rt, (sextloadi16 addrmodepc:$addr))]>;
1879
1880def PICLDRSB : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1881                            4, IIC_iLoad_bh_r,
1882                            [(set GPR:$Rt, (sextloadi8 addrmodepc:$addr))]>;
1883}
1884let AddedComplexity = 10 in {
1885def PICSTR  : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1886      4, IIC_iStore_r, [(store GPR:$src, addrmodepc:$addr)]>;
1887
1888def PICSTRH : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1889      4, IIC_iStore_bh_r, [(truncstorei16 GPR:$src,
1890                                                   addrmodepc:$addr)]>;
1891
1892def PICSTRB : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1893      4, IIC_iStore_bh_r, [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
1894}
1895} // isNotDuplicable = 1
1896
1897
1898// LEApcrel - Load a pc-relative address into a register without offending the
1899// assembler.
1900let neverHasSideEffects = 1, isReMaterializable = 1 in
1901// The 'adr' mnemonic encodes differently if the label is before or after
1902// the instruction. The {24-21} opcode bits are set by the fixup, as we don't
1903// know until then which form of the instruction will be used.
1904def ADR : AI1<{0,?,?,0}, (outs GPR:$Rd), (ins adrlabel:$label),
1905                 MiscFrm, IIC_iALUi, "adr", "\t$Rd, $label", []>,
1906                 Sched<[WriteALU, ReadALU]> {
1907  bits<4> Rd;
1908  bits<14> label;
1909  let Inst{27-25} = 0b001;
1910  let Inst{24} = 0;
1911  let Inst{23-22} = label{13-12};
1912  let Inst{21} = 0;
1913  let Inst{20} = 0;
1914  let Inst{19-16} = 0b1111;
1915  let Inst{15-12} = Rd;
1916  let Inst{11-0} = label{11-0};
1917}
1918
1919let hasSideEffects = 1 in {
1920def LEApcrel : ARMPseudoInst<(outs GPR:$Rd), (ins i32imm:$label, pred:$p),
1921                    4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
1922
1923def LEApcrelJT : ARMPseudoInst<(outs GPR:$Rd),
1924                      (ins i32imm:$label, nohash_imm:$id, pred:$p),
1925                      4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
1926}
1927
1928//===----------------------------------------------------------------------===//
1929//  Control Flow Instructions.
1930//
1931
1932let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
1933  // ARMV4T and above
1934  def BX_RET : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1935                  "bx", "\tlr", [(ARMretflag)]>,
1936               Requires<[IsARM, HasV4T]>, Sched<[WriteBr]> {
1937    let Inst{27-0}  = 0b0001001011111111111100011110;
1938  }
1939
1940  // ARMV4 only
1941  def MOVPCLR : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1942                  "mov", "\tpc, lr", [(ARMretflag)]>,
1943               Requires<[IsARM, NoV4T]>, Sched<[WriteBr]> {
1944    let Inst{27-0} = 0b0001101000001111000000001110;
1945  }
1946
1947  // Exception return: N.b. doesn't set CPSR as far as we're concerned (it sets
1948  // the user-space one).
1949  def SUBS_PC_LR : ARMPseudoInst<(outs), (ins i32imm:$offset, pred:$p),
1950                                 4, IIC_Br,
1951                                 [(ARMintretflag imm:$offset)]>;
1952}
1953
1954// Indirect branches
1955let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1956  // ARMV4T and above
1957  def BX : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "bx\t$dst",
1958                  [(brind GPR:$dst)]>,
1959              Requires<[IsARM, HasV4T]>, Sched<[WriteBr]> {
1960    bits<4> dst;
1961    let Inst{31-4} = 0b1110000100101111111111110001;
1962    let Inst{3-0}  = dst;
1963  }
1964
1965  def BX_pred : AI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br,
1966                  "bx", "\t$dst", [/* pattern left blank */]>,
1967              Requires<[IsARM, HasV4T]>, Sched<[WriteBr]> {
1968    bits<4> dst;
1969    let Inst{27-4} = 0b000100101111111111110001;
1970    let Inst{3-0}  = dst;
1971  }
1972}
1973
1974// SP is marked as a use to prevent stack-pointer assignments that appear
1975// immediately before calls from potentially appearing dead.
1976let isCall = 1,
1977  // FIXME:  Do we really need a non-predicated version? If so, it should
1978  // at least be a pseudo instruction expanding to the predicated version
1979  // at MC lowering time.
1980  Defs = [LR], Uses = [SP] in {
1981  def BL  : ABXI<0b1011, (outs), (ins bl_target:$func),
1982                IIC_Br, "bl\t$func",
1983                [(ARMcall tglobaladdr:$func)]>,
1984            Requires<[IsARM]>, Sched<[WriteBrL]> {
1985    let Inst{31-28} = 0b1110;
1986    bits<24> func;
1987    let Inst{23-0} = func;
1988    let DecoderMethod = "DecodeBranchImmInstruction";
1989  }
1990
1991  def BL_pred : ABI<0b1011, (outs), (ins bl_target:$func),
1992                   IIC_Br, "bl", "\t$func",
1993                   [(ARMcall_pred tglobaladdr:$func)]>,
1994                Requires<[IsARM]>, Sched<[WriteBrL]> {
1995    bits<24> func;
1996    let Inst{23-0} = func;
1997    let DecoderMethod = "DecodeBranchImmInstruction";
1998  }
1999
2000  // ARMv5T and above
2001  def BLX : AXI<(outs), (ins GPR:$func), BrMiscFrm,
2002                IIC_Br, "blx\t$func",
2003                [(ARMcall GPR:$func)]>,
2004            Requires<[IsARM, HasV5T]>, Sched<[WriteBrL]> {
2005    bits<4> func;
2006    let Inst{31-4} = 0b1110000100101111111111110011;
2007    let Inst{3-0}  = func;
2008  }
2009
2010  def BLX_pred : AI<(outs), (ins GPR:$func), BrMiscFrm,
2011                    IIC_Br, "blx", "\t$func",
2012                    [(ARMcall_pred GPR:$func)]>,
2013                 Requires<[IsARM, HasV5T]>, Sched<[WriteBrL]> {
2014    bits<4> func;
2015    let Inst{27-4} = 0b000100101111111111110011;
2016    let Inst{3-0}  = func;
2017  }
2018
2019  // ARMv4T
2020  // Note: Restrict $func to the tGPR regclass to prevent it being in LR.
2021  def BX_CALL : ARMPseudoInst<(outs), (ins tGPR:$func),
2022                   8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
2023                   Requires<[IsARM, HasV4T]>, Sched<[WriteBr]>;
2024
2025  // ARMv4
2026  def BMOVPCRX_CALL : ARMPseudoInst<(outs), (ins tGPR:$func),
2027                   8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
2028                   Requires<[IsARM, NoV4T]>, Sched<[WriteBr]>;
2029
2030  // mov lr, pc; b if callee is marked noreturn to avoid confusing the
2031  // return stack predictor.
2032  def BMOVPCB_CALL : ARMPseudoInst<(outs), (ins bl_target:$func),
2033                               8, IIC_Br, [(ARMcall_nolink tglobaladdr:$func)]>,
2034                      Requires<[IsARM]>, Sched<[WriteBr]>;
2035}
2036
2037let isBranch = 1, isTerminator = 1 in {
2038  // FIXME: should be able to write a pattern for ARMBrcond, but can't use
2039  // a two-value operand where a dag node expects two operands. :(
2040  def Bcc : ABI<0b1010, (outs), (ins br_target:$target),
2041               IIC_Br, "b", "\t$target",
2042               [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>,
2043               Sched<[WriteBr]>  {
2044    bits<24> target;
2045    let Inst{23-0} = target;
2046    let DecoderMethod = "DecodeBranchImmInstruction";
2047  }
2048
2049  let isBarrier = 1 in {
2050    // B is "predicable" since it's just a Bcc with an 'always' condition.
2051    let isPredicable = 1 in
2052    // FIXME: We shouldn't need this pseudo at all. Just using Bcc directly
2053    // should be sufficient.
2054    // FIXME: Is B really a Barrier? That doesn't seem right.
2055    def B : ARMPseudoExpand<(outs), (ins br_target:$target), 4, IIC_Br,
2056                [(br bb:$target)], (Bcc br_target:$target, (ops 14, zero_reg))>,
2057                Sched<[WriteBr]>;
2058
2059    let isNotDuplicable = 1, isIndirectBranch = 1 in {
2060    def BR_JTr : ARMPseudoInst<(outs),
2061                      (ins GPR:$target, i32imm:$jt, i32imm:$id),
2062                      0, IIC_Br,
2063                      [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>,
2064                      Sched<[WriteBr]>;
2065    // FIXME: This shouldn't use the generic "addrmode2," but rather be split
2066    // into i12 and rs suffixed versions.
2067    def BR_JTm : ARMPseudoInst<(outs),
2068                     (ins addrmode2:$target, i32imm:$jt, i32imm:$id),
2069                     0, IIC_Br,
2070                     [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
2071                       imm:$id)]>, Sched<[WriteBrTbl]>;
2072    def BR_JTadd : ARMPseudoInst<(outs),
2073                   (ins GPR:$target, GPR:$idx, i32imm:$jt, i32imm:$id),
2074                   0, IIC_Br,
2075                   [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
2076                     imm:$id)]>, Sched<[WriteBrTbl]>;
2077    } // isNotDuplicable = 1, isIndirectBranch = 1
2078  } // isBarrier = 1
2079
2080}
2081
2082// BLX (immediate)
2083def BLXi : AXI<(outs), (ins blx_target:$target), BrMiscFrm, NoItinerary,
2084               "blx\t$target", []>,
2085           Requires<[IsARM, HasV5T]>, Sched<[WriteBrL]> {
2086  let Inst{31-25} = 0b1111101;
2087  bits<25> target;
2088  let Inst{23-0} = target{24-1};
2089  let Inst{24} = target{0};
2090}
2091
2092// Branch and Exchange Jazelle
2093def BXJ : ABI<0b0001, (outs), (ins GPR:$func), NoItinerary, "bxj", "\t$func",
2094              [/* pattern left blank */]>, Sched<[WriteBr]> {
2095  bits<4> func;
2096  let Inst{23-20} = 0b0010;
2097  let Inst{19-8} = 0xfff;
2098  let Inst{7-4} = 0b0010;
2099  let Inst{3-0} = func;
2100}
2101
2102// Tail calls.
2103
2104let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [SP] in {
2105  def TCRETURNdi : PseudoInst<(outs), (ins i32imm:$dst), IIC_Br, []>,
2106                   Sched<[WriteBr]>;
2107
2108  def TCRETURNri : PseudoInst<(outs), (ins tcGPR:$dst), IIC_Br, []>,
2109                   Sched<[WriteBr]>;
2110
2111  def TAILJMPd : ARMPseudoExpand<(outs), (ins br_target:$dst),
2112                                 4, IIC_Br, [],
2113                                 (Bcc br_target:$dst, (ops 14, zero_reg))>,
2114                                 Requires<[IsARM]>, Sched<[WriteBr]>;
2115
2116  def TAILJMPr : ARMPseudoExpand<(outs), (ins tcGPR:$dst),
2117                                 4, IIC_Br, [],
2118                                 (BX GPR:$dst)>, Sched<[WriteBr]>,
2119                                 Requires<[IsARM]>;
2120}
2121
2122// Secure Monitor Call is a system instruction.
2123def SMC : ABI<0b0001, (outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
2124              []>, Requires<[IsARM, HasTrustZone]> {
2125  bits<4> opt;
2126  let Inst{23-4} = 0b01100000000000000111;
2127  let Inst{3-0} = opt;
2128}
2129
2130// Supervisor Call (Software Interrupt)
2131let isCall = 1, Uses = [SP] in {
2132def SVC : ABI<0b1111, (outs), (ins imm24b:$svc), IIC_Br, "svc", "\t$svc", []>,
2133          Sched<[WriteBr]> {
2134  bits<24> svc;
2135  let Inst{23-0} = svc;
2136}
2137}
2138
2139// Store Return State
2140class SRSI<bit wb, string asm>
2141  : XI<(outs), (ins imm0_31:$mode), AddrModeNone, 4, IndexModeNone, BrFrm,
2142       NoItinerary, asm, "", []> {
2143  bits<5> mode;
2144  let Inst{31-28} = 0b1111;
2145  let Inst{27-25} = 0b100;
2146  let Inst{22} = 1;
2147  let Inst{21} = wb;
2148  let Inst{20} = 0;
2149  let Inst{19-16} = 0b1101;  // SP
2150  let Inst{15-5} = 0b00000101000;
2151  let Inst{4-0} = mode;
2152}
2153
2154def SRSDA : SRSI<0, "srsda\tsp, $mode"> {
2155  let Inst{24-23} = 0;
2156}
2157def SRSDA_UPD : SRSI<1, "srsda\tsp!, $mode"> {
2158  let Inst{24-23} = 0;
2159}
2160def SRSDB : SRSI<0, "srsdb\tsp, $mode"> {
2161  let Inst{24-23} = 0b10;
2162}
2163def SRSDB_UPD : SRSI<1, "srsdb\tsp!, $mode"> {
2164  let Inst{24-23} = 0b10;
2165}
2166def SRSIA : SRSI<0, "srsia\tsp, $mode"> {
2167  let Inst{24-23} = 0b01;
2168}
2169def SRSIA_UPD : SRSI<1, "srsia\tsp!, $mode"> {
2170  let Inst{24-23} = 0b01;
2171}
2172def SRSIB : SRSI<0, "srsib\tsp, $mode"> {
2173  let Inst{24-23} = 0b11;
2174}
2175def SRSIB_UPD : SRSI<1, "srsib\tsp!, $mode"> {
2176  let Inst{24-23} = 0b11;
2177}
2178
2179def : ARMInstAlias<"srsda $mode", (SRSDA imm0_31:$mode)>;
2180def : ARMInstAlias<"srsda $mode!", (SRSDA_UPD imm0_31:$mode)>;
2181
2182def : ARMInstAlias<"srsdb $mode", (SRSDB imm0_31:$mode)>;
2183def : ARMInstAlias<"srsdb $mode!", (SRSDB_UPD imm0_31:$mode)>;
2184
2185def : ARMInstAlias<"srsia $mode", (SRSIA imm0_31:$mode)>;
2186def : ARMInstAlias<"srsia $mode!", (SRSIA_UPD imm0_31:$mode)>;
2187
2188def : ARMInstAlias<"srsib $mode", (SRSIB imm0_31:$mode)>;
2189def : ARMInstAlias<"srsib $mode!", (SRSIB_UPD imm0_31:$mode)>;
2190
2191// Return From Exception
2192class RFEI<bit wb, string asm>
2193  : XI<(outs), (ins GPR:$Rn), AddrModeNone, 4, IndexModeNone, BrFrm,
2194       NoItinerary, asm, "", []> {
2195  bits<4> Rn;
2196  let Inst{31-28} = 0b1111;
2197  let Inst{27-25} = 0b100;
2198  let Inst{22} = 0;
2199  let Inst{21} = wb;
2200  let Inst{20} = 1;
2201  let Inst{19-16} = Rn;
2202  let Inst{15-0} = 0xa00;
2203}
2204
2205def RFEDA : RFEI<0, "rfeda\t$Rn"> {
2206  let Inst{24-23} = 0;
2207}
2208def RFEDA_UPD : RFEI<1, "rfeda\t$Rn!"> {
2209  let Inst{24-23} = 0;
2210}
2211def RFEDB : RFEI<0, "rfedb\t$Rn"> {
2212  let Inst{24-23} = 0b10;
2213}
2214def RFEDB_UPD : RFEI<1, "rfedb\t$Rn!"> {
2215  let Inst{24-23} = 0b10;
2216}
2217def RFEIA : RFEI<0, "rfeia\t$Rn"> {
2218  let Inst{24-23} = 0b01;
2219}
2220def RFEIA_UPD : RFEI<1, "rfeia\t$Rn!"> {
2221  let Inst{24-23} = 0b01;
2222}
2223def RFEIB : RFEI<0, "rfeib\t$Rn"> {
2224  let Inst{24-23} = 0b11;
2225}
2226def RFEIB_UPD : RFEI<1, "rfeib\t$Rn!"> {
2227  let Inst{24-23} = 0b11;
2228}
2229
2230//===----------------------------------------------------------------------===//
2231//  Load / Store Instructions.
2232//
2233
2234// Load
2235
2236
2237defm LDR  : AI_ldr1<0, "ldr", IIC_iLoad_r, IIC_iLoad_si,
2238                    UnOpFrag<(load node:$Src)>>;
2239defm LDRB : AI_ldr1nopc<1, "ldrb", IIC_iLoad_bh_r, IIC_iLoad_bh_si,
2240                    UnOpFrag<(zextloadi8 node:$Src)>>;
2241defm STR  : AI_str1<0, "str", IIC_iStore_r, IIC_iStore_si,
2242                   BinOpFrag<(store node:$LHS, node:$RHS)>>;
2243defm STRB : AI_str1nopc<1, "strb", IIC_iStore_bh_r, IIC_iStore_bh_si,
2244                   BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
2245
2246// Special LDR for loads from non-pc-relative constpools.
2247let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
2248    isReMaterializable = 1, isCodeGenOnly = 1 in
2249def LDRcp : AI2ldst<0b010, 1, 0, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
2250                 AddrMode_i12, LdFrm, IIC_iLoad_r, "ldr", "\t$Rt, $addr",
2251                 []> {
2252  bits<4> Rt;
2253  bits<17> addr;
2254  let Inst{23}    = addr{12};     // U (add = ('U' == 1))
2255  let Inst{19-16} = 0b1111;
2256  let Inst{15-12} = Rt;
2257  let Inst{11-0}  = addr{11-0};   // imm12
2258}
2259
2260// Loads with zero extension
2261def LDRH  : AI3ld<0b1011, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
2262                  IIC_iLoad_bh_r, "ldrh", "\t$Rt, $addr",
2263                  [(set GPR:$Rt, (zextloadi16 addrmode3:$addr))]>;
2264
2265// Loads with sign extension
2266def LDRSH : AI3ld<0b1111, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
2267                   IIC_iLoad_bh_r, "ldrsh", "\t$Rt, $addr",
2268                   [(set GPR:$Rt, (sextloadi16 addrmode3:$addr))]>;
2269
2270def LDRSB : AI3ld<0b1101, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
2271                   IIC_iLoad_bh_r, "ldrsb", "\t$Rt, $addr",
2272                   [(set GPR:$Rt, (sextloadi8 addrmode3:$addr))]>;
2273
2274let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
2275// Load doubleword
2276def LDRD : AI3ld<0b1101, 0, (outs GPR:$Rd, GPR:$dst2),
2277                 (ins addrmode3:$addr), LdMiscFrm,
2278                 IIC_iLoad_d_r, "ldrd", "\t$Rd, $dst2, $addr",
2279                 []>, Requires<[IsARM, HasV5TE]>;
2280}
2281
2282def LDA : AIldracq<0b00, (outs GPR:$Rt), (ins addr_offset_none:$addr),
2283                    NoItinerary, "lda", "\t$Rt, $addr", []>;
2284def LDAB : AIldracq<0b10, (outs GPR:$Rt), (ins addr_offset_none:$addr),
2285                    NoItinerary, "ldab", "\t$Rt, $addr", []>;
2286def LDAH : AIldracq<0b11, (outs GPR:$Rt), (ins addr_offset_none:$addr),
2287                    NoItinerary, "ldah", "\t$Rt, $addr", []>;
2288
2289// Indexed loads
2290multiclass AI2_ldridx<bit isByte, string opc,
2291                      InstrItinClass iii, InstrItinClass iir> {
2292  def _PRE_IMM  : AI2ldstidx<1, isByte, 1, (outs GPR:$Rt, GPR:$Rn_wb),
2293                      (ins addrmode_imm12_pre:$addr), IndexModePre, LdFrm, iii,
2294                      opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2295    bits<17> addr;
2296    let Inst{25} = 0;
2297    let Inst{23} = addr{12};
2298    let Inst{19-16} = addr{16-13};
2299    let Inst{11-0} = addr{11-0};
2300    let DecoderMethod = "DecodeLDRPreImm";
2301  }
2302
2303  def _PRE_REG  : AI2ldstidx<1, isByte, 1, (outs GPR:$Rt, GPR:$Rn_wb),
2304                      (ins ldst_so_reg:$addr), IndexModePre, LdFrm, iir,
2305                      opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2306    bits<17> addr;
2307    let Inst{25} = 1;
2308    let Inst{23} = addr{12};
2309    let Inst{19-16} = addr{16-13};
2310    let Inst{11-0} = addr{11-0};
2311    let Inst{4} = 0;
2312    let DecoderMethod = "DecodeLDRPreReg";
2313  }
2314
2315  def _POST_REG : AI2ldstidx<1, isByte, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2316                       (ins addr_offset_none:$addr, am2offset_reg:$offset),
2317                       IndexModePost, LdFrm, iir,
2318                       opc, "\t$Rt, $addr, $offset",
2319                       "$addr.base = $Rn_wb", []> {
2320     // {12}     isAdd
2321     // {11-0}   imm12/Rm
2322     bits<14> offset;
2323     bits<4> addr;
2324     let Inst{25} = 1;
2325     let Inst{23} = offset{12};
2326     let Inst{19-16} = addr;
2327     let Inst{11-0} = offset{11-0};
2328     let Inst{4} = 0;
2329
2330    let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2331   }
2332
2333   def _POST_IMM : AI2ldstidx<1, isByte, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2334                       (ins addr_offset_none:$addr, am2offset_imm:$offset),
2335                      IndexModePost, LdFrm, iii,
2336                      opc, "\t$Rt, $addr, $offset",
2337                      "$addr.base = $Rn_wb", []> {
2338    // {12}     isAdd
2339    // {11-0}   imm12/Rm
2340    bits<14> offset;
2341    bits<4> addr;
2342    let Inst{25} = 0;
2343    let Inst{23} = offset{12};
2344    let Inst{19-16} = addr;
2345    let Inst{11-0} = offset{11-0};
2346
2347    let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2348  }
2349
2350}
2351
2352let mayLoad = 1, neverHasSideEffects = 1 in {
2353// FIXME: for LDR_PRE_REG etc. the itineray should be either IIC_iLoad_ru or
2354// IIC_iLoad_siu depending on whether it the offset register is shifted.
2355defm LDR  : AI2_ldridx<0, "ldr", IIC_iLoad_iu, IIC_iLoad_ru>;
2356defm LDRB : AI2_ldridx<1, "ldrb", IIC_iLoad_bh_iu, IIC_iLoad_bh_ru>;
2357}
2358
2359multiclass AI3_ldridx<bits<4> op, string opc, InstrItinClass itin> {
2360  def _PRE  : AI3ldstidx<op, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
2361                        (ins addrmode3_pre:$addr), IndexModePre,
2362                        LdMiscFrm, itin,
2363                        opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2364    bits<14> addr;
2365    let Inst{23}    = addr{8};      // U bit
2366    let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2367    let Inst{19-16} = addr{12-9};   // Rn
2368    let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2369    let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2370    let DecoderMethod = "DecodeAddrMode3Instruction";
2371  }
2372  def _POST : AI3ldstidx<op, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2373                        (ins addr_offset_none:$addr, am3offset:$offset),
2374                        IndexModePost, LdMiscFrm, itin,
2375                        opc, "\t$Rt, $addr, $offset", "$addr.base = $Rn_wb",
2376                        []> {
2377    bits<10> offset;
2378    bits<4> addr;
2379    let Inst{23}    = offset{8};      // U bit
2380    let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2381    let Inst{19-16} = addr;
2382    let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2383    let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2384    let DecoderMethod = "DecodeAddrMode3Instruction";
2385  }
2386}
2387
2388let mayLoad = 1, neverHasSideEffects = 1 in {
2389defm LDRH  : AI3_ldridx<0b1011, "ldrh", IIC_iLoad_bh_ru>;
2390defm LDRSH : AI3_ldridx<0b1111, "ldrsh", IIC_iLoad_bh_ru>;
2391defm LDRSB : AI3_ldridx<0b1101, "ldrsb", IIC_iLoad_bh_ru>;
2392let hasExtraDefRegAllocReq = 1 in {
2393def LDRD_PRE : AI3ldstidx<0b1101, 0, 1, (outs GPR:$Rt, GPR:$Rt2, GPR:$Rn_wb),
2394                          (ins addrmode3_pre:$addr), IndexModePre,
2395                          LdMiscFrm, IIC_iLoad_d_ru,
2396                          "ldrd", "\t$Rt, $Rt2, $addr!",
2397                          "$addr.base = $Rn_wb", []> {
2398  bits<14> addr;
2399  let Inst{23}    = addr{8};      // U bit
2400  let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2401  let Inst{19-16} = addr{12-9};   // Rn
2402  let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2403  let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2404  let DecoderMethod = "DecodeAddrMode3Instruction";
2405}
2406def LDRD_POST: AI3ldstidx<0b1101, 0, 0, (outs GPR:$Rt, GPR:$Rt2, GPR:$Rn_wb),
2407                          (ins addr_offset_none:$addr, am3offset:$offset),
2408                          IndexModePost, LdMiscFrm, IIC_iLoad_d_ru,
2409                          "ldrd", "\t$Rt, $Rt2, $addr, $offset",
2410                          "$addr.base = $Rn_wb", []> {
2411  bits<10> offset;
2412  bits<4> addr;
2413  let Inst{23}    = offset{8};      // U bit
2414  let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2415  let Inst{19-16} = addr;
2416  let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2417  let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2418  let DecoderMethod = "DecodeAddrMode3Instruction";
2419}
2420} // hasExtraDefRegAllocReq = 1
2421} // mayLoad = 1, neverHasSideEffects = 1
2422
2423// LDRT, LDRBT, LDRSBT, LDRHT, LDRSHT.
2424let mayLoad = 1, neverHasSideEffects = 1 in {
2425def LDRT_POST_REG : AI2ldstidx<1, 0, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2426                    (ins addr_offset_none:$addr, am2offset_reg:$offset),
2427                    IndexModePost, LdFrm, IIC_iLoad_ru,
2428                    "ldrt", "\t$Rt, $addr, $offset",
2429                    "$addr.base = $Rn_wb", []> {
2430  // {12}     isAdd
2431  // {11-0}   imm12/Rm
2432  bits<14> offset;
2433  bits<4> addr;
2434  let Inst{25} = 1;
2435  let Inst{23} = offset{12};
2436  let Inst{21} = 1; // overwrite
2437  let Inst{19-16} = addr;
2438  let Inst{11-5} = offset{11-5};
2439  let Inst{4} = 0;
2440  let Inst{3-0} = offset{3-0};
2441  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2442}
2443
2444def LDRT_POST_IMM : AI2ldstidx<1, 0, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2445                    (ins addr_offset_none:$addr, am2offset_imm:$offset),
2446                   IndexModePost, LdFrm, IIC_iLoad_ru,
2447                   "ldrt", "\t$Rt, $addr, $offset",
2448                   "$addr.base = $Rn_wb", []> {
2449  // {12}     isAdd
2450  // {11-0}   imm12/Rm
2451  bits<14> offset;
2452  bits<4> addr;
2453  let Inst{25} = 0;
2454  let Inst{23} = offset{12};
2455  let Inst{21} = 1; // overwrite
2456  let Inst{19-16} = addr;
2457  let Inst{11-0} = offset{11-0};
2458  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2459}
2460
2461def LDRBT_POST_REG : AI2ldstidx<1, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2462                     (ins addr_offset_none:$addr, am2offset_reg:$offset),
2463                     IndexModePost, LdFrm, IIC_iLoad_bh_ru,
2464                     "ldrbt", "\t$Rt, $addr, $offset",
2465                     "$addr.base = $Rn_wb", []> {
2466  // {12}     isAdd
2467  // {11-0}   imm12/Rm
2468  bits<14> offset;
2469  bits<4> addr;
2470  let Inst{25} = 1;
2471  let Inst{23} = offset{12};
2472  let Inst{21} = 1; // overwrite
2473  let Inst{19-16} = addr;
2474  let Inst{11-5} = offset{11-5};
2475  let Inst{4} = 0;
2476  let Inst{3-0} = offset{3-0};
2477  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2478}
2479
2480def LDRBT_POST_IMM : AI2ldstidx<1, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2481                     (ins addr_offset_none:$addr, am2offset_imm:$offset),
2482                    IndexModePost, LdFrm, IIC_iLoad_bh_ru,
2483                    "ldrbt", "\t$Rt, $addr, $offset",
2484                    "$addr.base = $Rn_wb", []> {
2485  // {12}     isAdd
2486  // {11-0}   imm12/Rm
2487  bits<14> offset;
2488  bits<4> addr;
2489  let Inst{25} = 0;
2490  let Inst{23} = offset{12};
2491  let Inst{21} = 1; // overwrite
2492  let Inst{19-16} = addr;
2493  let Inst{11-0} = offset{11-0};
2494  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2495}
2496
2497multiclass AI3ldrT<bits<4> op, string opc> {
2498  def i : AI3ldstidxT<op, 1, (outs GPR:$Rt, GPR:$base_wb),
2499                      (ins addr_offset_none:$addr, postidx_imm8:$offset),
2500                      IndexModePost, LdMiscFrm, IIC_iLoad_bh_ru, opc,
2501                      "\t$Rt, $addr, $offset", "$addr.base = $base_wb", []> {
2502    bits<9> offset;
2503    let Inst{23} = offset{8};
2504    let Inst{22} = 1;
2505    let Inst{11-8} = offset{7-4};
2506    let Inst{3-0} = offset{3-0};
2507  }
2508  def r : AI3ldstidxT<op, 1, (outs GPRnopc:$Rt, GPRnopc:$base_wb),
2509                      (ins addr_offset_none:$addr, postidx_reg:$Rm),
2510                      IndexModePost, LdMiscFrm, IIC_iLoad_bh_ru, opc,
2511                      "\t$Rt, $addr, $Rm", "$addr.base = $base_wb", []> {
2512    bits<5> Rm;
2513    let Inst{23} = Rm{4};
2514    let Inst{22} = 0;
2515    let Inst{11-8} = 0;
2516    let Unpredictable{11-8} = 0b1111;
2517    let Inst{3-0} = Rm{3-0};
2518    let DecoderMethod = "DecodeLDR";
2519  }
2520}
2521
2522defm LDRSBT : AI3ldrT<0b1101, "ldrsbt">;
2523defm LDRHT  : AI3ldrT<0b1011, "ldrht">;
2524defm LDRSHT : AI3ldrT<0b1111, "ldrsht">;
2525}
2526
2527// Store
2528
2529// Stores with truncate
2530def STRH : AI3str<0b1011, (outs), (ins GPR:$Rt, addrmode3:$addr), StMiscFrm,
2531               IIC_iStore_bh_r, "strh", "\t$Rt, $addr",
2532               [(truncstorei16 GPR:$Rt, addrmode3:$addr)]>;
2533
2534// Store doubleword
2535let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
2536def STRD : AI3str<0b1111, (outs), (ins GPR:$Rt, GPR:$src2, addrmode3:$addr),
2537               StMiscFrm, IIC_iStore_d_r,
2538               "strd", "\t$Rt, $src2, $addr", []>,
2539           Requires<[IsARM, HasV5TE]> {
2540  let Inst{21} = 0;
2541}
2542
2543// Indexed stores
2544multiclass AI2_stridx<bit isByte, string opc,
2545                      InstrItinClass iii, InstrItinClass iir> {
2546  def _PRE_IMM : AI2ldstidx<0, isByte, 1, (outs GPR:$Rn_wb),
2547                            (ins GPR:$Rt, addrmode_imm12_pre:$addr), IndexModePre,
2548                            StFrm, iii,
2549                            opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2550    bits<17> addr;
2551    let Inst{25} = 0;
2552    let Inst{23}    = addr{12};     // U (add = ('U' == 1))
2553    let Inst{19-16} = addr{16-13};  // Rn
2554    let Inst{11-0}  = addr{11-0};   // imm12
2555    let DecoderMethod = "DecodeSTRPreImm";
2556  }
2557
2558  def _PRE_REG  : AI2ldstidx<0, isByte, 1, (outs GPR:$Rn_wb),
2559                      (ins GPR:$Rt, ldst_so_reg:$addr),
2560                      IndexModePre, StFrm, iir,
2561                      opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2562    bits<17> addr;
2563    let Inst{25} = 1;
2564    let Inst{23}    = addr{12};    // U (add = ('U' == 1))
2565    let Inst{19-16} = addr{16-13}; // Rn
2566    let Inst{11-0}  = addr{11-0};
2567    let Inst{4}     = 0;           // Inst{4} = 0
2568    let DecoderMethod = "DecodeSTRPreReg";
2569  }
2570  def _POST_REG : AI2ldstidx<0, isByte, 0, (outs GPR:$Rn_wb),
2571                (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2572                IndexModePost, StFrm, iir,
2573                opc, "\t$Rt, $addr, $offset",
2574                "$addr.base = $Rn_wb", []> {
2575     // {12}     isAdd
2576     // {11-0}   imm12/Rm
2577     bits<14> offset;
2578     bits<4> addr;
2579     let Inst{25} = 1;
2580     let Inst{23} = offset{12};
2581     let Inst{19-16} = addr;
2582     let Inst{11-0} = offset{11-0};
2583     let Inst{4} = 0;
2584
2585    let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2586   }
2587
2588   def _POST_IMM : AI2ldstidx<0, isByte, 0, (outs GPR:$Rn_wb),
2589                (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2590                IndexModePost, StFrm, iii,
2591                opc, "\t$Rt, $addr, $offset",
2592                "$addr.base = $Rn_wb", []> {
2593    // {12}     isAdd
2594    // {11-0}   imm12/Rm
2595    bits<14> offset;
2596    bits<4> addr;
2597    let Inst{25} = 0;
2598    let Inst{23} = offset{12};
2599    let Inst{19-16} = addr;
2600    let Inst{11-0} = offset{11-0};
2601
2602    let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2603  }
2604}
2605
2606let mayStore = 1, neverHasSideEffects = 1 in {
2607// FIXME: for STR_PRE_REG etc. the itineray should be either IIC_iStore_ru or
2608// IIC_iStore_siu depending on whether it the offset register is shifted.
2609defm STR  : AI2_stridx<0, "str", IIC_iStore_iu, IIC_iStore_ru>;
2610defm STRB : AI2_stridx<1, "strb", IIC_iStore_bh_iu, IIC_iStore_bh_ru>;
2611}
2612
2613def : ARMPat<(post_store GPR:$Rt, addr_offset_none:$addr,
2614                         am2offset_reg:$offset),
2615             (STR_POST_REG GPR:$Rt, addr_offset_none:$addr,
2616                           am2offset_reg:$offset)>;
2617def : ARMPat<(post_store GPR:$Rt, addr_offset_none:$addr,
2618                         am2offset_imm:$offset),
2619             (STR_POST_IMM GPR:$Rt, addr_offset_none:$addr,
2620                           am2offset_imm:$offset)>;
2621def : ARMPat<(post_truncsti8 GPR:$Rt, addr_offset_none:$addr,
2622                             am2offset_reg:$offset),
2623             (STRB_POST_REG GPR:$Rt, addr_offset_none:$addr,
2624                            am2offset_reg:$offset)>;
2625def : ARMPat<(post_truncsti8 GPR:$Rt, addr_offset_none:$addr,
2626                             am2offset_imm:$offset),
2627             (STRB_POST_IMM GPR:$Rt, addr_offset_none:$addr,
2628                            am2offset_imm:$offset)>;
2629
2630// Pseudo-instructions for pattern matching the pre-indexed stores. We can't
2631// put the patterns on the instruction definitions directly as ISel wants
2632// the address base and offset to be separate operands, not a single
2633// complex operand like we represent the instructions themselves. The
2634// pseudos map between the two.
2635let usesCustomInserter = 1,
2636    Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
2637def STRi_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2638               (ins GPR:$Rt, GPR:$Rn, am2offset_imm:$offset, pred:$p),
2639               4, IIC_iStore_ru,
2640            [(set GPR:$Rn_wb,
2641                  (pre_store GPR:$Rt, GPR:$Rn, am2offset_imm:$offset))]>;
2642def STRr_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2643               (ins GPR:$Rt, GPR:$Rn, am2offset_reg:$offset, pred:$p),
2644               4, IIC_iStore_ru,
2645            [(set GPR:$Rn_wb,
2646                  (pre_store GPR:$Rt, GPR:$Rn, am2offset_reg:$offset))]>;
2647def STRBi_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2648               (ins GPR:$Rt, GPR:$Rn, am2offset_imm:$offset, pred:$p),
2649               4, IIC_iStore_ru,
2650            [(set GPR:$Rn_wb,
2651                  (pre_truncsti8 GPR:$Rt, GPR:$Rn, am2offset_imm:$offset))]>;
2652def STRBr_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2653               (ins GPR:$Rt, GPR:$Rn, am2offset_reg:$offset, pred:$p),
2654               4, IIC_iStore_ru,
2655            [(set GPR:$Rn_wb,
2656                  (pre_truncsti8 GPR:$Rt, GPR:$Rn, am2offset_reg:$offset))]>;
2657def STRH_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2658               (ins GPR:$Rt, GPR:$Rn, am3offset:$offset, pred:$p),
2659               4, IIC_iStore_ru,
2660            [(set GPR:$Rn_wb,
2661                  (pre_truncsti16 GPR:$Rt, GPR:$Rn, am3offset:$offset))]>;
2662}
2663
2664
2665
2666def STRH_PRE  : AI3ldstidx<0b1011, 0, 1, (outs GPR:$Rn_wb),
2667                           (ins GPR:$Rt, addrmode3_pre:$addr), IndexModePre,
2668                           StMiscFrm, IIC_iStore_bh_ru,
2669                           "strh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2670  bits<14> addr;
2671  let Inst{23}    = addr{8};      // U bit
2672  let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2673  let Inst{19-16} = addr{12-9};   // Rn
2674  let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2675  let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2676  let DecoderMethod = "DecodeAddrMode3Instruction";
2677}
2678
2679def STRH_POST : AI3ldstidx<0b1011, 0, 0, (outs GPR:$Rn_wb),
2680                       (ins GPR:$Rt, addr_offset_none:$addr, am3offset:$offset),
2681                       IndexModePost, StMiscFrm, IIC_iStore_bh_ru,
2682                       "strh", "\t$Rt, $addr, $offset", "$addr.base = $Rn_wb",
2683                   [(set GPR:$Rn_wb, (post_truncsti16 GPR:$Rt,
2684                                                      addr_offset_none:$addr,
2685                                                      am3offset:$offset))]> {
2686  bits<10> offset;
2687  bits<4> addr;
2688  let Inst{23}    = offset{8};      // U bit
2689  let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2690  let Inst{19-16} = addr;
2691  let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2692  let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2693  let DecoderMethod = "DecodeAddrMode3Instruction";
2694}
2695
2696let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in {
2697def STRD_PRE : AI3ldstidx<0b1111, 0, 1, (outs GPR:$Rn_wb),
2698                          (ins GPR:$Rt, GPR:$Rt2, addrmode3_pre:$addr),
2699                          IndexModePre, StMiscFrm, IIC_iStore_d_ru,
2700                          "strd", "\t$Rt, $Rt2, $addr!",
2701                          "$addr.base = $Rn_wb", []> {
2702  bits<14> addr;
2703  let Inst{23}    = addr{8};      // U bit
2704  let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2705  let Inst{19-16} = addr{12-9};   // Rn
2706  let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2707  let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2708  let DecoderMethod = "DecodeAddrMode3Instruction";
2709}
2710
2711def STRD_POST: AI3ldstidx<0b1111, 0, 0, (outs GPR:$Rn_wb),
2712                          (ins GPR:$Rt, GPR:$Rt2, addr_offset_none:$addr,
2713                               am3offset:$offset),
2714                          IndexModePost, StMiscFrm, IIC_iStore_d_ru,
2715                          "strd", "\t$Rt, $Rt2, $addr, $offset",
2716                          "$addr.base = $Rn_wb", []> {
2717  bits<10> offset;
2718  bits<4> addr;
2719  let Inst{23}    = offset{8};      // U bit
2720  let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2721  let Inst{19-16} = addr;
2722  let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2723  let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2724  let DecoderMethod = "DecodeAddrMode3Instruction";
2725}
2726} // mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1
2727
2728// STRT, STRBT, and STRHT
2729
2730def STRBT_POST_REG : AI2ldstidx<0, 1, 0, (outs GPR:$Rn_wb),
2731                   (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2732                   IndexModePost, StFrm, IIC_iStore_bh_ru,
2733                   "strbt", "\t$Rt, $addr, $offset",
2734                   "$addr.base = $Rn_wb", []> {
2735  // {12}     isAdd
2736  // {11-0}   imm12/Rm
2737  bits<14> offset;
2738  bits<4> addr;
2739  let Inst{25} = 1;
2740  let Inst{23} = offset{12};
2741  let Inst{21} = 1; // overwrite
2742  let Inst{19-16} = addr;
2743  let Inst{11-5} = offset{11-5};
2744  let Inst{4} = 0;
2745  let Inst{3-0} = offset{3-0};
2746  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2747}
2748
2749def STRBT_POST_IMM : AI2ldstidx<0, 1, 0, (outs GPR:$Rn_wb),
2750                   (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2751                   IndexModePost, StFrm, IIC_iStore_bh_ru,
2752                   "strbt", "\t$Rt, $addr, $offset",
2753                   "$addr.base = $Rn_wb", []> {
2754  // {12}     isAdd
2755  // {11-0}   imm12/Rm
2756  bits<14> offset;
2757  bits<4> addr;
2758  let Inst{25} = 0;
2759  let Inst{23} = offset{12};
2760  let Inst{21} = 1; // overwrite
2761  let Inst{19-16} = addr;
2762  let Inst{11-0} = offset{11-0};
2763  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2764}
2765
2766let mayStore = 1, neverHasSideEffects = 1 in {
2767def STRT_POST_REG : AI2ldstidx<0, 0, 0, (outs GPR:$Rn_wb),
2768                   (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2769                   IndexModePost, StFrm, IIC_iStore_ru,
2770                   "strt", "\t$Rt, $addr, $offset",
2771                   "$addr.base = $Rn_wb", []> {
2772  // {12}     isAdd
2773  // {11-0}   imm12/Rm
2774  bits<14> offset;
2775  bits<4> addr;
2776  let Inst{25} = 1;
2777  let Inst{23} = offset{12};
2778  let Inst{21} = 1; // overwrite
2779  let Inst{19-16} = addr;
2780  let Inst{11-5} = offset{11-5};
2781  let Inst{4} = 0;
2782  let Inst{3-0} = offset{3-0};
2783  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2784}
2785
2786def STRT_POST_IMM : AI2ldstidx<0, 0, 0, (outs GPR:$Rn_wb),
2787                   (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2788                   IndexModePost, StFrm, IIC_iStore_ru,
2789                   "strt", "\t$Rt, $addr, $offset",
2790                   "$addr.base = $Rn_wb", []> {
2791  // {12}     isAdd
2792  // {11-0}   imm12/Rm
2793  bits<14> offset;
2794  bits<4> addr;
2795  let Inst{25} = 0;
2796  let Inst{23} = offset{12};
2797  let Inst{21} = 1; // overwrite
2798  let Inst{19-16} = addr;
2799  let Inst{11-0} = offset{11-0};
2800  let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2801}
2802}
2803
2804
2805multiclass AI3strT<bits<4> op, string opc> {
2806  def i : AI3ldstidxT<op, 0, (outs GPR:$base_wb),
2807                    (ins GPR:$Rt, addr_offset_none:$addr, postidx_imm8:$offset),
2808                    IndexModePost, StMiscFrm, IIC_iStore_bh_ru, opc,
2809                    "\t$Rt, $addr, $offset", "$addr.base = $base_wb", []> {
2810    bits<9> offset;
2811    let Inst{23} = offset{8};
2812    let Inst{22} = 1;
2813    let Inst{11-8} = offset{7-4};
2814    let Inst{3-0} = offset{3-0};
2815  }
2816  def r : AI3ldstidxT<op, 0, (outs GPR:$base_wb),
2817                      (ins GPR:$Rt, addr_offset_none:$addr, postidx_reg:$Rm),
2818                      IndexModePost, StMiscFrm, IIC_iStore_bh_ru, opc,
2819                      "\t$Rt, $addr, $Rm", "$addr.base = $base_wb", []> {
2820    bits<5> Rm;
2821    let Inst{23} = Rm{4};
2822    let Inst{22} = 0;
2823    let Inst{11-8} = 0;
2824    let Inst{3-0} = Rm{3-0};
2825  }
2826}
2827
2828
2829defm STRHT : AI3strT<0b1011, "strht">;
2830
2831def STL : AIstrrel<0b00, (outs), (ins GPR:$Rt, addr_offset_none:$addr),
2832                   NoItinerary, "stl", "\t$Rt, $addr", []>;
2833def STLB : AIstrrel<0b10, (outs), (ins GPR:$Rt, addr_offset_none:$addr),
2834                    NoItinerary, "stlb", "\t$Rt, $addr", []>;
2835def STLH : AIstrrel<0b11, (outs), (ins GPR:$Rt, addr_offset_none:$addr),
2836                    NoItinerary, "stlh", "\t$Rt, $addr", []>;
2837
2838//===----------------------------------------------------------------------===//
2839//  Load / store multiple Instructions.
2840//
2841
2842multiclass arm_ldst_mult<string asm, string sfx, bit L_bit, bit P_bit, Format f,
2843                         InstrItinClass itin, InstrItinClass itin_upd> {
2844  // IA is the default, so no need for an explicit suffix on the
2845  // mnemonic here. Without it is the canonical spelling.
2846  def IA :
2847    AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2848         IndexModeNone, f, itin,
2849         !strconcat(asm, "${p}\t$Rn, $regs", sfx), "", []> {
2850    let Inst{24-23} = 0b01;       // Increment After
2851    let Inst{22}    = P_bit;
2852    let Inst{21}    = 0;          // No writeback
2853    let Inst{20}    = L_bit;
2854  }
2855  def IA_UPD :
2856    AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2857         IndexModeUpd, f, itin_upd,
2858         !strconcat(asm, "${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2859    let Inst{24-23} = 0b01;       // Increment After
2860    let Inst{22}    = P_bit;
2861    let Inst{21}    = 1;          // Writeback
2862    let Inst{20}    = L_bit;
2863
2864    let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2865  }
2866  def DA :
2867    AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2868         IndexModeNone, f, itin,
2869         !strconcat(asm, "da${p}\t$Rn, $regs", sfx), "", []> {
2870    let Inst{24-23} = 0b00;       // Decrement After
2871    let Inst{22}    = P_bit;
2872    let Inst{21}    = 0;          // No writeback
2873    let Inst{20}    = L_bit;
2874  }
2875  def DA_UPD :
2876    AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2877         IndexModeUpd, f, itin_upd,
2878         !strconcat(asm, "da${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2879    let Inst{24-23} = 0b00;       // Decrement After
2880    let Inst{22}    = P_bit;
2881    let Inst{21}    = 1;          // Writeback
2882    let Inst{20}    = L_bit;
2883
2884    let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2885  }
2886  def DB :
2887    AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2888         IndexModeNone, f, itin,
2889         !strconcat(asm, "db${p}\t$Rn, $regs", sfx), "", []> {
2890    let Inst{24-23} = 0b10;       // Decrement Before
2891    let Inst{22}    = P_bit;
2892    let Inst{21}    = 0;          // No writeback
2893    let Inst{20}    = L_bit;
2894  }
2895  def DB_UPD :
2896    AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2897         IndexModeUpd, f, itin_upd,
2898         !strconcat(asm, "db${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2899    let Inst{24-23} = 0b10;       // Decrement Before
2900    let Inst{22}    = P_bit;
2901    let Inst{21}    = 1;          // Writeback
2902    let Inst{20}    = L_bit;
2903
2904    let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2905  }
2906  def IB :
2907    AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2908         IndexModeNone, f, itin,
2909         !strconcat(asm, "ib${p}\t$Rn, $regs", sfx), "", []> {
2910    let Inst{24-23} = 0b11;       // Increment Before
2911    let Inst{22}    = P_bit;
2912    let Inst{21}    = 0;          // No writeback
2913    let Inst{20}    = L_bit;
2914  }
2915  def IB_UPD :
2916    AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2917         IndexModeUpd, f, itin_upd,
2918         !strconcat(asm, "ib${p}\t$Rn!, $regs", sfx), "$Rn = $wb", []> {
2919    let Inst{24-23} = 0b11;       // Increment Before
2920    let Inst{22}    = P_bit;
2921    let Inst{21}    = 1;          // Writeback
2922    let Inst{20}    = L_bit;
2923
2924    let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2925  }
2926}
2927
2928let neverHasSideEffects = 1 in {
2929
2930let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
2931defm LDM : arm_ldst_mult<"ldm", "", 1, 0, LdStMulFrm, IIC_iLoad_m,
2932                         IIC_iLoad_mu>;
2933
2934let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
2935defm STM : arm_ldst_mult<"stm", "", 0, 0, LdStMulFrm, IIC_iStore_m,
2936                         IIC_iStore_mu>;
2937
2938} // neverHasSideEffects
2939
2940// FIXME: remove when we have a way to marking a MI with these properties.
2941// FIXME: Should pc be an implicit operand like PICADD, etc?
2942let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
2943    hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
2944def LDMIA_RET : ARMPseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
2945                                                 reglist:$regs, variable_ops),
2946                     4, IIC_iLoad_mBr, [],
2947                     (LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
2948      RegConstraint<"$Rn = $wb">;
2949
2950let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
2951defm sysLDM : arm_ldst_mult<"ldm", " ^", 1, 1, LdStMulFrm, IIC_iLoad_m,
2952                               IIC_iLoad_mu>;
2953
2954let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
2955defm sysSTM : arm_ldst_mult<"stm", " ^", 0, 1, LdStMulFrm, IIC_iStore_m,
2956                               IIC_iStore_mu>;
2957
2958
2959
2960//===----------------------------------------------------------------------===//
2961//  Move Instructions.
2962//
2963
2964let neverHasSideEffects = 1 in
2965def MOVr : AsI1<0b1101, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMOVr,
2966                "mov", "\t$Rd, $Rm", []>, UnaryDP, Sched<[WriteALU]> {
2967  bits<4> Rd;
2968  bits<4> Rm;
2969
2970  let Inst{19-16} = 0b0000;
2971  let Inst{11-4} = 0b00000000;
2972  let Inst{25} = 0;
2973  let Inst{3-0} = Rm;
2974  let Inst{15-12} = Rd;
2975}
2976
2977// A version for the smaller set of tail call registers.
2978let neverHasSideEffects = 1 in
2979def MOVr_TC : AsI1<0b1101, (outs tcGPR:$Rd), (ins tcGPR:$Rm), DPFrm,
2980                IIC_iMOVr, "mov", "\t$Rd, $Rm", []>, UnaryDP, Sched<[WriteALU]> {
2981  bits<4> Rd;
2982  bits<4> Rm;
2983
2984  let Inst{11-4} = 0b00000000;
2985  let Inst{25} = 0;
2986  let Inst{3-0} = Rm;
2987  let Inst{15-12} = Rd;
2988}
2989
2990def MOVsr : AsI1<0b1101, (outs GPRnopc:$Rd), (ins shift_so_reg_reg:$src),
2991                DPSoRegRegFrm, IIC_iMOVsr,
2992                "mov", "\t$Rd, $src",
2993                [(set GPRnopc:$Rd, shift_so_reg_reg:$src)]>, UnaryDP,
2994                Sched<[WriteALU]> {
2995  bits<4> Rd;
2996  bits<12> src;
2997  let Inst{15-12} = Rd;
2998  let Inst{19-16} = 0b0000;
2999  let Inst{11-8} = src{11-8};
3000  let Inst{7} = 0;
3001  let Inst{6-5} = src{6-5};
3002  let Inst{4} = 1;
3003  let Inst{3-0} = src{3-0};
3004  let Inst{25} = 0;
3005}
3006
3007def MOVsi : AsI1<0b1101, (outs GPR:$Rd), (ins shift_so_reg_imm:$src),
3008                DPSoRegImmFrm, IIC_iMOVsr,
3009                "mov", "\t$Rd, $src", [(set GPR:$Rd, shift_so_reg_imm:$src)]>,
3010                UnaryDP, Sched<[WriteALU]> {
3011  bits<4> Rd;
3012  bits<12> src;
3013  let Inst{15-12} = Rd;
3014  let Inst{19-16} = 0b0000;
3015  let Inst{11-5} = src{11-5};
3016  let Inst{4} = 0;
3017  let Inst{3-0} = src{3-0};
3018  let Inst{25} = 0;
3019}
3020
3021let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
3022def MOVi : AsI1<0b1101, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm, IIC_iMOVi,
3023                "mov", "\t$Rd, $imm", [(set GPR:$Rd, so_imm:$imm)]>, UnaryDP,
3024                Sched<[WriteALU]> {
3025  bits<4> Rd;
3026  bits<12> imm;
3027  let Inst{25} = 1;
3028  let Inst{15-12} = Rd;
3029  let Inst{19-16} = 0b0000;
3030  let Inst{11-0} = imm;
3031}
3032
3033let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
3034def MOVi16 : AI1<0b1000, (outs GPR:$Rd), (ins imm0_65535_expr:$imm),
3035                 DPFrm, IIC_iMOVi,
3036                 "movw", "\t$Rd, $imm",
3037                 [(set GPR:$Rd, imm0_65535:$imm)]>,
3038                 Requires<[IsARM, HasV6T2]>, UnaryDP, Sched<[WriteALU]> {
3039  bits<4> Rd;
3040  bits<16> imm;
3041  let Inst{15-12} = Rd;
3042  let Inst{11-0}  = imm{11-0};
3043  let Inst{19-16} = imm{15-12};
3044  let Inst{20} = 0;
3045  let Inst{25} = 1;
3046  let DecoderMethod = "DecodeArmMOVTWInstruction";
3047}
3048
3049def : InstAlias<"mov${p} $Rd, $imm",
3050                (MOVi16 GPR:$Rd, imm0_65535_expr:$imm, pred:$p)>,
3051        Requires<[IsARM]>;
3052
3053def MOVi16_ga_pcrel : PseudoInst<(outs GPR:$Rd),
3054                                (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
3055                      Sched<[WriteALU]>;
3056
3057let Constraints = "$src = $Rd" in {
3058def MOVTi16 : AI1<0b1010, (outs GPRnopc:$Rd),
3059                  (ins GPR:$src, imm0_65535_expr:$imm),
3060                  DPFrm, IIC_iMOVi,
3061                  "movt", "\t$Rd, $imm",
3062                  [(set GPRnopc:$Rd,
3063                        (or (and GPR:$src, 0xffff),
3064                            lo16AllZero:$imm))]>, UnaryDP,
3065                  Requires<[IsARM, HasV6T2]>, Sched<[WriteALU]> {
3066  bits<4> Rd;
3067  bits<16> imm;
3068  let Inst{15-12} = Rd;
3069  let Inst{11-0}  = imm{11-0};
3070  let Inst{19-16} = imm{15-12};
3071  let Inst{20} = 0;
3072  let Inst{25} = 1;
3073  let DecoderMethod = "DecodeArmMOVTWInstruction";
3074}
3075
3076def MOVTi16_ga_pcrel : PseudoInst<(outs GPR:$Rd),
3077                      (ins GPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
3078                      Sched<[WriteALU]>;
3079
3080} // Constraints
3081
3082def : ARMPat<(or GPR:$src, 0xffff0000), (MOVTi16 GPR:$src, 0xffff)>,
3083      Requires<[IsARM, HasV6T2]>;
3084
3085let Uses = [CPSR] in
3086def RRX: PseudoInst<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVsi,
3087                    [(set GPR:$Rd, (ARMrrx GPR:$Rm))]>, UnaryDP,
3088                    Requires<[IsARM]>, Sched<[WriteALU]>;
3089
3090// These aren't really mov instructions, but we have to define them this way
3091// due to flag operands.
3092
3093let Defs = [CPSR] in {
3094def MOVsrl_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi,
3095                      [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP,
3096                      Sched<[WriteALU]>, Requires<[IsARM]>;
3097def MOVsra_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi,
3098                      [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP,
3099                      Sched<[WriteALU]>, Requires<[IsARM]>;
3100}
3101
3102//===----------------------------------------------------------------------===//
3103//  Extend Instructions.
3104//
3105
3106// Sign extenders
3107
3108def SXTB  : AI_ext_rrot<0b01101010,
3109                         "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
3110def SXTH  : AI_ext_rrot<0b01101011,
3111                         "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
3112
3113def SXTAB : AI_exta_rrot<0b01101010,
3114               "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
3115def SXTAH : AI_exta_rrot<0b01101011,
3116               "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
3117
3118def SXTB16  : AI_ext_rrot_np<0b01101000, "sxtb16">;
3119
3120def SXTAB16 : AI_exta_rrot_np<0b01101000, "sxtab16">;
3121
3122// Zero extenders
3123
3124let AddedComplexity = 16 in {
3125def UXTB   : AI_ext_rrot<0b01101110,
3126                          "uxtb"  , UnOpFrag<(and node:$Src, 0x000000FF)>>;
3127def UXTH   : AI_ext_rrot<0b01101111,
3128                          "uxth"  , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
3129def UXTB16 : AI_ext_rrot<0b01101100,
3130                          "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
3131
3132// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
3133//        The transformation should probably be done as a combiner action
3134//        instead so we can include a check for masking back in the upper
3135//        eight bits of the source into the lower eight bits of the result.
3136//def : ARMV6Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
3137//               (UXTB16r_rot GPR:$Src, 3)>;
3138def : ARMV6Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
3139               (UXTB16 GPR:$Src, 1)>;
3140
3141def UXTAB : AI_exta_rrot<0b01101110, "uxtab",
3142                        BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
3143def UXTAH : AI_exta_rrot<0b01101111, "uxtah",
3144                        BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
3145}
3146
3147// This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
3148def UXTAB16 : AI_exta_rrot_np<0b01101100, "uxtab16">;
3149
3150
3151def SBFX  : I<(outs GPRnopc:$Rd),
3152              (ins GPRnopc:$Rn, imm0_31:$lsb, imm1_32:$width),
3153               AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3154               "sbfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
3155               Requires<[IsARM, HasV6T2]> {
3156  bits<4> Rd;
3157  bits<4> Rn;
3158  bits<5> lsb;
3159  bits<5> width;
3160  let Inst{27-21} = 0b0111101;
3161  let Inst{6-4}   = 0b101;
3162  let Inst{20-16} = width;
3163  let Inst{15-12} = Rd;
3164  let Inst{11-7}  = lsb;
3165  let Inst{3-0}   = Rn;
3166}
3167
3168def UBFX  : I<(outs GPR:$Rd),
3169              (ins GPR:$Rn, imm0_31:$lsb, imm1_32:$width),
3170               AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3171               "ubfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
3172               Requires<[IsARM, HasV6T2]> {
3173  bits<4> Rd;
3174  bits<4> Rn;
3175  bits<5> lsb;
3176  bits<5> width;
3177  let Inst{27-21} = 0b0111111;
3178  let Inst{6-4}   = 0b101;
3179  let Inst{20-16} = width;
3180  let Inst{15-12} = Rd;
3181  let Inst{11-7}  = lsb;
3182  let Inst{3-0}   = Rn;
3183}
3184
3185//===----------------------------------------------------------------------===//
3186//  Arithmetic Instructions.
3187//
3188
3189defm ADD  : AsI1_bin_irs<0b0100, "add",
3190                         IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3191                         BinOpFrag<(add  node:$LHS, node:$RHS)>, 1>;
3192defm SUB  : AsI1_bin_irs<0b0010, "sub",
3193                         IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3194                         BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
3195
3196// ADD and SUB with 's' bit set.
3197//
3198// Currently, ADDS/SUBS are pseudo opcodes that exist only in the
3199// selection DAG. They are "lowered" to real ADD/SUB opcodes by
3200// AdjustInstrPostInstrSelection where we determine whether or not to
3201// set the "s" bit based on CPSR liveness.
3202//
3203// FIXME: Eliminate ADDS/SUBS pseudo opcodes after adding tablegen
3204// support for an optional CPSR definition that corresponds to the DAG
3205// node's second value. We can then eliminate the implicit def of CPSR.
3206defm ADDS : AsI1_bin_s_irs<IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3207                           BinOpFrag<(ARMaddc node:$LHS, node:$RHS)>, 1>;
3208defm SUBS : AsI1_bin_s_irs<IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3209                           BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
3210
3211defm ADC : AI1_adde_sube_irs<0b0101, "adc",
3212              BinOpWithFlagFrag<(ARMadde node:$LHS, node:$RHS, node:$FLAG)>, 1>;
3213defm SBC : AI1_adde_sube_irs<0b0110, "sbc",
3214              BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>>;
3215
3216defm RSB  : AsI1_rbin_irs<0b0011, "rsb",
3217                          IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3218                          BinOpFrag<(sub node:$LHS, node:$RHS)>>;
3219
3220// FIXME: Eliminate them if we can write def : Pat patterns which defines
3221// CPSR and the implicit def of CPSR is not needed.
3222defm RSBS : AsI1_rbin_s_is<IIC_iALUi, IIC_iALUr, IIC_iALUsr,
3223                           BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
3224
3225defm RSC : AI1_rsc_irs<0b0111, "rsc",
3226                BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>>;
3227
3228// (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
3229// The assume-no-carry-in form uses the negation of the input since add/sub
3230// assume opposite meanings of the carry flag (i.e., carry == !borrow).
3231// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
3232// details.
3233def : ARMPat<(add     GPR:$src, so_imm_neg:$imm),
3234             (SUBri   GPR:$src, so_imm_neg:$imm)>;
3235def : ARMPat<(ARMaddc GPR:$src, so_imm_neg:$imm),
3236             (SUBSri  GPR:$src, so_imm_neg:$imm)>;
3237
3238def : ARMPat<(add     GPR:$src, imm0_65535_neg:$imm),
3239             (SUBrr   GPR:$src, (MOVi16 (imm_neg_XFORM imm:$imm)))>,
3240             Requires<[IsARM, HasV6T2]>;
3241def : ARMPat<(ARMaddc GPR:$src, imm0_65535_neg:$imm),
3242             (SUBSrr  GPR:$src, (MOVi16 (imm_neg_XFORM imm:$imm)))>,
3243             Requires<[IsARM, HasV6T2]>;
3244
3245// The with-carry-in form matches bitwise not instead of the negation.
3246// Effectively, the inverse interpretation of the carry flag already accounts
3247// for part of the negation.
3248def : ARMPat<(ARMadde GPR:$src, so_imm_not:$imm, CPSR),
3249             (SBCri   GPR:$src, so_imm_not:$imm)>;
3250def : ARMPat<(ARMadde GPR:$src, imm0_65535_neg:$imm, CPSR),
3251             (SBCrr   GPR:$src, (MOVi16 (imm_not_XFORM imm:$imm)))>,
3252             Requires<[IsARM, HasV6T2]>;
3253
3254// Note: These are implemented in C++ code, because they have to generate
3255// ADD/SUBrs instructions, which use a complex pattern that a xform function
3256// cannot produce.
3257// (mul X, 2^n+1) -> (add (X << n), X)
3258// (mul X, 2^n-1) -> (rsb X, (X << n))
3259
3260// ARM Arithmetic Instruction
3261// GPR:$dst = GPR:$a op GPR:$b
3262class AAI<bits<8> op27_20, bits<8> op11_4, string opc,
3263          list<dag> pattern = [],
3264          dag iops = (ins GPRnopc:$Rn, GPRnopc:$Rm),
3265          string asm = "\t$Rd, $Rn, $Rm">
3266  : AI<(outs GPRnopc:$Rd), iops, DPFrm, IIC_iALUr, opc, asm, pattern>,
3267    Sched<[WriteALU, ReadALU, ReadALU]> {
3268  bits<4> Rn;
3269  bits<4> Rd;
3270  bits<4> Rm;
3271  let Inst{27-20} = op27_20;
3272  let Inst{11-4} = op11_4;
3273  let Inst{19-16} = Rn;
3274  let Inst{15-12} = Rd;
3275  let Inst{3-0}   = Rm;
3276
3277  let Unpredictable{11-8} = 0b1111;
3278}
3279
3280// Saturating add/subtract
3281
3282let DecoderMethod = "DecodeQADDInstruction" in
3283def QADD    : AAI<0b00010000, 0b00000101, "qadd",
3284                  [(set GPRnopc:$Rd, (int_arm_qadd GPRnopc:$Rm, GPRnopc:$Rn))],
3285                  (ins GPRnopc:$Rm, GPRnopc:$Rn), "\t$Rd, $Rm, $Rn">;
3286
3287def QSUB    : AAI<0b00010010, 0b00000101, "qsub",
3288                  [(set GPRnopc:$Rd, (int_arm_qsub GPRnopc:$Rm, GPRnopc:$Rn))],
3289                  (ins GPRnopc:$Rm, GPRnopc:$Rn), "\t$Rd, $Rm, $Rn">;
3290def QDADD   : AAI<0b00010100, 0b00000101, "qdadd", [],
3291                  (ins GPRnopc:$Rm, GPRnopc:$Rn),
3292                  "\t$Rd, $Rm, $Rn">;
3293def QDSUB   : AAI<0b00010110, 0b00000101, "qdsub", [],
3294                  (ins GPRnopc:$Rm, GPRnopc:$Rn),
3295                  "\t$Rd, $Rm, $Rn">;
3296
3297def QADD16  : AAI<0b01100010, 0b11110001, "qadd16">;
3298def QADD8   : AAI<0b01100010, 0b11111001, "qadd8">;
3299def QASX    : AAI<0b01100010, 0b11110011, "qasx">;
3300def QSAX    : AAI<0b01100010, 0b11110101, "qsax">;
3301def QSUB16  : AAI<0b01100010, 0b11110111, "qsub16">;
3302def QSUB8   : AAI<0b01100010, 0b11111111, "qsub8">;
3303def UQADD16 : AAI<0b01100110, 0b11110001, "uqadd16">;
3304def UQADD8  : AAI<0b01100110, 0b11111001, "uqadd8">;
3305def UQASX   : AAI<0b01100110, 0b11110011, "uqasx">;
3306def UQSAX   : AAI<0b01100110, 0b11110101, "uqsax">;
3307def UQSUB16 : AAI<0b01100110, 0b11110111, "uqsub16">;
3308def UQSUB8  : AAI<0b01100110, 0b11111111, "uqsub8">;
3309
3310// Signed/Unsigned add/subtract
3311
3312def SASX   : AAI<0b01100001, 0b11110011, "sasx">;
3313def SADD16 : AAI<0b01100001, 0b11110001, "sadd16">;
3314def SADD8  : AAI<0b01100001, 0b11111001, "sadd8">;
3315def SSAX   : AAI<0b01100001, 0b11110101, "ssax">;
3316def SSUB16 : AAI<0b01100001, 0b11110111, "ssub16">;
3317def SSUB8  : AAI<0b01100001, 0b11111111, "ssub8">;
3318def UASX   : AAI<0b01100101, 0b11110011, "uasx">;
3319def UADD16 : AAI<0b01100101, 0b11110001, "uadd16">;
3320def UADD8  : AAI<0b01100101, 0b11111001, "uadd8">;
3321def USAX   : AAI<0b01100101, 0b11110101, "usax">;
3322def USUB16 : AAI<0b01100101, 0b11110111, "usub16">;
3323def USUB8  : AAI<0b01100101, 0b11111111, "usub8">;
3324
3325// Signed/Unsigned halving add/subtract
3326
3327def SHASX   : AAI<0b01100011, 0b11110011, "shasx">;
3328def SHADD16 : AAI<0b01100011, 0b11110001, "shadd16">;
3329def SHADD8  : AAI<0b01100011, 0b11111001, "shadd8">;
3330def SHSAX   : AAI<0b01100011, 0b11110101, "shsax">;
3331def SHSUB16 : AAI<0b01100011, 0b11110111, "shsub16">;
3332def SHSUB8  : AAI<0b01100011, 0b11111111, "shsub8">;
3333def UHASX   : AAI<0b01100111, 0b11110011, "uhasx">;
3334def UHADD16 : AAI<0b01100111, 0b11110001, "uhadd16">;
3335def UHADD8  : AAI<0b01100111, 0b11111001, "uhadd8">;
3336def UHSAX   : AAI<0b01100111, 0b11110101, "uhsax">;
3337def UHSUB16 : AAI<0b01100111, 0b11110111, "uhsub16">;
3338def UHSUB8  : AAI<0b01100111, 0b11111111, "uhsub8">;
3339
3340// Unsigned Sum of Absolute Differences [and Accumulate].
3341
3342def USAD8  : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3343                MulFrm /* for convenience */, NoItinerary, "usad8",
3344                "\t$Rd, $Rn, $Rm", []>,
3345             Requires<[IsARM, HasV6]>, Sched<[WriteALU, ReadALU, ReadALU]> {
3346  bits<4> Rd;
3347  bits<4> Rn;
3348  bits<4> Rm;
3349  let Inst{27-20} = 0b01111000;
3350  let Inst{15-12} = 0b1111;
3351  let Inst{7-4} = 0b0001;
3352  let Inst{19-16} = Rd;
3353  let Inst{11-8} = Rm;
3354  let Inst{3-0} = Rn;
3355}
3356def USADA8 : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3357                MulFrm /* for convenience */, NoItinerary, "usada8",
3358                "\t$Rd, $Rn, $Rm, $Ra", []>,
3359             Requires<[IsARM, HasV6]>, Sched<[WriteALU, ReadALU, ReadALU]>{
3360  bits<4> Rd;
3361  bits<4> Rn;
3362  bits<4> Rm;
3363  bits<4> Ra;
3364  let Inst{27-20} = 0b01111000;
3365  let Inst{7-4} = 0b0001;
3366  let Inst{19-16} = Rd;
3367  let Inst{15-12} = Ra;
3368  let Inst{11-8} = Rm;
3369  let Inst{3-0} = Rn;
3370}
3371
3372// Signed/Unsigned saturate
3373
3374def SSAT : AI<(outs GPRnopc:$Rd),
3375              (ins imm1_32:$sat_imm, GPRnopc:$Rn, shift_imm:$sh),
3376              SatFrm, NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> {
3377  bits<4> Rd;
3378  bits<5> sat_imm;
3379  bits<4> Rn;
3380  bits<8> sh;
3381  let Inst{27-21} = 0b0110101;
3382  let Inst{5-4} = 0b01;
3383  let Inst{20-16} = sat_imm;
3384  let Inst{15-12} = Rd;
3385  let Inst{11-7} = sh{4-0};
3386  let Inst{6} = sh{5};
3387  let Inst{3-0} = Rn;
3388}
3389
3390def SSAT16 : AI<(outs GPRnopc:$Rd),
3391                (ins imm1_16:$sat_imm, GPRnopc:$Rn), SatFrm,
3392                NoItinerary, "ssat16", "\t$Rd, $sat_imm, $Rn", []> {
3393  bits<4> Rd;
3394  bits<4> sat_imm;
3395  bits<4> Rn;
3396  let Inst{27-20} = 0b01101010;
3397  let Inst{11-4} = 0b11110011;
3398  let Inst{15-12} = Rd;
3399  let Inst{19-16} = sat_imm;
3400  let Inst{3-0} = Rn;
3401}
3402
3403def USAT : AI<(outs GPRnopc:$Rd),
3404              (ins imm0_31:$sat_imm, GPRnopc:$Rn, shift_imm:$sh),
3405              SatFrm, NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> {
3406  bits<4> Rd;
3407  bits<5> sat_imm;
3408  bits<4> Rn;
3409  bits<8> sh;
3410  let Inst{27-21} = 0b0110111;
3411  let Inst{5-4} = 0b01;
3412  let Inst{15-12} = Rd;
3413  let Inst{11-7} = sh{4-0};
3414  let Inst{6} = sh{5};
3415  let Inst{20-16} = sat_imm;
3416  let Inst{3-0} = Rn;
3417}
3418
3419def USAT16 : AI<(outs GPRnopc:$Rd),
3420                (ins imm0_15:$sat_imm, GPRnopc:$Rn), SatFrm,
3421                NoItinerary, "usat16", "\t$Rd, $sat_imm, $Rn", []> {
3422  bits<4> Rd;
3423  bits<4> sat_imm;
3424  bits<4> Rn;
3425  let Inst{27-20} = 0b01101110;
3426  let Inst{11-4} = 0b11110011;
3427  let Inst{15-12} = Rd;
3428  let Inst{19-16} = sat_imm;
3429  let Inst{3-0} = Rn;
3430}
3431
3432def : ARMV6Pat<(int_arm_ssat GPRnopc:$a, imm:$pos),
3433               (SSAT imm:$pos, GPRnopc:$a, 0)>;
3434def : ARMV6Pat<(int_arm_usat GPRnopc:$a, imm:$pos),
3435               (USAT imm:$pos, GPRnopc:$a, 0)>;
3436
3437//===----------------------------------------------------------------------===//
3438//  Bitwise Instructions.
3439//
3440
3441defm AND   : AsI1_bin_irs<0b0000, "and",
3442                          IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3443                          BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
3444defm ORR   : AsI1_bin_irs<0b1100, "orr",
3445                          IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3446                          BinOpFrag<(or  node:$LHS, node:$RHS)>, 1>;
3447defm EOR   : AsI1_bin_irs<0b0001, "eor",
3448                          IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3449                          BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
3450defm BIC   : AsI1_bin_irs<0b1110, "bic",
3451                          IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3452                          BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
3453
3454// FIXME: bf_inv_mask_imm should be two operands, the lsb and the msb, just
3455// like in the actual instruction encoding. The complexity of mapping the mask
3456// to the lsb/msb pair should be handled by ISel, not encapsulated in the
3457// instruction description.
3458def BFC    : I<(outs GPR:$Rd), (ins GPR:$src, bf_inv_mask_imm:$imm),
3459               AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3460               "bfc", "\t$Rd, $imm", "$src = $Rd",
3461               [(set GPR:$Rd, (and GPR:$src, bf_inv_mask_imm:$imm))]>,
3462               Requires<[IsARM, HasV6T2]> {
3463  bits<4> Rd;
3464  bits<10> imm;
3465  let Inst{27-21} = 0b0111110;
3466  let Inst{6-0}   = 0b0011111;
3467  let Inst{15-12} = Rd;
3468  let Inst{11-7}  = imm{4-0}; // lsb
3469  let Inst{20-16} = imm{9-5}; // msb
3470}
3471
3472// A8.6.18  BFI - Bitfield insert (Encoding A1)
3473def BFI:I<(outs GPRnopc:$Rd), (ins GPRnopc:$src, GPR:$Rn, bf_inv_mask_imm:$imm),
3474          AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3475          "bfi", "\t$Rd, $Rn, $imm", "$src = $Rd",
3476          [(set GPRnopc:$Rd, (ARMbfi GPRnopc:$src, GPR:$Rn,
3477                           bf_inv_mask_imm:$imm))]>,
3478          Requires<[IsARM, HasV6T2]> {
3479  bits<4> Rd;
3480  bits<4> Rn;
3481  bits<10> imm;
3482  let Inst{27-21} = 0b0111110;
3483  let Inst{6-4}   = 0b001; // Rn: Inst{3-0} != 15
3484  let Inst{15-12} = Rd;
3485  let Inst{11-7}  = imm{4-0}; // lsb
3486  let Inst{20-16} = imm{9-5}; // width
3487  let Inst{3-0}   = Rn;
3488}
3489
3490def  MVNr  : AsI1<0b1111, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMVNr,
3491                  "mvn", "\t$Rd, $Rm",
3492                  [(set GPR:$Rd, (not GPR:$Rm))]>, UnaryDP, Sched<[WriteALU]> {
3493  bits<4> Rd;
3494  bits<4> Rm;
3495  let Inst{25} = 0;
3496  let Inst{19-16} = 0b0000;
3497  let Inst{11-4} = 0b00000000;
3498  let Inst{15-12} = Rd;
3499  let Inst{3-0} = Rm;
3500}
3501def  MVNsi  : AsI1<0b1111, (outs GPR:$Rd), (ins so_reg_imm:$shift),
3502                  DPSoRegImmFrm, IIC_iMVNsr, "mvn", "\t$Rd, $shift",
3503                  [(set GPR:$Rd, (not so_reg_imm:$shift))]>, UnaryDP,
3504                  Sched<[WriteALU]> {
3505  bits<4> Rd;
3506  bits<12> shift;
3507  let Inst{25} = 0;
3508  let Inst{19-16} = 0b0000;
3509  let Inst{15-12} = Rd;
3510  let Inst{11-5} = shift{11-5};
3511  let Inst{4} = 0;
3512  let Inst{3-0} = shift{3-0};
3513}
3514def  MVNsr  : AsI1<0b1111, (outs GPR:$Rd), (ins so_reg_reg:$shift),
3515                  DPSoRegRegFrm, IIC_iMVNsr, "mvn", "\t$Rd, $shift",
3516                  [(set GPR:$Rd, (not so_reg_reg:$shift))]>, UnaryDP,
3517                  Sched<[WriteALU]> {
3518  bits<4> Rd;
3519  bits<12> shift;
3520  let Inst{25} = 0;
3521  let Inst{19-16} = 0b0000;
3522  let Inst{15-12} = Rd;
3523  let Inst{11-8} = shift{11-8};
3524  let Inst{7} = 0;
3525  let Inst{6-5} = shift{6-5};
3526  let Inst{4} = 1;
3527  let Inst{3-0} = shift{3-0};
3528}
3529let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
3530def  MVNi  : AsI1<0b1111, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm,
3531                  IIC_iMVNi, "mvn", "\t$Rd, $imm",
3532                  [(set GPR:$Rd, so_imm_not:$imm)]>,UnaryDP, Sched<[WriteALU]> {
3533  bits<4> Rd;
3534  bits<12> imm;
3535  let Inst{25} = 1;
3536  let Inst{19-16} = 0b0000;
3537  let Inst{15-12} = Rd;
3538  let Inst{11-0} = imm;
3539}
3540
3541def : ARMPat<(and   GPR:$src, so_imm_not:$imm),
3542             (BICri GPR:$src, so_imm_not:$imm)>;
3543
3544//===----------------------------------------------------------------------===//
3545//  Multiply Instructions.
3546//
3547class AsMul1I32<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
3548             string opc, string asm, list<dag> pattern>
3549  : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
3550  bits<4> Rd;
3551  bits<4> Rm;
3552  bits<4> Rn;
3553  let Inst{19-16} = Rd;
3554  let Inst{11-8}  = Rm;
3555  let Inst{3-0}   = Rn;
3556}
3557class AsMul1I64<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
3558             string opc, string asm, list<dag> pattern>
3559  : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
3560  bits<4> RdLo;
3561  bits<4> RdHi;
3562  bits<4> Rm;
3563  bits<4> Rn;
3564  let Inst{19-16} = RdHi;
3565  let Inst{15-12} = RdLo;
3566  let Inst{11-8}  = Rm;
3567  let Inst{3-0}   = Rn;
3568}
3569class AsMla1I64<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
3570             string opc, string asm, list<dag> pattern>
3571  : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
3572  bits<4> RdLo;
3573  bits<4> RdHi;
3574  bits<4> Rm;
3575  bits<4> Rn;
3576  let Inst{19-16} = RdHi;
3577  let Inst{15-12} = RdLo;
3578  let Inst{11-8}  = Rm;
3579  let Inst{3-0}   = Rn;
3580}
3581
3582// FIXME: The v5 pseudos are only necessary for the additional Constraint
3583//        property. Remove them when it's possible to add those properties
3584//        on an individual MachineInstr, not just an instruction description.
3585let isCommutable = 1, TwoOperandAliasConstraint = "$Rn = $Rd" in {
3586def MUL : AsMul1I32<0b0000000, (outs GPRnopc:$Rd),
3587                    (ins GPRnopc:$Rn, GPRnopc:$Rm),
3588                    IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm",
3589                  [(set GPRnopc:$Rd, (mul GPRnopc:$Rn, GPRnopc:$Rm))]>,
3590                  Requires<[IsARM, HasV6]> {
3591  let Inst{15-12} = 0b0000;
3592  let Unpredictable{15-12} = 0b1111;
3593}
3594
3595let Constraints = "@earlyclobber $Rd" in
3596def MULv5: ARMPseudoExpand<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, GPRnopc:$Rm,
3597                                                    pred:$p, cc_out:$s),
3598                           4, IIC_iMUL32,
3599               [(set GPRnopc:$Rd, (mul GPRnopc:$Rn, GPRnopc:$Rm))],
3600               (MUL GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p, cc_out:$s)>,
3601               Requires<[IsARM, NoV6, UseMulOps]>;
3602}
3603
3604def MLA  : AsMul1I32<0b0000001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3605                     IIC_iMAC32, "mla", "\t$Rd, $Rn, $Rm, $Ra",
3606                   [(set GPR:$Rd, (add (mul GPR:$Rn, GPR:$Rm), GPR:$Ra))]>,
3607                   Requires<[IsARM, HasV6, UseMulOps]> {
3608  bits<4> Ra;
3609  let Inst{15-12} = Ra;
3610}
3611
3612let Constraints = "@earlyclobber $Rd" in
3613def MLAv5: ARMPseudoExpand<(outs GPR:$Rd),
3614                           (ins GPR:$Rn, GPR:$Rm, GPR:$Ra, pred:$p, cc_out:$s),
3615                           4, IIC_iMAC32,
3616                        [(set GPR:$Rd, (add (mul GPR:$Rn, GPR:$Rm), GPR:$Ra))],
3617                  (MLA GPR:$Rd, GPR:$Rn, GPR:$Rm, GPR:$Ra, pred:$p, cc_out:$s)>,
3618                        Requires<[IsARM, NoV6]>;
3619
3620def MLS  : AMul1I<0b0000011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3621                   IIC_iMAC32, "mls", "\t$Rd, $Rn, $Rm, $Ra",
3622                   [(set GPR:$Rd, (sub GPR:$Ra, (mul GPR:$Rn, GPR:$Rm)))]>,
3623                   Requires<[IsARM, HasV6T2, UseMulOps]> {
3624  bits<4> Rd;
3625  bits<4> Rm;
3626  bits<4> Rn;
3627  bits<4> Ra;
3628  let Inst{19-16} = Rd;
3629  let Inst{15-12} = Ra;
3630  let Inst{11-8}  = Rm;
3631  let Inst{3-0}   = Rn;
3632}
3633
3634// Extra precision multiplies with low / high results
3635let neverHasSideEffects = 1 in {
3636let isCommutable = 1 in {
3637def SMULL : AsMul1I64<0b0000110, (outs GPR:$RdLo, GPR:$RdHi),
3638                                 (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
3639                    "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3640                    Requires<[IsARM, HasV6]>;
3641
3642def UMULL : AsMul1I64<0b0000100, (outs GPR:$RdLo, GPR:$RdHi),
3643                                 (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
3644                    "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3645                    Requires<[IsARM, HasV6]>;
3646
3647let Constraints = "@earlyclobber $RdLo,@earlyclobber $RdHi" in {
3648def SMULLv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3649                            (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3650                            4, IIC_iMUL64, [],
3651          (SMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3652                           Requires<[IsARM, NoV6]>;
3653
3654def UMULLv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3655                            (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3656                            4, IIC_iMUL64, [],
3657          (UMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3658                           Requires<[IsARM, NoV6]>;
3659}
3660}
3661
3662// Multiply + accumulate
3663def SMLAL : AsMla1I64<0b0000111, (outs GPR:$RdLo, GPR:$RdHi),
3664                        (ins GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi), IIC_iMAC64,
3665                    "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3666         RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">, Requires<[IsARM, HasV6]>;
3667def UMLAL : AsMla1I64<0b0000101, (outs GPR:$RdLo, GPR:$RdHi),
3668                        (ins GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi), IIC_iMAC64,
3669                    "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3670         RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">, Requires<[IsARM, HasV6]>;
3671
3672def UMAAL : AMul1I <0b0000010, (outs GPR:$RdLo, GPR:$RdHi),
3673                               (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
3674                    "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3675                    Requires<[IsARM, HasV6]> {
3676  bits<4> RdLo;
3677  bits<4> RdHi;
3678  bits<4> Rm;
3679  bits<4> Rn;
3680  let Inst{19-16} = RdHi;
3681  let Inst{15-12} = RdLo;
3682  let Inst{11-8}  = Rm;
3683  let Inst{3-0}   = Rn;
3684}
3685
3686let Constraints = "$RLo = $RdLo,$RHi = $RdHi" in {
3687def SMLALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3688                (ins GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi, pred:$p, cc_out:$s),
3689                              4, IIC_iMAC64, [],
3690             (SMLAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi,
3691                           pred:$p, cc_out:$s)>,
3692                           Requires<[IsARM, NoV6]>;
3693def UMLALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3694                (ins GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi, pred:$p, cc_out:$s),
3695                              4, IIC_iMAC64, [],
3696             (UMLAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi,
3697                           pred:$p, cc_out:$s)>,
3698                           Requires<[IsARM, NoV6]>;
3699}
3700
3701let Constraints = "@earlyclobber $RdLo,@earlyclobber $RdHi" in {
3702def UMAALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3703                              (ins GPR:$Rn, GPR:$Rm, pred:$p),
3704                              4, IIC_iMAC64, [],
3705          (UMAAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p)>,
3706                           Requires<[IsARM, NoV6]>;
3707}
3708
3709} // neverHasSideEffects
3710
3711// Most significant word multiply
3712def SMMUL : AMul2I <0b0111010, 0b0001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3713               IIC_iMUL32, "smmul", "\t$Rd, $Rn, $Rm",
3714               [(set GPR:$Rd, (mulhs GPR:$Rn, GPR:$Rm))]>,
3715            Requires<[IsARM, HasV6]> {
3716  let Inst{15-12} = 0b1111;
3717}
3718
3719def SMMULR : AMul2I <0b0111010, 0b0011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3720               IIC_iMUL32, "smmulr", "\t$Rd, $Rn, $Rm", []>,
3721            Requires<[IsARM, HasV6]> {
3722  let Inst{15-12} = 0b1111;
3723}
3724
3725def SMMLA : AMul2Ia <0b0111010, 0b0001, (outs GPR:$Rd),
3726               (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3727               IIC_iMAC32, "smmla", "\t$Rd, $Rn, $Rm, $Ra",
3728               [(set GPR:$Rd, (add (mulhs GPR:$Rn, GPR:$Rm), GPR:$Ra))]>,
3729            Requires<[IsARM, HasV6, UseMulOps]>;
3730
3731def SMMLAR : AMul2Ia <0b0111010, 0b0011, (outs GPR:$Rd),
3732               (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3733               IIC_iMAC32, "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
3734            Requires<[IsARM, HasV6]>;
3735
3736def SMMLS : AMul2Ia <0b0111010, 0b1101, (outs GPR:$Rd),
3737               (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3738               IIC_iMAC32, "smmls", "\t$Rd, $Rn, $Rm, $Ra", []>,
3739            Requires<[IsARM, HasV6, UseMulOps]>;
3740
3741def SMMLSR : AMul2Ia <0b0111010, 0b1111, (outs GPR:$Rd),
3742               (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3743               IIC_iMAC32, "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
3744            Requires<[IsARM, HasV6]>;
3745
3746multiclass AI_smul<string opc, PatFrag opnode> {
3747  def BB : AMulxyI<0b0001011, 0b00, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3748              IIC_iMUL16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
3749              [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
3750                                      (sext_inreg GPR:$Rm, i16)))]>,
3751           Requires<[IsARM, HasV5TE]>;
3752
3753  def BT : AMulxyI<0b0001011, 0b10, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3754              IIC_iMUL16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
3755              [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
3756                                      (sra GPR:$Rm, (i32 16))))]>,
3757           Requires<[IsARM, HasV5TE]>;
3758
3759  def TB : AMulxyI<0b0001011, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3760              IIC_iMUL16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
3761              [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
3762                                      (sext_inreg GPR:$Rm, i16)))]>,
3763           Requires<[IsARM, HasV5TE]>;
3764
3765  def TT : AMulxyI<0b0001011, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3766              IIC_iMUL16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
3767              [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
3768                                      (sra GPR:$Rm, (i32 16))))]>,
3769            Requires<[IsARM, HasV5TE]>;
3770
3771  def WB : AMulxyI<0b0001001, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3772              IIC_iMUL16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
3773              [(set GPR:$Rd, (sra (opnode GPR:$Rn,
3774                                    (sext_inreg GPR:$Rm, i16)), (i32 16)))]>,
3775           Requires<[IsARM, HasV5TE]>;
3776
3777  def WT : AMulxyI<0b0001001, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3778              IIC_iMUL16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
3779              [(set GPR:$Rd, (sra (opnode GPR:$Rn,
3780                                    (sra GPR:$Rm, (i32 16))), (i32 16)))]>,
3781            Requires<[IsARM, HasV5TE]>;
3782}
3783
3784
3785multiclass AI_smla<string opc, PatFrag opnode> {
3786  let DecoderMethod = "DecodeSMLAInstruction" in {
3787  def BB : AMulxyIa<0b0001000, 0b00, (outs GPRnopc:$Rd),
3788              (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3789              IIC_iMAC16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
3790              [(set GPRnopc:$Rd, (add GPR:$Ra,
3791                               (opnode (sext_inreg GPRnopc:$Rn, i16),
3792                                       (sext_inreg GPRnopc:$Rm, i16))))]>,
3793           Requires<[IsARM, HasV5TE, UseMulOps]>;
3794
3795  def BT : AMulxyIa<0b0001000, 0b10, (outs GPRnopc:$Rd),
3796              (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3797              IIC_iMAC16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
3798              [(set GPRnopc:$Rd,
3799                    (add GPR:$Ra, (opnode (sext_inreg GPRnopc:$Rn, i16),
3800                                          (sra GPRnopc:$Rm, (i32 16)))))]>,
3801           Requires<[IsARM, HasV5TE, UseMulOps]>;
3802
3803  def TB : AMulxyIa<0b0001000, 0b01, (outs GPRnopc:$Rd),
3804              (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3805              IIC_iMAC16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
3806              [(set GPRnopc:$Rd,
3807                    (add GPR:$Ra, (opnode (sra GPRnopc:$Rn, (i32 16)),
3808                                          (sext_inreg GPRnopc:$Rm, i16))))]>,
3809           Requires<[IsARM, HasV5TE, UseMulOps]>;
3810
3811  def TT : AMulxyIa<0b0001000, 0b11, (outs GPRnopc:$Rd),
3812              (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3813              IIC_iMAC16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
3814             [(set GPRnopc:$Rd,
3815                   (add GPR:$Ra, (opnode (sra GPRnopc:$Rn, (i32 16)),
3816                                         (sra GPRnopc:$Rm, (i32 16)))))]>,
3817            Requires<[IsARM, HasV5TE, UseMulOps]>;
3818
3819  def WB : AMulxyIa<0b0001001, 0b00, (outs GPRnopc:$Rd),
3820              (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3821              IIC_iMAC16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
3822              [(set GPRnopc:$Rd,
3823                    (add GPR:$Ra, (sra (opnode GPRnopc:$Rn,
3824                                  (sext_inreg GPRnopc:$Rm, i16)), (i32 16))))]>,
3825           Requires<[IsARM, HasV5TE, UseMulOps]>;
3826
3827  def WT : AMulxyIa<0b0001001, 0b10, (outs GPRnopc:$Rd),
3828              (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3829              IIC_iMAC16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
3830              [(set GPRnopc:$Rd,
3831                 (add GPR:$Ra, (sra (opnode GPRnopc:$Rn,
3832                                    (sra GPRnopc:$Rm, (i32 16))), (i32 16))))]>,
3833            Requires<[IsARM, HasV5TE, UseMulOps]>;
3834  }
3835}
3836
3837defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
3838defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
3839
3840// Halfword multiply accumulate long: SMLAL<x><y>.
3841def SMLALBB : AMulxyI64<0b0001010, 0b00, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3842                      (ins GPRnopc:$Rn, GPRnopc:$Rm),
3843                      IIC_iMAC64, "smlalbb", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3844              Requires<[IsARM, HasV5TE]>;
3845
3846def SMLALBT : AMulxyI64<0b0001010, 0b10, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3847                      (ins GPRnopc:$Rn, GPRnopc:$Rm),
3848                      IIC_iMAC64, "smlalbt", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3849              Requires<[IsARM, HasV5TE]>;
3850
3851def SMLALTB : AMulxyI64<0b0001010, 0b01, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3852                      (ins GPRnopc:$Rn, GPRnopc:$Rm),
3853                      IIC_iMAC64, "smlaltb", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3854              Requires<[IsARM, HasV5TE]>;
3855
3856def SMLALTT : AMulxyI64<0b0001010, 0b11, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3857                      (ins GPRnopc:$Rn, GPRnopc:$Rm),
3858                      IIC_iMAC64, "smlaltt", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3859              Requires<[IsARM, HasV5TE]>;
3860
3861// Helper class for AI_smld.
3862class AMulDualIbase<bit long, bit sub, bit swap, dag oops, dag iops,
3863                    InstrItinClass itin, string opc, string asm>
3864  : AI<oops, iops, MulFrm, itin, opc, asm, []>, Requires<[IsARM, HasV6]> {
3865  bits<4> Rn;
3866  bits<4> Rm;
3867  let Inst{27-23} = 0b01110;
3868  let Inst{22}    = long;
3869  let Inst{21-20} = 0b00;
3870  let Inst{11-8}  = Rm;
3871  let Inst{7}     = 0;
3872  let Inst{6}     = sub;
3873  let Inst{5}     = swap;
3874  let Inst{4}     = 1;
3875  let Inst{3-0}   = Rn;
3876}
3877class AMulDualI<bit long, bit sub, bit swap, dag oops, dag iops,
3878                InstrItinClass itin, string opc, string asm>
3879  : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3880  bits<4> Rd;
3881  let Inst{15-12} = 0b1111;
3882  let Inst{19-16} = Rd;
3883}
3884class AMulDualIa<bit long, bit sub, bit swap, dag oops, dag iops,
3885                InstrItinClass itin, string opc, string asm>
3886  : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3887  bits<4> Ra;
3888  bits<4> Rd;
3889  let Inst{19-16} = Rd;
3890  let Inst{15-12} = Ra;
3891}
3892class AMulDualI64<bit long, bit sub, bit swap, dag oops, dag iops,
3893                  InstrItinClass itin, string opc, string asm>
3894  : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3895  bits<4> RdLo;
3896  bits<4> RdHi;
3897  let Inst{19-16} = RdHi;
3898  let Inst{15-12} = RdLo;
3899}
3900
3901multiclass AI_smld<bit sub, string opc> {
3902
3903  def D : AMulDualIa<0, sub, 0, (outs GPRnopc:$Rd),
3904                  (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3905                  NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm, $Ra">;
3906
3907  def DX: AMulDualIa<0, sub, 1, (outs GPRnopc:$Rd),
3908                  (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3909                  NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm, $Ra">;
3910
3911  def LD: AMulDualI64<1, sub, 0, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3912                  (ins GPRnopc:$Rn, GPRnopc:$Rm), NoItinerary,
3913                  !strconcat(opc, "ld"), "\t$RdLo, $RdHi, $Rn, $Rm">;
3914
3915  def LDX : AMulDualI64<1, sub, 1, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3916                  (ins GPRnopc:$Rn, GPRnopc:$Rm), NoItinerary,
3917                  !strconcat(opc, "ldx"),"\t$RdLo, $RdHi, $Rn, $Rm">;
3918
3919}
3920
3921defm SMLA : AI_smld<0, "smla">;
3922defm SMLS : AI_smld<1, "smls">;
3923
3924multiclass AI_sdml<bit sub, string opc> {
3925
3926  def D:AMulDualI<0, sub, 0, (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, GPRnopc:$Rm),
3927                  NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm">;
3928  def DX:AMulDualI<0, sub, 1, (outs GPRnopc:$Rd),(ins GPRnopc:$Rn, GPRnopc:$Rm),
3929                  NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm">;
3930}
3931
3932defm SMUA : AI_sdml<0, "smua">;
3933defm SMUS : AI_sdml<1, "smus">;
3934
3935//===----------------------------------------------------------------------===//
3936//  Division Instructions (ARMv7-A with virtualization extension)
3937//
3938def SDIV : ADivA1I<0b001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), IIC_iDIV,
3939                   "sdiv", "\t$Rd, $Rn, $Rm",
3940                   [(set GPR:$Rd, (sdiv GPR:$Rn, GPR:$Rm))]>,
3941           Requires<[IsARM, HasDivideInARM]>;
3942
3943def UDIV : ADivA1I<0b011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), IIC_iDIV,
3944                   "udiv", "\t$Rd, $Rn, $Rm",
3945                   [(set GPR:$Rd, (udiv GPR:$Rn, GPR:$Rm))]>,
3946           Requires<[IsARM, HasDivideInARM]>;
3947
3948//===----------------------------------------------------------------------===//
3949//  Misc. Arithmetic Instructions.
3950//
3951
3952def CLZ  : AMiscA1I<0b000010110, 0b0001, (outs GPR:$Rd), (ins GPR:$Rm),
3953              IIC_iUNAr, "clz", "\t$Rd, $Rm",
3954              [(set GPR:$Rd, (ctlz GPR:$Rm))]>, Requires<[IsARM, HasV5T]>,
3955           Sched<[WriteALU]>;
3956
3957def RBIT : AMiscA1I<0b01101111, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
3958              IIC_iUNAr, "rbit", "\t$Rd, $Rm",
3959              [(set GPR:$Rd, (ARMrbit GPR:$Rm))]>,
3960           Requires<[IsARM, HasV6T2]>,
3961           Sched<[WriteALU]>;
3962
3963def REV  : AMiscA1I<0b01101011, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
3964              IIC_iUNAr, "rev", "\t$Rd, $Rm",
3965              [(set GPR:$Rd, (bswap GPR:$Rm))]>, Requires<[IsARM, HasV6]>,
3966           Sched<[WriteALU]>;
3967
3968let AddedComplexity = 5 in
3969def REV16 : AMiscA1I<0b01101011, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
3970               IIC_iUNAr, "rev16", "\t$Rd, $Rm",
3971               [(set GPR:$Rd, (rotr (bswap GPR:$Rm), (i32 16)))]>,
3972               Requires<[IsARM, HasV6]>,
3973           Sched<[WriteALU]>;
3974
3975let AddedComplexity = 5 in
3976def REVSH : AMiscA1I<0b01101111, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
3977               IIC_iUNAr, "revsh", "\t$Rd, $Rm",
3978               [(set GPR:$Rd, (sra (bswap GPR:$Rm), (i32 16)))]>,
3979               Requires<[IsARM, HasV6]>,
3980           Sched<[WriteALU]>;
3981
3982def : ARMV6Pat<(or (sra (shl GPR:$Rm, (i32 24)), (i32 16)),
3983                   (and (srl GPR:$Rm, (i32 8)), 0xFF)),
3984               (REVSH GPR:$Rm)>;
3985
3986def PKHBT : APKHI<0b01101000, 0, (outs GPRnopc:$Rd),
3987                              (ins GPRnopc:$Rn, GPRnopc:$Rm, pkh_lsl_amt:$sh),
3988               IIC_iALUsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
3989               [(set GPRnopc:$Rd, (or (and GPRnopc:$Rn, 0xFFFF),
3990                                      (and (shl GPRnopc:$Rm, pkh_lsl_amt:$sh),
3991                                           0xFFFF0000)))]>,
3992               Requires<[IsARM, HasV6]>,
3993           Sched<[WriteALUsi, ReadALU]>;
3994
3995// Alternate cases for PKHBT where identities eliminate some nodes.
3996def : ARMV6Pat<(or (and GPRnopc:$Rn, 0xFFFF), (and GPRnopc:$Rm, 0xFFFF0000)),
3997               (PKHBT GPRnopc:$Rn, GPRnopc:$Rm, 0)>;
3998def : ARMV6Pat<(or (and GPRnopc:$Rn, 0xFFFF), (shl GPRnopc:$Rm, imm16_31:$sh)),
3999               (PKHBT GPRnopc:$Rn, GPRnopc:$Rm, imm16_31:$sh)>;
4000
4001// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
4002// will match the pattern below.
4003def PKHTB : APKHI<0b01101000, 1, (outs GPRnopc:$Rd),
4004                              (ins GPRnopc:$Rn, GPRnopc:$Rm, pkh_asr_amt:$sh),
4005               IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
4006               [(set GPRnopc:$Rd, (or (and GPRnopc:$Rn, 0xFFFF0000),
4007                                      (and (sra GPRnopc:$Rm, pkh_asr_amt:$sh),
4008                                           0xFFFF)))]>,
4009               Requires<[IsARM, HasV6]>,
4010           Sched<[WriteALUsi, ReadALU]>;
4011
4012// Alternate cases for PKHTB where identities eliminate some nodes.  Note that
4013// a shift amount of 0 is *not legal* here, it is PKHBT instead.
4014// We also can not replace a srl (17..31) by an arithmetic shift we would use in
4015// pkhtb src1, src2, asr (17..31).
4016def : ARMV6Pat<(or (and GPRnopc:$src1, 0xFFFF0000),
4017                   (srl GPRnopc:$src2, imm16:$sh)),
4018               (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm16:$sh)>;
4019def : ARMV6Pat<(or (and GPRnopc:$src1, 0xFFFF0000),
4020                   (sra GPRnopc:$src2, imm16_31:$sh)),
4021               (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm16_31:$sh)>;
4022def : ARMV6Pat<(or (and GPRnopc:$src1, 0xFFFF0000),
4023                   (and (srl GPRnopc:$src2, imm1_15:$sh), 0xFFFF)),
4024               (PKHTB GPRnopc:$src1, GPRnopc:$src2, imm1_15:$sh)>;
4025
4026//===----------------------------------------------------------------------===//
4027// CRC Instructions
4028//
4029// Polynomials:
4030// + CRC32{B,H,W}       0x04C11DB7
4031// + CRC32C{B,H,W}      0x1EDC6F41
4032//
4033
4034class AI_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin>
4035  : AInoP<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, GPRnopc:$Rm), MiscFrm, NoItinerary,
4036               !strconcat("crc32", suffix), "\t$Rd, $Rn, $Rm",
4037               [(set GPRnopc:$Rd, (builtin GPRnopc:$Rn, GPRnopc:$Rm))]>,
4038               Requires<[IsARM, HasV8, HasCRC]> {
4039  bits<4> Rd;
4040  bits<4> Rn;
4041  bits<4> Rm;
4042
4043  let Inst{31-28} = 0b1110;
4044  let Inst{27-23} = 0b00010;
4045  let Inst{22-21} = sz;
4046  let Inst{20}    = 0;
4047  let Inst{19-16} = Rn;
4048  let Inst{15-12} = Rd;
4049  let Inst{11-10} = 0b00;
4050  let Inst{9}     = C;
4051  let Inst{8}     = 0;
4052  let Inst{7-4}   = 0b0100;
4053  let Inst{3-0}   = Rm;
4054
4055  let Unpredictable{11-8} = 0b1101;
4056}
4057
4058def CRC32B  : AI_crc32<0, 0b00, "b", int_arm_crc32b>;
4059def CRC32CB : AI_crc32<1, 0b00, "cb", int_arm_crc32cb>;
4060def CRC32H  : AI_crc32<0, 0b01, "h", int_arm_crc32h>;
4061def CRC32CH : AI_crc32<1, 0b01, "ch", int_arm_crc32ch>;
4062def CRC32W  : AI_crc32<0, 0b10, "w", int_arm_crc32w>;
4063def CRC32CW : AI_crc32<1, 0b10, "cw", int_arm_crc32cw>;
4064
4065//===----------------------------------------------------------------------===//
4066//  Comparison Instructions...
4067//
4068
4069defm CMP  : AI1_cmp_irs<0b1010, "cmp",
4070                        IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
4071                        BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
4072
4073// ARMcmpZ can re-use the above instruction definitions.
4074def : ARMPat<(ARMcmpZ GPR:$src, so_imm:$imm),
4075             (CMPri   GPR:$src, so_imm:$imm)>;
4076def : ARMPat<(ARMcmpZ GPR:$src, GPR:$rhs),
4077             (CMPrr   GPR:$src, GPR:$rhs)>;
4078def : ARMPat<(ARMcmpZ GPR:$src, so_reg_imm:$rhs),
4079             (CMPrsi   GPR:$src, so_reg_imm:$rhs)>;
4080def : ARMPat<(ARMcmpZ GPR:$src, so_reg_reg:$rhs),
4081             (CMPrsr   GPR:$src, so_reg_reg:$rhs)>;
4082
4083// CMN register-integer
4084let isCompare = 1, Defs = [CPSR] in {
4085def CMNri : AI1<0b1011, (outs), (ins GPR:$Rn, so_imm:$imm), DPFrm, IIC_iCMPi,
4086                "cmn", "\t$Rn, $imm",
4087                [(ARMcmn GPR:$Rn, so_imm:$imm)]>,
4088                Sched<[WriteCMP, ReadALU]> {
4089  bits<4> Rn;
4090  bits<12> imm;
4091  let Inst{25} = 1;
4092  let Inst{20} = 1;
4093  let Inst{19-16} = Rn;
4094  let Inst{15-12} = 0b0000;
4095  let Inst{11-0} = imm;
4096
4097  let Unpredictable{15-12} = 0b1111;
4098}
4099
4100// CMN register-register/shift
4101def CMNzrr : AI1<0b1011, (outs), (ins GPR:$Rn, GPR:$Rm), DPFrm, IIC_iCMPr,
4102                 "cmn", "\t$Rn, $Rm",
4103                 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
4104                   GPR:$Rn, GPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> {
4105  bits<4> Rn;
4106  bits<4> Rm;
4107  let isCommutable = 1;
4108  let Inst{25} = 0;
4109  let Inst{20} = 1;
4110  let Inst{19-16} = Rn;
4111  let Inst{15-12} = 0b0000;
4112  let Inst{11-4} = 0b00000000;
4113  let Inst{3-0} = Rm;
4114
4115  let Unpredictable{15-12} = 0b1111;
4116}
4117
4118def CMNzrsi : AI1<0b1011, (outs),
4119                  (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm, IIC_iCMPsr,
4120                  "cmn", "\t$Rn, $shift",
4121                  [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
4122                    GPR:$Rn, so_reg_imm:$shift)]>,
4123                    Sched<[WriteCMPsi, ReadALU]> {
4124  bits<4> Rn;
4125  bits<12> shift;
4126  let Inst{25} = 0;
4127  let Inst{20} = 1;
4128  let Inst{19-16} = Rn;
4129  let Inst{15-12} = 0b0000;
4130  let Inst{11-5} = shift{11-5};
4131  let Inst{4} = 0;
4132  let Inst{3-0} = shift{3-0};
4133
4134  let Unpredictable{15-12} = 0b1111;
4135}
4136
4137def CMNzrsr : AI1<0b1011, (outs),
4138                  (ins GPRnopc:$Rn, so_reg_reg:$shift), DPSoRegRegFrm, IIC_iCMPsr,
4139                  "cmn", "\t$Rn, $shift",
4140                  [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
4141                    GPRnopc:$Rn, so_reg_reg:$shift)]>,
4142                    Sched<[WriteCMPsr, ReadALU]> {
4143  bits<4> Rn;
4144  bits<12> shift;
4145  let Inst{25} = 0;
4146  let Inst{20} = 1;
4147  let Inst{19-16} = Rn;
4148  let Inst{15-12} = 0b0000;
4149  let Inst{11-8} = shift{11-8};
4150  let Inst{7} = 0;
4151  let Inst{6-5} = shift{6-5};
4152  let Inst{4} = 1;
4153  let Inst{3-0} = shift{3-0};
4154
4155  let Unpredictable{15-12} = 0b1111;
4156}
4157
4158}
4159
4160def : ARMPat<(ARMcmp  GPR:$src, so_imm_neg:$imm),
4161             (CMNri   GPR:$src, so_imm_neg:$imm)>;
4162
4163def : ARMPat<(ARMcmpZ GPR:$src, so_imm_neg:$imm),
4164             (CMNri   GPR:$src, so_imm_neg:$imm)>;
4165
4166// Note that TST/TEQ don't set all the same flags that CMP does!
4167defm TST  : AI1_cmp_irs<0b1000, "tst",
4168                        IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
4169                      BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>, 1>;
4170defm TEQ  : AI1_cmp_irs<0b1001, "teq",
4171                        IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
4172                      BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>, 1>;
4173
4174// Pseudo i64 compares for some floating point compares.
4175let usesCustomInserter = 1, isBranch = 1, isTerminator = 1,
4176    Defs = [CPSR] in {
4177def BCCi64 : PseudoInst<(outs),
4178    (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, brtarget:$dst),
4179     IIC_Br,
4180    [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, bb:$dst)]>,
4181    Sched<[WriteBr]>;
4182
4183def BCCZi64 : PseudoInst<(outs),
4184     (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, brtarget:$dst), IIC_Br,
4185    [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, 0, 0, bb:$dst)]>,
4186    Sched<[WriteBr]>;
4187} // usesCustomInserter
4188
4189
4190// Conditional moves
4191let neverHasSideEffects = 1 in {
4192
4193let isCommutable = 1, isSelect = 1 in
4194def MOVCCr : ARMPseudoInst<(outs GPR:$Rd),
4195                           (ins GPR:$false, GPR:$Rm, cmovpred:$p),
4196                           4, IIC_iCMOVr,
4197                           [(set GPR:$Rd, (ARMcmov GPR:$false, GPR:$Rm,
4198                                                   cmovpred:$p))]>,
4199             RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
4200
4201def MOVCCsi : ARMPseudoInst<(outs GPR:$Rd),
4202                            (ins GPR:$false, so_reg_imm:$shift, cmovpred:$p),
4203                            4, IIC_iCMOVsr,
4204                            [(set GPR:$Rd,
4205                                  (ARMcmov GPR:$false, so_reg_imm:$shift,
4206                                           cmovpred:$p))]>,
4207      RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
4208def MOVCCsr : ARMPseudoInst<(outs GPR:$Rd),
4209                            (ins GPR:$false, so_reg_reg:$shift, cmovpred:$p),
4210                           4, IIC_iCMOVsr,
4211  [(set GPR:$Rd, (ARMcmov GPR:$false, so_reg_reg:$shift,
4212                            cmovpred:$p))]>,
4213      RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
4214
4215
4216let isMoveImm = 1 in
4217def MOVCCi16
4218    : ARMPseudoInst<(outs GPR:$Rd),
4219                    (ins GPR:$false, imm0_65535_expr:$imm, cmovpred:$p),
4220                    4, IIC_iMOVi,
4221                    [(set GPR:$Rd, (ARMcmov GPR:$false, imm0_65535:$imm,
4222                                            cmovpred:$p))]>,
4223      RegConstraint<"$false = $Rd">, Requires<[IsARM, HasV6T2]>,
4224      Sched<[WriteALU]>;
4225
4226let isMoveImm = 1 in
4227def MOVCCi : ARMPseudoInst<(outs GPR:$Rd),
4228                           (ins GPR:$false, so_imm:$imm, cmovpred:$p),
4229                           4, IIC_iCMOVi,
4230                           [(set GPR:$Rd, (ARMcmov GPR:$false, so_imm:$imm,
4231                                                   cmovpred:$p))]>,
4232      RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
4233
4234// Two instruction predicate mov immediate.
4235let isMoveImm = 1 in
4236def MOVCCi32imm
4237    : ARMPseudoInst<(outs GPR:$Rd),
4238                    (ins GPR:$false, i32imm:$src, cmovpred:$p),
4239                    8, IIC_iCMOVix2,
4240                    [(set GPR:$Rd, (ARMcmov GPR:$false, imm:$src,
4241                                            cmovpred:$p))]>,
4242      RegConstraint<"$false = $Rd">, Requires<[IsARM, HasV6T2]>;
4243
4244let isMoveImm = 1 in
4245def MVNCCi : ARMPseudoInst<(outs GPR:$Rd),
4246                           (ins GPR:$false, so_imm:$imm, cmovpred:$p),
4247                           4, IIC_iCMOVi,
4248                           [(set GPR:$Rd, (ARMcmov GPR:$false, so_imm_not:$imm,
4249                                                   cmovpred:$p))]>,
4250                RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
4251
4252} // neverHasSideEffects
4253
4254
4255//===----------------------------------------------------------------------===//
4256// Atomic operations intrinsics
4257//
4258
4259def MemBarrierOptOperand : AsmOperandClass {
4260  let Name = "MemBarrierOpt";
4261  let ParserMethod = "parseMemBarrierOptOperand";
4262}
4263def memb_opt : Operand<i32> {
4264  let PrintMethod = "printMemBOption";
4265  let ParserMatchClass = MemBarrierOptOperand;
4266  let DecoderMethod = "DecodeMemBarrierOption";
4267}
4268
4269def InstSyncBarrierOptOperand : AsmOperandClass {
4270  let Name = "InstSyncBarrierOpt";
4271  let ParserMethod = "parseInstSyncBarrierOptOperand";
4272}
4273def instsyncb_opt : Operand<i32> {
4274  let PrintMethod = "printInstSyncBOption";
4275  let ParserMatchClass = InstSyncBarrierOptOperand;
4276  let DecoderMethod = "DecodeInstSyncBarrierOption";
4277}
4278
4279// memory barriers protect the atomic sequences
4280let hasSideEffects = 1 in {
4281def DMB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
4282                "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>,
4283                Requires<[IsARM, HasDB]> {
4284  bits<4> opt;
4285  let Inst{31-4} = 0xf57ff05;
4286  let Inst{3-0} = opt;
4287}
4288}
4289
4290def DSB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
4291                "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>,
4292                Requires<[IsARM, HasDB]> {
4293  bits<4> opt;
4294  let Inst{31-4} = 0xf57ff04;
4295  let Inst{3-0} = opt;
4296}
4297
4298// ISB has only full system option
4299def ISB : AInoP<(outs), (ins instsyncb_opt:$opt), MiscFrm, NoItinerary,
4300                "isb", "\t$opt", []>,
4301                Requires<[IsARM, HasDB]> {
4302  bits<4> opt;
4303  let Inst{31-4} = 0xf57ff06;
4304  let Inst{3-0} = opt;
4305}
4306
4307let usesCustomInserter = 1, Defs = [CPSR] in {
4308
4309// Pseudo instruction that combines movs + predicated rsbmi
4310// to implement integer ABS
4311  def ABS : ARMPseudoInst<(outs GPR:$dst), (ins GPR:$src), 8, NoItinerary, []>;
4312
4313// Atomic pseudo-insts which will be lowered to ldrex/strex loops.
4314// (64-bit pseudos use a hand-written selection code).
4315  let mayLoad = 1, mayStore = 1 in {
4316    def ATOMIC_LOAD_ADD_I8 : PseudoInst<
4317      (outs GPR:$dst),
4318      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4319      NoItinerary, []>;
4320    def ATOMIC_LOAD_SUB_I8 : PseudoInst<
4321      (outs GPR:$dst),
4322      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4323      NoItinerary, []>;
4324    def ATOMIC_LOAD_AND_I8 : PseudoInst<
4325      (outs GPR:$dst),
4326      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4327      NoItinerary, []>;
4328    def ATOMIC_LOAD_OR_I8 : PseudoInst<
4329      (outs GPR:$dst),
4330      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4331      NoItinerary, []>;
4332    def ATOMIC_LOAD_XOR_I8 : PseudoInst<
4333      (outs GPR:$dst),
4334      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4335      NoItinerary, []>;
4336    def ATOMIC_LOAD_NAND_I8 : PseudoInst<
4337      (outs GPR:$dst),
4338      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4339      NoItinerary, []>;
4340    def ATOMIC_LOAD_MIN_I8 : PseudoInst<
4341      (outs GPR:$dst),
4342      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4343      NoItinerary, []>;
4344    def ATOMIC_LOAD_MAX_I8 : PseudoInst<
4345      (outs GPR:$dst),
4346      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4347      NoItinerary, []>;
4348    def ATOMIC_LOAD_UMIN_I8 : PseudoInst<
4349      (outs GPR:$dst),
4350      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4351      NoItinerary, []>;
4352    def ATOMIC_LOAD_UMAX_I8 : PseudoInst<
4353      (outs GPR:$dst),
4354      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4355      NoItinerary, []>;
4356    def ATOMIC_SWAP_I8 : PseudoInst<
4357      (outs GPR:$dst),
4358      (ins GPR:$ptr, GPR:$new, i32imm:$ordering),
4359      NoItinerary, []>;
4360    def ATOMIC_CMP_SWAP_I8 : PseudoInst<
4361      (outs GPR:$dst),
4362      (ins GPR:$ptr, GPR:$old, GPR:$new, i32imm:$ordering),
4363      NoItinerary, []>;
4364    def ATOMIC_LOAD_ADD_I16 : PseudoInst<
4365      (outs GPR:$dst),
4366      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4367      NoItinerary, []>;
4368    def ATOMIC_LOAD_SUB_I16 : PseudoInst<
4369      (outs GPR:$dst),
4370      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4371      NoItinerary, []>;
4372    def ATOMIC_LOAD_AND_I16 : PseudoInst<
4373      (outs GPR:$dst),
4374      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4375      NoItinerary, []>;
4376    def ATOMIC_LOAD_OR_I16 : PseudoInst<
4377      (outs GPR:$dst),
4378      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4379      NoItinerary, []>;
4380    def ATOMIC_LOAD_XOR_I16 : PseudoInst<
4381      (outs GPR:$dst),
4382      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4383      NoItinerary, []>;
4384    def ATOMIC_LOAD_NAND_I16 : PseudoInst<
4385      (outs GPR:$dst),
4386      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4387      NoItinerary, []>;
4388    def ATOMIC_LOAD_MIN_I16 : PseudoInst<
4389      (outs GPR:$dst),
4390      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4391      NoItinerary, []>;
4392    def ATOMIC_LOAD_MAX_I16 : PseudoInst<
4393      (outs GPR:$dst),
4394      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4395      NoItinerary, []>;
4396    def ATOMIC_LOAD_UMIN_I16 : PseudoInst<
4397      (outs GPR:$dst),
4398      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4399      NoItinerary, []>;
4400    def ATOMIC_LOAD_UMAX_I16 : PseudoInst<
4401      (outs GPR:$dst),
4402      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4403      NoItinerary, []>;
4404    def ATOMIC_SWAP_I16 : PseudoInst<
4405      (outs GPR:$dst),
4406      (ins GPR:$ptr, GPR:$new, i32imm:$ordering),
4407      NoItinerary, []>;
4408    def ATOMIC_CMP_SWAP_I16 : PseudoInst<
4409      (outs GPR:$dst),
4410      (ins GPR:$ptr, GPR:$old, GPR:$new, i32imm:$ordering),
4411      NoItinerary, []>;
4412    def ATOMIC_LOAD_ADD_I32 : PseudoInst<
4413      (outs GPR:$dst),
4414      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4415      NoItinerary, []>;
4416    def ATOMIC_LOAD_SUB_I32 : PseudoInst<
4417      (outs GPR:$dst),
4418      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4419      NoItinerary, []>;
4420    def ATOMIC_LOAD_AND_I32 : PseudoInst<
4421      (outs GPR:$dst),
4422      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4423      NoItinerary, []>;
4424    def ATOMIC_LOAD_OR_I32 : PseudoInst<
4425      (outs GPR:$dst),
4426      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4427      NoItinerary, []>;
4428    def ATOMIC_LOAD_XOR_I32 : PseudoInst<
4429      (outs GPR:$dst),
4430      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4431      NoItinerary, []>;
4432    def ATOMIC_LOAD_NAND_I32 : PseudoInst<
4433      (outs GPR:$dst),
4434      (ins GPR:$ptr, GPR:$incr, i32imm:$ordering),
4435      NoItinerary, []>;
4436    def ATOMIC_LOAD_MIN_I32 : PseudoInst<
4437      (outs GPR:$dst),
4438      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4439      NoItinerary, []>;
4440    def ATOMIC_LOAD_MAX_I32 : PseudoInst<
4441      (outs GPR:$dst),
4442      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4443      NoItinerary, []>;
4444    def ATOMIC_LOAD_UMIN_I32 : PseudoInst<
4445      (outs GPR:$dst),
4446      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4447      NoItinerary, []>;
4448    def ATOMIC_LOAD_UMAX_I32 : PseudoInst<
4449      (outs GPR:$dst),
4450      (ins GPR:$ptr, GPR:$val, i32imm:$ordering),
4451      NoItinerary, []>;
4452    def ATOMIC_SWAP_I32 : PseudoInst<
4453      (outs GPR:$dst),
4454      (ins GPR:$ptr, GPR:$new, i32imm:$ordering),
4455      NoItinerary, []>;
4456    def ATOMIC_CMP_SWAP_I32 : PseudoInst<
4457      (outs GPR:$dst),
4458      (ins GPR:$ptr, GPR:$old, GPR:$new, i32imm:$ordering),
4459      NoItinerary, []>;
4460    def ATOMIC_LOAD_ADD_I64 : PseudoInst<
4461      (outs GPR:$dst1, GPR:$dst2),
4462      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4463      NoItinerary, []>;
4464    def ATOMIC_LOAD_SUB_I64 : PseudoInst<
4465      (outs GPR:$dst1, GPR:$dst2),
4466      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4467      NoItinerary, []>;
4468    def ATOMIC_LOAD_AND_I64 : PseudoInst<
4469      (outs GPR:$dst1, GPR:$dst2),
4470      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4471      NoItinerary, []>;
4472    def ATOMIC_LOAD_OR_I64 :  PseudoInst<
4473      (outs GPR:$dst1, GPR:$dst2),
4474      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4475      NoItinerary, []>;
4476    def ATOMIC_LOAD_XOR_I64 : PseudoInst<
4477      (outs GPR:$dst1, GPR:$dst2),
4478      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4479      NoItinerary, []>;
4480    def ATOMIC_LOAD_NAND_I64 : PseudoInst<
4481      (outs GPR:$dst1, GPR:$dst2),
4482      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4483      NoItinerary, []>;
4484    def ATOMIC_LOAD_MIN_I64 : PseudoInst<
4485      (outs GPR:$dst1, GPR:$dst2),
4486      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4487      NoItinerary, []>;
4488    def ATOMIC_LOAD_MAX_I64 : PseudoInst<
4489      (outs GPR:$dst1, GPR:$dst2),
4490      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4491      NoItinerary, []>;
4492    def ATOMIC_LOAD_UMIN_I64 : PseudoInst<
4493      (outs GPR:$dst1, GPR:$dst2),
4494      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4495      NoItinerary, []>;
4496    def ATOMIC_LOAD_UMAX_I64 : PseudoInst<
4497      (outs GPR:$dst1, GPR:$dst2),
4498      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4499      NoItinerary, []>;
4500    def ATOMIC_SWAP_I64 : PseudoInst<
4501      (outs GPR:$dst1, GPR:$dst2),
4502      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4503      NoItinerary, []>;
4504    def ATOMIC_CMP_SWAP_I64 : PseudoInst<
4505      (outs GPR:$dst1, GPR:$dst2),
4506      (ins GPR:$addr, GPR:$cmp1, GPR:$cmp2,
4507           GPR:$set1, GPR:$set2, i32imm:$ordering),
4508      NoItinerary, []>;
4509  }
4510  let mayLoad = 1 in
4511    def ATOMIC_LOAD_I64 : PseudoInst<
4512      (outs GPR:$dst1, GPR:$dst2),
4513      (ins GPR:$addr, i32imm:$ordering),
4514      NoItinerary, []>;
4515  let mayStore = 1 in
4516    def ATOMIC_STORE_I64 : PseudoInst<
4517      (outs GPR:$dst1, GPR:$dst2),
4518      (ins GPR:$addr, GPR:$src1, GPR:$src2, i32imm:$ordering),
4519      NoItinerary, []>;
4520}
4521
4522let usesCustomInserter = 1 in {
4523    def COPY_STRUCT_BYVAL_I32 : PseudoInst<
4524      (outs), (ins GPR:$dst, GPR:$src, i32imm:$size, i32imm:$alignment),
4525      NoItinerary,
4526      [(ARMcopystructbyval GPR:$dst, GPR:$src, imm:$size, imm:$alignment)]>;
4527}
4528
4529def ldrex_1 : PatFrag<(ops node:$ptr), (int_arm_ldrex node:$ptr), [{
4530  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i8;
4531}]>;
4532
4533def ldrex_2 : PatFrag<(ops node:$ptr), (int_arm_ldrex node:$ptr), [{
4534  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
4535}]>;
4536
4537def ldrex_4 : PatFrag<(ops node:$ptr), (int_arm_ldrex node:$ptr), [{
4538  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
4539}]>;
4540
4541def strex_1 : PatFrag<(ops node:$val, node:$ptr),
4542                      (int_arm_strex node:$val, node:$ptr), [{
4543  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i8;
4544}]>;
4545
4546def strex_2 : PatFrag<(ops node:$val, node:$ptr),
4547                      (int_arm_strex node:$val, node:$ptr), [{
4548  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
4549}]>;
4550
4551def strex_4 : PatFrag<(ops node:$val, node:$ptr),
4552                      (int_arm_strex node:$val, node:$ptr), [{
4553  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
4554}]>;
4555
4556let mayLoad = 1 in {
4557def LDREXB : AIldrex<0b10, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4558                     NoItinerary, "ldrexb", "\t$Rt, $addr",
4559                     [(set GPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>;
4560def LDREXH : AIldrex<0b11, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4561                     NoItinerary, "ldrexh", "\t$Rt, $addr",
4562                     [(set GPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>;
4563def LDREX  : AIldrex<0b00, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4564                     NoItinerary, "ldrex", "\t$Rt, $addr",
4565                     [(set GPR:$Rt, (ldrex_4 addr_offset_none:$addr))]>;
4566let hasExtraDefRegAllocReq = 1 in
4567def LDREXD : AIldrex<0b01, (outs GPRPairOp:$Rt),(ins addr_offset_none:$addr),
4568                      NoItinerary, "ldrexd", "\t$Rt, $addr", []> {
4569  let DecoderMethod = "DecodeDoubleRegLoad";
4570}
4571
4572def LDAEXB : AIldaex<0b10, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4573                     NoItinerary, "ldaexb", "\t$Rt, $addr", []>;
4574def LDAEXH : AIldaex<0b11, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4575                     NoItinerary, "ldaexh", "\t$Rt, $addr", []>;
4576def LDAEX  : AIldaex<0b00, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4577                     NoItinerary, "ldaex", "\t$Rt, $addr", []>;
4578let hasExtraDefRegAllocReq = 1 in
4579def LDAEXD : AIldaex<0b01, (outs GPRPairOp:$Rt),(ins addr_offset_none:$addr),
4580                      NoItinerary, "ldaexd", "\t$Rt, $addr", []> {
4581  let DecoderMethod = "DecodeDoubleRegLoad";
4582}
4583}
4584
4585let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
4586def STREXB: AIstrex<0b10, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4587                    NoItinerary, "strexb", "\t$Rd, $Rt, $addr",
4588                    [(set GPR:$Rd, (strex_1 GPR:$Rt, addr_offset_none:$addr))]>;
4589def STREXH: AIstrex<0b11, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4590                    NoItinerary, "strexh", "\t$Rd, $Rt, $addr",
4591                    [(set GPR:$Rd, (strex_2 GPR:$Rt, addr_offset_none:$addr))]>;
4592def STREX : AIstrex<0b00, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4593                    NoItinerary, "strex", "\t$Rd, $Rt, $addr",
4594                    [(set GPR:$Rd, (strex_4 GPR:$Rt, addr_offset_none:$addr))]>;
4595let hasExtraSrcRegAllocReq = 1 in
4596def STREXD : AIstrex<0b01, (outs GPR:$Rd),
4597                    (ins GPRPairOp:$Rt, addr_offset_none:$addr),
4598                    NoItinerary, "strexd", "\t$Rd, $Rt, $addr", []> {
4599  let DecoderMethod = "DecodeDoubleRegStore";
4600}
4601def STLEXB: AIstlex<0b10, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4602                    NoItinerary, "stlexb", "\t$Rd, $Rt, $addr",
4603                    []>;
4604def STLEXH: AIstlex<0b11, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4605                    NoItinerary, "stlexh", "\t$Rd, $Rt, $addr",
4606                    []>;
4607def STLEX : AIstlex<0b00, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4608                    NoItinerary, "stlex", "\t$Rd, $Rt, $addr",
4609                    []>;
4610let hasExtraSrcRegAllocReq = 1 in
4611def STLEXD : AIstlex<0b01, (outs GPR:$Rd),
4612                    (ins GPRPairOp:$Rt, addr_offset_none:$addr),
4613                    NoItinerary, "stlexd", "\t$Rd, $Rt, $addr", []> {
4614  let DecoderMethod = "DecodeDoubleRegStore";
4615}
4616}
4617
4618def CLREX : AXI<(outs), (ins), MiscFrm, NoItinerary, "clrex",
4619                [(int_arm_clrex)]>,
4620            Requires<[IsARM, HasV7]>  {
4621  let Inst{31-0} = 0b11110101011111111111000000011111;
4622}
4623
4624def : ARMPat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
4625             (LDREXB addr_offset_none:$addr)>;
4626def : ARMPat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
4627             (LDREXH addr_offset_none:$addr)>;
4628def : ARMPat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
4629             (STREXB GPR:$Rt, addr_offset_none:$addr)>;
4630def : ARMPat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
4631             (STREXH GPR:$Rt, addr_offset_none:$addr)>;
4632
4633class acquiring_load<PatFrag base>
4634  : PatFrag<(ops node:$ptr), (base node:$ptr), [{
4635  AtomicOrdering Ordering = cast<AtomicSDNode>(N)->getOrdering();
4636  return Ordering == Acquire || Ordering == SequentiallyConsistent;
4637}]>;
4638
4639def atomic_load_acquire_8  : acquiring_load<atomic_load_8>;
4640def atomic_load_acquire_16 : acquiring_load<atomic_load_16>;
4641def atomic_load_acquire_32 : acquiring_load<atomic_load_32>;
4642
4643class releasing_store<PatFrag base>
4644  : PatFrag<(ops node:$ptr, node:$val), (base node:$ptr, node:$val), [{
4645  AtomicOrdering Ordering = cast<AtomicSDNode>(N)->getOrdering();
4646  return Ordering == Release || Ordering == SequentiallyConsistent;
4647}]>;
4648
4649def atomic_store_release_8  : releasing_store<atomic_store_8>;
4650def atomic_store_release_16 : releasing_store<atomic_store_16>;
4651def atomic_store_release_32 : releasing_store<atomic_store_32>;
4652
4653let AddedComplexity = 8 in {
4654  def : ARMPat<(atomic_load_acquire_8 addr_offset_none:$addr),  (LDAB addr_offset_none:$addr)>;
4655  def : ARMPat<(atomic_load_acquire_16 addr_offset_none:$addr), (LDAH addr_offset_none:$addr)>;
4656  def : ARMPat<(atomic_load_acquire_32 addr_offset_none:$addr), (LDA  addr_offset_none:$addr)>;
4657  def : ARMPat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val),  (STLB GPR:$val, addr_offset_none:$addr)>;
4658  def : ARMPat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (STLH GPR:$val, addr_offset_none:$addr)>;
4659  def : ARMPat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (STL  GPR:$val, addr_offset_none:$addr)>;
4660}
4661
4662// SWP/SWPB are deprecated in V6/V7.
4663let mayLoad = 1, mayStore = 1 in {
4664def SWP : AIswp<0, (outs GPRnopc:$Rt),
4665                (ins GPRnopc:$Rt2, addr_offset_none:$addr), "swp", []>,
4666                Requires<[PreV8]>;
4667def SWPB: AIswp<1, (outs GPRnopc:$Rt),
4668                (ins GPRnopc:$Rt2, addr_offset_none:$addr), "swpb", []>,
4669                Requires<[PreV8]>;
4670}
4671
4672//===----------------------------------------------------------------------===//
4673// Coprocessor Instructions.
4674//
4675
4676def CDP : ABI<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4677            c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4678            NoItinerary, "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4679            [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4680                          imm:$CRm, imm:$opc2)]>,
4681            Requires<[PreV8]> {
4682  bits<4> opc1;
4683  bits<4> CRn;
4684  bits<4> CRd;
4685  bits<4> cop;
4686  bits<3> opc2;
4687  bits<4> CRm;
4688
4689  let Inst{3-0}   = CRm;
4690  let Inst{4}     = 0;
4691  let Inst{7-5}   = opc2;
4692  let Inst{11-8}  = cop;
4693  let Inst{15-12} = CRd;
4694  let Inst{19-16} = CRn;
4695  let Inst{23-20} = opc1;
4696}
4697
4698def CDP2 : ABXI<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4699               c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4700               NoItinerary, "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4701               [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4702                              imm:$CRm, imm:$opc2)]>,
4703               Requires<[PreV8]> {
4704  let Inst{31-28} = 0b1111;
4705  bits<4> opc1;
4706  bits<4> CRn;
4707  bits<4> CRd;
4708  bits<4> cop;
4709  bits<3> opc2;
4710  bits<4> CRm;
4711
4712  let Inst{3-0}   = CRm;
4713  let Inst{4}     = 0;
4714  let Inst{7-5}   = opc2;
4715  let Inst{11-8}  = cop;
4716  let Inst{15-12} = CRd;
4717  let Inst{19-16} = CRn;
4718  let Inst{23-20} = opc1;
4719}
4720
4721class ACI<dag oops, dag iops, string opc, string asm,
4722          IndexMode im = IndexModeNone>
4723  : I<oops, iops, AddrModeNone, 4, im, BrFrm, NoItinerary,
4724      opc, asm, "", []> {
4725  let Inst{27-25} = 0b110;
4726}
4727class ACInoP<dag oops, dag iops, string opc, string asm,
4728          IndexMode im = IndexModeNone>
4729  : InoP<oops, iops, AddrModeNone, 4, im, BrFrm, NoItinerary,
4730         opc, asm, "", []> {
4731  let Inst{31-28} = 0b1111;
4732  let Inst{27-25} = 0b110;
4733}
4734multiclass LdStCop<bit load, bit Dbit, string asm> {
4735  def _OFFSET : ACI<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4736                    asm, "\t$cop, $CRd, $addr"> {
4737    bits<13> addr;
4738    bits<4> cop;
4739    bits<4> CRd;
4740    let Inst{24} = 1; // P = 1
4741    let Inst{23} = addr{8};
4742    let Inst{22} = Dbit;
4743    let Inst{21} = 0; // W = 0
4744    let Inst{20} = load;
4745    let Inst{19-16} = addr{12-9};
4746    let Inst{15-12} = CRd;
4747    let Inst{11-8} = cop;
4748    let Inst{7-0} = addr{7-0};
4749    let DecoderMethod = "DecodeCopMemInstruction";
4750  }
4751  def _PRE : ACI<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
4752                 asm, "\t$cop, $CRd, $addr!", IndexModePre> {
4753    bits<13> addr;
4754    bits<4> cop;
4755    bits<4> CRd;
4756    let Inst{24} = 1; // P = 1
4757    let Inst{23} = addr{8};
4758    let Inst{22} = Dbit;
4759    let Inst{21} = 1; // W = 1
4760    let Inst{20} = load;
4761    let Inst{19-16} = addr{12-9};
4762    let Inst{15-12} = CRd;
4763    let Inst{11-8} = cop;
4764    let Inst{7-0} = addr{7-0};
4765    let DecoderMethod = "DecodeCopMemInstruction";
4766  }
4767  def _POST: ACI<(outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4768                              postidx_imm8s4:$offset),
4769                 asm, "\t$cop, $CRd, $addr, $offset", IndexModePost> {
4770    bits<9> offset;
4771    bits<4> addr;
4772    bits<4> cop;
4773    bits<4> CRd;
4774    let Inst{24} = 0; // P = 0
4775    let Inst{23} = offset{8};
4776    let Inst{22} = Dbit;
4777    let Inst{21} = 1; // W = 1
4778    let Inst{20} = load;
4779    let Inst{19-16} = addr;
4780    let Inst{15-12} = CRd;
4781    let Inst{11-8} = cop;
4782    let Inst{7-0} = offset{7-0};
4783    let DecoderMethod = "DecodeCopMemInstruction";
4784  }
4785  def _OPTION : ACI<(outs),
4786                    (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4787                         coproc_option_imm:$option),
4788      asm, "\t$cop, $CRd, $addr, $option"> {
4789    bits<8> option;
4790    bits<4> addr;
4791    bits<4> cop;
4792    bits<4> CRd;
4793    let Inst{24} = 0; // P = 0
4794    let Inst{23} = 1; // U = 1
4795    let Inst{22} = Dbit;
4796    let Inst{21} = 0; // W = 0
4797    let Inst{20} = load;
4798    let Inst{19-16} = addr;
4799    let Inst{15-12} = CRd;
4800    let Inst{11-8} = cop;
4801    let Inst{7-0} = option;
4802    let DecoderMethod = "DecodeCopMemInstruction";
4803  }
4804}
4805multiclass LdSt2Cop<bit load, bit Dbit, string asm> {
4806  def _OFFSET : ACInoP<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
4807                       asm, "\t$cop, $CRd, $addr"> {
4808    bits<13> addr;
4809    bits<4> cop;
4810    bits<4> CRd;
4811    let Inst{24} = 1; // P = 1
4812    let Inst{23} = addr{8};
4813    let Inst{22} = Dbit;
4814    let Inst{21} = 0; // W = 0
4815    let Inst{20} = load;
4816    let Inst{19-16} = addr{12-9};
4817    let Inst{15-12} = CRd;
4818    let Inst{11-8} = cop;
4819    let Inst{7-0} = addr{7-0};
4820    let DecoderMethod = "DecodeCopMemInstruction";
4821  }
4822  def _PRE : ACInoP<(outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
4823                    asm, "\t$cop, $CRd, $addr!", IndexModePre> {
4824    bits<13> addr;
4825    bits<4> cop;
4826    bits<4> CRd;
4827    let Inst{24} = 1; // P = 1
4828    let Inst{23} = addr{8};
4829    let Inst{22} = Dbit;
4830    let Inst{21} = 1; // W = 1
4831    let Inst{20} = load;
4832    let Inst{19-16} = addr{12-9};
4833    let Inst{15-12} = CRd;
4834    let Inst{11-8} = cop;
4835    let Inst{7-0} = addr{7-0};
4836    let DecoderMethod = "DecodeCopMemInstruction";
4837  }
4838  def _POST: ACInoP<(outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4839                                 postidx_imm8s4:$offset),
4840                 asm, "\t$cop, $CRd, $addr, $offset", IndexModePost> {
4841    bits<9> offset;
4842    bits<4> addr;
4843    bits<4> cop;
4844    bits<4> CRd;
4845    let Inst{24} = 0; // P = 0
4846    let Inst{23} = offset{8};
4847    let Inst{22} = Dbit;
4848    let Inst{21} = 1; // W = 1
4849    let Inst{20} = load;
4850    let Inst{19-16} = addr;
4851    let Inst{15-12} = CRd;
4852    let Inst{11-8} = cop;
4853    let Inst{7-0} = offset{7-0};
4854    let DecoderMethod = "DecodeCopMemInstruction";
4855  }
4856  def _OPTION : ACInoP<(outs),
4857                       (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
4858                            coproc_option_imm:$option),
4859      asm, "\t$cop, $CRd, $addr, $option"> {
4860    bits<8> option;
4861    bits<4> addr;
4862    bits<4> cop;
4863    bits<4> CRd;
4864    let Inst{24} = 0; // P = 0
4865    let Inst{23} = 1; // U = 1
4866    let Inst{22} = Dbit;
4867    let Inst{21} = 0; // W = 0
4868    let Inst{20} = load;
4869    let Inst{19-16} = addr;
4870    let Inst{15-12} = CRd;
4871    let Inst{11-8} = cop;
4872    let Inst{7-0} = option;
4873    let DecoderMethod = "DecodeCopMemInstruction";
4874  }
4875}
4876
4877defm LDC   : LdStCop <1, 0, "ldc">;
4878defm LDCL  : LdStCop <1, 1, "ldcl">;
4879defm STC   : LdStCop <0, 0, "stc">;
4880defm STCL  : LdStCop <0, 1, "stcl">;
4881defm LDC2  : LdSt2Cop<1, 0, "ldc2">, Requires<[PreV8]>;
4882defm LDC2L : LdSt2Cop<1, 1, "ldc2l">, Requires<[PreV8]>;
4883defm STC2  : LdSt2Cop<0, 0, "stc2">, Requires<[PreV8]>;
4884defm STC2L : LdSt2Cop<0, 1, "stc2l">, Requires<[PreV8]>;
4885
4886//===----------------------------------------------------------------------===//
4887// Move between coprocessor and ARM core register.
4888//
4889
4890class MovRCopro<string opc, bit direction, dag oops, dag iops,
4891                list<dag> pattern>
4892  : ABI<0b1110, oops, iops, NoItinerary, opc,
4893        "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2", pattern> {
4894  let Inst{20} = direction;
4895  let Inst{4} = 1;
4896
4897  bits<4> Rt;
4898  bits<4> cop;
4899  bits<3> opc1;
4900  bits<3> opc2;
4901  bits<4> CRm;
4902  bits<4> CRn;
4903
4904  let Inst{15-12} = Rt;
4905  let Inst{11-8}  = cop;
4906  let Inst{23-21} = opc1;
4907  let Inst{7-5}   = opc2;
4908  let Inst{3-0}   = CRm;
4909  let Inst{19-16} = CRn;
4910}
4911
4912def MCR : MovRCopro<"mcr", 0 /* from ARM core register to coprocessor */,
4913                    (outs),
4914                    (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4915                         c_imm:$CRm, imm0_7:$opc2),
4916                    [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4917                                  imm:$CRm, imm:$opc2)]>,
4918                    ComplexDeprecationPredicate<"MCR">;
4919def : ARMInstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
4920                   (MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4921                        c_imm:$CRm, 0, pred:$p)>;
4922def MRC : MovRCopro<"mrc", 1 /* from coprocessor to ARM core register */,
4923                    (outs GPRwithAPSR:$Rt),
4924                    (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm,
4925                         imm0_7:$opc2), []>;
4926def : ARMInstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
4927                   (MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4928                        c_imm:$CRm, 0, pred:$p)>;
4929
4930def : ARMPat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
4931             (MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4932
4933class MovRCopro2<string opc, bit direction, dag oops, dag iops,
4934                 list<dag> pattern>
4935  : ABXI<0b1110, oops, iops, NoItinerary,
4936         !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"), pattern> {
4937  let Inst{31-24} = 0b11111110;
4938  let Inst{20} = direction;
4939  let Inst{4} = 1;
4940
4941  bits<4> Rt;
4942  bits<4> cop;
4943  bits<3> opc1;
4944  bits<3> opc2;
4945  bits<4> CRm;
4946  bits<4> CRn;
4947
4948  let Inst{15-12} = Rt;
4949  let Inst{11-8}  = cop;
4950  let Inst{23-21} = opc1;
4951  let Inst{7-5}   = opc2;
4952  let Inst{3-0}   = CRm;
4953  let Inst{19-16} = CRn;
4954}
4955
4956def MCR2 : MovRCopro2<"mcr2", 0 /* from ARM core register to coprocessor */,
4957                      (outs),
4958                      (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4959                           c_imm:$CRm, imm0_7:$opc2),
4960                      [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4961                                     imm:$CRm, imm:$opc2)]>,
4962                      Requires<[PreV8]>;
4963def : ARMInstAlias<"mcr2$ $cop, $opc1, $Rt, $CRn, $CRm",
4964                   (MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4965                         c_imm:$CRm, 0)>;
4966def MRC2 : MovRCopro2<"mrc2", 1 /* from coprocessor to ARM core register */,
4967                      (outs GPRwithAPSR:$Rt),
4968                      (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm,
4969                           imm0_7:$opc2), []>,
4970                      Requires<[PreV8]>;
4971def : ARMInstAlias<"mrc2$ $cop, $opc1, $Rt, $CRn, $CRm",
4972                   (MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
4973                         c_imm:$CRm, 0)>;
4974
4975def : ARMV5TPat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn,
4976                              imm:$CRm, imm:$opc2),
4977                (MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4978
4979class MovRRCopro<string opc, bit direction, list<dag> pattern = []>
4980  : ABI<0b1100, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4981        GPRnopc:$Rt, GPRnopc:$Rt2, c_imm:$CRm),
4982        NoItinerary, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
4983  let Inst{23-21} = 0b010;
4984  let Inst{20} = direction;
4985
4986  bits<4> Rt;
4987  bits<4> Rt2;
4988  bits<4> cop;
4989  bits<4> opc1;
4990  bits<4> CRm;
4991
4992  let Inst{15-12} = Rt;
4993  let Inst{19-16} = Rt2;
4994  let Inst{11-8}  = cop;
4995  let Inst{7-4}   = opc1;
4996  let Inst{3-0}   = CRm;
4997}
4998
4999def MCRR : MovRRCopro<"mcrr", 0 /* from ARM core register to coprocessor */,
5000                      [(int_arm_mcrr imm:$cop, imm:$opc1, GPRnopc:$Rt,
5001                                     GPRnopc:$Rt2, imm:$CRm)]>;
5002def MRRC : MovRRCopro<"mrrc", 1 /* from coprocessor to ARM core register */>;
5003
5004class MovRRCopro2<string opc, bit direction, list<dag> pattern = []>
5005  : ABXI<0b1100, (outs), (ins p_imm:$cop, imm0_15:$opc1,
5006         GPRnopc:$Rt, GPRnopc:$Rt2, c_imm:$CRm), NoItinerary,
5007         !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern>,
5008    Requires<[PreV8]> {
5009  let Inst{31-28} = 0b1111;
5010  let Inst{23-21} = 0b010;
5011  let Inst{20} = direction;
5012
5013  bits<4> Rt;
5014  bits<4> Rt2;
5015  bits<4> cop;
5016  bits<4> opc1;
5017  bits<4> CRm;
5018
5019  let Inst{15-12} = Rt;
5020  let Inst{19-16} = Rt2;
5021  let Inst{11-8}  = cop;
5022  let Inst{7-4}   = opc1;
5023  let Inst{3-0}   = CRm;
5024
5025  let DecoderMethod = "DecodeMRRC2";
5026}
5027
5028def MCRR2 : MovRRCopro2<"mcrr2", 0 /* from ARM core register to coprocessor */,
5029                        [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPRnopc:$Rt,
5030                                        GPRnopc:$Rt2, imm:$CRm)]>;
5031def MRRC2 : MovRRCopro2<"mrrc2", 1 /* from coprocessor to ARM core register */>;
5032
5033//===----------------------------------------------------------------------===//
5034// Move between special register and ARM core register
5035//
5036
5037// Move to ARM core register from Special Register
5038def MRS : ABI<0b0001, (outs GPRnopc:$Rd), (ins), NoItinerary,
5039              "mrs", "\t$Rd, apsr", []> {
5040  bits<4> Rd;
5041  let Inst{23-16} = 0b00001111;
5042  let Unpredictable{19-17} = 0b111;
5043
5044  let Inst{15-12} = Rd;
5045
5046  let Inst{11-0} = 0b000000000000;
5047  let Unpredictable{11-0} = 0b110100001111;
5048}
5049
5050def : InstAlias<"mrs${p} $Rd, cpsr", (MRS GPRnopc:$Rd, pred:$p)>,
5051         Requires<[IsARM]>;
5052
5053// The MRSsys instruction is the MRS instruction from the ARM ARM,
5054// section B9.3.9, with the R bit set to 1.
5055def MRSsys : ABI<0b0001, (outs GPRnopc:$Rd), (ins), NoItinerary,
5056                 "mrs", "\t$Rd, spsr", []> {
5057  bits<4> Rd;
5058  let Inst{23-16} = 0b01001111;
5059  let Unpredictable{19-16} = 0b1111;
5060
5061  let Inst{15-12} = Rd;
5062
5063  let Inst{11-0} = 0b000000000000;
5064  let Unpredictable{11-0} = 0b110100001111;
5065}
5066
5067// Move from ARM core register to Special Register
5068//
5069// No need to have both system and application versions, the encodings are the
5070// same and the assembly parser has no way to distinguish between them. The mask
5071// operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
5072// the mask with the fields to be accessed in the special register.
5073def MSR : ABI<0b0001, (outs), (ins msr_mask:$mask, GPR:$Rn), NoItinerary,
5074              "msr", "\t$mask, $Rn", []> {
5075  bits<5> mask;
5076  bits<4> Rn;
5077
5078  let Inst{23} = 0;
5079  let Inst{22} = mask{4}; // R bit
5080  let Inst{21-20} = 0b10;
5081  let Inst{19-16} = mask{3-0};
5082  let Inst{15-12} = 0b1111;
5083  let Inst{11-4} = 0b00000000;
5084  let Inst{3-0} = Rn;
5085}
5086
5087def MSRi : ABI<0b0011, (outs), (ins msr_mask:$mask,  so_imm:$a), NoItinerary,
5088               "msr", "\t$mask, $a", []> {
5089  bits<5> mask;
5090  bits<12> a;
5091
5092  let Inst{23} = 0;
5093  let Inst{22} = mask{4}; // R bit
5094  let Inst{21-20} = 0b10;
5095  let Inst{19-16} = mask{3-0};
5096  let Inst{15-12} = 0b1111;
5097  let Inst{11-0} = a;
5098}
5099
5100//===----------------------------------------------------------------------===//
5101// TLS Instructions
5102//
5103
5104// __aeabi_read_tp preserves the registers r1-r3.
5105// This is a pseudo inst so that we can get the encoding right,
5106// complete with fixup for the aeabi_read_tp function.
5107let isCall = 1,
5108  Defs = [R0, R12, LR, CPSR], Uses = [SP] in {
5109  def TPsoft : PseudoInst<(outs), (ins), IIC_Br,
5110               [(set R0, ARMthread_pointer)]>, Sched<[WriteBr]>;
5111}
5112
5113//===----------------------------------------------------------------------===//
5114// SJLJ Exception handling intrinsics
5115//   eh_sjlj_setjmp() is an instruction sequence to store the return
5116//   address and save #0 in R0 for the non-longjmp case.
5117//   Since by its nature we may be coming from some other function to get
5118//   here, and we're using the stack frame for the containing function to
5119//   save/restore registers, we can't keep anything live in regs across
5120//   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
5121//   when we get here from a longjmp(). We force everything out of registers
5122//   except for our own input by listing the relevant registers in Defs. By
5123//   doing so, we also cause the prologue/epilogue code to actively preserve
5124//   all of the callee-saved resgisters, which is exactly what we want.
5125//   A constant value is passed in $val, and we use the location as a scratch.
5126//
5127// These are pseudo-instructions and are lowered to individual MC-insts, so
5128// no encoding information is necessary.
5129let Defs =
5130  [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR,
5131    Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15 ],
5132  hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
5133  def Int_eh_sjlj_setjmp : PseudoInst<(outs), (ins GPR:$src, GPR:$val),
5134                               NoItinerary,
5135                         [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
5136                           Requires<[IsARM, HasVFP2]>;
5137}
5138
5139let Defs =
5140  [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR ],
5141  hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
5142  def Int_eh_sjlj_setjmp_nofp : PseudoInst<(outs), (ins GPR:$src, GPR:$val),
5143                                   NoItinerary,
5144                         [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
5145                                Requires<[IsARM, NoVFP]>;
5146}
5147
5148// FIXME: Non-IOS version(s)
5149let isBarrier = 1, hasSideEffects = 1, isTerminator = 1,
5150    Defs = [ R7, LR, SP ] in {
5151def Int_eh_sjlj_longjmp : PseudoInst<(outs), (ins GPR:$src, GPR:$scratch),
5152                             NoItinerary,
5153                         [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
5154                                Requires<[IsARM, IsIOS]>;
5155}
5156
5157// eh.sjlj.dispatchsetup pseudo-instruction.
5158// This pseudo is used for both ARM and Thumb. Any differences are handled when
5159// the pseudo is expanded (which happens before any passes that need the
5160// instruction size).
5161let isBarrier = 1 in
5162def Int_eh_sjlj_dispatchsetup : PseudoInst<(outs), (ins), NoItinerary, []>;
5163
5164
5165//===----------------------------------------------------------------------===//
5166// Non-Instruction Patterns
5167//
5168
5169// ARMv4 indirect branch using (MOVr PC, dst)
5170let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
5171  def MOVPCRX : ARMPseudoExpand<(outs), (ins GPR:$dst),
5172                    4, IIC_Br, [(brind GPR:$dst)],
5173                    (MOVr PC, GPR:$dst, (ops 14, zero_reg), zero_reg)>,
5174                  Requires<[IsARM, NoV4T]>, Sched<[WriteBr]>;
5175
5176// Large immediate handling.
5177
5178// 32-bit immediate using two piece so_imms or movw + movt.
5179// This is a single pseudo instruction, the benefit is that it can be remat'd
5180// as a single unit instead of having to handle reg inputs.
5181// FIXME: Remove this when we can do generalized remat.
5182let isReMaterializable = 1, isMoveImm = 1 in
5183def MOVi32imm : PseudoInst<(outs GPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
5184                           [(set GPR:$dst, (arm_i32imm:$src))]>,
5185                           Requires<[IsARM]>;
5186
5187// Pseudo instruction that combines movw + movt + add pc (if PIC).
5188// It also makes it possible to rematerialize the instructions.
5189// FIXME: Remove this when we can do generalized remat and when machine licm
5190// can properly the instructions.
5191let isReMaterializable = 1 in {
5192def MOV_ga_pcrel : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
5193                              IIC_iMOVix2addpc,
5194                        [(set GPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
5195                        Requires<[IsARM, UseMovt]>;
5196
5197def MOV_ga_dyn : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
5198                             IIC_iMOVix2,
5199                        [(set GPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
5200                        Requires<[IsARM, UseMovt]>;
5201
5202let AddedComplexity = 10 in
5203def MOV_ga_pcrel_ldr : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
5204                                IIC_iMOVix2ld,
5205                    [(set GPR:$dst, (load (ARMWrapperPIC tglobaladdr:$addr)))]>,
5206                    Requires<[IsARM, UseMovt]>;
5207} // isReMaterializable
5208
5209// ConstantPool, GlobalAddress, and JumpTable
5210def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>,
5211            Requires<[IsARM, DontUseMovt]>;
5212def : ARMPat<(ARMWrapper  tconstpool  :$dst), (LEApcrel tconstpool  :$dst)>;
5213def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (MOVi32imm tglobaladdr :$dst)>,
5214            Requires<[IsARM, UseMovt]>;
5215def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
5216             (LEApcrelJT tjumptable:$dst, imm:$id)>;
5217
5218// TODO: add,sub,and, 3-instr forms?
5219
5220// Tail calls. These patterns also apply to Thumb mode.
5221def : Pat<(ARMtcret tcGPR:$dst), (TCRETURNri tcGPR:$dst)>;
5222def : Pat<(ARMtcret (i32 tglobaladdr:$dst)), (TCRETURNdi texternalsym:$dst)>;
5223def : Pat<(ARMtcret (i32 texternalsym:$dst)), (TCRETURNdi texternalsym:$dst)>;
5224
5225// Direct calls
5226def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
5227def : ARMPat<(ARMcall_nolink texternalsym:$func),
5228             (BMOVPCB_CALL texternalsym:$func)>;
5229
5230// zextload i1 -> zextload i8
5231def : ARMPat<(zextloadi1 addrmode_imm12:$addr), (LDRBi12 addrmode_imm12:$addr)>;
5232def : ARMPat<(zextloadi1 ldst_so_reg:$addr),    (LDRBrs ldst_so_reg:$addr)>;
5233
5234// extload -> zextload
5235def : ARMPat<(extloadi1 addrmode_imm12:$addr),  (LDRBi12 addrmode_imm12:$addr)>;
5236def : ARMPat<(extloadi1 ldst_so_reg:$addr),     (LDRBrs ldst_so_reg:$addr)>;
5237def : ARMPat<(extloadi8 addrmode_imm12:$addr),  (LDRBi12 addrmode_imm12:$addr)>;
5238def : ARMPat<(extloadi8 ldst_so_reg:$addr),     (LDRBrs ldst_so_reg:$addr)>;
5239
5240def : ARMPat<(extloadi16 addrmode3:$addr),  (LDRH addrmode3:$addr)>;
5241
5242def : ARMPat<(extloadi8  addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
5243def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
5244
5245// smul* and smla*
5246def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
5247                      (sra (shl GPR:$b, (i32 16)), (i32 16))),
5248                 (SMULBB GPR:$a, GPR:$b)>;
5249def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
5250                 (SMULBB GPR:$a, GPR:$b)>;
5251def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
5252                      (sra GPR:$b, (i32 16))),
5253                 (SMULBT GPR:$a, GPR:$b)>;
5254def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, (i32 16))),
5255                 (SMULBT GPR:$a, GPR:$b)>;
5256def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)),
5257                      (sra (shl GPR:$b, (i32 16)), (i32 16))),
5258                 (SMULTB GPR:$a, GPR:$b)>;
5259def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)), sext_16_node:$b),
5260                (SMULTB GPR:$a, GPR:$b)>;
5261def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
5262                      (i32 16)),
5263                 (SMULWB GPR:$a, GPR:$b)>;
5264def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), (i32 16)),
5265                 (SMULWB GPR:$a, GPR:$b)>;
5266
5267def : ARMV5MOPat<(add GPR:$acc,
5268                      (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
5269                           (sra (shl GPR:$b, (i32 16)), (i32 16)))),
5270                 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
5271def : ARMV5MOPat<(add GPR:$acc,
5272                      (mul sext_16_node:$a, sext_16_node:$b)),
5273                 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
5274def : ARMV5MOPat<(add GPR:$acc,
5275                      (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
5276                           (sra GPR:$b, (i32 16)))),
5277                 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
5278def : ARMV5MOPat<(add GPR:$acc,
5279                      (mul sext_16_node:$a, (sra GPR:$b, (i32 16)))),
5280                 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
5281def : ARMV5MOPat<(add GPR:$acc,
5282                      (mul (sra GPR:$a, (i32 16)),
5283                           (sra (shl GPR:$b, (i32 16)), (i32 16)))),
5284                 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
5285def : ARMV5MOPat<(add GPR:$acc,
5286                      (mul (sra GPR:$a, (i32 16)), sext_16_node:$b)),
5287                 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
5288def : ARMV5MOPat<(add GPR:$acc,
5289                      (sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
5290                           (i32 16))),
5291                 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
5292def : ARMV5MOPat<(add GPR:$acc,
5293                      (sra (mul GPR:$a, sext_16_node:$b), (i32 16))),
5294                 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
5295
5296
5297// Pre-v7 uses MCR for synchronization barriers.
5298def : ARMPat<(ARMMemBarrierMCR GPR:$zero), (MCR 15, 0, GPR:$zero, 7, 10, 5)>,
5299         Requires<[IsARM, HasV6]>;
5300
5301// SXT/UXT with no rotate
5302let AddedComplexity = 16 in {
5303def : ARMV6Pat<(and GPR:$Src, 0x000000FF), (UXTB GPR:$Src, 0)>;
5304def : ARMV6Pat<(and GPR:$Src, 0x0000FFFF), (UXTH GPR:$Src, 0)>;
5305def : ARMV6Pat<(and GPR:$Src, 0x00FF00FF), (UXTB16 GPR:$Src, 0)>;
5306def : ARMV6Pat<(add GPR:$Rn, (and GPR:$Rm, 0x00FF)),
5307               (UXTAB GPR:$Rn, GPR:$Rm, 0)>;
5308def : ARMV6Pat<(add GPR:$Rn, (and GPR:$Rm, 0xFFFF)),
5309               (UXTAH GPR:$Rn, GPR:$Rm, 0)>;
5310}
5311
5312def : ARMV6Pat<(sext_inreg GPR:$Src, i8),  (SXTB GPR:$Src, 0)>;
5313def : ARMV6Pat<(sext_inreg GPR:$Src, i16), (SXTH GPR:$Src, 0)>;
5314
5315def : ARMV6Pat<(add GPR:$Rn, (sext_inreg GPRnopc:$Rm, i8)),
5316               (SXTAB GPR:$Rn, GPRnopc:$Rm, 0)>;
5317def : ARMV6Pat<(add GPR:$Rn, (sext_inreg GPRnopc:$Rm, i16)),
5318               (SXTAH GPR:$Rn, GPRnopc:$Rm, 0)>;
5319
5320// Atomic load/store patterns
5321def : ARMPat<(atomic_load_8 ldst_so_reg:$src),
5322             (LDRBrs ldst_so_reg:$src)>;
5323def : ARMPat<(atomic_load_8 addrmode_imm12:$src),
5324             (LDRBi12 addrmode_imm12:$src)>;
5325def : ARMPat<(atomic_load_16 addrmode3:$src),
5326             (LDRH addrmode3:$src)>;
5327def : ARMPat<(atomic_load_32 ldst_so_reg:$src),
5328             (LDRrs ldst_so_reg:$src)>;
5329def : ARMPat<(atomic_load_32 addrmode_imm12:$src),
5330             (LDRi12 addrmode_imm12:$src)>;
5331def : ARMPat<(atomic_store_8 ldst_so_reg:$ptr, GPR:$val),
5332             (STRBrs GPR:$val, ldst_so_reg:$ptr)>;
5333def : ARMPat<(atomic_store_8 addrmode_imm12:$ptr, GPR:$val),
5334             (STRBi12 GPR:$val, addrmode_imm12:$ptr)>;
5335def : ARMPat<(atomic_store_16 addrmode3:$ptr, GPR:$val),
5336             (STRH GPR:$val, addrmode3:$ptr)>;
5337def : ARMPat<(atomic_store_32 ldst_so_reg:$ptr, GPR:$val),
5338             (STRrs GPR:$val, ldst_so_reg:$ptr)>;
5339def : ARMPat<(atomic_store_32 addrmode_imm12:$ptr, GPR:$val),
5340             (STRi12 GPR:$val, addrmode_imm12:$ptr)>;
5341
5342
5343//===----------------------------------------------------------------------===//
5344// Thumb Support
5345//
5346
5347include "ARMInstrThumb.td"
5348
5349//===----------------------------------------------------------------------===//
5350// Thumb2 Support
5351//
5352
5353include "ARMInstrThumb2.td"
5354
5355//===----------------------------------------------------------------------===//
5356// Floating Point Support
5357//
5358
5359include "ARMInstrVFP.td"
5360
5361//===----------------------------------------------------------------------===//
5362// Advanced SIMD (NEON) Support
5363//
5364
5365include "ARMInstrNEON.td"
5366
5367//===----------------------------------------------------------------------===//
5368// Assembler aliases
5369//
5370
5371// Memory barriers
5372def : InstAlias<"dmb", (DMB 0xf)>, Requires<[IsARM, HasDB]>;
5373def : InstAlias<"dsb", (DSB 0xf)>, Requires<[IsARM, HasDB]>;
5374def : InstAlias<"isb", (ISB 0xf)>, Requires<[IsARM, HasDB]>;
5375
5376// System instructions
5377def : MnemonicAlias<"swi", "svc">;
5378
5379// Load / Store Multiple
5380def : MnemonicAlias<"ldmfd", "ldm">;
5381def : MnemonicAlias<"ldmia", "ldm">;
5382def : MnemonicAlias<"ldmea", "ldmdb">;
5383def : MnemonicAlias<"stmfd", "stmdb">;
5384def : MnemonicAlias<"stmia", "stm">;
5385def : MnemonicAlias<"stmea", "stm">;
5386
5387// PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the
5388// shift amount is zero (i.e., unspecified).
5389def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
5390                (PKHBT GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, 0, pred:$p)>,
5391        Requires<[IsARM, HasV6]>;
5392def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
5393                (PKHBT GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, 0, pred:$p)>,
5394        Requires<[IsARM, HasV6]>;
5395
5396// PUSH/POP aliases for STM/LDM
5397def : ARMInstAlias<"push${p} $regs", (STMDB_UPD SP, pred:$p, reglist:$regs)>;
5398def : ARMInstAlias<"pop${p} $regs", (LDMIA_UPD SP, pred:$p, reglist:$regs)>;
5399
5400// SSAT/USAT optional shift operand.
5401def : ARMInstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
5402                (SSAT GPRnopc:$Rd, imm1_32:$sat_imm, GPRnopc:$Rn, 0, pred:$p)>;
5403def : ARMInstAlias<"usat${p} $Rd, $sat_imm, $Rn",
5404                (USAT GPRnopc:$Rd, imm0_31:$sat_imm, GPRnopc:$Rn, 0, pred:$p)>;
5405
5406
5407// Extend instruction optional rotate operand.
5408def : ARMInstAlias<"sxtab${p} $Rd, $Rn, $Rm",
5409                (SXTAB GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5410def : ARMInstAlias<"sxtah${p} $Rd, $Rn, $Rm",
5411                (SXTAH GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5412def : ARMInstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
5413                (SXTAB16 GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5414def : ARMInstAlias<"sxtb${p} $Rd, $Rm",
5415                (SXTB GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5416def : ARMInstAlias<"sxtb16${p} $Rd, $Rm",
5417                (SXTB16 GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5418def : ARMInstAlias<"sxth${p} $Rd, $Rm",
5419                (SXTH GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5420
5421def : ARMInstAlias<"uxtab${p} $Rd, $Rn, $Rm",
5422                (UXTAB GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5423def : ARMInstAlias<"uxtah${p} $Rd, $Rn, $Rm",
5424                (UXTAH GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5425def : ARMInstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
5426                (UXTAB16 GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
5427def : ARMInstAlias<"uxtb${p} $Rd, $Rm",
5428                (UXTB GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5429def : ARMInstAlias<"uxtb16${p} $Rd, $Rm",
5430                (UXTB16 GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5431def : ARMInstAlias<"uxth${p} $Rd, $Rm",
5432                (UXTH GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
5433
5434
5435// RFE aliases
5436def : MnemonicAlias<"rfefa", "rfeda">;
5437def : MnemonicAlias<"rfeea", "rfedb">;
5438def : MnemonicAlias<"rfefd", "rfeia">;
5439def : MnemonicAlias<"rfeed", "rfeib">;
5440def : MnemonicAlias<"rfe", "rfeia">;
5441
5442// SRS aliases
5443def : MnemonicAlias<"srsfa", "srsib">;
5444def : MnemonicAlias<"srsea", "srsia">;
5445def : MnemonicAlias<"srsfd", "srsdb">;
5446def : MnemonicAlias<"srsed", "srsda">;
5447def : MnemonicAlias<"srs", "srsia">;
5448
5449// QSAX == QSUBADDX
5450def : MnemonicAlias<"qsubaddx", "qsax">;
5451// SASX == SADDSUBX
5452def : MnemonicAlias<"saddsubx", "sasx">;
5453// SHASX == SHADDSUBX
5454def : MnemonicAlias<"shaddsubx", "shasx">;
5455// SHSAX == SHSUBADDX
5456def : MnemonicAlias<"shsubaddx", "shsax">;
5457// SSAX == SSUBADDX
5458def : MnemonicAlias<"ssubaddx", "ssax">;
5459// UASX == UADDSUBX
5460def : MnemonicAlias<"uaddsubx", "uasx">;
5461// UHASX == UHADDSUBX
5462def : MnemonicAlias<"uhaddsubx", "uhasx">;
5463// UHSAX == UHSUBADDX
5464def : MnemonicAlias<"uhsubaddx", "uhsax">;
5465// UQASX == UQADDSUBX
5466def : MnemonicAlias<"uqaddsubx", "uqasx">;
5467// UQSAX == UQSUBADDX
5468def : MnemonicAlias<"uqsubaddx", "uqsax">;
5469// USAX == USUBADDX
5470def : MnemonicAlias<"usubaddx", "usax">;
5471
5472// "mov Rd, so_imm_not" can be handled via "mvn" in assembly, just like
5473// for isel.
5474def : ARMInstAlias<"mov${s}${p} $Rd, $imm",
5475                   (MVNi rGPR:$Rd, so_imm_not:$imm, pred:$p, cc_out:$s)>;
5476def : ARMInstAlias<"mvn${s}${p} $Rd, $imm",
5477                   (MOVi rGPR:$Rd, so_imm_not:$imm, pred:$p, cc_out:$s)>;
5478// Same for AND <--> BIC
5479def : ARMInstAlias<"bic${s}${p} $Rd, $Rn, $imm",
5480                   (ANDri rGPR:$Rd, rGPR:$Rn, so_imm_not:$imm,
5481                          pred:$p, cc_out:$s)>;
5482def : ARMInstAlias<"bic${s}${p} $Rdn, $imm",
5483                   (ANDri rGPR:$Rdn, rGPR:$Rdn, so_imm_not:$imm,
5484                          pred:$p, cc_out:$s)>;
5485def : ARMInstAlias<"and${s}${p} $Rd, $Rn, $imm",
5486                   (BICri rGPR:$Rd, rGPR:$Rn, so_imm_not:$imm,
5487                          pred:$p, cc_out:$s)>;
5488def : ARMInstAlias<"and${s}${p} $Rdn, $imm",
5489                   (BICri rGPR:$Rdn, rGPR:$Rdn, so_imm_not:$imm,
5490                          pred:$p, cc_out:$s)>;
5491
5492// Likewise, "add Rd, so_imm_neg" -> sub
5493def : ARMInstAlias<"add${s}${p} $Rd, $Rn, $imm",
5494                 (SUBri GPR:$Rd, GPR:$Rn, so_imm_neg:$imm, pred:$p, cc_out:$s)>;
5495def : ARMInstAlias<"add${s}${p} $Rd, $imm",
5496                 (SUBri GPR:$Rd, GPR:$Rd, so_imm_neg:$imm, pred:$p, cc_out:$s)>;
5497// Same for CMP <--> CMN via so_imm_neg
5498def : ARMInstAlias<"cmp${p} $Rd, $imm",
5499                   (CMNri rGPR:$Rd, so_imm_neg:$imm, pred:$p)>;
5500def : ARMInstAlias<"cmn${p} $Rd, $imm",
5501                   (CMPri rGPR:$Rd, so_imm_neg:$imm, pred:$p)>;
5502
5503// The shifter forms of the MOV instruction are aliased to the ASR, LSL,
5504// LSR, ROR, and RRX instructions.
5505// FIXME: We need C++ parser hooks to map the alias to the MOV
5506//        encoding. It seems we should be able to do that sort of thing
5507//        in tblgen, but it could get ugly.
5508let TwoOperandAliasConstraint = "$Rm = $Rd" in {
5509def ASRi : ARMAsmPseudo<"asr${s}${p} $Rd, $Rm, $imm",
5510                        (ins GPR:$Rd, GPR:$Rm, imm0_32:$imm, pred:$p,
5511                             cc_out:$s)>;
5512def LSRi : ARMAsmPseudo<"lsr${s}${p} $Rd, $Rm, $imm",
5513                        (ins GPR:$Rd, GPR:$Rm, imm0_32:$imm, pred:$p,
5514                             cc_out:$s)>;
5515def LSLi : ARMAsmPseudo<"lsl${s}${p} $Rd, $Rm, $imm",
5516                        (ins GPR:$Rd, GPR:$Rm, imm0_31:$imm, pred:$p,
5517                             cc_out:$s)>;
5518def RORi : ARMAsmPseudo<"ror${s}${p} $Rd, $Rm, $imm",
5519                        (ins GPR:$Rd, GPR:$Rm, imm0_31:$imm, pred:$p,
5520                             cc_out:$s)>;
5521}
5522def RRXi : ARMAsmPseudo<"rrx${s}${p} $Rd, $Rm",
5523                        (ins GPR:$Rd, GPR:$Rm, pred:$p, cc_out:$s)>;
5524let TwoOperandAliasConstraint = "$Rn = $Rd" in {
5525def ASRr : ARMAsmPseudo<"asr${s}${p} $Rd, $Rn, $Rm",
5526                        (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5527                             cc_out:$s)>;
5528def LSRr : ARMAsmPseudo<"lsr${s}${p} $Rd, $Rn, $Rm",
5529                        (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5530                             cc_out:$s)>;
5531def LSLr : ARMAsmPseudo<"lsl${s}${p} $Rd, $Rn, $Rm",
5532                        (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5533                             cc_out:$s)>;
5534def RORr : ARMAsmPseudo<"ror${s}${p} $Rd, $Rn, $Rm",
5535                        (ins GPRnopc:$Rd, GPRnopc:$Rn, GPRnopc:$Rm, pred:$p,
5536                             cc_out:$s)>;
5537}
5538
5539// "neg" is and alias for "rsb rd, rn, #0"
5540def : ARMInstAlias<"neg${s}${p} $Rd, $Rm",
5541                   (RSBri GPR:$Rd, GPR:$Rm, 0, pred:$p, cc_out:$s)>;
5542
5543// Pre-v6, 'mov r0, r0' was used as a NOP encoding.
5544def : InstAlias<"nop${p}", (MOVr R0, R0, pred:$p, zero_reg)>,
5545         Requires<[IsARM, NoV6]>;
5546
5547// UMULL/SMULL are available on all arches, but the instruction definitions
5548// need difference constraints pre-v6. Use these aliases for the assembly
5549// parsing on pre-v6.
5550def : InstAlias<"smull${s}${p} $RdLo, $RdHi, $Rn, $Rm",
5551            (SMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
5552         Requires<[IsARM, NoV6]>;
5553def : InstAlias<"umull${s}${p} $RdLo, $RdHi, $Rn, $Rm",
5554            (UMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
5555         Requires<[IsARM, NoV6]>;
5556
5557// 'it' blocks in ARM mode just validate the predicates. The IT itself
5558// is discarded.
5559def ITasm : ARMAsmPseudo<"it$mask $cc", (ins it_pred:$cc, it_mask:$mask)>,
5560         ComplexDeprecationPredicate<"IT">;
5561