1 //===- bolt/Passes/FixRISCVCallsPass.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 // 9 // This file declares the FixRISCVCallsPass class, which replaces all types of 10 // calls with PseudoCALL pseudo instructions. This ensures that relaxed calls 11 // get expanded to auipc/jalr pairs so that BOLT can freely reassign function 12 // addresses without having to worry about the limited range of relaxed calls. 13 // Using PseudoCALL also ensures that the RISC-V backend inserts the necessary 14 // relaxation-related relocations to allow JITLink to relax instruction back to 15 // shorter versions where possible. 16 //===----------------------------------------------------------------------===// 17 18 #ifndef BOLT_PASSES_FIXRISCVCALLSPASS_H 19 #define BOLT_PASSES_FIXRISCVCALLSPASS_H 20 21 #include "bolt/Passes/BinaryPasses.h" 22 23 namespace llvm { 24 namespace bolt { 25 26 class FixRISCVCallsPass : public BinaryFunctionPass { 27 void runOnFunction(BinaryFunction &Function); 28 29 public: FixRISCVCallsPass(const cl::opt<bool> & PrintPass)30 explicit FixRISCVCallsPass(const cl::opt<bool> &PrintPass) 31 : BinaryFunctionPass(PrintPass) {} 32 getName()33 const char *getName() const override { return "fix-riscv-calls"; } 34 35 /// Pass entry point 36 Error runOnFunctions(BinaryContext &BC) override; 37 }; 38 39 } // namespace bolt 40 } // namespace llvm 41 42 #endif 43