LLVM 23.0.0git
MCAsmInfoGOFF.cpp
Go to the documentation of this file.
1//===- MCAsmInfoGOFF.cpp - MCGOFFAsmInfo properties -----------------------===//
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///
9/// \file
10/// This file defines certain target specific asm properties for GOFF (z/OS)
11/// based targets.
12///
13//===----------------------------------------------------------------------===//
14
21
22using namespace llvm;
23
32
33static void emitCATTR(raw_ostream &OS, StringRef Name, GOFF::ESDRmode Rmode,
34 GOFF::ESDAlignment Alignment,
35 GOFF::ESDLoadingBehavior LoadBehavior,
36 GOFF::ESDExecutable Executable, bool IsReadOnly,
37 uint32_t SortKey, uint8_t FillByteValue,
38 StringRef PartName) {
39 OS << Name << " CATTR ";
40 OS << "ALIGN(" << static_cast<unsigned>(Alignment) << "),"
41 << "FILL(" << static_cast<unsigned>(FillByteValue) << ")";
42 switch (LoadBehavior) {
44 OS << ",DEFLOAD";
45 break;
47 OS << ",NOLOAD";
48 break;
49 default:
50 break;
51 }
52 switch (Executable) {
54 OS << ",EXECUTABLE";
55 break;
57 OS << ",NOTEXECUTABLE";
58 break;
59 default:
60 break;
61 }
62 if (IsReadOnly)
63 OS << ",READONLY";
64 if (Rmode != GOFF::ESD_RMODE_None) {
65 OS << ',';
66 OS << "RMODE(";
67 switch (Rmode) {
71 OS << "24";
72 break;
74 OS << "31";
75 break;
77 OS << "64";
78 break;
79 }
80 OS << ')';
81 }
82 if (SortKey)
83 OS << ",PRIORITY(" << SortKey << ")";
84 if (!PartName.empty())
85 OS << ",PART(" << PartName << ")";
86 OS << '\n';
87}
88
89static void emitXATTR(raw_ostream &OS, StringRef Name, MCSectionGOFF *ADA,
91 GOFF::ESDExecutable Executable,
92 GOFF::ESDBindingScope BindingScope) {
93 llvm::ListSeparator Sep(",");
94 OS << Name << " XATTR ";
95 OS << Sep << "LINKAGE(" << (Linkage == GOFF::ESD_LT_OS ? "OS" : "XPLINK")
96 << ")";
97 if (Executable != GOFF::ESD_EXE_Unspecified)
98 OS << Sep << "REFERENCE("
99 << (Executable == GOFF::ESD_EXE_CODE ? "CODE" : "DATA") << ")";
100 if (ADA)
101 OS << Sep << "PSECT(" << ADA->getName() << ")";
102 if (BindingScope != GOFF::ESD_BSC_Unspecified) {
103 OS << Sep << "SCOPE(";
104 switch (BindingScope) {
106 OS << "SECTION";
107 break;
109 OS << "MODULE";
110 break;
112 OS << "LIBRARY";
113 break;
115 OS << "EXPORT";
116 break;
117 default:
118 break;
119 }
120 OS << ')';
121 }
122 OS << '\n';
123}
124
125void MCAsmInfoGOFF::printSwitchToSection(const MCSection &Section,
126 uint32_t Subsection, const Triple &T,
127 raw_ostream &OS) const {
128 auto &Sec =
129 const_cast<MCSectionGOFF &>(static_cast<const MCSectionGOFF &>(Section));
130 auto EmitExternalName = [&Sec, &OS]() {
131 if (Sec.hasExternalName())
132 OS << Sec.getName() << " ALIAS C'" << Sec.getExternalName() << "'\n";
133 };
134 switch (Sec.SymbolType) {
136 OS << Sec.getName() << " CSECT\n";
137 Sec.Emitted = true;
138 EmitExternalName();
139 break;
140 }
142 printSwitchToSection(*Sec.getParent(), Subsection, T, OS);
143 if (!Sec.Emitted) {
144 emitCATTR(OS, Sec.getName(), Sec.EDAttributes.Rmode,
145 Sec.EDAttributes.Alignment, Sec.EDAttributes.LoadBehavior,
146 GOFF::ESD_EXE_Unspecified, Sec.EDAttributes.IsReadOnly, 0,
147 Sec.EDAttributes.FillByteValue, StringRef());
148 if (auto *BeginSym = static_cast<MCSymbolGOFF *>(Sec.getBeginSymbol())) {
149 if (BeginSym->getADA())
150 emitXATTR(OS, BeginSym->getName(), BeginSym->getADA(),
153 }
154 Sec.Emitted = true;
155 EmitExternalName();
156 } else
157 OS << Sec.getName() << " CATTR\n";
158 break;
159 }
161 MCSectionGOFF *ED = Sec.getParent();
162 printSwitchToSection(*ED->getParent(), Subsection, T, OS);
163 if (!Sec.Emitted) {
164 emitCATTR(OS, ED->getName(), ED->getEDAttributes().Rmode,
166 Sec.PRAttributes.Executable, ED->EDAttributes.IsReadOnly,
167 Sec.PRAttributes.SortKey, ED->EDAttributes.FillByteValue,
168 Sec.getName());
169 MCSectionGOFF *ADA =
170 Sec.getBeginSymbol() != nullptr
171 ? static_cast<MCSymbolGOFF *>(Sec.getBeginSymbol())->getADA()
172 : nullptr;
173 emitXATTR(OS, Sec.getName(), ADA, Sec.PRAttributes.Linkage,
174 Sec.PRAttributes.Executable, Sec.PRAttributes.BindingScope);
175 ED->Emitted = true;
176 Sec.Emitted = true;
177 EmitExternalName();
178 } else
179 OS << ED->getName() << " CATTR PART(" << Sec.getName() << ")\n";
180 break;
181 }
182 default:
183 llvm_unreachable("Wrong section type");
184 }
185}
DXIL Finalize Linkage
static LVOptions Options
Definition LVOptions.cpp:25
static void emitCATTR(raw_ostream &OS, StringRef Name, GOFF::ESDRmode Rmode, GOFF::ESDAlignment Alignment, GOFF::ESDLoadingBehavior LoadBehavior, GOFF::ESDExecutable Executable, bool IsReadOnly, uint32_t SortKey, uint8_t FillByteValue, StringRef PartName)
static void emitXATTR(raw_ostream &OS, StringRef Name, MCSectionGOFF *ADA, GOFF::ESDLinkageType Linkage, GOFF::ESDExecutable Executable, GOFF::ESDBindingScope BindingScope)
This file defines certain target specific asm properties for GOFF (z/OS) based targets.
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
This file contains the MCSymbolGOFF class.
#define T
This file contains some functions that are useful when dealing with strings.
A helper class to return the specified delimiter string after the first invocation of operator String...
MCAsmInfoGOFF(const MCTargetOptions &Options)
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:160
const char * Data64bitsDirective
Definition MCAsmInfo.h:249
MCAsmInfo(const MCTargetOptions &Options)
Definition MCAsmInfo.cpp:44
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:327
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks. Defaults to "L".
Definition MCAsmInfo.h:163
const char * ZeroDirective
This should be set to the directive used to get some number of zero (and non-zero if supported by the...
Definition MCAsmInfo.h:225
GOFF::EDAttr getEDAttributes() const
GOFF::EDAttr EDAttributes
MCSectionGOFF * getParent() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:573
StringRef getName() const
Definition MCSection.h:643
Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:140
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ESDLoadingBehavior
Definition GOFF.h:127
@ ESD_LB_Deferred
Definition GOFF.h:129
@ ESD_LB_NoLoad
Definition GOFF.h:130
ESDExecutable
Definition GOFF.h:109
@ ESD_EXE_Unspecified
Definition GOFF.h:110
@ ESD_EXE_CODE
Definition GOFF.h:112
@ ESD_EXE_DATA
Definition GOFF.h:111
ESDAlignment
Definition GOFF.h:144
ESDBindingScope
Definition GOFF.h:134
@ ESD_BSC_Library
Definition GOFF.h:138
@ ESD_BSC_Module
Definition GOFF.h:137
@ ESD_BSC_Unspecified
Definition GOFF.h:135
@ ESD_BSC_ImportExport
Definition GOFF.h:139
@ ESD_BSC_Section
Definition GOFF.h:136
ESDLinkageType
Definition GOFF.h:142
@ ESD_LT_OS
Definition GOFF.h:142
@ ESD_LT_XPLink
Definition GOFF.h:142
@ ESD_ST_PartReference
Definition GOFF.h:57
@ ESD_ST_ElementDefinition
Definition GOFF.h:55
@ ESD_ST_SectionDefinition
Definition GOFF.h:54
@ ESD_RMODE_31
Definition GOFF.h:87
@ ESD_RMODE_None
Definition GOFF.h:85
@ ESD_RMODE_64
Definition GOFF.h:88
@ ESD_RMODE_24
Definition GOFF.h:86
This is an optimization pass for GlobalISel generic memory operations.
GOFF::ESDRmode Rmode
GOFF::ESDAlignment Alignment
GOFF::ESDLoadingBehavior LoadBehavior