2017-06-22 17:39:36 +08:00
|
|
|
//===- ARMMacroFusion.cpp - ARM Macro Fusion ----------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-06-22 17:39:36 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file This file contains the ARM implementation of the DAG scheduling
|
|
|
|
/// mutation to pair instructions back to back.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-12-14 06:21:02 +08:00
|
|
|
#include "ARMMacroFusion.h"
|
2017-06-22 17:39:36 +08:00
|
|
|
#include "ARMSubtarget.h"
|
|
|
|
#include "llvm/CodeGen/MacroFusion.h"
|
2017-11-08 09:01:31 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-06-22 17:39:36 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2018-07-28 02:16:47 +08:00
|
|
|
// Fuse AES crypto encoding or decoding.
|
|
|
|
static bool isAESPair(const MachineInstr *FirstMI,
|
|
|
|
const MachineInstr &SecondMI) {
|
|
|
|
// Assume the 1st instr to be a wildcard if it is unspecified.
|
2018-10-17 01:19:51 +08:00
|
|
|
switch(SecondMI.getOpcode()) {
|
2018-07-28 02:16:47 +08:00
|
|
|
// AES encode.
|
|
|
|
case ARM::AESMC :
|
2018-10-17 01:19:51 +08:00
|
|
|
return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESE;
|
2018-07-28 02:16:47 +08:00
|
|
|
// AES decode.
|
|
|
|
case ARM::AESIMC:
|
2018-10-17 01:19:51 +08:00
|
|
|
return FirstMI == nullptr || FirstMI->getOpcode() == ARM::AESD;
|
2018-07-28 02:16:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fuse literal generation.
|
|
|
|
static bool isLiteralsPair(const MachineInstr *FirstMI,
|
|
|
|
const MachineInstr &SecondMI) {
|
|
|
|
// Assume the 1st instr to be a wildcard if it is unspecified.
|
2018-10-17 01:19:51 +08:00
|
|
|
if ((FirstMI == nullptr || FirstMI->getOpcode() == ARM::MOVi16) &&
|
|
|
|
SecondMI.getOpcode() == ARM::MOVTi16)
|
2018-07-28 02:16:47 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Check if the instr pair, FirstMI and SecondMI, should be fused
|
2017-06-22 17:39:36 +08:00
|
|
|
/// together. Given SecondMI, when FirstMI is unspecified, then check if
|
|
|
|
/// SecondMI may be part of a fused pair at all.
|
|
|
|
static bool shouldScheduleAdjacent(const TargetInstrInfo &TII,
|
|
|
|
const TargetSubtargetInfo &TSI,
|
|
|
|
const MachineInstr *FirstMI,
|
|
|
|
const MachineInstr &SecondMI) {
|
|
|
|
const ARMSubtarget &ST = static_cast<const ARMSubtarget&>(TSI);
|
|
|
|
|
2018-07-28 02:16:47 +08:00
|
|
|
if (ST.hasFuseAES() && isAESPair(FirstMI, SecondMI))
|
|
|
|
return true;
|
|
|
|
if (ST.hasFuseLiterals() && isLiteralsPair(FirstMI, SecondMI))
|
|
|
|
return true;
|
2017-06-22 17:39:36 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<ScheduleDAGMutation> createARMMacroFusionDAGMutation () {
|
|
|
|
return createMacroFusionDAGMutation(shouldScheduleAdjacent);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace llvm
|