1 //===- ARMMacroFusion.cpp - ARM Macro Fusion ----------------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// \file This file contains the ARM implementation of the DAG scheduling
10 /// mutation to pair instructions back to back.
12 //===----------------------------------------------------------------------===//
14 #include "ARMMacroFusion.h"
15 #include "ARMSubtarget.h"
16 #include "llvm/CodeGen/MacroFusion.h"
17 #include "llvm/CodeGen/TargetInstrInfo.h"
21 // Fuse AES crypto encoding or decoding.
22 static bool isAESPair(const MachineInstr
*FirstMI
,
23 const MachineInstr
&SecondMI
) {
24 // Assume the 1st instr to be a wildcard if it is unspecified.
25 switch(SecondMI
.getOpcode()) {
28 return FirstMI
== nullptr || FirstMI
->getOpcode() == ARM::AESE
;
31 return FirstMI
== nullptr || FirstMI
->getOpcode() == ARM::AESD
;
37 // Fuse literal generation.
38 static bool isLiteralsPair(const MachineInstr
*FirstMI
,
39 const MachineInstr
&SecondMI
) {
40 // Assume the 1st instr to be a wildcard if it is unspecified.
41 if ((FirstMI
== nullptr || FirstMI
->getOpcode() == ARM::MOVi16
) &&
42 SecondMI
.getOpcode() == ARM::MOVTi16
)
48 /// Check if the instr pair, FirstMI and SecondMI, should be fused
49 /// together. Given SecondMI, when FirstMI is unspecified, then check if
50 /// SecondMI may be part of a fused pair at all.
51 static bool shouldScheduleAdjacent(const TargetInstrInfo
&TII
,
52 const TargetSubtargetInfo
&TSI
,
53 const MachineInstr
*FirstMI
,
54 const MachineInstr
&SecondMI
) {
55 const ARMSubtarget
&ST
= static_cast<const ARMSubtarget
&>(TSI
);
57 if (ST
.hasFuseAES() && isAESPair(FirstMI
, SecondMI
))
59 if (ST
.hasFuseLiterals() && isLiteralsPair(FirstMI
, SecondMI
))
65 std::unique_ptr
<ScheduleDAGMutation
> createARMMacroFusionDAGMutation () {
66 return createMacroFusionDAGMutation(shouldScheduleAdjacent
);
69 } // end namespace llvm