OSDN Git Service

android-x86/external-swiftshader.git
9 years agoSubzero: Fix broken lit tests.
Jim Stichnoth [Thu, 30 Oct 2014 01:51:56 +0000 (18:51 -0700)]
Subzero: Fix broken lit tests.

The file ifatts.py no longer exists.

BUG= none
R=jvoung@chromium.org

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

9 years agoRemove IceConverter when LLVM IR is not allowed.
Karl Schimpf [Wed, 29 Oct 2014 21:58:25 +0000 (14:58 -0700)]
Remove IceConverter when LLVM IR is not allowed.

BUG=
R=stichnot@chromium.org

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

9 years agoRemove building llvm2ice.build_atts from Subzero build.
Karl Schimpf [Wed, 29 Oct 2014 21:55:00 +0000 (14:55 -0700)]
Remove building llvm2ice.build_atts from Subzero build.

BUG=None
R=stichnot@chromium.org

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

9 years agoFix insert/extract element vector operations to check that literal
Karl Schimpf [Wed, 29 Oct 2014 21:32:07 +0000 (14:32 -0700)]
Fix insert/extract element vector operations to check that literal
indices are used.

Also introduces a "error" instruction method for inserting an instruction
placeholder when an instruction is erroneous, and the type of generated
value is known.

BUG=
R=stichnot@chromium.org

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

9 years agoAllow conditional lit tests in Subzero, based on build flags.
Karl Schimpf [Mon, 27 Oct 2014 21:41:57 +0000 (14:41 -0700)]
Allow conditional lit tests in Subzero, based on build flags.

Adds conditionality to lit tests in two ways:

1) Allows the use of "; REQUIRES: XXX" lines in lit tests. In this
case, the tests defined by the file are only run if all REQUIRES are
met.

2) Allows the conditional running of RUN commands, based on build
flags. This comes in two subforms. There are predefined %ifX commands
that run the command defined by remaining arguments, if the
corresponding %X2i command is applicable. Alternatively, one can use
%if with explicit '--att' arguments to define what conditions should
be checked.

In any case, unlike REQUIRES, the %if commands RUN all the time, but
simply generate empty output, rather then output defined by the
following command, if the condition is not met. These latter tests are
useful when the same input is to be tested under different conditions,
since the REQUIRES form does not allow this.

Note that m2i, p2i, l2i, and lc2i are also conditionally controlled,
so that they do nothing if the build did not construct the appropriate
Subzero translator.

This CL replaces https://codereview.chromium.org/644143002

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

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

9 years agoSubzero: Refactor newline emission for Inst::emit().
Jim Stichnoth [Mon, 27 Oct 2014 16:51:55 +0000 (09:51 -0700)]
Subzero: Refactor newline emission for Inst::emit().

The (final) newline is emitted by the caller of emit(), instead of
by all the emit() implementations.  This sets the stage for being
able to add useful comments to the textual asm, such as annotating
which registers became free after the instruction.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Minor refactoring/additions in preparation for phi edge splitting.
Jim Stichnoth [Fri, 24 Oct 2014 17:59:02 +0000 (10:59 -0700)]
Subzero: Minor refactoring/additions in preparation for phi edge splitting.

The only functional change (though not actually visible at this point) is that redundant assignment elimination is moved into a separate pass.

BUG= none
R=jvoung@chromium.org

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

9 years agoFirst pass at emitIAS for branches and binding labels
Jan Voung [Fri, 24 Oct 2014 17:29:30 +0000 (10:29 -0700)]
First pass at emitIAS for branches and binding labels

Currently not testing fixups of forward branches and
instead streaming a ".byte (foo - (. + 1))" or
".long (foo - (. + 4))". It should be supported once
emitIAS() delays writing things out until after the
function is fully emitted (and therefore forward labels
have all been bound).

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Adjust expectations now that llvm-mc aligns calls not just naclcall.
Jan Voung [Fri, 24 Oct 2014 16:33:27 +0000 (09:33 -0700)]
Subzero: Adjust expectations now that llvm-mc aligns calls not just naclcall.

Previously, llvm would emit naclcall instead of call to get the effect
of bundle-align-to-end, but now it just emits plain calls and aligns
plain calls like NaCl binutils would do. Adjust a few Subzero tests.
See: https://codereview.chromium.org/647443005/

Currently leaving the nop checks loose in case the integrated assembler
has some intermediate stage where it emits the bytes of a call
in a "raw" manner (without padding).

BUG=none
R=kschimpf@google.com

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

9 years agoSubzero: Improve debugging controls, plus minor refactoring.
Jim Stichnoth [Thu, 23 Oct 2014 19:02:08 +0000 (12:02 -0700)]
Subzero: Improve debugging controls, plus minor refactoring.

1. Decorate the list of live-in and live-out variables with register assignments in the dump() output.  This helps one to assess register pressure.

2. Fix a bug where the DisableInternal flag wasn't being honored for function definitions.

3. Add a -translate-only=<symbol> to limit translation to a single function or global variable.  This makes it easier to focus on debugging a single function.

4. Change the -no-phi-edge-split option to -phi-edge-split and invert the meaning, to better not avoid the non double negatives.

BUG= none
R=jvoung@chromium.org

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

9 years agoFix nacl-atomic-fence-all test to have alignment specified in load.
Jan Voung [Tue, 21 Oct 2014 01:04:56 +0000 (18:04 -0700)]
Fix nacl-atomic-fence-all test to have alignment specified in load.

Helps make it work with p2i instead of lc2i. This affected the
address mode optimizations, so some of the test expectations
have changed.

BUG=none
(happened to notice it while trying to test some things manually)

R=stichnot@chromium.org

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

9 years agoFix cross test test_global.
Karl Schimpf [Mon, 20 Oct 2014 21:26:24 +0000 (14:26 -0700)]
Fix cross test test_global.

The definition of ExternName4 in crosstest/test_global_main.cpp was
not defined as a pointer, but was in crosstest/test_global.cpp. As
a result, that name was not linked properly.

BUG=None
R=stichnot@chromium.org

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

9 years agoFix handling of relocation names, so that prefix mangling works.
Karl Schimpf [Mon, 20 Oct 2014 21:09:00 +0000 (14:09 -0700)]
Fix handling of relocation names, so that prefix mangling works.

Fixes bug in the representation of relocation names (in either global
initializers or as constant expressions in code) so that they
understand when the name is externally defined. This allows us to test
this property using command line arguments, and fixes relocation tests
in cross compilations (where externnally referenced names shouldn't be
name mangled).

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

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

9 years agoSubzero: Do class definition cleanups for assembler files too.
Jan Voung [Thu, 16 Oct 2014 22:39:22 +0000 (15:39 -0700)]
Subzero: Do class definition cleanups for assembler files too.

Similar to https://codereview.chromium.org/656123003/, but cover some of
the assembler files which were avoided to avoid conflicts.

BUG=none
R=stichnot@chromium.org

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

9 years agoemitIAS for store and indirect calls.
Jan Voung [Thu, 16 Oct 2014 16:40:02 +0000 (09:40 -0700)]
emitIAS for store and indirect calls.

We can't do direct calls via the .long sym hack, since that is
normally for an absolute relocation, but calls are expecting
relative relocations (except for reg/mem forms).

Nop-out the InstFake emitIAS methods. Remove the generic dispatcher
that redirects emitIAS() to emit(), since only branches and labels
are left.

BUG=none
R=stichnot@chromium.org

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

9 years agoemitIAS for movsx and movzx.
Jan Voung [Wed, 15 Oct 2014 22:16:54 +0000 (15:16 -0700)]
emitIAS for movsx and movzx.

Force dest to be the full 32-bit reg instead of sometimes being
a 16-bit reg. This is to save on a operand size prefix (and
avoid passing the DestTy down to the dispatchers).

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Speed up VariablesMetadata initialization.
Jim Stichnoth [Wed, 15 Oct 2014 22:13:06 +0000 (15:13 -0700)]
Subzero: Speed up VariablesMetadata initialization.

Currently, O2 calls VariablesMetadata::init() 4 times:

- Twice for liveness analysis, where only multi-block use information is needed for dealing with sparse bit vectors.

- Once for address mode inference, where single-definition information is needed.

- Once for register allocation, where all information is needed, including the set of all definitions which is needed for determining AllowOverlap.

So we limit the amount of data we gather based on the actual need.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Class definition cleanup.
Jim Stichnoth [Wed, 15 Oct 2014 21:39:23 +0000 (14:39 -0700)]
Subzero: Class definition cleanup.

For consistency, put deleted ctors at the beginning of the class
definition.

If the default copy ctor or assignment operator is not deleted,
and the default implementation is used, leave it commented out to
indicate it is intentional.

Also, fixed one C++11 related TODO.

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

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

9 years agoSubzero: Register allocator performance improvements and simplifications.
Jim Stichnoth [Wed, 15 Oct 2014 17:16:54 +0000 (10:16 -0700)]
Subzero: Register allocator performance improvements and simplifications.

This removes the redundancy between live ranges stored in the Variable and those stored in Liveness, by removing the Liveness copy.  After liveness analysis, live ranges are constructed directly into the Variable.

Also, the LiveRangeWrapper is removed and Variable * is directly used instead.  The original thought behind LiveRangeWrapper was that it could be extended to include live range splitting.  However, when/if live range splitting is implemented, it will probably involve creating a new variable with its own live range, and carrying around some extra bookkeeping until the split is committed, so such a wrapper probably won't be needed.

BUG= none
R=jvoung@chromium.org

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

9 years agoemitIAS for Shld and Shrd and the ternary and three-address ops.
Jan Voung [Wed, 15 Oct 2014 16:32:58 +0000 (09:32 -0700)]
emitIAS for Shld and Shrd and the ternary and three-address ops.

Give a different name to the crosstest .s and .o files depending on the
CPU features as well. That way the SSE2 and SSE4.1 .s and .o are separate.

The encodings for Pextrw and Pextrb/d... make me sad.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Enhance the timer dump format.
Jim Stichnoth [Tue, 14 Oct 2014 18:09:27 +0000 (11:09 -0700)]
Subzero: Enhance the timer dump format.

This adds update counts to the output, e.g.:

Total across all functions - Flat times:
    0.262297 (13.0%): [ 1287] linearScan
    0.243965 (12.1%): [ 1287] emit
...

This is useful to know when some passes are called once per function and others are called several times per function.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Improve performance of liveness analysis and live range construction.
Jim Stichnoth [Tue, 14 Oct 2014 00:15:08 +0000 (17:15 -0700)]
Subzero: Improve performance of liveness analysis and live range construction.

The key performance problem was that the per-block LiveBegin and LiveEnd vectors were dense with respect to the multi-block "global" variables, even though very few of the global variables are ever live within the block.  This led to large vectors needlessly initialized and iterated over.

The new approach is to accumulate two small vectors of <variable,instruction_number> tuples (LiveBegin and LiveEnd) as each block is processed, then sort the vectors and iterate over them in parallel to construct the live ranges.

Some of the anomalies in the original liveness analysis code have been straightened out:

1. Variables have an IgnoreLiveness attribute to suppress analysis.  This is currently used only on the esp register.

2. Instructions have a DestNonKillable attribute which causes the Dest variable not to be marked as starting a new live range at that instruction.  This is used when a variable is non-SSA and has more than one assignment within a block, but we want to treat it as a single live range.  This lets the variable have zero or one live range begins or ends within a block.  DestNonKillable is derived automatically for two-address instructions, and annotated manually in a few other cases.

This is tested by comparing the O2 asm output in each Spec2K component.  In theory, the output should be the same except for some differences in pseudo-instructions output as comments.  However, some actual differences showed up, related to the i64 shl instruction followed by trunc to i32.  This turned out to be a liveness bug that was accidentally fixed.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Translation-time improvements in the register allocator.
Jim Stichnoth [Mon, 13 Oct 2014 23:20:59 +0000 (16:20 -0700)]
Subzero: Translation-time improvements in the register allocator.

1. Use a sorted std::vector instead of std::set to improve management
of the Unhandled sets.  This is the main performance gain.

2. Use std::list.splice() to move items between lists, instead of
erase()+push_back().  This doesn't really save much, but the intention
is somewhat clearer.

BUG= none
R=jvoung@chromium.org

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

9 years agoHandle "Mov" which is mov, movss, movsd, and used for nacl.read.tp.
Jan Voung [Mon, 13 Oct 2014 22:56:32 +0000 (15:56 -0700)]
Handle "Mov" which is mov, movss, movsd, and used for nacl.read.tp.

Currently, this only checks and emits the segment
override only for GPR instructions, assuming it's mostly
only used for nacl.read.tp. The code will assert when used
in other situations.

The lea hack is still tested in some files, but it's not
emitted with emitIAS, and instead the "immediate" operand
now has a fixup.

There is a more compact encoding for "mov eax, moffs32",
etc., but that isn't used right now.

BUG=none
R=stichnot@chromium.org

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

9 years agoIntroduce the notion of function addresses in Subzero.
Karl Schimpf [Mon, 13 Oct 2014 22:01:08 +0000 (15:01 -0700)]
Introduce the notion of function addresses in Subzero.

Introduces the notion of a function address, to replace using LLVM
IR's Function class. Modifies Ice converter, and Subzero's bitcode
reader, to build function addresses.

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

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

9 years agoemitIAS for the couple of blend instructions.
Jan Voung [Mon, 13 Oct 2014 21:06:50 +0000 (14:06 -0700)]
emitIAS for the couple of blend instructions.

BUG=none
R=stichnot@chromium.org

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

9 years agoemitIAS for fld and fstp
Jan Voung [Thu, 9 Oct 2014 04:05:27 +0000 (21:05 -0700)]
emitIAS for fld and fstp

BUG=none
R=stichnot@chromium.org

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

9 years agoemitIAS for cvtt?.*2.*
Jan Voung [Wed, 8 Oct 2014 20:52:10 +0000 (13:52 -0700)]
emitIAS for cvtt?.*2.*

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Fix emission of global initializers.
Jim Stichnoth [Wed, 8 Oct 2014 18:24:51 +0000 (11:24 -0700)]
Subzero: Fix emission of global initializers.

Also changes the szbuild.py script to add -fdata-sections, and entirely removes the -disable-globals option.

The global initializer emission basically copies what llc does, based on 3 properties of the global: constant vs non-constant, internal vs external, and full zero-initializer vs non-trivial initializer.

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

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

9 years agoConvert Subzero's bitcode reader to generate ICE types.
Karl Schimpf [Wed, 8 Oct 2014 16:05:53 +0000 (09:05 -0700)]
Convert Subzero's bitcode reader to generate ICE types.

Changes Subzero's bitcode reader to build and store ICE types,
instead of using LLVM's types. Note: This code doesn't remove
all uses of LLVM types. They are still used to check types for
instructions and to generate function addresses.

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

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

9 years agoSubzero: Improve the output with the --timing-focus=xxx option.
Jim Stichnoth [Wed, 8 Oct 2014 15:28:36 +0000 (08:28 -0700)]
Subzero: Improve the output with the --timing-focus=xxx option.

Makes sure the percentages represent only the function(s) focused on, and not with respect to the total translation time across all functions.

Reset the timings between functions so that --timing-focus=* gives reasonable numbers.

Also, adds a timer for the live range construction phase.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd cross test for vector itofp and fptoi casts.
Jan Voung [Wed, 8 Oct 2014 00:22:51 +0000 (17:22 -0700)]
Add cross test for vector itofp and fptoi casts.

Add the SZ runtime functions for unsigned conversion.
Add some more cast tests before doing emitIAS for cvt.

BUG=none
R=stichnot@chromium.org

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

9 years agoemitIAS for push -- simplify push since it's not used for args passing anymore
Jan Voung [Tue, 7 Oct 2014 18:20:10 +0000 (11:20 -0700)]
emitIAS for push -- simplify push since it's not used for args passing anymore

Since push isn't used for args passing anymore, the cases of handling
push for vectors and floats/doubles isn't needed anymore. Passing
vectors requires a bit more care of alignment, so that was changed.

I can imagine push needing to handle addresses later (at least on
x86-64 to push the lower 32-bits of return address), but for now,
this means only handling GPRs. The XMM registers are not callee saved.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Optimize live range overlaps() computation through trimming.
Jim Stichnoth [Tue, 7 Oct 2014 18:09:33 +0000 (11:09 -0700)]
Subzero: Optimize live range overlaps() computation through trimming.

The main optimization is for the repeated overlaps() calls against the Inactive set, by iteratively trimming away the early sections of the Inactive live ranges that can no longer overlap with Cur.

A more minor optimization doesn't bother checking pure point-valued Inactive ranges for expiring or reactivating.

BUG= none
R=jvoung@chromium.org

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

9 years agoIntroduce model of global initializers in Subzero.
Karl Schimpf [Tue, 7 Oct 2014 17:38:22 +0000 (10:38 -0700)]
Introduce model of global initializers in Subzero.

Modifies both LLVM to ICE converter, and Subzero's bitcode reader,
to build Subzero's global initializers. Modifies target lowering
routines for global initializers to use this new model.

Also modifies both to now handle relocations in global variable
initializers.

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

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

9 years agoSubzero: Add a few performance measurement tools.
Jim Stichnoth [Tue, 7 Oct 2014 17:02:38 +0000 (10:02 -0700)]
Subzero: Add a few performance measurement tools.

--timing-funcs - Produces a sorted list of total time spent translating each function.

--timing-focus=<F> - Turns on the --timing equivalent just for one function.  Use '*' to do this for all functions, i.e. get complete timing breakdowns across all functions.

--verbose-focus=<F> - Temporarily turns on --verbose=all for one function.

BUG= none
R=jvoung@chromium.org

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

9 years agoemitIAS for icmp, and test, movss-reg, movq, movups, storep, storeq, tighten some...
Jan Voung [Mon, 6 Oct 2014 15:53:52 +0000 (08:53 -0700)]
emitIAS for icmp, and test, movss-reg, movq, movups, storep, storeq, tighten some of the Xmm ops

The "test" instruction is used in very limited situations. I've made a best effort
to fill in the possible forms (address for the first operand), but it's not tested,
so I put the *untested* parts behind an assert. Otherwise it's very similar to
icmp, so if it starts to be used and tested then the asserts can be taken out,
and the code shared with icmp.

Tighten some of the XMM dispatch/emitters. Most of those XMM instructions
can only encode the variant where dest is a register. Rather than waste
a slot for a NULL method pointer, just make the struct type have two variants
instead of three.

Fill out a couple of XMM instructions which *do* allow mem-ops as dest
(mov instructions).

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Optimize a common live range overlap calculation.
Jim Stichnoth [Sat, 4 Oct 2014 12:43:47 +0000 (05:43 -0700)]
Subzero: Optimize a common live range overlap calculation.

Call instruction lowering includes the FakeKill instruction, which creates several precolored variables, one for each scratch register.  The live range for each of these variables consists of a set of "point" ranges, one point for every FakeKill instruction.  The overlaps() logic is such that a point range never overlaps with an individual instruction, but it can overlap with a normal non-point range.

It turns out that during register allocation, usually most of the variables on the Inactive list are these FakeKill instructions.  The live range representation can be quite large if there are many calls in the function.  In the "Check for inactive ranges that have expired or reactivated" section, a lot of time was spent on overlapsStart() calls that were doomed to return false.

This change lets the live range keep track of whether it contains non-point segments, and if not, optimize the overlaps(InstNumberT) method.

BUG= none
R=jvoung@chromium.org

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

9 years agoHandle GPR and vector shift ops. Handle pmull also.
Jan Voung [Sat, 4 Oct 2014 04:58:02 +0000 (21:58 -0700)]
Handle GPR and vector shift ops. Handle pmull also.

For the integer shift ops, since the Src1 operand is forced
to be an immediate or register (cl), it should be legal to
have Dest+Src0 be either register or memory. However, we
are currently only using the register form. It might be the
case that shift w/ Dest+Src0 as mem are less optimized
on some micro-architectures though, since it has to load,
shift, and store all in one operation, but I'm not sure.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Improve regalloc performance by optimizing UnhandledPrecolored.
Jim Stichnoth [Thu, 2 Oct 2014 19:58:21 +0000 (12:58 -0700)]
Subzero: Improve regalloc performance by optimizing UnhandledPrecolored.

A lot of time was being spent in the two loops that check precolored ranges in the Unhandled set, specifically in the endsBefore() check.

Solve this by keeping a shadow copy of Unhandled, restricted to the ranges that are precolored.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Remove LLVM_DELETED_FUNCTION.
Jim Stichnoth [Wed, 1 Oct 2014 21:23:01 +0000 (14:23 -0700)]
Subzero: Remove LLVM_DELETED_FUNCTION.

sed -i 's/LLVM_DELETED_FUNCTION/= delete/' src/*.{h,cpp}

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

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

9 years agoSubzero: Auto-awesome iterators.
Jim Stichnoth [Wed, 1 Oct 2014 21:05:51 +0000 (14:05 -0700)]
Subzero: Auto-awesome iterators.

Use C++11 'auto' where practical to make iteration more concise.
Use C++11 range-based for loops where possible.

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

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

9 years agoSubzero: Move to C++11 static_assert().
Jim Stichnoth [Wed, 1 Oct 2014 20:06:21 +0000 (13:06 -0700)]
Subzero: Move to C++11 static_assert().

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

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

9 years agoSubzero: Allow builds with assertions disabled.
Jim Stichnoth [Wed, 1 Oct 2014 16:28:21 +0000 (09:28 -0700)]
Subzero: Allow builds with assertions disabled.

1. Setting command-line make variable NOASSERT=1 adds -DNDEBUG and builds in a separate directory.  By default, we still get Release+Asserts.

2. Add "(void)foo;" as necessary when foo is only used in an assert(), to remove warnings.

3. Minimize inclusion of llvm/Support/Timer.h because it adds warnings.

4. Call validateLiveness() only when asserts are enabled, because it's relatively expensive.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Change llvm::OwningPtr to C++11's std::unique_ptr.
Jim Stichnoth [Wed, 1 Oct 2014 02:10:22 +0000 (19:10 -0700)]
Subzero: Change llvm::OwningPtr to C++11's std::unique_ptr.

While I'm at it, normalize the #include order:

1. C++ library headers
2. LLVM headers
3. Subzero headers

A blank line between each group.  Each group sorted alphabetically, case-insensitive.

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

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

9 years agoSubzero: Rewrite the pass timing infrastructure.
Jim Stichnoth [Tue, 30 Sep 2014 23:49:38 +0000 (16:49 -0700)]
Subzero: Rewrite the pass timing infrastructure.

This makes it much more useful for individual analysis and long-term translation performance tracking.

1. Collect and report aggregated across the entire translation, instead of function-by-function.  If you really care about a single function, just extract it and translate it separately for analysis.

2. Remove "-verbose time" and just use -timing.

3. Collects two kinds of timings: cumulative and flat.  Cumulative measures the total time, even if a callee also times itself.  Flat only measures the currently active timer at the top of the stack.  The flat times should add up to 100%, but cumulative will usually add up to much more than 100%.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Change the echoing in shellcmd().
Jim Stichnoth [Tue, 30 Sep 2014 17:52:04 +0000 (10:52 -0700)]
Subzero: Change the echoing in shellcmd().

This makes it much easier to copy/paste the output.

BUG= none
R=jvoung@chromium.org

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

9 years agoHandle imul, pcmpeq, pcmpgt.
Jan Voung [Tue, 30 Sep 2014 15:36:06 +0000 (08:36 -0700)]
Handle imul, pcmpeq, pcmpgt.

Be sure to legalize 8-bit imul immediates (there is only the r/m form).
Add a test for that, and cover a couple of other ops too...

There is a one-byte-shorter form when Dest/Src0 == EAX and Src1 is not
an immediate, but that isn't taken advantage of.

Go ahead and add the optimization for 8-bit immediates for i16/i32
(not allowed for i8). It shows up sometimes in spec, e.g., to multiply by 10.
There is a lot of multiply by 4 as well, that we could strength-reduce.

BUG=none
R=stichnot@chromium.org

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

9 years agoChange some explicit type checks into using helper functions.
Jan Voung [Mon, 29 Sep 2014 17:16:01 +0000 (10:16 -0700)]
Change some explicit type checks into using helper functions.

For some arithmetic assembler methods, instead of checking
IceType_i8 || IceType_i1, only allow IceType_i8 and assert if
an i1 leaked to that stage (should have been vetted earlier
by the bitcode reader / ABI checks). Could have looked up the
type width and isIntegerArithmeticType, etc. in the property table,
but that seemed a bit heavy for just checking one type
(or one of two types).

Also changed some f32 || f64 checks into just using
isScalarFloatingType() which looks things up in a property table.
Could alternatively just keep it as an simple f32 || f64 check,
and I could change isScalarFloatingType()'s implementation.

In some places where we assume something is either i32 or i64
and do a select, change that into using a helper function
so that we can do one compare, and then assert. Some of the
asserts are really redundant (already within a branch which
already checked that), but hopefully that disappears if
we compile in release mode.
Similar for f32 or f64 (which happened a lot in the assembler).

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

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

9 years agoSubzero: Update link path after recent newlib install changes.
Jim Stichnoth [Mon, 29 Sep 2014 17:06:29 +0000 (10:06 -0700)]
Subzero: Update link path after recent newlib install changes.

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

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

9 years agoSubzero: Fix emission of 16-bit immediates.
Jim Stichnoth [Mon, 29 Sep 2014 03:30:21 +0000 (20:30 -0700)]
Subzero: Fix emission of 16-bit immediates.

The operand type needs to be propagated into EmitImmediate() and EmitComplex() so that we know whether to emit the 2-byte or 4-byte form.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Build both Debug and Release version of llvm2ice.
Jim Stichnoth [Sat, 27 Sep 2014 01:53:41 +0000 (18:53 -0700)]
Subzero: Build both Debug and Release version of llvm2ice.

Separate objects are built with -O0 and -O2.

Separate executables are built:
  build/Release/llvm2ice - Release build
  build/Debug/llvm2ice - Debug build

The executable built depends on whether the DEBUG make variable is set:
  make -f Makefile.standalone
  make -f Makefile.standalone DEBUG=1

The llvm2ice file in the top-level directory is always removed and symlinked to the appropriate build.

BUG= none
R=jvoung@chromium.org

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

9 years agoHandle add, adc, etc., mfence, div, idiv, mul in the assembler.
Jan Voung [Fri, 26 Sep 2014 18:14:30 +0000 (11:14 -0700)]
Handle add, adc, etc., mfence, div, idiv, mul in the assembler.

Add a test to check that the encodings are efficient for immediates
(chooses the i8, and eax encodings when appropriate).

The .byte syntax breaks NaCl bundle straddle checking in llvm-mc,
so I had to change one of the tests which noted that a nop appeared
(no longer does).

This also assumes that _add(), etc. are usually done with _add(T, ...) and
then _mov(dst, T) so that the dest is always register.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Change szbuild.py to prefer Subzero by default.
Jim Stichnoth [Fri, 26 Sep 2014 16:47:32 +0000 (09:47 -0700)]
Subzero: Change szbuild.py to prefer Subzero by default.

Subzero translation is stable enough that szbuild.py should prefer Subzero-translated symbols by default.  The exception is that if you explicitly use --include, the intuitive interpretation is that you only want Subzero to include those symbols (minus any given with --exclude).

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Use 'override' as appropriate for C++11.
Jim Stichnoth [Fri, 26 Sep 2014 16:28:46 +0000 (09:28 -0700)]
Subzero: Use 'override' as appropriate for C++11.

Not necessary for the LLVM 3.5 merge, but nice to have anyway.

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

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

9 years agoRemove broken szdiff tests.
Karl Schimpf [Fri, 26 Sep 2014 16:17:21 +0000 (09:17 -0700)]
Remove broken szdiff tests.

szdiff is an approximate match tool used in early tests. When
Subzero's bitcode reader tests already exist for failing cases of
szdiff, remove the broken tests.

BUG=None
R=stichnot@chromium.org

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

9 years agoFix undef test to use Subzero's bitcode reader.
Karl Schimpf [Fri, 26 Sep 2014 16:15:04 +0000 (09:15 -0700)]
Fix undef test to use Subzero's bitcode reader.

This test was previously failing because insertelement returned the
wrong type. However, a previous CL fixed this problem and the test
now works with Subzero's bitcode reader.

BUG=None
R=stichnot@chromium.org

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

9 years agoSubzero: Enable the C++11 build.
Jim Stichnoth [Fri, 26 Sep 2014 00:51:47 +0000 (17:51 -0700)]
Subzero: Enable the C++11 build.

This just adds -std=c++11 to the compiler flags and fixes the resulting errors/warnings.

Later CLs can fix things related to the LLVM 3.5 merge.

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

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

9 years agoFix bug in Subzero bitcode reader for insertelement instruction.
Karl Schimpf [Thu, 25 Sep 2014 21:04:12 +0000 (14:04 -0700)]
Fix bug in Subzero bitcode reader for insertelement instruction.

Instruction insertelement was incorrectly generating a result
corresponding to the element type, instead of the updated
vector type.

BUG= None
R=jvoung@chromium.org

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

9 years agoSubzero: Automatically infer regalloc preferences and overlap.
Jim Stichnoth [Thu, 25 Sep 2014 19:44:17 +0000 (12:44 -0700)]
Subzero: Automatically infer regalloc preferences and overlap.

Originally, for a given Variable, register preference and overlap were manually specified.  That is, when choosing a free register for a Variable, it would be manually specified which (if any) related Variable would be a good choice for register selection, all things being equal.  Also, it allowed the rather dangerous "AllowOverlap" specification which let the Variable use its preferred Variable's register, even if their live ranges overlap.

Now, all this selection is automatic, and the machinery for manual specification is removed.

A few other changes in this CL:

- Address mode inference leverages the more precise

- Better regalloc dump messages to follow the logic

- "-verbose most" enables all verbose options except regalloc and time

- "-ias" is an alias for "-integrated-as"

- Bug fix: prevent 8-bit register ah from being used in register allocation, unless it is pre-colored

- Bug fix: the _mov helper where Dest is NULL wasn't always actually creating a new Variable

- A few tests are updated based on slightly different O2 register allocation decisions

The static stats actually improve slightly across the board (around 1%), except that frame size improves by 6-10%.  This is probably from smarter register allocation decisions, particularly involving phi lowering temporaries, where the manual hints weren't too good to start with.

BUG= none
R=jvoung@chromium.org

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

9 years agoClean up run script to use for testing Subzero.
Karl Schimpf [Thu, 25 Sep 2014 16:37:49 +0000 (09:37 -0700)]
Clean up run script to use for testing Subzero.

Adds the python script run-llvm2ice.py (was llvm2iceinsts.py) that
automatically handles conversion of LLVM source to a PEXE file,
and then runs llvm2ice on the corresponding PEXE file.

Also, defines three paths in tests, based on the executable chosen:

  %lc2i - Directly reads from LLVM source, and converts to Subzero.
  %l2i  - Parses a PEXE file into LLVM IR, and converts to Subzero.
  %p2i  - Parses a PEXE directly into Subzero.

Note that for all three executables, the same arguments can be used,
making it easy to change how the input is handled.

Also moves tests to use %p2i whenever possible.

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

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

9 years agoHandle "inplace" ops and unary ops w/ assembler
Jan Voung [Wed, 24 Sep 2014 20:32:39 +0000 (13:32 -0700)]
Handle "inplace" ops and unary ops w/ assembler

Extend the bswap test to have a case which will exhibit a bit of register
pressure to test register encoding more (at first wasn't sure if it was
0xC8 + reg or 0xC8 | reg... but it should be the same since there's only
0-7 for regs).

BUG=none
R=stichnot@chromium.org

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

9 years agoHandle a few more instructions in assembler (cmov, cdq, cmpxchg, xadd, xchg).
Jan Voung [Tue, 23 Sep 2014 20:32:18 +0000 (13:32 -0700)]
Handle a few more instructions in assembler (cmov, cdq, cmpxchg, xadd, xchg).

BUG=none
R=stichnot@chromium.org

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

9 years agoAdd initial integrated assembler w/ some Xmm ops.
Jan Voung [Tue, 23 Sep 2014 01:02:25 +0000 (18:02 -0700)]
Add initial integrated assembler w/ some Xmm ops.

Add a flag to use the integrated assembler.

Handle simple XMM binary op instructions as an initial example of how
instructions might be handled. This tests fixups in a very limited sense --
Track buffer locations of fixups for floating point immediates.

Patchset one shows the original dart assembler code (revision 39313), so that
it can be diffed.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Refactor tracking of Defs and block-local Variables.
Jim Stichnoth [Mon, 22 Sep 2014 23:02:59 +0000 (16:02 -0700)]
Subzero: Refactor tracking of Defs and block-local Variables.

This affects tracking of two kinds of Variable metadata: whether a
Variable is block-local (i.e., all uses are in a single block) and if
so, which CfgNode that is; and whether a Variable has a single defining
instruction, and if so, which Inst that is.

Originally, this metadata was constructed incrementally, which was
quite fragile and most likely inaccurate under many circumstances.

In the new approach, this metadata is reconstructed in a separate pass
as needed.

As a side benefit, the metadata fields are removed from each Variable
and pulled into a separate structure, shrinking the size of Variable.

There should be no functional changes, except that simple stack slot
coalescing is turned off under Om1, since it takes a separate pass to
calculate block-local variables, and passes are minimized under Om1.
As a result, a couple of the lit tests needed to be changed.

There are a few non-mechanical changes, generally to tighten up
Variable tracking for liveness analysis.

This is being done mainly to get precise Variable definition
information so that register allocation can infer the best register
preferences as well as when overlapping live ranges are allowable.

BUG=none
R=jvoung@chromium.org

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

9 years agoMake tests stricter after fixing "lock foo" bundling bug.
Jan Voung [Mon, 22 Sep 2014 21:43:58 +0000 (14:43 -0700)]
Make tests stricter after fixing "lock foo" bundling bug.

Should be fixed now.

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

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

9 years agoTest generation of global initializers in Subzero bitcode reader.
Karl Schimpf [Mon, 22 Sep 2014 17:28:42 +0000 (10:28 -0700)]
Test generation of global initializers in Subzero bitcode reader.

Adds workaround that uses IceConverter's convertGlobals to
generate global initializers. This should complete the initial
implementation of Subzero's bitcode reader.

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

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

9 years agoSubzero: Change the way bitcast stack slot lowering is handled.
Jim Stichnoth [Sat, 20 Sep 2014 19:25:02 +0000 (12:25 -0700)]
Subzero: Change the way bitcast stack slot lowering is handled.

When doing a bitcast between int and FP types, the way lowering works
is that a spill temporary is created, with regalloc weight of zero to
inhibit register allocation, and this spill temporary is used for the
cvt instruction.  If the other variable does not get
register-allocated, then addProlog() forces the spill temporary to
share the same stack slot as the other variable.

Currently, the lowering code passes this information to addProlog()
by using the setPreferredRegister() mechanism.

This is changed by creating a target-specific subclass of Variable, so
that only the spill temporaries need to carry this extra information.

Ultimately, many of the existing Variable fields will be refactored
into a separate structure, and only generated/used as needed by
various optimization passes.  The spill temporary linkage is the one
thing that is still needed with Om1 when no optimizations are enabled,
motivating this change.

A couple other minor cleanups are also done here.

The key test is that the cast cross tests continue to work,
specifically the bitcast tests.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdjust paths for host_x86_32/bin -> bin and for switch to 64-bit.
Jan Voung [Fri, 19 Sep 2014 20:11:36 +0000 (13:11 -0700)]
Adjust paths for host_x86_32/bin -> bin and for switch to 64-bit.

See: https://codereview.chromium.org/580983002

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

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

9 years agoAdd call instructions to Subzero's bitcode reader.
Karl Schimpf [Fri, 19 Sep 2014 16:33:26 +0000 (09:33 -0700)]
Add call instructions to Subzero's bitcode reader.

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

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

9 years agoLift register and condition code enums out into their own file.
Jan Voung [Fri, 19 Sep 2014 01:18:10 +0000 (18:18 -0700)]
Lift register and condition code enums out into their own file.

Lift the enums out of IceInstX8632.h and IceTargetLoweringX8632.h.
This will later allow the assembler to share the enum values and
use them as encodings where appropriate. E.g., to avoid having a separate
enum in:
https://codereview.chromium.org/476323004/diff/680001/src/assembler_constants_ia32.h

The "all registers" enum is retained, but separate GPRRegister and
XmmRegister enums are created with tags "Encoded_Reg_foo" to represent
the encoded value of register "foo". Functions are added to convert
from the "all registers" namespace to the encoded ones.

Re-order the BrCond so that they match the encoding according to
the "Instruction Subcode" in B.1 of the Intel Manuals.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Allow extra args to be passed to llc and Subzero.
Jim Stichnoth [Thu, 18 Sep 2014 16:43:30 +0000 (09:43 -0700)]
Subzero: Allow extra args to be passed to llc and Subzero.

Use --llc to pass extra arguments to pnacl-translate.

Use --sz to pass extra arguments to llvm2ice.

The --stats argument is removed from the script because it is Subzero-only, and can now be done with --sz=--stats .

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Add branch optimization.
Jim Stichnoth [Thu, 18 Sep 2014 11:50:49 +0000 (04:50 -0700)]
Subzero: Add branch optimization.

1. Unconditional branch to the next basic block is removed.

2. For a conditional branch with a "false" edge to the next basic block, remove the unconditional branch to the fallthrough block.

3. For a conditional branch with a "true" edge to the next basic block, invert the condition and do like #2.

This is enabled only for O2, particularly because inverting the branch condition is a marginally risky operation.

This decreases the instruction count by about 5-6%.

Also, --stats prints a final tally to make it easier to post-process the output.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd switch instruction to Subzero bitcode reader.
Karl Schimpf [Wed, 17 Sep 2014 22:38:17 +0000 (15:38 -0700)]
Add switch instruction to Subzero bitcode reader.

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

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

9 years agoSubzero: Add a convenience script for Spec2K. Add the --stats argument.
Jim Stichnoth [Wed, 17 Sep 2014 16:42:53 +0000 (09:42 -0700)]
Subzero: Add a convenience script for Spec2K. Add the --stats argument.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd forward instruction declaration to Subzero bitcode reader.
Karl Schimpf [Wed, 17 Sep 2014 16:07:20 +0000 (09:07 -0700)]
Add forward instruction declaration to Subzero bitcode reader.

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

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

9 years agoSubzero: Use ccache for building, if available.
Jim Stichnoth [Wed, 17 Sep 2014 15:41:21 +0000 (08:41 -0700)]
Subzero: Use ccache for building, if available.

This is needed since we are now using an absolute (and non-standard) path to clang++.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Add rudimentary statistics on generated code.
Jim Stichnoth [Wed, 17 Sep 2014 02:59:35 +0000 (19:59 -0700)]
Subzero: Add rudimentary statistics on generated code.

The following are collected:
- Number of machine instructions emitted
- Number of registers saved/restored in prolog/epilog
- Number of stack frame bytes (non-alloca) allocated
- Number of "spills", or stores to stack slots
- Number of "fills", or loads/operations from stack slots
- Fill+Spill count (sum of above two)

These are somewhat reasonable approximations of code quality, and the primary intention is to compare before-and-after when trying out an optimization.

The statistics are dumped after translating each function.  Per-function and cumulative statistics are collected.  The output lines have a prefix that is easy to filter.

BUG= none
R=jvoung@chromium.org

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

9 years agoSplit ConstantInteger into ConstantInteger32 and ConstantInteger64.
Jan Voung [Tue, 16 Sep 2014 22:09:10 +0000 (15:09 -0700)]
Split ConstantInteger into ConstantInteger32 and ConstantInteger64.

In many cases, we expect a constant to be 32-bits or less.
This simplifies range checking for x86 memory operand displacements
(can only be 32-bit), or immediates in instructions (also 32-bit),
since we only store 32-bits (so it trivially fits in 32-bits).

Checks for whether a constant fits in 8-bits can be done on the 32-bit value
instead of the 64-bit value.

When TargetLowering sees a 64-bit immediate as an operand on a 64-bit
instruction, it should have split the 64-bit immediate into a 32-bit
loOperand(), and a 32-bit hiOperand(). So what's left for the Emit pass
should be 32-bit constants.

Other places which work with constants:
- intrinsic operands (the ABI only allows i32 params for atomic mem order,
  or atomic is lock free byte-size, or the longjmp param).
- addressing mode optimization (gep expansion should be working with
  i32 constants).
- insertelement, and extractelement constant indices (bitcode reader
  restricts the type of the index to be i32 also).

I guess now you may end up with multiple copies of what may be the
"same" constant (i64 0 vs i32 0).

BUG=none
R=stichnot@chromium.org

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

9 years agoAdd unreachable instruction to Subzero.
Karl Schimpf [Tue, 16 Sep 2014 20:35:32 +0000 (13:35 -0700)]
Add unreachable instruction to Subzero.

Also fixes error messages on instruction operands, to print
out the operand (rather than pointer to it), since we can
now print out operands.

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

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

9 years agoSubzero: Make python clean up after itself by removing its /tmp subdir.
Jim Stichnoth [Tue, 16 Sep 2014 17:22:26 +0000 (10:22 -0700)]
Subzero: Make python clean up after itself by removing its /tmp subdir.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Make the szbuild.py script more automatic.
Jim Stichnoth [Tue, 16 Sep 2014 17:19:03 +0000 (10:19 -0700)]
Subzero: Make the szbuild.py script more automatic.

One wants to omit the --init option to make things go faster, but then there's the risk that the pexe or llvm2ice or llc has changed and --init is actually necessary.

This change automatically compares the modification timestamps of the pexe and the llvm2ice and llc binaries against the modification timestamps of the object files to determine whether re-translation is needed.

The --init option forces re-translation regardless of timestamps.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Refactor Operand::dump().
Jim Stichnoth [Tue, 16 Sep 2014 17:16:00 +0000 (10:16 -0700)]
Subzero: Refactor Operand::dump().

A "standalone" version of dump() is provided, taking just an Ostream
argument and not requiring a Cfg or GlobalContext argument.

BUG= none
R=kschimpf@google.com

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

9 years agoFix makefile to use chrome clang to compile, so we link to LLVM.
Karl Schimpf [Mon, 15 Sep 2014 19:56:50 +0000 (12:56 -0700)]
Fix makefile to use chrome clang to compile, so we link to LLVM.

LLVM objects/libraries are now built using clang from chrome. This
CL changes the compiler to chrome clang, and adds an appropriate
dynamic library path to the linked executable so that llvm2ice
can be run in any directory.

BUG=None
R=jvoung@chromium.org

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

9 years agoSubzero: Fix incorrect address mode inference involving Phi temporaries.
Jim Stichnoth [Mon, 15 Sep 2014 17:42:14 +0000 (10:42 -0700)]
Subzero: Fix incorrect address mode inference involving Phi temporaries.

Also, refactor the key part of the address mode inference into separate functions, since it's getting unwieldy.

The main thing is that we mark phi temporaries as multi-definition, and disallow address mode inference transformations that involve such temporaries, because this is incorrect particular when there are backward branches involved.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Always be sure x87 FP stack is emptied after a call.
Jim Stichnoth [Fri, 12 Sep 2014 20:06:09 +0000 (13:06 -0700)]
Subzero: Always be sure x87 FP stack is emptied after a call.

In x86-32, floating point values are returned to the caller on the top of the x87 floating point stack.  The caller is required to remove it from the x87 FP stack, e.g. via the fstp instruction.

This must be done even when the return value is not actually used anywhere else in the function, in which case O2 is likely to want to dead-code eliminate the fstp instruction.

We enforce this by adding a fake use of the fstp destination.

BUG= none
R=jvoung@chromium.org

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

9 years agoSwitch to llvm::findFirstSet instead of ffs since mingw doesn't have ffs.
Jan Voung [Fri, 12 Sep 2014 18:05:47 +0000 (11:05 -0700)]
Switch to llvm::findFirstSet instead of ffs since mingw doesn't have ffs.

ffs() vs findFirstSet() are slightly different, indexing is
0-based instead of 1-based.

Example mingw error:
http://build.chromium.org/p/tryserver.nacl/builders/nacl-toolchain-win7-pnacl-x86_64/builds/1920/steps/llvm_i686_w64_mingw32%20%28build%29/logs/stdio

BUG=none
R=stichnot@chromium.org

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

9 years agoAllow ability to name unnamed global addresses in Subzero.
Karl Schimpf [Fri, 12 Sep 2014 17:41:40 +0000 (10:41 -0700)]
Allow ability to name unnamed global addresses in Subzero.

This is a workaround for issue that Subzero currently assumes all
global addresses have a name, but finalized pexe files leave most
global addresses unnamed.

It does this by allowing two optional command-line flag name prefixes
that are used to generate names for unnamed global addresses.

BUG= None
R=stichnot@chromium.org

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

9 years agoMark setjmp as "returns twice" and turn off SimpleCoalescing when called.
Jan Voung [Fri, 12 Sep 2014 02:18:03 +0000 (19:18 -0700)]
Mark setjmp as "returns twice" and turn off SimpleCoalescing when called.

BUG=none
R=stichnot@chromium.org

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

9 years agoAdd phi instruction to Subzero bitcode reader.
Karl Schimpf [Thu, 11 Sep 2014 21:42:49 +0000 (14:42 -0700)]
Add phi instruction to Subzero bitcode reader.

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

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

9 years agoSubzero: Print defaults as appropriate in python script help text.
Jim Stichnoth [Thu, 11 Sep 2014 16:47:59 +0000 (09:47 -0700)]
Subzero: Print defaults as appropriate in python script help text.

BUG= none
R=jfb@chromium.org

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

9 years agoFix symbol table handling in functions.
Karl Schimpf [Thu, 11 Sep 2014 16:43:47 +0000 (09:43 -0700)]
Fix symbol table handling in functions.

Also fixes minor issues with branches in instructions (i.e. defining
entry node and computing predecessors).

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

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

9 years agoFix bug introduced by CL 561883002.
Karl Schimpf [Wed, 10 Sep 2014 22:02:08 +0000 (15:02 -0700)]
Fix bug introduced by CL 561883002.

Fixes call to extractElement.

BUG= None
R=stichnot@chromium.org

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

9 years agoAdd load and store instructions to Subzero bitcode reader.
Karl Schimpf [Wed, 10 Sep 2014 21:36:07 +0000 (14:36 -0700)]
Add load and store instructions to Subzero bitcode reader.

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

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

9 years agoSubzero: Fix Phi lowering.
Jim Stichnoth [Wed, 10 Sep 2014 18:51:38 +0000 (11:51 -0700)]
Subzero: Fix Phi lowering.

This addresses a TODO and fixes a code generation bug that was causing sprintf and _vfprintf_r to execute incorrectly.

BUG= none
R=jvoung@chromium.org

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

9 years agoList Subzero's local optlevel flags after LLVM's cxxflags (precedence).
Jan Voung [Tue, 9 Sep 2014 23:36:42 +0000 (16:36 -0700)]
List Subzero's local optlevel flags after LLVM's cxxflags (precedence).

Ended up needing to fix the InstX8632Lockable error that JF ran into
now that -O0 is really -O0:
https://codereview.chromium.org/512933006/

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: The cross tests should use the actual Subzero runtime.
Jim Stichnoth [Tue, 9 Sep 2014 21:40:40 +0000 (14:40 -0700)]
Subzero: The cross tests should use the actual Subzero runtime.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd alloca instruction to Subzero bitcode reader.
Karl Schimpf [Tue, 9 Sep 2014 18:40:09 +0000 (11:40 -0700)]
Add alloca instruction to Subzero bitcode reader.

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

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

9 years agoSubzero: Add a script that builds a hybrid Subzero/llc native executable.
Jim Stichnoth [Tue, 9 Sep 2014 18:19:12 +0000 (11:19 -0700)]
Subzero: Add a script that builds a hybrid Subzero/llc native executable.

The script translates a pexe using both Subzero and llc, and then uses linker tricks to resolve each symbol into either its Subzero or llc version.  This enables quick bisection-based debugging of Subzero code generation.

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

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

9 years agoSubzero: Make sure alloca with align=0 is handled correctly.
Jim Stichnoth [Tue, 9 Sep 2014 00:56:50 +0000 (17:56 -0700)]
Subzero: Make sure alloca with align=0 is handled correctly.

1. Modify dump() to match LLVM.

2. If it weren't for minimum stack alignment, the alignment code would be broken, so add a test in case the alignment code changes.

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

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