//===---- HexagonFixupHwLoops.cpp - Fixup HW loops too far from LOOPn. ----===// // // 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 // // The loop start address in the LOOPn instruction is encoded as a distance // from the LOOPn instruction itself. If the start address is too far from // the LOOPn instruction, the instruction needs to use a constant extender. // This pass will identify and convert such LOOPn instructions to a proper // form. //===----------------------------------------------------------------------===// #include "Hexagon.h" #include "HexagonTargetMachine.h" #include "llvm/ADT/DenseMap.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/Support/MathExtras.h" #include "llvm/Pass.h" usingnamespacellvm; static cl::opt<unsigned> MaxLoopRange( "hexagon-loop-range", cl::Hidden, cl::init(200), cl::desc("Restrict range of loopN instructions (testing only)")); namespace llvm { FunctionPass *createHexagonFixupHwLoops(); void initializeHexagonFixupHwLoopsPass(PassRegistry&); } namespace { struct HexagonFixupHwLoops : public MachineFunctionPass { … }; char HexagonFixupHwLoops::ID = …; } INITIALIZE_PASS(…) FunctionPass *llvm::createHexagonFixupHwLoops() { … } /// Returns true if the instruction is a hardware loop instruction. static bool isHardwareLoop(const MachineInstr &MI) { … } bool HexagonFixupHwLoops::runOnMachineFunction(MachineFunction &MF) { … } /// For Hexagon, if the loop label is to far from the /// loop instruction then we need to set the LC0 and SA0 registers /// explicitly instead of using LOOP(start,count). This function /// checks the distance, and generates register assignments if needed. /// /// This function makes two passes over the basic blocks. The first /// pass computes the offset of the basic block from the start. /// The second pass checks all the loop instructions. bool HexagonFixupHwLoops::fixupLoopInstrs(MachineFunction &MF) { … } /// Replace loop instructions with the constant extended version. void HexagonFixupHwLoops::useExtLoopInstr(MachineFunction &MF, MachineBasicBlock::iterator &MII) { … }