2005-01-24 18:37:48 +00:00
|
|
|
//===-- AlphaAsmPrinter.cpp - Alpha LLVM assembly writer ------------------===//
|
2005-04-21 23:13:11 +00:00
|
|
|
//
|
2005-01-22 23:41:55 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:13:11 +00:00
|
|
|
//
|
2005-01-22 23:41:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to GAS-format Alpha assembly language.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "Alpha.h"
|
|
|
|
#include "AlphaInstrInfo.h"
|
2005-09-29 22:54:56 +00:00
|
|
|
#include "AlphaTargetMachine.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/Module.h"
|
2005-03-17 15:38:16 +00:00
|
|
|
#include "llvm/Type.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2009-02-18 23:12:06 +00:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2009-08-19 05:49:37 +00:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-09-13 17:14:04 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2009-07-28 03:13:23 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2009-07-15 20:24:03 +00:00
|
|
|
#include "llvm/Target/TargetRegistry.h"
|
2009-07-08 19:04:27 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-14 20:18:05 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
namespace {
|
2009-10-25 06:33:48 +00:00
|
|
|
struct AlphaAsmPrinter : public AsmPrinter {
|
2005-01-22 23:41:55 +00:00
|
|
|
/// Unique incrementer for label values for referencing Global values.
|
|
|
|
///
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2009-07-14 20:18:05 +00:00
|
|
|
explicit AlphaAsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
2009-08-22 20:48:53 +00:00
|
|
|
const MCAsmInfo *T, bool V)
|
2009-07-01 01:48:54 +00:00
|
|
|
: AsmPrinter(o, tm, T, V) {}
|
2005-01-22 23:41:55 +00:00
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Alpha Assembly Printer";
|
|
|
|
}
|
2009-08-08 01:32:19 +00:00
|
|
|
void printInstruction(const MachineInstr *MI);
|
2009-09-13 20:19:22 +00:00
|
|
|
static const char *getRegisterName(unsigned RegNo);
|
2009-09-13 20:08:00 +00:00
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
void printOp(const MachineOperand &MO, bool IsCallOp = false);
|
2005-11-30 18:54:35 +00:00
|
|
|
void printOperand(const MachineInstr *MI, int opNum);
|
2009-07-21 18:38:57 +00:00
|
|
|
void printBaseOffsetPair(const MachineInstr *MI, int i, bool brackets=true);
|
2005-04-21 23:13:11 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &F);
|
2009-09-30 22:06:26 +00:00
|
|
|
void EmitStartOfAsmFile(Module &M);
|
2008-08-07 09:53:57 +00:00
|
|
|
|
2006-06-21 13:37:27 +00:00
|
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant, const char *ExtraCode);
|
2008-08-07 09:53:57 +00:00
|
|
|
bool PrintAsmMemoryOperand(const MachineInstr *MI,
|
2007-04-16 18:10:23 +00:00
|
|
|
unsigned OpNo,
|
2008-08-07 09:53:57 +00:00
|
|
|
unsigned AsmVariant,
|
2007-04-16 18:10:23 +00:00
|
|
|
const char *ExtraCode);
|
2005-01-22 23:41:55 +00:00
|
|
|
};
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
#include "AlphaGenAsmWriter.inc"
|
|
|
|
|
2005-11-30 18:54:35 +00:00
|
|
|
void AlphaAsmPrinter::printOperand(const MachineInstr *MI, int opNum)
|
2005-01-22 23:41:55 +00:00
|
|
|
{
|
|
|
|
const MachineOperand &MO = MI->getOperand(opNum);
|
2006-05-04 18:05:43 +00:00
|
|
|
if (MO.getType() == MachineOperand::MO_Register) {
|
2008-02-10 18:45:23 +00:00
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
|
|
|
|
"Not physreg??");
|
2009-09-13 20:31:40 +00:00
|
|
|
O << getRegisterName(MO.getReg());
|
2008-10-03 15:45:36 +00:00
|
|
|
} else if (MO.isImm()) {
|
2007-12-30 20:49:49 +00:00
|
|
|
O << MO.getImm();
|
|
|
|
assert(MO.getImm() < (1 << 30));
|
2005-01-22 23:41:55 +00:00
|
|
|
} else {
|
|
|
|
printOp(MO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
|
|
|
|
switch (MO.getType()) {
|
2006-05-04 18:05:43 +00:00
|
|
|
case MachineOperand::MO_Register:
|
2009-09-13 20:31:40 +00:00
|
|
|
O << getRegisterName(MO.getReg());
|
2005-01-22 23:41:55 +00:00
|
|
|
return;
|
|
|
|
|
2006-05-04 17:21:20 +00:00
|
|
|
case MachineOperand::MO_Immediate:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("printOp() does not handle immediate values");
|
2005-01-22 23:41:55 +00:00
|
|
|
return;
|
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2010-01-26 04:55:51 +00:00
|
|
|
O << *MO.getMBB()->getSymbol(OutContext);
|
2005-01-22 23:41:55 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
|
2007-12-30 23:10:15 +00:00
|
|
|
<< MO.getIndex();
|
2005-01-22 23:41:55 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
O << MO.getSymbolName();
|
|
|
|
return;
|
|
|
|
|
2009-07-14 18:17:16 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2010-01-17 21:43:43 +00:00
|
|
|
O << *GetGlobalValueSymbol(MO.getGlobal());
|
2005-01-22 23:41:55 +00:00
|
|
|
return;
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2006-09-18 18:01:03 +00:00
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-12-30 23:10:15 +00:00
|
|
|
<< '_' << MO.getIndex();
|
2006-09-18 18:01:03 +00:00
|
|
|
return;
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
default:
|
|
|
|
O << "<unknown operand type: " << MO.getType() << ">";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// runOnMachineFunction - This uses the printMachineInstruction()
|
|
|
|
/// method to print assembly for each instruction.
|
|
|
|
///
|
|
|
|
bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
2005-11-21 07:51:23 +00:00
|
|
|
SetupMachineFunction(MF);
|
2005-01-22 23:41:55 +00:00
|
|
|
O << "\n\n";
|
|
|
|
|
2010-01-27 00:17:20 +00:00
|
|
|
EmitFunctionHeader();
|
|
|
|
|
2010-01-17 21:43:43 +00:00
|
|
|
O << "\t.ent " << *CurrentFnSym << "\n";
|
2005-01-22 23:41:55 +00:00
|
|
|
|
|
|
|
// Print out code for the function.
|
|
|
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
|
|
|
I != E; ++I) {
|
2010-01-17 21:43:43 +00:00
|
|
|
if (I != MF.begin())
|
2009-09-13 18:25:37 +00:00
|
|
|
EmitBasicBlockStart(I);
|
2010-01-17 21:43:43 +00:00
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
|
|
|
|
II != E; ++II) {
|
|
|
|
// Print the assembly for the instruction.
|
2006-12-07 23:55:55 +00:00
|
|
|
++EmittedInsts;
|
2009-10-06 02:19:11 +00:00
|
|
|
processDebugLoc(II, true);
|
2009-08-08 00:05:42 +00:00
|
|
|
printInstruction(II);
|
2009-09-09 23:14:36 +00:00
|
|
|
|
2009-11-13 21:34:57 +00:00
|
|
|
if (VerboseAsm)
|
2009-09-09 23:14:36 +00:00
|
|
|
EmitComments(*II);
|
|
|
|
O << '\n';
|
2009-10-06 02:19:11 +00:00
|
|
|
processDebugLoc(II, false);
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-17 21:43:43 +00:00
|
|
|
O << "\t.end " << *CurrentFnSym << "\n";
|
2005-01-22 23:41:55 +00:00
|
|
|
|
2010-01-27 00:17:20 +00:00
|
|
|
// Print out jump tables referenced by the function
|
2010-01-28 01:02:27 +00:00
|
|
|
EmitJumpTableInfo();
|
2010-01-27 00:17:20 +00:00
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
// We didn't modify anything.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-30 22:06:26 +00:00
|
|
|
void AlphaAsmPrinter::EmitStartOfAsmFile(Module &M) {
|
|
|
|
if (TM.getSubtarget<AlphaSubtarget>().hasCT())
|
2007-01-24 21:09:16 +00:00
|
|
|
O << "\t.arch ev6\n"; //This might need to be ev67, so leave this test here
|
2005-04-14 16:24:00 +00:00
|
|
|
else
|
2007-01-24 21:09:16 +00:00
|
|
|
O << "\t.arch ev6\n";
|
2005-07-22 20:52:16 +00:00
|
|
|
O << "\t.set noat\n";
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2006-06-21 13:37:27 +00:00
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
|
|
|
bool AlphaAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
2008-08-07 09:53:57 +00:00
|
|
|
unsigned AsmVariant,
|
2007-04-16 18:10:23 +00:00
|
|
|
const char *ExtraCode) {
|
2006-06-21 13:37:27 +00:00
|
|
|
printOperand(MI, OpNo);
|
|
|
|
return false;
|
|
|
|
}
|
2006-06-21 15:42:36 +00:00
|
|
|
|
2008-08-07 09:53:57 +00:00
|
|
|
bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
2007-04-16 18:10:23 +00:00
|
|
|
unsigned OpNo,
|
2008-08-07 09:53:57 +00:00
|
|
|
unsigned AsmVariant,
|
2007-04-16 18:10:23 +00:00
|
|
|
const char *ExtraCode) {
|
2006-06-21 15:42:36 +00:00
|
|
|
if (ExtraCode && ExtraCode[0])
|
|
|
|
return true; // Unknown modifier.
|
2006-07-03 17:57:34 +00:00
|
|
|
O << "0(";
|
2006-06-21 15:42:36 +00:00
|
|
|
printOperand(MI, OpNo);
|
2006-07-03 17:57:34 +00:00
|
|
|
O << ")";
|
2006-06-21 15:42:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-16 20:12:29 +00:00
|
|
|
|
2009-07-15 20:24:03 +00:00
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeAlphaAsmPrinter() {
|
2009-07-25 06:49:55 +00:00
|
|
|
RegisterAsmPrinter<AlphaAsmPrinter> X(TheAlphaTarget);
|
2009-07-15 20:24:03 +00:00
|
|
|
}
|