//=- RISCVRedundantCopyElimination.cpp - Remove useless copy for RISC-V -----=// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This pass removes unnecessary zero copies in BBs that are targets of // beqz/bnez instructions. For instance, the copy instruction in the code below // can be removed because the beqz jumps to BB#2 when a0 is zero. // BB#1: // beqz %a0, <BB#2> // BB#2: // %a0 = COPY %x0 // This pass should be run after register allocation. // // This pass is based on the earliest versions of // AArch64RedundantCopyElimination. // // FIXME: Support compares with constants other than zero? This is harder to // do on RISC-V since branches can't have immediates. // //===----------------------------------------------------------------------===// #include "RISCV.h" #include "RISCVInstrInfo.h" #include "llvm/ADT/Statistic.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/Support/Debug.h" usingnamespacellvm; #define DEBUG_TYPE … STATISTIC(NumCopiesRemoved, "Number of copies removed."); namespace { class RISCVRedundantCopyElimination : public MachineFunctionPass { … }; } // end anonymous namespace char RISCVRedundantCopyElimination::ID = …; INITIALIZE_PASS(…) static bool guaranteesZeroRegInBlock(MachineBasicBlock &MBB, const SmallVectorImpl<MachineOperand> &Cond, MachineBasicBlock *TBB) { … } bool RISCVRedundantCopyElimination::optimizeBlock(MachineBasicBlock &MBB) { … } bool RISCVRedundantCopyElimination::runOnMachineFunction(MachineFunction &MF) { … } FunctionPass *llvm::createRISCVRedundantCopyEliminationPass() { … }