OSDN Git Service

android-x86/external-swiftshader.git
9 years agoSubzero: Rerun clang-format after LLVM 3.6 merge.
Jim Stichnoth [Wed, 4 Mar 2015 01:06:33 +0000 (17:06 -0800)]
Subzero: Rerun clang-format after LLVM 3.6 merge.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/974113002

9 years agoSubzero: Run sandboxed cross tests, and do some cleanup.
Jim Stichnoth [Wed, 4 Mar 2015 00:13:11 +0000 (16:13 -0800)]
Subzero: Run sandboxed cross tests, and do some cleanup.

Tests all cross tests in both sandboxed and unsandboxed modes.  Unfortunately, crosstest run time is more than doubled because of LTO of the crosstest drivers.  (We may want to add "full" and "lite" versions of cross tests.)

LLVM triple strings are removed where possible (from .ll files), and when generated, we use just i686 or i686-nacl.

"Fix" the integrated assembler to emit the lock prefix after the 16-bit operand prefix, to make the validator happy.

Don't add external symbol references to the ELF file for llvm.* intrinsic functions.

Make the ELF object writer honor the -externalize argument.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4092
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/973823003

9 years agoIgnore NaCl st_blksize of 0 and buffer writes to raw_fd_ostream.
Jan Voung [Tue, 3 Mar 2015 18:22:00 +0000 (10:22 -0800)]
Ignore NaCl st_blksize of 0 and buffer writes to raw_fd_ostream.

The default LLVM raw_fd_ostream buffer size is based on stat'ing the
FD and then checking st_blksize. Unfortunately, in the NaCl sandboxed
build of pnacl-sz, NaCl's syscall returns st_blksize of 0 which makes
the writes unbuffered. There is a comment in "src/trusted/service_runtime/include/bits/stat.h":

  nacl_abi_blksize_t nacl_abi_st_blksize;   /* not implemented */

And the " src/trusted/desc/" implementation sets this to 0.

This results in half a million write syscalls to translate the GCC pexe,
which roughly doubles the translation time in sandboxed mode vs
unsandboxed mode.

Manually set a buffer size (Linux st_blksize seems to be about
4KB for comparison). This drops the number of write syscalls
to about 200 for translating the GCC pexe.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4091
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/969403003

9 years agoSubzero: Fix a register allocation issue for "advanced phi lowering".
Jim Stichnoth [Tue, 3 Mar 2015 00:56:20 +0000 (16:56 -0800)]
Subzero: Fix a register allocation issue for "advanced phi lowering".

When the advanced phi lowering handles a phi arg that is Undef, it lowers it to an assignment of a constant zero (or vector of zeroes).  The ad-hoc register allocation was missing the fact that a vector of zeroes is done with "pxor %reg, %reg".  This resulted in a pxor instruction with invalid addressing modes at emission time.

The fix is to tell legalize() to use the dest physical register if dest has one; and if dest lacks a register, take the path where it actually does the ad-hoc register allocation as though the source operand were a memory operand.

Tests are added for these vector undef phi args, and for scalar undef phi args as well for good measure.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/969703002

9 years agoSubzero makefile changes for linking a static llvm2ice nexe w/ LLVM build sys.
Jan Voung [Mon, 2 Mar 2015 22:21:54 +0000 (14:21 -0800)]
Subzero makefile changes for linking a static llvm2ice nexe w/ LLVM build sys.

Need to list more dependencies, otherwise the static
link fails. The current unsandboxed build is a shared build
which uses libLLVM-3.*.so.

Also mess with the CXXFlags a bit. The current pnacl-llc
nexe build uses O3, but that triggers a method pointer bug:
https://code.google.com/p/nativeclient/issues/detail?id=3857,
so override that with O2. We may just want to change the
pnacl-llc build as well (maybe use Os), but I don't
know of the performance implications right now.

Use gnu++11, because of newlib + libc++.

Toggle the feature flags to be a MINIMAL build when
building the sandboxed translator w/ the LLVM-based
Makefile.

Goes with build script change https://codereview.chromium.org/945473003/

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4091
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3857
R=dschuff@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/937283002

9 years agoSubzero: Clean up the runtime implementation.
Jim Stichnoth [Mon, 2 Mar 2015 07:12:55 +0000 (23:12 -0800)]
Subzero: Clean up the runtime implementation.

The runtime helpers are given more consistent names:
  __Sz_<bitcode>_<type1>_<type2>

Missing helpers (various vector bitcasts) are implemented.

We'd prefer to avoid calling external library functions, e.g. in compiler-rt, but even llc uses these helpers for some bitcode on x86-32, so the alternative is to copy their implementation into Subzero's runtime.

BUG= none
R=mtrofin@chromium.org

Review URL: https://codereview.chromium.org/961413002

9 years agollvm-readobj no longer prints section data for .bss sections (adjust test)
Jan Voung [Thu, 26 Feb 2015 21:23:03 +0000 (13:23 -0800)]
llvm-readobj no longer prints section data for .bss sections (adjust test)

9 years agoMerge latest changes from branch 'master' into merge_36 branch.
Jan Voung [Thu, 26 Feb 2015 18:03:41 +0000 (10:03 -0800)]
Merge latest changes from branch 'master' into merge_36 branch.

9 years agoSubzero: Change the name llvm2ice to the more appropriate pnacl-sz.
Jim Stichnoth [Thu, 26 Feb 2015 17:42:36 +0000 (09:42 -0800)]
Subzero: Change the name llvm2ice to the more appropriate pnacl-sz.

Most of this is a mechanical change of 'llvm2ice' to 'pnacl-sz'.  This is a convenient naming choice because both strings are the same length which minimizes the need for line length reformatting.

Python variables needed to use pnacl_sz instead, and sometimes pnacl_sz_ .

The IceConverter still uses LLVM2Ice naming, which is actually appropriate there since it actually converts LLVM IR into ICE.

I will rename tests_lit/llvm2ice_tests/ in a separate CL, otherwise this CL will look misleadingly massive and no one will review it.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/956123002

9 years agoSubzero: Clean up function header emission.
Jim Stichnoth [Wed, 25 Feb 2015 22:48:43 +0000 (14:48 -0800)]
Subzero: Clean up function header emission.

1. Don't do anything in Cfg::emitTextHeader() in MINIMAL mode.  (Reduces binary size by 1KB.)  This actually broke a number of lit tests for the MINIMAL build, so "--assemble --disassemble" was changed to "--filetype=obj --disassemble".  This allowed (or required) better precision in checking for data symbols.

1a. For the lit files touched, go ahead and remove "-verbose none" since that will forevermore by the default.

2. Don't emit the ".bundle_align_mode" directive.  This is not
necessary when assembling with the right -triple argument.

BUG= none
R=jvoung@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/955003002

9 years agoGet text align in elf writer from the target asm method instead.
Jan Voung [Wed, 25 Feb 2015 17:08:44 +0000 (09:08 -0800)]
Get text align in elf writer from the target asm method instead.

Rather than hard code 32.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4080
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/948343007

9 years agoOmit textual emitConstPool in MINIMAL build.
Jan Voung [Wed, 25 Feb 2015 00:57:17 +0000 (16:57 -0800)]
Omit textual emitConstPool in MINIMAL build.

Noticed the "Note: Still used by emit IAS" and decided
to check if we can omit it. Saves about 3KB.

There's also the "Note: Still used by emit IAS" CFG
text header, but I haven't looked at that.

This would silently cripple the -filetype=asm or
-filetype=iasm in the MINIMAL build, but that isn't
supposed to be supported. Had to conditionalize some more
of the tests.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4080
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/952993006

9 years agoSubzero: Improve class definition hygiene.
Jim Stichnoth [Tue, 24 Feb 2015 17:30:30 +0000 (09:30 -0800)]
Subzero: Improve class definition hygiene.

Delete zero-argument ctor where possible.

Delete default copy ctor and default assignment operator where possible (some were missed in the past).

(The above are not done to the cross tests because we aren't yet building them with C++11.)

Declare single-argument ctor as "explicit".

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/952953002

9 years agoSubzero: Fix a warning (promoted to an error) under NOASSERT=1 build.
Jim Stichnoth [Tue, 24 Feb 2015 17:11:13 +0000 (09:11 -0800)]
Subzero: Fix a warning (promoted to an error) under NOASSERT=1 build.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/951283002

9 years agoHandle ffunction-sections w/ filetype=obj.
Jan Voung [Tue, 24 Feb 2015 16:53:52 +0000 (08:53 -0800)]
Handle ffunction-sections w/ filetype=obj.

Just create a new section of the appropriate name, instead of
trying to reuse the .text section.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4080
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/948943004

9 years agoSubzero: Update tests and build scripts for sandboxing.
Jim Stichnoth [Tue, 24 Feb 2015 00:39:06 +0000 (16:39 -0800)]
Subzero: Update tests and build scripts for sandboxing.

Spec2k now runs sandboxed, using all filetypes (asm, iasm, obj).

The new build-runtime.py script builds the native and sandboxed runtimes in build/runtime/ .  The various Subzero driver scripts are updated to use that.

Fixes a stack frame bug in sandboxed mode when the integrated assembler is used.  The stack adjustment for setting up a function call wasn't being rolled back for the second emitIAS() pass, so stack variables passed as arguments to the callee were being copied from the wrong stack slot.

Notes:

1. The hybrid Subzero/llc bisection debugging builds probably do not work as intended for -filetype=obj since the ELF emitter doesn't yet support -ffunction-sections.  (This was also true for non-sandboxed hybrid builds.)

2. The cross tests have not yet been adapted for testing sandboxing.  I'd prefer to first make progress on https://code.google.com/p/nativeclient/issues/detail?id=4085 in order to avoid blindly doubling the number of tests.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4079
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/944333002

9 years agoSubzero: Translate the unreachable bitcode directly to ud2.
Jim Stichnoth [Fri, 20 Feb 2015 19:43:41 +0000 (11:43 -0800)]
Subzero: Translate the unreachable bitcode directly to ud2.

This removes ice_unreachable() from the Subzero runtime.  The ice_unreachable() implementation is problematic since it makes a call to external function abort(), which leads to an undefined symbol error in the linker because abort() is internalized at link time.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4091
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/945953002

9 years agoSubzero: Add sandboxing for x86-32.
Jim Stichnoth [Fri, 20 Feb 2015 17:20:14 +0000 (09:20 -0800)]
Subzero: Add sandboxing for x86-32.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4079
R=jvoung@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/930733002

9 years agoSubzero: switch from llvm-objdump to objdump for lit tests (for LLVM merge)
Jan Voung [Thu, 19 Feb 2015 19:27:44 +0000 (11:27 -0800)]
Subzero: switch from llvm-objdump to objdump for lit tests (for LLVM merge)

After the next LLVM merge, llvm-objdump is going to lose the "--symbolize"
flag. It also sounds like llvm-objdump may at some point converge to the
objdump-style of output.

So, rather than keep updating test expectations, switch to objdump,
assuming objdump will be more stable than llvm-objdump.

Also stash the assembler/disassembler commandlines in
the run-llvm2ice.py script. In theory this will let us
tweak the commandlines more easily (one place).
In practice the test expectatations will probably need
to be adjusted if the base commandlines change though.

Bulk edit the test expectations to match objdump now.
Some of this is assisted by a python script.
Example script: https://codereview.chromium.org/928663002/

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4026
R=kschimpf@google.com, stichnot@chromium.org

Review URL: https://codereview.chromium.org/914263005

9 years agoFix Makefile for toolchain_build_pnacl.py.
Karl Schimpf [Fri, 13 Feb 2015 19:53:36 +0000 (11:53 -0800)]
Fix Makefile for toolchain_build_pnacl.py.

BUG=None
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/923183002

9 years agoSubzero: Make threads=2 and filetype=obj the testing defaults.
Jim Stichnoth [Fri, 13 Feb 2015 18:00:10 +0000 (10:00 -0800)]
Subzero: Make threads=2 and filetype=obj the testing defaults.

Change crosstest.py's -elf argument to the now-standard -filetype and just pass it through to llvm2ice.  This also fixes a leftover -elf-writer argument that should have been changed to -filetype=obj.

It would be nice to change all the explicit -threads=0 to -threads=1 in the lit tests, but that uncovers too many assumptions about dump/emit output order, or ordering between function and global data emission.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/924023002

9 years agoConvert a few lit tests that use "lc2i | llvm-mc | llvm-objdump" to use p2i.
Jan Voung [Fri, 13 Feb 2015 17:47:09 +0000 (09:47 -0800)]
Convert a few lit tests that use "lc2i | llvm-mc | llvm-objdump" to use p2i.

Makes it more uniform for a later bulk refactoring of
"p2i | llvm-mc | llvm-objdump", so it only needs to match p2i
and not lc2i. Some of the test expectations change though.

Also there was a stray XCHECK that I don't remember why
it was XCHECK... change that to CHECK.

BUG= none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/927433002

9 years agoSubzero: Honor the Internal flag when filetype=asm.
Jim Stichnoth [Fri, 13 Feb 2015 05:35:34 +0000 (21:35 -0800)]
Subzero: Honor the Internal flag when filetype=asm.

When filetype=asm, the Internal flag of the Cfg wasn't being copied to the Assembler, so all symbols were made global.  This would cause multiply defined symbols in Spec, particularly main().

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/921043002

9 years agoSubzero: Generate a web page showing llvm2ice size breakdown.
Jim Stichnoth [Fri, 13 Feb 2015 00:10:37 +0000 (16:10 -0800)]
Subzero: Generate a web page showing llvm2ice size breakdown.

"make -f Makefile.standalone bloat" generates a json file containing ./llvm2ice size data, and launches google-chrome on the output.

bloat.py is taken verbatim from https://github.com/martine/bloat/blob/master/bloat.py .

webtreemap.{js,css} are taken verbatim from https://github.com/martine/webtreemap .

llvm2ice.bloat.html is adapted from https://github.com/martine/webtreemap/blob/gh-pages/demo/demo.html .

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/917203002

9 years agoSubzero: Use -filetype instead of -ias and -elf-writer.
Jim Stichnoth [Thu, 12 Feb 2015 22:01:48 +0000 (14:01 -0800)]
Subzero: Use -filetype instead of -ias and -elf-writer.

This matches LLVM's -filetype={obj,asm} options, and also adds -filetype=iasm to get textual rendering with the integrated assembler.

It also removes the old illegal combination of -ias=0 -elf-writer.

BUG= none
R=jvoung@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/920953002

9 years agoSubzero: Emit functions and global initializers in a separate thread.
Jim Stichnoth [Thu, 12 Feb 2015 00:08:31 +0000 (16:08 -0800)]
Subzero: Emit functions and global initializers in a separate thread.

(This is a continuation of https://codereview.chromium.org/876083007/ .)

Emission is done in a separate thread when -threads=N with N>0 is specified.  This includes both functions and global initializers.

Emission is deterministic.  The parser assigns sequence numbers, and the emitter thread reassembles work units into their original order, regardless of the number of threads.

Dump output, however, is not intended to be in deterministic, reassembled order.  As such, lit tests that test dump output (i.e., '-verbose inst') are explicitly run with -threads=0.

For -elf-writer and -ias=1, the translator thread invokes Cfg::emitIAS() and the assembler buffer is passed to the emitter thread.  For -ias=0, the translator thread passed the Cfg to the emitter thread which then invokes Cfg::emit() to produce the textual asm.

Minor cleanup along the way:
  * Removed Flags from the Ice::Translator object and ctor, since it was redundant with Ctx->getFlags().
  * Cfg::getAssembler<> is the same as Cfg::getAssembler<Assembler> and is useful for just passing the assembler around.
  * Removed the redundant Ctx argument from TargetDataLowering::lowerConstants() .

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4075
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/916653004

9 years agoFix PNaCl bitcode reader to release global variables to emitter.
Karl Schimpf [Tue, 10 Feb 2015 22:43:45 +0000 (14:43 -0800)]
Fix PNaCl bitcode reader to release global variables to emitter.

Fixes the PNaCl bitcode reader to maintain two lists of global
variables. The first, VariableDeclarations, is the list of
variable declarations to be lowered by the emitter. The second,
ValueIDConstants, is the corresponding constant symbol to use
when references to the corresponding global variable declaration
is referenced when processing functions.

BUG=None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/883673005

9 years agoAdds accessor methods to class ClFlags.
Karl Schimpf [Mon, 9 Feb 2015 22:20:22 +0000 (14:20 -0800)]
Adds accessor methods to class ClFlags.

Allows one to define explicit overrides in get accessors, based on
compilation features. To show usage, modified SubConstantCalls to
never be enabled if building a minimal llvm2ice.

BUG=None
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/905463003

9 years agoConvert a few getName() methods to return a const string ref.
Jan Voung [Fri, 6 Feb 2015 01:31:28 +0000 (17:31 -0800)]
Convert a few getName() methods to return a const string ref.

Followup to a previous code review.
Saves 2KB from the minimal build =)

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/904783002

9 years agoAllow stubbing of called constant addresses using command line argument.
Karl Schimpf [Thu, 5 Feb 2015 18:55:36 +0000 (10:55 -0800)]
Allow stubbing of called constant addresses using command line argument.

When specified (via command line) replaces all called constant addresses
with a stubbed call to the first defined function in the bitcode file.
This allows testing of subzero without having to fix that downstream
code (after parsing) may not handle such addresses.

BUG=None
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/902713002

9 years agoChanges to rebase Subzero to LLVM 223109 APIs.
Jan Voung [Tue, 3 Feb 2015 01:59:02 +0000 (17:59 -0800)]
Changes to rebase Subzero to LLVM 223109 APIs.

9 years agoAdd comment for the forked Dart revision for the assembler code.
Jan Voung [Wed, 4 Feb 2015 00:06:42 +0000 (16:06 -0800)]
Add comment for the forked Dart revision for the assembler code.

Also note to keep that up to date.
See also Patch set 1 of https://codereview.chromium.org/574133002/,
vs later patch sets.

Some things that were changed:
(*) Headers / constants use Ice version (RegX8632::Encoded_Reg_eax vs EAX), (KB / MB -> other...)
(*) Use llvm/Subzero allocator instead of Dart one.
(*) Class/Field/On-stack-replacement/Dart runtime stuff is removed
(*) Relocation/Fixups are now POD -- rather than a class
with a virtual method for fixup. For now, we write out
an ELF relocation, but later we may do a target pass
to handle function calls within the same section, etc.
(*) ASSERT -> assert
(*) uword -> uintptr_t (should check).
(*) clang-format
(*) ???

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/901453002

9 years agoSubzero: Fix unittest build dependencies.
Jim Stichnoth [Tue, 3 Feb 2015 22:35:51 +0000 (14:35 -0800)]
Subzero: Fix unittest build dependencies.

The unittest .o files also depend on some of the llvm2ice headers, as well as the unittest headers.

To reproduce the problem, try this:

make -f Makefile.standalone clean
make -f Makefile.standalone check-unit 2>/dev/null | grep BitcodeMunge.cpp

This will print a line containing BitcodeMunge.cpp.

Now do:

touch unittest/BitcodeMunge.h
make -f Makefile.standalone check-unit 2>/dev/null | grep BitcodeMunge.cpp

This should print a line, but it doesn't.

Finally:

touch src/PNaClTranslator.h
make -f Makefile.standalone check-unit 2>/dev/null | grep BitcodeMunge.cpp

This should also print a line, but it doesn't.

With this patch, the unittest files get rebuilt after header file changes.

BUG= none
R=jvoung@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/895143003

9 years agoTrack protos + globals w/out initializers as undef too (not just helper funcs)
Jan Voung [Tue, 3 Feb 2015 20:48:38 +0000 (12:48 -0800)]
Track protos + globals w/out initializers as undef too (not just helper funcs)

Also handle empty global variable lists -- and initialize
ShAddralign to 1 instead of 0, just in case. Previously
it would try to align by 0 when the variable list was empty.

This should help the crosstests pass with --elf.

BUG=none
R=kschimpf@google.com, stichnot@chromium.org

Review URL: https://codereview.chromium.org/899483002

9 years agoSubzero: Fix some -Winconsistent-missing-override that clang 3.6 warns about.
Jan Voung [Tue, 3 Feb 2015 16:27:44 +0000 (08:27 -0800)]
Subzero: Fix some -Winconsistent-missing-override that clang 3.6 warns about.

I'd like to bump the *trusted* clang compiler also,
since the really old trusted clang compiler seems to crash
if we pair old clang with new libcxx. (So the merge will
probably have to bump the trusted clang compiler to
a newer rev).

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4026
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/898693002

9 years agoSubzero: Manage each Cfg as a std::unique_ptr<Cfg>.
Jim Stichnoth [Tue, 3 Feb 2015 01:03:08 +0000 (17:03 -0800)]
Subzero: Manage each Cfg as a std::unique_ptr<Cfg>.

The Cfg::create() method now returns a unique_ptr.  Once the parser fully builds the Cfg, it is released onto the work queue, and then acquired and ultimately deleted by the translator thread.

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/892063002

9 years agoTrack undefined sym in the symtab. Remove hack for missing relocs against undef.
Jan Voung [Sun, 1 Feb 2015 18:31:03 +0000 (10:31 -0800)]
Track undefined sym in the symtab. Remove hack for missing relocs against undef.

Preliminary linking tests, seems to show that the linker
and objcopy are happy to use 'em on spec2k, and the
result runs! (Had to be careful to clobber the old .s
and .o files to make it's testing the right copy).

Haven't tried crosstests yet.

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/889613004

9 years agoSubzero: Add a --elf arg to szbuild.py and crosstest.py.
Jim Stichnoth [Sun, 1 Feb 2015 01:57:41 +0000 (17:57 -0800)]
Subzero: Add a --elf arg to szbuild.py and crosstest.py.

This also implicitly applies to szbuild_spec2k.py.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/892803002

9 years agoSubzero: Fix stats collection and output for multithreading.
Jim Stichnoth [Sat, 31 Jan 2015 18:48:11 +0000 (10:48 -0800)]
Subzero: Fix stats collection and output for multithreading.

Updates of current-function and cumulative stats are done entirely in TLS.  At the end, cumulative stats are merged across all threads' TLS into the global cumulative stats.

Printing of cumulative stats after every function is removed, since there's very little value from that.  It was probably done in the first place just to give partial cumulative information in the face of crashes or assertion failures.

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/887213002

9 years agoFix subzero Windows build
JF Bastien [Sat, 31 Jan 2015 18:13:25 +0000 (10:13 -0800)]
Fix subzero Windows build

MinGW's GCC 4.8.1 was sad because SectionType was shadowing the other SectionType. Also, the enum's values are in the ELFObjectWriter namespace, not ELFObjectWriter::SectionType.

R=stichnot@chromium.org, jvoung@chromium.org
BUG= Windows build is sad

Review URL: https://codereview.chromium.org/891953002

9 years agoSubzero: Fix timers for multithreaded translation.
Jim Stichnoth [Fri, 30 Jan 2015 21:10:39 +0000 (13:10 -0800)]
Subzero: Fix timers for multithreaded translation.

Now that multithreaded parsing and translation is in place, timer operations have to be made thread-local.  After the non-main threads end, their thread-local timer data needs to be merged into the global timer data, which resides in the GlobalContext object.  The merge is a bit tricky because the internal timer stack structure is built up dynamically as items are pushed and popped.  Two threads may have radically different timing data:

1. The parser thread profile is completely different from a translator thread.

2. For -timing-funcs, two translator threads hold data for entirely different sets of functions.

A bit more tweaking will need to be done to make the timing output fully usable in a multithreaded run.  Because of multiple threads, times may add up to >100%.  Also, time spent blocked is being "unfairly" attributed to the caller of the blocking operation - we should either count the user time instead of wall-clock time, or add a special timer marker for blocking locking operations.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/878383004

9 years agoSubzero: Minor Makefile fix.
Jim Stichnoth [Fri, 30 Jan 2015 17:34:05 +0000 (09:34 -0800)]
Subzero: Minor Makefile fix.

The problem showed up after the link step failed, in which case $(OBJDIR)/llvm2ice was deleted but the ./llvm2ice symlink still existed.  A subsequent "make check-lit" or "make check" would fail, so the basic "make" would have to be done first.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/887873002

9 years agoWrite out global initializers and data rel directly to ELF file.
Jan Voung [Thu, 29 Jan 2015 22:42:38 +0000 (14:42 -0800)]
Write out global initializers and data rel directly to ELF file.

The local symbol relocations are a bit different from
llvm-mc, which are section-relative. E.g., instead "bytes",
it will be ".data + offsetof(bytes, .data)". So the
contents of the text/data/rodata sections can also differ
since the offsets written in place are different.

Still need to fill the symbol table with undefined
symbols (e.g., memset, and szrt lib functions) before
trying to link.

BUG=none
R=kschimpf@google.com, stichnot@chromium.org

Review URL: https://codereview.chromium.org/874353006

9 years agoWork around GCC bug in constexpr to attributes
JF Bastien [Wed, 28 Jan 2015 23:07:38 +0000 (15:07 -0800)]
Work around GCC bug in constexpr to attributes

__attribute__((aligned(MaxCacheLineSize))) triggers a GCC bug because enum {MaxCacheLineSize = 64 }; isn't constant enough. Adding zero to it makes it that much more constant.

R= stichnot@chromium.org
BUG= https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55382

Review URL: https://codereview.chromium.org/867483004

9 years agoAdd missing period
JF Bastien [Wed, 28 Jan 2015 22:32:28 +0000 (14:32 -0800)]
Add missing period

The period, it was missing

R= stichnot@chromium.org
BUG= none
.

Review URL: https://codereview.chromium.org/888473002

9 years agoFix missing header include
JF Bastien [Wed, 28 Jan 2015 22:10:35 +0000 (14:10 -0800)]
Fix missing header include

<mutex> is already included from IceDefs.h (where GlobalLockType is defined) but <condition_variable> isn't included anywhere. It's probably included indirectly in some standard libraries and not others, causing build failures on Windows.

TBR= stichnot@chromium.org
BUG= none

Review URL: https://codereview.chromium.org/884283002

9 years agoRemove unnecessary fields in top-level parser of Subzero.
Karl Schimpf [Wed, 28 Jan 2015 18:58:25 +0000 (10:58 -0800)]
Remove unnecessary fields in top-level parser of Subzero.

Cleans up code by removing unnecessary fields/data structures in top-level parser of Subzero. In particular:

1) Uses FunctionDeclarationList.size() instead of NumFunctionIds.

2) Removes the need for vector DefiningFunctionDeclarationList. Instead uses an (incremented) index NextDefiningFunctionID into vector
FunctionDeclarationList.

BUG=None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/883493002

9 years agoAdd a missing #include, to fix the Windows build.
Jim Stichnoth [Wed, 28 Jan 2015 16:55:28 +0000 (08:55 -0800)]
Add a missing #include, to fix the Windows build.

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/865093003

9 years agoAdd -pedantic to Makefile.standalone to match production.
Jim Stichnoth [Wed, 28 Jan 2015 16:37:22 +0000 (08:37 -0800)]
Add -pedantic to Makefile.standalone to match production.

This also requires modifying the ICE_CACHELINE_BOUNDARY macro to avoid a warning about anonymous structs:

src/IceUtils.h:132:3: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/883983002

9 years agoFix pedantic build warnings;
JF Bastien [Tue, 27 Jan 2015 20:56:49 +0000 (12:56 -0800)]
Fix pedantic build warnings;

GCC 4.8.1 is sad;

There are extra semicolons in Subzero;

It removes the semicolons or it gets the build warning hose again;^H

R=stichnot@chromium.org
BUG= none

Review URL: https://codereview.chromium.org/882743003

9 years agoSubzero: Use a "known" version of clang-format.
Jim Stichnoth [Tue, 27 Jan 2015 20:53:53 +0000 (12:53 -0800)]
Subzero: Use a "known" version of clang-format.

There are two problems with "make format" and "make format-diff" in
Makefile.standalone:

1. You have to make sure clang-format and clang-format-diff.py are
available in $PATH.

2. Different users may have different versions installed (even for the
same user on different machines), leading to whitespace wars.  Can't we
all just get along?

Since the normal LLVM build that Subzero depends on also exposes and
builds clang-format and friends, we might as well use it.  The
clang-format binary is found in $LLVM_BIN_PATH, and clang-format-diff.py
is found relative to $LLVM_SRC_PATH.  As long as the user's LLVM build
is fairly up to date, whitespace wars are unlikely.

Given this, there's a much higher incentive to use "make format"
regularly instead of "make format-diff".  In particular, inline comments
on variable/field declaration lists can get lined up more nicely by
looking at the entire context, rather than the small diff window.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/877003003

9 years agoSubzero: Initial implementation of multithreaded translation.
Jim Stichnoth [Tue, 27 Jan 2015 13:06:03 +0000 (05:06 -0800)]
Subzero: Initial implementation of multithreaded translation.

Provides a single-producer, multiple-consumer translation queue where the number of translation threads is given by the -threads=N argument.  The producer (i.e., bitcode parser) blocks if the queue size is >=N, in order to control the memory footprint.  If N=0 (which is the default), execution is purely single-threaded.  If N=1, there is a single translation thread running in parallel with the parser thread.  "make check" succeeds with the default changed to N=1.

Currently emission is also done by the translation thread, which limits scalability since the emit stream has to be locked.  Also, since the ELF writer stream is not locked, it won't be safe to use N>1 with the ELF writer.  Furthermore, for N>1, emitted function ordering is nondeterministic and needs to be recombobulated.  This will all be fixed in a follow-on CL.

The -timing option is broken for N>0.  This will be fixed in a follow-on CL.

Verbose flags are now managed in the Cfg instead of (or in addition to) the GlobalContext, due to the -verbose-focus option which wants to temporarily change the verbose level for a particular function.

TargetLowering::emitConstants() and related methods are changed to be static, so that a valid TargetLowering object isn't required.  This is because the TargetLowering object wants to hold a valid Cfg, and none really exists after all functions are translated and the constant pool is ready for emission.

The Makefile.standalone now has a TSAN=1 option to enable ThreadSanitizer.

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/870653002

9 years agoSubzero: Second attempt at fixing MacOS 10.6 build.
Jim Stichnoth [Mon, 26 Jan 2015 19:10:03 +0000 (11:10 -0800)]
Subzero: Second attempt at fixing MacOS 10.6 build.

Manages thread_local pointer fields through a set of macros.  If ICE_THREAD_LOCAL_HACK is defined, the thread_local definitions and accesses are defined in terms of pthread operations.  This assumes that the underlying std::thread library is based on pthread.

BUG= none
R=jfb@chromium.org, jvoung@chromium.org

Review URL: https://codereview.chromium.org/872933002

9 years agoMake use of BSS more explicit in global initializers (vs a local .comm).
Jan Voung [Sun, 25 Jan 2015 18:46:00 +0000 (10:46 -0800)]
Make use of BSS more explicit in global initializers (vs a local .comm).

This reduces the number of conditionals, and will more closely reflect
the structure of the ELF writer's version of the same thing.
Without fdata-sections, the ELF writer version will have to batch all
initializers of a certain type so that they can be contiguous on the file
and the overall alignment can be determined.

A downside of this is that, .s files will be different from llc's output.
The spec .o and executables are identical before/after the change.

BUG=none
R=kschimpf@google.com, stichnot@chromium.org

Review URL: https://codereview.chromium.org/870123003

9 years agoSubzero: Make thread_local work under MacOS 10.6.
Jim Stichnoth [Fri, 23 Jan 2015 18:22:56 +0000 (10:22 -0800)]
Subzero: Make thread_local work under MacOS 10.6.

MacOS doesn't support the thread_local keyword until 10.7 or later, and our bots run 10.6.

Who knows whether Visual Studio supports it yet.

In the meantime, use the old-style syntax.

BUG= https://codereview.chromium.org/873443004/
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/865973006

9 years agoFix build warnings
JF Bastien [Thu, 22 Jan 2015 22:30:57 +0000 (14:30 -0800)]
Fix build warnings

The following CL enables -Werror:
  https://codereview.chromium.org/863093002/

There were two warnings left in our subzero build:
 - Dead default cases because all of an enum's values were handled by the switch.
 - Use of C99 VLA.

R=stichnot@chromium.org
TEST= make check
BUG= none

Review URL: https://codereview.chromium.org/862853003

9 years agoFix the PNaCl translator to lock the dump stream when printing errors.
Karl Schimpf [Thu, 22 Jan 2015 18:00:07 +0000 (10:00 -0800)]
Fix the PNaCl translator to lock the dump stream when printing errors.

The previous code did not do this. Also localizes the lock to when
the error is actually printed.

Note: requires https://codereview.chromium.org/865963002

BUG=None
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/864383002

9 years agoSubzero: Remove the GlobalContext::GlobalDeclarations vector.
Jim Stichnoth [Tue, 20 Jan 2015 22:53:57 +0000 (14:53 -0800)]
Subzero: Remove the GlobalContext::GlobalDeclarations vector.

Elements were added to this vector, but never inspected, so it is
essentially a useless field.  Plus, the removal allows us to remove a
couple of friend declarations.

BUG=none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/814163004

9 years agoSubzero: Add locking to prepare for multithreaded translation.
Jim Stichnoth [Tue, 20 Jan 2015 20:52:51 +0000 (12:52 -0800)]
Subzero: Add locking to prepare for multithreaded translation.

This just gets the locking in place.  Actual multithreading will be added later.

Mutexes are added for accessing the GlobalContext allocator, the constant pool, the stats data, and the profiling timers.  These are managed via the LockedPtr<> helper.  Finer grain locks on the constant pool may be added later, i.e. a separate lock for each data type.

An vector of pointers to TLS objects is added to GlobalContext.  Each new thread will get its own TLS object, whose address is added to the vector.  (After threads complete, things like stats can be combined by iterating over the vector.)

The dump/emit streams are guarded by a separate lock, to avoid fine-grain interleaving of output by multiple threads.  E.g., lock the streams, emit an entire function, and unlock the streams.  This works for dumping too, though dump output for different passes on the same function may be interleaved with that of another thread.  There is an OstreamLocker helper class to keep this simple.

CodeStats is made an inner class of GlobalContext (this was missed on a previous CL).

BUG= none
R=jfb@chromium.org, jvoung@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/848193003

9 years agoAdd instruction alignment tests to unit tests.
Karl Schimpf [Tue, 20 Jan 2015 20:19:15 +0000 (12:19 -0800)]
Add instruction alignment tests to unit tests.

BUG=None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/848473002

9 years agoSubzero: Remove the IceV_RegManager enum value.
Jim Stichnoth [Thu, 15 Jan 2015 17:05:08 +0000 (09:05 -0800)]
Subzero: Remove the IceV_RegManager enum value.

This hasn't been used in a very long time, and there's no intention of using it again.

Originally there was the idea of a "fast" block-local register allocator for an O1-like configuration, which would allocate registers for infinite-weight temporaries during target lowering, using a "local register manager".  This verbose option was for tracing execution of this register manager.  However, by now it seems unlikely that this would do a better/faster job than the current Om1 register allocation approach, which reuses the linear-scan code quite effectively and does very well at separation of concerns.  So adios IceV_RegManager!

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/831663008

9 years agoStart writing out some relocation sections (text).
Jan Voung [Tue, 13 Jan 2015 01:00:22 +0000 (17:00 -0800)]
Start writing out some relocation sections (text).

Pass the full assembler pointer to the elf writer, so
that it has access to both the text buffer and the fixups.

Remove some child classes of AssemblerFixups. They didn't
really do much, and were pretty much identical to the
original AssemblerFixup class. Dart had a virtual method
for fixups to do necessary patching, but we currently
don't do the patching and just emit the relocations.
TODO see if patching is more efficient than writing out
relocations and letting the linker do the work.

This CL also makes AssemblerFixups POD.

Change the fixup kind to be a plain unsigned int, which
the target can fill w/ target/container-specific values.

Move the fwd declaration of Assembler to IceDefs and remove
the others. Do similar for fwd declaration refactoring for
ELFWriter.

Make the createAssembler method return a std::unique_ptr.

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/828873002

9 years agoSubzero: Use SmallVector<> instead of vector<> in a couple places.
Jim Stichnoth [Mon, 12 Jan 2015 17:00:50 +0000 (09:00 -0800)]
Subzero: Use SmallVector<> instead of vector<> in a couple places.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/848603002

9 years agoSubzero: Update the lowering documentation.
Jim Stichnoth [Mon, 12 Jan 2015 16:59:21 +0000 (08:59 -0800)]
Subzero: Update the lowering documentation.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/846763002

9 years agoMake fixups reference any constant (allow const float/double pool literals).
Jan Voung [Fri, 9 Jan 2015 22:57:32 +0000 (14:57 -0800)]
Make fixups reference any constant (allow const float/double pool literals).

This avoids doing getConstantSym to avoid hitting the global
context's getConstantSym during emitIAS(), which may be desirable for
multi-threading, since each function's emitIAS() should be able to happen
on a separate thread.

The stringification is moved till later, so it still happens, just without
creating a constant relocatable w/ offset of 0.

This ends up tickling an issue where -O0 on 252.eon now gets 2x as many
page faults, and I'm not sure exactly why. This makes the overall time
higher, though emit time is lower.

When translating with -O2 # of page faults is about the same before/after,
so that oddness is restricted to O0.

Before this change, tweaking the slab size at O0 doesn't
seem to affect as drastically as 2x swings either.

To work around this, I turned the slab size of the assembler down to 32KB.

===

Move all the .L$type$poolid into a function (replacing getPoolEntryID).

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/837553009

9 years agoAdd ability to test parsing of bitcode records in Subzero.
Karl Schimpf [Fri, 9 Jan 2015 21:04:13 +0000 (13:04 -0800)]
Add ability to test parsing of bitcode records in Subzero.

Extends the NaCl bitcode munger so that the PNaClTranslator parser
can be applied to the defined sequence of record values.

BUG=None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/800883006

9 years agoSubzero: Write float/double constant pools directly to the ELF file.
Jan Voung [Fri, 9 Jan 2015 21:01:42 +0000 (13:01 -0800)]
Subzero: Write float/double constant pools directly to the ELF file.

Create the section, write the data and define the symbols in
the symbol table.

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/837393005

9 years agoSubzero: Clean up a few areas.
Jim Stichnoth [Fri, 9 Jan 2015 19:43:26 +0000 (11:43 -0800)]
Subzero: Clean up a few areas.

1. Use a reverse_range() adaptor for range-based reverse iteration through containers.

2. Remove the emitting of the commented llvm-mc command line.

3. Remove a few TODOs.

4. For commented-out declarations within a class T like this:
   // T(const T&) = delete;
   // T &operator=(const T &) = delete;
Replace them with this:
   T(const T&) = default;
   T &operator=(const T &) = default;
And try to keep them private where possible.

5. Make LivenessNode and TimerTreeNode into internal classes.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/830303003

9 years agoRemove isPooled virtual method from IceOperand.
Jan Voung [Fri, 9 Jan 2015 18:15:43 +0000 (10:15 -0800)]
Remove isPooled virtual method from IceOperand.

It doesn't seem to be used?

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/840343002

9 years agoSubzero: Use the CfgLocalAllocator for more vector types.
Jim Stichnoth [Fri, 9 Jan 2015 00:56:49 +0000 (16:56 -0800)]
Subzero: Use the CfgLocalAllocator for more vector types.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/812023003

9 years agoSubzero: Use range-based for loops with llvm::ilist<Inst> lists.
Jim Stichnoth [Tue, 23 Dec 2014 20:26:24 +0000 (12:26 -0800)]
Subzero: Use range-based for loops with llvm::ilist<Inst> lists.

This reestablishes C++11 features lost after switching to llvm::ilist<> in two previous CLs:
https://codereview.chromium.org/709533002/
https://codereview.chromium.org/794923002/

BUG= none
R=jfb@chromium.org, jvoung@chromium.org

Review URL: https://codereview.chromium.org/819403002

9 years agoSubzero: Convert NULL->nullptr.
Jim Stichnoth [Sat, 20 Dec 2014 14:17:49 +0000 (06:17 -0800)]
Subzero: Convert NULL->nullptr.

This is limited to the src directory, and not (yet) the crosstest directory.

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/814353002

9 years agoSubzero: Use CFG-local arena allocation for relevant containers.
Jim Stichnoth [Fri, 19 Dec 2014 20:51:35 +0000 (12:51 -0800)]
Subzero: Use CFG-local arena allocation for relevant containers.

In particular, node lists for in and out edges of a CfgNode, and the live range segment list in a Variable.  This is done by making the Cfg allocator globally available through TLS, and providing the STL containers with an allocator struct that uses this.

This also cleans up some other allocation-related issues:

* The allocator is now hung off the Cfg via a pointer, rather than being embedded into the Cfg.  This allows a const Cfg pointer to be stored in TLS while still allowing its allocator to be mutated.

* Cfg is now created via a static create() method.

* The redundant Cfg::allocateInst<> methods are removed.

* The Variable::asType() method allocates a whole new Variable from the Cfg arena, rather than allocating it on the stack, removing the need for the move constructor in Variable and Operand.  This is OK since asType() is only used for textual asm emission.

* The same 1MB arena allocator is now used by the assembler as well.  The fact that it wasn't changed over to be the same as Cfg and GlobalContext was an oversight.  (It turns out this adds ~3MB to the translator memory footprint, so that could be tuned later.)

BUG= none
R=jfb@chromium.org, jvoung@chromium.org

Review URL: https://codereview.chromium.org/802183004

9 years agoSubzero: Randomize register assignment.
Jim Stichnoth [Fri, 19 Dec 2014 13:42:24 +0000 (05:42 -0800)]
Subzero: Randomize register assignment.

Randomize the order that registers appear in the free list.  Only
randomize fully "equivalent" registers to ensure no extra spills.

This adds the -randomize-regalloc option.

This is a continuation of https://codereview.chromium.org/456033003/ which Matt owns.

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/807293003

9 years agoRemove TypeConverter and Module from minimal subzero build.
Karl Schimpf [Mon, 15 Dec 2014 21:45:00 +0000 (13:45 -0800)]
Remove TypeConverter and Module from minimal subzero build.

Removes the need to model LLVM types from the minimal subzero build.
It isn't removed from the nonminimal build because IceConverter still needs
to be able to convert LLVM types to corresponding Ice types.

Note that this CL reduces the size of Release+Min/llvm2ice (after
strip) to about 638K bytes.

BUG=None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/805943002

9 years agoRemove using LLVM tools to check correctness of cast operation.
Karl Schimpf [Mon, 15 Dec 2014 18:16:31 +0000 (10:16 -0800)]
Remove using LLVM tools to check correctness of cast operation.

Removes cast instruction checks (in PNaClTranslator.cpp) that used
LLVM utilities to use locally defined methods instead. Remove the need
to call naclbitc::DecodeCastOpcode and CastInst::castIsValid.

Also removes two more calls to convertToLLVMType.

BUG= None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/794823002

9 years agoSubzero: Clean up live range construction.
Jim Stichnoth [Mon, 15 Dec 2014 17:58:51 +0000 (09:58 -0800)]
Subzero: Clean up live range construction.

Moves the deletion of newly dead instructions into the main liveness() routine.  The old livenessPostProcess() routine is renamed and now used purely for live range construction.

The hack is removed in which live in-args have a custom live range segment added to avoid an artifact of the live ranges.  It is replaced with a gentler hack that extends the instruction numbering range of the initial basic block to avoid the artifact.

Since special live range segments no longer need to be prepended, the live range representation is simplified and we can always assume that segments are being appended, never prepended (and as before, never added to the middle).

Some magic constants involving special instruction numbers are replaced with symbolic constants.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/802003003

9 years agoSimplify LLVM's APInt and APFloat for use in Subzero.
Karl Schimpf [Mon, 15 Dec 2014 17:52:26 +0000 (09:52 -0800)]
Simplify LLVM's APInt and APFloat for use in Subzero.

In Subzero, we only need to be able to convert 64 bit constants in
bitcode files to the corresponding Ice integer or floating type. This
CL extracts the minimal implementation needed for Subzero. The intent
of this change is to remove loading unnecessary LLVM code into
(minimal) llvm2ice.

BUG=None
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/797323002

9 years agoSubzero: Don't store std::string objects inside Variable.
Jim Stichnoth [Thu, 11 Dec 2014 23:51:42 +0000 (15:51 -0800)]
Subzero: Don't store std::string objects inside Variable.

Instead, extend 668a7a333d6ddc3102b5b7c7c07448f6d259113c to include both CfgNode and Variable, keeping a pool of strings in the Cfg.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/798693003

9 years agoSubzero: Add memory usage to "-szstats" output.
Jim Stichnoth [Thu, 11 Dec 2014 18:04:32 +0000 (10:04 -0800)]
Subzero: Add memory usage to "-szstats" output.

Requires the LLVM option -track-memory to get meaningful results.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/795063003

9 years agoSubzero: Use llvm::ilist<> for PhiList and AssignList.
Jim Stichnoth [Thu, 11 Dec 2014 17:22:45 +0000 (09:22 -0800)]
Subzero: Use llvm::ilist<> for PhiList and AssignList.

This is toward the goal of pulling non-POD fields out of the CfgNode
class so that CfgNode can be arena-allocated and not leak memory.

For now, PhiList and AssignList are defined as InstList.  Ideally,
they would be ilist<> of InstPhi and InstAssign, but SFINAE happens.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/794923002

9 years agoSubzero: Pull the node name out of the node structure.
Jim Stichnoth [Wed, 10 Dec 2014 23:32:25 +0000 (15:32 -0800)]
Subzero: Pull the node name out of the node structure.

Instead, non-empty node names are kept in a single vector in the Cfg
object.

This is toward the goal of pulling non-POD fields out of the CfgNode
class so that CfgNode can be arena-allocated and not leak memory.

Also, actual setting of the node name is now guarded by ALLOW_DUMP.

BUG= none
R=jvoung@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/787333005

9 years agoReduce one layer of decoding for binary operations in bitcode reading.
Karl Schimpf [Wed, 10 Dec 2014 20:54:34 +0000 (12:54 -0800)]
Reduce one layer of decoding for binary operations in bitcode reading.

Removes the need to call function llvm::DecodeBinaryOp. In turn, this removes
the need for enum type llvm::Instruction::BinaryOps, llvm::Type.isFPOrFPVectorTy, and one call to llvm::convertToLLVMType.

BUG= None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/788283002

9 years agoRemove call to PNaClABIProps::isAllowedAlignment from subzero.
Karl Schimpf [Tue, 9 Dec 2014 21:50:07 +0000 (13:50 -0800)]
Remove call to PNaClABIProps::isAllowedAlignment from subzero.

Also removes the need for DataLayout.

BUG=None
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/789483003

9 years agoSubzero: Disable stats and timers under the MINIMAL build.
Jim Stichnoth [Mon, 8 Dec 2014 22:57:52 +0000 (14:57 -0800)]
Subzero: Disable stats and timers under the MINIMAL build.

Specifically, don't bother to collect "-timing" and "-szstats" information since they anyway don't get printed out under the MINIMAL build.  This is done by using the ALLOW_DUMP flag to guard whether code and timing stats are collected.  This ends up reducing the native translator size by about 3%.  ALLOW_DUMP is used as the guard since it already guards the output of the collected data - no sense collecting the data if it can never be printed out.

To minimize the number of ALLOW_DUMP tests, we push the tests into the timing/stats class methods.

BUG= none
R=jvoung@chromium.org, kschimpf@google.com

Review URL: https://codereview.chromium.org/788713002

9 years agoSubzero: Build with function/data sections and -gc-sections.
Jim Stichnoth [Sun, 7 Dec 2014 22:25:34 +0000 (14:25 -0800)]
Subzero: Build with function/data sections and -gc-sections.

This is consistent with how LLVM is built, and makes it easier to analyze the potential size of a translator build and what may be inappropriately brought into the build.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/783023002

9 years agoSubzero: Improve performance by using llvm::SmallVector<>.
Jim Stichnoth [Sat, 6 Dec 2014 00:43:08 +0000 (16:43 -0800)]
Subzero: Improve performance by using llvm::SmallVector<>.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/775953003

9 years agoSubzero: Disable asserts in the MINIMAL build.
Jim Stichnoth [Fri, 5 Dec 2014 22:16:07 +0000 (14:16 -0800)]
Subzero: Disable asserts in the MINIMAL build.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/785583002

9 years agoSubzero: Fix the g++ build (e.g. Windows).
Jim Stichnoth [Thu, 4 Dec 2014 22:09:21 +0000 (14:09 -0800)]
Subzero: Fix the g++ build (e.g. Windows).

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4006
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/773583004

9 years agoSubzero: Use std::vector<> instead of std::list for live range segments.
Jim Stichnoth [Thu, 4 Dec 2014 19:45:03 +0000 (11:45 -0800)]
Subzero: Use std::vector<> instead of std::list for live range segments.

This generally uses less memory and fewer allocations.

Also removes the commented-out alternative implementation using std::set<>, which would almost certainly never be a good idea here.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/734053006

9 years agoSubzero: Add llvm-readobj to lit.cfg.
Jim Stichnoth [Thu, 4 Dec 2014 17:11:48 +0000 (09:11 -0800)]
Subzero: Add llvm-readobj to lit.cfg.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/780783003

9 years agoSubzero: Improve the memory-related performance of the register allocator.
Jim Stichnoth [Thu, 4 Dec 2014 04:30:34 +0000 (20:30 -0800)]
Subzero: Improve the memory-related performance of the register allocator.

Profiling indicated a noticeable amount of time spent on malloc/free related to the std::list<> implementation of UnorderedRanges.  Therefore, we change the implementation to be std::vector<>, and up-front reserve a conservative amount of space to avoid expansion.  The push_back() operation is always constant time with no allocation.  Removing an element from the middle of the vector is done by swapping with the last element and then popping the last element, which is reasonable in principle because it is used as an unordered collection.  Because of the swapping trick, the UnorderedRanges iterators are changed to iterate in reverse.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/781683002

9 years agoTry to fix mismatch between writeELFHeaderInternal def and decl.
Jan Voung [Wed, 3 Dec 2014 23:51:22 +0000 (15:51 -0800)]
Try to fix mismatch between writeELFHeaderInternal def and decl.

BUG=build failure
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/773853005

9 years agoFix PNaCl bitcode to LLVM IR reader to match new API.
Karl Schimpf [Wed, 3 Dec 2014 22:49:53 +0000 (14:49 -0800)]
Fix PNaCl bitcode to LLVM IR reader to match new API.

When LLVM 3.5 was merged, the handling of errors was broken. This
is being fixed in the CL listed below. This CL fixes Subzero's
call so that it will work with the CL listed below.

Relavant LLVM CL: https://codereview.chromium.org/770853002

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4006
R=jfb@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/775173002

9 years agoSubzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers).
Jan Voung [Tue, 2 Dec 2014 01:55:16 +0000 (17:55 -0800)]
Subzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers).

Able to write out the ELF file header w/ a text section,
a symbol table, and string table. Write text buffer
directly to file after translating each CFG.
This means that the header is written out early w/ fake
data and then we seek back and write the real header
at the very end.

Does not yet handle relocations, data, rodata, constant
pools, bss, or -ffunction-sections, more than 64K sections
or more than 2^24 symbols.

Numbers w/ current NOASSERT=1 build on 176.gcc:

w/out -elf-writer:
    0.233771 (21.1%): [ 1287] emit
    28MB .s file

w/ -elf-writer:
    0.051056 ( 5.6%): [ 1287] emit
    2.4MB .o file

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/678533005

9 years agoCreate local config file for subzero reader tests.
Karl Schimpf [Mon, 1 Dec 2014 21:39:00 +0000 (13:39 -0800)]
Create local config file for subzero reader tests.

Using lit.local.cfg, don't allow reader tests unless dumping
of IR is allowed.

This was suggested by Jan in: https://codereview.chromium.org/686913005

BUG=None
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/735513002

9 years agoSubzero: Fix a bug in postLower().
Jim Stichnoth [Mon, 1 Dec 2014 17:30:55 +0000 (09:30 -0800)]
Subzero: Fix a bug in postLower().

In -O2 mode, postLower() is supposed to iterate over just the
instructions that were most recently added.  Instead, it was iterating
all the way to the end of the block, also post-lowering high-level ICE
instructions that hadn't yet been lowered.  This was basically
harmless, given that the spec2k asm code is identical after this
patch, but it improves performance.

BUG= none
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/721333004

9 years agoSubzero: Improve malloc/free behavior.
Jim Stichnoth [Wed, 26 Nov 2014 22:11:53 +0000 (14:11 -0800)]
Subzero: Improve malloc/free behavior.

Use a bigger block size in the bump-pointer allocators, since we
basically know up front that we'll need lots of memory.  The 1MB value
(versus the default of 4KB) was chosen somewhat arbitrarily, and
succeeds in pretty much removing bump-pointer related mallocs from the
profile.

Pre-reserve the a priori known number of edges in getTerminatorEdges()
to avoid vector resizing.

BUG= none
R=kschimpf@google.com

Review URL: https://codereview.chromium.org/760973002

9 years agoSubzero: Fix new issues after the LLVM 3.5 merge.
Jim Stichnoth [Mon, 24 Nov 2014 22:36:23 +0000 (14:36 -0800)]
Subzero: Fix new issues after the LLVM 3.5 merge.

We need to link with -lpthread now.

The CALLTARGETS workaround in our lit tests can be removed, since llvm-objdump has gotten more accurate than before with respect to symbols.

The -stats and -rng-seed options need to be renamed to avoid conflicting with the LLVM options being brought in.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3930
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/756543002

9 years agoMerge remote-tracking branch 'origin/merge_35'
JF Bastien [Fri, 21 Nov 2014 18:02:17 +0000 (10:02 -0800)]
Merge remote-tracking branch 'origin/merge_35'

R=stichnot@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3930

Review URL: https://codereview.chromium.org/752603003