Skip to content

Commit 7763a9f

Browse files
committed
Update
1 parent a80ae0f commit 7763a9f

File tree

7 files changed

+105
-11
lines changed

7 files changed

+105
-11
lines changed

llvm/include/llvm/MC/MCDirectives.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ enum MCSymbolAttr {
4848
MCSA_WeakDefAutoPrivate, ///< .weak_def_can_be_hidden (MachO)
4949
MCSA_WeakAntiDep, ///< .weak_anti_dep (COFF)
5050
MCSA_Memtag, ///< .memtag (ELF)
51+
52+
// Attributes specific for HLASM.
53+
MCSA_Code, ///< symbol is code (GOFF)
54+
MCSA_Data, ///< symbol is data (GOFF)
5155
};
5256

5357
enum MCDataRegionType {

llvm/lib/MC/MCSymbolGOFF.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
using namespace llvm;
1515

1616
void MCSymbolGOFF::initAttributes() {
17+
// Temporary labels are not emitted into the object file.
18+
if (isTemporary())
19+
return;
20+
21+
// Do not initialize the attributes multiple times.
1722
if (hasLDAttributes())
1823
return;
1924

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
#include "SystemZHLASMAsmStreamer.h"
1010
#include "llvm/ADT/StringExtras.h"
11+
#include "llvm/BinaryFormat/GOFF.h"
12+
#include "llvm/MC/MCGOFFAttributes.h"
13+
#include "llvm/MC/MCSymbolGOFF.h"
1114
#include "llvm/Support/Casting.h"
1215
#include "llvm/Support/Signals.h"
1316
#include <sstream>
@@ -183,17 +186,74 @@ void SystemZHLASMAsmStreamer::emitInstruction(const MCInst &Inst,
183186
EmitEOL();
184187
}
185188

189+
static void emitXATTR(raw_ostream &OS, StringRef Name,
190+
GOFF::ESDLinkageType Linkage,
191+
GOFF::ESDExecutable Executable,
192+
GOFF::ESDBindingScope BindingScope) {
193+
OS << Name << " XATTR ";
194+
OS << "LINKAGE(" << (Linkage == GOFF::ESD_LT_OS ? "OS" : "XPLINK") << "),";
195+
if (Executable != GOFF::ESD_EXE_Unspecified)
196+
OS << "REFERENCE(" << (Executable == GOFF::ESD_EXE_CODE ? "CODE" : "DATA")
197+
<< "),";
198+
if (BindingScope != GOFF::ESD_BSC_Unspecified) {
199+
OS << "SCOPE(";
200+
switch (BindingScope) {
201+
case GOFF::ESD_BSC_Section:
202+
OS << "SECTION";
203+
break;
204+
case GOFF::ESD_BSC_Module:
205+
OS << "MODULE";
206+
break;
207+
case GOFF::ESD_BSC_Library:
208+
OS << "LIBRARY";
209+
break;
210+
case GOFF::ESD_BSC_ImportExport:
211+
OS << "EXPORT";
212+
break;
213+
default:
214+
break;
215+
}
216+
OS << ')';
217+
}
218+
OS << '\n';
219+
}
220+
221+
static bool sameNameAsCSECT(MCSymbolGOFF *Sym) {
222+
if (Sym->hasLDAttributes() && Sym->isInSection()) {
223+
MCSectionGOFF &ED = cast<MCSectionGOFF>(Sym->getSection());
224+
return Sym->getName() == ED.getParent()->getName();
225+
}
226+
return false;
227+
}
228+
186229
void SystemZHLASMAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
230+
MCSymbolGOFF *Sym = cast<MCSymbolGOFF>(Symbol);
231+
232+
MCStreamer::emitLabel(Sym, Loc);
233+
Sym->initAttributes();
234+
235+
// Emit ENTRY statement only if not implied by CSECT.
236+
bool EmitEntry = !sameNameAsCSECT(Sym);
187237

188-
MCStreamer::emitLabel(Symbol, Loc);
238+
if (!Sym->isTemporary() && Sym->hasLDAttributes()) {
239+
GOFF::LDAttr &LD = Sym->getLDAttributes();
240+
if (EmitEntry) {
241+
OS << " ENTRY " << Sym->getName();
242+
EmitEOL();
243+
}
244+
245+
emitXATTR(OS, Sym->getName(), LD.Linkage, LD.Executable, LD.BindingScope);
246+
EmitEOL();
247+
}
189248

190-
Symbol->print(OS, MAI);
191249
// TODO Need to adjust this based on Label type
192-
OS << " DS 0H";
193-
// TODO Update LabelSuffix in SystemZMCAsmInfoGOFF once tests have been
194-
// moved to HLASM syntax.
195-
// OS << MAI->getLabelSuffix();
196-
EmitEOL();
250+
if (EmitEntry) {
251+
OS << Sym->getName() << " DS 0H";
252+
// TODO Update LabelSuffix in SystemZMCAsmInfoGOFF once tests have been
253+
// moved to HLASM syntax.
254+
// OS << MAI->getLabelSuffix();
255+
EmitEOL();
256+
}
197257
}
198258

199259
void SystemZHLASMAsmStreamer::emitRawTextImpl(StringRef String) {
@@ -285,3 +345,10 @@ void SystemZHLASMAsmStreamer::emitEnd() {
285345
OS << " END";
286346
EmitEOL();
287347
}
348+
349+
void SystemZHLASMAsmStreamer::emitExtern(MCSymbolGOFF &Sym) {
350+
Sym.initAttributes();
351+
OS << " EXTRN " << Sym.getName();
352+
EmitEOL();
353+
// TODO Emit XATTR.
354+
}

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/Support/FormattedStream.h"
2929

3030
namespace llvm {
31+
class MCSymbolGOFF;
3132

3233
class SystemZHLASMAsmStreamer final : public MCStreamer {
3334
constexpr static size_t InstLimit = 80;
@@ -123,6 +124,7 @@ class SystemZHLASMAsmStreamer final : public MCStreamer {
123124
/// @}
124125

125126
void emitEnd();
127+
void emitExtern(MCSymbolGOFF &Sym);
126128
};
127129
} // namespace llvm
128130

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "SystemZHLASMAsmStreamer.h"
1717
#include "llvm/MC/MCAsmInfo.h"
1818
#include "llvm/MC/MCObjectFileInfo.h"
19+
#include "llvm/MC/MCSymbolGOFF.h"
20+
#include "llvm/Support/Casting.h"
1921

2022
using namespace llvm;
2123

@@ -38,8 +40,8 @@ SystemZHLASMAsmStreamer &SystemZTargetHLASMStreamer::getHLASMStreamer() {
3840
return static_cast<SystemZHLASMAsmStreamer &>(getStreamer());
3941
}
4042

41-
void SystemZTargetHLASMStreamer::emitExtern(StringRef Sym) {
42-
getStreamer().emitRawText(Twine(" EXTRN ") + Twine(Sym));
43+
void SystemZTargetHLASMStreamer::emitExtern(MCSymbol *Symbol) {
44+
getHLASMStreamer().emitExtern(*cast<MCSymbolGOFF>(Symbol));
4345
}
4446

4547
void SystemZTargetHLASMStreamer::emitEnd() { getHLASMStreamer().emitEnd(); }

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZTargetStreamer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SystemZTargetStreamer : public MCTargetStreamer {
5757

5858
virtual void emitMachine(StringRef CPUOrCommand) {};
5959

60-
virtual void emitExtern(StringRef Str) {};
60+
virtual void emitExtern(MCSymbol *Symbol) {};
6161
virtual void emitEnd() {};
6262

6363
virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
@@ -69,6 +69,7 @@ class SystemZTargetStreamer : public MCTargetStreamer {
6969
class SystemZTargetGOFFStreamer : public SystemZTargetStreamer {
7070
public:
7171
SystemZTargetGOFFStreamer(MCStreamer &S) : SystemZTargetStreamer(S) {}
72+
//void emitExtern(MCSymbol *Symbol) override;
7273
const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
7374
const MCSymbol *Lo) override;
7475
};
@@ -80,7 +81,7 @@ class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
8081
SystemZTargetHLASMStreamer(MCStreamer &S, formatted_raw_ostream &OS)
8182
: SystemZTargetStreamer(S), OS(OS) {}
8283
SystemZHLASMAsmStreamer &getHLASMStreamer();
83-
void emitExtern(StringRef Sym) override;
84+
void emitExtern(MCSymbol *Symbol) override;
8485
void emitEnd() override;
8586
const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
8687
const MCSymbol *Lo) override;

llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
2727
#include "llvm/IR/Mangler.h"
2828
#include "llvm/IR/Module.h"
29+
#include "llvm/MC/MCDirectives.h"
2930
#include "llvm/MC/MCExpr.h"
3031
#include "llvm/MC/MCInstBuilder.h"
3132
#include "llvm/MC/MCSectionELF.h"
@@ -1112,6 +1113,17 @@ void SystemZAsmPrinter::emitEndOfAsmFile(Module &M) {
11121113
if (TT.isOSzOS()) {
11131114
emitADASection();
11141115
emitIDRLSection(M);
1116+
// Emit EXTRN declarations.
1117+
for (auto &GO : M.global_objects()) {
1118+
if (GO.isDeclaration()) {
1119+
MCSymbol *Sym = TM.getSymbol(&GO);
1120+
OutStreamer->emitSymbolAttribute(
1121+
Sym, GO.hasWeakLinkage() ? MCSA_WeakReference : MCSA_Global);
1122+
OutStreamer->emitSymbolAttribute(Sym, isa<Function>(GO) ? MCSA_Code
1123+
: MCSA_Data);
1124+
getTargetStreamer()->emitExtern(Sym);
1125+
}
1126+
}
11151127
}
11161128
emitAttributes(M);
11171129
// Emit the END instruction in case of HLASM output. This must be the last
@@ -1570,6 +1582,7 @@ void SystemZAsmPrinter::emitPPA2(Module &M) {
15701582
// Make CELQSTRT symbol.
15711583
const char *StartSymbolName = "CELQSTRT";
15721584
MCSymbol *CELQSTRT = OutContext.getOrCreateSymbol(StartSymbolName);
1585+
getTargetStreamer()->emitExtern(CELQSTRT);
15731586

15741587
// Create symbol and assign to class field for use in PPA1.
15751588
PPA2Sym = OutContext.createTempSymbol("PPA2", false);

0 commit comments

Comments
 (0)