Skip to content

Commit

Permalink
AArch64: Add support for reading pc using llvm.read_register.
Browse files Browse the repository at this point in the history
This is useful for allowing code to efficiently take an address
that can be later mapped onto debug info. Currently the hwasan
pass achieves this by taking the address of the current function:
http://llvm-cs.pcc.me.uk/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp#921

but this costs two instructions (plus a GOT entry in PIC code) per function
with stack variables. This will allow the cost to be reduced to a single
instruction.

Differential Revision: https://reviews.llvm.org/D63471

llvm-svn: 364126
  • Loading branch information
pcc committed Jun 22, 2019
1 parent 01d649c commit 8cd780b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,14 @@ bool AArch64DAGToDAGISel::tryReadRegister(SDNode *N) {
return true;
}

if (RegString->getString() == "pc") {
ReplaceNode(N, CurDAG->getMachineNode(
AArch64::ADR, DL, N->getSimpleValueType(0), MVT::Other,
CurDAG->getTargetConstant(0, DL, MVT::i32),
N->getOperand(0)));
return true;
}

return false;
}

Expand Down
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/AArch64/read-pc.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; RUN: llc < %s -mtriple=arm64-linux-gnu | FileCheck %s

define i64 @read_pc() {
; CHECK: adr x0, #0
%pc = call i64 @llvm.read_register.i64(metadata !0)
ret i64 %pc
}

declare i64 @llvm.read_register.i64(metadata) nounwind

!0 = !{!"pc"}

0 comments on commit 8cd780b

Please sign in to comment.