2013-05-07 00:15:19 +08:00
|
|
|
//==- SystemZInstPrinter.h - Convert SystemZ MCInst to assembly --*- C++ -*-==//
|
|
|
|
//
|
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
|
2013-05-07 00:15:19 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class prints a SystemZ MCInst to a .s file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-05-11 11:36:16 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
|
|
|
|
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2017-02-04 07:39:06 +08:00
|
|
|
#include <cstdint>
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-02-04 07:39:06 +08:00
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
class MCOperand;
|
|
|
|
|
|
|
|
class SystemZInstPrinter : public MCInstPrinter {
|
|
|
|
public:
|
|
|
|
SystemZInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
|
|
|
|
const MCRegisterInfo &MRI)
|
|
|
|
: MCInstPrinter(MAI, MII, MRI) {}
|
|
|
|
|
|
|
|
// Automatically generated by tblgen.
|
2020-11-17 17:38:17 +08:00
|
|
|
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
|
2020-01-04 04:02:46 +08:00
|
|
|
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
|
2013-05-07 00:15:19 +08:00
|
|
|
static const char *getRegisterName(unsigned RegNo);
|
|
|
|
|
|
|
|
// Print an address with the given base, displacement and index.
|
|
|
|
static void printAddress(unsigned Base, int64_t Disp, unsigned Index,
|
|
|
|
raw_ostream &O);
|
|
|
|
|
|
|
|
// Print the given operand.
|
2015-06-09 08:31:39 +08:00
|
|
|
static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
|
|
|
|
raw_ostream &O);
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Override MCInstPrinter.
|
2014-03-06 20:03:36 +08:00
|
|
|
void printRegName(raw_ostream &O, unsigned RegNo) const override;
|
2020-01-04 02:55:30 +08:00
|
|
|
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
|
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) override;
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Print various types of operand.
|
|
|
|
void printOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
[MCInstPrinter] Pass `Address` parameter to MCOI::OPERAND_PCREL typed operands. NFC
Follow-up of D72172 and D72180
This patch passes `uint64_t Address` to print methods of PC-relative
operands so that subsequent target specific patches can change
`*InstPrinter::print{Operand,PCRelImm,...}` to customize the output.
Add MCInstPrinter::PrintBranchImmAsAddress which is set to true by
llvm-objdump.
```
// Current llvm-objdump -d output
aarch64: 20000: bl #0
ppc: 20000: bl .+4
x86: 20000: callq 0
// Ideal output
aarch64: 20000: bl 0x20000
ppc: 20000: bl 0x20004
x86: 20000: callq 0x20005
// GNU objdump -d. The lack of 0x is not ideal because the result cannot be re-assembled
aarch64: 20000: bl 20000
ppc: 20000: bl 0x20004
x86: 20000: callq 20005
```
In `lib/Target/X86/X86GenAsmWriter1.inc` (generated by `llvm-tblgen -gen-asm-writer`):
```
case 12:
// CALL64pcrel32, CALLpcrel16, CALLpcrel32, EH_SjLj_Setup, JCXZ, JECXZ, J...
- printPCRelImm(MI, 0, O);
+ printPCRelImm(MI, Address, 0, O);
return;
```
Some targets have 2 `printOperand` overloads, one without `Address` and
one with `Address`. They should annotate derived `Operand` properly with
`let OperandType = "OPERAND_PCREL"`.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D76574
2020-03-23 03:32:27 +08:00
|
|
|
void printOperand(const MCInst *MI, uint64_t /*Address*/, unsigned OpNum,
|
|
|
|
raw_ostream &O) {
|
|
|
|
printOperand(MI, OpNum, O);
|
|
|
|
}
|
2013-05-07 00:15:19 +08:00
|
|
|
void printBDAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printBDXAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2013-07-02 22:56:45 +08:00
|
|
|
void printBDLAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2016-10-31 22:21:36 +08:00
|
|
|
void printBDRAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2015-05-06 03:23:40 +08:00
|
|
|
void printBDVAddrOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printU1ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printU2ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printU3ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2013-05-07 00:15:19 +08:00
|
|
|
void printU4ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printU6ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printS8ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printU8ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2015-05-06 03:23:40 +08:00
|
|
|
void printU12ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2013-05-07 00:15:19 +08:00
|
|
|
void printS16ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printU16ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printS32ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
void printU32ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2016-08-08 23:13:08 +08:00
|
|
|
void printU48ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
2013-05-14 18:17:52 +08:00
|
|
|
void printPCRelOperand(const MCInst *MI, int OpNum, raw_ostream &O);
|
[MCInstPrinter] Pass `Address` parameter to MCOI::OPERAND_PCREL typed operands. NFC
Follow-up of D72172 and D72180
This patch passes `uint64_t Address` to print methods of PC-relative
operands so that subsequent target specific patches can change
`*InstPrinter::print{Operand,PCRelImm,...}` to customize the output.
Add MCInstPrinter::PrintBranchImmAsAddress which is set to true by
llvm-objdump.
```
// Current llvm-objdump -d output
aarch64: 20000: bl #0
ppc: 20000: bl .+4
x86: 20000: callq 0
// Ideal output
aarch64: 20000: bl 0x20000
ppc: 20000: bl 0x20004
x86: 20000: callq 0x20005
// GNU objdump -d. The lack of 0x is not ideal because the result cannot be re-assembled
aarch64: 20000: bl 20000
ppc: 20000: bl 0x20004
x86: 20000: callq 20005
```
In `lib/Target/X86/X86GenAsmWriter1.inc` (generated by `llvm-tblgen -gen-asm-writer`):
```
case 12:
// CALL64pcrel32, CALLpcrel16, CALLpcrel32, EH_SjLj_Setup, JCXZ, JECXZ, J...
- printPCRelImm(MI, 0, O);
+ printPCRelImm(MI, Address, 0, O);
return;
```
Some targets have 2 `printOperand` overloads, one without `Address` and
one with `Address`. They should annotate derived `Operand` properly with
`let OperandType = "OPERAND_PCREL"`.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D76574
2020-03-23 03:32:27 +08:00
|
|
|
void printPCRelOperand(const MCInst *MI, uint64_t /*Address*/, int OpNum,
|
|
|
|
raw_ostream &O) {
|
|
|
|
printPCRelOperand(MI, OpNum, O);
|
|
|
|
}
|
|
|
|
void printPCRelTLSOperand(const MCInst *MI, uint64_t Address, int OpNum,
|
|
|
|
raw_ostream &O);
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
// Print the mnemonic for a condition-code mask ("ne", "lh", etc.)
|
|
|
|
// This forms part of the instruction name rather than the operand list.
|
|
|
|
void printCond4Operand(const MCInst *MI, int OpNum, raw_ostream &O);
|
|
|
|
};
|
2017-02-04 07:39:06 +08:00
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
2019-05-11 11:36:16 +08:00
|
|
|
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZINSTPRINTER_H
|