LLVM 24.0.0git
AMDGPUMacroFusion.cpp
Go to the documentation of this file.
1//===--- AMDGPUMacroFusion.cpp - AMDGPU 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 AMDGPU implementation of the DAG scheduling
10/// mutation to pair instructions back to back.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AMDGPUMacroFusion.h"
15#include "SIInstrInfo.h"
17
18using namespace llvm;
19
20namespace {
21
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.
25static bool shouldScheduleAdjacent(const TargetInstrInfo &TII_,
26 const TargetSubtargetInfo &TSI,
27 const MachineInstr *FirstMI,
28 const MachineInstr &SecondMI,
29 const SDep *Dep) {
30 if (isNonDataDep(Dep))
31 return false;
32 const SIInstrInfo &TII = static_cast<const SIInstrInfo&>(TII_);
33
34 switch (SecondMI.getOpcode()) {
35 case AMDGPU::V_ADDC_U32_e64:
36 case AMDGPU::V_SUBB_U32_e64:
37 case AMDGPU::V_SUBBREV_U32_e64:
38 case AMDGPU::V_CNDMASK_B32_e64:
39 case AMDGPU::V_CNDMASK_B16_t16_e64:
40 case AMDGPU::V_CNDMASK_B16_fake16_e64: {
41 // Try to cluster defs of condition registers to their uses. This improves
42 // the chance VCC will be available which will allow shrinking to VOP2
43 // encodings.
44 if (!FirstMI)
45 return true;
46
47 const MachineBasicBlock &MBB = *FirstMI->getParent();
48 const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
50 const MachineOperand *Src2 = TII.getNamedOperand(SecondMI,
51 AMDGPU::OpName::src2);
52 return FirstMI->definesRegister(Src2->getReg(), TRI);
53 }
54 default:
55 return false;
56 }
57
58 return false;
59}
60
61} // end namespace
62
63
64namespace llvm {
65
66std::unique_ptr<ScheduleDAGMutation> createAMDGPUMacroFusionDAGMutation() {
68}
69
70} // end namespace llvm
MachineBasicBlock & MBB
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Interface definition for SIInstrInfo.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
bool definesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr fully defines the specified register.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterInfo * getTargetRegisterInfo() const
Scheduling dependency.
Definition ScheduleDAG.h:54
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI 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 > createAMDGPUMacroFusionDAGMutation()
Note that you have to add: DAG.addMutation(createAMDGPUMacroFusionDAGMutation()); to AMDGPUTargetMach...
static bool shouldScheduleAdjacent(const TargetInstrInfo &TII, const TargetSubtargetInfo &TSI, const MachineInstr *FirstMI, const MachineInstr &SecondMI, const SDep *Dep)
Check if the instr pair, FirstMI and SecondMI, should be fused together.
LLVM_ABI bool isNonDataDep(const SDep *Dep)
Returns true if Dep is a non-null non-data dependency.