2012-02-18 20:03:15 +08:00
|
|
|
//===-- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly --===//
|
2011-12-13 05:14:40 +08: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-04 00:50:05 +08:00
|
|
|
#include "Hexagon.h"
|
2013-02-21 00:13:27 +08:00
|
|
|
#include "HexagonAsmPrinter.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "HexagonMachineFunctionInfo.h"
|
2013-02-21 00:13:27 +08:00
|
|
|
#include "HexagonSubtarget.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "HexagonTargetMachine.h"
|
2014-11-21 05:56:35 +08:00
|
|
|
#include "MCTargetDesc/HexagonInstPrinter.h"
|
2015-02-20 05:10:50 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
2015-06-06 00:00:11 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCShuffler.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2012-04-13 01:55:53 +08:00
|
|
|
#include "llvm/Analysis/ConstantFolding.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2012-04-13 01:55:53 +08: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-13 05:14:40 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2012-04-13 01:55:53 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2012-03-18 02:46:09 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
2011-12-13 05:14:40 +08: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-19 04:29:04 +08:00
|
|
|
HexagonAsmPrinter::HexagonAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
2015-02-03 14:40:22 +08:00
|
|
|
: AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr) {}
|
2015-01-19 04:29:04 +08:00
|
|
|
|
2012-04-13 01:55:53 +08:00
|
|
|
void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
|
2011-12-13 05:14:40 +08:00
|
|
|
switch (MO.getType()) {
|
2012-05-04 05:52:53 +08:00
|
|
|
default: llvm_unreachable ("<unknown operand type>");
|
2012-04-13 01:55:53 +08:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
O << HexagonInstPrinter::getRegisterName(MO.getReg());
|
|
|
|
return;
|
2011-12-13 05:14:40 +08:00
|
|
|
case MachineOperand::MO_Immediate:
|
2012-04-13 01:55:53 +08:00
|
|
|
O << MO.getImm();
|
|
|
|
return;
|
2011-12-13 05:14:40 +08:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2015-06-09 08:31:39 +08:00
|
|
|
MO.getMBB()->getSymbol()->print(O, MAI);
|
2011-12-13 05:14:40 +08:00
|
|
|
return;
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2015-06-09 08:31:39 +08:00
|
|
|
GetCPISymbol(MO.getIndex())->print(O, MAI);
|
2011-12-13 05:14:40 +08:00
|
|
|
return;
|
2012-04-13 01:55:53 +08:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2011-12-13 05:14:40 +08:00
|
|
|
// Computing the address of a global symbol, not calling it.
|
2015-06-09 08:31:39 +08:00
|
|
|
getSymbol(MO.getGlobal())->print(O, MAI);
|
2011-12-13 05:14:40 +08: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-13 01:55:53 +08:00
|
|
|
raw_ostream &OS) {
|
2011-12-13 05:14:40 +08: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 21:49:27 +08:00
|
|
|
default:
|
|
|
|
// See if this is a generic print operand
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
|
2011-12-13 05:14:40 +08: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 10:50:20 +08:00
|
|
|
llvm_unreachable("Unimplemented");
|
2011-12-13 05:14:40 +08:00
|
|
|
|
|
|
|
if (Offset.isImm()) {
|
|
|
|
if (Offset.getImm())
|
|
|
|
O << " + #" << Offset.getImm();
|
|
|
|
}
|
|
|
|
else
|
2012-02-07 10:50:20 +08:00
|
|
|
llvm_unreachable("Unimplemented");
|
2011-12-13 05:14:40 +08: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-11-14 01:42:46 +08:00
|
|
|
MCInst MCB = HexagonMCInstrInfo::createBundle();
|
2012-05-04 05:52:53 +08:00
|
|
|
|
2015-05-29 22:44:13 +08:00
|
|
|
if (MI->isBundle()) {
|
|
|
|
const MachineBasicBlock* MBB = MI->getParent();
|
Hexagon: Remove implicit ilist iterator conversions, NFC
There are two things out of the ordinary in this commit. First, I made
a loop obviously "infinite" in HexagonInstrInfo.cpp. After checking if
an instruction was at the beginning of a basic block (in which case,
`break`), the loop decremented and checked the iterator for `nullptr` as
the loop condition. This has never been possible (the prev pointers are
always been circular, so even with the weird ilist/iplist
implementation, this isn't been possible), so I removed the condition.
Second, in HexagonAsmPrinter.cpp there was another case of comparing a
`MachineBasicBlock::instr_iterator` against `MachineBasicBlock::end()`
(which returns `MachineBasicBlock::iterator`). While not incorrect,
it's fragile. I switched this to `::instr_end()`.
All that said, no functionality change intended here.
llvm-svn: 250778
2015-10-20 08:46:39 +08:00
|
|
|
MachineBasicBlock::const_instr_iterator MII = MI->getIterator();
|
2015-05-29 22:44:13 +08:00
|
|
|
unsigned IgnoreCount = 0;
|
|
|
|
|
Hexagon: Remove implicit ilist iterator conversions, NFC
There are two things out of the ordinary in this commit. First, I made
a loop obviously "infinite" in HexagonInstrInfo.cpp. After checking if
an instruction was at the beginning of a basic block (in which case,
`break`), the loop decremented and checked the iterator for `nullptr` as
the loop condition. This has never been possible (the prev pointers are
always been circular, so even with the weird ilist/iplist
implementation, this isn't been possible), so I removed the condition.
Second, in HexagonAsmPrinter.cpp there was another case of comparing a
`MachineBasicBlock::instr_iterator` against `MachineBasicBlock::end()`
(which returns `MachineBasicBlock::iterator`). While not incorrect,
it's fragile. I switched this to `::instr_end()`.
All that said, no functionality change intended here.
llvm-svn: 250778
2015-10-20 08:46:39 +08:00
|
|
|
for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII) {
|
2015-05-29 22:44:13 +08:00
|
|
|
if (MII->getOpcode() == TargetOpcode::DBG_VALUE ||
|
|
|
|
MII->getOpcode() == TargetOpcode::IMPLICIT_DEF)
|
|
|
|
++IgnoreCount;
|
|
|
|
else {
|
Hexagon: Remove implicit ilist iterator conversions, NFC
There are two things out of the ordinary in this commit. First, I made
a loop obviously "infinite" in HexagonInstrInfo.cpp. After checking if
an instruction was at the beginning of a basic block (in which case,
`break`), the loop decremented and checked the iterator for `nullptr` as
the loop condition. This has never been possible (the prev pointers are
always been circular, so even with the weird ilist/iplist
implementation, this isn't been possible), so I removed the condition.
Second, in HexagonAsmPrinter.cpp there was another case of comparing a
`MachineBasicBlock::instr_iterator` against `MachineBasicBlock::end()`
(which returns `MachineBasicBlock::iterator`). While not incorrect,
it's fragile. I switched this to `::instr_end()`.
All that said, no functionality change intended here.
llvm-svn: 250778
2015-10-20 08:46:39 +08:00
|
|
|
HexagonLowerToMC(&*MII, MCB, *this);
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-05-29 22:44:13 +08:00
|
|
|
HexagonLowerToMC(MI, MCB, *this);
|
2015-11-13 15:58:06 +08:00
|
|
|
HexagonMCInstrInfo::padEndloop(OutStreamer->getContext(), MCB);
|
2012-05-04 05:52:53 +08:00
|
|
|
}
|
2015-06-09 00:34:47 +08:00
|
|
|
// Examine the packet and try to find instructions that can be converted
|
|
|
|
// to compounds.
|
|
|
|
HexagonMCInstrInfo::tryCompound(*Subtarget->getInstrInfo(),
|
|
|
|
OutStreamer->getContext(), MCB);
|
2015-06-06 00:00:11 +08:00
|
|
|
// Examine the packet and convert pairs of instructions to duplex
|
|
|
|
// instructions when possible.
|
|
|
|
SmallVector<DuplexCandidate, 8> possibleDuplexes;
|
2015-06-09 00:34:47 +08:00
|
|
|
possibleDuplexes = HexagonMCInstrInfo::getDuplexPossibilties(
|
|
|
|
*Subtarget->getInstrInfo(), MCB);
|
|
|
|
HexagonMCShuffle(*Subtarget->getInstrInfo(), *Subtarget,
|
|
|
|
OutStreamer->getContext(), MCB, possibleDuplexes);
|
2015-05-29 22:44:13 +08:00
|
|
|
EmitToStreamer(*OutStreamer, MCB);
|
2011-12-13 05:14:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void LLVMInitializeHexagonAsmPrinter() {
|
|
|
|
RegisterAsmPrinter<HexagonAsmPrinter> X(TheHexagonTarget);
|
|
|
|
}
|