LLVM  14.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"
19 
20 using namespace llvm;
21 
23  return X86::classifyFirstOpcodeInMacroFusion(MI.getOpcode());
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
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
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:209
TargetInstrInfo.h
llvm::X86::getCondFromBranch
CondCode getCondFromBranch(const MachineInstr &MI)
Definition: X86InstrInfo.cpp:2759
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:70
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
X86MacroFusion.h
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
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:64
MacroFusion.h
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
classifySecond
static X86::SecondMacroFusionInstKind classifySecond(const MachineInstr &MI)
Definition: X86MacroFusion.cpp:26
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
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:59
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:22
llvm::X86::FirstMacroFusionInstKind
FirstMacroFusionInstKind
Definition: X86BaseInfo.h:111