LLVM 23.0.0git
AArch64ExpandPseudoInsts.cpp
Go to the documentation of this file.
1//===- AArch64ExpandPseudoInsts.cpp - Expand pseudo instructions ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a pass that expands pseudo instructions into target
10// instructions to allow proper scheduling and other late optimizations. This
11// pass should be run after register allocation but before the post-regalloc
12// scheduling pass.
13//
14//===----------------------------------------------------------------------===//
15
16#include "AArch64ExpandImm.h"
17#include "AArch64InstrInfo.h"
19#include "AArch64Subtarget.h"
31#include "llvm/IR/DebugLoc.h"
32#include "llvm/MC/MCInstrDesc.h"
33#include "llvm/Pass.h"
37#include <cassert>
38#include <cstdint>
39#include <iterator>
40
41using namespace llvm;
42
43#define AARCH64_EXPAND_PSEUDO_NAME "AArch64 pseudo instruction expansion pass"
44
45namespace {
46
47class AArch64ExpandPseudo : public MachineFunctionPass {
48public:
49 const AArch64InstrInfo *TII;
50
51 static char ID;
52
53 AArch64ExpandPseudo() : MachineFunctionPass(ID) {}
54
55 bool runOnMachineFunction(MachineFunction &Fn) override;
56
57 StringRef getPassName() const override { return AARCH64_EXPAND_PSEUDO_NAME; }
58
59private:
60 bool expandMBB(MachineBasicBlock &MBB);
63 bool expandMultiVecPseudo(MachineBasicBlock &MBB,
65 TargetRegisterClass ContiguousClass,
66 TargetRegisterClass StridedClass,
67 unsigned ContiguousOpc, unsigned StridedOpc);
68 bool expandFormTuplePseudo(MachineBasicBlock &MBB,
71 unsigned Size);
73 unsigned BitSize);
74
75 bool expand_DestructiveOp(MachineInstr &MI, MachineBasicBlock &MBB,
78 unsigned LdarOp, unsigned StlrOp, unsigned CmpOp,
79 unsigned ExtendImm, unsigned ZeroReg,
81 bool expandCMP_SWAP_128(MachineBasicBlock &MBB,
84 bool expandSetTagLoop(MachineBasicBlock &MBB,
87 bool expandSVESpillFill(MachineBasicBlock &MBB,
89 unsigned N);
90 bool expandCALL_RVMARKER(MachineBasicBlock &MBB,
93 bool expandStoreSwiftAsyncContext(MachineBasicBlock &MBB,
95 struct ConditionalBlocks {
96 MachineBasicBlock &CondBB;
97 MachineBasicBlock &EndBB;
98 };
99 ConditionalBlocks expandConditionalPseudo(MachineBasicBlock &MBB,
101 DebugLoc DL,
102 MachineInstrBuilder &Branch);
103 MachineBasicBlock *expandRestoreZASave(MachineBasicBlock &MBB,
105 MachineBasicBlock *expandCommitZASave(MachineBasicBlock &MBB,
107 MachineBasicBlock *expandCondSMToggle(MachineBasicBlock &MBB,
109};
110
111} // end anonymous namespace
112
113char AArch64ExpandPseudo::ID = 0;
114
115INITIALIZE_PASS(AArch64ExpandPseudo, "aarch64-expand-pseudo",
116 AARCH64_EXPAND_PSEUDO_NAME, false, false)
117
118/// Transfer implicit operands on the pseudo instruction to the
119/// instructions created from the expansion.
120static void transferImpOps(MachineInstr &OldMI, MachineInstrBuilder &UseMI,
122 const MCInstrDesc &Desc = OldMI.getDesc();
123 for (const MachineOperand &MO :
124 llvm::drop_begin(OldMI.operands(), Desc.getNumOperands())) {
125 assert(MO.isReg() && MO.getReg());
126 if (MO.isUse())
127 UseMI.add(MO);
128 else
129 DefMI.add(MO);
130 }
131}
132
133/// Expand a MOVi32imm or MOVi64imm pseudo instruction to one or more
134/// real move-immediate instructions to synthesize the immediate.
135bool AArch64ExpandPseudo::expandMOVImm(MachineBasicBlock &MBB,
137 unsigned BitSize) {
138 MachineInstr &MI = *MBBI;
139 Register DstReg = MI.getOperand(0).getReg();
140 unsigned RenamableState =
141 getRenamableRegState(MI.getOperand(0).isRenamable());
142 uint64_t Imm = MI.getOperand(1).getImm();
143
144 if (DstReg == AArch64::XZR || DstReg == AArch64::WZR) {
145 // Useless def, and we don't want to risk creating an invalid ORR (which
146 // would really write to sp).
147 MI.eraseFromParent();
148 return true;
149 }
150
152 AArch64_IMM::expandMOVImm(Imm, BitSize, Insn);
153 assert(Insn.size() != 0);
154
155 SmallVector<MachineInstrBuilder, 4> MIBS;
156 for (auto I = Insn.begin(), E = Insn.end(); I != E; ++I) {
157 bool LastItem = std::next(I) == E;
158 switch (I->Opcode)
159 {
160 default: llvm_unreachable("unhandled!"); break;
161
162 case AArch64::ORRWri:
163 case AArch64::ORRXri:
164 if (I->Op1 == 0) {
165 MIBS.push_back(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(I->Opcode))
166 .add(MI.getOperand(0))
167 .addReg(BitSize == 32 ? AArch64::WZR : AArch64::XZR)
168 .addImm(I->Op2));
169 } else {
170 Register DstReg = MI.getOperand(0).getReg();
171 bool DstIsDead = MI.getOperand(0).isDead();
172 MIBS.push_back(
173 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(I->Opcode))
174 .addReg(DstReg, RegState::Define |
175 getDeadRegState(DstIsDead && LastItem) |
176 RenamableState)
177 .addReg(DstReg)
178 .addImm(I->Op2));
179 }
180 break;
181 case AArch64::EONXrs:
182 case AArch64::EORXrs:
183 case AArch64::ORRWrs:
184 case AArch64::ORRXrs: {
185 Register DstReg = MI.getOperand(0).getReg();
186 bool DstIsDead = MI.getOperand(0).isDead();
187 MIBS.push_back(
188 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(I->Opcode))
189 .addReg(DstReg, RegState::Define |
190 getDeadRegState(DstIsDead && LastItem) |
191 RenamableState)
192 .addReg(DstReg)
193 .addReg(DstReg)
194 .addImm(I->Op2));
195 } break;
196 case AArch64::ANDXri:
197 case AArch64::EORXri:
198 if (I->Op1 == 0) {
199 MIBS.push_back(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(I->Opcode))
200 .add(MI.getOperand(0))
201 .addReg(BitSize == 32 ? AArch64::WZR : AArch64::XZR)
202 .addImm(I->Op2));
203 } else {
204 Register DstReg = MI.getOperand(0).getReg();
205 bool DstIsDead = MI.getOperand(0).isDead();
206 MIBS.push_back(
207 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(I->Opcode))
208 .addReg(DstReg, RegState::Define |
209 getDeadRegState(DstIsDead && LastItem) |
210 RenamableState)
211 .addReg(DstReg)
212 .addImm(I->Op2));
213 }
214 break;
215 case AArch64::MOVNWi:
216 case AArch64::MOVNXi:
217 case AArch64::MOVZWi:
218 case AArch64::MOVZXi: {
219 bool DstIsDead = MI.getOperand(0).isDead();
220 MIBS.push_back(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(I->Opcode))
221 .addReg(DstReg, RegState::Define |
222 getDeadRegState(DstIsDead && LastItem) |
223 RenamableState)
224 .addImm(I->Op1)
225 .addImm(I->Op2));
226 } break;
227 case AArch64::MOVKWi:
228 case AArch64::MOVKXi: {
229 Register DstReg = MI.getOperand(0).getReg();
230 bool DstIsDead = MI.getOperand(0).isDead();
231 MIBS.push_back(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(I->Opcode))
232 .addReg(DstReg,
234 getDeadRegState(DstIsDead && LastItem) |
235 RenamableState)
236 .addReg(DstReg)
237 .addImm(I->Op1)
238 .addImm(I->Op2));
239 } break;
240 }
241 }
242 transferImpOps(MI, MIBS.front(), MIBS.back());
243 MI.eraseFromParent();
244 return true;
245}
246
247bool AArch64ExpandPseudo::expandCMP_SWAP(
248 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned LdarOp,
249 unsigned StlrOp, unsigned CmpOp, unsigned ExtendImm, unsigned ZeroReg,
250 MachineBasicBlock::iterator &NextMBBI) {
251 MachineInstr &MI = *MBBI;
252 MIMetadata MIMD(MI);
253 const MachineOperand &Dest = MI.getOperand(0);
254 Register StatusReg = MI.getOperand(1).getReg();
255 bool StatusDead = MI.getOperand(1).isDead();
256 // Duplicating undef operands into 2 instructions does not guarantee the same
257 // value on both; However undef should be replaced by xzr anyway.
258 assert(!MI.getOperand(2).isUndef() && "cannot handle undef");
259 Register AddrReg = MI.getOperand(2).getReg();
260 Register DesiredReg = MI.getOperand(3).getReg();
261 Register NewReg = MI.getOperand(4).getReg();
262
263 MachineFunction *MF = MBB.getParent();
264 auto LoadCmpBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
265 auto StoreBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
266 auto DoneBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
267
268 MF->insert(++MBB.getIterator(), LoadCmpBB);
269 MF->insert(++LoadCmpBB->getIterator(), StoreBB);
270 MF->insert(++StoreBB->getIterator(), DoneBB);
271
272 // .Lloadcmp:
273 // mov wStatus, 0
274 // ldaxr xDest, [xAddr]
275 // cmp xDest, xDesired
276 // b.ne .Ldone
277 if (!StatusDead)
278 BuildMI(LoadCmpBB, MIMD, TII->get(AArch64::MOVZWi), StatusReg)
279 .addImm(0).addImm(0);
280 BuildMI(LoadCmpBB, MIMD, TII->get(LdarOp), Dest.getReg())
281 .addReg(AddrReg);
282 BuildMI(LoadCmpBB, MIMD, TII->get(CmpOp), ZeroReg)
283 .addReg(Dest.getReg(), getKillRegState(Dest.isDead()))
284 .addReg(DesiredReg)
285 .addImm(ExtendImm);
286 BuildMI(LoadCmpBB, MIMD, TII->get(AArch64::Bcc))
288 .addMBB(DoneBB)
289 .addReg(AArch64::NZCV, RegState::Implicit | RegState::Kill);
290 LoadCmpBB->addSuccessor(DoneBB);
291 LoadCmpBB->addSuccessor(StoreBB);
292
293 // .Lstore:
294 // stlxr wStatus, xNew, [xAddr]
295 // cbnz wStatus, .Lloadcmp
296 BuildMI(StoreBB, MIMD, TII->get(StlrOp), StatusReg)
297 .addReg(NewReg)
298 .addReg(AddrReg);
299 BuildMI(StoreBB, MIMD, TII->get(AArch64::CBNZW))
300 .addReg(StatusReg, getKillRegState(StatusDead))
301 .addMBB(LoadCmpBB);
302 StoreBB->addSuccessor(LoadCmpBB);
303 StoreBB->addSuccessor(DoneBB);
304
305 DoneBB->splice(DoneBB->end(), &MBB, MI, MBB.end());
306 DoneBB->transferSuccessors(&MBB);
307
308 MBB.addSuccessor(LoadCmpBB);
309
310 NextMBBI = MBB.end();
311 MI.eraseFromParent();
312
313 // Recompute livein lists.
314 LivePhysRegs LiveRegs;
315 computeAndAddLiveIns(LiveRegs, *DoneBB);
316 computeAndAddLiveIns(LiveRegs, *StoreBB);
317 computeAndAddLiveIns(LiveRegs, *LoadCmpBB);
318 // Do an extra pass around the loop to get loop carried registers right.
319 StoreBB->clearLiveIns();
320 computeAndAddLiveIns(LiveRegs, *StoreBB);
321 LoadCmpBB->clearLiveIns();
322 computeAndAddLiveIns(LiveRegs, *LoadCmpBB);
323
324 return true;
325}
326
327bool AArch64ExpandPseudo::expandCMP_SWAP_128(
328 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
329 MachineBasicBlock::iterator &NextMBBI) {
330 MachineInstr &MI = *MBBI;
331 MIMetadata MIMD(MI);
332 MachineOperand &DestLo = MI.getOperand(0);
333 MachineOperand &DestHi = MI.getOperand(1);
334 Register StatusReg = MI.getOperand(2).getReg();
335 bool StatusDead = MI.getOperand(2).isDead();
336 // Duplicating undef operands into 2 instructions does not guarantee the same
337 // value on both; However undef should be replaced by xzr anyway.
338 assert(!MI.getOperand(3).isUndef() && "cannot handle undef");
339 Register AddrReg = MI.getOperand(3).getReg();
340 Register DesiredLoReg = MI.getOperand(4).getReg();
341 Register DesiredHiReg = MI.getOperand(5).getReg();
342 Register NewLoReg = MI.getOperand(6).getReg();
343 Register NewHiReg = MI.getOperand(7).getReg();
344
345 unsigned LdxpOp, StxpOp;
346
347 switch (MI.getOpcode()) {
348 case AArch64::CMP_SWAP_128_MONOTONIC:
349 LdxpOp = AArch64::LDXPX;
350 StxpOp = AArch64::STXPX;
351 break;
352 case AArch64::CMP_SWAP_128_RELEASE:
353 LdxpOp = AArch64::LDXPX;
354 StxpOp = AArch64::STLXPX;
355 break;
356 case AArch64::CMP_SWAP_128_ACQUIRE:
357 LdxpOp = AArch64::LDAXPX;
358 StxpOp = AArch64::STXPX;
359 break;
360 case AArch64::CMP_SWAP_128:
361 LdxpOp = AArch64::LDAXPX;
362 StxpOp = AArch64::STLXPX;
363 break;
364 default:
365 llvm_unreachable("Unexpected opcode");
366 }
367
368 MachineFunction *MF = MBB.getParent();
369 auto LoadCmpBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
370 auto StoreBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
371 auto FailBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
372 auto DoneBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
373
374 MF->insert(++MBB.getIterator(), LoadCmpBB);
375 MF->insert(++LoadCmpBB->getIterator(), StoreBB);
376 MF->insert(++StoreBB->getIterator(), FailBB);
377 MF->insert(++FailBB->getIterator(), DoneBB);
378
379 // .Lloadcmp:
380 // ldaxp xDestLo, xDestHi, [xAddr]
381 // cmp xDestLo, xDesiredLo
382 // sbcs xDestHi, xDesiredHi
383 // b.ne .Ldone
384 BuildMI(LoadCmpBB, MIMD, TII->get(LdxpOp))
385 .addReg(DestLo.getReg(), RegState::Define)
386 .addReg(DestHi.getReg(), RegState::Define)
387 .addReg(AddrReg);
388 BuildMI(LoadCmpBB, MIMD, TII->get(AArch64::SUBSXrs), AArch64::XZR)
389 .addReg(DestLo.getReg(), getKillRegState(DestLo.isDead()))
390 .addReg(DesiredLoReg)
391 .addImm(0);
392 BuildMI(LoadCmpBB, MIMD, TII->get(AArch64::CSINCWr), StatusReg)
393 .addUse(AArch64::WZR)
394 .addUse(AArch64::WZR)
396 BuildMI(LoadCmpBB, MIMD, TII->get(AArch64::SUBSXrs), AArch64::XZR)
397 .addReg(DestHi.getReg(), getKillRegState(DestHi.isDead()))
398 .addReg(DesiredHiReg)
399 .addImm(0);
400 BuildMI(LoadCmpBB, MIMD, TII->get(AArch64::CSINCWr), StatusReg)
401 .addUse(StatusReg, RegState::Kill)
402 .addUse(StatusReg, RegState::Kill)
404 BuildMI(LoadCmpBB, MIMD, TII->get(AArch64::CBNZW))
405 .addUse(StatusReg, getKillRegState(StatusDead))
406 .addMBB(FailBB);
407 LoadCmpBB->addSuccessor(FailBB);
408 LoadCmpBB->addSuccessor(StoreBB);
409
410 // .Lstore:
411 // stlxp wStatus, xNewLo, xNewHi, [xAddr]
412 // cbnz wStatus, .Lloadcmp
413 BuildMI(StoreBB, MIMD, TII->get(StxpOp), StatusReg)
414 .addReg(NewLoReg)
415 .addReg(NewHiReg)
416 .addReg(AddrReg);
417 BuildMI(StoreBB, MIMD, TII->get(AArch64::CBNZW))
418 .addReg(StatusReg, getKillRegState(StatusDead))
419 .addMBB(LoadCmpBB);
420 BuildMI(StoreBB, MIMD, TII->get(AArch64::B)).addMBB(DoneBB);
421 StoreBB->addSuccessor(LoadCmpBB);
422 StoreBB->addSuccessor(DoneBB);
423
424 // .Lfail:
425 // stlxp wStatus, xDestLo, xDestHi, [xAddr]
426 // cbnz wStatus, .Lloadcmp
427 BuildMI(FailBB, MIMD, TII->get(StxpOp), StatusReg)
428 .addReg(DestLo.getReg())
429 .addReg(DestHi.getReg())
430 .addReg(AddrReg);
431 BuildMI(FailBB, MIMD, TII->get(AArch64::CBNZW))
432 .addReg(StatusReg, getKillRegState(StatusDead))
433 .addMBB(LoadCmpBB);
434 FailBB->addSuccessor(LoadCmpBB);
435 FailBB->addSuccessor(DoneBB);
436
437 DoneBB->splice(DoneBB->end(), &MBB, MI, MBB.end());
438 DoneBB->transferSuccessors(&MBB);
439
440 MBB.addSuccessor(LoadCmpBB);
441
442 NextMBBI = MBB.end();
443 MI.eraseFromParent();
444
445 // Recompute liveness bottom up.
446 LivePhysRegs LiveRegs;
447 computeAndAddLiveIns(LiveRegs, *DoneBB);
448 computeAndAddLiveIns(LiveRegs, *FailBB);
449 computeAndAddLiveIns(LiveRegs, *StoreBB);
450 computeAndAddLiveIns(LiveRegs, *LoadCmpBB);
451
452 // Do an extra pass in the loop to get the loop carried dependencies right.
453 FailBB->clearLiveIns();
454 computeAndAddLiveIns(LiveRegs, *FailBB);
455 StoreBB->clearLiveIns();
456 computeAndAddLiveIns(LiveRegs, *StoreBB);
457 LoadCmpBB->clearLiveIns();
458 computeAndAddLiveIns(LiveRegs, *LoadCmpBB);
459
460 return true;
461}
462
463/// \brief Expand Pseudos to Instructions with destructive operands.
464///
465/// This mechanism uses MOVPRFX instructions for zeroing the false lanes
466/// or for fixing relaxed register allocation conditions to comply with
467/// the instructions register constraints. The latter case may be cheaper
468/// than setting the register constraints in the register allocator,
469/// since that will insert regular MOV instructions rather than MOVPRFX.
470///
471/// Example (after register allocation):
472///
473/// FSUB_ZPZZ_ZERO_B Z0, Pg, Z1, Z0
474///
475/// * The Pseudo FSUB_ZPZZ_ZERO_B maps to FSUB_ZPmZ_B.
476/// * We cannot map directly to FSUB_ZPmZ_B because the register
477/// constraints of the instruction are not met.
478/// * Also the _ZERO specifies the false lanes need to be zeroed.
479///
480/// We first try to see if the destructive operand == result operand,
481/// if not, we try to swap the operands, e.g.
482///
483/// FSUB_ZPmZ_B Z0, Pg/m, Z0, Z1
484///
485/// But because FSUB_ZPmZ is not commutative, this is semantically
486/// different, so we need a reverse instruction:
487///
488/// FSUBR_ZPmZ_B Z0, Pg/m, Z0, Z1
489///
490/// Then we implement the zeroing of the false lanes of Z0 by adding
491/// a zeroing MOVPRFX instruction:
492///
493/// MOVPRFX_ZPzZ_B Z0, Pg/z, Z0
494/// FSUBR_ZPmZ_B Z0, Pg/m, Z0, Z1
495///
496/// Note that this can only be done for _ZERO or _UNDEF variants where
497/// we can guarantee the false lanes to be zeroed (by implementing this)
498/// or that they are undef (don't care / not used), otherwise the
499/// swapping of operands is illegal because the operation is not
500/// (or cannot be emulated to be) fully commutative.
501bool AArch64ExpandPseudo::expand_DestructiveOp(
502 MachineInstr &MI,
503 MachineBasicBlock &MBB,
505 unsigned Opcode = AArch64::getSVEPseudoMap(MI.getOpcode());
506 uint64_t DType = TII->get(Opcode).TSFlags & AArch64::DestructiveInstTypeMask;
507 uint64_t FalseLanes = MI.getDesc().TSFlags & AArch64::FalseLanesMask;
508 bool FalseZero = FalseLanes == AArch64::FalseLanesZero;
509 Register DstReg = MI.getOperand(0).getReg();
510 bool DstIsDead = MI.getOperand(0).isDead();
511 bool UseRev = false;
512 unsigned PredIdx, DOPIdx, SrcIdx, Src2Idx;
513
514 switch (DType) {
517 if (DstReg == MI.getOperand(3).getReg()) {
518 // FSUB Zd, Pg, Zs1, Zd ==> FSUBR Zd, Pg/m, Zd, Zs1
519 std::tie(PredIdx, DOPIdx, SrcIdx) = std::make_tuple(1, 3, 2);
520 UseRev = true;
521 break;
522 }
523 [[fallthrough]];
526 std::tie(PredIdx, DOPIdx, SrcIdx) = std::make_tuple(1, 2, 3);
527 break;
529 std::tie(PredIdx, DOPIdx, SrcIdx) = std::make_tuple(2, 3, 3);
530 break;
532 std::tie(PredIdx, DOPIdx, SrcIdx, Src2Idx) = std::make_tuple(1, 2, 3, 4);
533 if (DstReg == MI.getOperand(3).getReg()) {
534 // FMLA Zd, Pg, Za, Zd, Zm ==> FMAD Zdn, Pg, Zm, Za
535 std::tie(PredIdx, DOPIdx, SrcIdx, Src2Idx) = std::make_tuple(1, 3, 4, 2);
536 UseRev = true;
537 } else if (DstReg == MI.getOperand(4).getReg()) {
538 // FMLA Zd, Pg, Za, Zm, Zd ==> FMAD Zdn, Pg, Zm, Za
539 std::tie(PredIdx, DOPIdx, SrcIdx, Src2Idx) = std::make_tuple(1, 4, 3, 2);
540 UseRev = true;
541 }
542 break;
544 // EXT_ZZI_CONSTRUCTIVE Zd, Zs, Imm
545 // ==> MOVPRFX Zd Zs; EXT_ZZI Zd, Zd, Zs, Imm
546 std::tie(DOPIdx, SrcIdx, Src2Idx) = std::make_tuple(1, 1, 2);
547 break;
548 default:
549 llvm_unreachable("Unsupported Destructive Operand type");
550 }
551
552 // MOVPRFX can only be used if the destination operand
553 // is the destructive operand, not as any other operand,
554 // so the Destructive Operand must be unique.
555 bool DOPRegIsUnique = false;
556 switch (DType) {
558 DOPRegIsUnique = DstReg != MI.getOperand(SrcIdx).getReg();
559 break;
562 DOPRegIsUnique =
563 DstReg != MI.getOperand(DOPIdx).getReg() ||
564 MI.getOperand(DOPIdx).getReg() != MI.getOperand(SrcIdx).getReg();
565 break;
569 DOPRegIsUnique = true;
570 break;
572 DOPRegIsUnique =
573 DstReg != MI.getOperand(DOPIdx).getReg() ||
574 (MI.getOperand(DOPIdx).getReg() != MI.getOperand(SrcIdx).getReg() &&
575 MI.getOperand(DOPIdx).getReg() != MI.getOperand(Src2Idx).getReg());
576 break;
577 }
578
579 // Resolve the reverse opcode
580 if (UseRev) {
581 int NewOpcode;
582 // e.g. DIV -> DIVR
583 if ((NewOpcode = AArch64::getSVERevInstr(Opcode)) != -1)
584 Opcode = NewOpcode;
585 // e.g. DIVR -> DIV
586 else if ((NewOpcode = AArch64::getSVENonRevInstr(Opcode)) != -1)
587 Opcode = NewOpcode;
588 }
589
590 // Get the right MOVPRFX
591 uint64_t ElementSize = TII->getElementSizeForOpcode(Opcode);
592 unsigned MovPrfx, LSLZero, MovPrfxZero;
593 switch (ElementSize) {
596 MovPrfx = AArch64::MOVPRFX_ZZ;
597 LSLZero = AArch64::LSL_ZPmI_B;
598 MovPrfxZero = AArch64::MOVPRFX_ZPzZ_B;
599 break;
601 MovPrfx = AArch64::MOVPRFX_ZZ;
602 LSLZero = AArch64::LSL_ZPmI_H;
603 MovPrfxZero = AArch64::MOVPRFX_ZPzZ_H;
604 break;
606 MovPrfx = AArch64::MOVPRFX_ZZ;
607 LSLZero = AArch64::LSL_ZPmI_S;
608 MovPrfxZero = AArch64::MOVPRFX_ZPzZ_S;
609 break;
611 MovPrfx = AArch64::MOVPRFX_ZZ;
612 LSLZero = AArch64::LSL_ZPmI_D;
613 MovPrfxZero = AArch64::MOVPRFX_ZPzZ_D;
614 break;
615 default:
616 llvm_unreachable("Unsupported ElementSize");
617 }
618
619 // Preserve undef state until DOP's reg is defined.
620 unsigned DOPRegState = getUndefRegState(MI.getOperand(DOPIdx).isUndef());
621
622 //
623 // Create the destructive operation (if required)
624 //
625 MachineInstrBuilder PRFX, DOP;
626 if (FalseZero) {
627 // If we cannot prefix the requested instruction we'll instead emit a
628 // prefixed_zeroing_mov for DestructiveBinary.
629 assert((DOPRegIsUnique || DType == AArch64::DestructiveBinary ||
632 "The destructive operand should be unique");
633 assert(ElementSize != AArch64::ElementSizeNone &&
634 "This instruction is unpredicated");
635
636 // Merge source operand into destination register
637 PRFX = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(MovPrfxZero))
638 .addReg(DstReg, RegState::Define)
639 .addReg(MI.getOperand(PredIdx).getReg())
640 .addReg(MI.getOperand(DOPIdx).getReg(), DOPRegState);
641
642 // After the movprfx, the destructive operand is same as Dst
643 DOPIdx = 0;
644 DOPRegState = 0;
645
646 // Create the additional LSL to zero the lanes when the DstReg is not
647 // unique. Zeros the lanes in z0 that aren't active in p0 with sequence
648 // movprfx z0.b, p0/z, z0.b; lsl z0.b, p0/m, z0.b, #0;
649 if ((DType == AArch64::DestructiveBinary ||
652 !DOPRegIsUnique) {
653 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(LSLZero))
654 .addReg(DstReg, RegState::Define)
655 .add(MI.getOperand(PredIdx))
656 .addReg(DstReg)
657 .addImm(0);
658 }
659 } else if (DstReg != MI.getOperand(DOPIdx).getReg()) {
660 assert(DOPRegIsUnique && "The destructive operand should be unique");
661 PRFX = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(MovPrfx))
662 .addReg(DstReg, RegState::Define)
663 .addReg(MI.getOperand(DOPIdx).getReg(), DOPRegState);
664 DOPIdx = 0;
665 DOPRegState = 0;
666 }
667
668 //
669 // Create the destructive operation
670 //
671 DOP = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opcode))
672 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead));
673 DOPRegState = DOPRegState | RegState::Kill;
674
675 switch (DType) {
677 DOP.addReg(MI.getOperand(DOPIdx).getReg(), DOPRegState)
678 .add(MI.getOperand(PredIdx))
679 .add(MI.getOperand(SrcIdx));
680 break;
685 DOP.add(MI.getOperand(PredIdx))
686 .addReg(MI.getOperand(DOPIdx).getReg(), DOPRegState)
687 .add(MI.getOperand(SrcIdx));
688 break;
690 DOP.add(MI.getOperand(PredIdx))
691 .addReg(MI.getOperand(DOPIdx).getReg(), DOPRegState)
692 .add(MI.getOperand(SrcIdx))
693 .add(MI.getOperand(Src2Idx));
694 break;
696 DOP.addReg(MI.getOperand(DOPIdx).getReg(), DOPRegState)
697 .add(MI.getOperand(SrcIdx))
698 .add(MI.getOperand(Src2Idx));
699 break;
700 }
701
702 if (PRFX) {
703 transferImpOps(MI, PRFX, DOP);
705 } else
706 transferImpOps(MI, DOP, DOP);
707
708 MI.eraseFromParent();
709 return true;
710}
711
712bool AArch64ExpandPseudo::expandSetTagLoop(
713 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
714 MachineBasicBlock::iterator &NextMBBI) {
715 MachineInstr &MI = *MBBI;
716 DebugLoc DL = MI.getDebugLoc();
717 Register SizeReg = MI.getOperand(0).getReg();
718 Register AddressReg = MI.getOperand(1).getReg();
719
720 MachineFunction *MF = MBB.getParent();
721
722 bool ZeroData = MI.getOpcode() == AArch64::STZGloop_wback;
723 const unsigned OpCode1 =
724 ZeroData ? AArch64::STZGPostIndex : AArch64::STGPostIndex;
725 const unsigned OpCode2 =
726 ZeroData ? AArch64::STZ2GPostIndex : AArch64::ST2GPostIndex;
727
728 unsigned Size = MI.getOperand(2).getImm();
729 assert(Size > 0 && Size % 16 == 0);
730 if (Size % (16 * 2) != 0) {
731 BuildMI(MBB, MBBI, DL, TII->get(OpCode1), AddressReg)
732 .addReg(AddressReg)
733 .addReg(AddressReg)
734 .addImm(1);
735 Size -= 16;
736 }
738 BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVi64imm), SizeReg)
739 .addImm(Size);
740 expandMOVImm(MBB, I, 64);
741
742 auto LoopBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
743 auto DoneBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
744
745 MF->insert(++MBB.getIterator(), LoopBB);
746 MF->insert(++LoopBB->getIterator(), DoneBB);
747
748 BuildMI(LoopBB, DL, TII->get(OpCode2))
749 .addDef(AddressReg)
750 .addReg(AddressReg)
751 .addReg(AddressReg)
752 .addImm(2)
754 .setMIFlags(MI.getFlags());
755 BuildMI(LoopBB, DL, TII->get(AArch64::SUBSXri))
756 .addDef(SizeReg)
757 .addReg(SizeReg)
758 .addImm(16 * 2)
759 .addImm(0);
760 BuildMI(LoopBB, DL, TII->get(AArch64::Bcc))
762 .addMBB(LoopBB)
763 .addReg(AArch64::NZCV, RegState::Implicit | RegState::Kill);
764
765 LoopBB->addSuccessor(LoopBB);
766 LoopBB->addSuccessor(DoneBB);
767
768 DoneBB->splice(DoneBB->end(), &MBB, MI, MBB.end());
769 DoneBB->transferSuccessors(&MBB);
770
771 MBB.addSuccessor(LoopBB);
772
773 NextMBBI = MBB.end();
774 MI.eraseFromParent();
775 // Recompute liveness bottom up.
776 LivePhysRegs LiveRegs;
777 computeAndAddLiveIns(LiveRegs, *DoneBB);
778 computeAndAddLiveIns(LiveRegs, *LoopBB);
779 // Do an extra pass in the loop to get the loop carried dependencies right.
780 // FIXME: is this necessary?
781 LoopBB->clearLiveIns();
782 computeAndAddLiveIns(LiveRegs, *LoopBB);
783 DoneBB->clearLiveIns();
784 computeAndAddLiveIns(LiveRegs, *DoneBB);
785
786 return true;
787}
788
789bool AArch64ExpandPseudo::expandSVESpillFill(MachineBasicBlock &MBB,
791 unsigned Opc, unsigned N) {
792 assert((Opc == AArch64::LDR_ZXI || Opc == AArch64::STR_ZXI ||
793 Opc == AArch64::LDR_PXI || Opc == AArch64::STR_PXI) &&
794 "Unexpected opcode");
795 unsigned RState =
796 getDefRegState(Opc == AArch64::LDR_ZXI || Opc == AArch64::LDR_PXI);
797 unsigned sub0 = (Opc == AArch64::LDR_ZXI || Opc == AArch64::STR_ZXI)
798 ? AArch64::zsub0
799 : AArch64::psub0;
800 const TargetRegisterInfo *TRI =
802 MachineInstr &MI = *MBBI;
803 for (unsigned Offset = 0; Offset < N; ++Offset) {
804 int ImmOffset = MI.getOperand(2).getImm() + Offset;
805 bool Kill = (Offset + 1 == N) ? MI.getOperand(1).isKill() : false;
806 assert(ImmOffset >= -256 && ImmOffset < 256 &&
807 "Immediate spill offset out of range");
808 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc))
809 .addReg(TRI->getSubReg(MI.getOperand(0).getReg(), sub0 + Offset),
810 RState)
811 .addReg(MI.getOperand(1).getReg(), getKillRegState(Kill))
812 .addImm(ImmOffset);
813 }
814 MI.eraseFromParent();
815 return true;
816}
817
818// Create a call with the passed opcode and explicit operands, copying over all
819// the implicit operands from *MBBI, starting at the regmask.
822 const AArch64InstrInfo *TII,
823 unsigned Opcode,
824 ArrayRef<MachineOperand> ExplicitOps,
825 unsigned RegMaskStartIdx) {
826 // Build the MI, with explicit operands first (including the call target).
827 MachineInstr *Call = BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII->get(Opcode))
828 .add(ExplicitOps)
829 .getInstr();
830
831 // Register arguments are added during ISel, but cannot be added as explicit
832 // operands of the branch as it expects to be B <target> which is only one
833 // operand. Instead they are implicit operands used by the branch.
834 while (!MBBI->getOperand(RegMaskStartIdx).isRegMask()) {
835 const MachineOperand &MOP = MBBI->getOperand(RegMaskStartIdx);
836 assert(MOP.isReg() && "can only add register operands");
838 MOP.getReg(), /*Def=*/false, /*Implicit=*/true, /*isKill=*/false,
839 /*isDead=*/false, /*isUndef=*/MOP.isUndef()));
840 RegMaskStartIdx++;
841 }
842 for (const MachineOperand &MO :
843 llvm::drop_begin(MBBI->operands(), RegMaskStartIdx))
844 Call->addOperand(MO);
845
846 return Call;
847}
848
849// Create a call to CallTarget, copying over all the operands from *MBBI,
850// starting at the regmask.
853 const AArch64InstrInfo *TII,
854 MachineOperand &CallTarget,
855 unsigned RegMaskStartIdx) {
856 unsigned Opc = CallTarget.isGlobal() ? AArch64::BL : AArch64::BLR;
857
858 assert((CallTarget.isGlobal() || CallTarget.isReg()) &&
859 "invalid operand for regular call");
860 return createCallWithOps(MBB, MBBI, TII, Opc, CallTarget, RegMaskStartIdx);
861}
862
863bool AArch64ExpandPseudo::expandCALL_RVMARKER(
864 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
865 // Expand CALL_RVMARKER pseudo to:
866 // - a branch to the call target, followed by
867 // - the special `mov x29, x29` marker, if necessary, and
868 // - another branch, to the runtime function
869 // Mark the sequence as bundle, to avoid passes moving other code in between.
870 MachineInstr &MI = *MBBI;
871 MachineOperand &RVTarget = MI.getOperand(0);
872 bool DoEmitMarker = MI.getOperand(1).getImm();
873 assert(RVTarget.isGlobal() && "invalid operand for attached call");
874
875 MachineInstr *OriginalCall = nullptr;
876
877 if (MI.getOpcode() == AArch64::BLRA_RVMARKER) {
878 // ptrauth call.
879 const MachineOperand &CallTarget = MI.getOperand(2);
880 const MachineOperand &Key = MI.getOperand(3);
881 const MachineOperand &IntDisc = MI.getOperand(4);
882 const MachineOperand &AddrDisc = MI.getOperand(5);
883
884 assert((Key.getImm() == AArch64PACKey::IA ||
885 Key.getImm() == AArch64PACKey::IB) &&
886 "Invalid auth call key");
887
888 MachineOperand Ops[] = {CallTarget, Key, IntDisc, AddrDisc};
889
890 OriginalCall = createCallWithOps(MBB, MBBI, TII, AArch64::BLRA, Ops,
891 /*RegMaskStartIdx=*/6);
892 } else {
893 assert(MI.getOpcode() == AArch64::BLR_RVMARKER && "unknown rvmarker MI");
894 OriginalCall = createCall(MBB, MBBI, TII, MI.getOperand(2),
895 // Regmask starts after the RV and call targets.
896 /*RegMaskStartIdx=*/3);
897 }
898
899 if (DoEmitMarker)
900 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ORRXrs))
901 .addReg(AArch64::FP, RegState::Define)
902 .addReg(AArch64::XZR)
903 .addReg(AArch64::FP)
904 .addImm(0);
905
906 auto *RVCall = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::BL))
907 .add(RVTarget)
908 .getInstr();
909
910 if (MI.shouldUpdateAdditionalCallInfo())
911 MBB.getParent()->moveAdditionalCallInfo(&MI, OriginalCall);
912
913 MI.eraseFromParent();
914 finalizeBundle(MBB, OriginalCall->getIterator(),
915 std::next(RVCall->getIterator()));
916 return true;
917}
918
919bool AArch64ExpandPseudo::expandCALL_BTI(MachineBasicBlock &MBB,
921 // Expand CALL_BTI pseudo to:
922 // - a branch to the call target
923 // - a BTI instruction
924 // Mark the sequence as a bundle, to avoid passes moving other code in
925 // between.
926 MachineInstr &MI = *MBBI;
927 MachineInstr *Call = createCall(MBB, MBBI, TII, MI.getOperand(0),
928 // Regmask starts after the call target.
929 /*RegMaskStartIdx=*/1);
930
931 Call->setCFIType(*MBB.getParent(), MI.getCFIType());
932
933 MachineInstr *BTI =
934 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::HINT))
935 // BTI J so that setjmp can to BR to this.
936 .addImm(36)
937 .getInstr();
938
939 if (MI.shouldUpdateAdditionalCallInfo())
941
942 MI.eraseFromParent();
943 finalizeBundle(MBB, Call->getIterator(), std::next(BTI->getIterator()));
944 return true;
945}
946
947bool AArch64ExpandPseudo::expandStoreSwiftAsyncContext(
948 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
949 Register CtxReg = MBBI->getOperand(0).getReg();
950 Register BaseReg = MBBI->getOperand(1).getReg();
951 int Offset = MBBI->getOperand(2).getImm();
952 DebugLoc DL(MBBI->getDebugLoc());
953 auto &STI = MBB.getParent()->getSubtarget<AArch64Subtarget>();
954
955 if (STI.getTargetTriple().getArchName() != "arm64e") {
956 BuildMI(MBB, MBBI, DL, TII->get(AArch64::STRXui))
957 .addUse(CtxReg)
958 .addUse(BaseReg)
959 .addImm(Offset / 8)
962 return true;
963 }
964
965 // We need to sign the context in an address-discriminated way. 0xc31a is a
966 // fixed random value, chosen as part of the ABI.
967 // add x16, xBase, #Offset
968 // movk x16, #0xc31a, lsl #48
969 // mov x17, x22/xzr
970 // pacdb x17, x16
971 // str x17, [xBase, #Offset]
972 unsigned Opc = Offset >= 0 ? AArch64::ADDXri : AArch64::SUBXri;
973 BuildMI(MBB, MBBI, DL, TII->get(Opc), AArch64::X16)
974 .addUse(BaseReg)
975 .addImm(abs(Offset))
976 .addImm(0)
978 BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVKXi), AArch64::X16)
979 .addUse(AArch64::X16)
980 .addImm(0xc31a)
981 .addImm(48)
983 // We're not allowed to clobber X22 (and couldn't clobber XZR if we tried), so
984 // move it somewhere before signing.
985 BuildMI(MBB, MBBI, DL, TII->get(AArch64::ORRXrs), AArch64::X17)
986 .addUse(AArch64::XZR)
987 .addUse(CtxReg)
988 .addImm(0)
990 BuildMI(MBB, MBBI, DL, TII->get(AArch64::PACDB), AArch64::X17)
991 .addUse(AArch64::X17)
992 .addUse(AArch64::X16)
994 BuildMI(MBB, MBBI, DL, TII->get(AArch64::STRXui))
995 .addUse(AArch64::X17)
996 .addUse(BaseReg)
997 .addImm(Offset / 8)
999
1001 return true;
1002}
1003
1004AArch64ExpandPseudo::ConditionalBlocks
1005AArch64ExpandPseudo::expandConditionalPseudo(MachineBasicBlock &MBB,
1007 DebugLoc DL,
1008 MachineInstrBuilder &Branch) {
1009 assert((std::next(MBBI) != MBB.end() ||
1010 MBB.successors().begin() != MBB.successors().end()) &&
1011 "Unexpected unreachable in block");
1012
1013 // Split MBB and create two new blocks:
1014 // - MBB now contains all instructions before the conditional pseudo.
1015 // - CondBB contains the conditional pseudo instruction only.
1016 // - EndBB contains all instructions after the conditional pseudo.
1017 MachineInstr &PrevMI = *std::prev(MBBI);
1018 MachineBasicBlock *CondBB = MBB.splitAt(PrevMI, /*UpdateLiveIns*/ true);
1019 MachineBasicBlock *EndBB =
1020 std::next(MBBI) == CondBB->end()
1021 ? *CondBB->successors().begin()
1022 : CondBB->splitAt(*MBBI, /*UpdateLiveIns*/ true);
1023
1024 // Add the SMBB label to the branch instruction & create a branch to EndBB.
1025 Branch.addMBB(CondBB);
1026 BuildMI(&MBB, DL, TII->get(AArch64::B))
1027 .addMBB(EndBB);
1028 MBB.addSuccessor(EndBB);
1029
1030 // Create branch from CondBB to EndBB. Users of this helper should insert new
1031 // instructions at CondBB.back() -- i.e. before the branch.
1032 BuildMI(CondBB, DL, TII->get(AArch64::B)).addMBB(EndBB);
1033 return {*CondBB, *EndBB};
1034}
1035
1036MachineBasicBlock *
1037AArch64ExpandPseudo::expandRestoreZASave(MachineBasicBlock &MBB,
1039 MachineInstr &MI = *MBBI;
1040 DebugLoc DL = MI.getDebugLoc();
1041
1042 // Compare TPIDR2_EL0 against 0. Restore ZA if TPIDR2_EL0 is zero.
1043 MachineInstrBuilder Branch =
1044 BuildMI(MBB, MBBI, DL, TII->get(AArch64::CBZX)).add(MI.getOperand(0));
1045
1046 auto [CondBB, EndBB] = expandConditionalPseudo(MBB, MBBI, DL, Branch);
1047 // Replace the pseudo with a call (BL).
1048 MachineInstrBuilder MIB =
1049 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::BL));
1050 // Copy operands (mainly the regmask) from the pseudo.
1051 for (unsigned I = 2; I < MI.getNumOperands(); ++I)
1052 MIB.add(MI.getOperand(I));
1053 // Mark the TPIDR2 block pointer (X0) as an implicit use.
1054 MIB.addReg(MI.getOperand(1).getReg(), RegState::Implicit);
1055
1056 MI.eraseFromParent();
1057 return &EndBB;
1058}
1059
1060static constexpr unsigned ZERO_ALL_ZA_MASK = 0b11111111;
1061
1063AArch64ExpandPseudo::expandCommitZASave(MachineBasicBlock &MBB,
1065 MachineInstr &MI = *MBBI;
1066 DebugLoc DL = MI.getDebugLoc();
1067 [[maybe_unused]] auto *RI = MBB.getParent()->getSubtarget().getRegisterInfo();
1068
1069 // Compare TPIDR2_EL0 against 0. Commit ZA if TPIDR2_EL0 is non-zero.
1070 MachineInstrBuilder Branch =
1071 BuildMI(MBB, MBBI, DL, TII->get(AArch64::CBNZX)).add(MI.getOperand(0));
1072
1073 auto [CondBB, EndBB] = expandConditionalPseudo(MBB, MBBI, DL, Branch);
1074 // Replace the pseudo with a call (BL).
1076 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::BL));
1077 // Copy operands (mainly the regmask) from the pseudo.
1078 for (unsigned I = 3; I < MI.getNumOperands(); ++I)
1079 MIB.add(MI.getOperand(I));
1080 // Clear TPIDR2_EL0.
1081 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::MSR))
1082 .addImm(AArch64SysReg::TPIDR2_EL0)
1083 .addReg(AArch64::XZR);
1084 bool ZeroZA = MI.getOperand(1).getImm() != 0;
1085 bool ZeroZT0 = MI.getOperand(2).getImm() != 0;
1086 if (ZeroZA) {
1087 assert(MI.definesRegister(AArch64::ZAB0, RI) && "should define ZA!");
1088 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::ZERO_M))
1090 .addDef(AArch64::ZAB0, RegState::ImplicitDefine);
1091 }
1092 if (ZeroZT0) {
1093 assert(MI.definesRegister(AArch64::ZT0, RI) && "should define ZT0!");
1094 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::ZERO_T))
1095 .addDef(AArch64::ZT0);
1096 }
1097
1098 MI.eraseFromParent();
1099 return &EndBB;
1100}
1101
1102MachineBasicBlock *
1103AArch64ExpandPseudo::expandCondSMToggle(MachineBasicBlock &MBB,
1105 MachineInstr &MI = *MBBI;
1106 // In the case of a smstart/smstop before a unreachable, just remove the pseudo.
1107 // Exception handling code generated by Clang may introduce unreachables and it
1108 // seems unnecessary to restore pstate.sm when that happens. Note that it is
1109 // not just an optimisation, the code below expects a successor instruction/block
1110 // in order to split the block at MBBI.
1111 if (std::next(MBBI) == MBB.end() &&
1112 MI.getParent()->successors().begin() ==
1113 MI.getParent()->successors().end()) {
1114 MI.eraseFromParent();
1115 return &MBB;
1116 }
1117
1118 // Expand the pseudo into smstart or smstop instruction. The pseudo has the
1119 // following operands:
1120 //
1121 // MSRpstatePseudo <za|sm|both>, <0|1>, condition[, pstate.sm], <regmask>
1122 //
1123 // The pseudo is expanded into a conditional smstart/smstop, with a
1124 // check if pstate.sm (register) equals the expected value, and if not,
1125 // invokes the smstart/smstop.
1126 //
1127 // As an example, the following block contains a normal call from a
1128 // streaming-compatible function:
1129 //
1130 // OrigBB:
1131 // MSRpstatePseudo 3, 0, IfCallerIsStreaming, %0, <regmask> <- Cond SMSTOP
1132 // bl @normal_callee
1133 // MSRpstatePseudo 3, 1, IfCallerIsStreaming, %0, <regmask> <- Cond SMSTART
1134 //
1135 // ...which will be transformed into:
1136 //
1137 // OrigBB:
1138 // TBNZx %0:gpr64, 0, SMBB
1139 // b EndBB
1140 //
1141 // SMBB:
1142 // MSRpstatesvcrImm1 3, 0, <regmask> <- SMSTOP
1143 //
1144 // EndBB:
1145 // bl @normal_callee
1146 // MSRcond_pstatesvcrImm1 3, 1, <regmask> <- SMSTART
1147 //
1148 DebugLoc DL = MI.getDebugLoc();
1149
1150 // Create the conditional branch based on the third operand of the
1151 // instruction, which tells us if we are wrapping a normal or streaming
1152 // function.
1153 // We test the live value of pstate.sm and toggle pstate.sm if this is not the
1154 // expected value for the callee (0 for a normal callee and 1 for a streaming
1155 // callee).
1156 unsigned Opc;
1157 switch (MI.getOperand(2).getImm()) {
1158 case AArch64SME::Always:
1159 llvm_unreachable("Should have matched to instruction directly");
1161 Opc = AArch64::TBNZW;
1162 break;
1164 Opc = AArch64::TBZW;
1165 break;
1166 }
1167 auto PStateSM = MI.getOperand(3).getReg();
1169 unsigned SMReg32 = TRI->getSubReg(PStateSM, AArch64::sub_32);
1170 MachineInstrBuilder Tbx =
1171 BuildMI(MBB, MBBI, DL, TII->get(Opc)).addReg(SMReg32).addImm(0);
1172
1173 auto [CondBB, EndBB] = expandConditionalPseudo(MBB, MBBI, DL, Tbx);
1174 // Create the SMSTART/SMSTOP (MSRpstatesvcrImm1) instruction in SMBB.
1175 MachineInstrBuilder MIB = BuildMI(CondBB, CondBB.back(), MI.getDebugLoc(),
1176 TII->get(AArch64::MSRpstatesvcrImm1));
1177 // Copy all but the second and third operands of MSRcond_pstatesvcrImm1 (as
1178 // these contain the CopyFromReg for the first argument and the flag to
1179 // indicate whether the callee is streaming or normal).
1180 MIB.add(MI.getOperand(0));
1181 MIB.add(MI.getOperand(1));
1182 for (unsigned i = 4; i < MI.getNumOperands(); ++i)
1183 MIB.add(MI.getOperand(i));
1184
1185 MI.eraseFromParent();
1186 return &EndBB;
1187}
1188
1189bool AArch64ExpandPseudo::expandMultiVecPseudo(
1190 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
1191 TargetRegisterClass ContiguousClass, TargetRegisterClass StridedClass,
1192 unsigned ContiguousOp, unsigned StridedOpc) {
1193 MachineInstr &MI = *MBBI;
1194 Register Tuple = MI.getOperand(0).getReg();
1195
1196 auto ContiguousRange = ContiguousClass.getRegisters();
1197 auto StridedRange = StridedClass.getRegisters();
1198 unsigned Opc;
1199 if (llvm::is_contained(ContiguousRange, Tuple.asMCReg())) {
1200 Opc = ContiguousOp;
1201 } else if (llvm::is_contained(StridedRange, Tuple.asMCReg())) {
1202 Opc = StridedOpc;
1203 } else
1204 llvm_unreachable("Cannot expand Multi-Vector pseudo");
1205
1206 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc))
1207 .add(MI.getOperand(0))
1208 .add(MI.getOperand(1))
1209 .add(MI.getOperand(2))
1210 .add(MI.getOperand(3));
1211 transferImpOps(MI, MIB, MIB);
1212 MI.eraseFromParent();
1213 return true;
1214}
1215
1216bool AArch64ExpandPseudo::expandFormTuplePseudo(
1217 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
1218 MachineBasicBlock::iterator &NextMBBI, unsigned Size) {
1219 assert((Size == 2 || Size == 4) && "Invalid Tuple Size");
1220 MachineInstr &MI = *MBBI;
1221 Register ReturnTuple = MI.getOperand(0).getReg();
1222
1223 const TargetRegisterInfo *TRI =
1225 for (unsigned I = 0; I < Size; ++I) {
1226 Register FormTupleOpReg = MI.getOperand(I + 1).getReg();
1227 Register ReturnTupleSubReg =
1228 TRI->getSubReg(ReturnTuple, AArch64::zsub0 + I);
1229 // Add copies to ensure the subregisters remain in the correct order
1230 // for any contigious operation they are used by.
1231 if (FormTupleOpReg != ReturnTupleSubReg)
1232 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ORR_ZZZ))
1233 .addReg(ReturnTupleSubReg, RegState::Define)
1234 .addReg(FormTupleOpReg)
1235 .addReg(FormTupleOpReg);
1236 }
1237
1238 MI.eraseFromParent();
1239 return true;
1240}
1241
1242/// If MBBI references a pseudo instruction that should be expanded here,
1243/// do the expansion and return true. Otherwise return false.
1244bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
1246 MachineBasicBlock::iterator &NextMBBI) {
1247 MachineInstr &MI = *MBBI;
1248 unsigned Opcode = MI.getOpcode();
1249
1250 // Check if we can expand the destructive op
1251 int OrigInstr = AArch64::getSVEPseudoMap(MI.getOpcode());
1252 if (OrigInstr != -1) {
1253 auto &Orig = TII->get(OrigInstr);
1254 if ((Orig.TSFlags & AArch64::DestructiveInstTypeMask) !=
1256 return expand_DestructiveOp(MI, MBB, MBBI);
1257 }
1258 }
1259
1260 switch (Opcode) {
1261 default:
1262 break;
1263
1264 case AArch64::BSPv8i8:
1265 case AArch64::BSPv16i8: {
1266 Register DstReg = MI.getOperand(0).getReg();
1267 if (DstReg == MI.getOperand(3).getReg()) {
1268 // Expand to BIT
1269 auto I = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1270 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BITv8i8
1271 : AArch64::BITv16i8))
1272 .add(MI.getOperand(0))
1273 .add(MI.getOperand(3))
1274 .add(MI.getOperand(2))
1275 .add(MI.getOperand(1));
1276 transferImpOps(MI, I, I);
1277 } else if (DstReg == MI.getOperand(2).getReg()) {
1278 // Expand to BIF
1279 auto I = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1280 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BIFv8i8
1281 : AArch64::BIFv16i8))
1282 .add(MI.getOperand(0))
1283 .add(MI.getOperand(2))
1284 .add(MI.getOperand(3))
1285 .add(MI.getOperand(1));
1286 transferImpOps(MI, I, I);
1287 } else {
1288 // Expand to BSL, use additional move if required
1289 if (DstReg == MI.getOperand(1).getReg()) {
1290 auto I =
1291 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1292 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BSLv8i8
1293 : AArch64::BSLv16i8))
1294 .add(MI.getOperand(0))
1295 .add(MI.getOperand(1))
1296 .add(MI.getOperand(2))
1297 .add(MI.getOperand(3));
1298 transferImpOps(MI, I, I);
1299 } else {
1300 unsigned RegState =
1301 getRenamableRegState(MI.getOperand(1).isRenamable()) |
1303 MI.getOperand(1).isKill() &&
1304 MI.getOperand(1).getReg() != MI.getOperand(2).getReg() &&
1305 MI.getOperand(1).getReg() != MI.getOperand(3).getReg());
1306 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1307 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::ORRv8i8
1308 : AArch64::ORRv16i8))
1309 .addReg(DstReg,
1311 getRenamableRegState(MI.getOperand(0).isRenamable()))
1312 .addReg(MI.getOperand(1).getReg(), RegState)
1313 .addReg(MI.getOperand(1).getReg(), RegState);
1314 auto I2 =
1315 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1316 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BSLv8i8
1317 : AArch64::BSLv16i8))
1318 .add(MI.getOperand(0))
1319 .addReg(DstReg,
1321 MI.getOperand(0).isRenamable()))
1322 .add(MI.getOperand(2))
1323 .add(MI.getOperand(3));
1324 transferImpOps(MI, I2, I2);
1325 }
1326 }
1327 MI.eraseFromParent();
1328 return true;
1329 }
1330
1331 case AArch64::ADDWrr:
1332 case AArch64::SUBWrr:
1333 case AArch64::ADDXrr:
1334 case AArch64::SUBXrr:
1335 case AArch64::ADDSWrr:
1336 case AArch64::SUBSWrr:
1337 case AArch64::ADDSXrr:
1338 case AArch64::SUBSXrr:
1339 case AArch64::ANDWrr:
1340 case AArch64::ANDXrr:
1341 case AArch64::BICWrr:
1342 case AArch64::BICXrr:
1343 case AArch64::ANDSWrr:
1344 case AArch64::ANDSXrr:
1345 case AArch64::BICSWrr:
1346 case AArch64::BICSXrr:
1347 case AArch64::EONWrr:
1348 case AArch64::EONXrr:
1349 case AArch64::EORWrr:
1350 case AArch64::EORXrr:
1351 case AArch64::ORNWrr:
1352 case AArch64::ORNXrr:
1353 case AArch64::ORRWrr:
1354 case AArch64::ORRXrr: {
1355 unsigned Opcode;
1356 switch (MI.getOpcode()) {
1357 default:
1358 return false;
1359 case AArch64::ADDWrr: Opcode = AArch64::ADDWrs; break;
1360 case AArch64::SUBWrr: Opcode = AArch64::SUBWrs; break;
1361 case AArch64::ADDXrr: Opcode = AArch64::ADDXrs; break;
1362 case AArch64::SUBXrr: Opcode = AArch64::SUBXrs; break;
1363 case AArch64::ADDSWrr: Opcode = AArch64::ADDSWrs; break;
1364 case AArch64::SUBSWrr: Opcode = AArch64::SUBSWrs; break;
1365 case AArch64::ADDSXrr: Opcode = AArch64::ADDSXrs; break;
1366 case AArch64::SUBSXrr: Opcode = AArch64::SUBSXrs; break;
1367 case AArch64::ANDWrr: Opcode = AArch64::ANDWrs; break;
1368 case AArch64::ANDXrr: Opcode = AArch64::ANDXrs; break;
1369 case AArch64::BICWrr: Opcode = AArch64::BICWrs; break;
1370 case AArch64::BICXrr: Opcode = AArch64::BICXrs; break;
1371 case AArch64::ANDSWrr: Opcode = AArch64::ANDSWrs; break;
1372 case AArch64::ANDSXrr: Opcode = AArch64::ANDSXrs; break;
1373 case AArch64::BICSWrr: Opcode = AArch64::BICSWrs; break;
1374 case AArch64::BICSXrr: Opcode = AArch64::BICSXrs; break;
1375 case AArch64::EONWrr: Opcode = AArch64::EONWrs; break;
1376 case AArch64::EONXrr: Opcode = AArch64::EONXrs; break;
1377 case AArch64::EORWrr: Opcode = AArch64::EORWrs; break;
1378 case AArch64::EORXrr: Opcode = AArch64::EORXrs; break;
1379 case AArch64::ORNWrr: Opcode = AArch64::ORNWrs; break;
1380 case AArch64::ORNXrr: Opcode = AArch64::ORNXrs; break;
1381 case AArch64::ORRWrr: Opcode = AArch64::ORRWrs; break;
1382 case AArch64::ORRXrr: Opcode = AArch64::ORRXrs; break;
1383 }
1384 MachineFunction &MF = *MBB.getParent();
1385 // Try to create new inst without implicit operands added.
1386 MachineInstr *NewMI = MF.CreateMachineInstr(
1387 TII->get(Opcode), MI.getDebugLoc(), /*NoImplicit=*/true);
1388 MBB.insert(MBBI, NewMI);
1389 MachineInstrBuilder MIB1(MF, NewMI);
1390 MIB1->setPCSections(MF, MI.getPCSections());
1391 MIB1.addReg(MI.getOperand(0).getReg(), RegState::Define)
1392 .add(MI.getOperand(1))
1393 .add(MI.getOperand(2))
1395 transferImpOps(MI, MIB1, MIB1);
1396 if (auto DebugNumber = MI.peekDebugInstrNum())
1397 NewMI->setDebugInstrNum(DebugNumber);
1398 MI.eraseFromParent();
1399 return true;
1400 }
1401
1402 case AArch64::LOADgot: {
1403 MachineFunction *MF = MBB.getParent();
1404 Register DstReg = MI.getOperand(0).getReg();
1405 const MachineOperand &MO1 = MI.getOperand(1);
1406 unsigned Flags = MO1.getTargetFlags();
1407
1408 if (MF->getTarget().getCodeModel() == CodeModel::Tiny) {
1409 // Tiny codemodel expand to LDR
1410 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1411 TII->get(AArch64::LDRXl), DstReg);
1412
1413 if (MO1.isGlobal()) {
1414 MIB.addGlobalAddress(MO1.getGlobal(), 0, Flags);
1415 } else if (MO1.isSymbol()) {
1416 MIB.addExternalSymbol(MO1.getSymbolName(), Flags);
1417 } else {
1418 assert(MO1.isCPI() &&
1419 "Only expect globals, externalsymbols, or constant pools");
1420 MIB.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(), Flags);
1421 }
1422 } else {
1423 // Small codemodel expand into ADRP + LDR.
1424 MachineFunction &MF = *MI.getParent()->getParent();
1425 DebugLoc DL = MI.getDebugLoc();
1426 MachineInstrBuilder MIB1 =
1427 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg);
1428
1429 MachineInstrBuilder MIB2;
1430 if (MF.getSubtarget<AArch64Subtarget>().isTargetILP32()) {
1432 unsigned Reg32 = TRI->getSubReg(DstReg, AArch64::sub_32);
1433 unsigned DstFlags = MI.getOperand(0).getTargetFlags();
1434 MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::LDRWui))
1435 .addDef(Reg32)
1436 .addReg(DstReg, RegState::Kill)
1437 .addReg(DstReg, DstFlags | RegState::Implicit);
1438 } else {
1439 Register DstReg = MI.getOperand(0).getReg();
1440 MIB2 = BuildMI(MBB, MBBI, DL, TII->get(AArch64::LDRXui))
1441 .add(MI.getOperand(0))
1442 .addUse(DstReg, RegState::Kill);
1443 }
1444
1445 if (MO1.isGlobal()) {
1446 MIB1.addGlobalAddress(MO1.getGlobal(), 0, Flags | AArch64II::MO_PAGE);
1447 MIB2.addGlobalAddress(MO1.getGlobal(), 0,
1449 } else if (MO1.isSymbol()) {
1451 MIB2.addExternalSymbol(MO1.getSymbolName(), Flags |
1454 } else {
1455 assert(MO1.isCPI() &&
1456 "Only expect globals, externalsymbols, or constant pools");
1457 MIB1.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(),
1458 Flags | AArch64II::MO_PAGE);
1459 MIB2.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(),
1460 Flags | AArch64II::MO_PAGEOFF |
1462 }
1463
1464 // If the LOADgot instruction has a debug-instr-number, annotate the
1465 // LDRWui instruction that it is expanded to with the same
1466 // debug-instr-number to preserve debug information.
1467 if (MI.peekDebugInstrNum() != 0)
1468 MIB2->setDebugInstrNum(MI.peekDebugInstrNum());
1469 transferImpOps(MI, MIB1, MIB2);
1470 }
1471 MI.eraseFromParent();
1472 return true;
1473 }
1474 case AArch64::MOVaddrBA: {
1475 MachineFunction &MF = *MI.getParent()->getParent();
1476 if (MF.getSubtarget<AArch64Subtarget>().isTargetMachO()) {
1477 // blockaddress expressions have to come from a constant pool because the
1478 // largest addend (and hence offset within a function) allowed for ADRP is
1479 // only 8MB.
1480 const BlockAddress *BA = MI.getOperand(1).getBlockAddress();
1481 assert(MI.getOperand(1).getOffset() == 0 && "unexpected offset");
1482
1483 MachineConstantPool *MCP = MF.getConstantPool();
1484 unsigned CPIdx = MCP->getConstantPoolIndex(BA, Align(8));
1485
1486 Register DstReg = MI.getOperand(0).getReg();
1487 auto MIB1 =
1488 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg)
1490 auto MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1491 TII->get(AArch64::LDRXui), DstReg)
1492 .addUse(DstReg)
1495 transferImpOps(MI, MIB1, MIB2);
1496 MI.eraseFromParent();
1497 return true;
1498 }
1499 }
1500 [[fallthrough]];
1501 case AArch64::MOVaddr:
1502 case AArch64::MOVaddrJT:
1503 case AArch64::MOVaddrCP:
1504 case AArch64::MOVaddrTLS:
1505 case AArch64::MOVaddrEXT: {
1506 // Expand into ADRP + ADD.
1507 Register DstReg = MI.getOperand(0).getReg();
1508 assert(DstReg != AArch64::XZR);
1509 MachineInstrBuilder MIB1 =
1510 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg)
1511 .add(MI.getOperand(1));
1512
1513 if (MI.getOperand(1).getTargetFlags() & AArch64II::MO_TAGGED) {
1514 // MO_TAGGED on the page indicates a tagged address. Set the tag now.
1515 // We do so by creating a MOVK that sets bits 48-63 of the register to
1516 // (global address + 0x100000000 - PC) >> 48. This assumes that we're in
1517 // the small code model so we can assume a binary size of <= 4GB, which
1518 // makes the untagged PC relative offset positive. The binary must also be
1519 // loaded into address range [0, 2^48). Both of these properties need to
1520 // be ensured at runtime when using tagged addresses.
1521 auto Tag = MI.getOperand(1);
1522 Tag.setTargetFlags(AArch64II::MO_PREL | AArch64II::MO_G3);
1523 Tag.setOffset(0x100000000);
1524 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MOVKXi), DstReg)
1525 .addReg(DstReg)
1526 .add(Tag)
1527 .addImm(48);
1528 }
1529
1530 MachineInstrBuilder MIB2 =
1531 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADDXri))
1532 .add(MI.getOperand(0))
1533 .addReg(DstReg)
1534 .add(MI.getOperand(2))
1535 .addImm(0);
1536
1537 transferImpOps(MI, MIB1, MIB2);
1538 MI.eraseFromParent();
1539 return true;
1540 }
1541 case AArch64::ADDlowTLS:
1542 // Produce a plain ADD
1543 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADDXri))
1544 .add(MI.getOperand(0))
1545 .add(MI.getOperand(1))
1546 .add(MI.getOperand(2))
1547 .addImm(0);
1548 MI.eraseFromParent();
1549 return true;
1550
1551 case AArch64::MOVbaseTLS: {
1552 Register DstReg = MI.getOperand(0).getReg();
1553 auto SysReg = AArch64SysReg::TPIDR_EL0;
1554 MachineFunction *MF = MBB.getParent();
1555 if (MF->getSubtarget<AArch64Subtarget>().useEL3ForTP())
1556 SysReg = AArch64SysReg::TPIDR_EL3;
1557 else if (MF->getSubtarget<AArch64Subtarget>().useEL2ForTP())
1558 SysReg = AArch64SysReg::TPIDR_EL2;
1559 else if (MF->getSubtarget<AArch64Subtarget>().useEL1ForTP())
1560 SysReg = AArch64SysReg::TPIDR_EL1;
1561 else if (MF->getSubtarget<AArch64Subtarget>().useROEL0ForTP())
1562 SysReg = AArch64SysReg::TPIDRRO_EL0;
1563 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MRS), DstReg)
1564 .addImm(SysReg);
1565 MI.eraseFromParent();
1566 return true;
1567 }
1568
1569 case AArch64::MOVi32imm:
1570 return expandMOVImm(MBB, MBBI, 32);
1571 case AArch64::MOVi64imm:
1572 return expandMOVImm(MBB, MBBI, 64);
1573 case AArch64::RET_ReallyLR: {
1574 // Hiding the LR use with RET_ReallyLR may lead to extra kills in the
1575 // function and missing live-ins. We are fine in practice because callee
1576 // saved register handling ensures the register value is restored before
1577 // RET, but we need the undef flag here to appease the MachineVerifier
1578 // liveness checks.
1579 MachineInstrBuilder MIB =
1580 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::RET))
1581 .addReg(AArch64::LR, RegState::Undef);
1582 transferImpOps(MI, MIB, MIB);
1583 MI.eraseFromParent();
1584 return true;
1585 }
1586 case AArch64::CMP_SWAP_8:
1587 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRB, AArch64::STLXRB,
1588 AArch64::SUBSWrx,
1590 AArch64::WZR, NextMBBI);
1591 case AArch64::CMP_SWAP_16:
1592 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRH, AArch64::STLXRH,
1593 AArch64::SUBSWrx,
1595 AArch64::WZR, NextMBBI);
1596 case AArch64::CMP_SWAP_32:
1597 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRW, AArch64::STLXRW,
1598 AArch64::SUBSWrs,
1600 AArch64::WZR, NextMBBI);
1601 case AArch64::CMP_SWAP_64:
1602 return expandCMP_SWAP(MBB, MBBI,
1603 AArch64::LDAXRX, AArch64::STLXRX, AArch64::SUBSXrs,
1605 AArch64::XZR, NextMBBI);
1606 case AArch64::CMP_SWAP_128:
1607 case AArch64::CMP_SWAP_128_RELEASE:
1608 case AArch64::CMP_SWAP_128_ACQUIRE:
1609 case AArch64::CMP_SWAP_128_MONOTONIC:
1610 return expandCMP_SWAP_128(MBB, MBBI, NextMBBI);
1611
1612 case AArch64::AESMCrrTied:
1613 case AArch64::AESIMCrrTied: {
1614 MachineInstrBuilder MIB =
1615 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1616 TII->get(Opcode == AArch64::AESMCrrTied ? AArch64::AESMCrr :
1617 AArch64::AESIMCrr))
1618 .add(MI.getOperand(0))
1619 .add(MI.getOperand(1));
1620 transferImpOps(MI, MIB, MIB);
1621 MI.eraseFromParent();
1622 return true;
1623 }
1624 case AArch64::IRGstack: {
1625 MachineFunction &MF = *MBB.getParent();
1626 const AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
1627 const AArch64FrameLowering *TFI =
1628 MF.getSubtarget<AArch64Subtarget>().getFrameLowering();
1629
1630 // IRG does not allow immediate offset. getTaggedBasePointerOffset should
1631 // almost always point to SP-after-prologue; if not, emit a longer
1632 // instruction sequence.
1633 int BaseOffset = -AFI->getTaggedBasePointerOffset();
1634 Register FrameReg;
1635 StackOffset FrameRegOffset = TFI->resolveFrameOffsetReference(
1636 MF, BaseOffset, false /*isFixed*/, TargetStackID::Default /*StackID*/,
1637 FrameReg,
1638 /*PreferFP=*/false,
1639 /*ForSimm=*/true);
1640 Register SrcReg = FrameReg;
1641 if (FrameRegOffset) {
1642 // Use output register as temporary.
1643 SrcReg = MI.getOperand(0).getReg();
1644 emitFrameOffset(MBB, &MI, MI.getDebugLoc(), SrcReg, FrameReg,
1645 FrameRegOffset, TII);
1646 }
1647 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::IRG))
1648 .add(MI.getOperand(0))
1649 .addUse(SrcReg)
1650 .add(MI.getOperand(2));
1651 MI.eraseFromParent();
1652 return true;
1653 }
1654 case AArch64::TAGPstack: {
1655 int64_t Offset = MI.getOperand(2).getImm();
1656 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1657 TII->get(Offset >= 0 ? AArch64::ADDG : AArch64::SUBG))
1658 .add(MI.getOperand(0))
1659 .add(MI.getOperand(1))
1660 .addImm(std::abs(Offset))
1661 .add(MI.getOperand(4));
1662 MI.eraseFromParent();
1663 return true;
1664 }
1665 case AArch64::STGloop_wback:
1666 case AArch64::STZGloop_wback:
1667 return expandSetTagLoop(MBB, MBBI, NextMBBI);
1668 case AArch64::STGloop:
1669 case AArch64::STZGloop:
1671 "Non-writeback variants of STGloop / STZGloop should not "
1672 "survive past PrologEpilogInserter.");
1673 case AArch64::STR_ZZZZXI:
1674 case AArch64::STR_ZZZZXI_STRIDED_CONTIGUOUS:
1675 return expandSVESpillFill(MBB, MBBI, AArch64::STR_ZXI, 4);
1676 case AArch64::STR_ZZZXI:
1677 return expandSVESpillFill(MBB, MBBI, AArch64::STR_ZXI, 3);
1678 case AArch64::STR_ZZXI:
1679 case AArch64::STR_ZZXI_STRIDED_CONTIGUOUS:
1680 return expandSVESpillFill(MBB, MBBI, AArch64::STR_ZXI, 2);
1681 case AArch64::STR_PPXI:
1682 return expandSVESpillFill(MBB, MBBI, AArch64::STR_PXI, 2);
1683 case AArch64::LDR_ZZZZXI:
1684 case AArch64::LDR_ZZZZXI_STRIDED_CONTIGUOUS:
1685 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_ZXI, 4);
1686 case AArch64::LDR_ZZZXI:
1687 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_ZXI, 3);
1688 case AArch64::LDR_ZZXI:
1689 case AArch64::LDR_ZZXI_STRIDED_CONTIGUOUS:
1690 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_ZXI, 2);
1691 case AArch64::LDR_PPXI:
1692 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_PXI, 2);
1693 case AArch64::BLR_RVMARKER:
1694 case AArch64::BLRA_RVMARKER:
1695 return expandCALL_RVMARKER(MBB, MBBI);
1696 case AArch64::BLR_BTI:
1697 return expandCALL_BTI(MBB, MBBI);
1698 case AArch64::StoreSwiftAsyncContext:
1699 return expandStoreSwiftAsyncContext(MBB, MBBI);
1700 case AArch64::RestoreZAPseudo:
1701 case AArch64::CommitZASavePseudo:
1702 case AArch64::MSRpstatePseudo: {
1703 auto *NewMBB = [&] {
1704 switch (Opcode) {
1705 case AArch64::RestoreZAPseudo:
1706 return expandRestoreZASave(MBB, MBBI);
1707 case AArch64::CommitZASavePseudo:
1708 return expandCommitZASave(MBB, MBBI);
1709 case AArch64::MSRpstatePseudo:
1710 return expandCondSMToggle(MBB, MBBI);
1711 default:
1712 llvm_unreachable("Unexpected conditional pseudo!");
1713 }
1714 }();
1715 if (NewMBB != &MBB)
1716 NextMBBI = MBB.end(); // The NextMBBI iterator is invalidated.
1717 return true;
1718 }
1719 case AArch64::InOutZAUsePseudo:
1720 case AArch64::RequiresZASavePseudo:
1721 case AArch64::RequiresZT0SavePseudo:
1722 case AArch64::SMEStateAllocPseudo:
1723 case AArch64::COALESCER_BARRIER_FPR16:
1724 case AArch64::COALESCER_BARRIER_FPR32:
1725 case AArch64::COALESCER_BARRIER_FPR64:
1726 case AArch64::COALESCER_BARRIER_FPR128:
1727 MI.eraseFromParent();
1728 return true;
1729 case AArch64::LD1B_2Z_IMM_PSEUDO:
1730 return expandMultiVecPseudo(
1731 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1732 AArch64::LD1B_2Z_IMM, AArch64::LD1B_2Z_STRIDED_IMM);
1733 case AArch64::LD1H_2Z_IMM_PSEUDO:
1734 return expandMultiVecPseudo(
1735 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1736 AArch64::LD1H_2Z_IMM, AArch64::LD1H_2Z_STRIDED_IMM);
1737 case AArch64::LD1W_2Z_IMM_PSEUDO:
1738 return expandMultiVecPseudo(
1739 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1740 AArch64::LD1W_2Z_IMM, AArch64::LD1W_2Z_STRIDED_IMM);
1741 case AArch64::LD1D_2Z_IMM_PSEUDO:
1742 return expandMultiVecPseudo(
1743 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1744 AArch64::LD1D_2Z_IMM, AArch64::LD1D_2Z_STRIDED_IMM);
1745 case AArch64::LDNT1B_2Z_IMM_PSEUDO:
1746 return expandMultiVecPseudo(
1747 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1748 AArch64::LDNT1B_2Z_IMM, AArch64::LDNT1B_2Z_STRIDED_IMM);
1749 case AArch64::LDNT1H_2Z_IMM_PSEUDO:
1750 return expandMultiVecPseudo(
1751 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1752 AArch64::LDNT1H_2Z_IMM, AArch64::LDNT1H_2Z_STRIDED_IMM);
1753 case AArch64::LDNT1W_2Z_IMM_PSEUDO:
1754 return expandMultiVecPseudo(
1755 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1756 AArch64::LDNT1W_2Z_IMM, AArch64::LDNT1W_2Z_STRIDED_IMM);
1757 case AArch64::LDNT1D_2Z_IMM_PSEUDO:
1758 return expandMultiVecPseudo(
1759 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1760 AArch64::LDNT1D_2Z_IMM, AArch64::LDNT1D_2Z_STRIDED_IMM);
1761 case AArch64::LD1B_2Z_PSEUDO:
1762 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1763 AArch64::ZPR2StridedRegClass, AArch64::LD1B_2Z,
1764 AArch64::LD1B_2Z_STRIDED);
1765 case AArch64::LD1H_2Z_PSEUDO:
1766 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1767 AArch64::ZPR2StridedRegClass, AArch64::LD1H_2Z,
1768 AArch64::LD1H_2Z_STRIDED);
1769 case AArch64::LD1W_2Z_PSEUDO:
1770 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1771 AArch64::ZPR2StridedRegClass, AArch64::LD1W_2Z,
1772 AArch64::LD1W_2Z_STRIDED);
1773 case AArch64::LD1D_2Z_PSEUDO:
1774 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1775 AArch64::ZPR2StridedRegClass, AArch64::LD1D_2Z,
1776 AArch64::LD1D_2Z_STRIDED);
1777 case AArch64::LDNT1B_2Z_PSEUDO:
1778 return expandMultiVecPseudo(
1779 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1780 AArch64::LDNT1B_2Z, AArch64::LDNT1B_2Z_STRIDED);
1781 case AArch64::LDNT1H_2Z_PSEUDO:
1782 return expandMultiVecPseudo(
1783 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1784 AArch64::LDNT1H_2Z, AArch64::LDNT1H_2Z_STRIDED);
1785 case AArch64::LDNT1W_2Z_PSEUDO:
1786 return expandMultiVecPseudo(
1787 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1788 AArch64::LDNT1W_2Z, AArch64::LDNT1W_2Z_STRIDED);
1789 case AArch64::LDNT1D_2Z_PSEUDO:
1790 return expandMultiVecPseudo(
1791 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1792 AArch64::LDNT1D_2Z, AArch64::LDNT1D_2Z_STRIDED);
1793 case AArch64::LD1B_4Z_IMM_PSEUDO:
1794 return expandMultiVecPseudo(
1795 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1796 AArch64::LD1B_4Z_IMM, AArch64::LD1B_4Z_STRIDED_IMM);
1797 case AArch64::LD1H_4Z_IMM_PSEUDO:
1798 return expandMultiVecPseudo(
1799 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1800 AArch64::LD1H_4Z_IMM, AArch64::LD1H_4Z_STRIDED_IMM);
1801 case AArch64::LD1W_4Z_IMM_PSEUDO:
1802 return expandMultiVecPseudo(
1803 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1804 AArch64::LD1W_4Z_IMM, AArch64::LD1W_4Z_STRIDED_IMM);
1805 case AArch64::LD1D_4Z_IMM_PSEUDO:
1806 return expandMultiVecPseudo(
1807 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1808 AArch64::LD1D_4Z_IMM, AArch64::LD1D_4Z_STRIDED_IMM);
1809 case AArch64::LDNT1B_4Z_IMM_PSEUDO:
1810 return expandMultiVecPseudo(
1811 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1812 AArch64::LDNT1B_4Z_IMM, AArch64::LDNT1B_4Z_STRIDED_IMM);
1813 case AArch64::LDNT1H_4Z_IMM_PSEUDO:
1814 return expandMultiVecPseudo(
1815 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1816 AArch64::LDNT1H_4Z_IMM, AArch64::LDNT1H_4Z_STRIDED_IMM);
1817 case AArch64::LDNT1W_4Z_IMM_PSEUDO:
1818 return expandMultiVecPseudo(
1819 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1820 AArch64::LDNT1W_4Z_IMM, AArch64::LDNT1W_4Z_STRIDED_IMM);
1821 case AArch64::LDNT1D_4Z_IMM_PSEUDO:
1822 return expandMultiVecPseudo(
1823 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1824 AArch64::LDNT1D_4Z_IMM, AArch64::LDNT1D_4Z_STRIDED_IMM);
1825 case AArch64::LD1B_4Z_PSEUDO:
1826 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1827 AArch64::ZPR4StridedRegClass, AArch64::LD1B_4Z,
1828 AArch64::LD1B_4Z_STRIDED);
1829 case AArch64::LD1H_4Z_PSEUDO:
1830 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1831 AArch64::ZPR4StridedRegClass, AArch64::LD1H_4Z,
1832 AArch64::LD1H_4Z_STRIDED);
1833 case AArch64::LD1W_4Z_PSEUDO:
1834 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1835 AArch64::ZPR4StridedRegClass, AArch64::LD1W_4Z,
1836 AArch64::LD1W_4Z_STRIDED);
1837 case AArch64::LD1D_4Z_PSEUDO:
1838 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1839 AArch64::ZPR4StridedRegClass, AArch64::LD1D_4Z,
1840 AArch64::LD1D_4Z_STRIDED);
1841 case AArch64::LDNT1B_4Z_PSEUDO:
1842 return expandMultiVecPseudo(
1843 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1844 AArch64::LDNT1B_4Z, AArch64::LDNT1B_4Z_STRIDED);
1845 case AArch64::LDNT1H_4Z_PSEUDO:
1846 return expandMultiVecPseudo(
1847 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1848 AArch64::LDNT1H_4Z, AArch64::LDNT1H_4Z_STRIDED);
1849 case AArch64::LDNT1W_4Z_PSEUDO:
1850 return expandMultiVecPseudo(
1851 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1852 AArch64::LDNT1W_4Z, AArch64::LDNT1W_4Z_STRIDED);
1853 case AArch64::LDNT1D_4Z_PSEUDO:
1854 return expandMultiVecPseudo(
1855 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1856 AArch64::LDNT1D_4Z, AArch64::LDNT1D_4Z_STRIDED);
1857 case AArch64::FORM_TRANSPOSED_REG_TUPLE_X2_PSEUDO:
1858 return expandFormTuplePseudo(MBB, MBBI, NextMBBI, 2);
1859 case AArch64::FORM_TRANSPOSED_REG_TUPLE_X4_PSEUDO:
1860 return expandFormTuplePseudo(MBB, MBBI, NextMBBI, 4);
1861 }
1862 return false;
1863}
1864
1865/// Iterate over the instructions in basic block MBB and expand any
1866/// pseudo instructions. Return true if anything was modified.
1867bool AArch64ExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
1868 bool Modified = false;
1869
1871 while (MBBI != E) {
1872 MachineBasicBlock::iterator NMBBI = std::next(MBBI);
1873 Modified |= expandMI(MBB, MBBI, NMBBI);
1874 MBBI = NMBBI;
1875 }
1876
1877 return Modified;
1878}
1879
1880bool AArch64ExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
1881 TII = MF.getSubtarget<AArch64Subtarget>().getInstrInfo();
1882
1883 bool Modified = false;
1884 for (auto &MBB : MF)
1885 Modified |= expandMBB(MBB);
1886 return Modified;
1887}
1888
1889/// Returns an instance of the pseudo instruction expansion pass.
1891 return new AArch64ExpandPseudo();
1892}
#define AARCH64_EXPAND_PSEUDO_NAME
MachineInstrBuilder & UseMI
static MachineInstr * createCallWithOps(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const AArch64InstrInfo *TII, unsigned Opcode, ArrayRef< MachineOperand > ExplicitOps, unsigned RegMaskStartIdx)
static constexpr unsigned ZERO_ALL_ZA_MASK
static MachineInstr * createCall(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const AArch64InstrInfo *TII, MachineOperand &CallTarget, unsigned RegMaskStartIdx)
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define I(x, y, z)
Definition MD5.cpp:57
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:123
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
Describe properties that are true of each instruction in the target description file.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI MachineBasicBlock * splitAt(MachineInstr &SplitInst, bool UpdateLiveIns=true, LiveIntervals *LIS=nullptr)
Split a basic block into 2 pieces at SplitPoint.
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
MachineInstrBundleIterator< MachineInstr > iterator
unsigned getConstantPoolIndex(const Constant *C, Align Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void moveAdditionalCallInfo(const MachineInstr *Old, const MachineInstr *New)
Move the call site info from Old to \New call site info.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) 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
const MachineInstrBuilder & addReg(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
void setDebugInstrNum(unsigned Num)
Set instruction number of this MachineInstr.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
int64_t getOffset() const
Return the offset from the symbol in this operand.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:107
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
CodeModel::Model getCodeModel() const
Returns the code model.
ArrayRef< MCPhysReg > getRegisters() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
self_iterator getIterator()
Definition ilist_node.h:123
IteratorT end() const
IteratorT begin() const
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ MO_NC
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow.
@ MO_PAGEOFF
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page.
@ MO_PREL
MO_PREL - Indicates that the bits of the symbol operand represented by MO_G0 etc are PC relative.
@ MO_PAGE
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
@ MO_TAGGED
MO_TAGGED - With MO_PAGE, indicates that the page includes a memory tag in bits 56-63.
@ MO_G3
MO_G3 - A symbol operand with this flag (granule 3) represents the high 16-bits of a 64-bit address,...
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
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 ==...
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...
int getSVERevInstr(uint16_t Opcode)
int getSVEPseudoMap(uint16_t Opcode)
int getSVENonRevInstr(uint16_t Opcode)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Define
Register definition.
@ Kill
The last use of a register.
@ Undef
Value of the register doesn't matter.
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
Definition SFrame.h:77
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
constexpr unsigned getRenamableRegState(bool B)
@ Offset
Definition DWP.cpp:532
constexpr unsigned getDeadRegState(bool B)
LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr unsigned getKillRegState(bool B)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition APFloat.h:1626
Op::Description Desc
FunctionPass * createAArch64ExpandPseudoPass()
Returns an instance of the pseudo instruction expansion pass.
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, bool EmitCFAOffset=false, StackOffset InitialOffset={}, unsigned FrameReg=AArch64::SP)
emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg plus Offset.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
constexpr unsigned getDefRegState(bool B)
constexpr unsigned getUndefRegState(bool B)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1945
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
#define N