Add a libgccjit.pc file for use by pkg-config

gcc/ChangeLog.jit:
	* Makefile.in (pkgconfigdir): New.
	(installdirs): Add creation of $(DESTDIR)$(pkgconfigdir).
	* configure.ac (gcc_version): Expose this value for use via
	AC_SUBST, since we need it within the new file libgccjit.pc.in.
	* configure: Regenerate.

gcc/jit/ChangeLog.jit:
	* Make-lang.in (jit.install-common): Install libgccjit.pc to
	"$(DESTDIR)/$(libdir)/pkgconfig".
	* config-lang.in (outputs): Define this, adding jit/libgccjit.pc
	so that it makes it into AC_CONFIG_FILES and is thus generated from
	jit/libgccjit.pc.in at configure time.
	* docs/intro/install.rst ("Hello world"): Add discussion about the
	use of pkg-config when building against an install in
	a non-standard location.
	* docs/_build/texinfo/libgccjit.texi: Regenerate.
	* libgccjit.pc.in: New.
Add an example of adding JIT-compilation to an interpreter

gcc/jit/ChangeLog.jit:
	* TODO.rst: Add detection of uninitialized variables, since
	this bit me when developing "toyvm".

	* docs/examples/tut03-toyvm/Makefile: New.
	* docs/examples/tut03-toyvm/factorial.toy: New.
	* docs/examples/tut03-toyvm/fibonacci.toy: New.
	* docs/examples/tut03-toyvm/toyvm.c: New.

	* docs/intro/index.rst: Add tutorial03.rst.
	* docs/intro/tutorial01.rst: Fix example of how to dump
	generated machine code.
	* docs/intro/tutorial03.rst: New.
	* docs/intro/factorial.png: New.

	* docs/_build/texinfo/libgccjit.texi: Regenerate.
	* docs/_build/texinfo/factorial.png: New (copied by sphinx from
	docs/intro/factorial.png).
Improvements to documentation

gcc/jit/ChangeLog.jit:
	* docs/_build/texinfo/libgccjit.texi: Regenerate.
	* docs/intro/install.rst: Reduce width of listing.
	* docs/intro/tutorial01.rst: Use <libgccjit.h> rather than
	"libgccjit.h" when including the header.
	* docs/intro/tutorial02.rst: Likewise.
	* docs/intro/tutorial03.rst: Clarify various sections; show
	effect of reducing optimization level down from 3 to 2.
	("Putting it all together"): Move to above...
	("Behind the curtain: optimizing away stack manipulation"):
	...this, and rename this to...
	("Behind the curtain: How does our code get optimized?"): ...and
	add more detail, and discussion of elimination of tail recursion.
Add notes on internals to documentation

gcc/jit/ChangeLog.jit:
	* docs/index.rst: Add internals/index.rst.
	* docs/internals/index.rst: New.
	* notes.txt: Update to reflect renaming of toplev_main to
	toplev::main.
Remove stray "FIXME"

gcc/jit/ChangeLog.jit:
	* docs/intro/tutorial01.rst: Remove stray "FIXME".
	* docs/_build/texinfo/libgccjit.texi: Regenerate.
Remove more FIXMEs

gcc/ChangeLog.jit:
	* cgraph.c (cgraph_c_finalize): Remove FIXME.
	* timevar.c (timevar_init): Likewise.
Fix segfault in ipa-pure-const.c during LTO

In the initial commit on the JIT branch I moved
gcc/ipa-pure-const.c: register_hooks to be a method of
class pass_ipa_pure_const and the static local "init_p" within it
to be member data of the class, to ensure that the pass can be rerun
by separate invocations within one process.

Since the IPA hooks aren't virtual functions they don't have a "this"
so I faked it somewhat by setting "current_pass" before calling the hooks.

Except that I only set "current_pass" when calling "generate_summary": I
forgot to set it when calling the other IPA hooks.  This led to a segfault
when running LTO, due to a NULL dereference of "pass" in ipa-pure-const.c
here, due to current_pass being NULL:

Program received signal SIGSEGV, Segmentation fault.
pure_const_read_summary () at ../../../src/gcc/ipa-pure-const.c:1026
1026      pass->register_hooks ();

(gdb) list
1021      struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
1022      struct lto_file_decl_data *file_data;
1023      unsigned int j = 0;
1024
1025      pass_ipa_pure_const *pass = static_cast <pass_ipa_pure_const *> (current_pass);
1026      pass->register_hooks ();
1027
1028      while ((file_data = file_data_vec[j++]))
1029        {
1030          const char *data;

(gdb) p current_pass
$2 = (opt_pass *) 0x0

(gdb) bt
#0  pure_const_read_summary () at ../../../src/gcc/ipa-pure-const.c:1026
#1  0x00000000008feb20 in ipa_read_summaries_1 (pass=0x18b3900) at ../../../src/gcc/passes.c:2457
#2  0x00000000008ffefb in ipa_read_summaries () at ../../../src/gcc/passes.c:2480
#3  0x00000000005b27bd in read_cgraph_and_symbols (fnames=<optimized out>, nfiles=<optimized out>)
    at ../../../src/gcc/lto/lto.c:3068
#4  lto_main () at ../../../src/gcc/lto/lto.c:3415
#5  0x00000000009bf90e in compile_file () at ../../../src/gcc/toplev.c:553
#6  0x0000000000588c94 in do_compile () at ../../../src/gcc/toplev.c:1943
#7  toplev::main (this=this@entry=0x7fffffffdb5f, argc=argc@entry=26, argv=argv@entry=0x7fffffffdc58)
    at ../../../src/gcc/toplev.c:2040
#8  0x000000000058987c in main (argc=26, argv=0x7fffffffdc58) at ../../../src/gcc/main.c:38

This patch fixes the crash by setting current_pass before calling an IPA
hook.

Bootstrapped&regrtested on x86_64-unknown-linux-gnu (Fedora 20)

gcc/ChangeLog:
	* passes.c (execute_ipa_summary_passes): Fix whitespace when
	assigning to current_pass.
	(ipa_write_summaries_2): Assign "pass" to "current_pass" global
	before calling write_summary hook.
	(ipa_write_optimization_summaries_1): Likewise when calling
	write_optimization_summary hook.
	(ipa_read_summaries_1): Likewise for read_summary hook.
	(ipa_read_optimization_summaries_1): Likewise for
	read_optimization_summary hook.
	(execute_ipa_stmt_fixups): Likewise for stmt_fixup hook.
Add missing gcc/ChangeLog.jit entry from last commit
Don't hardcode documentation version/release

gcc/jit/ChangeLog.jit:
	* docs/conf.py (__read_file): New helper function, for
	extracting...
	(gcc_BASEVER): New variable, read from "BASE-VER" in gcc src dir.
	(gcc_DEVPHASE): Likewise, from file "DEV-PHASE".
	(gcc_DATESTAMP): Likewise, from file "DATESTAMP".
	(gcc_REVISION): Likewise, from file "REVISION" (if present).
	(version): Rather than hardcoding this variable, extract from file
	BASE-VER, via gcc_BASEVER local.
	(release): Likewise, building it up from the files read above.
	* docs/_build/texinfo/libgccjit.texi: Regenerate.
Fix toyvm.c to run within the testsuite

I wrote toyvm to be run standalone, but with
63ff70786e01bd6265e9e7ac1052e4cb8fe5dd38 it's also being run by
jit.exp in the testsuite.

Fix it up so that it meaningfully exercises all this code when run in
this way.

This brings the number of expected passes in jit.sum to 4304

gcc/jit/ChangeLog.jit:
	* docs/examples/tut03-toyvm/toyvm.c: Include <dejagnu.h>.
	Add missing typedef of compilation_state.
	(toyvm_function_parse): Add "name param.
	(test): New.
	(CHECK_NON_NULL): New, from harness.h
	(CHECK_VALUE): Likewise.
	(test_script): New.
	(PATH_TO_SCRIPTS): New define.
	(test_suite): New.
	(main): If called with no args, run the test suite.
Update TODO.rst

gcc/jit/ChangeLog.jit:
	* TODO.rst: Rename "Initial Release" section to "API", and
	remove completed items: builtins, docs, pkgconfig file, fuzz
	testing.  Move ability to name contexts and stmt_list per block
	ideas to a new "Nice to have" section and note that it might be
	better to go straight to gimple.
	Move code coverage to "Test suite" section.
	Add a "Probably not needed" section, moving some items to it.
	Note that we're still missing shift operators.
	Add idea that we could warn about unused objects in a context.
Add shift operators

With this commit, jit.sum has:
	# of expected passes		4600

gcc/jit/ChangeLog.jit:
	* TODO.rst (API): Shift operators are done.
	* docs/topics/expressions.rst (Binary): Add shift operators.
	* internal-api.c (binary_op_strings): Likewise.
	(gcc::jit::playback::context::new_binary_op): Likewise.
	* libgccjit.h (enum gcc_jit_binary_op): Likewise.

gcc/testsuite/ChangeLog.jit:
	* jit.dg/test-expressions.c (make_tests_of_binary_ops): Add
	shift operators.
	(verify_binary_ops): Likewise.
Update the various "*_c_finalize" functions

Five of the *_c_finalize functions were empty, since their files
contain no state [1][2].  Delete them.

Fix up the formatting of the remaining *_c_finalize functions, and
ensure they have descriptive leading comments.

[1] Most of these lost their state when the symbol_table class was
introduced, in r214422.

[2] predict.c has state in the form of these variables:

  static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
               real_inv_br_prob_base, real_one_half, real_bb_freq_max;

and, within function estimate_bb_frequencies:

        static int real_values_initialized = 0;

but it seems to me that this state doesn't need to be reset between
repeated in-process invocations.

gcc/ChangeLog.jit:
	* cgraph.h (cgraphbuild_c_finalize): Delete prototype of empty
	function.
	(ipa_c_finalize): Likewise.
	(predict_c_finalize): Likewise.
	(symtab_c_finalize): Likewise.
	(varpool_c_finalize): Likewise.

	* cgraph.c (cgraph_c_finalize): Add leading comment.  Put return
	type on line before function name.
	* cgraphunit.c (cgraphunit_c_finalize): Likewise.
	* dwarf2out.c (dwarf2out_c_finalize): Likewise.
	* gcse.c (gcse_c_finalize): Likewise.
	* ipa-cp.c (ipa_cp_c_finalize): Likewise.
	* ipa-reference.c (ipa_reference_c_finalize): Likewise.

	* params.c (params_c_finalize): Update leading comment to match
	format of the others mentioned above.

	* cgraphbuild.c (cgraphbuild_c_finalize): Delete empty function.
	* ipa.c (ipa_c_finalize): Likewise.
	* predict.c (predict_c_finalize): Likewise.
	* symtab.c (symtab_c_finalize): Likewise.
	* varpool.c (varpool_c_finalize): Likewise.

	* toplev.c (toplev::finalize): Remove calls to empty functions
	cgraphbuild_c_finalize, ipa_c_finalize, predict_c_finalize,
	symtab_c_finalize, varpool_c_finalize.
Add missing change to gcc/ChangeLog.jit meant for previous commit
Add copyright and license headers and footers

ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

contrib/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

gcc/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

gcc/java/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

gcc/jit/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.
	* Make-lang.in: Update copyright.
	* config-lang.in: Update copyright.
	* docs/examples/install-hello-world.c: Add copyright header.
	* docs/examples/tut01-square.c: Likewise.
	* docs/examples/tut02-sum-of-squares.c: Likewise.
	* docs/examples/tut03-toyvm/toyvm.c: Likewise.
	* internal-api.c: Likewise.
	* internal-api.h: Likewise.
	* libgccjit++.h: Likewise.
	* libgccjit.c: Likewise.
	* libgccjit.h: Likewise.
	* libgccjit.map: Likewise.

gcc/testsuite/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

libbacktrace/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

libcpp/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

libdecnumber/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

libiberty/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.

zlib/ChangeLog.jit:
	* ChangeLog.jit: Add copyright footer.
Use standard initial includes

gcc/jit/ChangeLog.jit:

	* dummy-frontend.c: Update copyright year.  Follow standard for
	initial includes by removing redundant include of "ansidecl.h".
	* internal-api.c: Follow standard for initial includes by removing
	redundant include of "ansidecl.h".
	* jit-builtins.c: Likewise.
	* libgccjit.c: Likewise.
Eliminate fixed-size buffers used with vsnprintf

gcc/jit/ChangeLog.jit:
	* internal-api.c (gcc::jit::dump::write): Eliminate fixed-size
	buffer "buf" by replacing call to vsnprintf with one to vasprintf
	and a free, emitting an error on the dump's context if a malloc
	failure occurs.
	(gcc::jit::recording::context::add_error_va): Likewise, using
	a precanned message if the malloc inside vasprinf fails.  Split
	local "buf" into "malloced_msg" and "errmsg" to ensure that we
	free the message iff we're using one malloc-ed by vasprintf.
	(gcc::jit::recording::string::from_printf): Eliminate fixed-size
	buffer "buf" by replacing call to vsnprintf with one to vasprintf
	and a free, emitting an error on the relevant context if a malloc
	failure occurs.
Add internal API documention and rename some variables

gcc/jit/ChangeLog.jit:
	* dummy-frontend.c (my_walker): Rename to...
	(my_ggc_walker): ...this.
	(my_root_tab): Rename to...
	(jit_root_tab): ...this.
	(jit_langhook_init): Update for renaming of "my_root_tab" to
	"jit_root_tab".
	* internal-api.c: Add descriptive API comments to functions
	throughout.
	(mutex): Rename to...
	(jit_mutex): ...this.
	(gcc::jit::recording::context::compile): Update for renaming of
	"mutex" to "jit_mutex".
	* internal-api.h: Add descriptive API comments to functions
	throughout.  Add indentation to forward declarations of classes
	to indicate inheritance.
	* jit-builtins.c: Likewise.
Flesh out the "Overview of code structure" in the docs

gcc/jit/ChangeLog.jit:
	* docs/internals/index.rst ("Overview of code structure"): Add
	more descriptive text, including various fragments of
	internal-api.h as appropriate.
	* internal-api.h: Add marker comments for use by "literalinclude"
	directives in docs/internals/index.rst.
Expose choose_tmpdir and use it when building tmpdir for jit compilation

Fix the return type of libiberty's choose_tmpdir.

Expose it in libiberty.h

Use it within the JIT's playback::context::compile when building the
tempdir to avoid hardcoding "/tmp/".

gcc/jit/ChangeLog.jit:
	* internal-api.c (make_tempdir_path_template): New.
	(gcc::jit::playback::context::compile): Call
	make_tempdir_path_template to make m_path_template, rather than
	hardcoding "/tmp/" within "/tmp/libgccjit-XXXXXX".

include/ChangeLog.jit:
	* libiberty.h (choose_tmpdir): New prototype.
	* ChangeLog.jit: New.

libiberty/ChangeLog.jit:
	* choose-temp.c (choose_tmpdir): Remove now-redundant local
	copy of prototype.
	* functions.texi: Regenerate.
	* make-temp-file.c (choose_tmpdir): Convert return type from
	char * to const char * - given that this returns a pointer to
	a memoized allocation, the caller must not touch it.