blob: d11fe9d5c502dccfc575c0a00432010eb0072cb8 [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.
26 unsigned FirstOpcode =
27 FirstMI ? FirstMI->getOpcode()
28 : static_cast<unsigned>(ARM::INSTRUCTION_LIST_END);
29 unsigned SecondOpcode = SecondMI.getOpcode();
30
31 switch(SecondOpcode) {
32 // AES encode.
33 case ARM::AESMC :
34 return FirstOpcode == ARM::AESE ||
35 FirstOpcode == ARM::INSTRUCTION_LIST_END;
36 // AES decode.
37 case ARM::AESIMC:
38 return FirstOpcode == ARM::AESD ||
39 FirstOpcode == ARM::INSTRUCTION_LIST_END;
40 }
41
42 return false;
43}
44
45// Fuse literal generation.
46static bool isLiteralsPair(const MachineInstr *FirstMI,
47 const MachineInstr &SecondMI) {
48 // Assume the 1st instr to be a wildcard if it is unspecified.
49 unsigned FirstOpcode =
50 FirstMI ? FirstMI->getOpcode()
51 : static_cast<unsigned>(ARM::INSTRUCTION_LIST_END);
52 unsigned SecondOpcode = SecondMI.getOpcode();
53
54 // 32 bit immediate.
55 if ((FirstOpcode == ARM::INSTRUCTION_LIST_END ||
56 FirstOpcode == ARM::MOVi16) &&
57 SecondOpcode == ARM::MOVTi16)
58 return true;
59
60 return false;
61}
62
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000063/// Check if the instr pair, FirstMI and SecondMI, should be fused
Florian Hahnb489e562017-06-22 09:39:36 +000064/// together. Given SecondMI, when FirstMI is unspecified, then check if
65/// SecondMI may be part of a fused pair at all.
66static bool shouldScheduleAdjacent(const TargetInstrInfo &TII,
67 const TargetSubtargetInfo &TSI,
68 const MachineInstr *FirstMI,
69 const MachineInstr &SecondMI) {
70 const ARMSubtarget &ST = static_cast<const ARMSubtarget&>(TSI);
71
Evandro Menezesfcca45f2018-07-27 18:16:47 +000072 if (ST.hasFuseAES() && isAESPair(FirstMI, SecondMI))
73 return true;
74 if (ST.hasFuseLiterals() && isLiteralsPair(FirstMI, SecondMI))
75 return true;
Florian Hahnb489e562017-06-22 09:39:36 +000076
77 return false;
78}
79
80std::unique_ptr<ScheduleDAGMutation> createARMMacroFusionDAGMutation () {
81 return createMacroFusionDAGMutation(shouldScheduleAdjacent);
82}
83
84} // end namespace llvm