2010-10-02 09:08:17 +08:00
|
|
|
//===-- MSP430AsmPrinter.cpp - MSP430 LLVM assembly writer ----------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-10-02 09:08:17 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to the MSP430 assembly language.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-05-11 09:58:52 +08:00
|
|
|
#include "MCTargetDesc/MSP430InstPrinter.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "MSP430.h"
|
2010-10-02 09:08:17 +08:00
|
|
|
#include "MSP430InstrInfo.h"
|
|
|
|
#include "MSP430MCInstLower.h"
|
|
|
|
#include "MSP430TargetMachine.h"
|
2019-05-15 07:45:18 +08:00
|
|
|
#include "TargetInfo/MSP430TargetInfo.h"
|
2019-01-16 22:03:41 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2010-10-02 09:08:17 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2010-10-02 09:08:17 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.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/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-07-15 07:50:31 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2010-10-02 09:08:17 +08:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2019-01-16 22:03:41 +08:00
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2010-10-02 09:08:17 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2010-10-02 09:08:17 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
2010-10-02 09:08:17 +08:00
|
|
|
namespace {
|
|
|
|
class MSP430AsmPrinter : public AsmPrinter {
|
|
|
|
public:
|
2015-01-19 04:29:04 +08:00
|
|
|
MSP430AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
|
|
|
|
: AsmPrinter(TM, std::move(Streamer)) {}
|
2010-10-02 09:08:17 +08:00
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override { return "MSP430 Assembly Printer"; }
|
2010-10-02 09:08:17 +08:00
|
|
|
|
2019-01-16 22:03:41 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
[AsmPrinter] refactor to support %c w/ GlobalAddress'
Summary:
Targets like ARM, MSP430, PPC, and SystemZ have complex behavior when
printing the address of a MachineOperand::MO_GlobalAddress. Move that
handling into a new overriden method in each base class. A virtual
method was added to the base class for handling the generic case.
Refactors a few subclasses to support the target independent %a, %c, and
%n.
The patch also contains small cleanups for AVRAsmPrinter and
SystemZAsmPrinter.
It seems that NVPTXTargetLowering is possibly missing some logic to
transform GlobalAddressSDNodes for
TargetLowering::LowerAsmOperandForConstraint to handle with "i" extended
inline assembly asm constraints.
Fixes:
- https://bugs.llvm.org/show_bug.cgi?id=41402
- https://github.com/ClangBuiltLinux/linux/issues/449
Reviewers: echristo, void
Reviewed By: void
Subscribers: void, craig.topper, jholewinski, dschuff, jyknight, dylanmckay, sdardis, nemanjai, javed.absar, sbc100, jgravelle-google, eraman, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, jrtc27, atanasyan, jsji, llvm-commits, kees, tpimh, nathanchance, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60887
llvm-svn: 359337
2019-04-27 02:45:04 +08:00
|
|
|
void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;
|
2010-10-02 09:08:17 +08:00
|
|
|
void printOperand(const MachineInstr *MI, int OpNum,
|
2014-04-25 13:30:21 +08:00
|
|
|
raw_ostream &O, const char* Modifier = nullptr);
|
2010-10-02 09:08:17 +08:00
|
|
|
void printSrcMemOperand(const MachineInstr *MI, int OpNum,
|
|
|
|
raw_ostream &O);
|
|
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
const char *ExtraCode, raw_ostream &O) override;
|
|
|
|
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
2014-04-29 15:58:09 +08:00
|
|
|
const char *ExtraCode, raw_ostream &O) override;
|
2020-02-14 13:58:16 +08:00
|
|
|
void emitInstruction(const MachineInstr *MI) override;
|
2019-01-16 22:03:41 +08:00
|
|
|
|
|
|
|
void EmitInterruptVectorSection(MachineFunction &ISR);
|
2010-10-02 09:08:17 +08:00
|
|
|
};
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
[AsmPrinter] refactor to support %c w/ GlobalAddress'
Summary:
Targets like ARM, MSP430, PPC, and SystemZ have complex behavior when
printing the address of a MachineOperand::MO_GlobalAddress. Move that
handling into a new overriden method in each base class. A virtual
method was added to the base class for handling the generic case.
Refactors a few subclasses to support the target independent %a, %c, and
%n.
The patch also contains small cleanups for AVRAsmPrinter and
SystemZAsmPrinter.
It seems that NVPTXTargetLowering is possibly missing some logic to
transform GlobalAddressSDNodes for
TargetLowering::LowerAsmOperandForConstraint to handle with "i" extended
inline assembly asm constraints.
Fixes:
- https://bugs.llvm.org/show_bug.cgi?id=41402
- https://github.com/ClangBuiltLinux/linux/issues/449
Reviewers: echristo, void
Reviewed By: void
Subscribers: void, craig.topper, jholewinski, dschuff, jyknight, dylanmckay, sdardis, nemanjai, javed.absar, sbc100, jgravelle-google, eraman, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, jrtc27, atanasyan, jsji, llvm-commits, kees, tpimh, nathanchance, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60887
llvm-svn: 359337
2019-04-27 02:45:04 +08:00
|
|
|
void MSP430AsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
|
|
|
|
raw_ostream &O) {
|
|
|
|
uint64_t Offset = MO.getOffset();
|
|
|
|
if (Offset)
|
|
|
|
O << '(' << Offset << '+';
|
|
|
|
|
|
|
|
getSymbol(MO.getGlobal())->print(O, MAI);
|
|
|
|
|
|
|
|
if (Offset)
|
|
|
|
O << ')';
|
|
|
|
}
|
2010-10-02 09:08:17 +08:00
|
|
|
|
|
|
|
void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
|
|
|
|
raw_ostream &O, const char *Modifier) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNum);
|
|
|
|
switch (MO.getType()) {
|
2012-02-07 10:50:20 +08:00
|
|
|
default: llvm_unreachable("Not implemented yet!");
|
2010-10-02 09:08:17 +08:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
O << MSP430InstPrinter::getRegisterName(MO.getReg());
|
|
|
|
return;
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
if (!Modifier || strcmp(Modifier, "nohash"))
|
|
|
|
O << '#';
|
|
|
|
O << MO.getImm();
|
|
|
|
return;
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2015-06-09 08:31:39 +08:00
|
|
|
MO.getMBB()->getSymbol()->print(O, MAI);
|
2010-10-02 09:08:17 +08:00
|
|
|
return;
|
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
|
|
|
// If the global address expression is a part of displacement field with a
|
|
|
|
// register base, we should not emit any prefix symbol here, e.g.
|
|
|
|
// mov.w glb(r1), r2
|
|
|
|
// Otherwise (!) msp430-as will silently miscompile the output :(
|
|
|
|
if (!Modifier || strcmp(Modifier, "nohash"))
|
[AsmPrinter] refactor to support %c w/ GlobalAddress'
Summary:
Targets like ARM, MSP430, PPC, and SystemZ have complex behavior when
printing the address of a MachineOperand::MO_GlobalAddress. Move that
handling into a new overriden method in each base class. A virtual
method was added to the base class for handling the generic case.
Refactors a few subclasses to support the target independent %a, %c, and
%n.
The patch also contains small cleanups for AVRAsmPrinter and
SystemZAsmPrinter.
It seems that NVPTXTargetLowering is possibly missing some logic to
transform GlobalAddressSDNodes for
TargetLowering::LowerAsmOperandForConstraint to handle with "i" extended
inline assembly asm constraints.
Fixes:
- https://bugs.llvm.org/show_bug.cgi?id=41402
- https://github.com/ClangBuiltLinux/linux/issues/449
Reviewers: echristo, void
Reviewed By: void
Subscribers: void, craig.topper, jholewinski, dschuff, jyknight, dylanmckay, sdardis, nemanjai, javed.absar, sbc100, jgravelle-google, eraman, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, jrtc27, atanasyan, jsji, llvm-commits, kees, tpimh, nathanchance, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60887
llvm-svn: 359337
2019-04-27 02:45:04 +08:00
|
|
|
O << '#';
|
|
|
|
PrintSymbolOperand(MO, O);
|
2010-10-02 09:08:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
|
|
|
|
raw_ostream &O) {
|
|
|
|
const MachineOperand &Base = MI->getOperand(OpNum);
|
|
|
|
const MachineOperand &Disp = MI->getOperand(OpNum+1);
|
|
|
|
|
|
|
|
// Print displacement first
|
|
|
|
|
|
|
|
// Imm here is in fact global address - print extra modifier.
|
2019-01-25 17:14:05 +08:00
|
|
|
if (Disp.isImm() && Base.getReg() == MSP430::SR)
|
2010-10-02 09:08:17 +08:00
|
|
|
O << '&';
|
|
|
|
printOperand(MI, OpNum+1, O, "nohash");
|
|
|
|
|
|
|
|
// Print register base field
|
2019-01-25 17:14:05 +08:00
|
|
|
if (Base.getReg() != MSP430::SR && Base.getReg() != MSP430::PC) {
|
2010-10-02 09:08:17 +08:00
|
|
|
O << '(';
|
|
|
|
printOperand(MI, OpNum, O);
|
|
|
|
O << ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
|
|
|
bool MSP430AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
const char *ExtraCode, raw_ostream &O) {
|
|
|
|
// Does this asm operand have a single letter operand modifier?
|
|
|
|
if (ExtraCode && ExtraCode[0])
|
[AsmPrinter] refactor to support %c w/ GlobalAddress'
Summary:
Targets like ARM, MSP430, PPC, and SystemZ have complex behavior when
printing the address of a MachineOperand::MO_GlobalAddress. Move that
handling into a new overriden method in each base class. A virtual
method was added to the base class for handling the generic case.
Refactors a few subclasses to support the target independent %a, %c, and
%n.
The patch also contains small cleanups for AVRAsmPrinter and
SystemZAsmPrinter.
It seems that NVPTXTargetLowering is possibly missing some logic to
transform GlobalAddressSDNodes for
TargetLowering::LowerAsmOperandForConstraint to handle with "i" extended
inline assembly asm constraints.
Fixes:
- https://bugs.llvm.org/show_bug.cgi?id=41402
- https://github.com/ClangBuiltLinux/linux/issues/449
Reviewers: echristo, void
Reviewed By: void
Subscribers: void, craig.topper, jholewinski, dschuff, jyknight, dylanmckay, sdardis, nemanjai, javed.absar, sbc100, jgravelle-google, eraman, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, jrtc27, atanasyan, jsji, llvm-commits, kees, tpimh, nathanchance, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60887
llvm-svn: 359337
2019-04-27 02:45:04 +08:00
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
|
2010-10-02 09:08:17 +08:00
|
|
|
|
|
|
|
printOperand(MI, OpNo, O);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MSP430AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
unsigned OpNo,
|
2010-10-02 09:08:17 +08:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
return true; // Unknown modifier.
|
|
|
|
}
|
|
|
|
printSrcMemOperand(MI, OpNo, O);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-02-14 13:58:16 +08:00
|
|
|
void MSP430AsmPrinter::emitInstruction(const MachineInstr *MI) {
|
2012-06-07 02:25:08 +08:00
|
|
|
MSP430MCInstLower MCInstLowering(OutContext, *this);
|
2010-10-02 09:08:17 +08:00
|
|
|
|
|
|
|
MCInst TmpInst;
|
|
|
|
MCInstLowering.Lower(MI, TmpInst);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2010-10-02 09:08:17 +08:00
|
|
|
}
|
|
|
|
|
2019-01-16 22:03:41 +08:00
|
|
|
void MSP430AsmPrinter::EmitInterruptVectorSection(MachineFunction &ISR) {
|
|
|
|
MCSection *Cur = OutStreamer->getCurrentSectionOnly();
|
|
|
|
const auto *F = &ISR.getFunction();
|
2019-09-26 02:58:07 +08:00
|
|
|
if (F->getCallingConv() != CallingConv::MSP430_INTR) {
|
|
|
|
report_fatal_error("Functions with 'interrupt' attribute must have msp430_intrcc CC");
|
|
|
|
}
|
2019-01-16 22:03:41 +08:00
|
|
|
StringRef IVIdx = F->getFnAttribute("interrupt").getValueAsString();
|
|
|
|
MCSection *IV = OutStreamer->getContext().getELFSection(
|
|
|
|
"__interrupt_vector_" + IVIdx,
|
|
|
|
ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_EXECINSTR);
|
|
|
|
OutStreamer->SwitchSection(IV);
|
|
|
|
|
|
|
|
const MCSymbol *FunctionSymbol = getSymbol(F);
|
2020-02-15 11:21:58 +08:00
|
|
|
OutStreamer->emitSymbolValue(FunctionSymbol, TM.getProgramPointerSize());
|
2019-01-16 22:03:41 +08:00
|
|
|
OutStreamer->SwitchSection(Cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
// Emit separate section for an interrupt vector if ISR
|
2019-09-26 02:58:07 +08:00
|
|
|
if (MF.getFunction().hasFnAttribute("interrupt")) {
|
2019-01-16 22:03:41 +08:00
|
|
|
EmitInterruptVectorSection(MF);
|
2019-09-26 02:58:07 +08:00
|
|
|
}
|
2019-01-16 22:03:41 +08:00
|
|
|
|
|
|
|
SetupMachineFunction(MF);
|
2020-02-14 05:10:49 +08:00
|
|
|
emitFunctionBody();
|
2019-01-16 22:03:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-02 09:08:17 +08:00
|
|
|
// Force static initialization.
|
CMake: Make most target symbols hidden by default
Summary:
For builds with LLVM_BUILD_LLVM_DYLIB=ON and BUILD_SHARED_LIBS=OFF
this change makes all symbols in the target specific libraries hidden
by default.
A new macro called LLVM_EXTERNAL_VISIBILITY has been added to mark symbols in these
libraries public, which is mainly needed for the definitions of the
LLVMInitialize* functions.
This patch reduces the number of public symbols in libLLVM.so by about
25%. This should improve load times for the dynamic library and also
make abi checker tools, like abidiff require less memory when analyzing
libLLVM.so
One side-effect of this change is that for builds with
LLVM_BUILD_LLVM_DYLIB=ON and LLVM_LINK_LLVM_DYLIB=ON some unittests that
access symbols that are no longer public will need to be statically linked.
Before and after public symbol counts (using gcc 8.2.1, ld.bfd 2.31.1):
nm before/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
36221
nm after/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
26278
Reviewers: chandlerc, beanz, mgorny, rnk, hans
Reviewed By: rnk, hans
Subscribers: merge_guards_bot, luismarques, smeenai, ldionne, lenary, s.egerton, pzheng, sameer.abuasal, MaskRay, wuzish, echristo, Jim, hiraditya, michaelplatings, chapuni, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, mgrang, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, kristina, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D54439
2020-01-15 11:15:07 +08:00
|
|
|
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMSP430AsmPrinter() {
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterAsmPrinter<MSP430AsmPrinter> X(getTheMSP430Target());
|
2010-10-02 09:08:17 +08:00
|
|
|
}
|