//===- MipsMulMulBugPass.cpp - Mips VR4300 mulmul bugfix pass -------------===// // // 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 // //===----------------------------------------------------------------------===// // // Early revisions of the VR4300 have a hardware bug where two consecutive // multiplications can produce an incorrect result in the second multiply. // // This pass scans for mul instructions in each basic block and inserts // a nop whenever the following conditions are met: // // - The current instruction is a single or double-precision floating-point // mul instruction. // - The next instruction is either a mul instruction (any kind) // or a branch instruction. //===----------------------------------------------------------------------===// #include "Mips.h" #include "MipsInstrInfo.h" #include "MipsSubtarget.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Target/TargetMachine.h" #define DEBUG_TYPE … usingnamespacellvm; namespace { class MipsMulMulBugFix : public MachineFunctionPass { … }; } // namespace INITIALIZE_PASS(…) char MipsMulMulBugFix::ID = …; bool MipsMulMulBugFix::runOnMachineFunction(MachineFunction &MF) { … } static bool isFirstMul(const MachineInstr &MI) { … } static bool isSecondMulOrBranch(const MachineInstr &MI) { … } bool MipsMulMulBugFix::fixMulMulBB(MachineBasicBlock &MBB, const MipsInstrInfo &MipsII) { … } FunctionPass *llvm::createMipsMulMulBugPass() { … }