LLVM 22.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 uint64_t RenamableState =
141 MI.getOperand(0).isRenamable() ? RegState::Renamable : 0;
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 = MI.getOperand(DOPIdx).isUndef() ? RegState::Undef : 0;
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 = (Opc == AArch64::LDR_ZXI || Opc == AArch64::LDR_PXI)
797 : 0;
798 unsigned sub0 = (Opc == AArch64::LDR_ZXI || Opc == AArch64::STR_ZXI)
799 ? AArch64::zsub0
800 : AArch64::psub0;
801 const TargetRegisterInfo *TRI =
803 MachineInstr &MI = *MBBI;
804 for (unsigned Offset = 0; Offset < N; ++Offset) {
805 int ImmOffset = MI.getOperand(2).getImm() + Offset;
806 bool Kill = (Offset + 1 == N) ? MI.getOperand(1).isKill() : false;
807 assert(ImmOffset >= -256 && ImmOffset < 256 &&
808 "Immediate spill offset out of range");
809 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc))
810 .addReg(TRI->getSubReg(MI.getOperand(0).getReg(), sub0 + Offset),
811 RState)
812 .addReg(MI.getOperand(1).getReg(), getKillRegState(Kill))
813 .addImm(ImmOffset);
814 }
815 MI.eraseFromParent();
816 return true;
817}
818
819// Create a call with the passed opcode and explicit operands, copying over all
820// the implicit operands from *MBBI, starting at the regmask.
823 const AArch64InstrInfo *TII,
824 unsigned Opcode,
825 ArrayRef<MachineOperand> ExplicitOps,
826 unsigned RegMaskStartIdx) {
827 // Build the MI, with explicit operands first (including the call target).
828 MachineInstr *Call = BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII->get(Opcode))
829 .add(ExplicitOps)
830 .getInstr();
831
832 // Register arguments are added during ISel, but cannot be added as explicit
833 // operands of the branch as it expects to be B <target> which is only one
834 // operand. Instead they are implicit operands used by the branch.
835 while (!MBBI->getOperand(RegMaskStartIdx).isRegMask()) {
836 const MachineOperand &MOP = MBBI->getOperand(RegMaskStartIdx);
837 assert(MOP.isReg() && "can only add register operands");
839 MOP.getReg(), /*Def=*/false, /*Implicit=*/true, /*isKill=*/false,
840 /*isDead=*/false, /*isUndef=*/MOP.isUndef()));
841 RegMaskStartIdx++;
842 }
843 for (const MachineOperand &MO :
844 llvm::drop_begin(MBBI->operands(), RegMaskStartIdx))
845 Call->addOperand(MO);
846
847 return Call;
848}
849
850// Create a call to CallTarget, copying over all the operands from *MBBI,
851// starting at the regmask.
854 const AArch64InstrInfo *TII,
855 MachineOperand &CallTarget,
856 unsigned RegMaskStartIdx) {
857 unsigned Opc = CallTarget.isGlobal() ? AArch64::BL : AArch64::BLR;
858
859 assert((CallTarget.isGlobal() || CallTarget.isReg()) &&
860 "invalid operand for regular call");
861 return createCallWithOps(MBB, MBBI, TII, Opc, CallTarget, RegMaskStartIdx);
862}
863
864bool AArch64ExpandPseudo::expandCALL_RVMARKER(
865 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
866 // Expand CALL_RVMARKER pseudo to:
867 // - a branch to the call target, followed by
868 // - the special `mov x29, x29` marker, if necessary, and
869 // - another branch, to the runtime function
870 // Mark the sequence as bundle, to avoid passes moving other code in between.
871 MachineInstr &MI = *MBBI;
872 MachineOperand &RVTarget = MI.getOperand(0);
873 bool DoEmitMarker = MI.getOperand(1).getImm();
874 assert(RVTarget.isGlobal() && "invalid operand for attached call");
875
876 MachineInstr *OriginalCall = nullptr;
877
878 if (MI.getOpcode() == AArch64::BLRA_RVMARKER) {
879 // ptrauth call.
880 const MachineOperand &CallTarget = MI.getOperand(2);
881 const MachineOperand &Key = MI.getOperand(3);
882 const MachineOperand &IntDisc = MI.getOperand(4);
883 const MachineOperand &AddrDisc = MI.getOperand(5);
884
885 assert((Key.getImm() == AArch64PACKey::IA ||
886 Key.getImm() == AArch64PACKey::IB) &&
887 "Invalid auth call key");
888
889 MachineOperand Ops[] = {CallTarget, Key, IntDisc, AddrDisc};
890
891 OriginalCall = createCallWithOps(MBB, MBBI, TII, AArch64::BLRA, Ops,
892 /*RegMaskStartIdx=*/6);
893 } else {
894 assert(MI.getOpcode() == AArch64::BLR_RVMARKER && "unknown rvmarker MI");
895 OriginalCall = createCall(MBB, MBBI, TII, MI.getOperand(2),
896 // Regmask starts after the RV and call targets.
897 /*RegMaskStartIdx=*/3);
898 }
899
900 if (DoEmitMarker)
901 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ORRXrs))
902 .addReg(AArch64::FP, RegState::Define)
903 .addReg(AArch64::XZR)
904 .addReg(AArch64::FP)
905 .addImm(0);
906
907 auto *RVCall = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::BL))
908 .add(RVTarget)
909 .getInstr();
910
911 if (MI.shouldUpdateAdditionalCallInfo())
912 MBB.getParent()->moveAdditionalCallInfo(&MI, OriginalCall);
913
914 MI.eraseFromParent();
915 finalizeBundle(MBB, OriginalCall->getIterator(),
916 std::next(RVCall->getIterator()));
917 return true;
918}
919
920bool AArch64ExpandPseudo::expandCALL_BTI(MachineBasicBlock &MBB,
922 // Expand CALL_BTI pseudo to:
923 // - a branch to the call target
924 // - a BTI instruction
925 // Mark the sequence as a bundle, to avoid passes moving other code in
926 // between.
927 MachineInstr &MI = *MBBI;
928 MachineInstr *Call = createCall(MBB, MBBI, TII, MI.getOperand(0),
929 // Regmask starts after the call target.
930 /*RegMaskStartIdx=*/1);
931
932 Call->setCFIType(*MBB.getParent(), MI.getCFIType());
933
934 MachineInstr *BTI =
935 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::HINT))
936 // BTI J so that setjmp can to BR to this.
937 .addImm(36)
938 .getInstr();
939
940 if (MI.shouldUpdateAdditionalCallInfo())
942
943 MI.eraseFromParent();
944 finalizeBundle(MBB, Call->getIterator(), std::next(BTI->getIterator()));
945 return true;
946}
947
948bool AArch64ExpandPseudo::expandStoreSwiftAsyncContext(
949 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
950 Register CtxReg = MBBI->getOperand(0).getReg();
951 Register BaseReg = MBBI->getOperand(1).getReg();
952 int Offset = MBBI->getOperand(2).getImm();
953 DebugLoc DL(MBBI->getDebugLoc());
954 auto &STI = MBB.getParent()->getSubtarget<AArch64Subtarget>();
955
956 if (STI.getTargetTriple().getArchName() != "arm64e") {
957 BuildMI(MBB, MBBI, DL, TII->get(AArch64::STRXui))
958 .addUse(CtxReg)
959 .addUse(BaseReg)
960 .addImm(Offset / 8)
963 return true;
964 }
965
966 // We need to sign the context in an address-discriminated way. 0xc31a is a
967 // fixed random value, chosen as part of the ABI.
968 // add x16, xBase, #Offset
969 // movk x16, #0xc31a, lsl #48
970 // mov x17, x22/xzr
971 // pacdb x17, x16
972 // str x17, [xBase, #Offset]
973 unsigned Opc = Offset >= 0 ? AArch64::ADDXri : AArch64::SUBXri;
974 BuildMI(MBB, MBBI, DL, TII->get(Opc), AArch64::X16)
975 .addUse(BaseReg)
976 .addImm(abs(Offset))
977 .addImm(0)
979 BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVKXi), AArch64::X16)
980 .addUse(AArch64::X16)
981 .addImm(0xc31a)
982 .addImm(48)
984 // We're not allowed to clobber X22 (and couldn't clobber XZR if we tried), so
985 // move it somewhere before signing.
986 BuildMI(MBB, MBBI, DL, TII->get(AArch64::ORRXrs), AArch64::X17)
987 .addUse(AArch64::XZR)
988 .addUse(CtxReg)
989 .addImm(0)
991 BuildMI(MBB, MBBI, DL, TII->get(AArch64::PACDB), AArch64::X17)
992 .addUse(AArch64::X17)
993 .addUse(AArch64::X16)
995 BuildMI(MBB, MBBI, DL, TII->get(AArch64::STRXui))
996 .addUse(AArch64::X17)
997 .addUse(BaseReg)
998 .addImm(Offset / 8)
1000
1002 return true;
1003}
1004
1005AArch64ExpandPseudo::ConditionalBlocks
1006AArch64ExpandPseudo::expandConditionalPseudo(MachineBasicBlock &MBB,
1008 DebugLoc DL,
1009 MachineInstrBuilder &Branch) {
1010 assert((std::next(MBBI) != MBB.end() ||
1011 MBB.successors().begin() != MBB.successors().end()) &&
1012 "Unexpected unreachable in block");
1013
1014 // Split MBB and create two new blocks:
1015 // - MBB now contains all instructions before the conditional pseudo.
1016 // - CondBB contains the conditional pseudo instruction only.
1017 // - EndBB contains all instructions after the conditional pseudo.
1018 MachineInstr &PrevMI = *std::prev(MBBI);
1019 MachineBasicBlock *CondBB = MBB.splitAt(PrevMI, /*UpdateLiveIns*/ true);
1020 MachineBasicBlock *EndBB =
1021 std::next(MBBI) == CondBB->end()
1022 ? *CondBB->successors().begin()
1023 : CondBB->splitAt(*MBBI, /*UpdateLiveIns*/ true);
1024
1025 // Add the SMBB label to the branch instruction & create a branch to EndBB.
1026 Branch.addMBB(CondBB);
1027 BuildMI(&MBB, DL, TII->get(AArch64::B))
1028 .addMBB(EndBB);
1029 MBB.addSuccessor(EndBB);
1030
1031 // Create branch from CondBB to EndBB. Users of this helper should insert new
1032 // instructions at CondBB.back() -- i.e. before the branch.
1033 BuildMI(CondBB, DL, TII->get(AArch64::B)).addMBB(EndBB);
1034 return {*CondBB, *EndBB};
1035}
1036
1037MachineBasicBlock *
1038AArch64ExpandPseudo::expandRestoreZASave(MachineBasicBlock &MBB,
1040 MachineInstr &MI = *MBBI;
1041 DebugLoc DL = MI.getDebugLoc();
1042
1043 // Compare TPIDR2_EL0 against 0. Restore ZA if TPIDR2_EL0 is zero.
1044 MachineInstrBuilder Branch =
1045 BuildMI(MBB, MBBI, DL, TII->get(AArch64::CBZX)).add(MI.getOperand(0));
1046
1047 auto [CondBB, EndBB] = expandConditionalPseudo(MBB, MBBI, DL, Branch);
1048 // Replace the pseudo with a call (BL).
1049 MachineInstrBuilder MIB =
1050 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::BL));
1051 // Copy operands (mainly the regmask) from the pseudo.
1052 for (unsigned I = 2; I < MI.getNumOperands(); ++I)
1053 MIB.add(MI.getOperand(I));
1054 // Mark the TPIDR2 block pointer (X0) as an implicit use.
1055 MIB.addReg(MI.getOperand(1).getReg(), RegState::Implicit);
1056
1057 MI.eraseFromParent();
1058 return &EndBB;
1059}
1060
1061static constexpr unsigned ZERO_ALL_ZA_MASK = 0b11111111;
1062
1064AArch64ExpandPseudo::expandCommitZASave(MachineBasicBlock &MBB,
1066 MachineInstr &MI = *MBBI;
1067 DebugLoc DL = MI.getDebugLoc();
1068 [[maybe_unused]] auto *RI = MBB.getParent()->getSubtarget().getRegisterInfo();
1069
1070 // Compare TPIDR2_EL0 against 0. Commit ZA if TPIDR2_EL0 is non-zero.
1071 MachineInstrBuilder Branch =
1072 BuildMI(MBB, MBBI, DL, TII->get(AArch64::CBNZX)).add(MI.getOperand(0));
1073
1074 auto [CondBB, EndBB] = expandConditionalPseudo(MBB, MBBI, DL, Branch);
1075 // Replace the pseudo with a call (BL).
1077 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::BL));
1078 // Copy operands (mainly the regmask) from the pseudo.
1079 for (unsigned I = 3; I < MI.getNumOperands(); ++I)
1080 MIB.add(MI.getOperand(I));
1081 // Clear TPIDR2_EL0.
1082 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::MSR))
1083 .addImm(AArch64SysReg::TPIDR2_EL0)
1084 .addReg(AArch64::XZR);
1085 bool ZeroZA = MI.getOperand(1).getImm() != 0;
1086 bool ZeroZT0 = MI.getOperand(2).getImm() != 0;
1087 if (ZeroZA) {
1088 assert(MI.definesRegister(AArch64::ZAB0, RI) && "should define ZA!");
1089 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::ZERO_M))
1091 .addDef(AArch64::ZAB0, RegState::ImplicitDefine);
1092 }
1093 if (ZeroZT0) {
1094 assert(MI.definesRegister(AArch64::ZT0, RI) && "should define ZT0!");
1095 BuildMI(CondBB, CondBB.back(), DL, TII->get(AArch64::ZERO_T))
1096 .addDef(AArch64::ZT0);
1097 }
1098
1099 MI.eraseFromParent();
1100 return &EndBB;
1101}
1102
1103MachineBasicBlock *
1104AArch64ExpandPseudo::expandCondSMToggle(MachineBasicBlock &MBB,
1106 MachineInstr &MI = *MBBI;
1107 // In the case of a smstart/smstop before a unreachable, just remove the pseudo.
1108 // Exception handling code generated by Clang may introduce unreachables and it
1109 // seems unnecessary to restore pstate.sm when that happens. Note that it is
1110 // not just an optimisation, the code below expects a successor instruction/block
1111 // in order to split the block at MBBI.
1112 if (std::next(MBBI) == MBB.end() &&
1113 MI.getParent()->successors().begin() ==
1114 MI.getParent()->successors().end()) {
1115 MI.eraseFromParent();
1116 return &MBB;
1117 }
1118
1119 // Expand the pseudo into smstart or smstop instruction. The pseudo has the
1120 // following operands:
1121 //
1122 // MSRpstatePseudo <za|sm|both>, <0|1>, condition[, pstate.sm], <regmask>
1123 //
1124 // The pseudo is expanded into a conditional smstart/smstop, with a
1125 // check if pstate.sm (register) equals the expected value, and if not,
1126 // invokes the smstart/smstop.
1127 //
1128 // As an example, the following block contains a normal call from a
1129 // streaming-compatible function:
1130 //
1131 // OrigBB:
1132 // MSRpstatePseudo 3, 0, IfCallerIsStreaming, %0, <regmask> <- Cond SMSTOP
1133 // bl @normal_callee
1134 // MSRpstatePseudo 3, 1, IfCallerIsStreaming, %0, <regmask> <- Cond SMSTART
1135 //
1136 // ...which will be transformed into:
1137 //
1138 // OrigBB:
1139 // TBNZx %0:gpr64, 0, SMBB
1140 // b EndBB
1141 //
1142 // SMBB:
1143 // MSRpstatesvcrImm1 3, 0, <regmask> <- SMSTOP
1144 //
1145 // EndBB:
1146 // bl @normal_callee
1147 // MSRcond_pstatesvcrImm1 3, 1, <regmask> <- SMSTART
1148 //
1149 DebugLoc DL = MI.getDebugLoc();
1150
1151 // Create the conditional branch based on the third operand of the
1152 // instruction, which tells us if we are wrapping a normal or streaming
1153 // function.
1154 // We test the live value of pstate.sm and toggle pstate.sm if this is not the
1155 // expected value for the callee (0 for a normal callee and 1 for a streaming
1156 // callee).
1157 unsigned Opc;
1158 switch (MI.getOperand(2).getImm()) {
1159 case AArch64SME::Always:
1160 llvm_unreachable("Should have matched to instruction directly");
1162 Opc = AArch64::TBNZW;
1163 break;
1165 Opc = AArch64::TBZW;
1166 break;
1167 }
1168 auto PStateSM = MI.getOperand(3).getReg();
1170 unsigned SMReg32 = TRI->getSubReg(PStateSM, AArch64::sub_32);
1171 MachineInstrBuilder Tbx =
1172 BuildMI(MBB, MBBI, DL, TII->get(Opc)).addReg(SMReg32).addImm(0);
1173
1174 auto [CondBB, EndBB] = expandConditionalPseudo(MBB, MBBI, DL, Tbx);
1175 // Create the SMSTART/SMSTOP (MSRpstatesvcrImm1) instruction in SMBB.
1176 MachineInstrBuilder MIB = BuildMI(CondBB, CondBB.back(), MI.getDebugLoc(),
1177 TII->get(AArch64::MSRpstatesvcrImm1));
1178 // Copy all but the second and third operands of MSRcond_pstatesvcrImm1 (as
1179 // these contain the CopyFromReg for the first argument and the flag to
1180 // indicate whether the callee is streaming or normal).
1181 MIB.add(MI.getOperand(0));
1182 MIB.add(MI.getOperand(1));
1183 for (unsigned i = 4; i < MI.getNumOperands(); ++i)
1184 MIB.add(MI.getOperand(i));
1185
1186 MI.eraseFromParent();
1187 return &EndBB;
1188}
1189
1190bool AArch64ExpandPseudo::expandMultiVecPseudo(
1191 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
1192 TargetRegisterClass ContiguousClass, TargetRegisterClass StridedClass,
1193 unsigned ContiguousOp, unsigned StridedOpc) {
1194 MachineInstr &MI = *MBBI;
1195 Register Tuple = MI.getOperand(0).getReg();
1196
1197 auto ContiguousRange = ContiguousClass.getRegisters();
1198 auto StridedRange = StridedClass.getRegisters();
1199 unsigned Opc;
1200 if (llvm::is_contained(ContiguousRange, Tuple.asMCReg())) {
1201 Opc = ContiguousOp;
1202 } else if (llvm::is_contained(StridedRange, Tuple.asMCReg())) {
1203 Opc = StridedOpc;
1204 } else
1205 llvm_unreachable("Cannot expand Multi-Vector pseudo");
1206
1207 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc))
1208 .add(MI.getOperand(0))
1209 .add(MI.getOperand(1))
1210 .add(MI.getOperand(2))
1211 .add(MI.getOperand(3));
1212 transferImpOps(MI, MIB, MIB);
1213 MI.eraseFromParent();
1214 return true;
1215}
1216
1217bool AArch64ExpandPseudo::expandFormTuplePseudo(
1218 MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
1219 MachineBasicBlock::iterator &NextMBBI, unsigned Size) {
1220 assert((Size == 2 || Size == 4) && "Invalid Tuple Size");
1221 MachineInstr &MI = *MBBI;
1222 Register ReturnTuple = MI.getOperand(0).getReg();
1223
1224 const TargetRegisterInfo *TRI =
1226 for (unsigned I = 0; I < Size; ++I) {
1227 Register FormTupleOpReg = MI.getOperand(I + 1).getReg();
1228 Register ReturnTupleSubReg =
1229 TRI->getSubReg(ReturnTuple, AArch64::zsub0 + I);
1230 // Add copies to ensure the subregisters remain in the correct order
1231 // for any contigious operation they are used by.
1232 if (FormTupleOpReg != ReturnTupleSubReg)
1233 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ORR_ZZZ))
1234 .addReg(ReturnTupleSubReg, RegState::Define)
1235 .addReg(FormTupleOpReg)
1236 .addReg(FormTupleOpReg);
1237 }
1238
1239 MI.eraseFromParent();
1240 return true;
1241}
1242
1243/// If MBBI references a pseudo instruction that should be expanded here,
1244/// do the expansion and return true. Otherwise return false.
1245bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
1247 MachineBasicBlock::iterator &NextMBBI) {
1248 MachineInstr &MI = *MBBI;
1249 unsigned Opcode = MI.getOpcode();
1250
1251 // Check if we can expand the destructive op
1252 int OrigInstr = AArch64::getSVEPseudoMap(MI.getOpcode());
1253 if (OrigInstr != -1) {
1254 auto &Orig = TII->get(OrigInstr);
1255 if ((Orig.TSFlags & AArch64::DestructiveInstTypeMask) !=
1257 return expand_DestructiveOp(MI, MBB, MBBI);
1258 }
1259 }
1260
1261 switch (Opcode) {
1262 default:
1263 break;
1264
1265 case AArch64::BSPv8i8:
1266 case AArch64::BSPv16i8: {
1267 Register DstReg = MI.getOperand(0).getReg();
1268 if (DstReg == MI.getOperand(3).getReg()) {
1269 // Expand to BIT
1270 auto I = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1271 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BITv8i8
1272 : AArch64::BITv16i8))
1273 .add(MI.getOperand(0))
1274 .add(MI.getOperand(3))
1275 .add(MI.getOperand(2))
1276 .add(MI.getOperand(1));
1277 transferImpOps(MI, I, I);
1278 } else if (DstReg == MI.getOperand(2).getReg()) {
1279 // Expand to BIF
1280 auto I = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1281 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BIFv8i8
1282 : AArch64::BIFv16i8))
1283 .add(MI.getOperand(0))
1284 .add(MI.getOperand(2))
1285 .add(MI.getOperand(3))
1286 .add(MI.getOperand(1));
1287 transferImpOps(MI, I, I);
1288 } else {
1289 // Expand to BSL, use additional move if required
1290 if (DstReg == MI.getOperand(1).getReg()) {
1291 auto I =
1292 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1293 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BSLv8i8
1294 : AArch64::BSLv16i8))
1295 .add(MI.getOperand(0))
1296 .add(MI.getOperand(1))
1297 .add(MI.getOperand(2))
1298 .add(MI.getOperand(3));
1299 transferImpOps(MI, I, I);
1300 } else {
1301 unsigned RegState =
1302 getRenamableRegState(MI.getOperand(1).isRenamable()) |
1304 MI.getOperand(1).isKill() &&
1305 MI.getOperand(1).getReg() != MI.getOperand(2).getReg() &&
1306 MI.getOperand(1).getReg() != MI.getOperand(3).getReg());
1307 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1308 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::ORRv8i8
1309 : AArch64::ORRv16i8))
1310 .addReg(DstReg,
1312 getRenamableRegState(MI.getOperand(0).isRenamable()))
1313 .addReg(MI.getOperand(1).getReg(), RegState)
1314 .addReg(MI.getOperand(1).getReg(), RegState);
1315 auto I2 =
1316 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1317 TII->get(Opcode == AArch64::BSPv8i8 ? AArch64::BSLv8i8
1318 : AArch64::BSLv16i8))
1319 .add(MI.getOperand(0))
1320 .addReg(DstReg,
1322 MI.getOperand(0).isRenamable()))
1323 .add(MI.getOperand(2))
1324 .add(MI.getOperand(3));
1325 transferImpOps(MI, I2, I2);
1326 }
1327 }
1328 MI.eraseFromParent();
1329 return true;
1330 }
1331
1332 case AArch64::ADDWrr:
1333 case AArch64::SUBWrr:
1334 case AArch64::ADDXrr:
1335 case AArch64::SUBXrr:
1336 case AArch64::ADDSWrr:
1337 case AArch64::SUBSWrr:
1338 case AArch64::ADDSXrr:
1339 case AArch64::SUBSXrr:
1340 case AArch64::ANDWrr:
1341 case AArch64::ANDXrr:
1342 case AArch64::BICWrr:
1343 case AArch64::BICXrr:
1344 case AArch64::ANDSWrr:
1345 case AArch64::ANDSXrr:
1346 case AArch64::BICSWrr:
1347 case AArch64::BICSXrr:
1348 case AArch64::EONWrr:
1349 case AArch64::EONXrr:
1350 case AArch64::EORWrr:
1351 case AArch64::EORXrr:
1352 case AArch64::ORNWrr:
1353 case AArch64::ORNXrr:
1354 case AArch64::ORRWrr:
1355 case AArch64::ORRXrr: {
1356 unsigned Opcode;
1357 switch (MI.getOpcode()) {
1358 default:
1359 return false;
1360 case AArch64::ADDWrr: Opcode = AArch64::ADDWrs; break;
1361 case AArch64::SUBWrr: Opcode = AArch64::SUBWrs; break;
1362 case AArch64::ADDXrr: Opcode = AArch64::ADDXrs; break;
1363 case AArch64::SUBXrr: Opcode = AArch64::SUBXrs; break;
1364 case AArch64::ADDSWrr: Opcode = AArch64::ADDSWrs; break;
1365 case AArch64::SUBSWrr: Opcode = AArch64::SUBSWrs; break;
1366 case AArch64::ADDSXrr: Opcode = AArch64::ADDSXrs; break;
1367 case AArch64::SUBSXrr: Opcode = AArch64::SUBSXrs; break;
1368 case AArch64::ANDWrr: Opcode = AArch64::ANDWrs; break;
1369 case AArch64::ANDXrr: Opcode = AArch64::ANDXrs; break;
1370 case AArch64::BICWrr: Opcode = AArch64::BICWrs; break;
1371 case AArch64::BICXrr: Opcode = AArch64::BICXrs; break;
1372 case AArch64::ANDSWrr: Opcode = AArch64::ANDSWrs; break;
1373 case AArch64::ANDSXrr: Opcode = AArch64::ANDSXrs; break;
1374 case AArch64::BICSWrr: Opcode = AArch64::BICSWrs; break;
1375 case AArch64::BICSXrr: Opcode = AArch64::BICSXrs; break;
1376 case AArch64::EONWrr: Opcode = AArch64::EONWrs; break;
1377 case AArch64::EONXrr: Opcode = AArch64::EONXrs; break;
1378 case AArch64::EORWrr: Opcode = AArch64::EORWrs; break;
1379 case AArch64::EORXrr: Opcode = AArch64::EORXrs; break;
1380 case AArch64::ORNWrr: Opcode = AArch64::ORNWrs; break;
1381 case AArch64::ORNXrr: Opcode = AArch64::ORNXrs; break;
1382 case AArch64::ORRWrr: Opcode = AArch64::ORRWrs; break;
1383 case AArch64::ORRXrr: Opcode = AArch64::ORRXrs; break;
1384 }
1385 MachineFunction &MF = *MBB.getParent();
1386 // Try to create new inst without implicit operands added.
1387 MachineInstr *NewMI = MF.CreateMachineInstr(
1388 TII->get(Opcode), MI.getDebugLoc(), /*NoImplicit=*/true);
1389 MBB.insert(MBBI, NewMI);
1390 MachineInstrBuilder MIB1(MF, NewMI);
1391 MIB1->setPCSections(MF, MI.getPCSections());
1392 MIB1.addReg(MI.getOperand(0).getReg(), RegState::Define)
1393 .add(MI.getOperand(1))
1394 .add(MI.getOperand(2))
1396 transferImpOps(MI, MIB1, MIB1);
1397 if (auto DebugNumber = MI.peekDebugInstrNum())
1398 NewMI->setDebugInstrNum(DebugNumber);
1399 MI.eraseFromParent();
1400 return true;
1401 }
1402
1403 case AArch64::LOADgot: {
1404 MachineFunction *MF = MBB.getParent();
1405 Register DstReg = MI.getOperand(0).getReg();
1406 const MachineOperand &MO1 = MI.getOperand(1);
1407 unsigned Flags = MO1.getTargetFlags();
1408
1409 if (MF->getTarget().getCodeModel() == CodeModel::Tiny) {
1410 // Tiny codemodel expand to LDR
1411 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1412 TII->get(AArch64::LDRXl), DstReg);
1413
1414 if (MO1.isGlobal()) {
1415 MIB.addGlobalAddress(MO1.getGlobal(), 0, Flags);
1416 } else if (MO1.isSymbol()) {
1417 MIB.addExternalSymbol(MO1.getSymbolName(), Flags);
1418 } else {
1419 assert(MO1.isCPI() &&
1420 "Only expect globals, externalsymbols, or constant pools");
1421 MIB.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(), Flags);
1422 }
1423 } else {
1424 // Small codemodel expand into ADRP + LDR.
1425 MachineFunction &MF = *MI.getParent()->getParent();
1426 DebugLoc DL = MI.getDebugLoc();
1427 MachineInstrBuilder MIB1 =
1428 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg);
1429
1430 MachineInstrBuilder MIB2;
1431 if (MF.getSubtarget<AArch64Subtarget>().isTargetILP32()) {
1433 unsigned Reg32 = TRI->getSubReg(DstReg, AArch64::sub_32);
1434 unsigned DstFlags = MI.getOperand(0).getTargetFlags();
1435 MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::LDRWui))
1436 .addDef(Reg32)
1437 .addReg(DstReg, RegState::Kill)
1438 .addReg(DstReg, DstFlags | RegState::Implicit);
1439 } else {
1440 Register DstReg = MI.getOperand(0).getReg();
1441 MIB2 = BuildMI(MBB, MBBI, DL, TII->get(AArch64::LDRXui))
1442 .add(MI.getOperand(0))
1443 .addUse(DstReg, RegState::Kill);
1444 }
1445
1446 if (MO1.isGlobal()) {
1447 MIB1.addGlobalAddress(MO1.getGlobal(), 0, Flags | AArch64II::MO_PAGE);
1448 MIB2.addGlobalAddress(MO1.getGlobal(), 0,
1450 } else if (MO1.isSymbol()) {
1452 MIB2.addExternalSymbol(MO1.getSymbolName(), Flags |
1455 } else {
1456 assert(MO1.isCPI() &&
1457 "Only expect globals, externalsymbols, or constant pools");
1458 MIB1.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(),
1459 Flags | AArch64II::MO_PAGE);
1460 MIB2.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(),
1461 Flags | AArch64II::MO_PAGEOFF |
1463 }
1464
1465 // If the LOADgot instruction has a debug-instr-number, annotate the
1466 // LDRWui instruction that it is expanded to with the same
1467 // debug-instr-number to preserve debug information.
1468 if (MI.peekDebugInstrNum() != 0)
1469 MIB2->setDebugInstrNum(MI.peekDebugInstrNum());
1470 transferImpOps(MI, MIB1, MIB2);
1471 }
1472 MI.eraseFromParent();
1473 return true;
1474 }
1475 case AArch64::MOVaddrBA: {
1476 MachineFunction &MF = *MI.getParent()->getParent();
1477 if (MF.getSubtarget<AArch64Subtarget>().isTargetMachO()) {
1478 // blockaddress expressions have to come from a constant pool because the
1479 // largest addend (and hence offset within a function) allowed for ADRP is
1480 // only 8MB.
1481 const BlockAddress *BA = MI.getOperand(1).getBlockAddress();
1482 assert(MI.getOperand(1).getOffset() == 0 && "unexpected offset");
1483
1484 MachineConstantPool *MCP = MF.getConstantPool();
1485 unsigned CPIdx = MCP->getConstantPoolIndex(BA, Align(8));
1486
1487 Register DstReg = MI.getOperand(0).getReg();
1488 auto MIB1 =
1489 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg)
1491 auto MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1492 TII->get(AArch64::LDRXui), DstReg)
1493 .addUse(DstReg)
1496 transferImpOps(MI, MIB1, MIB2);
1497 MI.eraseFromParent();
1498 return true;
1499 }
1500 }
1501 [[fallthrough]];
1502 case AArch64::MOVaddr:
1503 case AArch64::MOVaddrJT:
1504 case AArch64::MOVaddrCP:
1505 case AArch64::MOVaddrTLS:
1506 case AArch64::MOVaddrEXT: {
1507 // Expand into ADRP + ADD.
1508 Register DstReg = MI.getOperand(0).getReg();
1509 assert(DstReg != AArch64::XZR);
1510 MachineInstrBuilder MIB1 =
1511 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg)
1512 .add(MI.getOperand(1));
1513
1514 if (MI.getOperand(1).getTargetFlags() & AArch64II::MO_TAGGED) {
1515 // MO_TAGGED on the page indicates a tagged address. Set the tag now.
1516 // We do so by creating a MOVK that sets bits 48-63 of the register to
1517 // (global address + 0x100000000 - PC) >> 48. This assumes that we're in
1518 // the small code model so we can assume a binary size of <= 4GB, which
1519 // makes the untagged PC relative offset positive. The binary must also be
1520 // loaded into address range [0, 2^48). Both of these properties need to
1521 // be ensured at runtime when using tagged addresses.
1522 auto Tag = MI.getOperand(1);
1523 Tag.setTargetFlags(AArch64II::MO_PREL | AArch64II::MO_G3);
1524 Tag.setOffset(0x100000000);
1525 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MOVKXi), DstReg)
1526 .addReg(DstReg)
1527 .add(Tag)
1528 .addImm(48);
1529 }
1530
1531 MachineInstrBuilder MIB2 =
1532 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADDXri))
1533 .add(MI.getOperand(0))
1534 .addReg(DstReg)
1535 .add(MI.getOperand(2))
1536 .addImm(0);
1537
1538 transferImpOps(MI, MIB1, MIB2);
1539 MI.eraseFromParent();
1540 return true;
1541 }
1542 case AArch64::ADDlowTLS:
1543 // Produce a plain ADD
1544 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADDXri))
1545 .add(MI.getOperand(0))
1546 .add(MI.getOperand(1))
1547 .add(MI.getOperand(2))
1548 .addImm(0);
1549 MI.eraseFromParent();
1550 return true;
1551
1552 case AArch64::MOVbaseTLS: {
1553 Register DstReg = MI.getOperand(0).getReg();
1554 auto SysReg = AArch64SysReg::TPIDR_EL0;
1555 MachineFunction *MF = MBB.getParent();
1556 if (MF->getSubtarget<AArch64Subtarget>().useEL3ForTP())
1557 SysReg = AArch64SysReg::TPIDR_EL3;
1558 else if (MF->getSubtarget<AArch64Subtarget>().useEL2ForTP())
1559 SysReg = AArch64SysReg::TPIDR_EL2;
1560 else if (MF->getSubtarget<AArch64Subtarget>().useEL1ForTP())
1561 SysReg = AArch64SysReg::TPIDR_EL1;
1562 else if (MF->getSubtarget<AArch64Subtarget>().useROEL0ForTP())
1563 SysReg = AArch64SysReg::TPIDRRO_EL0;
1564 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MRS), DstReg)
1565 .addImm(SysReg);
1566 MI.eraseFromParent();
1567 return true;
1568 }
1569
1570 case AArch64::MOVi32imm:
1571 return expandMOVImm(MBB, MBBI, 32);
1572 case AArch64::MOVi64imm:
1573 return expandMOVImm(MBB, MBBI, 64);
1574 case AArch64::RET_ReallyLR: {
1575 // Hiding the LR use with RET_ReallyLR may lead to extra kills in the
1576 // function and missing live-ins. We are fine in practice because callee
1577 // saved register handling ensures the register value is restored before
1578 // RET, but we need the undef flag here to appease the MachineVerifier
1579 // liveness checks.
1580 MachineInstrBuilder MIB =
1581 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::RET))
1582 .addReg(AArch64::LR, RegState::Undef);
1583 transferImpOps(MI, MIB, MIB);
1584 MI.eraseFromParent();
1585 return true;
1586 }
1587 case AArch64::CMP_SWAP_8:
1588 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRB, AArch64::STLXRB,
1589 AArch64::SUBSWrx,
1591 AArch64::WZR, NextMBBI);
1592 case AArch64::CMP_SWAP_16:
1593 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRH, AArch64::STLXRH,
1594 AArch64::SUBSWrx,
1596 AArch64::WZR, NextMBBI);
1597 case AArch64::CMP_SWAP_32:
1598 return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRW, AArch64::STLXRW,
1599 AArch64::SUBSWrs,
1601 AArch64::WZR, NextMBBI);
1602 case AArch64::CMP_SWAP_64:
1603 return expandCMP_SWAP(MBB, MBBI,
1604 AArch64::LDAXRX, AArch64::STLXRX, AArch64::SUBSXrs,
1606 AArch64::XZR, NextMBBI);
1607 case AArch64::CMP_SWAP_128:
1608 case AArch64::CMP_SWAP_128_RELEASE:
1609 case AArch64::CMP_SWAP_128_ACQUIRE:
1610 case AArch64::CMP_SWAP_128_MONOTONIC:
1611 return expandCMP_SWAP_128(MBB, MBBI, NextMBBI);
1612
1613 case AArch64::AESMCrrTied:
1614 case AArch64::AESIMCrrTied: {
1615 MachineInstrBuilder MIB =
1616 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1617 TII->get(Opcode == AArch64::AESMCrrTied ? AArch64::AESMCrr :
1618 AArch64::AESIMCrr))
1619 .add(MI.getOperand(0))
1620 .add(MI.getOperand(1));
1621 transferImpOps(MI, MIB, MIB);
1622 MI.eraseFromParent();
1623 return true;
1624 }
1625 case AArch64::IRGstack: {
1626 MachineFunction &MF = *MBB.getParent();
1627 const AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
1628 const AArch64FrameLowering *TFI =
1629 MF.getSubtarget<AArch64Subtarget>().getFrameLowering();
1630
1631 // IRG does not allow immediate offset. getTaggedBasePointerOffset should
1632 // almost always point to SP-after-prologue; if not, emit a longer
1633 // instruction sequence.
1634 int BaseOffset = -AFI->getTaggedBasePointerOffset();
1635 Register FrameReg;
1636 StackOffset FrameRegOffset = TFI->resolveFrameOffsetReference(
1637 MF, BaseOffset, false /*isFixed*/, TargetStackID::Default /*StackID*/,
1638 FrameReg,
1639 /*PreferFP=*/false,
1640 /*ForSimm=*/true);
1641 Register SrcReg = FrameReg;
1642 if (FrameRegOffset) {
1643 // Use output register as temporary.
1644 SrcReg = MI.getOperand(0).getReg();
1645 emitFrameOffset(MBB, &MI, MI.getDebugLoc(), SrcReg, FrameReg,
1646 FrameRegOffset, TII);
1647 }
1648 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::IRG))
1649 .add(MI.getOperand(0))
1650 .addUse(SrcReg)
1651 .add(MI.getOperand(2));
1652 MI.eraseFromParent();
1653 return true;
1654 }
1655 case AArch64::TAGPstack: {
1656 int64_t Offset = MI.getOperand(2).getImm();
1657 BuildMI(MBB, MBBI, MI.getDebugLoc(),
1658 TII->get(Offset >= 0 ? AArch64::ADDG : AArch64::SUBG))
1659 .add(MI.getOperand(0))
1660 .add(MI.getOperand(1))
1661 .addImm(std::abs(Offset))
1662 .add(MI.getOperand(4));
1663 MI.eraseFromParent();
1664 return true;
1665 }
1666 case AArch64::STGloop_wback:
1667 case AArch64::STZGloop_wback:
1668 return expandSetTagLoop(MBB, MBBI, NextMBBI);
1669 case AArch64::STGloop:
1670 case AArch64::STZGloop:
1672 "Non-writeback variants of STGloop / STZGloop should not "
1673 "survive past PrologEpilogInserter.");
1674 case AArch64::STR_ZZZZXI:
1675 case AArch64::STR_ZZZZXI_STRIDED_CONTIGUOUS:
1676 return expandSVESpillFill(MBB, MBBI, AArch64::STR_ZXI, 4);
1677 case AArch64::STR_ZZZXI:
1678 return expandSVESpillFill(MBB, MBBI, AArch64::STR_ZXI, 3);
1679 case AArch64::STR_ZZXI:
1680 case AArch64::STR_ZZXI_STRIDED_CONTIGUOUS:
1681 return expandSVESpillFill(MBB, MBBI, AArch64::STR_ZXI, 2);
1682 case AArch64::STR_PPXI:
1683 return expandSVESpillFill(MBB, MBBI, AArch64::STR_PXI, 2);
1684 case AArch64::LDR_ZZZZXI:
1685 case AArch64::LDR_ZZZZXI_STRIDED_CONTIGUOUS:
1686 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_ZXI, 4);
1687 case AArch64::LDR_ZZZXI:
1688 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_ZXI, 3);
1689 case AArch64::LDR_ZZXI:
1690 case AArch64::LDR_ZZXI_STRIDED_CONTIGUOUS:
1691 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_ZXI, 2);
1692 case AArch64::LDR_PPXI:
1693 return expandSVESpillFill(MBB, MBBI, AArch64::LDR_PXI, 2);
1694 case AArch64::BLR_RVMARKER:
1695 case AArch64::BLRA_RVMARKER:
1696 return expandCALL_RVMARKER(MBB, MBBI);
1697 case AArch64::BLR_BTI:
1698 return expandCALL_BTI(MBB, MBBI);
1699 case AArch64::StoreSwiftAsyncContext:
1700 return expandStoreSwiftAsyncContext(MBB, MBBI);
1701 case AArch64::RestoreZAPseudo:
1702 case AArch64::CommitZASavePseudo:
1703 case AArch64::MSRpstatePseudo: {
1704 auto *NewMBB = [&] {
1705 switch (Opcode) {
1706 case AArch64::RestoreZAPseudo:
1707 return expandRestoreZASave(MBB, MBBI);
1708 case AArch64::CommitZASavePseudo:
1709 return expandCommitZASave(MBB, MBBI);
1710 case AArch64::MSRpstatePseudo:
1711 return expandCondSMToggle(MBB, MBBI);
1712 default:
1713 llvm_unreachable("Unexpected conditional pseudo!");
1714 }
1715 }();
1716 if (NewMBB != &MBB)
1717 NextMBBI = MBB.end(); // The NextMBBI iterator is invalidated.
1718 return true;
1719 }
1720 case AArch64::InOutZAUsePseudo:
1721 case AArch64::RequiresZASavePseudo:
1722 case AArch64::RequiresZT0SavePseudo:
1723 case AArch64::SMEStateAllocPseudo:
1724 case AArch64::COALESCER_BARRIER_FPR16:
1725 case AArch64::COALESCER_BARRIER_FPR32:
1726 case AArch64::COALESCER_BARRIER_FPR64:
1727 case AArch64::COALESCER_BARRIER_FPR128:
1728 MI.eraseFromParent();
1729 return true;
1730 case AArch64::LD1B_2Z_IMM_PSEUDO:
1731 return expandMultiVecPseudo(
1732 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1733 AArch64::LD1B_2Z_IMM, AArch64::LD1B_2Z_STRIDED_IMM);
1734 case AArch64::LD1H_2Z_IMM_PSEUDO:
1735 return expandMultiVecPseudo(
1736 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1737 AArch64::LD1H_2Z_IMM, AArch64::LD1H_2Z_STRIDED_IMM);
1738 case AArch64::LD1W_2Z_IMM_PSEUDO:
1739 return expandMultiVecPseudo(
1740 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1741 AArch64::LD1W_2Z_IMM, AArch64::LD1W_2Z_STRIDED_IMM);
1742 case AArch64::LD1D_2Z_IMM_PSEUDO:
1743 return expandMultiVecPseudo(
1744 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1745 AArch64::LD1D_2Z_IMM, AArch64::LD1D_2Z_STRIDED_IMM);
1746 case AArch64::LDNT1B_2Z_IMM_PSEUDO:
1747 return expandMultiVecPseudo(
1748 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1749 AArch64::LDNT1B_2Z_IMM, AArch64::LDNT1B_2Z_STRIDED_IMM);
1750 case AArch64::LDNT1H_2Z_IMM_PSEUDO:
1751 return expandMultiVecPseudo(
1752 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1753 AArch64::LDNT1H_2Z_IMM, AArch64::LDNT1H_2Z_STRIDED_IMM);
1754 case AArch64::LDNT1W_2Z_IMM_PSEUDO:
1755 return expandMultiVecPseudo(
1756 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1757 AArch64::LDNT1W_2Z_IMM, AArch64::LDNT1W_2Z_STRIDED_IMM);
1758 case AArch64::LDNT1D_2Z_IMM_PSEUDO:
1759 return expandMultiVecPseudo(
1760 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1761 AArch64::LDNT1D_2Z_IMM, AArch64::LDNT1D_2Z_STRIDED_IMM);
1762 case AArch64::LD1B_2Z_PSEUDO:
1763 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1764 AArch64::ZPR2StridedRegClass, AArch64::LD1B_2Z,
1765 AArch64::LD1B_2Z_STRIDED);
1766 case AArch64::LD1H_2Z_PSEUDO:
1767 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1768 AArch64::ZPR2StridedRegClass, AArch64::LD1H_2Z,
1769 AArch64::LD1H_2Z_STRIDED);
1770 case AArch64::LD1W_2Z_PSEUDO:
1771 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1772 AArch64::ZPR2StridedRegClass, AArch64::LD1W_2Z,
1773 AArch64::LD1W_2Z_STRIDED);
1774 case AArch64::LD1D_2Z_PSEUDO:
1775 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR2RegClass,
1776 AArch64::ZPR2StridedRegClass, AArch64::LD1D_2Z,
1777 AArch64::LD1D_2Z_STRIDED);
1778 case AArch64::LDNT1B_2Z_PSEUDO:
1779 return expandMultiVecPseudo(
1780 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1781 AArch64::LDNT1B_2Z, AArch64::LDNT1B_2Z_STRIDED);
1782 case AArch64::LDNT1H_2Z_PSEUDO:
1783 return expandMultiVecPseudo(
1784 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1785 AArch64::LDNT1H_2Z, AArch64::LDNT1H_2Z_STRIDED);
1786 case AArch64::LDNT1W_2Z_PSEUDO:
1787 return expandMultiVecPseudo(
1788 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1789 AArch64::LDNT1W_2Z, AArch64::LDNT1W_2Z_STRIDED);
1790 case AArch64::LDNT1D_2Z_PSEUDO:
1791 return expandMultiVecPseudo(
1792 MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,
1793 AArch64::LDNT1D_2Z, AArch64::LDNT1D_2Z_STRIDED);
1794 case AArch64::LD1B_4Z_IMM_PSEUDO:
1795 return expandMultiVecPseudo(
1796 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1797 AArch64::LD1B_4Z_IMM, AArch64::LD1B_4Z_STRIDED_IMM);
1798 case AArch64::LD1H_4Z_IMM_PSEUDO:
1799 return expandMultiVecPseudo(
1800 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1801 AArch64::LD1H_4Z_IMM, AArch64::LD1H_4Z_STRIDED_IMM);
1802 case AArch64::LD1W_4Z_IMM_PSEUDO:
1803 return expandMultiVecPseudo(
1804 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1805 AArch64::LD1W_4Z_IMM, AArch64::LD1W_4Z_STRIDED_IMM);
1806 case AArch64::LD1D_4Z_IMM_PSEUDO:
1807 return expandMultiVecPseudo(
1808 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1809 AArch64::LD1D_4Z_IMM, AArch64::LD1D_4Z_STRIDED_IMM);
1810 case AArch64::LDNT1B_4Z_IMM_PSEUDO:
1811 return expandMultiVecPseudo(
1812 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1813 AArch64::LDNT1B_4Z_IMM, AArch64::LDNT1B_4Z_STRIDED_IMM);
1814 case AArch64::LDNT1H_4Z_IMM_PSEUDO:
1815 return expandMultiVecPseudo(
1816 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1817 AArch64::LDNT1H_4Z_IMM, AArch64::LDNT1H_4Z_STRIDED_IMM);
1818 case AArch64::LDNT1W_4Z_IMM_PSEUDO:
1819 return expandMultiVecPseudo(
1820 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1821 AArch64::LDNT1W_4Z_IMM, AArch64::LDNT1W_4Z_STRIDED_IMM);
1822 case AArch64::LDNT1D_4Z_IMM_PSEUDO:
1823 return expandMultiVecPseudo(
1824 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1825 AArch64::LDNT1D_4Z_IMM, AArch64::LDNT1D_4Z_STRIDED_IMM);
1826 case AArch64::LD1B_4Z_PSEUDO:
1827 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1828 AArch64::ZPR4StridedRegClass, AArch64::LD1B_4Z,
1829 AArch64::LD1B_4Z_STRIDED);
1830 case AArch64::LD1H_4Z_PSEUDO:
1831 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1832 AArch64::ZPR4StridedRegClass, AArch64::LD1H_4Z,
1833 AArch64::LD1H_4Z_STRIDED);
1834 case AArch64::LD1W_4Z_PSEUDO:
1835 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1836 AArch64::ZPR4StridedRegClass, AArch64::LD1W_4Z,
1837 AArch64::LD1W_4Z_STRIDED);
1838 case AArch64::LD1D_4Z_PSEUDO:
1839 return expandMultiVecPseudo(MBB, MBBI, AArch64::ZPR4RegClass,
1840 AArch64::ZPR4StridedRegClass, AArch64::LD1D_4Z,
1841 AArch64::LD1D_4Z_STRIDED);
1842 case AArch64::LDNT1B_4Z_PSEUDO:
1843 return expandMultiVecPseudo(
1844 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1845 AArch64::LDNT1B_4Z, AArch64::LDNT1B_4Z_STRIDED);
1846 case AArch64::LDNT1H_4Z_PSEUDO:
1847 return expandMultiVecPseudo(
1848 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1849 AArch64::LDNT1H_4Z, AArch64::LDNT1H_4Z_STRIDED);
1850 case AArch64::LDNT1W_4Z_PSEUDO:
1851 return expandMultiVecPseudo(
1852 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1853 AArch64::LDNT1W_4Z, AArch64::LDNT1W_4Z_STRIDED);
1854 case AArch64::LDNT1D_4Z_PSEUDO:
1855 return expandMultiVecPseudo(
1856 MBB, MBBI, AArch64::ZPR4RegClass, AArch64::ZPR4StridedRegClass,
1857 AArch64::LDNT1D_4Z, AArch64::LDNT1D_4Z_STRIDED);
1858 case AArch64::FORM_TRANSPOSED_REG_TUPLE_X2_PSEUDO:
1859 return expandFormTuplePseudo(MBB, MBBI, NextMBBI, 2);
1860 case AArch64::FORM_TRANSPOSED_REG_TUPLE_X4_PSEUDO:
1861 return expandFormTuplePseudo(MBB, MBBI, NextMBBI, 4);
1862 }
1863 return false;
1864}
1865
1866/// Iterate over the instructions in basic block MBB and expand any
1867/// pseudo instructions. Return true if anything was modified.
1868bool AArch64ExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
1869 bool Modified = false;
1870
1872 while (MBBI != E) {
1873 MachineBasicBlock::iterator NMBBI = std::next(MBBI);
1874 Modified |= expandMI(MBB, MBBI, NMBBI);
1875 MBBI = NMBBI;
1876 }
1877
1878 return Modified;
1879}
1880
1881bool AArch64ExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
1882 TII = MF.getSubtarget<AArch64Subtarget>().getInstrInfo();
1883
1884 bool Modified = false;
1885 for (auto &MBB : MF)
1886 Modified |= expandMBB(MBB);
1887 return Modified;
1888}
1889
1890/// Returns an instance of the pseudo instruction expansion pass.
1892 return new AArch64ExpandPseudo();
1893}
#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).
@ Renamable
Register that may be renamed.
@ 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.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
@ Offset
Definition DWP.cpp:532
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.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Definition APFloat.h:1545
unsigned getDeadRegState(bool B)
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:167
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
unsigned getKillRegState(bool B)
unsigned getRenamableRegState(bool B)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1909
void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
#define N