1 //===- X86MacroFusion.cpp - X86 Macro Fusion ------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// \file This file contains the X86 implementation of the DAG scheduling
10 /// mutation to pair instructions back to back.
12 //===----------------------------------------------------------------------===//
14 #include "X86MacroFusion.h"
15 #include "X86Subtarget.h"
16 #include "llvm/CodeGen/MacroFusion.h"
17 #include "llvm/CodeGen/TargetInstrInfo.h"
21 /// Check if the instr pair, FirstMI and SecondMI, should be fused
22 /// together. Given SecondMI, when FirstMI is unspecified, then check if
23 /// SecondMI may be part of a fused pair at all.
24 static bool shouldScheduleAdjacent(const TargetInstrInfo
&TII
,
25 const TargetSubtargetInfo
&TSI
,
26 const MachineInstr
*FirstMI
,
27 const MachineInstr
&SecondMI
) {
28 const X86Subtarget
&ST
= static_cast<const X86Subtarget
&>(TSI
);
29 // Check if this processor supports macro-fusion.
30 if (!ST
.hasMacroFusion())
39 unsigned FirstOpcode
= FirstMI
40 ? FirstMI
->getOpcode()
41 : static_cast<unsigned>(X86::INSTRUCTION_LIST_END
);
42 unsigned SecondOpcode
= SecondMI
.getOpcode();
44 switch (SecondOpcode
) {
71 switch (FirstOpcode
) {
123 case X86::ADD16ri8_DB
:
124 case X86::ADD16ri_DB
:
127 case X86::ADD16rr_DB
:
130 case X86::ADD32ri8_DB
:
131 case X86::ADD32ri_DB
:
134 case X86::ADD32rr_DB
:
136 case X86::ADD64ri32_DB
:
138 case X86::ADD64ri8_DB
:
141 case X86::ADD64rr_DB
:
160 return FuseKind
== FuseCmp
|| FuseKind
== FuseInc
;
169 return FuseKind
== FuseInc
;
170 case X86::INSTRUCTION_LIST_END
:
177 std::unique_ptr
<ScheduleDAGMutation
>
178 createX86MacroFusionDAGMutation () {
179 return createBranchMacroFusionDAGMutation(shouldScheduleAdjacent
);
182 } // end namespace llvm