mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-24 12:29:33 +00:00
On Nehalem and newer CPUs there is a 2 cycle latency penalty on using a register in a different domain than where it was defined. Some instructions have equvivalents for different domains, like por/orps/orpd. The SSEDomainFix pass tries to minimize the number of domain crossings by changing between equvivalent opcodes where possible. This is a work in progress, in particular the pass doesn't do anything yet. SSE instructions are tagged with their execution domain in TableGen using the last two bits of TSFlags. Note that not all instructions are tagged correctly. Life just isn't that simple. The SSE execution domain issue is very similar to the ARM NEON/VFP pipeline issue handled by NEONMoveFixPass. This pass may become target independent to handle both. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99524 91177308-0d34-0410-b5e6-96231b3b80d8
99 lines
3.0 KiB
C++
99 lines
3.0 KiB
C++
//===- SSEDomainFix.cpp - Use proper int/float domain for SSE ---*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains the SSEDomainFix pass.
|
|
//
|
|
// Some SSE instructions like mov, and, or, xor are available in different
|
|
// variants for different operand types. These variant instructions are
|
|
// equivalent, but on Nehalem and newer cpus there is extra latency
|
|
// transferring data between integer and floating point domains.
|
|
//
|
|
// This pass changes the variant instructions to minimize domain crossings.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#define DEBUG_TYPE "sse-domain-fix"
|
|
#include "X86InstrInfo.h"
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
|
#include "llvm/Support/Debug.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
class SSEDomainFixPass : public MachineFunctionPass {
|
|
static char ID;
|
|
const X86InstrInfo *TII;
|
|
|
|
MachineFunction *MF;
|
|
MachineBasicBlock *MBB;
|
|
public:
|
|
SSEDomainFixPass() : MachineFunctionPass(&ID) {}
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.setPreservesAll();
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
}
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
virtual const char *getPassName() const {
|
|
return "SSE execution domain fixup";
|
|
}
|
|
|
|
private:
|
|
void enterBasicBlock(MachineBasicBlock *MBB);
|
|
};
|
|
}
|
|
|
|
char SSEDomainFixPass::ID = 0;
|
|
|
|
void SSEDomainFixPass::enterBasicBlock(MachineBasicBlock *mbb) {
|
|
MBB = mbb;
|
|
DEBUG(dbgs() << "Entering MBB " << MBB->getName() << "\n");
|
|
}
|
|
|
|
bool SSEDomainFixPass::runOnMachineFunction(MachineFunction &mf) {
|
|
MF = &mf;
|
|
TII = static_cast<const X86InstrInfo*>(MF->getTarget().getInstrInfo());
|
|
|
|
// If no XMM registers are used in the function, we can skip it completely.
|
|
bool XMMIsUsed = false;
|
|
for (TargetRegisterClass::const_iterator I = X86::VR128RegClass.begin(),
|
|
E = X86::VR128RegClass.end(); I != E; ++I)
|
|
if (MF->getRegInfo().isPhysRegUsed(*I)) {
|
|
XMMIsUsed = true;
|
|
break;
|
|
}
|
|
if (!XMMIsUsed) return false;
|
|
|
|
MachineBasicBlock *Entry = MF->begin();
|
|
SmallPtrSet<MachineBasicBlock*, 16> Visited;
|
|
for (df_ext_iterator<MachineBasicBlock*,
|
|
SmallPtrSet<MachineBasicBlock*, 16> >
|
|
DFI = df_ext_begin(Entry, Visited), DFE = df_ext_end(Entry, Visited);
|
|
DFI != DFE; ++DFI) {
|
|
enterBasicBlock(*DFI);
|
|
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;
|
|
++I) {
|
|
MachineInstr *MI = I;
|
|
const unsigned *equiv = 0;
|
|
X86InstrInfo::SSEDomain domain = TII->GetSSEDomain(MI, equiv);
|
|
DEBUG(dbgs() << "-isd"[domain] << (equiv ? "* " : " ") << *MI);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
FunctionPass *llvm::createSSEDomainFixPass() {
|
|
return new SSEDomainFixPass();
|
|
}
|