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