LLVM backend for 6502
Go to file
Hal Finkel 94dc061e85 [PowerPC] Loosen ELFv1 PPC64 func descriptor loads for indirect calls
Function pointers under PPC64 ELFv1 (which is used on PPC64/Linux on the
POWER7, A2 and earlier cores) are really pointers to a function descriptor, a
structure with three pointers: the actual pointer to the code to which to jump,
the pointer to the TOC needed by the callee, and an environment pointer. We
used to chain these loads, and make them opaque to the rest of the optimizer,
so that they'd always occur directly before the call. This is not necessary,
and in fact, highly suboptimal on embedded cores. Once the function pointer is
known, the loads can be performed ahead of time; in fact, they can be hoisted
out of loops.

Now these function descriptors are almost always generated by the linker, and
thus the contents of the descriptors are invariant. As a result, by default,
we'll mark the associated loads as invariant (allowing them to be hoisted out
of loops). I've added a target feature to turn this off, however, just in case
someone needs that option (constructing an on-stack descriptor, casting it to a
function pointer, and then calling it cannot be well-defined C/C++ code, but I
can imagine some JIT-compilation system doing so).

Consider this simple test:
  $ cat call.c

  typedef void (*fp)();
  void bar(fp x) {
    for (int i = 0; i < 1600000000; ++i)
      x();
  }

  $ cat main.c

  typedef void (*fp)();
  void bar(fp x);
  void foo() {}
  int main() {
    bar(foo);
  }

On the PPC A2 (the BG/Q supercomputer), marking the function-descriptor loads
as invariant brings the execution time down to ~8 seconds from ~32 seconds with
the loads in the loop.

The difference on the POWER7 is smaller. Compiling with:

  gcc -std=c99 -O3 -mcpu=native call.c main.c : ~6 seconds [this is 4.8.2]

  clang -O3 -mcpu=native call.c main.c : ~5.3 seconds

  clang -O3 -mcpu=native call.c main.c -mno-invariant-function-descriptors : ~4 seconds
  (looks like we'd benefit from additional loop unrolling here, as a first
   guess, because this is faster with the extra loads)

The -mno-invariant-function-descriptors will be added to Clang shortly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226207 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-15 21:17:34 +00:00
autoconf Trunk is now 3.7.0svn 2015-01-14 17:38:03 +00:00
bindings [OCaml] Allow out-of-tree builds of LLVM bindings. 2015-01-13 12:17:56 +00:00
cmake [OCaml] Use $CAMLORIGIN, an rpath-$ORIGIN-like mechanism in OCaml. 2015-01-13 09:47:59 +00:00
docs ReleaseNotes.rst: bump version to 3.7 2015-01-14 18:07:30 +00:00
examples
include Add a new pass "inductive range check elimination" 2015-01-15 20:45:46 +00:00
lib [PowerPC] Loosen ELFv1 PPC64 func descriptor loads for indirect calls 2015-01-15 21:17:34 +00:00
projects
test [PowerPC] Loosen ELFv1 PPC64 func descriptor loads for indirect calls 2015-01-15 21:17:34 +00:00
tools [PM] Port TargetLibraryInfo to the new pass manager, provided by the 2015-01-15 11:39:46 +00:00
unittests Fix the C-API MCJIT test for 32-bit big endian machines. 2015-01-15 15:36:04 +00:00
utils Replace size method call of containers to empty method where appropriate 2015-01-15 11:41:30 +00:00
.arcconfig
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt Trunk is now 3.7.0svn 2015-01-14 17:38:03 +00:00
CODE_OWNERS.TXT
configure Trunk is now 3.7.0svn 2015-01-14 17:38:03 +00:00
CREDITS.TXT
LICENSE.TXT
llvm.spec.in
LLVMBuild.txt
Makefile
Makefile.common
Makefile.config.in
Makefile.rules
README.txt

Low Level Virtual Machine (LLVM)
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you're writing a package for LLVM, see docs/Packaging.rst for our
suggestions.