Skip to content

Commit ebcf7f9

Browse files
authored
[SystemZ][HLASM] Emit END instruction (#146110)
A HLASM source file must end with the END instruction. It is implemented by adding a new function to the target streamer. This change also turns SystemZHLASMSAsmString.h into a proper header file, and only uses the SystemZTargetHLASMStreamer when HLASM output is generated.
1 parent bbcebec commit ebcf7f9

File tree

7 files changed

+31
-3
lines changed

7 files changed

+31
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "llvm/Support/Signals.h"
1313
#include <sstream>
1414

15-
#include <cmath>
15+
using namespace llvm;
1616

1717
void SystemZHLASMAsmStreamer::EmitEOL() {
1818
// Comments are emitted on a new line before the instruction.
@@ -280,3 +280,8 @@ void SystemZHLASMAsmStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
280280
emitHLASMValueImpl(Value, Size, true);
281281
EmitEOL();
282282
}
283+
284+
void SystemZHLASMAsmStreamer::emitEnd() {
285+
OS << " END";
286+
EmitEOL();
287+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#ifndef LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H
14+
#define LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H
15+
1316
#include "llvm/ADT/SmallString.h"
1417
#include "llvm/ADT/StringRef.h"
1518
#include "llvm/MC/MCAsmBackend.h"
@@ -24,7 +27,7 @@
2427
#include "llvm/MC/MCTargetOptions.h"
2528
#include "llvm/Support/FormattedStream.h"
2629

27-
using namespace llvm;
30+
namespace llvm {
2831

2932
class SystemZHLASMAsmStreamer final : public MCStreamer {
3033
constexpr static size_t InstLimit = 80;
@@ -119,4 +122,9 @@ class SystemZHLASMAsmStreamer final : public MCStreamer {
119122
void emitHLASMValueImpl(const MCExpr *Value, unsigned Size,
120123
bool Parens = false);
121124
/// @}
125+
126+
void emitEnd();
122127
};
128+
} // namespace llvm
129+
130+
#endif // LLVM_LIB_TARGET_SYSTEMZ_MCTARGETDESC_SYSTEMZHLASMASMSTREAMER_H

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static MCInstPrinter *createSystemZMCInstPrinter(const Triple &T,
203203
static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
204204
formatted_raw_ostream &OS,
205205
MCInstPrinter *InstPrint) {
206-
if (S.getContext().getTargetTriple().isOSzOS())
206+
if (S.getContext().getTargetTriple().isOSzOS() && !GNUAsOnzOSCL)
207207
return new SystemZTargetHLASMStreamer(S, OS);
208208
else
209209
return new SystemZTargetGNUStreamer(S, OS);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "SystemZTargetStreamer.h"
16+
#include "SystemZHLASMAsmStreamer.h"
1617
#include "llvm/MC/MCAsmInfo.h"
1718
#include "llvm/MC/MCObjectFileInfo.h"
1819

@@ -33,10 +34,16 @@ void SystemZTargetStreamer::emitConstantPools() {
3334
EXRLTargets2Sym.clear();
3435
}
3536

37+
SystemZHLASMAsmStreamer &SystemZTargetHLASMStreamer::getHLASMStreamer() {
38+
return static_cast<SystemZHLASMAsmStreamer &>(getStreamer());
39+
}
40+
3641
void SystemZTargetHLASMStreamer::emitExtern(StringRef Sym) {
3742
getStreamer().emitRawText(Twine(" EXTRN ") + Twine(Sym));
3843
}
3944

45+
void SystemZTargetHLASMStreamer::emitEnd() { getHLASMStreamer().emitEnd(); }
46+
4047
// HLASM statements can only perform a single operation at a time
4148
const MCExpr *SystemZTargetHLASMStreamer::createWordDiffExpr(
4249
MCContext &Ctx, const MCSymbol *Hi, const MCSymbol *Lo) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <utility>
2121

2222
namespace llvm {
23+
class SystemZHLASMAsmStreamer;
2324

2425
class SystemZTargetStreamer : public MCTargetStreamer {
2526
public:
@@ -57,6 +58,7 @@ class SystemZTargetStreamer : public MCTargetStreamer {
5758
virtual void emitMachine(StringRef CPUOrCommand) {};
5859

5960
virtual void emitExtern(StringRef Str) {};
61+
virtual void emitEnd() {};
6062

6163
virtual const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
6264
const MCSymbol *Lo) {
@@ -77,7 +79,9 @@ class SystemZTargetHLASMStreamer : public SystemZTargetStreamer {
7779
public:
7880
SystemZTargetHLASMStreamer(MCStreamer &S, formatted_raw_ostream &OS)
7981
: SystemZTargetStreamer(S), OS(OS) {}
82+
SystemZHLASMAsmStreamer &getHLASMStreamer();
8083
void emitExtern(StringRef Sym) override;
84+
void emitEnd() override;
8185
const MCExpr *createWordDiffExpr(MCContext &Ctx, const MCSymbol *Hi,
8286
const MCSymbol *Lo) override;
8387
};

llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,9 @@ void SystemZAsmPrinter::emitEndOfAsmFile(Module &M) {
11141114
emitIDRLSection(M);
11151115
}
11161116
emitAttributes(M);
1117+
// Emit the END instruction in case of HLASM output. This must be the last
1118+
// instruction in the source file.
1119+
getTargetStreamer()->emitEnd();
11171120
}
11181121

11191122
void SystemZAsmPrinter::emitADASection() {

llvm/test/CodeGen/SystemZ/zos-hlasm-out.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ define void @foo() {
4242
; CHECK: DS 0B
4343
; CHECK-LABEL: L#.str.1 DS 0H
4444
; CHECK: DC XL6'576F726C6400'
45+
; CHECK: END
4546
entry:
4647
%0 = load ptr, ptr @Greeting, align 8
4748
call void (ptr, ...) @outs(ptr noundef %0, ptr noundef @.str.1)

0 commit comments

Comments
 (0)