2012-02-18 12:03:15 +00:00
|
|
|
//===-- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly --===//
|
2011-12-12 21:14:40 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to Hexagon assembly language. This printer is
|
|
|
|
// the output mechanism used by `llc'.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "Hexagon.h"
|
2013-02-20 16:13:27 +00:00
|
|
|
#include "HexagonAsmPrinter.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "HexagonMachineFunctionInfo.h"
|
2013-02-20 16:13:27 +00:00
|
|
|
#include "HexagonSubtarget.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "HexagonTargetMachine.h"
|
2014-11-20 21:56:35 +00:00
|
|
|
#include "MCTargetDesc/HexagonInstPrinter.h"
|
2015-02-19 21:10:50 +00:00
|
|
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
2015-06-05 16:00:11 +00:00
|
|
|
#include "MCTargetDesc/HexagonMCShuffler.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2012-04-12 17:55:53 +00:00
|
|
|
#include "llvm/Analysis/ConstantFolding.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2014-01-07 21:19:40 +00:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2012-04-12 17:55:53 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2012-04-12 17:55:53 +00:00
|
|
|
#include "llvm/Support/Format.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2012-03-17 18:46:09 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 02:41:26 +00:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
2011-12-12 21:14:40 +00:00
|
|
|
static cl::opt<bool> AlignCalls(
|
|
|
|
"hexagon-align-calls", cl::Hidden, cl::init(true),
|
|
|
|
cl::desc("Insert falign after call instruction for Hexagon target"));
|
|
|
|
|
2015-01-18 20:29:04 +00:00
|
|
|
HexagonAsmPrinter::HexagonAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
2015-02-03 06:40:22 +00:00
|
|
|
: AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr) {}
|
2015-01-18 20:29:04 +00:00
|
|
|
|
2012-04-12 17:55:53 +00:00
|
|
|
void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
|
2011-12-12 21:14:40 +00:00
|
|
|
switch (MO.getType()) {
|
2012-05-03 21:52:53 +00:00
|
|
|
default: llvm_unreachable ("<unknown operand type>");
|
2012-04-12 17:55:53 +00:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
O << HexagonInstPrinter::getRegisterName(MO.getReg());
|
|
|
|
return;
|
2011-12-12 21:14:40 +00:00
|
|
|
case MachineOperand::MO_Immediate:
|
2012-04-12 17:55:53 +00:00
|
|
|
O << MO.getImm();
|
|
|
|
return;
|
2011-12-12 21:14:40 +00:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2015-06-09 00:31:39 +00:00
|
|
|
MO.getMBB()->getSymbol()->print(O, MAI);
|
2011-12-12 21:14:40 +00:00
|
|
|
return;
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2015-06-09 00:31:39 +00:00
|
|
|
GetCPISymbol(MO.getIndex())->print(O, MAI);
|
2011-12-12 21:14:40 +00:00
|
|
|
return;
|
2012-04-12 17:55:53 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2011-12-12 21:14:40 +00:00
|
|
|
// Computing the address of a global symbol, not calling it.
|
2015-06-09 00:31:39 +00:00
|
|
|
getSymbol(MO.getGlobal())->print(O, MAI);
|
2011-12-12 21:14:40 +00:00
|
|
|
printOffset(MO.getOffset(), O);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// isBlockOnlyReachableByFallthrough - We need to override this since the
|
|
|
|
// default AsmPrinter does not print labels for any basic block that
|
|
|
|
// is only reachable by a fall through. That works for all cases except
|
|
|
|
// for the case in which the basic block is reachable by a fall through but
|
|
|
|
// through an indirect from a jump table. In this case, the jump table
|
|
|
|
// will contain a label not defined by AsmPrinter.
|
|
|
|
//
|
|
|
|
bool HexagonAsmPrinter::
|
|
|
|
isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
|
|
|
|
if (MBB->hasAddressTaken()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return AsmPrinter::isBlockOnlyReachableByFallthrough(MBB);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
|
|
|
bool HexagonAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
|
|
|
const char *ExtraCode,
|
2012-04-12 17:55:53 +00:00
|
|
|
raw_ostream &OS) {
|
2011-12-12 21:14:40 +00:00
|
|
|
// Does this asm operand have a single letter operand modifier?
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
|
|
|
|
|
|
|
switch (ExtraCode[0]) {
|
2012-06-26 13:49:27 +00:00
|
|
|
default:
|
|
|
|
// See if this is a generic print operand
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
|
2011-12-12 21:14:40 +00:00
|
|
|
case 'c': // Don't print "$" before a global var name or constant.
|
|
|
|
// Hexagon never has a prefix.
|
|
|
|
printOperand(MI, OpNo, OS);
|
|
|
|
return false;
|
|
|
|
case 'L': // Write second word of DImode reference.
|
|
|
|
// Verify that this operand has two consecutive registers.
|
|
|
|
if (!MI->getOperand(OpNo).isReg() ||
|
|
|
|
OpNo+1 == MI->getNumOperands() ||
|
|
|
|
!MI->getOperand(OpNo+1).isReg())
|
|
|
|
return true;
|
|
|
|
++OpNo; // Return the high-part.
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
// Write 'i' if an integer constant, otherwise nothing. Used to print
|
|
|
|
// addi vs add, etc.
|
|
|
|
if (MI->getOperand(OpNo).isImm())
|
|
|
|
OS << "i";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printOperand(MI, OpNo, OS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HexagonAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
|
|
|
unsigned OpNo, unsigned AsmVariant,
|
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
|
|
|
if (ExtraCode && ExtraCode[0])
|
|
|
|
return true; // Unknown modifier.
|
|
|
|
|
|
|
|
const MachineOperand &Base = MI->getOperand(OpNo);
|
|
|
|
const MachineOperand &Offset = MI->getOperand(OpNo+1);
|
|
|
|
|
|
|
|
if (Base.isReg())
|
|
|
|
printOperand(MI, OpNo, O);
|
|
|
|
else
|
2012-02-07 02:50:20 +00:00
|
|
|
llvm_unreachable("Unimplemented");
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
if (Offset.isImm()) {
|
|
|
|
if (Offset.getImm())
|
|
|
|
O << " + #" << Offset.getImm();
|
|
|
|
}
|
|
|
|
else
|
2012-02-07 02:50:20 +00:00
|
|
|
llvm_unreachable("Unimplemented");
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// printMachineInstruction -- Print out a single Hexagon MI in Darwin syntax to
|
|
|
|
/// the current output stream.
|
|
|
|
///
|
|
|
|
void HexagonAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
2015-05-29 14:44:13 +00:00
|
|
|
MCInst MCB;
|
|
|
|
MCB.setOpcode(Hexagon::BUNDLE);
|
|
|
|
MCB.addOperand(MCOperand::createImm(0));
|
2012-05-03 21:52:53 +00:00
|
|
|
|
2015-05-29 14:44:13 +00:00
|
|
|
if (MI->isBundle()) {
|
|
|
|
const MachineBasicBlock* MBB = MI->getParent();
|
2012-05-03 21:52:53 +00:00
|
|
|
MachineBasicBlock::const_instr_iterator MII = MI;
|
2015-05-29 14:44:13 +00:00
|
|
|
unsigned IgnoreCount = 0;
|
|
|
|
|
|
|
|
for (++MII; MII != MBB->end() && MII->isInsideBundle(); ++MII) {
|
|
|
|
if (MII->getOpcode() == TargetOpcode::DBG_VALUE ||
|
|
|
|
MII->getOpcode() == TargetOpcode::IMPLICIT_DEF)
|
|
|
|
++IgnoreCount;
|
|
|
|
else {
|
|
|
|
HexagonLowerToMC(MII, MCB, *this);
|
2012-05-03 21:52:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-05-29 14:44:13 +00:00
|
|
|
HexagonLowerToMC(MI, MCB, *this);
|
|
|
|
HexagonMCInstrInfo::padEndloop(MCB);
|
2012-05-03 21:52:53 +00:00
|
|
|
}
|
2015-06-08 16:34:47 +00:00
|
|
|
// Examine the packet and try to find instructions that can be converted
|
|
|
|
// to compounds.
|
|
|
|
HexagonMCInstrInfo::tryCompound(*Subtarget->getInstrInfo(),
|
|
|
|
OutStreamer->getContext(), MCB);
|
2015-06-05 16:00:11 +00:00
|
|
|
// Examine the packet and convert pairs of instructions to duplex
|
|
|
|
// instructions when possible.
|
|
|
|
SmallVector<DuplexCandidate, 8> possibleDuplexes;
|
2015-06-08 16:34:47 +00:00
|
|
|
possibleDuplexes = HexagonMCInstrInfo::getDuplexPossibilties(
|
|
|
|
*Subtarget->getInstrInfo(), MCB);
|
|
|
|
HexagonMCShuffle(*Subtarget->getInstrInfo(), *Subtarget,
|
|
|
|
OutStreamer->getContext(), MCB, possibleDuplexes);
|
2015-05-29 14:44:13 +00:00
|
|
|
EmitToStreamer(*OutStreamer, MCB);
|
2011-12-12 21:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void LLVMInitializeHexagonAsmPrinter() {
|
|
|
|
RegisterAsmPrinter<HexagonAsmPrinter> X(TheHexagonTarget);
|
|
|
|
}
|