1 //===- HardwareLoops.h ------------------------------------------*- C++ -*-===// 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 /// \file 9 /// 10 /// Defines an IR pass for the creation of hardware loops. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CODEGEN_HARDWARELOOPS_H 15 #define LLVM_CODEGEN_HARDWARELOOPS_H 16 17 #include "llvm/IR/PassManager.h" 18 19 namespace llvm { 20 21 struct HardwareLoopOptions { 22 std::optional<unsigned> Decrement; 23 std::optional<unsigned> Bitwidth; 24 std::optional<bool> Force; 25 std::optional<bool> ForcePhi; 26 std::optional<bool> ForceNested; 27 std::optional<bool> ForceGuard; 28 setDecrementHardwareLoopOptions29 HardwareLoopOptions &setDecrement(unsigned Count) { 30 Decrement = Count; 31 return *this; 32 } setCounterBitwidthHardwareLoopOptions33 HardwareLoopOptions &setCounterBitwidth(unsigned Width) { 34 Bitwidth = Width; 35 return *this; 36 } setForceHardwareLoopOptions37 HardwareLoopOptions &setForce(bool Force) { 38 this->Force = Force; 39 return *this; 40 } setForcePhiHardwareLoopOptions41 HardwareLoopOptions &setForcePhi(bool Force) { 42 ForcePhi = Force; 43 return *this; 44 } setForceNestedHardwareLoopOptions45 HardwareLoopOptions &setForceNested(bool Force) { 46 ForceNested = Force; 47 return *this; 48 } setForceGuardHardwareLoopOptions49 HardwareLoopOptions &setForceGuard(bool Force) { 50 ForceGuard = Force; 51 return *this; 52 } getForcePhiHardwareLoopOptions53 bool getForcePhi() const { 54 return ForcePhi.has_value() && ForcePhi.value(); 55 } getForceNestedHardwareLoopOptions56 bool getForceNested() const { 57 return ForceNested.has_value() && ForceNested.value(); 58 } getForceGuardHardwareLoopOptions59 bool getForceGuard() const { 60 return ForceGuard.has_value() && ForceGuard.value(); 61 } 62 }; 63 64 class HardwareLoopsPass : public PassInfoMixin<HardwareLoopsPass> { 65 HardwareLoopOptions Opts; 66 67 public: 68 explicit HardwareLoopsPass(HardwareLoopOptions Opts = {}) Opts(Opts)69 : Opts(Opts) { } 70 71 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 72 }; 73 74 } // end namespace llvm 75 76 #endif // LLVM_CODEGEN_HARDWARELOOPS_H 77