diff options
| author | Richard Osborne <richard@xmos.com> | 2012-11-16 21:12:38 +0000 |
|---|---|---|
| committer | Richard Osborne <richard@xmos.com> | 2012-11-16 21:12:38 +0000 |
| commit | 9a43772783776a0ddbf8d58ba69f9922e324410d (patch) | |
| tree | d483776e12ec4e21ae2673f305aacff5761f6a4f | |
| parent | 2c5ac70dd9ed46b54c3a513e971808686d43b04b (diff) | |
| download | bcm5719-llvm-9a43772783776a0ddbf8d58ba69f9922e324410d.tar.gz bcm5719-llvm-9a43772783776a0ddbf8d58ba69f9922e324410d.zip | |
Fix handling of aliases to functions.
An alias to a function should use pc relative addressing.
llvm-svn: 168199
| -rw-r--r-- | llvm/lib/Target/XCore/XCoreISelLowering.cpp | 22 | ||||
| -rw-r--r-- | llvm/test/CodeGen/XCore/aliases.ll | 32 |
2 files changed, 41 insertions, 13 deletions
diff --git a/llvm/lib/Target/XCore/XCoreISelLowering.cpp b/llvm/lib/Target/XCore/XCoreISelLowering.cpp index 9e7816e21f8..f1098f9dc35 100644 --- a/llvm/lib/Target/XCore/XCoreISelLowering.cpp +++ b/llvm/lib/Target/XCore/XCoreISelLowering.cpp @@ -225,20 +225,16 @@ getGlobalAddressWrapper(SDValue GA, const GlobalValue *GV, { // FIXME there is no actual debug info here DebugLoc dl = GA.getDebugLoc(); - if (isa<Function>(GV)) { - return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA); + const GlobalValue *UnderlyingGV = GV; + // If GV is an alias then use the aliasee to determine the wrapper type + if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) + UnderlyingGV = GA->resolveAliasedGlobal(); + if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(UnderlyingGV)) { + if (GVar->isConstant()) + return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA); + return DAG.getNode(XCoreISD::DPRelativeWrapper, dl, MVT::i32, GA); } - const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); - if (!GVar) { - // If GV is an alias then use the aliasee to determine constness - if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) - GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal()); - } - bool isConst = GVar && GVar->isConstant(); - if (isConst) { - return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA); - } - return DAG.getNode(XCoreISD::DPRelativeWrapper, dl, MVT::i32, GA); + return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA); } SDValue XCoreTargetLowering:: diff --git a/llvm/test/CodeGen/XCore/aliases.ll b/llvm/test/CodeGen/XCore/aliases.ll new file mode 100644 index 00000000000..d83b246a552 --- /dev/null +++ b/llvm/test/CodeGen/XCore/aliases.ll @@ -0,0 +1,32 @@ +; RUN: llc < %s -march=xcore | FileCheck %s +declare void @a_val() nounwind +@b_val = external constant i32, section ".cp.rodata" +@c_val = external global i32 + +@a = alias void ()* @a_val +@b = alias i32* @b_val +@c = alias i32* @c_val + +; CHECK: a_addr: +; CHECK: ldap r11, a +; CHECK: retsp +define void ()* @a_addr() nounwind { +entry: + ret void ()* @a +} + +; CHECK: b_addr: +; CHECK: ldaw r11, cp[b] +; CHECK: retsp +define i32 *@b_addr() nounwind { +entry: + ret i32* @b +} + +; CHECK: c_addr: +; CHECK: ldaw r0, dp[c] +; CHECK: retsp +define i32 *@c_addr() nounwind { +entry: + ret i32* @c +} |

