[llvm] 6be1578 - [SystemZ] Recognize mrecord-mcount in backend

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 09:11:30 PST 2019


Author: Jonas Paulsson
Date: 2019-12-19T09:06:18-08:00
New Revision: 6be15788951b44b2516f503bb7feb555364c6e5a

URL: https://github.com/llvm/llvm-project/commit/6be15788951b44b2516f503bb7feb555364c6e5a
DIFF: https://github.com/llvm/llvm-project/commit/6be15788951b44b2516f503bb7feb555364c6e5a.diff

LOG: [SystemZ]  Recognize mrecord-mcount in backend

Emit the __mcount_loc section for all fentry calls.

Review: Ulrich Weigand
https://reviews.llvm.org/D71629

Added: 
    llvm/test/CodeGen/SystemZ/mrecord-mcount-01.ll
    llvm/test/CodeGen/SystemZ/mrecord-mcount-02.ll

Modified: 
    llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
    llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 34f7bc99a0d7..1a7f17790757 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -16,11 +16,13 @@
 #include "SystemZConstantPoolValue.h"
 #include "SystemZMCInstLower.h"
 #include "TargetInfo/SystemZTargetInfo.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
 #include "llvm/IR/Mangler.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInstBuilder.h"
+#include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/Support/TargetRegistry.h"
 
@@ -553,6 +555,16 @@ static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer,
 void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
                                          SystemZMCInstLower &Lower) {
   MCContext &Ctx = MF->getContext();
+  if (MF->getFunction().hasFnAttribute("mrecord-mcount")) {
+    MCSymbol *DotSym = OutContext.createTempSymbol();
+    OutStreamer->PushSection();
+    OutStreamer->SwitchSection(
+        Ctx.getELFSection("__mcount_loc", ELF::SHT_PROGBITS, ELF::SHF_ALLOC));
+    OutStreamer->EmitSymbolValue(DotSym, 8);
+    OutStreamer->PopSection();
+    OutStreamer->EmitLabel(DotSym);
+  }
+
   if (MF->getFunction().hasFnAttribute("mnop-mcount")) {
     EmitNop(Ctx, *OutStreamer, 6, getSubtargetInfo());
     return;

diff  --git a/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp b/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
index 0bcbce68a5fe..74d66516321c 100644
--- a/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
@@ -347,9 +347,12 @@ class SystemZDAGToDAGISel : public SelectionDAGISel {
 
   bool runOnMachineFunction(MachineFunction &MF) override {
     const Function &F = MF.getFunction();
-    if (F.hasFnAttribute("mnop-mcount") &&
-        F.getFnAttribute("fentry-call").getValueAsString() != "true")
-      report_fatal_error("mnop-mcount only supported with fentry-call");
+    if (F.getFnAttribute("fentry-call").getValueAsString() != "true") {
+      if (F.hasFnAttribute("mnop-mcount"))
+        report_fatal_error("mnop-mcount only supported with fentry-call");
+      if (F.hasFnAttribute("mrecord-mcount"))
+        report_fatal_error("mrecord-mcount only supported with fentry-call");
+    }
 
     Subtarget = &MF.getSubtarget<SystemZSubtarget>();
     return SelectionDAGISel::runOnMachineFunction(MF);

diff  --git a/llvm/test/CodeGen/SystemZ/mrecord-mcount-01.ll b/llvm/test/CodeGen/SystemZ/mrecord-mcount-01.ll
new file mode 100644
index 000000000000..f4f17fd31def
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/mrecord-mcount-01.ll
@@ -0,0 +1,32 @@
+; RUN: llc %s -mtriple=s390x-linux-gnu -mcpu=z10 -o - -verify-machineinstrs \
+; RUN:   | FileCheck %s
+
+define void @test1() #0 {
+entry:
+  ret void
+
+; CHECK-LABEL: test1:
+; CHECK: .section __mcount_loc,"a", at progbits
+; CHECK: .quad .Ltmp0
+; CHECK: .text
+; CHECK: .Ltmp0:
+; CHECK: brasl %r0, __fentry__ at PLT
+; CHECK: br %r14
+}
+
+define void @test2() #1 {
+entry:
+  ret void
+
+; CHECK-LABEL: test2:
+; CHECK: .section __mcount_loc,"a", at progbits
+; CHECK: .quad .Ltmp1
+; CHECK: .text
+; CHECK: .Ltmp1:
+; CHECK: brcl 0, .Ltmp2
+; CHECK: .Ltmp2:
+; CHECK: br %r14
+}
+
+attributes #0 = { "fentry-call"="true" "mrecord-mcount" }
+attributes #1 = { "fentry-call"="true" "mnop-mcount" "mrecord-mcount" }

diff  --git a/llvm/test/CodeGen/SystemZ/mrecord-mcount-02.ll b/llvm/test/CodeGen/SystemZ/mrecord-mcount-02.ll
new file mode 100644
index 000000000000..9ce7cdd418e3
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/mrecord-mcount-02.ll
@@ -0,0 +1,10 @@
+; RUN: not llc %s -mtriple=s390x-linux-gnu -o - 2>&1 | FileCheck %s
+;
+; CHECK: LLVM ERROR: mrecord-mcount only supported with fentry-call
+
+define void @test1() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { "instrument-function-entry-inlined"="mcount" "mrecord-mcount" }


        


More information about the llvm-commits mailing list