xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/MacroFusion.h (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
1 //===- MacroFusion.h - Macro Fusion -----------------------------*- 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 /// \file This file contains the definition of the DAG scheduling mutation to
10 /// pair instructions back to back.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MACROFUSION_H
15 #define LLVM_CODEGEN_MACROFUSION_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include <memory>
19 
20 namespace llvm {
21 
22 class MachineInstr;
23 class ScheduleDAGMutation;
24 class TargetInstrInfo;
25 class TargetSubtargetInfo;
26 class ScheduleDAGInstrs;
27 class SUnit;
28 
29 /// Check if the instr pair, FirstMI and SecondMI, should be fused
30 /// together. Given SecondMI, when FirstMI is unspecified, then check if
31 /// SecondMI may be part of a fused pair at all.
32 using MacroFusionPredTy = bool (*)(const TargetInstrInfo &TII,
33                                    const TargetSubtargetInfo &STI,
34                                    const MachineInstr *FirstMI,
35                                    const MachineInstr &SecondMI);
36 
37 /// Checks if the number of cluster edges between SU and its predecessors is
38 /// less than FuseLimit
39 bool hasLessThanNumFused(const SUnit &SU, unsigned FuseLimit);
40 
41 /// Create an artificial edge between FirstSU and SecondSU.
42 /// Make data dependencies from the FirstSU also dependent on the SecondSU to
43 /// prevent them from being scheduled between the FirstSU and the SecondSU
44 /// and vice-versa.
45 /// Fusing more than 2 instructions is not currently supported.
46 bool fuseInstructionPair(ScheduleDAGInstrs &DAG, SUnit &FirstSU,
47                          SUnit &SecondSU);
48 
49 /// Create a DAG scheduling mutation to pair instructions back to back
50 /// for instructions that benefit according to the target-specific
51 /// predicate functions. shouldScheduleAdjacent will be true if any of the
52 /// provided predicates are true.
53 /// If BranchOnly is true, only branch instructions with one of their
54 /// predecessors will be fused.
55 std::unique_ptr<ScheduleDAGMutation>
56 createMacroFusionDAGMutation(ArrayRef<MacroFusionPredTy> Predicates,
57                              bool BranchOnly = false);
58 
59 } // end namespace llvm
60 
61 #endif // LLVM_CODEGEN_MACROFUSION_H
62