llvm-6502/include/llvm/IR
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
..
Argument.h Add an inalloca flag to allocas 2014-01-17 23:58:17 +00:00
AssemblyAnnotationWriter.h Move the LLVM IR asm writer header files into the IR directory, as they 2014-01-07 12:34:26 +00:00
Attributes.h [C++11] Expand and eliminate the LLVM_ENUM_INT_TYPE() macro 2014-03-02 03:20:38 +00:00
AutoUpgrade.h [Layering] Move AutoUpgrade.h into the IR library where its 2014-03-05 10:34:14 +00:00
BasicBlock.h Use DataLayout from the module when easily available. 2014-02-25 23:25:17 +00:00
CallingConv.h For functions with ARM target specific calling convention, when simplify-libcall 2014-03-10 20:49:45 +00:00
CallSite.h [C++11] Add range based accessors for the Use-Def chain of a Value. 2014-03-09 03:16:01 +00:00
CFG.h [C++11] Add range based accessors for the Use-Def chain of a Value. 2014-03-09 03:16:01 +00:00
CMakeLists.txt [CMake] intrinsics_gen: Use add_public_tablegen_target(). 2014-02-20 13:42:16 +00:00
Constant.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
ConstantFolder.h [Modules] Move the ConstantFolder into the IR library where it can 2014-03-04 12:02:47 +00:00
ConstantRange.h [Modules] Move the ConstantRange class into the IR library. This is 2014-03-04 12:24:34 +00:00
Constants.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
DataLayout.h [C++11] Modernize the IR library a bit. 2014-03-10 15:03:06 +00:00
DebugInfo.h [Layering] Move DebugInfo.h into the IR library where its implementation 2014-03-06 00:46:21 +00:00
DebugLoc.h [Layering] Move DebugLoc.h into the IR library. The implementation 2014-03-05 10:30:38 +00:00
DerivedTypes.h Fix the segfault reported in PR 11990. 2013-12-07 00:13:34 +00:00
DiagnosticInfo.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
DiagnosticPrinter.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
DIBuilder.h [Layering] Move DebugInfo.h into the IR library where its implementation 2014-03-06 00:46:21 +00:00
Dominators.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
Function.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
GetElementPtrTypeIterator.h [Modules] Move GetElementPtrTypeIterator into the IR library. As its 2014-03-04 10:40:04 +00:00
GlobalAlias.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
GlobalValue.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
GlobalVariable.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
GVMaterializer.h [Layering] Move GVMaterializer.h into the IR library where its 2014-03-06 03:50:29 +00:00
InlineAsm.h [C++11] Expand and eliminate the LLVM_ENUM_INT_TYPE() macro 2014-03-02 03:20:38 +00:00
InstIterator.h [Modules] Move InstIterator out of the Support library, where it had no 2014-03-04 10:30:26 +00:00
InstrTypes.h [C++11] Remove 'virtual' keyword from methods marked with 'override' keyword. 2014-03-10 05:29:18 +00:00
Instruction.def Add addrspacecast instruction. 2013-11-15 01:34:59 +00:00
Instruction.h [C++11] Add range based accessors for the Use-Def chain of a Value. 2014-03-09 03:16:01 +00:00
Instructions.h [C++11] Add range based accessors for the Use-Def chain of a Value. 2014-03-09 03:16:01 +00:00
InstVisitor.h [Layering] Move InstVisitor.h into the IR library as it is pretty 2014-03-06 03:23:41 +00:00
IntrinsicInst.h Add some convenience accessors for the underlying Use of an operand. 2014-02-25 03:34:17 +00:00
Intrinsics.h Enable variable arguments support for intrinsics. 2013-10-31 17:18:11 +00:00
Intrinsics.td Change math intrinsic attributes from readonly to readnone. These 2014-03-06 00:18:15 +00:00
IntrinsicsAArch64.td AArch64: simplify tbl/tbx polymorphism 2014-02-26 11:55:09 +00:00
IntrinsicsARM.td ARM: use natural LLVM IR for vshll instructions 2014-02-10 16:20:29 +00:00
IntrinsicsHexagon.td
IntrinsicsMips.td [mips][msa] Add DLSA instruction. 2014-02-10 12:05:17 +00:00
IntrinsicsNVVM.td [NVPTX] Remove i8 register class. PTX support for i8 (.b8, .u8, .s8) is rather poor and we're better off just ignoring it and letting LLVM expand all i8 ops out to i16. 2013-06-28 17:57:59 +00:00
IntrinsicsPowerPC.td Implement PPC counter loops as a late IR-level pass 2013-05-15 21:37:41 +00:00
IntrinsicsR600.td
IntrinsicsX86.td Changed attributes of all gather intrinsics from IntrReadMem to IntrReadArgMem as they access only memory based on argument. Patch by Robert Khasanov. 2014-02-11 04:05:33 +00:00
IntrinsicsXCore.td [XCore] Add intrinsic for CLRPT (clear port time) instruction. 2014-02-25 17:31:15 +00:00
IRBuilder.h [Modules] Move the ConstantFolder into the IR library where it can 2014-03-04 12:02:47 +00:00
IRPrintingPasses.h [PM] Fix stale header blocker, found by Duncan Smith in code review! 2014-01-14 05:50:19 +00:00
LeakDetector.h [Modules] Move the LeakDetector header into the IR library where the 2014-03-04 12:46:06 +00:00
LegacyPassManager.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
LegacyPassManagers.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
LegacyPassNameParser.h [C++11] Add 'override' keyword to IR library. 2014-03-05 06:35:38 +00:00
LLVMContext.h Re-sort all of the includes with ./utils/sort_includes.py so that 2014-01-07 11:48:04 +00:00
Mangler.h Add back r201608, r201622, r201624 and r201625 2014-02-19 17:23:20 +00:00
MDBuilder.h [C++11] Modernize the IR library a bit. 2014-03-10 15:03:06 +00:00
Metadata.h Change the tag on this iterator to bidir and implement enough operators to make it true. 2014-03-06 02:02:43 +00:00
Module.h [C++11] Add range views for various parts of a Module. 2014-03-09 12:20:30 +00:00
NoFolder.h [Modules] Move the NoFolder into the IR library as it creates 2014-03-04 12:05:47 +00:00
OperandTraits.h Fix include guards so they exactly match file names. 2013-01-10 00:45:19 +00:00
Operator.h [Modules] Move GetElementPtrTypeIterator into the IR library. As its 2014-03-04 10:40:04 +00:00
PassManager.h [PM] Cleanup formatting and namespace commenting. Mostly done with 2014-03-10 01:42:03 +00:00
PatternMatch.h [Modules] Move the LLVM IR pattern match header into the IR library, it 2014-03-04 11:08:18 +00:00
PredIteratorCache.h [Modules] Move the PredIteratorCache into the IR library -- it is 2014-03-04 12:09:19 +00:00
SymbolTableListTraits.h Fix include guards so they exactly match file names. 2013-01-10 00:45:19 +00:00
Type.h Re-sort all of the includes with ./utils/sort_includes.py so that 2014-01-07 11:48:04 +00:00
TypeBuilder.h #include <climits> instead of <limits.h> in C++ header file. 2013-06-13 23:49:09 +00:00
TypeFinder.h Move TypeFinder.h into the IR tree, it clearly belongs with the IR library. 2013-01-07 15:43:51 +00:00
Use.h [C++11] Sink the iterator over a Value's users into the Value type 2014-03-05 01:50:35 +00:00
User.h [C++11] Modernize the IR library a bit. 2014-03-10 15:03:06 +00:00
Value.h [C++11] Add range based accessors for the Use-Def chain of a Value. 2014-03-09 03:16:01 +00:00
ValueHandle.h [Modules] Move ValueHandle into the IR library where Value itself lives. 2014-03-04 11:17:44 +00:00
ValueMap.h [C++11] Replace LLVM-style type traits with C++11 standard ones. 2014-03-07 14:42:25 +00:00
ValueSymbolTable.h Fix include guards so they exactly match file names. 2013-01-10 00:45:19 +00:00
Verifier.h [PM] Wire up the Verifier for the new pass manager and connect it to the 2014-01-20 11:34:08 +00:00