LLVM  10.0.0
X86MacroFusion.cpp
Go to the documentation of this file.
1 //===- X86MacroFusion.cpp - X86 Macro Fusion ------------------------------===//
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 X86 implementation of the DAG scheduling
10 /// mutation to pair instructions back to back.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "X86MacroFusion.h"
16 #include "X86Subtarget.h"
19 
20 using namespace llvm;
21 
24 }
25 
29 }
30 
31 /// Check if the instr pair, FirstMI and SecondMI, should be fused
32 /// together. Given SecondMI, when FirstMI is unspecified, then check if
33 /// SecondMI may be part of a fused pair at all.
35  const TargetSubtargetInfo &TSI,
36  const MachineInstr *FirstMI,
37  const MachineInstr &SecondMI) {
38  const X86Subtarget &ST = static_cast<const X86Subtarget &>(TSI);
39 
40  // Check if this processor supports any kind of fusion.
41  if (!(ST.hasBranchFusion() || ST.hasMacroFusion()))
42  return false;
43 
44  const X86::SecondMacroFusionInstKind BranchKind = classifySecond(SecondMI);
45 
47  return false; // Second cannot be fused with anything.
48 
49  if (FirstMI == nullptr)
50  return true; // We're only checking whether Second can be fused at all.
51 
52  const X86::FirstMacroFusionInstKind TestKind = classifyFirst(*FirstMI);
53 
54  if (ST.hasBranchFusion()) {
55  // Branch fusion can merge CMP and TEST with all conditional jumps.
56  return (TestKind == X86::FirstMacroFusionInstKind::Cmp ||
58  }
59 
60  if (ST.hasMacroFusion()) {
61  return X86::isMacroFused(TestKind, BranchKind);
62  }
63 
64  llvm_unreachable("unknown fusion type");
65 }
66 
67 namespace llvm {
68 
69 std::unique_ptr<ScheduleDAGMutation>
72 }
73 
74 } // end namespace llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
SecondMacroFusionInstKind
Definition: X86BaseInfo.h:121
SecondMacroFusionInstKind classifySecondCondCodeInMacroFusion(X86::CondCode CC)
Definition: X86BaseInfo.h:282
std::unique_ptr< ScheduleDAGMutation > createX86MacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createX86MacroFusionDAGMutation()); to X86PassConfig::crea...
const HexagonInstrInfo * TII
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
TargetInstrInfo - Interface to description of machine instruction set.
static X86::FirstMacroFusionInstKind classifyFirst(const MachineInstr &MI)
FirstMacroFusionInstKind classifyFirstOpcodeInMacroFusion(unsigned Opcode)
Definition: X86BaseInfo.h:134
static bool shouldScheduleAdjacent(const TargetInstrInfo &TII, const TargetSubtargetInfo &TSI, const MachineInstr *FirstMI, const MachineInstr &SecondMI)
Check if the instr pair, FirstMI and SecondMI, should be fused together.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
CondCode getCondFromBranch(const MachineInstr &MI)
std::unique_ptr< ScheduleDAGMutation > createBranchMacroFusionDAGMutation(ShouldSchedulePredTy shouldScheduleAdjacent)
Create a DAG scheduling mutation to pair branch instructions with one of their predecessors back to b...
FirstMacroFusionInstKind
Definition: X86BaseInfo.h:106
TargetSubtargetInfo - Generic base class for all target subtargets.
Representation of each machine instruction.
Definition: MachineInstr.h:63
bool hasBranchFusion() const
Definition: X86Subtarget.h:672
bool isMacroFused(FirstMacroFusionInstKind FirstKind, SecondMacroFusionInstKind SecondKind)
Definition: X86BaseInfo.h:331
bool hasMacroFusion() const
Definition: X86Subtarget.h:671
IRTranslator LLVM IR MI
static X86::SecondMacroFusionInstKind classifySecond(const MachineInstr &MI)