llvm-6502/include/llvm
Evan Cheng d89b0f200c For functions with ARM target specific calling convention, when simplify-libcall
optimize a call to a llvm intrinsic to something that invovles a call to a C
library call, make sure it sets the right calling convention on the call.

e.g.
extern double pow(double, double);
double t(double x) {
  return pow(10, x);
}

Compiles to something like this for AAPCS-VFP:
define arm_aapcs_vfpcc double @t(double %x) #0 {
entry:
  %0 = call double @llvm.pow.f64(double 1.000000e+01, double %x)
  ret double %0
}

declare double @llvm.pow.f64(double, double) #1

Simplify libcall (part of instcombine) will turn the above into:
define arm_aapcs_vfpcc double @t(double %x) #0 {
entry:
  %__exp10 = call double @__exp10(double %x) #1
  ret double %__exp10
}

declare double @__exp10(double)

The pre-instcombine code works because calls to LLVM builtins are special.
Instruction selection will chose the right calling convention for the call.
However, the code after instcombine is wrong. The call to __exp10 will use
the C calling convention.

I can think of 3 options to fix this.

1. Make "C" calling convention just work since the target should know what CC
   is being used.

   This doesn't work because each function can use different CC with the "pcs"
   attribute.

2. Have Clang add the right CC keyword on the calls to LLVM builtin.

   This will work but it doesn't match the LLVM IR specification which states
   these are "Standard C Library Intrinsics".

3. Fix simplify libcall so the resulting calls to the C routines will have the
   proper CC keyword. e.g.
   %__exp10 = call arm_aapcs_vfpcc double @__exp10(double %x) #1

   This works and is the solution I implemented here.

Both solutions #2 and #3 would work. After carefully considering the pros and
cons, I decided to implement #3 for the following reasons.

1. It doesn't change the "spec" of the intrinsics.
2. It's a self-contained fix.

There are a couple of potential downsides.
1. There could be other places in the optimizer that is broken in the same way
   that's not addressed by this.
2. There could be other calling conventions that need to be propagated by
   simplify-libcall that's not handled.

But for now, this is the fix that I'm most comfortable with.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203488 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-10 20:49:45 +00:00
..
ADT Removing llvm::distance and llvm::copy for iterator_range based on post-commit review feedback. Adding an explicit range-based constructor to SmallVector, which supersedes the llvm::copy functionality. 2014-03-10 13:43:46 +00:00
Analysis [LCG] Make this call graph a fully regular type by giving it assignment 2014-03-10 08:08:59 +00:00
AsmParser Move the LLVM IR asm writer header files into the IR directory, as they 2014-01-07 12:34:26 +00:00
Bitcode Replace OwningPtr<T> with std::unique_ptr<T>. 2014-03-06 05:51:42 +00:00
CodeGen MachineModuleInfo: Turn nested std::pairs into a proper struct. 2014-03-09 15:44:39 +00:00
Config Add patch level to llvm version in CMake and Autoconf 2014-03-03 15:22:00 +00:00
DebugInfo Revert "Clean up SmallString a bit" 2014-03-09 06:22:58 +00:00
ExecutionEngine [C++11] Add 'override' keyword to virtual methods that override their base class. 2014-03-08 07:51:20 +00:00
IR For functions with ARM target specific calling convention, when simplify-libcall 2014-03-10 20:49:45 +00:00
IRReader Split out the IRReader header and the utility functions it provides into 2013-03-26 02:25:37 +00:00
LineEditor Replace OwningPtr<T> with std::unique_ptr<T>. 2014-03-06 05:51:42 +00:00
Linker [Layering] Sink Linker.h into a Linker subdirectory to make it 2014-03-06 03:42:23 +00:00
LTO Replace OwningPtr<T> with std::unique_ptr<T>. 2014-03-06 05:51:42 +00:00
MC [C++11] Remove 'virtual' keyword from methods marked with 'override' keyword. 2014-03-10 05:29:18 +00:00
Object [C++11] Replace LLVM-style type traits with C++11 standard ones. 2014-03-07 14:42:25 +00:00
Option [C++11] Add 'override' keyword to virtual methods that override their base class. 2014-03-05 07:52:44 +00:00
Support [C++11] Remove 'virtual' keyword from methods marked with 'override' keyword. 2014-03-10 03:53:12 +00:00
TableGen [C++11] Add 'override' keywords to tablegen code. 2014-03-05 05:17:42 +00:00
Target Replace PROLOG_LABEL with a new CFI_INSTRUCTION. 2014-03-07 06:08:31 +00:00
Transforms [C++11] Add 'override' keyword to virtual methods that override their base class. 2014-03-05 09:10:37 +00:00
CMakeLists.txt The llvm_headers_do_not_build project needs to be excluded from the default build, otherwise it gets built (at least in Visual Studio 2013). 2014-01-28 16:07:10 +00:00
InitializePasses.h Pass to emit DWARF path discriminators. 2014-03-03 20:06:11 +00:00
LinkAllIR.h [cleanup] Move the Dominators.h and Verifier.h headers into the IR 2014-01-13 09:26:24 +00:00
LinkAllPasses.h Revert "Revert "Add Constant Hoisting Pass" (r200034)" 2014-01-25 02:02:55 +00:00
Pass.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
PassAnalysisSupport.h Fix include guards so they exactly match file names. 2013-01-10 00:45:19 +00:00
PassManager.h Move the old pass manager infrastructure into a legacy namespace and 2013-11-09 12:26:54 +00:00
PassRegistry.h Re-sort all of the includes with ./utils/sort_includes.py so that 2014-01-07 11:48:04 +00:00
PassSupport.h Revert "[C++11] Replace LLVM atomics with std::atomic." 2014-03-03 18:02:34 +00:00