OSDN Git Service

android-x86/external-swiftshader.git
9 years agoSubzero ARM: addProlog/addEpilogue -- share some code with x86.
Jan Voung [Mon, 1 Jun 2015 18:04:04 +0000 (11:04 -0700)]
Subzero ARM: addProlog/addEpilogue -- share some code with x86.

Split out some of the addProlog code from x86 and
reuse that for ARM. Mainly, the code that doesn't
concern preserved registers or stack arguments is split out.

ARM push and pop take a whole list of registers (not
necessarily consecutive, but should be in ascending order).
There is also "vpush" for callee-saved float/vector
registers but we do not handle that yet (the register
numbers for that have to be consecutive).

Enable some of the int-arg.ll tests, which relied on
addPrologue's finishArgumentLowering to pull from the
correct argument stack slot.

Test some of the frame pointer usage (push/pop) when
handling a variable sized alloca.

Also change the classification of LR, and PC so that
they are not "CalleeSave". We don't want to push LR
if it isn't overwritten by another call. It will certainly be
"used" by the return however. The prologue code only checks
if a CalleeSave register is used somewhere before deciding
to preserve it. We could make that stricter and check if
the register is also written to, but there are some
additional writes that are not visible till after the
push/pop are generated (e.g., copy from argument stack slot
to the argument register). Instead, keep checking use
only, and handle LR as a special case (IsLeafFunction).

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

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

9 years agoSubzero: Fold the load instruction into the next cast instruction.
Jim Stichnoth [Mon, 1 Jun 2015 06:34:44 +0000 (23:34 -0700)]
Subzero: Fold the load instruction into the next cast instruction.

This is similar to the way a load instruction may be folded into the next arithmetic instruction.

Usually the effect is to improve a sequence like:
  mov ax, WORD PTR [mem]
  movsx eax, ax
into this:
  movsx eax, WORD PTR [mem]
without actually improving register allocation, though other kinds of casts may have different improvements.

Existing tests needed to be fixed when they "inadvertently" did a cast to i32 return type and triggered the optimization when it wasn't wanted.  These were fixed by inserting a "dummy" instruction between the load and the cast.

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

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

9 years agoUse ldr for movs out of stack slots (instead of mov reg, [sp/fp]).
Jan Voung [Wed, 27 May 2015 21:34:34 +0000 (14:34 -0700)]
Use ldr for movs out of stack slots (instead of mov reg, [sp/fp]).

So far we've been using ldr/str (32-bit) to load/store
the whole stack slot, independent of the variable type.

Toggle on some tests that didn't have an Om1 variant
previously. Didn't toggle everything since there are still
some problems with liveness from code being unimplemented.

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

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

9 years agoSubzero: More asm-verbose fixes.
Jim Stichnoth [Wed, 27 May 2015 17:41:07 +0000 (10:41 -0700)]
Subzero: More asm-verbose fixes.

It turns out that code deleted in 9a05aea88a8d9484d5f0ea1f2eabf52ee5a3647f actually had a legitimate purpose, so it is added back, this time with more extensive comments justifying it.

Also, takes the instruction's IsDestNonKillable flag into account when updating the live register usage count (along with extra comments on why that is necessary).

Furthermore, removes an unnecessary assert that otherwise fails when --asm-verbose is used with --filetype=iasm or --filetype-obj.

BUG= none
R=jvoung@chromium.org

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

9 years agoRemove the FrameSizeLocals field which appears to be unused (write-only).
Jan Voung [Wed, 27 May 2015 17:04:17 +0000 (10:04 -0700)]
Remove the FrameSizeLocals field which appears to be unused (write-only).

Might have gotten replaced by some other field, but don't
quite remember. Spotted while looking for ways to share
the addProlog() code between targets.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Fix/improve -asm-verbose output.
Jim Stichnoth [Tue, 26 May 2015 23:01:23 +0000 (16:01 -0700)]
Subzero: Fix/improve -asm-verbose output.

Fixes a bug where a num-uses counter wasn't being updated because of C
operator && semantics.  The code was something like "if (A && --B) ..."
but we want --B to happen even when A is false.

Sorts the LiveIn and LiveOut lists by regnum so that the lists always
display the set of registers in a consistent/familiar order.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero ARM: lower alloca instruction.
Jan Voung [Tue, 26 May 2015 21:25:40 +0000 (14:25 -0700)]
Subzero ARM: lower alloca instruction.

Lower alloca in a way similar to x86. Subtract the stack
and align if needed, then copy that stack address to dest.
Sometimes use "bic" for the mask, sometimes use "and",
depending on what fits better.

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

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

9 years agoSubzero ARM: do lowerIcmp, lowerBr, and a bit of lowerCall.
Jan Voung [Fri, 22 May 2015 23:35:25 +0000 (16:35 -0700)]
Subzero ARM: do lowerIcmp, lowerBr, and a bit of lowerCall.

Allow instructions to be predicated and use that in lower icmp
and branch. Tracking the predicate for almost every instruction
is a bit overkill, but technically possible. Add that to most of
the instruction constructors except ret and call for now.

This doesn't yet do compare + branch fusing, but it does handle
the branch fallthrough to avoid branching twice.

I can't yet test 8bit and 16bit, since those come from "trunc"
and "trunc" is not lowered yet (or load, which also isn't
handled yet).

Adds basic "call(void)" lowering, just to get the call markers
showing up in tests.

64bit.pnacl.ll no longer explodes with liveness consistency errors,
so risk running that and backfill some of the 64bit arith tests.

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

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

9 years agoSubzero: Use setcc for most fcmp conditions, instead of control flow.
Jim Stichnoth [Fri, 22 May 2015 20:17:30 +0000 (13:17 -0700)]
Subzero: Use setcc for most fcmp conditions, instead of control flow.

For C/C++ semantics, this applies to all the FP comparisons except == and != which require two comparisons due to ordered/unordered requirements.  For == and !=, two comparisons and control flow are still used.

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

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

9 years agoLower a few basic ARM binops for i{8,16,32,64}.
Jan Voung [Tue, 19 May 2015 18:24:51 +0000 (11:24 -0700)]
Lower a few basic ARM binops for i{8,16,32,64}.

Do basic lowering for add, sub, and, or, xor, mul.
We don't yet take advantage of commuting immediate operands
(e.g., use rsb to reverse subtract instead of sub) or
inverting immediate operands (use bic to bit clear instead
of using and).

The binary operations can set the flags register (e.g., to
have the carry bit for use with a subsequent adc
instruction). That is optional for the "data processing"
instructions.

I'm not yet able to compile 8bit.pnacl.ll and
64bit.pnacl.ll so 8-bit and 64-bit are not well tested yet.
Only tests are in the arith.ll file (like arith-opt.ll, but
assembled instead of testing the "verbose inst" output).

Not doing divide yet. ARM divide by 0 does not trap, but
PNaCl requires uniform behavior for such bad code. Thus,
in LLVM we insert a 0 check and would have to do the same.

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

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

9 years agoSubzero: Use cmov to improve lowering for the select instruction.
Jim Stichnoth [Tue, 19 May 2015 16:48:44 +0000 (09:48 -0700)]
Subzero: Use cmov to improve lowering for the select instruction.

This is instead of explicit control flow which may interfere with branch prediction.  However, explicit control flow is still needed for types other than i16 and i32, due to cmov limitations.

The assembler for cmov is extended to allow the non-dest operand to be a memory operand.

The select lowering is getting large enough that it was in our best interest to combine the default lowering with the bool-folding optimization.

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

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

9 years agoSubzero ARM: lowerArguments (GPR), basic legalize(), and lowerRet(i32, i64).
Jan Voung [Mon, 18 May 2015 16:38:21 +0000 (09:38 -0700)]
Subzero ARM: lowerArguments (GPR), basic legalize(), and lowerRet(i32, i64).

Adds basic assignment instructions, mov, movn, movw, movt,
ldr, etc. in order to copy around the first few integer
(i32, i64) arguments out of r0 - r3, and then return then.

The "mov" instruction is a bit special and can actually
be a "str" when the dest is a stack slot.

Model the Memory operand types, and the "flexible Operand2".
Add a few tests demonstrating the flexibility of the
immediate encoding.

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

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

9 years agoSubzero: Fold icmp into br/select lowering.
Jim Stichnoth [Sun, 17 May 2015 17:11:41 +0000 (10:11 -0700)]
Subzero: Fold icmp into br/select lowering.

Originally there was a peephole-style optimization in lowerIcmp() that looks ahead to see if the next instruction is a conditional branch with the right properties, and if so, folds the icmp and br into a single lowering sequence.

However, sometimes extra instructions come between the icmp and br instructions, disabling the folding even though it would still be possible.

One thought is to do the folding inside lowerBr() instead of lowerIcmp(), by looking backward for a suitable icmp instruction.  The problem here is that the icmp lowering code may leave lowered instructions that can't easily be dead-code eliminated, e.g. instructions lacking a dest variable.

Instead, before lowering a basic block, we do a prepass on the block to identify folding candidates.  For the icmp/br example, the prepass would tentatively delete the icmp instruction and then the br lowering would fold in the icmp.

This folding can also be extended to several producers:
  icmp (i32 operands), icmp (i64 operands), fcmp, trunc .. to i1
and several consumers:
  br, select, sext, zext

This CL starts with 2 combinations: icmp32 paired with br & select.  Other combinations will be added in later CLs.

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

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

9 years agoChange a build-attribute REQUIRES check to use supported not requested.
Jan Voung [Sat, 16 May 2015 00:02:52 +0000 (17:02 -0700)]
Change a build-attribute REQUIRES check to use supported not requested.

Previously it would print both the targets compiled-in and the
target requested on the commandline, but we really only care
about what's compiled-in.

BUG=none
R=stichnot@chromium.org

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

9 years agoConvert Constant->emit() definitions to allow multiple targets to define them.
Jan Voung [Thu, 14 May 2015 16:26:19 +0000 (09:26 -0700)]
Convert Constant->emit() definitions to allow multiple targets to define them.

Wasn't sure how to allow TargetX8632 and TargetARM32
to both define "ConstantInteger32::emit(GlobalContext *)",
and define them differently if both targets happen to be
ifdef'ed into the code. Rearranged things so that it's now
"TargetFoo::emit(ConstantInteger32 *)", so that each
TargetFoo can have a separate definition.

Some targets may allow emitting some types of constants
while other targets do not (64-bit int for x86-64?).
Also they emit constants with a different style.
E.g., the prefix for x86 is "$" while the prefix for ARM
is "#" and there isn't a prefix for mips(?).
Renamed emitWithoutDollar to emitWithoutPrefix.

Did this sort of multi-method dispatch via a visitor
pattern, which is a bit verbose though.

We may be able to remove the emitWithoutDollar/Prefix for
ConstantPrimitive by just inlining that into the few places
that need it (only needed for ConstantInteger32). This
undoes the unreachable methods added by: https://codereview.chromium.org/1017373002/diff/60001/src/IceTargetLoweringX8632.cpp
The only place extra was for emitting calls to constants.
There was already an inlined instance for OperandX8632Mem.

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

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

9 years agoHandle ARM "ret void" and function alignment with proper padding.
Jan Voung [Tue, 12 May 2015 16:53:50 +0000 (09:53 -0700)]
Handle ARM "ret void" and function alignment with proper padding.

Modify run-pnacl-sz to pass in the correct assembler/disasembler flags
for ARM when not using the integrated assembler.

Model the "ret" pseudo instruction (special form of
"bx" inst). Separate from "bx" to allow epilogue
insertion to find the terminator.

Add a flag "--skip-unimplemented" to skip through all of the
"Not yet implemented" assertions, and use that in the test.

Set up a stack trace printer when ALLOW_DUMP so that the
UnimplementedError prints out some useful information of
*which* case is unimplemented.

Change the .type ...,@function from @function to %function.
ARM assembler seems to only like %function because
"@" is a comment character.

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

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

9 years agoUpdate subzero bitcode parser to use new API for bitstream reading.
Karl Schimpf [Tue, 12 May 2015 15:26:23 +0000 (08:26 -0700)]
Update subzero bitcode parser to use new API for bitstream reading.

Dependent on https://codereview.chromium.org/1122423005
being committed first.

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

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

9 years agoSubzero: Simplify the icmp i64 lowering.
Jim Stichnoth [Thu, 7 May 2015 16:35:07 +0000 (09:35 -0700)]
Subzero: Simplify the icmp i64 lowering.

The original code for 64-bit icmp lowering had separate cases for
eq/ne versus other conditions, mostly because eq/ne need two 32-bit
comparisons while the others need three.  However, with small changes,
we can handle everything uniformly, simplifying the code.

This gets thoroughly tested by the test_icmp cross test.

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

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

9 years agoSubzero: Use a setcc sequence for better icmp lowering.
Jim Stichnoth [Mon, 4 May 2015 17:22:17 +0000 (10:22 -0700)]
Subzero: Use a setcc sequence for better icmp lowering.

For an example like:
  %a = icmp eq i32 %b, %c

The original icmp lowering sequence for i8/i16/i32 was something like:

  cmpl b, c
  movb 1, a
  je label
  movb 0, a
label:

The improved sequence is:
  cmpl b, c
  sete a

In O2 mode, this doesn't help when successive compare/branch instructions are fused, but it does help when the boolean result needs to be saved and later used.

BUG= none
R=jvoung@chromium.org

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

9 years agoFix instruction unit tests to use new editing constants.
Karl Schimpf [Thu, 30 Apr 2015 22:32:04 +0000 (15:32 -0700)]
Fix instruction unit tests to use new editing constants.

Fixes code to follow new editing constants in class NaClMungedBitcode
rather than obsolete editing constants in class NaClBitcodeMunger.

BUG=None
R=jvoung@chromium.org

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

9 years agoRename AssemblerX86 to AssemblerX8632 so it works with SZTargets.def.
Jan Voung [Thu, 30 Apr 2015 21:15:10 +0000 (14:15 -0700)]
Rename AssemblerX86 to AssemblerX8632 so it works with SZTargets.def.

This is to conditionally (ifdef) include only the enabled
target assemblers. Also rename the assembler's "x86"
namespace to "X8632" for similar reasons. The namespace was
created to hide generic sounding classes like "Address"
which are used all over the assembler.

Plop the somewhat empty AssemblerARM32 in an ARM32
namespace for consistency.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Also dump live-end info for stack vars under -asm-verbose.
Jim Stichnoth [Thu, 30 Apr 2015 19:26:22 +0000 (12:26 -0700)]
Subzero: Also dump live-end info for stack vars under -asm-verbose.

It's sometimes useful to know whether a use of a stack variable (as opposed to a physical register) is the last use of that variable.  For example, in a code sequence like:
  movl %edx, 24(%esp)
  movl 24(%esp), %edx
it would be nice to know whether the code sequence is merely bad (i.e., 24(%esp) will be used later), or horrible (i.e., this ends 24(%esp)'s live range).

We add stack variables to the per-instruction live-range-end annotation, but not to the per-block live-in and live-out annotations, because the latter would clutter the output greatly while adding very little actionable information.

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

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

9 years agoSubzero: Produce actually correct code in --asm-verbose mode.
Jim Stichnoth [Wed, 29 Apr 2015 17:20:07 +0000 (10:20 -0700)]
Subzero: Produce actually correct code in --asm-verbose mode.

The "pnacl-sz --asm-verbose=1" mode annotates the asm output with physical register liveness information, including which registers are live at the beginning and end of each basic block, and which registers' live ranges end at each instruction.  Computing this information requires a final liveness analysis pass.  One of the side effects of liveness analysis is to remove dead instructions, which happens when the instruction's dest variable is not live and the instruction lacks important side effects.

In some cases, direct manipulation of physical registers was missing extra fakedef/fakeuse/etc., and as as result these instructions could be eliminated, leading to incorrect code.  Without --asm-verbose, these instructions were being created after the last run of liveness analysis, so they had no chance of being eliminated and everything was fine.  But with --asm-verbose, some instructions would be eliminated.

This CL fixes the omissions so that the resulting code is runnable.

An alternative would be to add a flag to liveness analysis directing it not to dead-code eliminate any more instructions.  However, it's better to get the liveness right in case future late-stage optimizations rely on it.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4135
TEST= pydir/szbuild_spec2k.py --filetype=asm -v --sz=--asm-verbose=1 --force
R=jvoung@chromium.org, kschimpf@google.com

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

9 years agoSubzero: Fix asm (non-ELF) output files.
Jim Stichnoth [Tue, 28 Apr 2015 21:12:20 +0000 (14:12 -0700)]
Subzero: Fix asm (non-ELF) output files.

In an earlier version of Subzero, the text output stream object was
stack-allocated within main.  A later refactoring moved its allocation
into a helper function, but it was still being stack-allocated, which
was bad when the helper function returned.

This change allocates the object via "new", which fixes that problem,
but reveals another problem: the raw_ostream object for some reason
doesn't finish writing everything to disk and yielding a truncated
output file.  This is solved in the style of the ELF streamer, by
using raw_fd_ostream instead.

BUG= none
R=kschimpf@google.com

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

9 years agoFirst attempt to capture parser/translation errors in browser.
Karl Schimpf [Wed, 22 Apr 2015 22:20:16 +0000 (15:20 -0700)]
First attempt to capture parser/translation errors in browser.

Adds a notion of an (optional) error stream to the existing
log and emit streams. If not specified, the log stream is used.
Error messages in parser/translation are sent to this new error
stream.

In the browser compiler server, a separate error (string) stream is
created to capture errors. Method onEndCallBack returns the contents
of the error stream (if non-empty) instead of a generic error message.

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

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

9 years agoAdd a basic TargetARM32 skeleton which knows nothing.
Jan Voung [Wed, 22 Apr 2015 00:01:49 +0000 (17:01 -0700)]
Add a basic TargetARM32 skeleton which knows nothing.

Later commits will add more information, but this tests the
conditional compilation and build setup.

One way to do conditional compilation: determine this
early, at LLVM configure/CMake time. Configure will
fill in the template of SZTargets.def.in to get
a SZTargets.def file.

LLVM change:
https://codereview.chromium.org/1084753002/

NaCl change:
https://codereview.chromium.org/1082953002/

I suppose an alternative is to fill in the .def file via
-D flags in CXXFLAGS.

For conditional lit testing, pnacl-sz dumps the attributes
when given the --build-atts so we just build on top of that.
We do that instead of go the LLVM way of filling in a
lit.site.cfg.in -> lit.site.cfg at configure/CMake time.

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

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

9 years agoSubzero: Improve "make check-unit" execution.
Jim Stichnoth [Tue, 21 Apr 2015 22:05:22 +0000 (15:05 -0700)]
Subzero: Improve "make check-unit" execution.

If you switch between "cmake" and "autoconf" toolchain builds, and
neglect to clean out pnacl_newlib_raw/ in between, the wrong libgtest
and libgtest_main may get pulled in for the autoconf build, leading to
an assertion failure in "make check-unit".

This tweak fixes that problem by rejiggering the lib search path.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Auto-detect cmake versus autoconf LLVM build.
Jim Stichnoth [Tue, 21 Apr 2015 16:59:21 +0000 (09:59 -0700)]
Subzero: Auto-detect cmake versus autoconf LLVM build.

The CMAKE=1 option is no longer needed.

Pretty much all the tools we need are now in pnacl_newlib_raw/bin, so use PNACL_BIN_PATH set to that instead of using LLVM_BIN_PATH and BINUTILS_BIN_PATH.

However, for the autoconf build, libgtest and libtest_main and clang-format are only under the llvm_x86_64_linux_work directory, so they need special casing.  This also means that you have to actually do an LLVM build and not blow away the work directory in order to "make check-unit" or "make format".

BUG= none
R=jvoung@chromium.org

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

9 years agoFix locking for printing error messages.
Karl Schimpf [Thu, 16 Apr 2015 22:47:25 +0000 (15:47 -0700)]
Fix locking for printing error messages.

Same as CL https://codereview.chromium.org/1071423003 (which has LGTM).

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4138

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

9 years agoRevert "Fix locking for printing error messages."
Karl Schimpf [Thu, 16 Apr 2015 22:11:07 +0000 (15:11 -0700)]
Revert "Fix locking for printing error messages."

This reverts commit 187b3dfab5cca45e2af192bf7f5db09bcc156314.

A unit test fails when it shouldn't.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4138

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

9 years agoRevert "Revert "Adjust Subzero CMAKE=1 build to also use libc++ (like autoconf).""
Karl Schimpf [Thu, 16 Apr 2015 22:08:05 +0000 (15:08 -0700)]
Revert "Revert "Adjust Subzero CMAKE=1 build to also use libc++ (like autoconf).""

This reverts commit a73408832dd716c3d076fe7f612194de614d7eee.

I reverted the wrong patch!

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4138

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

9 years agoRevert "Adjust Subzero CMAKE=1 build to also use libc++ (like autoconf)."
Karl Schimpf [Thu, 16 Apr 2015 22:03:49 +0000 (15:03 -0700)]
Revert "Adjust Subzero CMAKE=1 build to also use libc++ (like autoconf)."

This reverts commit d8fb3d33f38258b7fb177bd4cb420fab2e0c2c3a.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4138

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

9 years agoFix locking for printing error messages.
Karl Schimpf [Thu, 16 Apr 2015 20:50:43 +0000 (13:50 -0700)]
Fix locking for printing error messages.

The method TopLevelParser::ErrorAt applies a lock to print the error
message. Unfortunately, it keeps the lock longer than necessary,
resulting in deadlock (on following fatal message) if error recovery
is not allowed.

Fixed by limiting scope of lock to only apply to the printing of the
error message.

Modified ClFlags to allow a "reset", and made ClFlags modifiable
by bitcode munge tests. This allowed us to test this problem as
a unit test.

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

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

9 years agoAdjust Subzero CMAKE=1 build to also use libc++ (like autoconf).
Jan Voung [Fri, 10 Apr 2015 17:50:47 +0000 (10:50 -0700)]
Adjust Subzero CMAKE=1 build to also use libc++ (like autoconf).

This is to go with toolchain_build changes which make LLVM cmake
also use libc++:
https://codereview.chromium.org/978963002/

May help with the memory sanitizer build, which wants most code
to be built with memory sanitizer (e.g., make a special build of libc++).

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

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

9 years agoSubzero: Use a "deterministic" random shuffle for register allocation.
Jim Stichnoth [Thu, 9 Apr 2015 18:19:38 +0000 (11:19 -0700)]
Subzero: Use a "deterministic" random shuffle for register allocation.

To make this work, Subzero provides its own RandomShuffle() as a replacement for std::random_shuffle(), and the Subzero implementation doesn't depend on the stdlib implementation.

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

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

9 years agoSubzero: Deterministically sort constant pool entries.
Jim Stichnoth [Thu, 9 Apr 2015 16:11:18 +0000 (09:11 -0700)]
Subzero: Deterministically sort constant pool entries.

Otherwise, constant pools are emitted in hash table order, which can vary across systems.

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

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

9 years agoSubzero: Fix the standalone build to work with the LLVM cmake build.
Jim Stichnoth [Tue, 7 Apr 2015 21:22:25 +0000 (14:22 -0700)]
Subzero: Fix the standalone build to work with the LLVM cmake build.

Autoconf is the default.  Use "make -f Makefile.standalong CMAKE=1" to use the cmake build.

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

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

9 years agoRemoving 3 gcc warnings:
Mircea Trofin [Mon, 6 Apr 2015 23:06:47 +0000 (16:06 -0700)]
Removing 3 gcc warnings:

- redundant ';' after namespace decls
- mix of enums and integer values
- use of && insteand of & for bitwise operations

BUG=NONE
R=stichnot@chromium.org

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

9 years agoAdd argv[0] before parsing commandline flags.
Jan Voung [Tue, 31 Mar 2015 21:14:20 +0000 (14:14 -0700)]
Add argv[0] before parsing commandline flags.

The \0 delimited string array that the browser sends doesn't have
the program name and the IRT only tokenizes that and forwards
it along. We need argv[0] to make the llvm CL parser happy
(used for -help message, etc).

Alternatively, we could have the IRT fill in a program name
so that the argv is a real argv. That will involve less copying since
the argv will be the right size to begin with, but prevents each app
from customizing its argv[0] =/

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4091
TEST= manual for now (construct the sel_universal script to only pass
the "--build-atts" flag and see it exits without being swallowed,
or pass "-Ofoo" and see an error + exit)

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

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

9 years agoSubzero: Fix the cmake build.
Jim Stichnoth [Mon, 30 Mar 2015 21:32:23 +0000 (14:32 -0700)]
Subzero: Fix the cmake build.

BUG= none
R=mtrofin@chromium.org

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

9 years agoSubzero: Fix dependency checking to avoid unnecessary rebuilds.
Jim Stichnoth [Sun, 29 Mar 2015 22:20:37 +0000 (15:20 -0700)]
Subzero: Fix dependency checking to avoid unnecessary rebuilds.

When trying to do bisection debugging, the pnacl-llc translation was happening every time even if the pexe didn't change.  This is because it was checking for a binary called 'llc' in the current directory, instead of an absolute path the pnacl-llc.  (This check is done so that updating pnacl-llc triggers a rebuild of the bisection binary, similar to the check for an update of pnacl-sz.)

BUG= none
R=jvoung@chromium.org

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

9 years agoRefactor Subzero initialization and add a browser callback handler.
Jan Voung [Fri, 27 Mar 2015 23:29:08 +0000 (16:29 -0700)]
Refactor Subzero initialization and add a browser callback handler.

Handlers are represented as a "compile server" even though
right now it can really only handle a single
compile request.

Then there can be a commandline-based server and a
browser-based server. This server takes over the main
thread. In the browser-based case the server can block,
waiting on bytes to be pushed. This becomes a producer of
bitcode bytes.

The original main thread which did bitcode reading is now
shifted to yet another worker thread, which is then the
consumer of bitcode bytes.

This uses an IRT interface for listening to messages
from the browser:
https://codereview.chromium.org/984713003/

TEST=Build the IRT core nexe w/ the above patch and compile w/ something like:

echo """
readwrite_file objfile /tmp/temp.nexe---gcc.opt.stripped.pexe---.o
rpc StreamInitWithSplit i(4) h(objfile) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) C(4,-O2\x00) * s()
stream_file /usr/local/google/home/jvoung/pexe_tests/gcc.opt.stripped.pexe 65536 1000000000
rpc StreamEnd * i() s() s() s()
echo "pnacl-sz complete"
""" | scons-out/opt-linux-x86-32/staging/sel_universal \
    -a -B scons-out/nacl_irt-x86-32/staging/irt_core.nexe \
    --abort_on_error \
    -- toolchain/linux_x86/pnacl_translator/translator/x86-32/bin/pnacl-sz.nexe

echo """
readwrite_file nexefile /tmp/temp.nexe.tmp
readonly_file objfile0 /tmp/temp.nexe---gcc.opt.stripped.pexe---.o
rpc RunWithSplit i(1) h(objfile0) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(invalid) h(nexefile) *
echo "ld complete"
""" | /usr/local/google/home/nacl3/native_client/scons-out/opt-linux-x86-32/staging/sel_universal \
    --abort_on_error \
    -a -B \
    scons-out/nacl_irt-x86-32/staging/irt_core.nexe \
    -E NACL_IRT_OPEN_RESOURCE_BASE=toolchain/linux_x86/pnacl_translator/translator/x86-32/lib/ \
    -E NACL_IRT_OPEN_RESOURCE_REMAP=libpnacl_irt_shim.a:libpnacl_irt_shim_dummy.a \
    -- toolchain/linux_x86/pnacl_translator/translator/x86-32/bin/ld.nexe

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

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

9 years agoSubzero: Fix a lowering bug involving xchg and xadd instructions.
Jim Stichnoth [Tue, 24 Mar 2015 22:39:16 +0000 (15:39 -0700)]
Subzero: Fix a lowering bug involving xchg and xadd instructions.

The x86-32 xchg and xadd instructions are modeled using two source operands, one of which is a memory operand and the other ultimately a physical register.  These instructions have a side effect of modifying both operands.

During lowering, we need to specially express that the instruction modifies the Variable operand (since it doesn't appear as the instruction's Dest variable).  This makes the register allocator aware of the Variable being multi-def, and prevents it from sharing a register with an overlapping live range.

This was being partially expressed by adding a FakeDef instruction.  However, FakeDef instructions are still allowed to be dead-code eliminated, and if this happens, the Variable may appear to be single-def, triggering the unsafe register sharing.

The solution is to prevent the FakeDef instruction from being eliminated, via a FakeUse instruction.

It turns out that the current register allocator isn't aggressive enough to manifest the bug with cmpxchg instructions, but the fix and tests are there just in case.

BUG= none
R=jvoung@chromium.org

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

9 years agoMake compile without ICE_THREAD_LOCAL_HACK (avoid "Type *TLS = TLS;")
Jan Voung [Tue, 24 Mar 2015 16:04:13 +0000 (09:04 -0700)]
Make compile without ICE_THREAD_LOCAL_HACK (avoid "Type *TLS = TLS;")

Otherwise you get:

In file included from src/IceGlobalContext.cpp:21:
In file included from src/IceCfg.h:21:
src/IceGlobalContext.h:257:44: error: variable 'TLS' is uninitialized when used within its own initialization [-Werror,-Wuninitialized]
    ThreadContext *TLS = ICE_TLS_GET_FIELD(TLS);
                   ~~~                     ^~~
src/IceTLS.h:95:39: note: expanded from macro 'ICE_TLS_GET_FIELD'
                                      ^
So rename the local var to Tls.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Don't use key SSE instructions on potentially unaligned loads.
Jim Stichnoth [Mon, 23 Mar 2015 22:10:54 +0000 (15:10 -0700)]
Subzero: Don't use key SSE instructions on potentially unaligned loads.

The non-mov-like SSE instructions generally require 16-byte aligned memory operands.  The PNaCl bitcode ABI only guarantees 4-byte alignment or less on vector loads and stores.  Subzero maintains stack alignment so stack memory operands are fine.

We handle this by legalizing memory operands into a register wherever there is doubt.

This bug was first discovered on the vector_align scons test.

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

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

9 years agoSubzero: Prune unreachable nodes after constructing the Cfg.
Jim Stichnoth [Mon, 23 Mar 2015 17:33:38 +0000 (10:33 -0700)]
Subzero: Prune unreachable nodes after constructing the Cfg.

The gcc torture test suite has examples where there is a function call (to a routine that throws an exception or aborts or something), followed by an "unreachable" instruction, followed by more code that may e.g. return a value to the caller.  In these examples, the code following the unreachable is itself unreachable.

Problems arise when the unreachable code references a variable defined in the reachable code.  This triggers a liveness consistency error because the use of the variable has no reaching definition.

It's a bit surprising that LLVM actually allows this, but it does so we need to deal with it.

The solution is, after initial CFG construction, do a traversal starting from the entry node and then delete any undiscovered nodes.

There is code in Subzero that assumes Cfg::Nodes[i]->Number == i, so the nodes need to be renumbered after pruning.  The alternative was to set Nodes[i]=nullptr and not change the node number, but that would mean peppering the code base with CfgNode null checks.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Fix inappropriate use of nullptr.
Jim Stichnoth [Mon, 23 Mar 2015 17:29:58 +0000 (10:29 -0700)]
Subzero: Fix inappropriate use of nullptr.

When lowering of a couple of atomic intrinsics down to a loop structure, a FakeUse on the memory address's base variable is created.  However, if the memory address is a global constant, there is no base variable.  So check for that and don't create a FakeUse if there is none.

BUG= none
TEST=synchronization_sync (scons test)
R=jvoung@chromium.org

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

9 years agoMove some flag-like props from GlobalContext and TargetLowering to ClFlags.
Jan Voung [Fri, 20 Mar 2015 22:01:26 +0000 (15:01 -0700)]
Move some flag-like props from GlobalContext and TargetLowering to ClFlags.

Simplifies the GlobalContext constructor so that a future
change may just set up the flags and the GlobalContext
before calling into what is currently "main".
Namely this change:
https://codereview.chromium.org/997773002/

This also moves all uses of LLVM's CommandLine.h to
a single file, so that in the future we may be able
to simplify the flags parsing (especially for the
minimal build).

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

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

9 years agoSubzero: Fix lowering of the fabs() intrinsic.
Jim Stichnoth [Fri, 20 Mar 2015 19:56:07 +0000 (12:56 -0700)]
Subzero: Fix lowering of the fabs() intrinsic.

The pand instruction for masking off the sign bit can operate on a register or an m128 memory location, but not a 32-bit or 64-bit memory location.  This means we need to make sure f32 and f64 operands are first loaded into a register.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Support non-IRT immediate calls with -filetype=iasm.
Jim Stichnoth [Fri, 20 Mar 2015 06:23:00 +0000 (23:23 -0700)]
Subzero: Support non-IRT immediate calls with -filetype=iasm.

This is done by emitting the following:
  .byte 0xe8
  .long __Sz_AbsoluteZero -4 - .

The linker is passed an argument like
  --defsym=__Sz_AbsoluteZero=0
to force the symbol's value to 0.

This special symbol is needed due to an llvm-mc parsing bug.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Fix floating-point constant pooling.
Jim Stichnoth [Thu, 19 Mar 2015 20:51:56 +0000 (13:51 -0700)]
Subzero: Fix floating-point constant pooling.

This fixes a regression likely introduced in d2cb4361c732dcddc98659415f37be45982e20c3 .

The problem is that by using the default std::unordered_map comparison predicate std::equal_to, we get incorrect behavior when the key is float or double:

1. 0.0 and -0.0 appear equal, so they share a constant pool entry even though the bit patterns are different.  This is a correctness bug.

2. Each instance of NaN gets a separate constant pool entry, because NaN != NaN by C equality rules.  This is a performance bug.  (This problem doesn't show up with the native bitcode reader, because constants are already unique-ified in the PNaCl bitcode file.)

The solution is to use memcmp for floating-point key types.

Also, the abi-atomics.ll test is disabled for the MINIMAL build, to fix an oversight from a previous CL.

BUG= none
R=jfb@chromium.org

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

9 years agoSubzero: Add fabs intrinsic support.
Jim Stichnoth [Thu, 19 Mar 2015 20:01:50 +0000 (13:01 -0700)]
Subzero: Add fabs intrinsic support.

The intrinsic is lowered using the standard technique of masking off the FP sign bit, which is the high-order bit.

To construct this mask, we use the existing trick of loading a vector register with all "1" bits, then logical-shift-right by one bit.

In the future, we should add 128-bit vector values to the constant pool and force them to memory, and this could be used for the other routines that synthesize a vector constant.

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

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

9 years agoAssemble calls to constant addresses.
Jan Voung [Thu, 19 Mar 2015 18:57:52 +0000 (11:57 -0700)]
Assemble calls to constant addresses.

Finally address this TODO in the assembler. This will help translate
non-IRT using programs (no ABI stability). The default scons testing
mode is non-IRT, so this helps with that. I haven't actually tested
this against scons yet, but I'm filling in the tests based on how
LLVM translates the same bitcode.

The filetype=asm is adjusted to omit the "*" and the "$".

The filetype=obj is adjusted to check for fixups with NullSymbols,
and also fill the assembler buffer at the instruction's immediate
field w/ the right constant.

The filetype=iasm is still TODO (hits an new assert in the Fixup's emit() function).

Reverts 7ad1bed99d058199a3ba246a5383458518596fbc:
"Allow stubbing of called constant addresses using command line argument."
since this is now handled (except for iasm).

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

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

9 years agoSubzero: Support non sequentially consistent memory orderings for atomic ops.
Jim Stichnoth [Wed, 18 Mar 2015 16:01:52 +0000 (09:01 -0700)]
Subzero: Support non sequentially consistent memory orderings for atomic ops.

The actual code lowering is unchanged, but the validation is made less strict to allow the additional orderings.

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

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

9 years agoSubzero: Fix a bug in cross test generation.
Jim Stichnoth [Wed, 18 Mar 2015 15:59:23 +0000 (08:59 -0700)]
Subzero: Fix a bug in cross test generation.

The attribute matching logic was wrong.  If you specify the exact set of attributes, i.e. for a single test, no match would be found due to the < instead of <= test.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Add a separate check-xtest target to Makefile.standlone.
Jim Stichnoth [Fri, 13 Mar 2015 18:59:49 +0000 (11:59 -0700)]
Subzero: Add a separate check-xtest target to Makefile.standlone.

This makes it more convenient to directly test the crosstests without having to go through the lit tests first.

BUG= none
R=kschimpf@google.com

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

9 years agoApply LLVM clean ups for errors when bitcode parsing.
Karl Schimpf [Thu, 12 Mar 2015 16:32:06 +0000 (09:32 -0700)]
Apply LLVM clean ups for errors when bitcode parsing.

Fixes error reporting to match that
of CL https://codereview.chromium.org/986453002

BUG=None
R=stichnot@chromium.org

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

9 years agoSubzero: Enable a cmake build.
Jim Stichnoth [Tue, 10 Mar 2015 21:34:53 +0000 (14:34 -0700)]
Subzero: Enable a cmake build.

This just puts the CMakeLists.txt file in place.  A couple other
changes are needed in other repos to make this take effect.

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

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

9 years agoSubzero: Run cross tests as a much more configurable python script.
Jim Stichnoth [Tue, 10 Mar 2015 18:17:15 +0000 (11:17 -0700)]
Subzero: Run cross tests as a much more configurable python script.

The runtests.sh script is removed and replaced with crosstest_generator.py.

"make check" limits to a relevant subset of cross tests to control the combinatorial explosion.  We cut the native tests almost in half, and the sandboxed tests down to a quarter.

The --include and --exclude logic is copied/adapted from szbuild.py.

The script works by running through every possible test in the combinatorial explosion, and if the test is a match against the --include and --exclude arguments, the test is built and run.

The script includes lit support, which is the most likely way it will be run.  When run with the --lit argument, it sprays the output directory with lit test files in the form of shell scripts, and "make check" runs lit on that directory.

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

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

9 years agoSubzero: Switch file reading to be based on a DataStreamer and MemoryObject.
Jan Voung [Fri, 6 Mar 2015 22:53:30 +0000 (14:53 -0800)]
Subzero: Switch file reading to be based on a DataStreamer and MemoryObject.

This makes it compatible with the current browser interface,
which pushes bytes to a DataStreamer.

In the browser-integration mode, there will be a push-based
DataStreamer (vs a file-based one).

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

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

9 years agoUse the installed/downloaded objdump instead of work-dir one.
Jan Voung [Thu, 5 Mar 2015 22:33:38 +0000 (14:33 -0800)]
Use the installed/downloaded objdump instead of work-dir one.

Sometimes the work dir is empty and only cached results are used.
I couldn't switch the LLVM one from work-dir to install/download-dir
because we prune all the .a file in the download-dir.

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

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

9 years agoFix subzero translator to use new API for reporting errors.
Karl Schimpf [Wed, 4 Mar 2015 20:17:20 +0000 (12:17 -0800)]
Fix subzero translator to use new API for reporting errors.

The error handling in LLVM for errors has been updated so that errors in
the bitcode stream no longer cause (assertion crashes). This CL applies
the appropriate changes to subzero.

See CL https://codereview.chromium.org/932953002 for changes to error
handling for LLVM.

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

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

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

BUG= none
R=jvoung@chromium.org

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

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

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

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

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

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

Make the ELF object writer honor the -externalize argument.

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

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

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

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

  nacl_abi_blksize_t nacl_abi_st_blksize;   /* not implemented */

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

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

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

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

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

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

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

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

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

BUG= none
R=jvoung@chromium.org

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

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

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

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

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

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

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

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

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

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

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

Missing helpers (various vector bitcasts) are implemented.

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

BUG= none
R=mtrofin@chromium.org

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

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

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

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

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

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

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

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

BUG= none
R=kschimpf@google.com

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

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

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

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

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

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

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

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

Rather than hard code 32.

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

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

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

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

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

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

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

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

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

Delete zero-argument ctor where possible.

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

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

Declare single-argument ctor as "explicit".

BUG= none
R=jfb@chromium.org

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

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

BUG= none
R=kschimpf@google.com

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

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

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

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

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

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

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

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

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

Notes:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

BUG=None
R=stichnot@chromium.org

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

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

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

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

BUG= none
R=kschimpf@google.com

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

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

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

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

BUG= none
R=stichnot@chromium.org

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

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

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

BUG= none
R=jvoung@chromium.org

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

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

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

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

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

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

BUG= none
R=jfb@chromium.org

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

BUG=None
R=stichnot@chromium.org

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

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

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

BUG=none
R=stichnot@chromium.org

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

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

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

BUG=None
R=jvoung@chromium.org

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

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

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

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

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

BUG=none
R=stichnot@chromium.org

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

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

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

To reproduce the problem, try this:

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

This will print a line containing BitcodeMunge.cpp.

Now do:

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

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

Finally:

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

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

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

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

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

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

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

This should help the crosstests pass with --elf.

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

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

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

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

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

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

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

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

BUG= none
R=jfb@chromium.org

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

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

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

Haven't tried crosstests yet.

BUG=none
R=stichnot@chromium.org

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

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

This also implicitly applies to szbuild_spec2k.py.

BUG= none
R=jvoung@chromium.org

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