From e89d1ea35f7bacb4291129f95d0a42280ddac1ee Mon Sep 17 00:00:00 2001 From: Jonas Paulsson Date: Tue, 3 Sep 2019 11:21:12 +0000 Subject: [PATCH] [SystemZ] Add support for fentry. SystemZAsmPrinter now properly emits function calls to __fentry__. Review: Ulrich Weigand llvm-svn: 370743 --- lib/Target/SystemZ/SystemZAsmPrinter.cpp | 14 ++++++++++++ lib/Target/SystemZ/SystemZAsmPrinter.h | 1 + test/CodeGen/SystemZ/fentry-insertion.ll | 29 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/CodeGen/SystemZ/fentry-insertion.ll diff --git a/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/lib/Target/SystemZ/SystemZAsmPrinter.cpp index ef378e4ade7..f03ed2014e4 100644 --- a/lib/Target/SystemZ/SystemZAsmPrinter.cpp +++ b/lib/Target/SystemZ/SystemZAsmPrinter.cpp @@ -501,6 +501,10 @@ void SystemZAsmPrinter::EmitInstruction(const MachineInstr *MI) { } break; + case TargetOpcode::FENTRY_CALL: + LowerFENTRY_CALL(*MI, Lower); + return; + case TargetOpcode::STACKMAP: LowerSTACKMAP(*MI); return; @@ -546,6 +550,16 @@ static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer, } } +void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI, + SystemZMCInstLower &Lower) { + MCContext &Ctx = MF->getContext(); + MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__"); + const MCSymbolRefExpr *Op = + MCSymbolRefExpr::create(fentry, MCSymbolRefExpr::VK_PLT, Ctx); + OutStreamer->EmitInstruction(MCInstBuilder(SystemZ::BRASL) + .addReg(SystemZ::R0D).addExpr(Op), getSubtargetInfo()); +} + void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) { const SystemZInstrInfo *TII = static_cast(MF->getSubtarget().getInstrInfo()); diff --git a/lib/Target/SystemZ/SystemZAsmPrinter.h b/lib/Target/SystemZ/SystemZAsmPrinter.h index aa5d3ca78e6..d01a17c2ebe 100644 --- a/lib/Target/SystemZ/SystemZAsmPrinter.h +++ b/lib/Target/SystemZ/SystemZAsmPrinter.h @@ -46,6 +46,7 @@ public: } private: + void LowerFENTRY_CALL(const MachineInstr &MI, SystemZMCInstLower &MCIL); void LowerSTACKMAP(const MachineInstr &MI); void LowerPATCHPOINT(const MachineInstr &MI, SystemZMCInstLower &Lower); }; diff --git a/test/CodeGen/SystemZ/fentry-insertion.ll b/test/CodeGen/SystemZ/fentry-insertion.ll new file mode 100644 index 00000000000..63632d58246 --- /dev/null +++ b/test/CodeGen/SystemZ/fentry-insertion.ll @@ -0,0 +1,29 @@ +; 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: mcount +; CHECK: br %r14 +} + +define void @test2() #1 { +entry: + br label %bb1 +bb1: + call void @address_taken(i64 ptrtoint (i8* blockaddress(@test2, %bb1) to i64), i32 512) + ret void + +; CHECK-LABEL: @test2 +; CHECK: brasl %r0, __fentry__ +; CHECK-NOT: mcount +; CHECK: br %r14 +} + +declare void @address_taken(i64, i32) local_unnamed_addr +attributes #0 = { "fentry-call"="true" } +attributes #1 = { inlinehint minsize noredzone nounwind optsize sspstrong "fentry-call"="true" }