LLVM 24.0.0git
SystemZHLASMInstPrinter.cpp
Go to the documentation of this file.
1//=- SystemZHLASMInstPrinter.cpp - Convert SystemZ MCInst to HLASM assembly -=//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "llvm/MC/MCInst.h"
12#include "llvm/MC/MCRegister.h"
14
15using namespace llvm;
16
17#define DEBUG_TYPE "asm-printer"
18
19#include "SystemZGenHLASMAsmWriter.inc"
20
21void SystemZHLASMInstPrinter::printFormattedRegName(const MCAsmInfo *MAI,
23 raw_ostream &O) {
24 const char *RegName = getRegisterName(Reg);
25 // Skip register prefix so that only register number is left
26 assert(isalpha(RegName[0]) && isdigit(RegName[1]));
27 markup(O, Markup::Register) << (RegName + 1);
28}
29
31 StringRef Annot,
32 const MCSubtargetInfo &STI,
33 raw_ostream &O) {
34 MCInst TempMI;
35 unsigned Opcode = MI->getOpcode();
36 if (Opcode == SystemZ::BRC || Opcode == SystemZ::BRCL ||
37 Opcode == SystemZ::BC || Opcode == SystemZ::BCR ||
38 Opcode == SystemZ::BIC) {
39 uint64_t CCValid = MI->getOperand(0).getImm();
40 uint64_t CCMask = MI->getOperand(1).getImm();
41 // Unsupported HLASM condition masks (which have no valid HLASM extended
42 // mnemonics): "nle" (3), "nhe" (5), "lh" (6), "nlh" (9), "he" (10), "le"
43 // (12).
44 if (CCMask == 3 || CCMask == 5 || CCMask == 6 || CCMask == 9 ||
45 CCMask == 10 || CCMask == 12) {
46 if ((CCValid & 1) == 0) {
47 // If CC 3 cannot happen, invert the low bit to yield a mask with a
48 // valid HLASM extended mnemonic (e.g. 10 ("he") -> 11 ("nl")).
49 TempMI = *MI;
50 TempMI.getOperand(1).setImm(CCMask ^ 1);
51 MI = &TempMI;
52 } else {
53 // Use variant instructions that print numerical masks.
54 unsigned AsmOpcode = 0;
55 switch (Opcode) {
56 case SystemZ::BRC:
57 AsmOpcode = SystemZ::BRCAsm;
58 break;
59 case SystemZ::BRCL:
60 AsmOpcode = SystemZ::BRCLAsm;
61 break;
62 case SystemZ::BC:
63 AsmOpcode = SystemZ::BCAsm;
64 break;
65 case SystemZ::BCR:
66 AsmOpcode = SystemZ::BCRAsm;
67 break;
68 case SystemZ::BIC:
69 AsmOpcode = SystemZ::BICAsm;
70 break;
71 }
72 TempMI.setOpcode(AsmOpcode);
73 TempMI.addOperand(MCOperand::createImm(CCMask));
74 for (unsigned I = 2; I < MI->getNumOperands(); ++I)
75 TempMI.addOperand(MI->getOperand(I));
76 MI = &TempMI;
77 }
78 }
79 }
80
81 std::string Str;
82 raw_string_ostream RSO(Str);
84 // Eat the first tab character and replace it with a space since it is
85 // hardcoded in AsmWriterEmitter::EmitPrintInstruction
86 // TODO: introduce a line prefix member to AsmWriter to avoid this problem
87 if (!Str.empty() && Str.front() == '\t')
88 O << " " << Str.substr(1, Str.length());
89 else
90 O << Str;
91
92 printAnnotation(O, Annot);
93}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
IRTranslator LLVM IR MI
#define RegName(no)
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:67
WithMarkup markup(raw_ostream &OS, Markup M)
void printAnnotation(raw_ostream &OS, StringRef Annot)
Utility function for printing annotations.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
void setImm(int64_t Val)
Definition MCInst.h:89
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Generic base class for all target subtargets.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static const char * getRegisterName(MCRegister Reg)
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O)
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override
Print the specified MCInst to the specified raw_ostream.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an std::string.
This is an optimization pass for GlobalISel generic memory operations.