LLVM 24.0.0git
PPCPreEmitPeephole.cpp
Go to the documentation of this file.
1//===--------- PPCPreEmitPeephole.cpp - Late peephole optimizations -------===//
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// A pre-emit peephole for catching opportunities introduced by late passes such
10// as MachineBlockPlacement.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PPC.h"
15#include "PPCInstrInfo.h"
16#include "PPCSubtarget.h"
17#include "llvm/ADT/Statistic.h"
23#include "llvm/MC/MCContext.h"
24#include "llvm/Support/Debug.h"
25
26using namespace llvm;
27
28#define DEBUG_TYPE "ppc-pre-emit-peephole"
29
30STATISTIC(NumRRConvertedInPreEmit,
31 "Number of r+r instructions converted to r+i in pre-emit peephole");
32STATISTIC(NumRemovedInPreEmit,
33 "Number of instructions deleted in pre-emit peephole");
34STATISTIC(NumberOfSelfCopies,
35 "Number of self copy instructions eliminated");
36STATISTIC(NumFrameOffFoldInPreEmit,
37 "Number of folding frame offset by using r+r in pre-emit peephole");
38STATISTIC(NumCmpsInPreEmit,
39 "Number of compares eliminated in pre-emit peephole");
40
41namespace {
42
43static bool hasPCRelativeForm(MachineInstr &Use) {
44 switch (Use.getOpcode()) {
45 default:
46 return false;
47 case PPC::LBZ:
48 case PPC::LBZ8:
49 case PPC::LHA:
50 case PPC::LHA8:
51 case PPC::LHZ:
52 case PPC::LHZ8:
53 case PPC::LWZ:
54 case PPC::LWZ8:
55 case PPC::STB:
56 case PPC::STB8:
57 case PPC::STH:
58 case PPC::STH8:
59 case PPC::STW:
60 case PPC::STW8:
61 case PPC::LD:
62 case PPC::STD:
63 case PPC::LWA:
64 case PPC::LXSD:
65 case PPC::LXSSP:
66 case PPC::LXV:
67 case PPC::STXSD:
68 case PPC::STXSSP:
69 case PPC::STXV:
70 case PPC::LFD:
71 case PPC::LFS:
72 case PPC::STFD:
73 case PPC::STFS:
74 case PPC::DFLOADf32:
75 case PPC::DFLOADf64:
76 case PPC::DFSTOREf32:
77 case PPC::DFSTOREf64:
78 return true;
79 }
80}
81
82 class PPCPreEmitPeephole : public MachineFunctionPass {
83 const PPCOptions *CLOpts = nullptr;
84
85 public:
86 static char ID;
87 PPCPreEmitPeephole() : MachineFunctionPass(ID) {}
88
89 void getAnalysisUsage(AnalysisUsage &AU) const override {
91 }
92
93 MachineFunctionProperties getRequiredProperties() const override {
94 return MachineFunctionProperties().setNoVRegs();
95 }
96
97 // This function removes any redundant load immediates. It has two level
98 // loops - The outer loop finds the load immediates BBI that could be used
99 // to replace following redundancy. The inner loop scans instructions that
100 // after BBI to find redundancy and update kill/dead flags accordingly. If
101 // AfterBBI is the same as BBI, it is redundant, otherwise any instructions
102 // that modify the def register of BBI would break the scanning.
103 // DeadOrKillToUnset is a pointer to the previous operand that had the
104 // kill/dead flag set. It keeps track of the def register of BBI, the use
105 // registers of AfterBBIs and the def registers of AfterBBIs.
106 bool removeRedundantLIs(MachineBasicBlock &MBB,
107 const TargetRegisterInfo *TRI) {
108 LLVM_DEBUG(dbgs() << "Remove redundant load immediates from MBB:\n";
109 MBB.dump(); dbgs() << "\n");
110
111 DenseSet<MachineInstr *> InstrsToErase;
112 for (auto BBI = MBB.instr_begin(); BBI != MBB.instr_end(); ++BBI) {
113 // Skip load immediate that is marked to be erased later because it
114 // cannot be used to replace any other instructions.
115 if (InstrsToErase.contains(&*BBI))
116 continue;
117 // Skip non-load immediate.
118 unsigned Opc = BBI->getOpcode();
119 if (Opc != PPC::LI && Opc != PPC::LI8 && Opc != PPC::LIS &&
120 Opc != PPC::LIS8)
121 continue;
122 // Skip load immediate, where the operand is a relocation (e.g., $r3 =
123 // LI target-flags(ppc-lo) %const.0).
124 if (!BBI->getOperand(1).isImm())
125 continue;
126 assert(BBI->getOperand(0).isReg() &&
127 "Expected a register for the first operand");
128
129 LLVM_DEBUG(dbgs() << "Scanning after load immediate: "; BBI->dump(););
130
131 Register Reg = BBI->getOperand(0).getReg();
132 int64_t Imm = BBI->getOperand(1).getImm();
133 MachineOperand *DeadOrKillToUnset = nullptr;
134 if (BBI->getOperand(0).isDead()) {
135 DeadOrKillToUnset = &BBI->getOperand(0);
136 LLVM_DEBUG(dbgs() << " Kill flag of " << *DeadOrKillToUnset
137 << " from load immediate " << *BBI
138 << " is a unsetting candidate\n");
139 }
140 // This loop scans instructions after BBI to see if there is any
141 // redundant load immediate.
142 for (auto AfterBBI = std::next(BBI); AfterBBI != MBB.instr_end();
143 ++AfterBBI) {
144 // Track the operand that kill Reg. We would unset the kill flag of
145 // the operand if there is a following redundant load immediate.
146 int KillIdx = AfterBBI->findRegisterUseOperandIdx(Reg, TRI, true);
147
148 // We can't just clear implicit kills, so if we encounter one, stop
149 // looking further.
150 if (KillIdx != -1 && AfterBBI->getOperand(KillIdx).isImplicit()) {
152 << "Encountered an implicit kill, cannot proceed: ");
153 LLVM_DEBUG(AfterBBI->dump());
154 break;
155 }
156
157 if (KillIdx != -1) {
158 assert(!DeadOrKillToUnset && "Shouldn't kill same register twice");
159 DeadOrKillToUnset = &AfterBBI->getOperand(KillIdx);
161 << " Kill flag of " << *DeadOrKillToUnset << " from "
162 << *AfterBBI << " is a unsetting candidate\n");
163 }
164
165 if (!AfterBBI->modifiesRegister(Reg, TRI))
166 continue;
167 // Finish scanning because Reg is overwritten by a non-load
168 // instruction.
169 if (AfterBBI->getOpcode() != Opc)
170 break;
171 assert(AfterBBI->getOperand(0).isReg() &&
172 "Expected a register for the first operand");
173 // Finish scanning because Reg is overwritten by a relocation or a
174 // different value.
175 if (!AfterBBI->getOperand(1).isImm() ||
176 AfterBBI->getOperand(1).getImm() != Imm)
177 break;
178
179 // It loads same immediate value to the same Reg, which is redundant.
180 // We would unset kill flag in previous Reg usage to extend live range
181 // of Reg first, then remove the redundancy.
182 if (DeadOrKillToUnset) {
184 << " Unset dead/kill flag of " << *DeadOrKillToUnset
185 << " from " << *DeadOrKillToUnset->getParent());
186 if (DeadOrKillToUnset->isDef())
187 DeadOrKillToUnset->setIsDead(false);
188 else
189 DeadOrKillToUnset->setIsKill(false);
190 }
191 DeadOrKillToUnset =
192 AfterBBI->findRegisterDefOperand(Reg, TRI, true, true);
193 if (DeadOrKillToUnset)
195 << " Dead flag of " << *DeadOrKillToUnset << " from "
196 << *AfterBBI << " is a unsetting candidate\n");
197 InstrsToErase.insert(&*AfterBBI);
198 LLVM_DEBUG(dbgs() << " Remove redundant load immediate: ";
199 AfterBBI->dump());
200 }
201 }
202
203 for (MachineInstr *MI : InstrsToErase) {
204 MI->eraseFromParent();
205 }
206 NumRemovedInPreEmit += InstrsToErase.size();
207 return !InstrsToErase.empty();
208 }
209
210 // Check if this instruction is a PLDpc that is part of a GOT indirect
211 // access.
212 bool isGOTPLDpc(MachineInstr &Instr) {
213 if (Instr.getOpcode() != PPC::PLDpc)
214 return false;
215
216 // The result must be a register.
217 const MachineOperand &LoadedAddressReg = Instr.getOperand(0);
218 if (!LoadedAddressReg.isReg())
219 return false;
220
221 // Make sure that this is a global symbol.
222 const MachineOperand &SymbolOp = Instr.getOperand(1);
223 if (!SymbolOp.isGlobal())
224 return false;
225
226 // Finally return true only if the GOT flag is present.
227 return PPCInstrInfo::hasGOTFlag(SymbolOp.getTargetFlags());
228 }
229
230 bool addLinkerOpt(MachineBasicBlock &MBB, const TargetRegisterInfo *TRI) {
232 // If the linker opt is disabled then just return.
233 if (!CLOpts->pcrel_linker_opt)
234 return false;
235
236 // Add this linker opt only if we are using PC Relative memops.
237 if (!MF->getSubtarget<PPCSubtarget>().isUsingPCRelativeCalls())
238 return false;
239
240 // Struct to keep track of one def/use pair for a GOT indirect access.
241 struct GOTDefUsePair {
244 Register DefReg;
246 bool StillValid;
247 };
248 // Vector of def/ues pairs in this basic block.
251 bool MadeChange = false;
252
253 // Run through all of the instructions in the basic block and try to
254 // collect potential pairs of GOT indirect access instructions.
255 for (auto BBI = MBB.instr_begin(); BBI != MBB.instr_end(); ++BBI) {
256 // Look for the initial GOT indirect load.
257 if (isGOTPLDpc(*BBI)) {
258 GOTDefUsePair CurrentPair{BBI, MachineBasicBlock::iterator(),
259 BBI->getOperand(0).getReg(),
260 PPC::NoRegister, true};
261 CandPairs.push_back(CurrentPair);
262 continue;
263 }
264
265 // We haven't encountered any new PLD instructions, nothing to check.
266 if (CandPairs.empty())
267 continue;
268
269 // Run through the candidate pairs and see if any of the registers
270 // defined in the PLD instructions are used by this instruction.
271 // Note: the size of CandPairs can change in the loop.
272 for (unsigned Idx = 0; Idx < CandPairs.size(); Idx++) {
273 GOTDefUsePair &Pair = CandPairs[Idx];
274 // The instruction does not use or modify this PLD's def reg,
275 // ignore it.
276 if (!BBI->readsRegister(Pair.DefReg, TRI) &&
277 !BBI->modifiesRegister(Pair.DefReg, TRI))
278 continue;
279
280 // The use needs to be used in the address computation and not
281 // as the register being stored for a store.
282 const MachineOperand *UseOp =
283 hasPCRelativeForm(*BBI) ? &BBI->getOperand(2) : nullptr;
284
285 // Check for a valid use.
286 if (UseOp && UseOp->isReg() && UseOp->getReg() == Pair.DefReg &&
287 UseOp->isUse() && UseOp->isKill()) {
288 Pair.UseInst = BBI;
289 Pair.UseReg = BBI->getOperand(0).getReg();
290 ValidPairs.push_back(Pair);
291 }
292 CandPairs.erase(CandPairs.begin() + Idx);
293 }
294 }
295
296 // Go through all of the pairs and check for any more valid uses.
297 for (auto Pair = ValidPairs.begin(); Pair != ValidPairs.end(); Pair++) {
298 // We shouldn't be here if we don't have a valid pair.
299 assert(Pair->UseInst.isValid() && Pair->StillValid &&
300 "Kept an invalid def/use pair for GOT PCRel opt");
301 // We have found a potential pair. Search through the instructions
302 // between the def and the use to see if it is valid to mark this as a
303 // linker opt.
304 MachineBasicBlock::iterator BBI = Pair->DefInst;
305 ++BBI;
306 for (; BBI != Pair->UseInst; ++BBI) {
307 if (BBI->readsRegister(Pair->UseReg, TRI) ||
308 BBI->modifiesRegister(Pair->UseReg, TRI)) {
309 Pair->StillValid = false;
310 break;
311 }
312 }
313
314 if (!Pair->StillValid)
315 continue;
316
317 // The load/store instruction that uses the address from the PLD will
318 // either use a register (for a store) or define a register (for the
319 // load). That register will be added as an implicit def to the PLD
320 // and as an implicit use on the second memory op. This is a precaution
321 // to prevent future passes from using that register between the two
322 // instructions.
323 MachineOperand ImplDef =
324 MachineOperand::CreateReg(Pair->UseReg, true, true);
325 MachineOperand ImplUse =
326 MachineOperand::CreateReg(Pair->UseReg, false, true);
327 Pair->DefInst->addOperand(ImplDef);
328 Pair->UseInst->addOperand(ImplUse);
329
330 // Create the symbol.
331 MCContext &Context = MF->getContext();
332 MCSymbol *Symbol = Context.createNamedTempSymbol("pcrel");
333 MachineOperand PCRelLabel =
335 Pair->DefInst->addOperand(*MF, PCRelLabel);
336 Pair->UseInst->addOperand(*MF, PCRelLabel);
337 MadeChange |= true;
338 }
339 return MadeChange;
340 }
341
342 // This function removes redundant pairs of accumulator prime/unprime
343 // instructions. In some situations, it's possible the compiler inserts an
344 // accumulator prime instruction followed by an unprime instruction (e.g.
345 // when we store an accumulator after restoring it from a spill). If the
346 // accumulator is not used between the two, they can be removed. This
347 // function removes these redundant pairs from basic blocks.
348 // The algorithm is quite straightforward - every time we encounter a prime
349 // instruction, the primed register is added to a candidate set. Any use
350 // other than a prime removes the candidate from the set and any de-prime
351 // of a current candidate marks both the prime and de-prime for removal.
352 // This way we ensure we only remove prime/de-prime *pairs* with no
353 // intervening uses.
354 bool removeAccPrimeUnprime(MachineBasicBlock &MBB) {
355 DenseSet<MachineInstr *> InstrsToErase;
356 // Initially, none of the acc registers are candidates.
357 SmallVector<MachineInstr *, 8> Candidates(
358 PPC::UACCRCRegClass.getNumRegs(), nullptr);
359
360 for (MachineInstr &BBI : MBB.instrs()) {
361 unsigned Opc = BBI.getOpcode();
362 // If we are visiting a xxmtacc instruction, we add it and its operand
363 // register to the candidate set.
364 if (Opc == PPC::XXMTACC) {
365 Register Acc = BBI.getOperand(0).getReg();
366 assert(PPC::ACCRCRegClass.contains(Acc) &&
367 "Unexpected register for XXMTACC");
368 Candidates[Acc - PPC::ACC0] = &BBI;
369 }
370 // If we are visiting a xxmfacc instruction and its operand register is
371 // in the candidate set, we mark the two instructions for removal.
372 else if (Opc == PPC::XXMFACC) {
373 Register Acc = BBI.getOperand(0).getReg();
374 assert(PPC::ACCRCRegClass.contains(Acc) &&
375 "Unexpected register for XXMFACC");
376 if (!Candidates[Acc - PPC::ACC0])
377 continue;
378 InstrsToErase.insert(&BBI);
379 InstrsToErase.insert(Candidates[Acc - PPC::ACC0]);
380 }
381 // If we are visiting an instruction using an accumulator register
382 // as operand, we remove it from the candidate set.
383 else {
384 for (MachineOperand &Operand : BBI.operands()) {
385 if (!Operand.isReg())
386 continue;
387 Register Reg = Operand.getReg();
388 if (PPC::ACCRCRegClass.contains(Reg))
389 Candidates[Reg - PPC::ACC0] = nullptr;
390 }
391 }
392 }
393
394 for (MachineInstr *MI : InstrsToErase)
395 MI->eraseFromParent();
396 NumRemovedInPreEmit += InstrsToErase.size();
397 return !InstrsToErase.empty();
398 }
399
400 bool runOnMachineFunction(MachineFunction &MF) override {
401 CLOpts = &MF.getSubtarget<PPCSubtarget>().getCLOpts();
402 // If the user wants to set the DSCR using command-line options,
403 // load in the specified value at the start of main.
404 if (CLOpts->set_dscr && MF.getName() == "main" &&
406 uint32_t DSCRValue = *CLOpts->set_dscr & 0x01FFFFFF; // 25-bit DSCR mask
407 RegScavenger RS;
408 MachineBasicBlock &MBB = MF.front();
409 // Find an unused GPR according to register liveness
410 RS.enterBasicBlock(MBB);
411 unsigned InDSCR = RS.FindUnusedReg(&PPC::GPRCRegClass);
412 if (InDSCR) {
413 const PPCInstrInfo *TII =
414 MF.getSubtarget<PPCSubtarget>().getInstrInfo();
415 DebugLoc dl;
416 MachineBasicBlock::iterator IP = MBB.begin(); // Insert Point
417 // Copy the 32-bit DSCRValue integer into the GPR InDSCR using LIS and
418 // ORI, then move to DSCR. If the requested DSCR value is contained
419 // in a 16-bit signed number, we can emit a single `LI`, but the
420 // impact of saving one instruction in one function does not warrant
421 // any additional complexity in the logic here.
422 BuildMI(MBB, IP, dl, TII->get(PPC::LIS), InDSCR)
423 .addImm(DSCRValue >> 16);
424 BuildMI(MBB, IP, dl, TII->get(PPC::ORI), InDSCR)
425 .addReg(InDSCR)
426 .addImm(DSCRValue & 0xFFFF);
427 BuildMI(MBB, IP, dl, TII->get(PPC::MTUDSCR))
428 .addReg(InDSCR, RegState::Kill);
429 } else
430 errs() << "Warning: Ran out of registers - Unable to set DSCR as "
431 "requested";
432 }
433
434 if (skipFunction(MF.getFunction()) || !CLOpts->late_peephole) {
435 // Remove UNENCODED_NOP even when this pass is disabled.
436 // This needs to be done unconditionally so we don't emit zeros
437 // in the instruction stream.
438 SmallVector<MachineInstr *, 4> InstrsToErase;
439 for (MachineBasicBlock &MBB : MF)
440 for (MachineInstr &MI : MBB)
441 if (MI.getOpcode() == PPC::UNENCODED_NOP)
442 InstrsToErase.push_back(&MI);
443 for (MachineInstr *MI : InstrsToErase)
444 MI->eraseFromParent();
445 return false;
446 }
447 bool Changed = false;
448 const PPCInstrInfo *TII = MF.getSubtarget<PPCSubtarget>().getInstrInfo();
449 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
450 SmallVector<MachineInstr *, 4> InstrsToErase;
451 for (MachineBasicBlock &MBB : MF) {
452 Changed |= removeRedundantLIs(MBB, TRI);
453 Changed |= addLinkerOpt(MBB, TRI);
454 Changed |= removeAccPrimeUnprime(MBB);
455 for (MachineInstr &MI : MBB) {
456 unsigned Opc = MI.getOpcode();
457 if (Opc == PPC::UNENCODED_NOP) {
458 InstrsToErase.push_back(&MI);
459 continue;
460 }
461 // Detect self copies - these can result from running AADB.
463 const MCInstrDesc &MCID = TII->get(Opc);
464 if (MCID.getNumOperands() == 3 &&
465 MI.getOperand(0).getReg() == MI.getOperand(1).getReg() &&
466 MI.getOperand(0).getReg() == MI.getOperand(2).getReg()) {
467 NumberOfSelfCopies++;
468 LLVM_DEBUG(dbgs() << "Deleting self-copy instruction: ");
469 LLVM_DEBUG(MI.dump());
470 InstrsToErase.push_back(&MI);
471 continue;
472 }
473 else if (MCID.getNumOperands() == 2 &&
474 MI.getOperand(0).getReg() == MI.getOperand(1).getReg()) {
475 NumberOfSelfCopies++;
476 LLVM_DEBUG(dbgs() << "Deleting self-copy instruction: ");
477 LLVM_DEBUG(MI.dump());
478 InstrsToErase.push_back(&MI);
479 continue;
480 }
481 }
482 MachineInstr *DefMIToErase = nullptr;
483 SmallSet<Register, 4> UpdatedRegs;
484 if (TII->convertToImmediateForm(MI, UpdatedRegs, &DefMIToErase)) {
485 Changed = true;
486 NumRRConvertedInPreEmit++;
487 LLVM_DEBUG(dbgs() << "Converted instruction to imm form: ");
488 LLVM_DEBUG(MI.dump());
489 if (DefMIToErase) {
490 InstrsToErase.push_back(DefMIToErase);
491 }
492 }
493 if (TII->foldFrameOffset(MI)) {
494 Changed = true;
495 NumFrameOffFoldInPreEmit++;
496 LLVM_DEBUG(dbgs() << "Frame offset folding by using index form: ");
497 LLVM_DEBUG(MI.dump());
498 }
499 if (TII->optimizeCmpPostRA(MI)) {
500 Changed = true;
501 NumCmpsInPreEmit++;
502 LLVM_DEBUG(dbgs() << "Optimize compare by using record form: ");
503 LLVM_DEBUG(MI.dump());
504 InstrsToErase.push_back(&MI);
505 }
506 }
507
508 // Eliminate conditional branch based on a constant CR bit by
509 // CRSET or CRUNSET. We eliminate the conditional branch or
510 // convert it into an unconditional branch. Also, if the CR bit
511 // is not used by other instructions, we eliminate CRSET as well.
513 if (I == MBB.instr_end())
514 continue;
515 MachineInstr *Br = &*I;
516 if (Br->getOpcode() != PPC::BC && Br->getOpcode() != PPC::BCn)
517 continue;
518 MachineInstr *CRSetMI = nullptr;
519 Register CRBit = Br->getOperand(0).getReg();
520 unsigned CRReg = getCRFromCRBit(CRBit);
521 bool SeenUse = false;
523 for (It++; It != Er; It++) {
524 if (It->modifiesRegister(CRBit, TRI)) {
525 if ((It->getOpcode() == PPC::CRUNSET ||
526 It->getOpcode() == PPC::CRSET) &&
527 It->getOperand(0).getReg() == CRBit)
528 CRSetMI = &*It;
529 break;
530 }
531 if (It->readsRegister(CRBit, TRI))
532 SeenUse = true;
533 }
534 if (!CRSetMI) continue;
535
536 unsigned CRSetOp = CRSetMI->getOpcode();
537 if ((Br->getOpcode() == PPC::BCn && CRSetOp == PPC::CRSET) ||
538 (Br->getOpcode() == PPC::BC && CRSetOp == PPC::CRUNSET)) {
539 // Remove this branch since it cannot be taken.
540 InstrsToErase.push_back(Br);
542 }
543 else {
544 // This conditional branch is always taken. So, remove all branches
545 // and insert an unconditional branch to the destination of this.
546 MachineBasicBlock::iterator It = Br, Er = MBB.end();
547 for (; It != Er; It++) {
548 if (It->isDebugInstr()) continue;
549 assert(It->isTerminator() && "Non-terminator after a terminator");
550 InstrsToErase.push_back(&*It);
551 }
552 if (!MBB.isLayoutSuccessor(Br->getOperand(1).getMBB())) {
554 TII->insertBranch(MBB, Br->getOperand(1).getMBB(), nullptr,
555 NoCond, Br->getDebugLoc());
556 }
557 for (auto &Succ : MBB.successors())
558 if (Succ != Br->getOperand(1).getMBB()) {
559 MBB.removeSuccessor(Succ);
560 break;
561 }
562 }
563
564 // If the CRBit is not used by another instruction, we can eliminate
565 // CRSET/CRUNSET instruction.
566 if (!SeenUse) {
567 // We need to check use of the CRBit in successors.
568 for (auto &SuccMBB : MBB.successors())
569 if (SuccMBB->isLiveIn(CRBit) || SuccMBB->isLiveIn(CRReg)) {
570 SeenUse = true;
571 break;
572 }
573 if (!SeenUse)
574 InstrsToErase.push_back(CRSetMI);
575 }
576 }
577 for (MachineInstr *MI : InstrsToErase) {
578 LLVM_DEBUG(dbgs() << "PPC pre-emit peephole: erasing instruction: ");
579 LLVM_DEBUG(MI->dump());
580 MI->eraseFromParent();
581 NumRemovedInPreEmit++;
582 }
583 return Changed;
584 }
585 };
586}
587
588INITIALIZE_PASS(PPCPreEmitPeephole, DEBUG_TYPE, "PowerPC Pre-Emit Peephole",
589 false, false)
590char PPCPreEmitPeephole::ID = 0;
591
593 return new PPCPreEmitPeephole();
594}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
uint64_t Imm
MachineBasicBlock & MBB
#define DEBUG_TYPE
static Register UseReg(const MachineOperand &MO)
IRTranslator LLVM IR MI
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
bool hasExternalLinkage() const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
LLVM_ABI void dump() const
LLVM_ABI void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
LLVM_ABI bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
LLVM_ABI instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & front() const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
void setIsDead(bool Val=true)
void setIsKill(bool Val=true)
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
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)
static bool isSameClassPhysRegCopy(unsigned Opcode)
static bool hasGOTFlag(unsigned TF)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:210
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
@ MO_PCREL_OPT_FLAG
MO_PCREL_OPT_FLAG - If this bit is set the operand is part of a PC Relative linker optimization.
Definition PPC.h:141
NodeAddr< InstrNode * > Instr
Definition RDFGraph.h:389
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createPPCPreEmitPeepholePass()
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static unsigned getCRFromCRBit(unsigned SrcReg)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
ArrayRef(const T &OneElt) -> ArrayRef< T >