2017-02-01 10:54:34 +08:00
|
|
|
//===- X86MacroFusion.cpp - X86 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-02-01 10:54:34 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2017-06-19 20:53:31 +08:00
|
|
|
/// \file This file contains the X86 implementation of the DAG scheduling
|
|
|
|
/// mutation to pair instructions back to back.
|
2017-02-01 10:54:34 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-12-14 06:21:02 +08:00
|
|
|
#include "X86MacroFusion.h"
|
2020-04-20 20:55:46 +08:00
|
|
|
#include "MCTargetDesc/X86BaseInfo.h"
|
2017-02-01 10:54:34 +08:00
|
|
|
#include "X86Subtarget.h"
|
2017-06-19 20:53:31 +08:00
|
|
|
#include "llvm/CodeGen/MacroFusion.h"
|
2017-11-08 09:01:31 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-02-22 06:16:13 +08:00
|
|
|
|
2017-02-01 10:54:34 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2019-12-05 09:40:11 +08:00
|
|
|
static X86::FirstMacroFusionInstKind classifyFirst(const MachineInstr &MI) {
|
|
|
|
return X86::classifyFirstOpcodeInMacroFusion(MI.getOpcode());
|
2019-03-28 22:12:46 +08:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:40:11 +08:00
|
|
|
static X86::SecondMacroFusionInstKind classifySecond(const MachineInstr &MI) {
|
[X86] Merge the different Jcc instructions for each condition code into single instructions that store the condition code as an operand.
Summary:
This avoids needing an isel pattern for each condition code. And it removes translation switches for converting between Jcc instructions and condition codes.
Now the printer, encoder and disassembler take care of converting the immediate. We use InstAliases to handle the assembly matching. But we print using the asm string in the instruction definition. The instruction itself is marked IsCodeGenOnly=1 to hide it from the assembly parser.
Reviewers: spatel, lebedev.ri, courbet, gchatelet, RKSimon
Reviewed By: RKSimon
Subscribers: MatzeB, qcolombet, eraman, hiraditya, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60228
llvm-svn: 357802
2019-04-06 03:28:09 +08:00
|
|
|
X86::CondCode CC = X86::getCondFromBranch(MI);
|
2019-12-05 09:40:11 +08:00
|
|
|
return X86::classifySecondCondCodeInMacroFusion(CC);
|
2019-03-28 22:12:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if the instr pair, FirstMI and SecondMI, should be fused
|
|
|
|
/// 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 X86Subtarget &ST = static_cast<const X86Subtarget &>(TSI);
|
|
|
|
|
|
|
|
// Check if this processor supports any kind of fusion.
|
|
|
|
if (!(ST.hasBranchFusion() || ST.hasMacroFusion()))
|
|
|
|
return false;
|
|
|
|
|
2019-12-05 09:40:11 +08:00
|
|
|
const X86::SecondMacroFusionInstKind BranchKind = classifySecond(SecondMI);
|
2019-03-28 22:12:46 +08:00
|
|
|
|
2019-12-05 09:40:11 +08:00
|
|
|
if (BranchKind == X86::SecondMacroFusionInstKind::Invalid)
|
2019-03-28 22:12:46 +08:00
|
|
|
return false; // Second cannot be fused with anything.
|
|
|
|
|
|
|
|
if (FirstMI == nullptr)
|
|
|
|
return true; // We're only checking whether Second can be fused at all.
|
|
|
|
|
2019-12-05 09:40:11 +08:00
|
|
|
const X86::FirstMacroFusionInstKind TestKind = classifyFirst(*FirstMI);
|
2019-03-28 22:12:46 +08:00
|
|
|
|
|
|
|
if (ST.hasBranchFusion()) {
|
|
|
|
// Branch fusion can merge CMP and TEST with all conditional jumps.
|
2019-12-05 09:40:11 +08:00
|
|
|
return (TestKind == X86::FirstMacroFusionInstKind::Cmp ||
|
|
|
|
TestKind == X86::FirstMacroFusionInstKind::Test);
|
2019-03-28 22:12:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ST.hasMacroFusion()) {
|
2019-12-05 09:40:11 +08:00
|
|
|
return X86::isMacroFused(TestKind, BranchKind);
|
2017-02-01 10:54:34 +08:00
|
|
|
}
|
2019-03-28 22:12:46 +08:00
|
|
|
|
2019-12-05 09:40:11 +08:00
|
|
|
llvm_unreachable("unknown fusion type");
|
2017-02-01 10:54:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
std::unique_ptr<ScheduleDAGMutation>
|
|
|
|
createX86MacroFusionDAGMutation () {
|
2017-06-19 20:53:31 +08:00
|
|
|
return createBranchMacroFusionDAGMutation(shouldScheduleAdjacent);
|
2017-02-01 10:54:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace llvm
|