mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
Give AsmPrinter the most common expected implementation of
runOnMachineFunction, and switch PPC to use EmitFunctionBody. The two ppc asmprinters now don't heave to define runOnMachineFunction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94722 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -207,6 +207,15 @@ namespace llvm {
|
|||||||
unsigned AsmVariant,
|
unsigned AsmVariant,
|
||||||
const char *ExtraCode);
|
const char *ExtraCode);
|
||||||
|
|
||||||
|
/// runOnMachineFunction - Emit the specified function out to the
|
||||||
|
/// OutStreamer.
|
||||||
|
virtual bool runOnMachineFunction(MachineFunction &MF) {
|
||||||
|
SetupMachineFunction(MF);
|
||||||
|
EmitFunctionHeader();
|
||||||
|
EmitFunctionBody();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// SetupMachineFunction - This should be called when a new MachineFunction
|
/// SetupMachineFunction - This should be called when a new MachineFunction
|
||||||
/// is being processed from runOnMachineFunction.
|
/// is being processed from runOnMachineFunction.
|
||||||
void SetupMachineFunction(MachineFunction &MF);
|
void SetupMachineFunction(MachineFunction &MF);
|
||||||
|
@@ -344,7 +344,6 @@ void AsmPrinter::EmitFunctionEntryLabel() {
|
|||||||
/// EmitFunctionBody - This method emits the body and trailer for a
|
/// EmitFunctionBody - This method emits the body and trailer for a
|
||||||
/// function.
|
/// function.
|
||||||
void AsmPrinter::EmitFunctionBody() {
|
void AsmPrinter::EmitFunctionBody() {
|
||||||
|
|
||||||
// Print out code for the function.
|
// Print out code for the function.
|
||||||
bool HasAnyRealCode = false;
|
bool HasAnyRealCode = false;
|
||||||
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
|
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
|
||||||
@@ -374,8 +373,8 @@ void AsmPrinter::EmitFunctionBody() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the function is empty and the object file uses .subsections_via_symbols,
|
// If the function is empty and the object file uses .subsections_via_symbols,
|
||||||
// then we need to emit *some* thing to the function body to prevent the
|
// then we need to emit *something* to the function body to prevent the
|
||||||
// labels from collapsing together.
|
// labels from collapsing together. Just emit a 0 byte.
|
||||||
if (MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode)
|
if (MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode)
|
||||||
OutStreamer.EmitIntValue(0, 1, 0/*addrspace*/);
|
OutStreamer.EmitIntValue(0, 1, 0/*addrspace*/);
|
||||||
|
|
||||||
|
@@ -256,12 +256,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
AFI = MF.getInfo<ARMFunctionInfo>();
|
AFI = MF.getInfo<ARMFunctionInfo>();
|
||||||
MCP = MF.getConstantPool();
|
MCP = MF.getConstantPool();
|
||||||
|
|
||||||
SetupMachineFunction(MF);
|
return AsmPrinter::runOnMachineFunction(MF);
|
||||||
O << "\n";
|
|
||||||
|
|
||||||
EmitFunctionHeader();
|
|
||||||
EmitFunctionBody();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
|
void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
|
||||||
|
@@ -47,14 +47,11 @@
|
|||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/FormattedStream.h"
|
#include "llvm/Support/FormattedStream.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
|
||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/ADT/StringSet.h"
|
#include "llvm/ADT/StringSet.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class PPCAsmPrinter : public AsmPrinter {
|
class PPCAsmPrinter : public AsmPrinter {
|
||||||
protected:
|
protected:
|
||||||
@@ -98,7 +95,7 @@ namespace {
|
|||||||
static const char *getRegisterName(unsigned RegNo);
|
static const char *getRegisterName(unsigned RegNo);
|
||||||
|
|
||||||
|
|
||||||
void printMachineInstruction(const MachineInstr *MI);
|
virtual void EmitInstruction(const MachineInstr *MI);
|
||||||
void printOp(const MachineOperand &MO);
|
void printOp(const MachineOperand &MO);
|
||||||
|
|
||||||
/// stripRegisterPrefix - This method strips the character prefix from a
|
/// stripRegisterPrefix - This method strips the character prefix from a
|
||||||
@@ -332,7 +329,6 @@ namespace {
|
|||||||
return "Linux PPC Assembly Printer";
|
return "Linux PPC Assembly Printer";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnMachineFunction(MachineFunction &F);
|
|
||||||
bool doFinalization(Module &M);
|
bool doFinalization(Module &M);
|
||||||
|
|
||||||
virtual void EmitFunctionEntryLabel();
|
virtual void EmitFunctionEntryLabel();
|
||||||
@@ -358,7 +354,6 @@ namespace {
|
|||||||
return "Darwin PPC Assembly Printer";
|
return "Darwin PPC Assembly Printer";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnMachineFunction(MachineFunction &F);
|
|
||||||
bool doFinalization(Module &M);
|
bool doFinalization(Module &M);
|
||||||
void EmitStartOfAsmFile(Module &M);
|
void EmitStartOfAsmFile(Module &M);
|
||||||
|
|
||||||
@@ -535,20 +530,16 @@ void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
|
/// EmitInstruction -- Print out a single PowerPC MI in Darwin syntax to
|
||||||
/// the current output stream.
|
/// the current output stream.
|
||||||
///
|
///
|
||||||
void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||||
++EmittedInsts;
|
|
||||||
|
|
||||||
processDebugLoc(MI, true);
|
|
||||||
|
|
||||||
// Check for slwi/srwi mnemonics.
|
// Check for slwi/srwi mnemonics.
|
||||||
bool useSubstituteMnemonic = false;
|
|
||||||
if (MI->getOpcode() == PPC::RLWINM) {
|
if (MI->getOpcode() == PPC::RLWINM) {
|
||||||
unsigned char SH = MI->getOperand(2).getImm();
|
unsigned char SH = MI->getOperand(2).getImm();
|
||||||
unsigned char MB = MI->getOperand(3).getImm();
|
unsigned char MB = MI->getOperand(3).getImm();
|
||||||
unsigned char ME = MI->getOperand(4).getImm();
|
unsigned char ME = MI->getOperand(4).getImm();
|
||||||
|
bool useSubstituteMnemonic = false;
|
||||||
if (SH <= 31 && MB == 0 && ME == (31-SH)) {
|
if (SH <= 31 && MB == 0 && ME == (31-SH)) {
|
||||||
O << "\tslwi "; useSubstituteMnemonic = true;
|
O << "\tslwi "; useSubstituteMnemonic = true;
|
||||||
}
|
}
|
||||||
@@ -561,37 +552,34 @@ void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
|||||||
O << ", ";
|
O << ", ";
|
||||||
printOperand(MI, 1);
|
printOperand(MI, 1);
|
||||||
O << ", " << (unsigned int)SH;
|
O << ", " << (unsigned int)SH;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) {
|
}
|
||||||
if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
|
|
||||||
useSubstituteMnemonic = true;
|
if ((MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) &&
|
||||||
O << "\tmr ";
|
MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
|
||||||
printOperand(MI, 0);
|
O << "\tmr ";
|
||||||
O << ", ";
|
printOperand(MI, 0);
|
||||||
printOperand(MI, 1);
|
O << ", ";
|
||||||
}
|
printOperand(MI, 1);
|
||||||
} else if (MI->getOpcode() == PPC::RLDICR) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MI->getOpcode() == PPC::RLDICR) {
|
||||||
unsigned char SH = MI->getOperand(2).getImm();
|
unsigned char SH = MI->getOperand(2).getImm();
|
||||||
unsigned char ME = MI->getOperand(3).getImm();
|
unsigned char ME = MI->getOperand(3).getImm();
|
||||||
// rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
|
// rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
|
||||||
if (63-SH == ME) {
|
if (63-SH == ME) {
|
||||||
useSubstituteMnemonic = true;
|
|
||||||
O << "\tsldi ";
|
O << "\tsldi ";
|
||||||
printOperand(MI, 0);
|
printOperand(MI, 0);
|
||||||
O << ", ";
|
O << ", ";
|
||||||
printOperand(MI, 1);
|
printOperand(MI, 1);
|
||||||
O << ", " << (unsigned int)SH;
|
O << ", " << (unsigned int)SH;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!useSubstituteMnemonic)
|
printInstruction(MI);
|
||||||
printInstruction(MI);
|
|
||||||
|
|
||||||
if (VerboseAsm)
|
|
||||||
EmitComments(*MI);
|
|
||||||
O << '\n';
|
|
||||||
|
|
||||||
processDebugLoc(MI, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPCLinuxAsmPrinter::EmitFunctionEntryLabel() {
|
void PPCLinuxAsmPrinter::EmitFunctionEntryLabel() {
|
||||||
@@ -609,39 +597,6 @@ void PPCLinuxAsmPrinter::EmitFunctionEntryLabel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// runOnMachineFunction - This uses the printMachineInstruction()
|
|
||||||
/// method to print assembly for each instruction.
|
|
||||||
///
|
|
||||||
bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
||||||
SetupMachineFunction(MF);
|
|
||||||
O << "\n\n";
|
|
||||||
|
|
||||||
EmitFunctionHeader();
|
|
||||||
|
|
||||||
// Print out code for the function.
|
|
||||||
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
|
||||||
I != E; ++I) {
|
|
||||||
// Print a label for the basic block.
|
|
||||||
EmitBasicBlockStart(I);
|
|
||||||
|
|
||||||
// Print the assembly for the instructions.
|
|
||||||
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
|
|
||||||
II != E; ++II)
|
|
||||||
printMachineInstruction(II);
|
|
||||||
}
|
|
||||||
|
|
||||||
O << "\t.size\t" << *CurrentFnSym << ",.-" << *CurrentFnSym << '\n';
|
|
||||||
|
|
||||||
// Emit post-function debug information.
|
|
||||||
DW->EndFunction(&MF);
|
|
||||||
|
|
||||||
// Print out jump tables referenced by the function.
|
|
||||||
EmitJumpTableInfo();
|
|
||||||
|
|
||||||
// We didn't modify anything.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
|
bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
|
||||||
const TargetData *TD = TM.getTargetData();
|
const TargetData *TD = TM.getTargetData();
|
||||||
|
|
||||||
@@ -662,46 +617,6 @@ bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
|
|||||||
return AsmPrinter::doFinalization(M);
|
return AsmPrinter::doFinalization(M);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// runOnMachineFunction - This uses the printMachineInstruction()
|
|
||||||
/// method to print assembly for each instruction.
|
|
||||||
///
|
|
||||||
bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
||||||
SetupMachineFunction(MF);
|
|
||||||
O << "\n\n";
|
|
||||||
|
|
||||||
EmitFunctionHeader();
|
|
||||||
|
|
||||||
// If the function is empty, then we need to emit *something*. Otherwise, the
|
|
||||||
// function's label might be associated with something that it wasn't meant to
|
|
||||||
// be associated with. We emit a noop in this situation.
|
|
||||||
MachineFunction::iterator I = MF.begin();
|
|
||||||
|
|
||||||
if (++I == MF.end() && MF.front().empty())
|
|
||||||
O << "\tnop\n";
|
|
||||||
|
|
||||||
// Print out code for the function.
|
|
||||||
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
|
||||||
I != E; ++I) {
|
|
||||||
// Print a label for the basic block.
|
|
||||||
EmitBasicBlockStart(I);
|
|
||||||
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
||||||
II != IE; ++II) {
|
|
||||||
// Print the assembly for the instruction.
|
|
||||||
printMachineInstruction(II);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emit post-function debug information.
|
|
||||||
DW->EndFunction(&MF);
|
|
||||||
|
|
||||||
// Print out jump tables referenced by the function.
|
|
||||||
EmitJumpTableInfo();
|
|
||||||
|
|
||||||
// We didn't modify anything.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PPCDarwinAsmPrinter::EmitStartOfAsmFile(Module &M) {
|
void PPCDarwinAsmPrinter::EmitStartOfAsmFile(Module &M) {
|
||||||
static const char *const CPUDirectives[] = {
|
static const char *const CPUDirectives[] = {
|
||||||
"",
|
"",
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
; RUN: llc < %s -march=ppc32 | grep nop
|
; RUN: llc < %s -march=ppc32 | grep .byte
|
||||||
target triple = "powerpc-apple-darwin8"
|
target triple = "powerpc-apple-darwin8"
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user