LLVM  15.0.0git
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 
14 #include "X86MacroFusion.h"
16 #include "X86Subtarget.h"
20 
21 using namespace llvm;
22 
24  return X86::classifyFirstOpcodeInMacroFusion(MI.getOpcode());
25 }
26 
30 }
31 
32 /// Check if the instr pair, FirstMI and SecondMI, should be fused
33 /// together. Given SecondMI, when FirstMI is unspecified, then check if
34 /// SecondMI may be part of a fused pair at all.
36  const TargetSubtargetInfo &TSI,
37  const MachineInstr *FirstMI,
38  const MachineInstr &SecondMI) {
39  const X86Subtarget &ST = static_cast<const X86Subtarget &>(TSI);
40 
41  // Check if this processor supports any kind of fusion.
42  if (!(ST.hasBranchFusion() || ST.hasMacroFusion()))
43  return false;
44 
45  const X86::SecondMacroFusionInstKind BranchKind = classifySecond(SecondMI);
46 
48  return false; // Second cannot be fused with anything.
49 
50  if (FirstMI == nullptr)
51  return true; // We're only checking whether Second can be fused at all.
52 
53  const X86::FirstMacroFusionInstKind TestKind = classifyFirst(*FirstMI);
54 
55  if (ST.hasBranchFusion()) {
56  // Branch fusion can merge CMP and TEST with all conditional jumps.
57  return (TestKind == X86::FirstMacroFusionInstKind::Cmp ||
59  }
60 
61  if (ST.hasMacroFusion()) {
62  return X86::isMacroFused(TestKind, BranchKind);
63  }
64 
65  llvm_unreachable("unknown fusion type");
66 }
67 
68 namespace llvm {
69 
70 std::unique_ptr<ScheduleDAGMutation>
73 }
74 
75 } // end namespace llvm
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
X86Subtarget.h
llvm::X86Subtarget
Definition: X86Subtarget.h:52
llvm::createBranchMacroFusionDAGMutation
std::unique_ptr< ScheduleDAGMutation > createBranchMacroFusionDAGMutation(ShouldSchedulePredTy shouldScheduleAdjacent)
Create a DAG scheduling mutation to pair branch instructions with one of their predecessors back to b...
Definition: MacroFusion.cpp:208
TargetInstrInfo.h
llvm::X86::getCondFromBranch
CondCode getCondFromBranch(const MachineInstr &MI)
Definition: X86InstrInfo.cpp:2708
llvm::X86::CondCode
CondCode
Definition: X86BaseInfo.h:80
llvm::X86::FirstMacroFusionInstKind::Test
@ Test
llvm::createX86MacroFusionDAGMutation
std::unique_ptr< ScheduleDAGMutation > createX86MacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createX86MacroFusionDAGMutation()); to X86PassConfig::crea...
Definition: X86MacroFusion.cpp:71
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
X86MacroFusion.h
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:125
llvm::X86::classifyFirstOpcodeInMacroFusion
FirstMacroFusionInstKind classifyFirstOpcodeInMacroFusion(unsigned Opcode)
Definition: X86BaseInfo.h:140
llvm::shouldScheduleAdjacent
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.
Definition: ARMMacroFusion.cpp:51
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
MacroFusion.h
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
ScheduleDAGMutation.h
classifySecond
static X86::SecondMacroFusionInstKind classifySecond(const MachineInstr &MI)
Definition: X86MacroFusion.cpp:27
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::X86::classifySecondCondCodeInMacroFusion
SecondMacroFusionInstKind classifySecondCondCodeInMacroFusion(X86::CondCode CC)
Definition: X86BaseInfo.h:289
llvm::X86::SecondMacroFusionInstKind::Invalid
@ Invalid
llvm::X86::isMacroFused
bool isMacroFused(FirstMacroFusionInstKind FirstKind, SecondMacroFusionInstKind SecondKind)
Definition: X86BaseInfo.h:338
llvm::TargetSubtargetInfo
TargetSubtargetInfo - Generic base class for all target subtargets.
Definition: TargetSubtargetInfo.h:60
llvm::X86::FirstMacroFusionInstKind::Cmp
@ Cmp
llvm::X86::SecondMacroFusionInstKind
SecondMacroFusionInstKind
Definition: X86BaseInfo.h:127
X86BaseInfo.h
classifyFirst
static X86::FirstMacroFusionInstKind classifyFirst(const MachineInstr &MI)
Definition: X86MacroFusion.cpp:23
llvm::X86::FirstMacroFusionInstKind
FirstMacroFusionInstKind
Definition: X86BaseInfo.h:111