From 06640d93e010b7dc6dc8a70621c2e5028686be89 Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Fri, 25 Jul 2014 17:47:14 +0000 Subject: [PATCH] [FastISel][AArch64] Add support for frameaddress intrinsic. This commit implements the frameaddress intrinsic for the AArch64 architecture in FastISel. There were two test cases that pretty much tested the same, so I combined them to a single test case. Fixes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213959 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AArch64/AArch64FastISel.cpp | 30 ++++++++++++++++++++++++++++-- test/CodeGen/AArch64/arm64-frameaddr.ll | 15 --------------- test/CodeGen/AArch64/frameaddr.ll | 29 +++++++++++++++++++---------- 3 files changed, 47 insertions(+), 27 deletions(-) delete mode 100644 test/CodeGen/AArch64/arm64-frameaddr.ll diff --git a/lib/Target/AArch64/AArch64FastISel.cpp b/lib/Target/AArch64/AArch64FastISel.cpp index 8f4fac9a56b..13312433e2d 100644 --- a/lib/Target/AArch64/AArch64FastISel.cpp +++ b/lib/Target/AArch64/AArch64FastISel.cpp @@ -1438,8 +1438,34 @@ bool AArch64FastISel::TryEmitSmallMemCpy(Address Dest, Address Src, bool AArch64FastISel::FastLowerIntrinsicCall(const IntrinsicInst *II) { // FIXME: Handle more intrinsics. switch (II->getIntrinsicID()) { - default: - return false; + default: return false; + case Intrinsic::frameaddress: { + MachineFrameInfo *MFI = FuncInfo.MF->getFrameInfo(); + MFI->setFrameAddressIsTaken(true); + + const AArch64RegisterInfo *RegInfo = + static_cast(TM.getRegisterInfo()); + unsigned FramePtr = RegInfo->getFrameRegister(*(FuncInfo.MF)); + unsigned SrcReg = FramePtr; + + // Recursively load frame address + // ldr x0, [fp] + // ldr x0, [x0] + // ldr x0, [x0] + // ... + unsigned DestReg; + unsigned Depth = cast(II->getOperand(0))->getZExtValue(); + while (Depth--) { + DestReg = createResultReg(&AArch64::GPR64RegClass); + BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, + TII.get(AArch64::LDRXui), DestReg) + .addReg(SrcReg).addImm(0); + SrcReg = DestReg; + } + + UpdateValueMap(II, SrcReg); + return true; + } case Intrinsic::memcpy: case Intrinsic::memmove: { const auto *MTI = cast(II); diff --git a/test/CodeGen/AArch64/arm64-frameaddr.ll b/test/CodeGen/AArch64/arm64-frameaddr.ll deleted file mode 100644 index 469078c8814..00000000000 --- a/test/CodeGen/AArch64/arm64-frameaddr.ll +++ /dev/null @@ -1,15 +0,0 @@ -; RUN: llc < %s -march=arm64 | FileCheck %s - -define i8* @t() nounwind { -entry: -; CHECK-LABEL: t: -; CHECK: stp x29, x30, [sp, #-16]! -; CHECK: mov x29, sp -; CHECK: mov x0, x29 -; CHECK: ldp x29, x30, [sp], #16 -; CHECK: ret - %0 = call i8* @llvm.frameaddress(i32 0) - ret i8* %0 -} - -declare i8* @llvm.frameaddress(i32) nounwind readnone diff --git a/test/CodeGen/AArch64/frameaddr.ll b/test/CodeGen/AArch64/frameaddr.ll index 85d95e21c9b..ff9916c156b 100644 --- a/test/CodeGen/AArch64/frameaddr.ll +++ b/test/CodeGen/AArch64/frameaddr.ll @@ -1,20 +1,29 @@ -; RUN: llc -o - %s -mtriple=arm64-apple-ios7.0 | FileCheck %s +; RUN: llc -mtriple=arm64-apple-ios7.0 < %s | FileCheck %s +; RUN: llc -mtriple=arm64-apple-ios7.0 -fast-isel -fast-isel-abort < %s | FileCheck %s -define i8* @t() nounwind { +define i8* @test_frameaddress0() nounwind { entry: -; CHECK-LABEL: t: +; CHECK-LABEL: test_frameaddress0: +; CHECK: stp x29, x30, [sp, #-16]! +; CHECK: mov x29, sp ; CHECK: mov x0, x29 - %0 = call i8* @llvm.frameaddress(i32 0) - ret i8* %0 +; CHECK: ldp x29, x30, [sp], #16 +; CHECK: ret + %0 = call i8* @llvm.frameaddress(i32 0) + ret i8* %0 } -define i8* @t2() nounwind { +define i8* @test_frameaddress2() nounwind { entry: -; CHECK-LABEL: t2: +; CHECK-LABEL: test_frameaddress2: +; CHECK: stp x29, x30, [sp, #-16]! +; CHECK: mov x29, sp ; CHECK: ldr x[[reg:[0-9]+]], [x29] -; CHECK: ldr {{x[0-9]+}}, [x[[reg]]] - %0 = call i8* @llvm.frameaddress(i32 2) - ret i8* %0 +; CHECK: ldr x0, [x[[reg]]] +; CHECK: ldp x29, x30, [sp], #16 +; CHECK: ret + %0 = call i8* @llvm.frameaddress(i32 2) + ret i8* %0 } declare i8* @llvm.frameaddress(i32) nounwind readnone -- 2.11.0