OSDN Git Service

android-x86/external-swiftshader.git
8 years agoSubzero: Crosstest test_arith properly tests i8/i16.
Jim Stichnoth [Tue, 31 May 2016 19:21:51 +0000 (12:21 -0700)]
Subzero: Crosstest test_arith properly tests i8/i16.

The problem is that because of C++ integral promotion rules, many of the i8 and i16 arithmetic tests were actually being performed as i32 operations.  Thus we weren't actually testing everything we meant to test.

The fix is to have a python script auto-generate the relevant tests with proper typing.

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

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

8 years agoRemoved an extraneous tab
Thomas Lively [Tue, 31 May 2016 18:44:22 +0000 (11:44 -0700)]
Removed an extraneous tab

BUG=None
R=kschimpf@google.com

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

8 years ago- This patch implements lowerstore for i32, i64 types for mips32 arch.
Mohit Bhakkad [Tue, 31 May 2016 18:19:03 +0000 (11:19 -0700)]
- This patch implements lowerstore for i32, i64 types for mips32 arch.

- InstMIPS32Memory class is added to represent memory related instructions(load/store). I will add remaining load/store instructions if you are okay with this patch.

- Changed uncond_br.ll test as it was failing due to hardcoded label no. expected in output.

R=jpp@chromium.org, stichnot@chromium.org

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

Patch from Mohit Bhakkad <mohit.bhakkad@imgtec.com>.

8 years ago[Subzero][MIPS32] Implement i1 cast operations
Sagar Thakur [Mon, 30 May 2016 14:54:47 +0000 (07:54 -0700)]
[Subzero][MIPS32] Implement i1 cast operations

R=stichnot@chromium.org

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

Patch from Sagar Thakur <sagar.thakur@imgtec.com>.

8 years agoSubzero, MIPS32: Introduction of floating point registers
Srdjan Obucina [Fri, 27 May 2016 21:40:32 +0000 (14:40 -0700)]
Subzero, MIPS32: Introduction of floating point registers

This patch introduces floating point registers used for 32-bit
operations, and basic handling of FP values in operands. It is
partial work needed as a base for further work.

R=stichnot@chromium.org

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

Patch from Srdjan Obucina <Srdjan.Obucina@imgtec.com>.

8 years agoSubzero: Initial implementation of BB Local CSE
Manasij Mukherjee [Tue, 24 May 2016 21:25:04 +0000 (14:25 -0700)]
Subzero: Initial implementation of BB Local CSE

Adds Cfg::localCse for basic-block local common-subexpression elimination
If we have
    t1 = op b c
    t2 = op b c
This pass will replace future uses of t2 in a basic block by t1.

To enable, use -enable-experimental in O2

BUG=none
R=stichnot@chromium.org

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

8 years agoAdded bool folding machinery for MIPS32.
Sagar Thakur [Tue, 24 May 2016 13:25:50 +0000 (06:25 -0700)]
Added bool folding machinery for MIPS32.
Added implementation for conditional branch instructions.

R=jpp@chromium.org, stichnot@chromium.org

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

Patch from Sagar Thakur <sagar.thakur@imgtec.com>.

8 years agoSubzero, MIPS32: Implements integer division instructions sdiv, udiv, srem, urem
Srdjan Obucina [Wed, 18 May 2016 18:31:15 +0000 (11:31 -0700)]
Subzero, MIPS32: Implements integer division instructions sdiv, udiv, srem, urem

This patch adds support for missing integer division instruction sdiv, udiv, srem, urem.

R=stichnot@chromium.org

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

Patch from Srdjan Obucina <Srdjan.Obucina@imgtec.com>.

8 years agoSubzero, MIPS32: Implement logical instructions ashr, lshr, shl
Srdjan Obucina [Tue, 17 May 2016 20:16:02 +0000 (13:16 -0700)]
Subzero, MIPS32: Implement logical instructions ashr, lshr, shl

This patch adds support for logical operations ashr, lshr and shl.

R=stichnot@chromium.org

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

Patch from Srdjan Obucina <Srdjan.Obucina@imgtec.com>.

8 years agoRemove compiler warning when building within LLVM trunk.
Karl Schimpf [Thu, 12 May 2016 17:12:23 +0000 (10:12 -0700)]
Remove compiler warning when building within LLVM trunk.

Clang doesn't realize that the end of method
NaClBitstreamCursor::readArrayAbbreviatedField is unreachable. Add
unreachable call to make the compiler happy.

BUG=None
R=stichnot@chromium.org

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

8 years agoSubzero: Add necessary PNaCl files for standalone build.
Jim Stichnoth [Tue, 10 May 2016 18:20:41 +0000 (11:20 -0700)]
Subzero: Add necessary PNaCl files for standalone build.

The README.txt file is new; all other files under pnacl-llvm/ are copied verbatim from the pnacl-llvm repo.

BUG= none
R=kschimpf@google.com

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

8 years agoSubzero: Update for LLVM 3.9 (trunk).
Jim Stichnoth [Mon, 9 May 2016 19:24:36 +0000 (12:24 -0700)]
Subzero: Update for LLVM 3.9 (trunk).

The purpose is to allow pnacl-sz to be built within an LLVM checkout (version 3.9 or later), and not require the complex PNaCl build environment.

Within an LLVM checkout, one would do something like the following:
  cd projects
  git clone https://chromium.googlesource.com/native_client/pnacl-subzero
  # change to LLVM build directory
  cmake -G "Ninja" <path_to_llvm_source_dir>
  ninja

A follow-on CL will add in the PNaCl bitcode reader source files that are needed for compiling and linking.

BUG= none
R=jpp@chromium.org

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

8 years ago[Subzero][MIPS32] Implement sext, zext and trunc
Sagar Thakur [Mon, 9 May 2016 18:57:59 +0000 (11:57 -0700)]
[Subzero][MIPS32] Implement sext, zext and trunc

This patch adds support for sext, zext, trunc operations on i8, i16, i32 source operand types. Support for i1 source operand type will follow.

R=stichnot@chromium.org

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

Patch from Sagar Thakur <sagar.thakur@imgtec.com>.

8 years agoSubzero WASM: avoid needless comparisons, add bounds check flag option
Eric Holk [Fri, 6 May 2016 21:28:04 +0000 (14:28 -0700)]
Subzero WASM: avoid needless comparisons, add bounds check flag option

Introduces a new BooleanVariable type which represents zero-extended
variables generated from an i1, saving a pointer to the original
i1. The Wasm frontend uses this to avoid comparing against 0 if
possible when translating branches. This led to about a 12%
improvement on the bzip2 spec benchmark.

This change also adds the -wasm-disable-bounds-check command line
option which omits bounds checking code.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4369
R=stichnot@chromium.org

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

8 years agoSubzero: Suppress a warning as a result of an updated clang.
Jim Stichnoth [Mon, 2 May 2016 19:06:22 +0000 (12:06 -0700)]
Subzero: Suppress a warning as a result of an updated clang.

Also improve some diagnostic output in the Makefile.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero, WASM: stop writing uninitialized data to .o file. Add timers.
Eric Holk [Mon, 2 May 2016 17:42:27 +0000 (10:42 -0700)]
Subzero, WASM: stop writing uninitialized data to .o file. Add timers.

Previously we were writing large numbers of zeros to the output
file. This change only writes out the initialized portion and
allocates the full address space at runtime. This reduces compile time
by around 50%.

This change also adds a couple of WASM-specific timers.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4369
R=jpp@chromium.org, stichnot@chromium.org

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

8 years agoSubzero, Wasm: Dynamically reallocate read buffer. Runtime improvements.
Eric Holk [Fri, 29 Apr 2016 21:42:17 +0000 (14:42 -0700)]
Subzero, Wasm: Dynamically reallocate read buffer. Runtime improvements.

This change fills in several more runtime functions needed by several
benchmarks, as well as changing the buffer handling in the WASM
decoder. Now the decoder will resize the buffer as needed to
accomodate large .wasm modules.

Tracing can now be enabled on runtime functions to aid with
debugging. Additionally, runtime failures such as bounds check
failures or invalid indirect function calls tell what kind of failure
occured.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4369
R=jpp@chromium.org, stichnot@chromium.org

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

8 years agoSubzero. X86. Uses pshufb for shufflevector lowering.
John Porto [Wed, 27 Apr 2016 02:16:07 +0000 (19:16 -0700)]
Subzero. X86. Uses pshufb for shufflevector lowering.

This CL enables subzero to lower shufflevector instructions in x86 using
pshufb (only for SSE 4.1)

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4136
BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4077
R=stichnot@chromium.org

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

8 years agoSubzero. X86. Lowers shufflevector using xmm instructions.
John Porto [Tue, 26 Apr 2016 11:26:33 +0000 (04:26 -0700)]
Subzero. X86. Lowers shufflevector using xmm instructions.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4136
R=stichnot@chromium.org

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

8 years agoSubzero. Wasm. Implement sbrk and correctly do bounds checks.
Eric Holk [Mon, 25 Apr 2016 19:52:49 +0000 (12:52 -0700)]
Subzero. Wasm. Implement sbrk and correctly do bounds checks.

Cleans up and generally improves memory handling in
WASM. WasmTranslator now outputs the number of pages requested so the
runtime can do correct bounds checks. The runtime also initializes the
stack pointer correctly (stored at address 1024), so we no longer have
to deal with negative pointers. This allows bounds checks to be done
with a single comparison against the size of the heap. Because of
this, we now support non-power-of-two heap sizes.

Sbrk is implemented by having the runtime keep track of the current
heap break and incrementing it as necessary. The heap break is
initialized to the start of the first page beyond any initialized data
in the WASM heap.

These changes allow us to pass the complete set of torture tests that
are passing on the Wasm waterfall.

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

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

8 years ago[Subzero][MIPS] Implement conditional branches and integer comparisons
Sagar Thakur [Mon, 25 Apr 2016 15:39:19 +0000 (08:39 -0700)]
[Subzero][MIPS] Implement conditional branches and integer comparisons

R=stichnot@chromium.org

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

Patch from Sagar Thakur <sagar.thakur@imgtec.com>.

8 years agoSubzero - WASM: Codegen fixes, better test infrastructure
Eric Holk [Fri, 22 Apr 2016 16:34:41 +0000 (09:34 -0700)]
Subzero - WASM: Codegen fixes, better test infrastructure

Fixes several bugs in code generation, including handling of booleans,
comparisons and shifts. The tests that get through code generation now
run successfully (except for the tests that are known to fail on
https://wasm-stat.us/).

This change also includes improvements to the test infrastructure. The
wasm test runner has a list of expected failures to skip. The tests
now run in parallel, which significantly cuts down the time to run the
whole test suite.

Finally, there are some minor improvements to the WASM runtime,
including an implementation of syscall20, i.e. getpid().

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

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

8 years agoSubzero: Provide missing isMemoryWrite() method.
Jim Stichnoth [Fri, 22 Apr 2016 00:57:56 +0000 (17:57 -0700)]
Subzero: Provide missing isMemoryWrite() method.

This is the result of an improper rebase in the previous CL.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero: Fix over-aggressive bool folding.
Jim Stichnoth [Thu, 21 Apr 2016 23:54:33 +0000 (16:54 -0700)]
Subzero: Fix over-aggressive bool folding.

The problem is that bitcode like this:

  %cond = cmp %var, [mem]
  store ..., mem
  br cond, target1, target2

would be bool-folded into this:

  //deleted cmp
  store ..., mem
  br (%var==[mem]), target1, target2

And if the memory operands point to the same location, results are incorrect.

In addition to stores, this is a problem for RMW instructions, and most call instructions which could perform stores before returning.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4370
R=eholk@chromium.org, jpp@chromium.org

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

8 years agoSubzero. Rematerializes shufflevector instructions.
John Porto [Thu, 21 Apr 2016 12:53:42 +0000 (05:53 -0700)]
Subzero. Rematerializes shufflevector instructions.

This CL is a first step towards optimizing vector shuffles in
Subzero.

PNaCl bitcode does not support the shufflevector instruction,
so pnacl-clang emits a series of extractelement/insertelement.
pnacl-llc is then responsible for performing a pattern match
on the output bitcode and rematerialize the shufflevector.

With this CL, we enable shufflevector rematerialization in
Subzero. To keep this CL simple, we introduce no efficient
shufflevector lowering. Instead, we scalarize the
rematerialized instructions.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4136
R=stichnot@chromium.org

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

8 years agoSubzero: Fix a warning message in the browser build.
Jim Stichnoth [Thu, 21 Apr 2016 12:38:49 +0000 (05:38 -0700)]
Subzero: Fix a warning message in the browser build.

Due to a mistake in the logic in https://codereview.chromium.org/1903553004 , a warning is printed even when LogFilename is properly set to "-".

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4370
R=jpp@chromium.org

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

8 years agoSubzero: Fix srem.i8/urem.i8 lowering for x86-64.
Jim Stichnoth [Thu, 21 Apr 2016 12:38:15 +0000 (05:38 -0700)]
Subzero: Fix srem.i8/urem.i8 lowering for x86-64.

The problem was that the lowering sequence might lead to the rem result %ah being directly moved into an 8-bit register other than al/bl/cl/dl/ah/bh/ch/dh.  This is not encodable, and attempting to encode it leads to actually moving from %spl instead of %ah.

The machinery to handle this was already available - copy through a temporary with register class RCX86_IsAhRcvr.  So this was just a matter of hooking it up for srem/urem.

This CL also requires relaxing some checks in the register allocator for when the -reg-reserve option is used.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4370
R=jpp@chromium.org

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

8 years agoSubzero: Allow overriding command-line args from the browser.
Jim Stichnoth [Wed, 20 Apr 2016 17:12:46 +0000 (10:12 -0700)]
Subzero: Allow overriding command-line args from the browser.

In the browser build only, allows arguments to be explicitly passed to pnacl-sz, in two ways:

1. The SZARGFILE envvar contains the name of a file with arguments, one per line.  For each line, initial whitespace is ignored, and lines starting with the '#' comment character are also ignored.

2. The SZARGLIST envvar contains all the arguments, separated by the '|' character.

Chrome needs to be started with special options to allow the envvars to be passed through, and also to allow access to the local file system.

In addition, specifying "-log=/dev/stderr" or "-o /dev/stderr" gets mapped to std::cerr, in the same way "-" gets mapped to std::cout.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4370
R=jpp@chromium.org

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

8 years agoAdded definition of ALLOW_WASM to CMakeLists.
Sean Klein [Tue, 19 Apr 2016 17:53:10 +0000 (10:53 -0700)]
Added definition of ALLOW_WASM to CMakeLists.

This change is required to run "toolchain_build_pnacl.py --cmake", since
without it, ALLOW_WASM will be undefined and throw a compilation error.

BUG=None
R=eholk@chromium.org

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

8 years agoSubzero. ARM32. De-scalarizes icmp and fcmp for vectors.
John Porto [Mon, 18 Apr 2016 22:32:27 +0000 (15:32 -0700)]
Subzero. ARM32. De-scalarizes icmp and fcmp for vectors.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4076
R=eholk@chromium.org, stichnot@chromium.org

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

8 years agoSubzero, Wasm: Link and run torture tests; bug fixes.
Eric Holk [Mon, 18 Apr 2016 22:08:19 +0000 (15:08 -0700)]
Subzero, Wasm: Link and run torture tests; bug fixes.

This modifies the torture test script to actually link and run the
tests in addition to just translating them.

It includes a number of bug fixes as well, particularly in the
handling of boolean values. There is some cleanup of memory address
handling, and in many cases it can avoid generating useless address
computations.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4369
R=jpp@chromium.org

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

8 years agoSubzero: Allow per-method controls.
Jim Stichnoth [Mon, 18 Apr 2016 19:52:09 +0000 (12:52 -0700)]
Subzero: Allow per-method controls.

Several aspects of compilation can now be controlled with fine per-function granularity:

- Focus -timing on individual functions
- Only translate certain functions
- Enable verbosity only for certain functions
- Force O2 translation for certain functions (with Om1 default)

In addition, -test-status limits the output of -verbose=status.  This is just used to enable lit testing of the RangeSpec class.

The main motivation here is to enable bisection debugging of a PNaCl application running in the browser.  The initial use is to control O2 versus Om1, and could be extended to control things like address mode inference and advanced phi lowering, possibly even controlling at the granularity of the instruction numbers.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4370
R=eholk@chromium.org, jpp@chromium.org

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

8 years agoSubzero. WASM. Additional progress.
Eric Holk [Fri, 15 Apr 2016 20:05:37 +0000 (13:05 -0700)]
Subzero. WASM. Additional progress.

This change includes a number of improvements since the last WASM
CL. It compiles against a newer version of V8 that matches the current
WASM binary format. Many more WASM instructions are supported, as well
as global variable initializers.

There is also the beginning of a runtime library that implements some
system calls required by the WASM C library. The c2wasm-exe.sh script
can be used to compile a C program to a .wasm module, which is then
compiled by Subzero into a native executable.

This change includes a new Breakpoint instruction, which inserts an
unconditional breakpoint into the executable. This has been helpful in
debugging code generation for some WASM instructions. The Breakpoint
instruction is only completely implemented on X86.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4369
R=stichnot@chromium.org

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

8 years agoSubzero. ARM32. Implements vector select.
John Porto [Fri, 15 Apr 2016 13:26:58 +0000 (06:26 -0700)]
Subzero. ARM32. Implements vector select.

Also piggy-backs necro-comments from cl 1878943009.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4076
R=kschimpf@google.com

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

8 years agoSubzero. ARM32. Vector casts.
John Porto [Thu, 14 Apr 2016 18:51:38 +0000 (11:51 -0700)]
Subzero. ARM32. Vector casts.

This CL un-scalarizes all vector casts operations in Subzero.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4076
R=eholk@chromium.org

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

8 years agoSubzero. ARM32. Vector shifts.
John Porto [Wed, 13 Apr 2016 19:57:14 +0000 (12:57 -0700)]
Subzero. ARM32. Vector shifts.

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

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

8 years agoReduce wait times for very large PEXE files.
Karl Schimpf [Mon, 11 Apr 2016 21:49:01 +0000 (14:49 -0700)]
Reduce wait times for very large PEXE files.

Investigated how many parser waits occur when the OptQ fills up. The
current implementation has 64k entries, which for 10Mb examples, never
fill up (but do come close to filling up).

To test, I dropped the queue size down. The numbers I got was that the
queue size plus the number of parse waits was within 2% of the total
number of function blocks. Hence, once OptQ fills up a lot of slow
notifies get applied.

Hence, for scaling, I modifed the code to not wake up the parse thread
(during a pop) until OptQ got half empty. The results were that once
the Opt got up to size 1024, less than 100 notifies would be
issued. From 1024 on, as the queue size doubled, the number of
notifies would drop roughly in half.

Based on this, I decided to add the feature that the OptQ did not wake
up the waiting parse thread until half empty. Since the queue size was
not shrunk, this CL shouldn't add any overhead for the PEXES we have,
and very few waits with significantly largers than the current (10Mb)
PEXES.

BUG=None
R=jpp@chromium.org

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

8 years agoAdd "vmov.<dt> <Qd>, #<imm>" to integrated ARM assembler.
Karl Schimpf [Mon, 11 Apr 2016 21:32:15 +0000 (14:32 -0700)]
Add "vmov.<dt> <Qd>, #<imm>" to integrated ARM assembler.

Adds the VMOV instruction to the integrated assembler. Because #<imm> is
complex, and we don't currently have a special ARM class to encode
constants defined by ARM method AdvSIMDExpandImm(), it currently only
accepts (nonnegative) integer32 constants that can fit into 8 bits.

There are no tests for this instruction, since there currently no
callers to this instruction. However, John will be checking in a CL
shortly that will use this instruction.

Add example generator for vector add.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4334
R=jpp@chromium.org

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

8 years agoSubzero. ARM32. Fixes Insert/Extract v(8|16)i1 bug.
John Porto [Mon, 11 Apr 2016 18:33:34 +0000 (11:33 -0700)]
Subzero. ARM32. Fixes Insert/Extract v(8|16)i1 bug.

Subzero emits the following sequence when extracting elements from a
vector of i1:

vmov.8 Rt, Dm[I]

I should be scaled when accessing v4i1, and v8i1, i.e., to extract the
n-th boolean in a v8i1, the emitted code should be

vmov.8 Rt, Dm[I*n]

Insertions are handled by changing the operands' types, so that a
v4i1 is handled as a v4i32, and a v8i1, as a v8i16. I.e., to insert
the n-th boolean into a v8i1, the emitted code should be

mov.16 Dt[I], Rm

instead of

mov.8 Dt[I*n], Rm

This clears the upper bits for that element.

BUG=
R=eholk@chromium.org

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

8 years agoSubzero: Shorten and normalize strings in non-DUMP builds.
Jim Stichnoth [Sat, 9 Apr 2016 15:54:20 +0000 (08:54 -0700)]
Subzero: Shorten and normalize strings in non-DUMP builds.

Jump table labels change from ".Lxxxxx_yy" to "$Jxxxxx_yy".

Pooled float labels change from ".L$float$xxxxyyyy" to "$Fxxxxyyyy".

Pooled double labels change from ".L$double$xxxxxxxxyyyyyyyy" to "$Dxxxxxxxxyyyyyyyy".

All these should in theory not conflict with C/C++ user symbols.

Float labels now likely fit into short strings and don't require extra memory allocation.

Double labels may exceed the limit - encoding in base64 instead of hex would fix that.  Or, directly use the binary bytes as the string value.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero: Improve the -timing output.
Jim Stichnoth [Sat, 9 Apr 2016 00:09:29 +0000 (17:09 -0700)]
Subzero: Improve the -timing output.

For "Flat times" output, adds a column with cumulative percentage.  Also, since these percentages add up to less than 100% due to timer overhead, we go ahead and scale up all of the "Flat times" percentages proportionally, to make them add to 100%.  This makes it easier to compare breakdowns across different pexes.

Also, simplify the output to be simple tabular without extra brackets and whatnot.  E.g.:

Total across all functions - Cumulative times:
     Seconds   Pct  EventCnt TimerPath
    8.580407 82.6%         0 szmain
    8.580054 82.6%         0 szmain.parseModule
    8.405447 80.9%     46473 szmain.parseModule.parseFunctions
...
Total across all functions - Flat times:
     Seconds   Pct CumPct  EventCnt TimerName
    1.354678 16.0%  16.0%    100716 linearScan
    1.131292 13.3%  29.3%    139419 liveness
    0.728727  8.6%  37.9%     46473 genCode
...

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

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

8 years agoSubzero: Fix an incorrect StringPool assert.
Jim Stichnoth [Thu, 7 Apr 2016 14:17:35 +0000 (07:17 -0700)]
Subzero: Fix an incorrect StringPool assert.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero: Remove a couple clumsy uses of snprintf.
Jim Stichnoth [Wed, 6 Apr 2016 19:21:14 +0000 (12:21 -0700)]
Subzero: Remove a couple clumsy uses of snprintf.

We can use llvm::format() to achieve the same result in these cases.

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

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

8 years agoSubzero: Dump register numbers as signed quantities.
Jim Stichnoth [Wed, 6 Apr 2016 19:20:18 +0000 (12:20 -0700)]
Subzero: Dump register numbers as signed quantities.

Undo an overly aggression application of unsigned to register numbers in 8aa396610b7baf728631a43ea16ad3d13e38397a (https://codereview.chromium.org/1676123002).

Now, instead of -verbose=regalloc output like:

++++++ Unhandled:
R=jpp@chromium.org, kschimpf@google.com, 4294967295  V=%__4  Range=[2:7), 4294967295  V=%__5  Range=[7:8), 4294967295  V=%__6  Range=[9:11), -1  V=%__4  Range=[2:7), -1  V=%__5  Range=[7:8), -1  V=%__6  Range=[9:11)

we have the originally intended:

++++++ Unhandled:

BUG= none

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

8 years agoSubzero: Fix -timing-focus .
Jim Stichnoth [Wed, 6 Apr 2016 13:37:15 +0000 (06:37 -0700)]
Subzero: Fix -timing-focus .

The problem is that the default timer is renamed to be the current function name, instead of "Total across all functions", but this causes an assertion failure during the final merge of thread-local timers into the global timers, because the names don't match.

The solution is to temporarily rename the timer to be the function name, until the timer is dumped, and then restore it to its original value.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero: Improve non-MINIMAL string performance.
Jim Stichnoth [Tue, 5 Apr 2016 22:31:43 +0000 (15:31 -0700)]
Subzero: Improve non-MINIMAL string performance.

In a DUMP-enabled build, such as the standard Release+Asserts build, translator performance has regressed as a result of 467ffe51bebcb3ae3e3ce745c38fc20e8837c31c (https://codereview.chromium.org/1838753002).

This is because Variable and CfgNode names are being instantiated unconditionally, rather than on-demand.

This CL restores most of that performance by going back to being on-demand.  Note that it should have no effect on MINIMAL build performance.

Also, it turns out that Variable::getName() does not really need the Cfg* parameter, so that is removed (and all its callers are fixed transitively).

In addition, Variable and CfgNode are made more uniform with respect to each other in terms of inline definitions of the ctor, getName(), and setName().

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

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

8 years agoSubzero. Refactors Switch Lowering.
John Porto [Tue, 5 Apr 2016 13:30:21 +0000 (06:30 -0700)]
Subzero. Refactors Switch Lowering.

BUG=
R=stichnot@chromium.org

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

8 years agoSubzero. Fixes Browser build.
John Porto [Tue, 5 Apr 2016 13:20:50 +0000 (06:20 -0700)]
Subzero. Fixes Browser build.

BUG=
R=stichnot@chromium.org

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

8 years agoInitial Subzero WASM prototype.
Eric Holk [Tue, 5 Apr 2016 00:07:42 +0000 (17:07 -0700)]
Initial Subzero WASM prototype.

BUG=
R=stichnot@chromium.org

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

8 years agoReplace constant conditional branches by unconditional branches
David Sehr [Mon, 4 Apr 2016 17:11:08 +0000 (10:11 -0700)]
Replace constant conditional branches by unconditional branches

BUG=
R=jpp@chromium.org, stichnot@chromium.org

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

8 years agoSubzero: Fix -timing-funcs and -timing-focus flags.
Jim Stichnoth [Mon, 4 Apr 2016 04:58:03 +0000 (21:58 -0700)]
Subzero: Fix -timing-funcs and -timing-focus flags.

1. Generate dummy FunctionXXX function names when either of those flags is given.

2. Remove the browser code that automatically sets F/G prefixes instead of Function/Global, since that performance tweak is no longer relevant.

3. Fix a presumably long-standing bug where -timing-focus would accumulate timings into the TLS copy of the timers, but would then try to print timing info based on the currently-empty GlobalContext copy of the timers.

BUG= none
R=kschimpf@google.com

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

8 years agoFix error reporting for parallel parsed function blocks.
Karl Schimpf [Sat, 2 Apr 2016 17:06:56 +0000 (10:06 -0700)]
Fix error reporting for parallel parsed function blocks.

Fixes error reporting in function blocks by adding a start address
with parallel parses, and then using the getErrorBitNo() method
of the bitstream cursor to correct error bit number, based on the
start address.

Dependent on CL https://codereview.chromium.org/1851163002.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4363
R=stichnot@chromium.org

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

8 years agoSimplify references to command line flags.
Karl Schimpf [Sat, 2 Apr 2016 16:55:31 +0000 (09:55 -0700)]
Simplify references to command line flags.

This CL removes all indirect pointer chasing to get the values of
command line flags. Since we are only using 1 copy of ClFlags, this CL
introduces a static field Flags to hold the defined command line flags
(it was previously a static field of GlobalContext).

For those few contexts where one must change CL flags due to context
(such as testsing and running in the browser), use ClFlags::Flags.

In the remainder of the cases, the code uses getFlags() which returns
a constant reference to ClFlags::Flags, allowing access to the get
accessors.

BUG=None
R=stichnot@chromium.org

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

8 years agoSubzero: Fix a cleanup error after the IceString removal CL.
Jim Stichnoth [Sat, 2 Apr 2016 01:26:16 +0000 (18:26 -0700)]
Subzero: Fix a cleanup error after the IceString removal CL.

This corrects a "cleanup" mistake in line 414/417 of https://codereview.chromium.org/1838753002/diff/120001/src/IceTargetLoweringX8664.cpp .

This wasn't caught before because "make presubmit" doesn't run any sandboxed x86-64 tests.  So we add that to the presubmit script.

In addition, the "make check-spec" is changed to run each spec component via the "--run" flag of szbuild_spec2k.py.  Otherwise, the makefile was hard-coding running the native binary setup instead of the sandboxed or nonsfi setup.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero. Outputs liveness memory usage.
John Porto [Fri, 1 Apr 2016 18:14:30 +0000 (11:14 -0700)]
Subzero. Outputs liveness memory usage.

BUG=
R=stichnot@chromium.org

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

8 years agoSubzero. Liveness memory management.
John Porto [Fri, 1 Apr 2016 12:43:09 +0000 (05:43 -0700)]
Subzero. Liveness memory management.

Creates a local arena allocator for holding liveness data structures.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4366
R=stichnot@chromium.org

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

8 years agoClean up Cl flag refrences in the bitcode parser.
Karl Schimpf [Thu, 31 Mar 2016 21:39:10 +0000 (14:39 -0700)]
Clean up Cl flag refrences in the bitcode parser.

The code previously had to navigate through 1 (or more) indirect
pointers to find the CL flags. Since CL flags are a static field in
the global context, simplify these references. Note: I have added
member functions to do this (where appropriate) so that fixing code
could be easy if we choose to move where the command line flags are
stored.

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

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

8 years agoForce sequential parsing when threads=0.
Karl Schimpf [Thu, 31 Mar 2016 20:22:11 +0000 (13:22 -0700)]
Force sequential parsing when threads=0.

When threads=0, it doesn't pay to run a parallel parse, since each
parallel parse slows down parsing by requiring a copy of bits in the
function block.

BUG=None
R=stichnot@chromium.org

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

8 years agoSubzero: Ignore variables with no actual uses.
Jim Stichnoth [Thu, 31 Mar 2016 18:55:23 +0000 (11:55 -0700)]
Subzero: Ignore variables with no actual uses.

Liveness analysis uses a pair of bit vectors in each CFG node.  The early bits correspond to "global" variables that are referenced in more than one block, and the latter bits correspond to "local" variables that are referenced in only that particular single block.

Due to an oversight, variables that have no uses are conservatively classified as global, and consume space in every liveness bit vector.

This CL improves memory usage by reducing liveness bit vector size:

1. Identify variables with no actual uses and exclude them from the bit vectors.

2. Don't do liveness analysis on rematerializable variables, because they have no need to be involved in register allocation or dead code elimination.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4366
R=jpp@chromium.org

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

8 years agoSubzero: Refine the memory usage report with -szstats .
Jim Stichnoth [Thu, 31 Mar 2016 18:05:39 +0000 (11:05 -0700)]
Subzero: Refine the memory usage report with -szstats .

The problem is that the memory usage that comes from the -track-memory option is not very well-defined (it's a hidden LLVM option after all).  It gives an OK sense of memory growth over time, but sometimes we really want to know how much CFG-local arena memory was allocated for a particular function.

To help with this, we add another row to the stats output, giving the MB size of the CFG arena at the end of translating the method.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4366
R=kschimpf@google.com

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

8 years agoAllow Subzero to parse function blocks in parallel.
Karl Schimpf [Thu, 31 Mar 2016 17:20:23 +0000 (10:20 -0700)]
Allow Subzero to parse function blocks in parallel.

This CL modifies the code so that we can do sequential and parallel
parsing of function blocks in bitcode files, based on a command line
argument.

The command line argument was added because during testing, I had one
compilation failure (transient), and do not know the cause. Hence, I
was reluctant to install this CL without a command-line flag.

To test the new parallel parser, the easiest solution is to edit
IceClFlags.def and set the default value of ParseParallel to true.

This code also fixes up unit parsing tests, as well as one parsing
test.  The cause of these problems was the implicit assumption that
function blocks are parsed sequentially, which no longer applies when
function blocks are parsed in parallel. To fix this, the "threads=0"
command line argument was added. It also added the starting up of
worker threads, since parsing of function blocks will happen in the
translation thread if parallel parsing is turned on.

The OptQ queue was modified to contain OptWorkerItem instances with a
single virtual to get the parsed code. This allows the IceConverter to
continue to work, by simply passing the generated Cfg as a work item.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4363
R=jpp@chromium.org, stichnot@chromium.org

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

8 years agoSubzero: Fix a bug in advanced phi lowering.
Jim Stichnoth [Wed, 30 Mar 2016 22:30:30 +0000 (15:30 -0700)]
Subzero: Fix a bug in advanced phi lowering.

The motivating example (simplified) is this:

%__698:eax = phi i32 [ %__646:ebx, %__188 ] // LIVEEND={%__646:ebx}
%__617:bh =  phi i8  [ %__618:ah,  %__188 ] // LIVEEND={%__618:ah}
%__615:bl =  phi i8  [ %__616:al,  %__188 ] // LIVEEND={%__616:al}

By default, it first lowers the __698 assignment.  However, that assignment has two "predecessors" because there are two other instructions whose dest variable aliases the __698 assignment's source operand.  This triggers an assertion failure where we assume there is only one predecessor.

The fix is two-pronged.  First, we go ahead and generate as many temp assignments as needed to break the cycle, simply by changing an "if" to a "while".  Second, when we need to break a cycle, we give preference to an instruction with only one predecessor so that only one temp assignment needs to be added.

(It might be possible to prove that the second approach, i.e. preferring single-predecessor assignments, makes the first approach unnecessary, i.e. changing "if" to "while".)

This change has no effect on the x86 output for spec2k.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4365
R=jpp@chromium.org

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

8 years agoSubzero: Remove IceString.
Jim Stichnoth [Tue, 29 Mar 2016 22:01:06 +0000 (15:01 -0700)]
Subzero: Remove IceString.

The purpose is to get control over excess string creation and deletion, especially when the strings are long enough to involve malloc/free.

Strings that interface with the outside world, or used for dump/debug, are now explicitly std::string.

Variable names and node names are represented as string IDs and pooled locally in the CFG.  (In a non-DUMP build, this pool should always be empty.)

Other strings that are used across functions are represented as string IDs and pooled globally in the GlobalContext.

The --dump-strings flag allows these strings to be dumped for sanity checking, even in a MINIMAL build.  In a MINIMAL build, the set of strings includes external symbol names, intrinsic names, helper function names, and label names of pooled constants to facilitate deterministic ELF string table output.  For now, it also includes jump table entry names until that gets sorted out.

Constants are fixed so that the name and pooled fields are properly immutable after the constant is fully initialized.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4360
R=jpp@chromium.org

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

8 years agoFix Subzero binary instruction to allow optional flags argument.
Karl Schimpf [Fri, 25 Mar 2016 14:12:26 +0000 (07:12 -0700)]
Fix Subzero binary instruction to allow optional flags argument.

This CL fixes pnacl-sz to handle smoothnacl.pexe.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4364
R=jpp@chromium.org, stichnot@chromium.org

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

8 years agoSubzero. Fixes valgrind errors.
John Porto [Thu, 24 Mar 2016 13:11:29 +0000 (06:11 -0700)]
Subzero. Fixes valgrind errors.

Valgrind used to report errors about uninitialized variable access in
Subzero, when it was built with -O2. The problem was traced to

size_t Alignment = Var->getAlignment;
Alignment = std::max(MinAlignment, Var->getAlignment())

Apparently, the compiler will not correctly zero-extend
Var->getAlignment(), and thus Alignment's upper 32-bits would be
garbage.

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

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

8 years agoSubzero: Fix the broken "make presubmit-lite".
Jim Stichnoth [Mon, 21 Mar 2016 21:53:03 +0000 (14:53 -0700)]
Subzero: Fix the broken "make presubmit-lite".

BUG= none
R=kschimpf@google.com

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

8 years agoSubzero: Add presubmit-lite target.
Jim Stichnoth [Mon, 21 Mar 2016 19:49:33 +0000 (12:49 -0700)]
Subzero: Add presubmit-lite target.

The big reduction is in greatly reducing the set of non-native cross tests.  Also, not so many copies of spec2k are run, and only one "representative" sandboxed target is built.

BUG= none
R=eholk@chromium.org

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

8 years agoSubzero. Flags refactoring.
John Porto [Mon, 21 Mar 2016 18:18:02 +0000 (11:18 -0700)]
Subzero. Flags refactoring.

BUG=
R=stichnot@chromium.org

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

8 years agoAdd malloc/new profiling on linux
David Sehr [Thu, 17 Mar 2016 20:51:42 +0000 (13:51 -0700)]
Add malloc/new profiling on linux

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

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

8 years agoCache common constants before lowering.
Karl Schimpf [Thu, 17 Mar 2016 20:30:13 +0000 (13:30 -0700)]
Cache common constants before lowering.

This code moves some constants used by the target lowering, so that they
are defined (and cached) during static initialization of the target
lowering, rather than looking up everytime they are used.

This CL does this for the constant zero, and predefined helper functions.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4076
R=jpp@chromium.org, stichnot@chromium.org

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

8 years agoSuzero. Refactors dependencies in Makefile.standalone.
John Porto [Wed, 16 Mar 2016 11:20:49 +0000 (04:20 -0700)]
Suzero. Refactors dependencies in Makefile.standalone.

Uses the compiler's frontend -MD -MP options to auto-generate make
dependencies.

BUG=
R=stichnot@chromium.org

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

8 years agoSubzero: Shorten global prefixes in non-DUMP build.
Jim Stichnoth [Tue, 15 Mar 2016 18:09:32 +0000 (11:09 -0700)]
Subzero: Shorten global prefixes in non-DUMP build.

Reverts part of 843142fe (https://codereview.chromium.org/1776343004).

Makes global prefixes short in all non-DUMP builds, not just the browser
build, so that the user doesn't need to remember to supply the override
options in a command-line MINIMAL build.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero. Uses unique_ptrs in the emit queue.
John Porto [Tue, 15 Mar 2016 18:06:25 +0000 (11:06 -0700)]
Subzero. Uses unique_ptrs in the emit queue.

Because explicit memory ownership is awesome!

BUG=
R=stichnot@chromium.org

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

8 years agoSubzero. Allocate global initializers from a dedicated arena.
John Porto [Tue, 15 Mar 2016 16:28:04 +0000 (09:28 -0700)]
Subzero. Allocate global initializers from a dedicated arena.

This allows Subzero to release the global initializers once they've been
lowered.

This CL also modifies the global initializer types to ensure they are
trivially destructible -- therefore not requiring destructors to run.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4360
R=stichnot@chromium.org

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

8 years agoSubzero: Control whether deleted instructions are retained.
Jim Stichnoth [Mon, 14 Mar 2016 15:37:52 +0000 (08:37 -0700)]
Subzero: Control whether deleted instructions are retained.

Normally, deleted instructions are preserved in the Cfg, and printed as part of dump output.  This helps debugging by partially explaining the provenance of new instructions that originated from the deleted instructions.

However, these instructions slow down iteration over the instruction list, and checking their deleted status may pollute the cache.

As such, in a non-DUMP enabled build, we repurpose the renumberInstructions() pass to also unlink deleted instructions as needed.

A flag is provided to override this behavior, in case we have to debug a situation where a bug only manifests in a DUMP build and not a non-DUMP build, or vice versa.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4360
R=eholk@chromium.org, jpp@chromium.org

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

8 years agoSubzero: Allow Makefile.standalone to build for a single target.
Jim Stichnoth [Sat, 12 Mar 2016 18:22:53 +0000 (10:22 -0800)]
Subzero: Allow Makefile.standalone to build for a single target.

This makes it easier to focus on reducing the translator size.

Enable with e.g.:
  make -f Makefile.standalone MINIMAL=1 SZTARGET=X8664 bloat-sb

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4362
R=jpp@chromium.org

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

8 years agoSubzero: Fix the Makefile for the LLVM build.
Jim Stichnoth [Sat, 12 Mar 2016 18:04:08 +0000 (10:04 -0800)]
Subzero: Fix the Makefile for the LLVM build.

https://codereview.chromium.org/1784243006/ added the ALLOW_TIMERS define, and I forgot to add it to Makefile and CMakeLists.txt.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero: Improve the use of timers.
Jim Stichnoth [Fri, 11 Mar 2016 23:33:00 +0000 (15:33 -0800)]
Subzero: Improve the use of timers.

Several things are done here:

1. Move timer support to be guarded by the ALLOW_TIMERS define, or the BuildDefs::timers() constexpr method.

2. Add a NODUMP build configuration to control whether dump support is built in.  So "make -f Makefile.standalone NODUMP=1 NOASSERT=1" is pretty close to a MINIMAL build with timer support.

3. Add some missing timers: alloca analysis, RMW analysis, helper call pre-lowering, load optimization analysis.  These omitted pass timings were being rolled up into the "O2" bucket.

4. Add timers around push and pop operations on the translate queue and the emit queue.

5. Refactor the clumsy code to push/pop function timers (as opposed to pass timers), so that it fits into the nice RAII TimerMarker class like the pass timers.

6. It turns out that even with MINIMAL or NODUMP builds, we still construct a longish std::string every time Cfg::dump() is called, even though the string isn't used in MINIMAL/NODUMP mode.  The dump() arg might as well be a const char * arg instead.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4360
R=kschimpf@google.com

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

8 years agoSubzero: Improve the behavior of resizing vectors.
Jim Stichnoth [Fri, 11 Mar 2016 22:59:43 +0000 (14:59 -0800)]
Subzero: Improve the behavior of resizing vectors.

In some cases, Subzero needs to insert into a std::vector at a particular index, resizing the vector as necessary.  It appears that our vector implementation sets the capacity to exactly the size when growing the vector, without leaving any extra capacity.  This causes lots of mallocs and recopies each time the vector size is increased.  (Adding elements via push_back() or emplace_back() doesn't seem to have that behavior.)

We help this by reserving some extra space before resizing - bump to the next power of 2 up to some point, then bump to the next multiple of a chunk size beyond that point.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4360
R=kschimpf@google.com

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

8 years agoSubzero: 'make presubmit' checks for certain prerequisites.
Jim Stichnoth [Fri, 11 Mar 2016 22:58:23 +0000 (14:58 -0800)]
Subzero: 'make presubmit' checks for certain prerequisites.

A fresh checkout of native_client lacks some components that Subzero's "make -f Makefile.standalone presubmit" needs.

Add explicit checks for these components, and when missing, print suggestions for how to create them.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4359
R=jpp@chromium.org, smklein@chromium.org

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

8 years agoPNaCl Dynamic Linking: Force __pnacl_pso_root to be an external declaration.
Sean Klein [Fri, 11 Mar 2016 17:49:36 +0000 (09:49 -0800)]
PNaCl Dynamic Linking: Force __pnacl_pso_root to be an external declaration.

This CL updates "isPNaClABIExternalName" -- Subzero checked for the symbol
"__pnacl_pso_root" as a function, but it is a declaration, and should be
checked as one. Additionally, when the PNaClTranslator is verifying the linkage
of declarations, allow "__pnacl_pso_root" to be flipped to external as a special
case.

Previously, translating a pso with --use-sz caused the warning:
"cannot find entry symbol '__pnacl_pso_root'".
That warning is removed with this CL.

Fixes revert from https://codereview.chromium.org/1745783002/

TEST=external_declaration.ll
BUG=https://bugs.chromium.org/p/nativeclient/issues/detail?id=4351
R=kschimpf@google.com, stichnot@chromium.org

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

8 years agoSubzero. X8664. No moar ::new for AutoBundle.
John Porto [Thu, 10 Mar 2016 18:59:02 +0000 (10:59 -0800)]
Subzero. X8664. No moar ::new for AutoBundle.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4360
BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4077
R=stichnot@chromium.org

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

Patch from John Porto <jpp@chromium.org>.

8 years agoRe-fix build errors from upgrading to clang 3.9 .
Jim Stichnoth [Thu, 10 Mar 2016 16:19:34 +0000 (08:19 -0800)]
Re-fix build errors from upgrading to clang 3.9 .

This reverts commit 5526c1718b43d77d90850ec0409a21ecfc975b2c (https://codereview.chromium.org/1778663003) and implements it per jpp's suggestion.

BUG= none
R=jpp@chromium.org

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

8 years agoEliminate all uses of 'le32-nacl-objcopy'.
Sean Klein [Wed, 9 Mar 2016 23:26:41 +0000 (15:26 -0800)]
Eliminate all uses of 'le32-nacl-objcopy'.

Additionally, refactor "GetObjdumpCmd" and "GetObjcopyCmd".

BUG=https://bugs.chromium.org/p/nativeclient/issues/detail?id=4361
R=stichnot@chromium.org

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

8 years agoSubzero: Tweaks to reduce malloc use.
Jim Stichnoth [Wed, 9 Mar 2016 23:19:40 +0000 (15:19 -0800)]
Subzero: Tweaks to reduce malloc use.

1. Subzero constructs many strings based in part on function name.  When function names are not present (as in properly finalized pexes), they are synthesized as something like "Function12345".  We can shorten these strings to e.g. "F12345" by using --default-function-prefix=F .  Similar for global variable names.

Using short strings makes it much less likely to have to use malloc.  As such, we force that to be the default in the browser translator build.  For perf-testing the command-line version, the user can just add the option manually for now.

Ultimately, we should avoid use of strings in this way.

2. The register allocator uses a few instances of llvm::SmallVector that are sized too small and therefore end up using malloc.  This can be fixed in a clean way, and there is a TODO for it, but in the meantime we just bump the size.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4360
R=jpp@chromium.org

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

8 years agoAllow subzero tests to pass without le32-nacl-objdump.
Sean Klein [Wed, 9 Mar 2016 18:29:54 +0000 (10:29 -0800)]
Allow subzero tests to pass without le32-nacl-objdump.

le32-nacl-objdump has been deprecated, and should no longer be used.
Instead, "arm-nacl-objdump" is being used. "le32-nacl-objdump" used to be
a hard link to "arm-nacl-objdump", but has since been deleted in NaCl's
"toolchain_build_pnacl.py" script.

R=phosek@chromium.org, stichnot@chromium.org

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

8 years agoSubzero: Fix build errors from upgrading to clang 3.9 .
Jim Stichnoth [Wed, 9 Mar 2016 06:46:19 +0000 (22:46 -0800)]
Subzero: Fix build errors from upgrading to clang 3.9 .

BUG= none
TBR=jpp@chromium.org

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

8 years agoSubzero: Control memory growth from local label fixups.
Jim Stichnoth [Wed, 9 Mar 2016 00:18:40 +0000 (16:18 -0800)]
Subzero: Control memory growth from local label fixups.

The ConstantRelocatable objects for pushing local labels are allocated from the Assembler arena, and are no longer pooled, which restricts the memory growth from sandboxing x86-64 calls.

Because the Assembler arena is destroyed while the fixups are still active, these fixups have to be fixed up by holding a pointer to the symbol rather than the constant.

On the 10MB test pexe, the overall growth by the end is ~20MB, instead of ~130MB as before.

This also partially fixes an existing bug with arm32/nonsfi/iasm, exposed by running cross tests and forcing iasm output.

BUG= none
R=jpp@chromium.org

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

8 years agoFix timing of parseFunctions.
Karl Schimpf [Tue, 8 Mar 2016 20:27:12 +0000 (12:27 -0800)]
Fix timing of parseFunctions.

The previous implementation was charging about 24% more time that it
should to the function parser. The cause was that the time to "queue" the
parsed functions, and the time to emit the assembled code (again
including "queue" time) was not accounted for. About 15% was going to
queuing costs, and 7% to emitting the ELF file.

This CL adds timing of function translateFunctions, which captures most
of the queueing costs, and timing for each of the major ELF emission
functions (emitELF). This allows the corresponding costs to be better
bucketed, and not charged to the time it takes to parse functions in
bitcode files.

Bug=None

R=jpp@chromium.org, stichnot@chromium.org

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

8 years agoSubzero. ARM32. Fix bugs uncovered by scons tests.
John Porto [Tue, 8 Mar 2016 19:00:53 +0000 (11:00 -0800)]
Subzero. ARM32. Fix bugs uncovered by scons tests.

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

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

8 years agoSubzero: Fix "make presubmit" for spec -Om1.
Jim Stichnoth [Mon, 7 Mar 2016 17:54:15 +0000 (09:54 -0800)]
Subzero: Fix "make presubmit" for spec -Om1.

For the Om1 spec tests, we were generating commands like this:

  ./pydir/szbuild_spec2k.py -v -Om1 --target=x8632 -O2 --filetype=obj 253.perlbmk

where -Om1 and -O2 both appear.  Python's argparse allows an argument to be set multiple times, and the last one would win, i.e. -O2 is used instead of -Om1.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero: Fix symbol name mangling. Make flags global.
Jim Stichnoth [Mon, 7 Mar 2016 17:26:22 +0000 (09:26 -0800)]
Subzero: Fix symbol name mangling. Make flags global.

This cleans up the whole --prefix handling mechanism, so that all mangling is done based on logic in the parser instead of scattered all over the code base.  Another nice side effect is that it allows some getName() style functions to return a const string reference instead of a string copy.

Also, moves ClFlags into a static field of GlobalContext, i.e. makes it global, so that these constant flags can be accessed without having to plumb a GlobalContext object.  Note that some of the ClFlags and ClFlagsExtra plumbing in the compile server classes could be simplified to directly use the corresponding static fields, but this is left mostly as is for now, for when we do a proper separation between core and supplemental flags.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero: Count lookups of each constant value in the constant pool.
Jim Stichnoth [Mon, 7 Mar 2016 16:25:24 +0000 (08:25 -0800)]
Subzero: Count lookups of each constant value in the constant pool.

With "-verbose cpool", at the end it dumps counts of the number of times each pooled constant was looked up.  The output is grouped by type and sorted by constant value, but it's easy to run it through "sort -nr" to see it ordered by popularity.

BUG= none
R=jpp@chromium.org

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

8 years agoSubzero. ARM32. Fixes bugs uncovered by the llvm test suite.
John Porto [Wed, 2 Mar 2016 23:10:19 +0000 (15:10 -0800)]
Subzero. ARM32. Fixes bugs uncovered by the llvm test suite.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4076
R=stichnot@chromium.org

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

8 years agoSubzero. ARM32. Fixes bugs uncovered by the gcc torture tests.
John Porto [Tue, 1 Mar 2016 23:19:29 +0000 (15:19 -0800)]
Subzero. ARM32. Fixes bugs uncovered by the gcc torture tests.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4076
R=stichnot@chromium.org

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

8 years agoSubzero: Print constant pool info with --szstats.
Jim Stichnoth [Tue, 1 Mar 2016 20:22:29 +0000 (12:22 -0800)]
Subzero: Print constant pool info with --szstats.

BUG= none
R=eholk@chromium.org, jpp@chromium.org

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

8 years agoSubzero. ARM32. Reverts cl 1687553002.
John Porto [Tue, 1 Mar 2016 14:11:05 +0000 (06:11 -0800)]
Subzero. ARM32. Reverts cl 1687553002.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4076
R=stichnot@chromium.org

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

8 years agoSubzero: Reduce copying of Liveness bitvectors.
Jim Stichnoth [Tue, 1 Mar 2016 00:58:15 +0000 (16:58 -0800)]
Subzero: Reduce copying of Liveness bitvectors.

There were a lot of unnecessary copying and resizing and sloppiness in the use of BitVector for liveness analysis.  This tries to reduce the amount of copying and associated memory allocation.

Also, works around a ConstantRelocatable hashing problem that was causing a huge slowdown in MINIMAL mode for the vector_shuffle scons test.

BUG= none
R=jpp@chromium.org

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

8 years agoFix clang warning "has virtual functions but non-virtual destructor".
Sean Klein [Tue, 1 Mar 2016 00:44:07 +0000 (16:44 -0800)]
Fix clang warning "has virtual functions but non-virtual destructor".

BUG= None
R=stichnot@chromium.org

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

8 years agoSubzero: Fix JumpTable lowering on x86-64.
Jim Stichnoth [Mon, 29 Feb 2016 17:54:55 +0000 (09:54 -0800)]
Subzero: Fix JumpTable lowering on x86-64.

The problem is that when switch lowering decides to use a JumpTable and the switch variable is i64 on x86-64, the lowering tries to movzx the i64 variable into an i32 variable, and the Movzx ctor asserts.

This happens when translating pnacl-llc.pexe, but luckily it is also triggered in the existing adv-switch.ll test.

BUG= none
R=jpp@chromium.org

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