[llvm] ea9dc0e - X86: Implement null target streamer
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 31 20:08:19 PDT 2022
Author: Matt Arsenault
Date: 2022-10-31T18:31:53-07:00
New Revision: ea9dc0ec3461160acb98a0e3dd668d7f3eef0604
URL: https://github.com/llvm/llvm-project/commit/ea9dc0ec3461160acb98a0e3dd668d7f3eef0604
DIFF: https://github.com/llvm/llvm-project/commit/ea9dc0ec3461160acb98a0e3dd668d7f3eef0604.diff
LOG: X86: Implement null target streamer
There should no need for null checks in the AsmPrinter
Added:
llvm/test/CodeGen/X86/null-mcstreamer.ll
Modified:
llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
llvm/lib/Target/X86/MCTargetDesc/X86TargetStreamer.h
llvm/lib/Target/X86/X86AsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
index 4c962de16530f..dcfbd305b732c 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
@@ -16,6 +16,7 @@
#include "X86BaseInfo.h"
#include "X86IntelInstPrinter.h"
#include "X86MCAsmInfo.h"
+#include "X86TargetStreamer.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/Triple.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
@@ -722,6 +723,9 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeX86TargetMC() {
// Register the asm target streamer.
TargetRegistry::RegisterAsmTargetStreamer(*T, createX86AsmTargetStreamer);
+ // Register the null streamer.
+ TargetRegistry::RegisterNullTargetStreamer(*T, createX86NullTargetStreamer);
+
TargetRegistry::RegisterCOFFStreamer(*T, createX86WinCOFFStreamer);
// Register the MCInstPrinter.
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86TargetStreamer.h b/llvm/lib/Target/X86/MCTargetDesc/X86TargetStreamer.h
index 3b1e9e7c34fb0..11bffa0bff106 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86TargetStreamer.h
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86TargetStreamer.h
@@ -19,16 +19,27 @@ class X86TargetStreamer : public MCTargetStreamer {
X86TargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
virtual bool emitFPOProc(const MCSymbol *ProcSym, unsigned ParamsSize,
- SMLoc L = {}) = 0;
- virtual bool emitFPOEndPrologue(SMLoc L = {}) = 0;
- virtual bool emitFPOEndProc(SMLoc L = {}) = 0;
- virtual bool emitFPOData(const MCSymbol *ProcSym, SMLoc L = {}) = 0;
- virtual bool emitFPOPushReg(unsigned Reg, SMLoc L = {}) = 0;
- virtual bool emitFPOStackAlloc(unsigned StackAlloc, SMLoc L = {}) = 0;
- virtual bool emitFPOStackAlign(unsigned Align, SMLoc L = {}) = 0;
- virtual bool emitFPOSetFrame(unsigned Reg, SMLoc L = {}) = 0;
+ SMLoc L = {}) {
+ return false;
+ }
+ virtual bool emitFPOEndPrologue(SMLoc L = {}) { return false; }
+ virtual bool emitFPOEndProc(SMLoc L = {}) { return false; };
+ virtual bool emitFPOData(const MCSymbol *ProcSym, SMLoc L = {}) {
+ return false;
+ }
+ virtual bool emitFPOPushReg(unsigned Reg, SMLoc L = {}) { return false; }
+ virtual bool emitFPOStackAlloc(unsigned StackAlloc, SMLoc L = {}) {
+ return false;
+ }
+ virtual bool emitFPOStackAlign(unsigned Align, SMLoc L = {}) { return false; }
+ virtual bool emitFPOSetFrame(unsigned Reg, SMLoc L = {}) { return false; }
};
+/// Implements X86-only null emission.
+inline MCTargetStreamer *createX86NullTargetStreamer(MCStreamer &S) {
+ return new X86TargetStreamer(S);
+}
+
} // end namespace llvm
#endif
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 1c8375dcd1714..88bc4b072ac8b 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -98,19 +98,19 @@ bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
void X86AsmPrinter::emitFunctionBodyStart() {
if (EmitFPOData) {
- if (auto *XTS =
- static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer()))
- XTS->emitFPOProc(
- CurrentFnSym,
- MF->getInfo<X86MachineFunctionInfo>()->getArgumentStackSize());
+ auto *XTS =
+ static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
+ XTS->emitFPOProc(
+ CurrentFnSym,
+ MF->getInfo<X86MachineFunctionInfo>()->getArgumentStackSize());
}
}
void X86AsmPrinter::emitFunctionBodyEnd() {
if (EmitFPOData) {
- if (auto *XTS =
- static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer()))
- XTS->emitFPOEndProc();
+ auto *XTS =
+ static_cast<X86TargetStreamer *>(OutStreamer->getTargetStreamer());
+ XTS->emitFPOEndProc();
}
}
diff --git a/llvm/test/CodeGen/X86/null-mcstreamer.ll b/llvm/test/CodeGen/X86/null-mcstreamer.ll
new file mode 100644
index 0000000000000..e464ac6c25dc5
--- /dev/null
+++ b/llvm/test/CodeGen/X86/null-mcstreamer.ll
@@ -0,0 +1,22 @@
+; RUN: llc -mtriple=i386-pc-windows-msvc -filetype=null %s
+
+define void @foo() !dbg !6 {
+entry:
+ ret void, !dbg !11
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 16.0.0 (git at github.com:llvm/llvm-project.git a8762195d56fb196d60d98045c75eb33af68df0c)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "/Users/matt/src/llvm-project/clang/test/Misc/<stdin>", directory: "/Users/matt/src/llvm-project/build_debug", checksumkind: CSK_MD5, checksum: "de25aa8ed7057b63c6695dfd0822438b")
+!2 = !{i32 1, !"NumRegisterParameters", i32 0}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 2}
+!6 = distinct !DISubprogram(name: "foo", scope: !7, file: !7, line: 5, type: !8, scopeLine: 5, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !10)
+!7 = !DIFile(filename: "clang/test/Misc/x86-emit-codegen-only.c", directory: "/Users/matt/src/llvm-project", checksumkind: CSK_MD5, checksum: "de25aa8ed7057b63c6695dfd0822438b")
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !{}
+!11 = !DILocation(line: 5, column: 13, scope: !6)
More information about the llvm-commits
mailing list