xref: /llvm-project/bolt/include/bolt/Passes/ThreeWayBranch.h (revision a5f3d1a803020167bd9d494a8a3921e7dcc1550a)
1 //===- bolt/Passes/ThreeWayBranch.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 #ifndef BOLT_PASSES_THREEWAYBRANCH_H
10 #define BOLT_PASSES_THREEWAYBRANCH_H
11 
12 #include "bolt/Passes/BinaryPasses.h"
13 
14 namespace llvm {
15 namespace bolt {
16 
17 /// Pass for optimizing a three way branch namely a single comparison and 2
18 /// conditional jumps by reordering blocks, replacing successors, and replacing
19 /// jump conditions and destinations
20 class ThreeWayBranch : public BinaryFunctionPass {
21   /// Record how many 3 way branches were adjusted
22   uint64_t BranchesAltered = 0;
23 
24   /// Returns true if this pass should run on Function
25   bool shouldRunOnFunction(BinaryFunction &Function);
26 
27   /// Runs pass on Function
28   void runOnFunction(BinaryFunction &Function);
29 
30 public:
ThreeWayBranch()31   explicit ThreeWayBranch() : BinaryFunctionPass(false) {}
32 
getName()33   const char *getName() const override { return "three way branch"; }
34 
35   Error runOnFunctions(BinaryContext &BC) override;
36 };
37 
38 } // namespace bolt
39 } // namespace llvm
40 
41 #endif
42