1 //===- ARMMacroFusion.cpp - ARM Macro Fusion ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \file This file contains the ARM implementation of the DAG scheduling
11 /// mutation to pair instructions back to back.
13 //===----------------------------------------------------------------------===//
15 #include "ARMMacroFusion.h"
16 #include "ARMSubtarget.h"
17 #include "llvm/CodeGen/MacroFusion.h"
18 #include "llvm/CodeGen/TargetInstrInfo.h"
22 // Fuse AES crypto encoding or decoding.
23 static bool isAESPair(const MachineInstr *FirstMI,
24 const MachineInstr &SecondMI) {
25 // Assume the 1st instr to be a wildcard if it is unspecified.
26 switch(SecondMI.getOpcode()) {
29 return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESE;
32 return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESD;
38 // Fuse literal generation.
39 static bool isLiteralsPair(const MachineInstr *FirstMI,
40 const MachineInstr &SecondMI) {
41 // Assume the 1st instr to be a wildcard if it is unspecified.
42 if ((FirstMI == nullptr || FirstMI->getOpcode() == ARM::MOVi16) &&
43 SecondMI.getOpcode() == ARM::MOVTi16)
49 /// Check if the instr pair, FirstMI and SecondMI, should be fused
50 /// together. Given SecondMI, when FirstMI is unspecified, then check if
51 /// SecondMI may be part of a fused pair at all.
52 static 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);
58 if (ST.hasFuseAES() && isAESPair(FirstMI, SecondMI))
60 if (ST.hasFuseLiterals() && isLiteralsPair(FirstMI, SecondMI))
66 std::unique_ptr<ScheduleDAGMutation> createARMMacroFusionDAGMutation () {
67 return createMacroFusionDAGMutation(shouldScheduleAdjacent);
70 } // end namespace llvm