1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00
llvm-mirror/lib/Target/Sparc/LeonPasses.cpp

80 lines
2.6 KiB
C++
Raw Normal View History

//===------ 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;
}