Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions llvm/include/llvm/MC/TargetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ class Target {
using AsmTargetStreamerCtorTy =
MCTargetStreamer *(*)(MCStreamer &S, formatted_raw_ostream &OS,
MCInstPrinter *InstPrint);
using AsmStreamerCtorTy =
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP, std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB);
using ObjectTargetStreamerCtorTy = MCTargetStreamer *(*)(
MCStreamer &S, const MCSubtargetInfo &STI);
using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
Expand Down Expand Up @@ -316,6 +320,10 @@ class Target {
/// registered (default = nullptr).
AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;

/// Construction function for this target's AsmStreamer, if
/// registered (default = nullptr).
AsmStreamerCtorTy AsmStreamerCtorFn = nullptr;

/// Construction function for this target's obj TargetStreamer, if
/// registered (default = nullptr).
ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
Expand Down Expand Up @@ -927,6 +935,10 @@ struct TargetRegistry {
T.NullTargetStreamerCtorFn = Fn;
}

static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
T.AsmStreamerCtorFn = Fn;
}

static void RegisterAsmTargetStreamer(Target &T,
Target::AsmTargetStreamerCtorTy Fn) {
T.AsmTargetStreamerCtorFn = Fn;
Expand Down
10 changes: 8 additions & 2 deletions llvm/lib/MC/TargetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ MCStreamer *Target::createAsmStreamer(MCContext &Ctx,
std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB) const {
formatted_raw_ostream &OSRef = *OS;
MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IP,
std::move(CE), std::move(TAB));
MCStreamer *S;
if (AsmStreamerCtorFn)
S = AsmStreamerCtorFn(Ctx, std::move(OS), IP, std::move(CE),
std::move(TAB));
else
S = llvm::createAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
std::move(TAB));

createAsmTargetStreamer(*S, OSRef, IP);
return S;
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_llvm_component_library(LLVMSystemZDesc
SystemZELFObjectWriter.cpp
SystemZGOFFObjectWriter.cpp
SystemZHLASMAsmStreamer.cpp
SystemZInstPrinter.cpp
SystemZMCAsmBackend.cpp
SystemZMCAsmInfo.cpp
Expand Down
24 changes: 24 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- SystemZHLASMAsmStreamer.cpp - HLASM Assembly Text Output -----------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "SystemZHLASMAsmStreamer.h"

void SystemZHLASMAsmStreamer::changeSection(MCSection *Section,
uint32_t Subsection) {
MCStreamer::changeSection(Section, Subsection);
}

void SystemZHLASMAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
MCStreamer::emitLabel(Symbol, Loc);

Symbol->print(OS, MAI);
// TODO: update LabelSuffix in SystemZMCAsmInfoGOFF once tests have been
// moved to HLASM syntax.
// OS << MAI->getLabelSuffix();
OS << '\n';
}
93 changes: 93 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//===- SystemZHLASMAsmStreamer.h - HLASM Assembly Text Output ---*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file declares the SystemZHLASMAsmStreamer class.
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Support/FormattedStream.h"

using namespace llvm;

class SystemZHLASMAsmStreamer final : public MCStreamer {
std::unique_ptr<formatted_raw_ostream> OSOwner;
formatted_raw_ostream &OS;
const MCAsmInfo *MAI;
std::unique_ptr<MCInstPrinter> InstPrinter;
std::unique_ptr<MCAssembler> Assembler;
SmallString<128> CommentToEmit;
raw_svector_ostream CommentStream;
raw_null_ostream NullStream;

bool IsVerboseAsm = false;

public:
SystemZHLASMAsmStreamer(MCContext &Context,
std::unique_ptr<formatted_raw_ostream> os,
MCInstPrinter *printer,
std::unique_ptr<MCCodeEmitter> emitter,
std::unique_ptr<MCAsmBackend> asmbackend)
: MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
MAI(Context.getAsmInfo()), InstPrinter(printer),
Assembler(std::make_unique<MCAssembler>(
Context, std::move(asmbackend), std::move(emitter),
(asmbackend) ? asmbackend->createObjectWriter(NullStream)
: nullptr)),
CommentStream(CommentToEmit) {
assert(InstPrinter);
if (Assembler->getBackendPtr())
setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());

Context.setUseNamesOnTempLabels(true);
auto *TO = Context.getTargetOptions();
if (!TO)
return;
IsVerboseAsm = TO->AsmVerbose;
if (IsVerboseAsm)
InstPrinter->setCommentStream(CommentStream);
}

MCAssembler &getAssembler() { return *Assembler; }

/// Return true if this streamer supports verbose assembly at all.
bool isVerboseAsm() const override { return IsVerboseAsm; }

/// Do we support EmitRawText?
bool hasRawTextSupport() const override { return true; }

/// @name MCStreamer Interface
/// @{

void changeSection(MCSection *Section, uint32_t Subsection) override;

void emitLabel(MCSymbol *Symbol, SMLoc Loc) override;
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override {
return false;
}

void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Align ByteAlignment) override {}

void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
uint64_t Size = 0, Align ByteAlignment = Align(1),
SMLoc Loc = SMLoc()) override {}

/// @}
};
25 changes: 25 additions & 0 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "SystemZMCTargetDesc.h"
#include "SystemZHLASMAsmStreamer.h"
#include "SystemZInstPrinter.h"
#include "SystemZMCAsmInfo.h"
#include "SystemZTargetStreamer.h"
Expand All @@ -19,6 +20,7 @@
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/CommandLine.h"

using namespace llvm;

Expand All @@ -32,6 +34,12 @@ using namespace llvm;
#define GET_REGINFO_MC_DESC
#include "SystemZGenRegisterInfo.inc"

// Temporary option to assist with the migration to a new HLASMAsmStreamer on
// z/OS
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move 'on' to the next line and add '.' at the end.

static cl::opt<bool> GNUAsOnzOSCL("emit-gnuas-syntax-on-zos",
cl::desc("Emit GNU Assembly Syntax on z/OS."),
cl::init(true));

const unsigned SystemZMC::GR32Regs[16] = {
SystemZ::R0L, SystemZ::R1L, SystemZ::R2L, SystemZ::R3L,
SystemZ::R4L, SystemZ::R5L, SystemZ::R6L, SystemZ::R7L,
Expand Down Expand Up @@ -229,6 +237,20 @@ static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
return new SystemZTargetAsmStreamer(S, OS);
}

static MCStreamer *createAsmStreamer(MCContext &Ctx,
std::unique_ptr<formatted_raw_ostream> OS,
MCInstPrinter *IP,
std::unique_ptr<MCCodeEmitter> CE,
std::unique_ptr<MCAsmBackend> TAB) {

auto TT = Ctx.getTargetTriple();
if (TT.isOSzOS() && !GNUAsOnzOSCL)
return new SystemZHLASMAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
std::move(TAB));

return llvm::createAsmStreamer(Ctx, std::move(OS), IP, std::move(CE),
std::move(TAB));
}
static MCTargetStreamer *
createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
return new SystemZTargetELFStreamer(S);
Expand Down Expand Up @@ -269,6 +291,9 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZTargetMC() {
createSystemZMCInstPrinter);

// Register the asm streamer.
TargetRegistry::RegisterAsmStreamer(getTheSystemZTarget(), createAsmStreamer);

// Register the asm target streamer.
TargetRegistry::RegisterAsmTargetStreamer(getTheSystemZTarget(),
createAsmTargetStreamer);

Expand Down
9 changes: 9 additions & 0 deletions llvm/test/CodeGen/SystemZ/zos-hlasm-out.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; RUN: llc < %s -emit-gnuas-syntax-on-zos=0 --mtriple=s390x-ibm-zos | FileCheck --match-full-lines %s

; empty function
; CHECK: foo
; CHECK-NEXT: L#func_end0
define void @foo() {
entry:
ret void
}