llvm.org GIT mirror llvm / 97f8f69
ARM: permit tail calls to weak externals on COFF Weak externals are resolved statically, so we can actually generate the tail call on PE/COFF targets without breaking the requirements. It is questionable whether we want to propagate the current behaviour for MachO as the requirements are part of the ARM ELF specifications, and it seems that prior to the SVN r215890, we would have tail'ed the call. For now, be conservative and only permit it on PE/COFF where the call will always be fully resolved. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225119 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 5 years ago
3 changed file(s) with 25 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
23572357 // cannot rely on the linker replacing the tail call with a return.
23582358 if (GlobalAddressSDNode *G = dyn_cast(Callee)) {
23592359 const GlobalValue *GV = G->getGlobal();
2360 if (GV->hasExternalWeakLinkage())
2360 const Triple TT(getTargetMachine().getTargetTriple());
2361 if (GV->hasExternalWeakLinkage() &&
2362 (!TT.isOSWindows() || TT.isOSBinFormatELF() || TT.isOSBinFormatMachO()))
23612363 return false;
23622364 }
23632365
20252025 // cannot rely on the linker replacing the tail call with a return.
20262026 if (GlobalAddressSDNode *G = dyn_cast(Callee)) {
20272027 const GlobalValue *GV = G->getGlobal();
2028 if (GV->hasExternalWeakLinkage())
2028 const Triple TT(getTargetMachine().getTargetTriple());
2029 if (GV->hasExternalWeakLinkage() &&
2030 (!TT.isOSWindows() || TT.isOSBinFormatELF() || TT.isOSBinFormatMachO()))
20292031 return false;
20302032 }
20312033
0 ; RUN: llc -mtriple thumbv7-windows-coff -filetype asm -o - %s | FileCheck %s -check-prefix CHECK-COFF
1 ; RUN: llc -mtriple thumbv7-elf -filetype asm -o - %s | FileCheck %s -check-prefix CHECK-ELF
2 ; RUN: llc -mtriple thumbv7-macho -filetype asm -o - %s | FileCheck %s -check-prefix CHECK-MACHO
3
4 declare i8* @f()
5 declare extern_weak i8* @g(i8*)
6
7 ; weak symbol resolution occurs statically in PE/COFF, ensure that we permit
8 ; tail calls on weak externals when targeting a COFF environment.
9 define void @test() {
10 %call = tail call i8* @f()
11 %call1 = tail call i8* @g(i8* %call)
12 ret void
13 }
14
15 ; CHECK-COFF: b g
16 ; CHECK-ELF: bl g
17 ; CHECK-MACHO: blx _g
18