1 //===- X86MacroFusion.cpp - X86 Macro Fusion ------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \file This file contains the X86 implementation of the DAG scheduling
11 /// mutation to pair instructions back to back.
13 //===----------------------------------------------------------------------===//
15 #include "X86MacroFusion.h"
16 #include "X86Subtarget.h"
17 #include "llvm/CodeGen/MacroFusion.h"
18 #include "llvm/CodeGen/TargetInstrInfo.h"
22 /// Check if the instr pair, FirstMI and SecondMI, should be fused
23 /// together. Given SecondMI, when FirstMI is unspecified, then check if
24 /// SecondMI may be part of a fused pair at all.
25 static bool shouldScheduleAdjacent(const TargetInstrInfo &TII,
26 const TargetSubtargetInfo &TSI,
27 const MachineInstr *FirstMI,
28 const MachineInstr &SecondMI) {
29 const X86Subtarget &ST = static_cast<const X86Subtarget&>(TSI);
30 // Check if this processor supports macro-fusion.
31 if (!ST.hasMacroFusion())
40 unsigned FirstOpcode = FirstMI
41 ? FirstMI->getOpcode()
42 : static_cast<unsigned>(X86::INSTRUCTION_LIST_END);
43 unsigned SecondOpcode = SecondMI.getOpcode();
45 switch (SecondOpcode) {
72 switch (FirstOpcode) {
124 case X86::ADD16ri8_DB:
125 case X86::ADD16ri_DB:
128 case X86::ADD16rr_DB:
131 case X86::ADD32ri8_DB:
132 case X86::ADD32ri_DB:
135 case X86::ADD32rr_DB:
137 case X86::ADD64ri32_DB:
139 case X86::ADD64ri8_DB:
142 case X86::ADD64rr_DB:
161 return FuseKind == FuseCmp || FuseKind == FuseInc;
170 return FuseKind == FuseInc;
171 case X86::INSTRUCTION_LIST_END:
178 std::unique_ptr<ScheduleDAGMutation>
179 createX86MacroFusionDAGMutation () {
180 return createBranchMacroFusionDAGMutation(shouldScheduleAdjacent);
183 } // end namespace llvm