2014-05-24 12:50:23 +00:00
|
|
|
//===--- AArch64StorePairSuppress.cpp --- Suppress store pair formation ---===//
|
2014-03-29 10:18:08 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass identifies floating point stores that should not be combined into
|
|
|
|
// store pairs. Later we may do the same for floating point loads.
|
|
|
|
// ===---------------------------------------------------------------------===//
|
|
|
|
|
2014-05-24 12:50:23 +00:00
|
|
|
#include "AArch64InstrInfo.h"
|
2014-03-29 10:18:08 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineTraceMetrics.h"
|
|
|
|
#include "llvm/CodeGen/TargetSchedule.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-05-22 01:07:18 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2014-03-29 10:18:08 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-05-24 12:50:23 +00:00
|
|
|
#define DEBUG_TYPE "aarch64-stp-suppress"
|
2014-04-22 02:41:26 +00:00
|
|
|
|
2014-03-29 10:18:08 +00:00
|
|
|
namespace {
|
2014-05-24 12:50:23 +00:00
|
|
|
class AArch64StorePairSuppress : public MachineFunctionPass {
|
|
|
|
const AArch64InstrInfo *TII;
|
2014-03-29 10:18:08 +00:00
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
const MachineRegisterInfo *MRI;
|
|
|
|
TargetSchedModel SchedModel;
|
|
|
|
MachineTraceMetrics *Traces;
|
|
|
|
MachineTraceMetrics::Ensemble *MinInstr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
2014-05-24 12:50:23 +00:00
|
|
|
AArch64StorePairSuppress() : MachineFunctionPass(ID) {}
|
2014-03-29 10:18:08 +00:00
|
|
|
|
2014-08-30 16:48:34 +00:00
|
|
|
const char *getPassName() const override {
|
2014-05-24 12:50:23 +00:00
|
|
|
return "AArch64 Store Pair Suppression";
|
2014-03-29 10:18:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-02 18:00:59 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &F) override;
|
2014-03-29 10:18:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool shouldAddSTPToBlock(const MachineBasicBlock *BB);
|
|
|
|
|
2014-04-02 18:00:59 +00:00
|
|
|
bool isNarrowFPStore(const MachineInstr &MI);
|
2014-03-29 10:18:08 +00:00
|
|
|
|
2014-08-30 16:48:34 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2014-03-29 10:18:08 +00:00
|
|
|
AU.setPreservesCFG();
|
|
|
|
AU.addRequired<MachineTraceMetrics>();
|
|
|
|
AU.addPreserved<MachineTraceMetrics>();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
};
|
2014-05-24 12:50:23 +00:00
|
|
|
char AArch64StorePairSuppress::ID = 0;
|
2015-06-23 09:49:53 +00:00
|
|
|
} // anonymous
|
2014-03-29 10:18:08 +00:00
|
|
|
|
2014-05-24 12:50:23 +00:00
|
|
|
FunctionPass *llvm::createAArch64StorePairSuppressPass() {
|
|
|
|
return new AArch64StorePairSuppress();
|
2014-03-29 10:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if an STP can be added to this block without increasing the
|
|
|
|
/// critical resource height. STP is good to form in Ld/St limited blocks and
|
|
|
|
/// bad to form in float-point limited blocks. This is true independent of the
|
|
|
|
/// critical path. If the critical path is longer than the resource height, the
|
|
|
|
/// extra vector ops can limit physreg renaming. Otherwise, it could simply
|
|
|
|
/// oversaturate the vector units.
|
2014-05-24 12:50:23 +00:00
|
|
|
bool AArch64StorePairSuppress::shouldAddSTPToBlock(const MachineBasicBlock *BB) {
|
2014-03-29 10:18:08 +00:00
|
|
|
if (!MinInstr)
|
|
|
|
MinInstr = Traces->getEnsemble(MachineTraceMetrics::TS_MinInstrCount);
|
|
|
|
|
|
|
|
MachineTraceMetrics::Trace BBTrace = MinInstr->getTrace(BB);
|
|
|
|
unsigned ResLength = BBTrace.getResourceLength();
|
|
|
|
|
|
|
|
// Get the machine model's scheduling class for STPQi.
|
|
|
|
// Bypass TargetSchedule's SchedClass resolution since we only have an opcode.
|
2014-05-24 12:50:23 +00:00
|
|
|
unsigned SCIdx = TII->get(AArch64::STPDi).getSchedClass();
|
2014-03-29 10:18:08 +00:00
|
|
|
const MCSchedClassDesc *SCDesc =
|
|
|
|
SchedModel.getMCSchedModel()->getSchedClassDesc(SCIdx);
|
|
|
|
|
|
|
|
// If a subtarget does not define resources for STPQi, bail here.
|
|
|
|
if (SCDesc->isValid() && !SCDesc->isVariant()) {
|
2014-08-27 05:25:25 +00:00
|
|
|
unsigned ResLenWithSTP = BBTrace.getResourceLength(None, SCDesc);
|
2014-03-29 10:18:08 +00:00
|
|
|
if (ResLenWithSTP > ResLength) {
|
|
|
|
DEBUG(dbgs() << " Suppress STP in BB: " << BB->getNumber()
|
|
|
|
<< " resources " << ResLength << " -> " << ResLenWithSTP
|
|
|
|
<< "\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if this is a floating-point store smaller than the V reg. On
|
|
|
|
/// cyclone, these require a vector shuffle before storing a pair.
|
|
|
|
/// Ideally we would call getMatchingPairOpcode() and have the machine model
|
|
|
|
/// tell us if it's profitable with no cpu knowledge here.
|
|
|
|
///
|
|
|
|
/// FIXME: We plan to develop a decent Target abstraction for simple loads and
|
2014-05-24 12:50:23 +00:00
|
|
|
/// stores. Until then use a nasty switch similar to AArch64LoadStoreOptimizer.
|
|
|
|
bool AArch64StorePairSuppress::isNarrowFPStore(const MachineInstr &MI) {
|
2014-04-02 18:00:59 +00:00
|
|
|
switch (MI.getOpcode()) {
|
2014-03-29 10:18:08 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2014-05-24 12:50:23 +00:00
|
|
|
case AArch64::STRSui:
|
|
|
|
case AArch64::STRDui:
|
|
|
|
case AArch64::STURSi:
|
|
|
|
case AArch64::STURDi:
|
2014-03-29 10:18:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 07:54:36 +00:00
|
|
|
bool AArch64StorePairSuppress::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
const TargetSubtargetInfo &ST = MF.getSubtarget();
|
|
|
|
TII = static_cast<const AArch64InstrInfo *>(ST.getInstrInfo());
|
|
|
|
TRI = ST.getRegisterInfo();
|
|
|
|
MRI = &MF.getRegInfo();
|
2014-09-02 17:43:54 +00:00
|
|
|
SchedModel.init(ST.getSchedModel(), &ST, TII);
|
2014-03-29 10:18:08 +00:00
|
|
|
Traces = &getAnalysis<MachineTraceMetrics>();
|
2014-04-25 05:30:21 +00:00
|
|
|
MinInstr = nullptr;
|
2014-03-29 10:18:08 +00:00
|
|
|
|
2015-01-27 07:54:36 +00:00
|
|
|
DEBUG(dbgs() << "*** " << getPassName() << ": " << MF.getName() << '\n');
|
2014-03-29 10:18:08 +00:00
|
|
|
|
|
|
|
if (!SchedModel.hasInstrSchedModel()) {
|
|
|
|
DEBUG(dbgs() << " Skipping pass: no machine model present.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for a sequence of stores to the same base address. We don't need to
|
|
|
|
// precisely determine whether a store pair can be formed. But we do want to
|
|
|
|
// filter out most situations where we can't form store pairs to avoid
|
|
|
|
// computing trace metrics in those cases.
|
2015-01-27 07:54:36 +00:00
|
|
|
for (auto &MBB : MF) {
|
2014-03-29 10:18:08 +00:00
|
|
|
bool SuppressSTP = false;
|
|
|
|
unsigned PrevBaseReg = 0;
|
2014-04-03 23:43:26 +00:00
|
|
|
for (auto &MI : MBB) {
|
2014-04-02 18:00:59 +00:00
|
|
|
if (!isNarrowFPStore(MI))
|
2014-03-29 10:18:08 +00:00
|
|
|
continue;
|
|
|
|
unsigned BaseReg;
|
|
|
|
unsigned Offset;
|
2015-06-15 18:44:14 +00:00
|
|
|
if (TII->getMemOpBaseRegImmOfs(&MI, BaseReg, Offset, TRI)) {
|
2014-03-29 10:18:08 +00:00
|
|
|
if (PrevBaseReg == BaseReg) {
|
|
|
|
// If this block can take STPs, skip ahead to the next block.
|
2014-04-02 18:00:59 +00:00
|
|
|
if (!SuppressSTP && shouldAddSTPToBlock(MI.getParent()))
|
2014-03-29 10:18:08 +00:00
|
|
|
break;
|
|
|
|
// Otherwise, continue unpairing the stores in this block.
|
2014-04-02 18:00:59 +00:00
|
|
|
DEBUG(dbgs() << "Unpairing store " << MI << "\n");
|
2014-03-29 10:18:08 +00:00
|
|
|
SuppressSTP = true;
|
2014-04-02 18:00:59 +00:00
|
|
|
TII->suppressLdStPair(&MI);
|
2014-03-29 10:18:08 +00:00
|
|
|
}
|
|
|
|
PrevBaseReg = BaseReg;
|
|
|
|
} else
|
|
|
|
PrevBaseReg = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// This pass just sets some internal MachineMemOperand flags. It can't really
|
|
|
|
// invalidate anything.
|
|
|
|
return false;
|
|
|
|
}
|