[PATCH] D45119: [RISCV] Override EmitToStreamer in RISCVAsmPrinter to handle missed compression opportunities

Sameer AbuAsal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 17:23:44 PDT 2018


sabuasal updated this revision to Diff 141244.
sabuasal added a comment.

Shadow instead of override.

Thanks @efriedma !


https://reviews.llvm.org/D45119

Files:
  lib/Target/RISCV/RISCVAsmPrinter.cpp
  test/CodeGen/RISCV/compress-Pseudo.ll


Index: test/CodeGen/RISCV/compress-Pseudo.ll
===================================================================
--- /dev/null
+++ test/CodeGen/RISCV/compress-Pseudo.ll
@@ -0,0 +1,10 @@
+; RUN: llc -mtriple=riscv32 -mattr=+c  -riscv-no-aliases -o %t1 < %s
+; RUN: FileCheck %s < %t1
+
+define void @foo() {
+; CHECK-LABEL: foo:
+; CHECK:   c.jr
+
+end:
+  ret void
+}
Index: lib/Target/RISCV/RISCVAsmPrinter.cpp
===================================================================
--- lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -49,6 +49,7 @@
                              unsigned AsmVariant, const char *ExtraCode,
                              raw_ostream &OS) override;
 
+  void EmitToStreamer(MCStreamer &S, const MCInst &Inst);
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
                                    const MachineInstr *MI);
 
@@ -59,22 +60,27 @@
 };
 }
 
+#define GEN_COMPRESS_INSTR
+#include "RISCVGenCompressInstEmitter.inc"
+void RISCVAsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst) {
+  MCInst CInst;
+  bool Res = compressInst(CInst, Inst, *TM.getMCSubtargetInfo(),
+                          OutStreamer->getContext());
+  AsmPrinter::EmitToStreamer(*OutStreamer, Res ? CInst : Inst);
+}
+
 // Simple pseudo-instructions have their lowering (with expansion to real
 // instructions) auto-generated.
 #include "RISCVGenMCPseudoLowering.inc"
 
-#define GEN_COMPRESS_INSTR
-#include "RISCVGenCompressInstEmitter.inc"
 void RISCVAsmPrinter::EmitInstruction(const MachineInstr *MI) {
   // Do any auto-generated pseudo lowerings.
   if (emitPseudoExpansionLowering(*OutStreamer, MI))
     return;
 
-  MCInst TmpInst, CInst;
+  MCInst TmpInst;
   LowerRISCVMachineInstrToMCInst(MI, TmpInst, *this);
-  bool Res = compressInst(CInst, TmpInst, *TM.getMCSubtargetInfo(),
-                          OutStreamer->getContext());
-  EmitToStreamer(*OutStreamer, Res ? CInst : TmpInst);
+  EmitToStreamer(*OutStreamer, TmpInst);
 }
 
 bool RISCVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45119.141244.patch
Type: text/x-patch
Size: 2089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/6caa8e62/attachment.bin>


More information about the llvm-commits mailing list