LLVM 20.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
21using 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
47 if (BranchKind == X86::SecondMacroFusionInstKind::Invalid)
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 ||
58 TestKind == X86::FirstMacroFusionInstKind::Test);
59 }
60
61 if (ST.hasMacroFusion()) {
62 return X86::isMacroFused(TestKind, BranchKind);
63 }
64
65 llvm_unreachable("unknown fusion type");
66}
67
68namespace llvm {
69
70std::unique_ptr<ScheduleDAGMutation> createX86MacroFusionDAGMutation() {
72 /*BranchOnly=*/true);
73}
74
75} // end namespace llvm
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
static X86::SecondMacroFusionInstKind classifySecond(const MachineInstr &MI)
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.
static X86::FirstMacroFusionInstKind classifyFirst(const MachineInstr &MI)
Representation of each machine instruction.
Definition: MachineInstr.h:69
TargetInstrInfo - Interface to description of machine instruction set.
TargetSubtargetInfo - Generic base class for all target subtargets.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
FirstMacroFusionInstKind classifyFirstOpcodeInMacroFusion(unsigned Opcode)
Definition: X86BaseInfo.h:126
CondCode getCondFromBranch(const MachineInstr &MI)
SecondMacroFusionInstKind
Definition: X86BaseInfo.h:116
FirstMacroFusionInstKind
Definition: X86BaseInfo.h:107
SecondMacroFusionInstKind classifySecondCondCodeInMacroFusion(X86::CondCode CC)
Definition: X86BaseInfo.h:258
bool isMacroFused(FirstMacroFusionInstKind FirstKind, SecondMacroFusionInstKind SecondKind)
Definition: X86BaseInfo.h:290
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::unique_ptr< ScheduleDAGMutation > createMacroFusionDAGMutation(ArrayRef< MacroFusionPredTy > Predicates, bool BranchOnly=false)
Create a DAG scheduling mutation to pair instructions back to back for instructions that benefit acco...
std::unique_ptr< ScheduleDAGMutation > createX86MacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createX86MacroFusionDAGMutation()); to X86PassConfig::crea...
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.