46 #define AARCH64_EXPAND_PSEUDO_NAME "AArch64 pseudo instruction expansion pass" 72 unsigned LdarOp,
unsigned StlrOp,
unsigned CmpOp,
73 unsigned ExtendImm,
unsigned ZeroReg,
113 uint64_t RenamableState =
117 if (DstReg == AArch64::XZR || DstReg == AArch64::WZR) {
130 bool LastItem = std::next(
I) ==
E;
135 case AArch64::ORRWri:
136 case AArch64::ORRXri:
139 .addReg(BitSize == 32 ? AArch64::WZR : AArch64::XZR)
142 case AArch64::MOVNWi:
143 case AArch64::MOVNXi:
144 case AArch64::MOVZWi:
145 case AArch64::MOVZXi: {
154 case AArch64::MOVKWi:
155 case AArch64::MOVKXi: {
169 transferImpOps(MI, MIBS.front(), MIBS.back());
174 bool AArch64ExpandPseudo::expandCMP_SWAP(
176 unsigned StlrOp,
unsigned CmpOp,
unsigned ExtendImm,
unsigned ZeroReg,
196 MF->
insert(++LoadCmpBB->getIterator(), StoreBB);
197 MF->
insert(++StoreBB->getIterator(), DoneBB);
205 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::MOVZWi), StatusReg)
209 BuildMI(LoadCmpBB, DL,
TII->get(CmpOp), ZeroReg)
213 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::Bcc))
217 LoadCmpBB->addSuccessor(DoneBB);
218 LoadCmpBB->addSuccessor(StoreBB);
223 BuildMI(StoreBB, DL,
TII->get(StlrOp), StatusReg)
226 BuildMI(StoreBB, DL,
TII->get(AArch64::CBNZW))
229 StoreBB->addSuccessor(LoadCmpBB);
230 StoreBB->addSuccessor(DoneBB);
232 DoneBB->splice(DoneBB->end(), &MBB,
MI, MBB.
end());
233 DoneBB->transferSuccessors(&MBB);
237 NextMBBI = MBB.
end();
238 MI.eraseFromParent();
246 StoreBB->clearLiveIns();
248 LoadCmpBB->clearLiveIns();
254 bool AArch64ExpandPseudo::expandCMP_SWAP_128(
278 MF->
insert(++LoadCmpBB->getIterator(), StoreBB);
279 MF->
insert(++StoreBB->getIterator(), DoneBB);
286 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::LDAXPX))
290 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::SUBSXrs), AArch64::XZR)
294 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::CSINCWr), StatusReg)
295 .addUse(AArch64::WZR)
298 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::SUBSXrs), AArch64::XZR)
302 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::CSINCWr), StatusReg)
306 BuildMI(LoadCmpBB, DL,
TII->get(AArch64::CBNZW))
309 LoadCmpBB->addSuccessor(DoneBB);
310 LoadCmpBB->addSuccessor(StoreBB);
315 BuildMI(StoreBB, DL,
TII->get(AArch64::STLXPX), StatusReg)
319 BuildMI(StoreBB, DL,
TII->get(AArch64::CBNZW))
322 StoreBB->addSuccessor(LoadCmpBB);
323 StoreBB->addSuccessor(DoneBB);
325 DoneBB->splice(DoneBB->end(), &MBB,
MI, MBB.
end());
326 DoneBB->transferSuccessors(&MBB);
330 NextMBBI = MBB.
end();
331 MI.eraseFromParent();
339 StoreBB->clearLiveIns();
341 LoadCmpBB->clearLiveIns();
347 bool AArch64ExpandPseudo::expandSetTagLoop(
357 bool ZeroData = MI.
getOpcode() == AArch64::STZGloop;
358 const unsigned OpCode =
359 ZeroData ? AArch64::STZ2GPostIndex : AArch64::ST2GPostIndex;
365 MF->
insert(++LoopBB->getIterator(), DoneBB);
374 BuildMI(LoopBB, DL,
TII->get(AArch64::SUBXri))
379 BuildMI(LoopBB, DL,
TII->get(AArch64::CBNZX)).addUse(SizeReg).
addMBB(LoopBB);
381 LoopBB->addSuccessor(LoopBB);
382 LoopBB->addSuccessor(DoneBB);
384 DoneBB->splice(DoneBB->end(), &MBB,
MI, MBB.
end());
385 DoneBB->transferSuccessors(&MBB);
389 NextMBBI = MBB.
end();
390 MI.eraseFromParent();
397 LoopBB->clearLiveIns();
399 DoneBB->clearLiveIns();
416 case AArch64::ADDWrr:
417 case AArch64::SUBWrr:
418 case AArch64::ADDXrr:
419 case AArch64::SUBXrr:
420 case AArch64::ADDSWrr:
421 case AArch64::SUBSWrr:
422 case AArch64::ADDSXrr:
423 case AArch64::SUBSXrr:
424 case AArch64::ANDWrr:
425 case AArch64::ANDXrr:
426 case AArch64::BICWrr:
427 case AArch64::BICXrr:
428 case AArch64::ANDSWrr:
429 case AArch64::ANDSXrr:
430 case AArch64::BICSWrr:
431 case AArch64::BICSXrr:
432 case AArch64::EONWrr:
433 case AArch64::EONXrr:
434 case AArch64::EORWrr:
435 case AArch64::EORXrr:
436 case AArch64::ORNWrr:
437 case AArch64::ORNXrr:
438 case AArch64::ORRWrr:
439 case AArch64::ORRXrr: {
444 case AArch64::ADDWrr: Opcode = AArch64::ADDWrs;
break;
445 case AArch64::SUBWrr: Opcode = AArch64::SUBWrs;
break;
446 case AArch64::ADDXrr: Opcode = AArch64::ADDXrs;
break;
447 case AArch64::SUBXrr: Opcode = AArch64::SUBXrs;
break;
448 case AArch64::ADDSWrr: Opcode = AArch64::ADDSWrs;
break;
449 case AArch64::SUBSWrr: Opcode = AArch64::SUBSWrs;
break;
450 case AArch64::ADDSXrr: Opcode = AArch64::ADDSXrs;
break;
451 case AArch64::SUBSXrr: Opcode = AArch64::SUBSXrs;
break;
452 case AArch64::ANDWrr: Opcode = AArch64::ANDWrs;
break;
453 case AArch64::ANDXrr: Opcode = AArch64::ANDXrs;
break;
454 case AArch64::BICWrr: Opcode = AArch64::BICWrs;
break;
455 case AArch64::BICXrr: Opcode = AArch64::BICXrs;
break;
456 case AArch64::ANDSWrr: Opcode = AArch64::ANDSWrs;
break;
457 case AArch64::ANDSXrr: Opcode = AArch64::ANDSXrs;
break;
458 case AArch64::BICSWrr: Opcode = AArch64::BICSWrs;
break;
459 case AArch64::BICSXrr: Opcode = AArch64::BICSXrs;
break;
460 case AArch64::EONWrr: Opcode = AArch64::EONWrs;
break;
461 case AArch64::EONXrr: Opcode = AArch64::EONXrs;
break;
462 case AArch64::EORWrr: Opcode = AArch64::EORWrs;
break;
463 case AArch64::EORXrr: Opcode = AArch64::EORXrs;
break;
464 case AArch64::ORNWrr: Opcode = AArch64::ORNWrs;
break;
465 case AArch64::ORNXrr: Opcode = AArch64::ORNXrs;
break;
466 case AArch64::ORRWrr: Opcode = AArch64::ORRWrs;
break;
467 case AArch64::ORRXrr: Opcode = AArch64::ORRXrs;
break;
475 transferImpOps(MI, MIB1, MIB1);
489 TII->get(AArch64::LDRXl), DstReg);
497 "Only expect globals, externalsymbols, or constant pools");
510 unsigned Reg32 =
TRI->getSubReg(DstReg, AArch64::sub_32);
518 MIB2 =
BuildMI(MBB, MBBI, DL,
TII->get(AArch64::LDRXui))
534 "Only expect globals, externalsymbols, or constant pools");
542 transferImpOps(MI, MIB1, MIB2);
548 case AArch64::MOVaddr:
549 case AArch64::MOVaddrJT:
550 case AArch64::MOVaddrCP:
551 case AArch64::MOVaddrBA:
552 case AArch64::MOVaddrTLS:
553 case AArch64::MOVaddrEXT: {
570 Tag.setOffset(0x100000000);
584 transferImpOps(MI, MIB1, MIB2);
588 case AArch64::ADDlowTLS:
598 case AArch64::MOVbaseTLS: {
600 auto SysReg = AArch64SysReg::TPIDR_EL0;
604 SysReg = AArch64SysReg::TPIDR_EL1;
606 SysReg = AArch64SysReg::TPIDR_EL3;
608 SysReg = AArch64SysReg::TPIDR_EL2;
610 SysReg = AArch64SysReg::TPIDR_EL1;
617 case AArch64::MOVi32imm:
619 case AArch64::MOVi64imm:
621 case AArch64::RET_ReallyLR: {
630 transferImpOps(MI, MIB, MIB);
634 case AArch64::CMP_SWAP_8:
635 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRB, AArch64::STLXRB,
638 AArch64::WZR, NextMBBI);
639 case AArch64::CMP_SWAP_16:
640 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRH, AArch64::STLXRH,
643 AArch64::WZR, NextMBBI);
644 case AArch64::CMP_SWAP_32:
645 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRW, AArch64::STLXRW,
648 AArch64::WZR, NextMBBI);
649 case AArch64::CMP_SWAP_64:
650 return expandCMP_SWAP(MBB, MBBI,
651 AArch64::LDAXRX, AArch64::STLXRX, AArch64::SUBSXrs,
653 AArch64::XZR, NextMBBI);
654 case AArch64::CMP_SWAP_128:
655 return expandCMP_SWAP_128(MBB, MBBI, NextMBBI);
657 case AArch64::AESMCrrTied:
658 case AArch64::AESIMCrrTied: {
661 TII->get(Opcode == AArch64::AESMCrrTied ? AArch64::AESMCrr :
665 transferImpOps(MI, MIB, MIB);
669 case AArch64::IRGstack: {
680 StackOffset FrameRegOffset = TFI->resolveFrameOffsetReference(
681 MF, BaseOffset,
false ,
false , FrameReg,
685 if (FrameRegOffset) {
689 FrameRegOffset,
TII);
698 case AArch64::TAGPstack: {
701 TII->get(Offset >= 0 ? AArch64::ADDG : AArch64::SUBG))
709 case AArch64::STGloop:
710 case AArch64::STZGloop:
711 return expandSetTagLoop(MBB, MBBI, NextMBBI);
724 Modified |= expandMI(MBB, MBBI, NMBBI);
736 Modified |= expandMBB(MBB);
742 return new AArch64ExpandPseudo();
unsigned getTargetFlags() const
MO_PREL - Indicates that the bits of the symbol operand represented by MO_G0 etc are PC relative...
const MachineInstrBuilder & add(const MachineOperand &MO) const
MO_G3 - A symbol operand with this flag (granule 3) represents the high 16-bits of a 64-bit address...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
StackOffset is a wrapper around scalable and non-scalable offsets and is used in several functions su...
This class represents lattice values for constants.
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
MO_TAGGED - With MO_PAGE, indicates that the page includes a memory tag in bits 56-63.
void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, StackOffset Offset, const TargetInstrInfo *TII, MachineInstr::MIFlag=MachineInstr::NoFlags, bool SetNZCV=false, bool NeedsWinCFI=false, bool *HasWinCFI=nullptr)
emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg plus Offset.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Describe properties that are true of each instruction in the target description file.
unsigned const TargetRegisterInfo * TRI
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const HexagonInstrInfo * TII
INITIALIZE_PASS(AArch64ExpandPseudo, "aarch64-expand-pseudo", AARCH64_EXPAND_PSEUDO_NAME, false, false) static void transferImpOps(MachineInstr &OldMI
Transfer implicit operands on the pseudo instruction to the instructions created from the expansion...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const char * getSymbolName() const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
virtual const TargetInstrInfo * getInstrInfo() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
unsigned getKillRegState(bool B)
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
unsigned getDeadRegState(bool B)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
void initializeAArch64ExpandPseudoPass(PassRegistry &)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineInstrBuilder & UseMI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const GlobalValue * getGlobal() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
const Triple & getTargetTriple() const
self_iterator getIterator()
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MachineInstrBuilder MachineInstrBuilder & DefMI
FunctionPass * createAArch64ExpandPseudoPass()
Returns an instance of the pseudo instruction expansion pass.
CodeModel::Model getCodeModel() const
Returns the code model.
bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
void expandMOVImm(uint64_t Imm, unsigned BitSize, SmallVectorImpl< ImmInsnModel > &Insn)
Expand a MOVi32imm or MOVi64imm pseudo instruction to one or more real move-immediate instructions to...
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
int64_t getOffset() const
Return the offset from the symbol in this operand.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
unsigned getTaggedBasePointerOffset() const
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
uint16_t getFlags() const
Return the MI flags bitvector.
#define AARCH64_EXPAND_PSEUDO_NAME
bool isTargetILP32() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
StringRef - Represent a constant reference to a string, i.e.
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow...
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
Wrapper class representing virtual and physical registers.