]> granicus.if.org Git - llvm/commitdiff
[SystemZ] Recognize mnop-mcount in backend
authorJonas Paulsson <paulsson@linux.vnet.ibm.com>
Thu, 26 Sep 2019 08:38:07 +0000 (08:38 +0000)
committerJonas Paulsson <paulsson@linux.vnet.ibm.com>
Thu, 26 Sep 2019 08:38:07 +0000 (08:38 +0000)
With -pg -mfentry -mnop-mcount, a nop is emitted instead of the call to
fentry.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372950 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/SystemZ/SystemZAsmPrinter.cpp
lib/Target/SystemZ/SystemZISelDAGToDAG.cpp
test/CodeGen/SystemZ/mnop-mcount-01.ll [new file with mode: 0644]
test/CodeGen/SystemZ/mnop-mcount-02.ll [new file with mode: 0644]

index f03ed2014e4a956643af188e22554fe8fc436e1d..10023e9e169c5a35e334b17dea883a00dce39534 100644 (file)
@@ -553,6 +553,12 @@ static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer,
 void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
                                          SystemZMCInstLower &Lower) {
   MCContext &Ctx = MF->getContext();
+  if (MF->getFunction().getFnAttribute("mnop-mcount")
+                       .getValueAsString() == "true") {
+    EmitNop(Ctx, *OutStreamer, 6, getSubtargetInfo());
+    return;
+  }
+
   MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__");
   const MCSymbolRefExpr *Op =
       MCSymbolRefExpr::create(fentry, MCSymbolRefExpr::VK_PLT, Ctx);
index e73d6e82e6e1f11d4b418c27533bd206c395a189..751034c2d41a1aa32edc3533532e84d813a32902 100644 (file)
@@ -346,6 +346,11 @@ public:
       : SelectionDAGISel(TM, OptLevel) {}
 
   bool runOnMachineFunction(MachineFunction &MF) override {
+    const Function &F = MF.getFunction();
+    if (F.getFnAttribute("mnop-mcount").getValueAsString() == "true" &&
+        F.getFnAttribute("fentry-call").getValueAsString() != "true")
+      report_fatal_error("mnop-mcount only supported with fentry-call");
+
     Subtarget = &MF.getSubtarget<SystemZSubtarget>();
     return SelectionDAGISel::runOnMachineFunction(MF);
   }
diff --git a/test/CodeGen/SystemZ/mnop-mcount-01.ll b/test/CodeGen/SystemZ/mnop-mcount-01.ll
new file mode 100644 (file)
index 0000000..38f1db5
--- /dev/null
@@ -0,0 +1,26 @@
+; 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: brasl %r0, __fentry__
+; CHECK-NOT: brcl 0, .Ltmp0
+; CHECK: br %r14
+}
+
+define void @test2() #1 {
+entry:
+  ret void
+
+; CHECK-LABEL: @test2
+; CHECK-NOT: brasl %r0, __fentry__
+; CHECK: brcl 0, .Ltmp0
+; CHECK: br %r14
+}
+
+attributes #0 = { "fentry-call"="true" }
+attributes #1 = { "fentry-call"="true" "mnop-mcount"="true" }
+
diff --git a/test/CodeGen/SystemZ/mnop-mcount-02.ll b/test/CodeGen/SystemZ/mnop-mcount-02.ll
new file mode 100644 (file)
index 0000000..19b1724
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: not llc %s -mtriple=s390x-linux-gnu -o - 2>&1 | FileCheck %s
+;
+; CHECK: LLVM ERROR: mnop-mcount only supported with fentry-call
+
+define void @test1() #0 {
+entry:
+  ret void
+}
+
+attributes #0 = { "instrument-function-entry-inlined"="mcount" "mnop-mcount"="true" }
+