blob: df1da9d8e4744ac2a4fad78a64dac00fa8d0d5ef [file] [log] [blame]
Florian Hahnb489e562017-06-22 09:39:36 +00001//===- ARMMacroFusion.cpp - ARM Macro Fusion ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file This file contains the ARM implementation of the DAG scheduling
11/// mutation to pair instructions back to back.
12//
13//===----------------------------------------------------------------------===//
14
Michael Zolotukhin67b04bd2017-12-13 22:21:02 +000015#include "ARMMacroFusion.h"
Florian Hahnb489e562017-06-22 09:39:36 +000016#include "ARMSubtarget.h"
17#include "llvm/CodeGen/MacroFusion.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000018#include "llvm/CodeGen/TargetInstrInfo.h"
Florian Hahnb489e562017-06-22 09:39:36 +000019
20namespace llvm {
21
Evandro Menezesfcca45f2018-07-27 18:16:47 +000022// Fuse AES crypto encoding or decoding.
23static bool isAESPair(const MachineInstr *FirstMI,
24 const MachineInstr &SecondMI) {
25 // Assume the 1st instr to be a wildcard if it is unspecified.
Evandro Menezes46eadcf2018-10-16 17:19:51 +000026 switch(SecondMI.getOpcode()) {
Evandro Menezesfcca45f2018-07-27 18:16:47 +000027 // AES encode.
28 case ARM::AESMC :
Evandro Menezes46eadcf2018-10-16 17:19:51 +000029 return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESE;
Evandro Menezesfcca45f2018-07-27 18:16:47 +000030 // AES decode.
31 case ARM::AESIMC:
Evandro Menezes46eadcf2018-10-16 17:19:51 +000032 return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESD;
Evandro Menezesfcca45f2018-07-27 18:16:47 +000033 }
34
35 return false;
36}
37
38// Fuse literal generation.
39static bool isLiteralsPair(const MachineInstr *FirstMI,
40 const MachineInstr &SecondMI) {
41 // Assume the 1st instr to be a wildcard if it is unspecified.
Evandro Menezes46eadcf2018-10-16 17:19:51 +000042 if ((FirstMI == nullptr || FirstMI->getOpcode() == ARM::MOVi16) &&
43 SecondMI.getOpcode() == ARM::MOVTi16)
Evandro Menezesfcca45f2018-07-27 18:16:47 +000044 return true;
45
46 return false;
47}
48
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000049/// Check if the instr pair, FirstMI and SecondMI, should be fused
Florian Hahnb489e562017-06-22 09:39:36 +000050/// together. Given SecondMI, when FirstMI is unspecified, then check if
51/// SecondMI may be part of a fused pair at all.
52static bool shouldScheduleAdjacent(const TargetInstrInfo &TII,
53 const TargetSubtargetInfo &TSI,
54 const MachineInstr *FirstMI,
55 const MachineInstr &SecondMI) {
56 const ARMSubtarget &ST = static_cast<const ARMSubtarget&>(TSI);
57
Evandro Menezesfcca45f2018-07-27 18:16:47 +000058 if (ST.hasFuseAES() && isAESPair(FirstMI, SecondMI))
59 return true;
60 if (ST.hasFuseLiterals() && isLiteralsPair(FirstMI, SecondMI))
61 return true;
Florian Hahnb489e562017-06-22 09:39:36 +000062
63 return false;
64}
65
66std::unique_ptr<ScheduleDAGMutation> createARMMacroFusionDAGMutation () {
67 return createMacroFusionDAGMutation(shouldScheduleAdjacent);
68}
69
70} // end namespace llvm