-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[MC] Introduce ability to add target specific AsmStreamer #107415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-mc Author: None (tltao) ChangesCurrently the AsmStreamer class This is the first patch to add this ability by utilizing the TargetRegistry functions. Full diff: https://github.com/llvm/llvm-project/pull/107415.diff 2 Files Affected:
diff --git a/llvm/include/llvm/MC/TargetRegistry.h b/llvm/include/llvm/MC/TargetRegistry.h
index 42d510c17bce39..1850139ba81491 100644
--- a/llvm/include/llvm/MC/TargetRegistry.h
+++ b/llvm/include/llvm/MC/TargetRegistry.h
@@ -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,
@@ -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;
@@ -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;
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 3be6f1d4634990..0d343a2c4e4d5f 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -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;
}
|
abhina-sree
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, assuming testcases that traverse this code path will be added in the future PRs
Yeah I didn't include any test case because the behaviour in this PR is identical to the current behaviour, and I don't see a way to test anything else with the existing changes. |
|
Also added use case in #108433 |
|
Closing this in favour of #130535. |
) A more fleshed out version of a previous PR #107415. The goal is to provide platforms an alternative to the current MCAsmStreamer which only supports the GNU Asm syntax. RFC: https://discourse.llvm.org/t/rfc-llvm-add-support-for-target-specific-asm-streamer/85095 --------- Co-authored-by: Tony Tao <[email protected]>
… z/OS (#130535) A more fleshed out version of a previous PR llvm/llvm-project#107415. The goal is to provide platforms an alternative to the current MCAsmStreamer which only supports the GNU Asm syntax. RFC: https://discourse.llvm.org/t/rfc-llvm-add-support-for-target-specific-asm-streamer/85095 --------- Co-authored-by: Tony Tao <[email protected]>
Currently the AsmStreamer class
MCAsmStreamer.cpponly outputs GNU assembly syntax. However, we wish to add additional AsmStreamer classes for specific targets that can output alternative assembly syntaxes (the immediate use case is HLASM syntax for z/OS).This is the first patch to add this ability by utilizing the TargetRegistry functions.