blob: 38bf28ba8219b9016524d5d15d3188ab4ff39727 [file] [log] [blame]
Florian Hahn7ebe2a22017-06-22 09:39:36 +00001//===- ARMMacroFusion.cpp - ARM Macro Fusion ----------------------===//
2//
Chandler Carruth6b547682019-01-19 08:50:56 +00003// 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
Florian Hahn7ebe2a22017-06-22 09:39:36 +00006//
7//===----------------------------------------------------------------------===//
8//
9/// \file This file contains the ARM implementation of the DAG scheduling
10/// mutation to pair instructions back to back.
11//
12//===----------------------------------------------------------------------===//
13
Michael Zolotukhin9d2ef852017-12-13 22:21:02 +000014#include "ARMMacroFusion.h"
Florian Hahn7ebe2a22017-06-22 09:39:36 +000015#include "ARMSubtarget.h"
16#include "llvm/CodeGen/MacroFusion.h"
David Blaikie48319232017-11-08 01:01:31 +000017#include "llvm/CodeGen/TargetInstrInfo.h"
Florian Hahn7ebe2a22017-06-22 09:39:36 +000018
19namespace llvm {
20
Evandro Menezesdd4e0832018-07-27 18:16:47 +000021// Fuse AES crypto encoding or decoding.
22static bool isAESPair(const MachineInstr *FirstMI,
23 const MachineInstr &SecondMI) {
24 // Assume the 1st instr to be a wildcard if it is unspecified.
Evandro Menezesae406302018-10-16 17:19:51 +000025 switch(SecondMI.getOpcode()) {
Evandro Menezesdd4e0832018-07-27 18:16:47 +000026 // AES encode.
27 case ARM::AESMC :
Evandro Menezesae406302018-10-16 17:19:51 +000028 return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESE;
Evandro Menezesdd4e0832018-07-27 18:16:47 +000029 // AES decode.
30 case ARM::AESIMC:
Evandro Menezesae406302018-10-16 17:19:51 +000031 return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESD;
Evandro Menezesdd4e0832018-07-27 18:16:47 +000032 }
33
34 return false;
35}
36
37// Fuse literal generation.
38static bool isLiteralsPair(const MachineInstr *FirstMI,
39 const MachineInstr &SecondMI) {
40 // Assume the 1st instr to be a wildcard if it is unspecified.
Evandro Menezesae406302018-10-16 17:19:51 +000041 if ((FirstMI == nullptr || FirstMI->getOpcode() == ARM::MOVi16) &&
42 SecondMI.getOpcode() == ARM::MOVTi16)
Evandro Menezesdd4e0832018-07-27 18:16:47 +000043 return true;
44
45 return false;
46}
47
Adrian Prantl26b584c2018-05-01 15:54:18 +000048/// Check if the instr pair, FirstMI and SecondMI, should be fused
Florian Hahn7ebe2a22017-06-22 09:39:36 +000049/// together. Given SecondMI, when FirstMI is unspecified, then check if
50/// SecondMI may be part of a fused pair at all.
51static 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);
56
Evandro Menezesdd4e0832018-07-27 18:16:47 +000057 if (ST.hasFuseAES() && isAESPair(FirstMI, SecondMI))
58 return true;
59 if (ST.hasFuseLiterals() && isLiteralsPair(FirstMI, SecondMI))
60 return true;
Florian Hahn7ebe2a22017-06-22 09:39:36 +000061
62 return false;
63}
64
65std::unique_ptr<ScheduleDAGMutation> createARMMacroFusionDAGMutation () {
66 return createMacroFusionDAGMutation(shouldScheduleAdjacent);
67}
68
69} // end namespace llvm