OSDN Git Service

android-x86/external-swiftshader.git
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

9 years agoAdd constants block to PNaCl bitcode reader.
Karl Schimpf [Mon, 8 Sep 2014 20:41:09 +0000 (13:41 -0700)]
Add constants block to PNaCl 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/548553002

9 years agoSubzero: Move python scripts into a common pydir.
Jim Stichnoth [Mon, 8 Sep 2014 19:57:52 +0000 (12:57 -0700)]
Subzero: Move python scripts into a common pydir.

This makes it much easier to run scripts from different working directories, as long as they are run somewhere under the native_client directory.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Be more strict about i1 calculations.
Jim Stichnoth [Mon, 8 Sep 2014 18:19:21 +0000 (11:19 -0700)]
Subzero: Be more strict about i1 calculations.

One issue is that the test_arith cross test defined functions on i1 but never actually invoked them.

Another issue is that the lowering was using 8-bit registers for i1 values, but was being sloppy about leaving stuff in the upper 7 bits, and then using all 8 bits for tests.

This takes the approach of explicitly masking the result whenever it's possible for the result to exceed one bit, such as trunc, fptosi, fptoui.

Another possibility might be to allow the upper 7 bits to stay sloppy, and explicitly only test the lower bit.

Additionally, some "CHECK: ret" lines were removed, since they aren't actually needed after the change to use CHECK-LABEL, and they are affected by an llvm-dump bug (which is fixed in LLVM 3.6).

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Use cvttss2si and similar instead of cvtss2si for fp->int casts.
Jim Stichnoth [Mon, 8 Sep 2014 17:47:23 +0000 (10:47 -0700)]
Subzero: Use cvttss2si and similar instead of cvtss2si for fp->int casts.

This is the truncating cvt instruction instead of rounding.

A few interesting floating point inputs are added to the cross tests.

Also, the cross test error output is modified to be more clear.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd branch instructions to Subzero bitcode reader.
Karl Schimpf [Fri, 5 Sep 2014 15:32:47 +0000 (08:32 -0700)]
Add branch instructions to Subzero bitcode reader.

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

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

9 years agoAdd icmp and fcmp instructions to Subzero bitcode reader.
Karl Schimpf [Fri, 5 Sep 2014 15:30:55 +0000 (08:30 -0700)]
Add icmp and fcmp instructions 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/543793003

9 years agoSubzero: Fix sext/zext lowering with i1 source operands.
Jim Stichnoth [Thu, 4 Sep 2014 23:39:02 +0000 (16:39 -0700)]
Subzero: Fix sext/zext lowering with i1 source operands.

Also declare a few variables as Constant* instead of Operand* when they hold the result of Ctx->getConstantInt(), to be consistent with the rest of the code.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd select instruction to Subzero bitcode reader.
Karl Schimpf [Thu, 4 Sep 2014 19:22:14 +0000 (12:22 -0700)]
Add select instruction to Subzero bitcode reader.

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

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

9 years agoSubzero: Work around another llvm-mc parser bug for relocatable symbols.
Jim Stichnoth [Thu, 4 Sep 2014 18:32:20 +0000 (11:32 -0700)]
Subzero: Work around another llvm-mc parser bug for relocatable symbols.

There's already a hack that emits asm like:
  lea eax, myglobal
instead of:
  mov eax, [myglobal]
because of an llvm-mc parser bug.  However, the lea hack still doesn't work if the symbol is a reserved word, e.g.:
  lea eax, flags

The extra hack is to drop into AT&T syntax temporarily:
.att_syntax
  leal flags, %eax
.intel_syntax

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Make sure register preferences obey register class constraints.
Jim Stichnoth [Thu, 4 Sep 2014 17:37:49 +0000 (10:37 -0700)]
Subzero: Make sure register preferences obey register class constraints.

The bug was first spotted in the optimized gl_Color4ub() from spec2k's mesa.  The lowering sequences for fptosi and fptoui with i8 or i16 include "mov T_2, T_1" where T_1 and T_2 may have different integer types, and the statement:
      T_2->setPreferredRegister(T_1, true);

If T_2's type is i8 and T_1 is assigned a register that has no 8-bit version, then T_2 gets an unsuitable register.

The fix is to honor RegisterOverlap only when RegMask allows.

It's hard to construct a good test for this, since it depends heavily on register allocation decisions, which will change over time.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Render constants in dump() to be more like LLVM.
Jim Stichnoth [Wed, 3 Sep 2014 22:19:12 +0000 (15:19 -0700)]
Subzero: Render constants in dump() to be more like LLVM.

Integers are generally dumped as signed instead of unsigned values.
Integers of i1 type are dumped as 'false' and 'true'.  Floating point
values still don't match LLVM.

BUG= none
R=kschimpf@google.com

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

9 years agoAdd vector insert/extract instructions to Subzero bitcode reader.
Karl Schimpf [Wed, 3 Sep 2014 16:46:24 +0000 (09:46 -0700)]
Add vector insert/extract instructions to Subzero bitcode reader.

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

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

9 years agoSubzero: Rename -external to -externalize to match llc.
Jim Stichnoth [Tue, 2 Sep 2014 22:13:00 +0000 (15:13 -0700)]
Subzero: Rename -external to -externalize to match llc.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Remove the need for a separate NaCl SDK installation.
Jim Stichnoth [Tue, 2 Sep 2014 21:11:57 +0000 (14:11 -0700)]
Subzero: Remove the need for a separate NaCl SDK installation.

Now it assumes tests are being run from within the Subzero portion of the native_client tree, and sets up PATH to find PNaCl tools relative to there.

It may be necessary to do a one-time setup to be able to build pexes:

    pnacl/build.sh sdk newlib

or the equivalent scons commands.

If the tool chain is updated, propagate the changes via:

    toolchain_build/toolchain_build_pnacl.py llvm_i686_linux --install=toolchain/linux_x86/pnacl_newlib

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd cast instructions to subzero's pnacl bitcode translator.
Karl Schimpf [Tue, 2 Sep 2014 17:47:28 +0000 (10:47 -0700)]
Add cast instructions to subzero's pnacl bitcode translator.

Also clean up other error cases (in function block) to simply return, since they have already generated an error message.

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

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

9 years agoConvert lit tests to check disassembled assembly.
Jan Voung [Fri, 29 Aug 2014 19:59:02 +0000 (12:59 -0700)]
Convert lit tests to check disassembled assembly.

Then when we have an integrated assembler, we can check
its disassembly and the result should be the same.
This only touches the tests that invoke llvm-mc currently.
There are other tests which check for .s file output.

There are quite a bit of quirks with llvm-objdump,
which is unfortunate:

(*) The symbolizer doesn't pick up non-section-local
function calls. Some externals were converted to be
local functions. Workaround: where it counts, I just
left a check via .s files and a new --check-prefix.
It's a little better in 3.6.

(*) The symbolizer doesn't pick up global variable names.
I just checked for the relocation addend instead.
Didn't check if it was better in 3.6, but maybe.

(*) We have a bug in bundling lock + instructions.
See
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3929

(*) There's no disassembly for branch lables.
Checks of jump instructions were converted to check
for positive or negative values, depending on whether
it is a forward or backward branch.

BUG=none
R=stichnot@chromium.org

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

9 years agoAlign function starts to target-specific bundle alignment.
Jan Voung [Thu, 28 Aug 2014 23:00:53 +0000 (16:00 -0700)]
Align function starts to target-specific bundle alignment.

BUG=none
R=stichnot@chromium.org

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

9 years agoAdd pnacl-freeze to the tests_lit/lit.cfg. Also, unsigned vs signed.
Jan Voung [Thu, 28 Aug 2014 17:04:03 +0000 (10:04 -0700)]
Add pnacl-freeze to the tests_lit/lit.cfg. Also, unsigned vs signed.

Otherwise, I don't have pnacl-freeze in my path, and
I think the lit tests have trouble finding it.

src/PNaClTranslator.cpp: In member function ‘uint32_t {anonymous}::FunctionParser::convertRelativeToAbsIndex(int32_t)’:
src/PNaClTranslator.cpp:882:55: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
     if (Id > 0 && AbsNextId < static_cast<uint32_t>(Id)) {
                                                       ^
BUG=none
R=kschimpf@google.com, stichnot@chromium.org

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

9 years agoStart processing function blocks.
Karl Schimpf [Wed, 27 Aug 2014 22:34:58 +0000 (15:34 -0700)]
Start processing function blocks.

Handle binops and returns.

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

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

9 years agoSubzero: Fix address mode optimization involving phi temporaries.
Jim Stichnoth [Wed, 27 Aug 2014 20:50:03 +0000 (13:50 -0700)]
Subzero: Fix address mode optimization involving phi temporaries.

Also adds much-needed logging of the decision process that goes into the address mode optimization.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Fix the link command for Trusty.
Jim Stichnoth [Wed, 27 Aug 2014 18:02:50 +0000 (11:02 -0700)]
Subzero: Fix the link command for Trusty.

With the original link command, -lpthread comes before some other LLVM libraries, and this ends up causing undefined pthreads symbols.  The new link command makes sure the -lpthread part comes last.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Fix some legalization issues involving immediates.
Jim Stichnoth [Wed, 27 Aug 2014 05:16:29 +0000 (22:16 -0700)]
Subzero: Fix some legalization issues involving immediates.

Some lowering sequences were incorrectly allowing immediate operands in native instructions.  This includes 32-bit icmp, 64-bit icmp, select, switch, and 64-bit mul.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Add a check-lit target for faster smoke testing.
Jim Stichnoth [Tue, 26 Aug 2014 21:07:13 +0000 (14:07 -0700)]
Subzero: Add a check-lit target for faster smoke testing.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Fixes for Hello World and bisection debugging.
Jim Stichnoth [Tue, 26 Aug 2014 17:29:05 +0000 (10:29 -0700)]
Subzero: Fixes for Hello World and bisection debugging.

Add the llvm2ice -sandbox option (false by default) to select between
native and sandboxed code generation.  Currently, it controls whether
the llvm.nacl.read.tp intrinsic is lowered to gs:[0x0] or a call to
__nacl_read_tp.

Change the asm output slightly for -ffunction-sections so that objdump
is more willing to provide a disassembly.

BUG= none
R=jvoung@chromium.org

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

9 years agoRevert "COmmit"
Jim Stichnoth [Tue, 26 Aug 2014 16:26:02 +0000 (09:26 -0700)]
Revert "COmmit"

This was committed as a test, not actually intended.

This reverts commit 420e8bf2ebdc6e681838c018ca07e33e4321235f.

BUG=
R=dschuff@chromium.org

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

9 years agoCOmmit
Jim Stichnoth [Tue, 26 Aug 2014 16:00:14 +0000 (09:00 -0700)]
COmmit

Patch from Jim Stichnoth <stichnot@chromium.org>.

9 years agoSubzero: Fix the simple register allocation for -Om1.
Jim Stichnoth [Mon, 18 Aug 2014 17:55:19 +0000 (10:55 -0700)]
Subzero: Fix the simple register allocation for -Om1.

Background: After lowering each high-level ICE instruction, Om1 calls
postLower() to do simple register allocation.  It only assigns
registers where absolutely necessary, specifically for infinite-weight
variables, while honoring pre-coloring decisions.  The original Om1
register allocation never tried to reuse registers within a lowered
sequence, which was generally OK except for very long lowering
sequences, such as call instructions or some intrinsics.  In these
cases, when it ran out of physical registers, it would just reset the
free list and hope for the best, but with no guarantee of correctness.

The fix involves keeping track of which instruction in the lowered
sequence holds the last use of each variable, and releasing each
register back to the free list after its last use.  This makes much
better use of registers.  It's not necessarily optimal, at least with
respect to pre-colored variables, since those registers are
black-listed even if they don't interfere with an infinite-weight
variable.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Randomly insert nops.
Matt Wala [Fri, 15 Aug 2014 23:21:56 +0000 (16:21 -0700)]
Subzero: Randomly insert nops.

Adds command line options -nop-insertion, -nop-insertion-probability=X, and -max-nops-per-instruction=X.

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

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

9 years agoSubzero: Start a list of SIMD improvement ideas.
Matt Wala [Fri, 15 Aug 2014 22:02:13 +0000 (15:02 -0700)]
Subzero: Start a list of SIMD improvement ideas.

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

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

9 years agoSubzero: Align spill locations to natural alignment.
Matt Wala [Thu, 14 Aug 2014 21:24:12 +0000 (14:24 -0700)]
Subzero: Align spill locations to natural alignment.

This requires sorting the spilled variables based on alignment and
introducing additional padding around the spill location areas.

These changes allow vector instructions to accept memory operands.

Old stack frame layout:  New stack frame layout:
+---------------------+  +---------------------+
| return address      |  | return address      |
+---------------------+  +---------------------+
| preserved registers |  | preserved registers |
+---------------------+  +---------------------+
| global spill area   |  | padding             |
+---------------------+  +---------------------+
| local spill area    |  | global spill area   |
+---------------------+  +---------------------+
| padding             |  | padding             |
+---------------------+  +---------------------+
| local variables     |  | local spill area    |
+---------------------+  +---------------------+
                         | padding             |
                         +---------------------+
                         | local variables     |
                         +---------------------+

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

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

9 years agoEmit .local before .comm for bss to make llvm-mc happy.
Jan Voung [Thu, 14 Aug 2014 15:20:44 +0000 (08:20 -0700)]
Emit .local before .comm for bss to make llvm-mc happy.

Otherwise llvm-mc asserts. This is also the order that llc emits the directives.
Change a couple of RUIN -> RUN in lit tests.

BUG=none
R=stichnot@chromium.org

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

9 years agoConvert lit test llvm-mc -arch arguments to full -triple.
Jan Voung [Wed, 13 Aug 2014 20:20:58 +0000 (13:20 -0700)]
Convert lit test llvm-mc -arch arguments to full -triple.

Mostly to make them a bit more portable across OSes.
Otherwise the OS assumed by llvm-mc is the build/host OS. So,
on Mac llvm-mc will assume it's targeting darwin and only accepts macho
assembler directives. Assembler directives like .rodata.cst8 are not accepted
(I'm guessing it uses .cstring, .literal4, etc. instead?).

Force an OS (NaCl) so that ELF-related assembler macros make sense.

Also remove a now unused function typeIdentString to make clang happy.

Example errors:
Command 5 Stderr:
<stdin>:5:2: error: unknown directive
        .type   fixed_400,@function
        ^
<stdin>:23:2: error: unknown directive
        .type   variable_n,@function
        ^
<stdin>:40:11: error: mach-o section specifier uses an unknown section type
        .section        .rodata.cst4,"aM",@progbits,4
                        ^
<stdin>:42:11: error: mach-o section specifier uses an unknown section type
        .section        .rodata.cst8,"aM",@progbits,8
                        ^

BUG=none
R=stichnot@chromium.org, wala@chromium.org

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

9 years agoSubzero: Factor our commonalities between mov-like instructions.
Matt Wala [Tue, 12 Aug 2014 20:15:04 +0000 (13:15 -0700)]
Subzero: Factor our commonalities between mov-like instructions.

Introduce a base class for mov, movq, and movp instruction classes.

BUG=none
R=jvoung@chromium.org

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

9 years agoSubzero: Align the stack at the point of function calls.
Matt Wala [Tue, 12 Aug 2014 02:56:19 +0000 (19:56 -0700)]
Subzero: Align the stack at the point of function calls.

Be compatible with the x86-32 calling convention by ensuring that the
stack is aligned to 16 bytes at the point of the call
instruction. Also ensure that vector arguments passed on the stack are
16 byte aligned.

Also, make alloca instructions respect alignment.

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

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

9 years agoSubzero: address mode opt: Transform *(reg+const) into [reg+const].
Matt Wala [Tue, 12 Aug 2014 00:46:58 +0000 (17:46 -0700)]
Subzero: address mode opt: Transform *(reg+const) into [reg+const].

Teach address mode optimization about Base=Base+Const,
Base=Const+Base, and Base=Base-Const patterns.

Change ConstantInteger::emit() to emit signed values.

BUG=none
R=jvoung@chromium.org

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

9 years agoSubzero: Fix a debugging string in the test_icmp crosstest.
Matt Wala [Tue, 12 Aug 2014 00:44:40 +0000 (17:44 -0700)]
Subzero: Fix a debugging string in the test_icmp crosstest.

STR(inst) should be STR(cmp).

BUG=none
R=jvoung@chromium.org

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

9 years agoSubzero: Add a random number generator.
Matt Wala [Fri, 8 Aug 2014 21:02:09 +0000 (14:02 -0700)]
Subzero: Add a random number generator.

This is inital work necessary for diversification support in Subzero.
The random number generator implementation is temporary.  It will
eventually use a cryptographically secure pseudorandom number
generator (perhaps from LLVM, if LLVM gets one).

Add the -rng-seed= option to seed the random number generator from
the command line.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Add the "llvm2ice -ffunction-sections" argument.
Jim Stichnoth [Fri, 8 Aug 2014 17:13:44 +0000 (10:13 -0700)]
Subzero: Add the "llvm2ice -ffunction-sections" argument.

The purpose is to enable bisection debugging of Subzero-translated functions, using objcopy to selectively splice functions from llc and Subzero into the binary.

Note that llvm-mc claims to take this argument, but actually does nothing with it, so we need to implement it in Subzero.

Also moves the ClFlags object into the GlobalContext so everyone can access it.

BUG= none
R=wala@chromium.org

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

9 years agoSubzero: Make InstX8632Cbwdq a UnaryOp.
Matt Wala [Fri, 8 Aug 2014 15:39:40 +0000 (08:39 -0700)]
Subzero: Make InstX8632Cbwdq a UnaryOp.

After the changes in CL 443203003, InstX8632Cbwdq fits the template for
a UnaryOp, so change it to be in instance of this class.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Use scalar arithmetic when no vector instruction exists.
Matt Wala [Thu, 7 Aug 2014 20:47:30 +0000 (13:47 -0700)]
Subzero: Use scalar arithmetic when no vector instruction exists.

Implement scalarizeArithmetic() which extracts the components of the
input vectors, performs the operation with scalar instructions, and
builds the output vector component by component.

Fix the lowering of sdiv and srem.  These were previously emitting a
wrong instruction (cdq) for i8 and i16 inputs (needing cbw, cwd).

In the test_arith crosstest, mask the inputs to vector shift
operations to ensure that the shifts are in range.  Otherwise the
Subzero output is not identical to the llc output in some (undefined)
cases.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: A few fixes toward running larger programs.
Jim Stichnoth [Thu, 7 Aug 2014 17:58:05 +0000 (10:58 -0700)]
Subzero: A few fixes toward running larger programs.

1. Add 'llvm2ice -disable-globals' to disable Subzero translation of
global initializers, since full support isn't yet implemented.

2. Change the names of intra-block branch target labels to avoid
collisions with basic block labels.

3. Fix lowering of "br i1 <constant>, label ...", which was producing
invalid instructions like "cmp 1, 0".

4. Fix the "make format-diff" operation, which was diffing against the wrong target.

BUG= none
R=wala@chromium.org

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