[llvm] r364126 - AArch64: Add support for reading pc using llvm.read_register.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 20:03:25 PDT 2019
Author: pcc
Date: Fri Jun 21 20:03:25 2019
New Revision: 364126
URL: http://llvm.org/viewvc/llvm-project?rev=364126&view=rev
Log:
AArch64: Add support for reading pc using llvm.read_register.
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
Added:
llvm/trunk/test/CodeGen/AArch64/read-pc.ll
Modified:
llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp?rev=364126&r1=364125&r2=364126&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp Fri Jun 21 20:03:25 2019
@@ -2678,6 +2678,14 @@ bool AArch64DAGToDAGISel::tryReadRegiste
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;
}
Added: llvm/trunk/test/CodeGen/AArch64/read-pc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/read-pc.ll?rev=364126&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/read-pc.ll (added)
+++ llvm/trunk/test/CodeGen/AArch64/read-pc.ll Fri Jun 21 20:03:25 2019
@@ -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"}
More information about the llvm-commits
mailing list