OSDN Git Service
Jim Stichnoth [Thu, 11 Jun 2015 20:26:33 +0000 (13:26 -0700)]
First patch for Mips subzero compiler
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4167
Move issue https://codereview.chromium.org/
1159823004/ here so that
it's under the proper email.
Review URL: https://codereview.chromium.org/
1169533003
Jim Stichnoth [Thu, 11 Jun 2015 17:19:32 +0000 (10:19 -0700)]
Subzero: Fix lit and cross tests broken in
f8b4cc8.
1. The data symbol __Sz_block_profile_info should never be mangled (for cross tests), similar to runtime helper calls. Add a SuppressMangling override for such variable declarations.
2. When cross tests contain more than one translated object file, we end up with multiple definitions of __Sz_block_profile_info . Work around this by making that symbol weak.
3. Don't try to attach global inits to an EmitterWorkItem that represents a translation error.
4. Update one lit test to reflect the additional profiling value in the data section.
5. Update one lit test to reflect that global initializers are emitted at the end instead of the beginning.
The check-unit test is still broken and will be fixed in a separate CL.
BUG= none
R=kschimpf@google.com
Review URL: https://codereview.chromium.org/
1180883002
John Porto [Thu, 11 Jun 2015 16:35:18 +0000 (09:35 -0700)]
Fixes a bug in that caused IceAssembler to use Allocator before it was initialized.
Initializes IceAssembler::Allocator before IceAssembler::Buffer.
BUG= None
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/
1177843006.
John Porto [Wed, 10 Jun 2015 23:35:06 +0000 (16:35 -0700)]
Renames the assembler* files.
Renames the assembler* files to IceAssembler*. Fixes whatever breaks.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4077
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/
1179563004.
John Porto [Wed, 10 Jun 2015 01:06:19 +0000 (18:06 -0700)]
Subzero: Basic Block Profiler.
BUG= None
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/
1147023007.
Karl Schimpf [Mon, 8 Jun 2015 16:25:15 +0000 (09:25 -0700)]
Clean up unit munging unit tests using common NaCl API.
Simplify the munging unit tests to follow the new NaCl utilities
for munging tests.
Note that this CL takes advantage of changes added by
CL https://codereview.chromium.org/
1140153004
BUG=None
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/
1149423011
John Porto [Fri, 5 Jun 2015 22:03:22 +0000 (15:03 -0700)]
Merge branch 'master' of https://chromium.googlesource.com/native_client/pnacl-subzero into subzero-ownership
John Porto [Fri, 5 Jun 2015 20:33:42 +0000 (13:33 -0700)]
Subzero: adding jpp@chromium.org to OWNERS.
BUG= None
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/
1149213006
John Porto [Fri, 5 Jun 2015 18:27:56 +0000 (11:27 -0700)]
Subzero: adding jpp@chromium.org to OWNERS.
Jan Voung [Fri, 5 Jun 2015 00:02:31 +0000 (17:02 -0700)]
Subzero ARM32: Lower shift and zext, sext, and trunc.
Sext, etc. usually uses shifts (especially for i1 and i64)
so implement shift, then implement those casts.
Implement just enough of bitcast to handle accessing
global addresses (used by some tests). Otherwise,
most other bitcasts are from GPR to FP and FP regs
aren't modeled yet.
Generally following the GCC style for 64-bit shifts.
This takes advantage of the flexible second operand in a "orr",
and takes advantage of the shift-beyond bitwidth saturation.
LLVM is almost the same, but only seems to take advantage
on one side of the 32-bits, not the other side. Should really
get some of the execution tests running to test this behavior!
Fix InstARM32Str::dump(). Str doesn't have a Dest, so use Src.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4076
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/
1143323013
Jim Stichnoth [Thu, 4 Jun 2015 16:25:07 +0000 (09:25 -0700)]
Subzero: Legalize FP constants directly into memory operands.
Previously, the legalize() function would always force a floating point constant into an xmm register before it could be used in an instruction. This uses an extra register unnecessarily when the instruction allows a memory operand for that operand.
We improve this by lowering the FP constant operand to an OperandX8632Mem that wraps a ConstantRelocatable representing the label for the constant pool entry, e.g. [.L$float$0]. (This may end up being copied into an xmm register if the instruction doesn't allow a memory operand for that operand.)
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4095
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/
1163943005
Jan Voung [Thu, 4 Jun 2015 00:50:20 +0000 (17:50 -0700)]
Use report_fatal_error before destroying input object on error.
The input object may be a QueueStreamer, which the compile
server will still have a reference to (even though
downstream the memory object API and parser API thinks it
has a unique_ptr). Terminate the thread quickly on error,
instead of free'ing and causing a use-after-free.
Also set up a report_fatal_error handler which has access
to the server's state. This allows the server to record the
error and stop pushing bytes to the QueueStreamer.
Otherwise the QueueStreamer can get full without a consumer
still active to unblock.
Unfortunately the fatal error handler only terminates the
current thread, and not all worker threads. NaCl doesn't
have support for signals or pthread_kill.
E.g., with pthread_kill(std_thread.native_handle(), SIGABRT).
So, other worker/emitter threads will have to hang waiting on
more input or something.
Random clang-format edits from 3.7.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4163
TEST= tbd:
I manually ran the translator a dummy text file (invalid bitcode
header), and observed that this no longer crashes. Instead the SRPC
calls finish and I see:
3> [17812,
4147750656:14:23:02.025382] Streaming file at 100000 bps
[17812,
4147750656:14:23:12.511574] RPC call failed: Rpc application returned an error.
[17812,
4147750656:14:23:12.511625] StreamChunk failed
[17812,
4147750656:14:23:12.511655] stream_file: SendDataChunk failed, but returning without failing. Expect call to StreamEnd.4> rpc call initiated StreamEnd::isss
[17812,
4147750656:14:23:12.511931] RPC call failed: Rpc application returned an error.
rpc call complete StreamEnd::isss
output 0: i(0)
output 1: s("")
output 2: s("")
output 3: s("Invalid PNaCl bitcode header")
[17812,
4147750656:14:23:12.512102] Command [rpc] failed.
R=kschimpf@google.com, stichnot@chromium.org
Review URL: https://codereview.chromium.org/
1168543002
Jim Stichnoth [Wed, 3 Jun 2015 22:58:12 +0000 (15:58 -0700)]
Subzero: Improve/refactor folding loads into the next instruction.
This is turned into a separate (O2-only) pass that looks for opportunities:
1. A Load instruction, or an AtomicLoad intrinsic that would be lowered just like a Load instruction
2. Followed immediately by an instruction with a whitelisted kind that uses the Load dest variable as one of its operands
3. Where the whitelisted instruction ends the live range of the Load dest variable.
In such cases, the original two instructions are deleted and a new instruction is added that folds the load into the whitelisted instruction.
We also do some work to splice the liveness information (Inst::LiveRangesEnded and Inst::isLastUse()) into the new instruction, so that the target lowering pass might still take advantage. Currently this is used quite sparingly, but in the future we could use that along with operator commutativity to choose among different lowering sequences to reduce register pressure.
The whitelisted instruction kinds are chosen based primarily on whether the main operation's native instruction can use a memory operand - e.g., arithmetic (add/sub/imul/etc), compare (cmp/ucomiss), cast (movsx/movzx/etc). Notably, call and ret are not included because arg passing is done through simple assignments which normal lowering is sufficient for.
BUG= none
R=jvoung@chromium.org, mtrofin@chromium.org
Review URL: https://codereview.chromium.org/
1169493002
Jim Stichnoth [Wed, 3 Jun 2015 07:18:14 +0000 (00:18 -0700)]
Subzero: Change pnacl_newlib ==> pnacl_newlib_raw in scripts.
BUG= none
R=jvoung@chromium.org, kschimpf@google.com
Review URL: https://codereview.chromium.org/
1162903003
Jan Voung [Tue, 2 Jun 2015 18:03:03 +0000 (11:03 -0700)]
Subzero ARM: lowerLoad and lowerStore.
Thought leaving "mov" simple and not handle memory operands,
but then we'd have to duplicate some of the lowerAssign code
for lowerLoad =/
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4076
R=kschimpf@google.com, stichnot@chromium.org
Review URL: https://codereview.chromium.org/
1152703006
Jim Stichnoth [Mon, 1 Jun 2015 22:17:20 +0000 (15:17 -0700)]
Subzero: Changes needed for LLVM 3.7 integration.
1. Change Makefile.standalone from 3.6 to 3.7.
2. Update to new load instruction .ll syntax. This includes changing InstLoad::dump() to match.
BUG= none
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/
1161543005
Jim Stichnoth [Mon, 1 Jun 2015 20:39:24 +0000 (13:39 -0700)]
Subzero: Remove a compile-time warning.
BUG= none
R=kschimpf@google.com
Review URL: https://codereview.chromium.org/
1161353002
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
Jan Voung [Thu, 26 Feb 2015 18:03:41 +0000 (10:03 -0800)]
Merge latest changes from branch 'master' into merge_36 branch.
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
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
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
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
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
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
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
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
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
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
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
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
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