llvm/lib/Target/Sparc/LeonPasses.cpp
Chris Dewhurst 69e68a5966 [Sparc][LEON] LEON Erratum fix. Insert NOP after LD or LDF instruction.
Due to an erratum in some versions of LEON, we must insert a NOP after any LD or LDF instruction to ensure the processor has time to load the value correctly before using it. This pass will implement that erratum fix.

The code will have no effect for other Sparc, but non-LEON processors.

Differential Review: http://reviews.llvm.org/D20353

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270417 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-23 10:56:36 +00:00

80 lines
2.6 KiB
C++
Executable File

//===------ LeonPasses.cpp - Define passes specific to LEON ---------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
#include "LeonPasses.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/ISDOpcodes.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
LEONMachineFunctionPass::LEONMachineFunctionPass(TargetMachine &tm, char& ID) :
MachineFunctionPass(ID)
{
}
LEONMachineFunctionPass::LEONMachineFunctionPass(char& ID) :
MachineFunctionPass(ID)
{
}
//*****************************************************************************
//**** InsertNOPLoad pass
//*****************************************************************************
//This pass inserts a NOP after any LD or LDF instruction.
//
char InsertNOPLoad::ID = 0;
InsertNOPLoad::InsertNOPLoad(TargetMachine &tm) :
LEONMachineFunctionPass(tm, ID)
{
}
bool InsertNOPLoad::runOnMachineFunction(MachineFunction& MF)
{
Subtarget = &MF.getSubtarget<SparcSubtarget>();
const TargetInstrInfo& TII = *Subtarget->getInstrInfo();
DebugLoc DL = DebugLoc();
bool Modified = false;
for (auto MFI = MF.begin(), E = MF.end(); MFI != E; ++MFI) {
MachineBasicBlock &MBB = *MFI;
for (auto MBBI = MBB.begin(), E = MBB.end(); MBBI != E; ++ MBBI) {
MachineInstr &MI = *MBBI;
unsigned Opcode = MI.getOpcode();
if (Opcode >= SP::LDDArr && Opcode <= SP::LDrr) {
//errs() << "Inserting NOP after LD instruction\n";
MachineBasicBlock::iterator NMBBI = std::next(MBBI);
BuildMI(MBB, NMBBI, DL, TII.get(SP::NOP));
Modified = true;
}
else if (MI.isInlineAsm()) {
std::string AsmString (MI.getOperand(InlineAsm::MIOp_AsmString)
.getSymbolName());
std::string LDOpCoode ("ld");
std::transform(AsmString.begin(), AsmString.end(), AsmString.begin(),
::tolower);
if (AsmString.find(LDOpCoode) == 0) { // an inline ld or ldf instruction
//errs() << "Inserting NOP after LD instruction\n";
MachineBasicBlock::iterator NMBBI = std::next(MBBI);
BuildMI(MBB, NMBBI, DL, TII.get(SP::NOP));
Modified = true;
}
}
}
}
return Modified;
}