This is an archive of the discontinued LLVM Phabricator instance.

[ARM, AArch64] Adds builtins to get current SP and PC
Needs RevisionPublic

Authored by weimingz on Jul 11 2016, 6:50 PM.

Details

Summary

This patch implements builtin_arm_current_sp and builtin_arm_current_pc.
__builtin_arm_current_sp is also implemented for AArch64

Diff Detail

Event Timeline

weimingz updated this revision to Diff 63623.Jul 11 2016, 6:50 PM
weimingz retitled this revision from to [ARM, AArch64] Adds builtins to get current SP and PC.
weimingz updated this object.
weimingz added a subscriber: cfe-commits.
rengolin requested changes to this revision.Jul 12 2016, 1:09 AM
rengolin added a reviewer: rengolin.

Hi Weiming,

We've discussed about creating builtins when I added support for named registers and the consensus was that, since there is already a way to access them, there is no point in adding a new builtin.

cheers,
--renato

This revision now requires changes to proceed.Jul 12 2016, 1:09 AM
t.p.northover edited edge metadata.Jul 12 2016, 8:00 AM

I agree with Renato too.

It seems like, as a compiler, we can provide virtually no guarantees about the value of __builtin_arm_current_pc: it's not necessarily in the PC-range of the dynamically innermost frame (inlining); it's not necessarily even in the callstack at all (you actually get PC+8 or PC+4).

About the only feasible use-case is a some kind of panic/abort implementation best-effort. And at that point you'll want r0-r14 as well.

Tim.

mgrang edited edge metadata.Jul 12 2016, 11:41 AM

Hi Tim/Renato,

On a similar note, I have a patch which adds the breakpoint intrinsic (for ARM and Thumb):
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/CJAHBCFH.html

Could you please let me know if this is something which the community would like to support. I can then push my patch.

Here are two other intrinsics which I wanted to implement:
enable_irq: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472m/chr1359124996163.html
disable_irq: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0472m/chr1359125001077.html

The use case for these intrinsics is a customer who makes calls to __builtin_arm_breakpoint (and others) in their code base. Currently they compile with ARMCC, but LLVM does not have these intrinsics. So porting the code to build with LLVM becomes a hassle.
To facilitate customers to switch to LLVM we wanted to implement these intrinsics.

Thanks,
Mandeep

Hi Tim/Renato,

On a similar note, I have a patch which adds the breakpoint intrinsic (for ARM and Thumb):
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/CJAHBCFH.html

Hi Mandeep,

I don't think we should be implementing old ARMCC intrinsics either. GCC doesn't, especially since most of them are easy to do with one line inline assembly snippets.

Those intrinsics are not covered by the ACLE (mentioned, but not defined), which reinforces the notion that we shouldn't be doing anyway.

cheers,
--renato

Thanks Renato for your comments. I guess I will not upstream my patches then.

--Mandeep