OSDN Git Service

android-x86/external-swiftshader.git
9 years agoFollowup to previous MIPS commit: implement dump(), rebase more.
Jan Voung [Thu, 9 Jul 2015 17:32:31 +0000 (10:32 -0700)]
Followup to previous MIPS commit: implement dump(), rebase more.

When compiling with DEBUG, there is a problem linking
InstMIPS32. It overrides dump, but never defined that.

Also, update the code for some recent changes.  Namely, we
no longer check ALLOW_DUMP but instead check
BuildDefs::dump().  Also, the instruction dtors have been
deleted.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4167
R=kschimpf@google.com

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

9 years agoimplement the null function for the Mips32 subzero compiler
Reed Kotler [Wed, 8 Jul 2015 16:49:07 +0000 (09:49 -0700)]
implement the null function for the Mips32 subzero compiler

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

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

Patch from Reed Kotler <reed.kotler@imgtec.com>.

9 years agoX8632 Templatization completed.
John Porto [Tue, 7 Jul 2015 18:56:26 +0000 (11:56 -0700)]
X8632 Templatization completed.

This CL introduces the X86Inst templates. The previous implementation relied on template specialization which did not played nice with the new design. This required a lot of other boilerplate code (i.e., tons of new named constructors, one for each X86Inst.)

This CL also moves X8632 code out of the X86Base{Impl}?.h files so that they are **almost** target agnostic. As we move to adding other X86 targets more methods will be moved to the target-specific trait class (e.g., call/ret/argument lowering.)

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

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

9 years agoRedelete IceAssemblerX8632.cpp
Andrew Scull [Mon, 6 Jul 2015 23:07:11 +0000 (16:07 -0700)]
Redelete IceAssemblerX8632.cpp

Accidentally resurrected during rebase when it shouldn't have been.

BUG=
R=jvoung@chromium.org

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

9 years agoDoxygenize the documentation comments
Andrew Scull [Mon, 6 Jul 2015 21:53:25 +0000 (14:53 -0700)]
Doxygenize the documentation comments

There were many // comment used to document classes, functions etc. but
those are not picked up by doxygen which expects /// comments. This
converts many comments from // to /// in order to improve the generated
documentation.

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

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

9 years agoFix ARM Om1 lowering for arithmetic, and test.
Jan Voung [Mon, 6 Jul 2015 21:01:25 +0000 (14:01 -0700)]
Fix ARM Om1 lowering for arithmetic, and test.

The original arithmetic lowering was introducing some
unused mov instructions from legalization (e.g., the upper
part of shift num bits -- which should be 0 anyway), and
div helper calls don't actually use the legalized
parameters (handled separately by lowerCall). These unused
instructions cause the Om1 allocator to assert that LRBegin
exists but LREnd does not.

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

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

9 years agoMove X8632-specific Assembler stuff to Machine Traits.
John Porto [Tue, 30 Jun 2015 22:29:21 +0000 (15:29 -0700)]
Move X8632-specific Assembler stuff to Machine Traits.

As part of the refactoring moves the MachineTraits<TargetX8632> to a separate header.

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

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

9 years agoFix invalid tests to not run when minimal.
Karl Schimpf [Tue, 30 Jun 2015 21:29:58 +0000 (14:29 -0700)]
Fix invalid tests to not run when minimal.

Deals with fact that minimal builds generate simple "generic" error
messages, rather than descriptive error messages.

BUG=None
R=stichnot@chromium.org

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

9 years agoSmall fixes for unused argument warnings w/ Makefile.standalone "sb" target.
Jan Voung [Tue, 30 Jun 2015 20:31:02 +0000 (13:31 -0700)]
Small fixes for unused argument warnings w/ Makefile.standalone "sb" target.

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

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

9 years agoARM lowering integer divide and remainder, with div by 0 checks.
Jan Voung [Tue, 30 Jun 2015 18:03:15 +0000 (11:03 -0700)]
ARM lowering integer divide and remainder, with div by 0 checks.

ARM normally just returns 0 when dividing by 0 with the
software and hw implementations, which is different from
what X86 does. So, for NaCl, we've modified LLVM to trap
by inserting explicit 0 checks.

Uses -mattr=hwdiv-arm attribute to decide if 32-bit
sdiv/udiv are supported.

Also lower the unreachable-inst to a trap-inst, since we
need a trap instruction for divide by 0 anyway.

Misc: fix switch test under MINIMAL=1, since ARM requires
allow_dump for filetype=asm.
Random clang-format changes...

TODO: check via cross tests

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

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

9 years agoFixes case where terminator instruction is missing at end of function.
Karl Schimpf [Tue, 30 Jun 2015 17:25:27 +0000 (10:25 -0700)]
Fixes case where terminator instruction is missing at end of function.

If the bitcode parser detects that the last block in the function
is missing a terminator, generate an error message and insert
a terminator instruction.

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

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

9 years agoARM: lowerSelect for integers.
Jan Voung [Tue, 30 Jun 2015 15:47:06 +0000 (08:47 -0700)]
ARM: lowerSelect for integers.

No bool-folding optimization, just the straightforward
compare followed by mov and conditional mov.

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

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

9 years agoImplement ARM32 switch lowering.
Andrew Scull [Mon, 29 Jun 2015 18:21:18 +0000 (11:21 -0700)]
Implement ARM32 switch lowering.

A naive implementation of switch lowering using sequential tests for each of the cases.

BUG= none
TEST=switch-opt.ll
R=jvoung@chromium.org

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

9 years agoAdd doxygen build target.
Andrew Scull [Mon, 29 Jun 2015 18:07:08 +0000 (11:07 -0700)]
Add doxygen build target.

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

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

9 years agoEnables llvm dyn_cast for Assemblers.
John Porto [Mon, 29 Jun 2015 14:57:02 +0000 (07:57 -0700)]
Enables llvm dyn_cast for Assemblers.

IceCfg::getAssembler() is a template that simply static_casts the CFG's assembler. This could potentially be problematic in the future, so we enabled the (relatively) cheap llvm dyn_cast operator for Assemblers.

This CL also renames assembler_mips32.h to IceAssemblerMIPS32.h.

BUG=
R=stichnot@chromium.org

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

9 years agoSubzero: Fix a new test under MINIMAL mode.
Jim Stichnoth [Sun, 28 Jun 2015 17:19:05 +0000 (10:19 -0700)]
Subzero: Fix a new test under MINIMAL mode.

It tests dump output and therefore requires allow_dump.

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

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

9 years agoSubzero: Enable errors for unused parameters.
Jim Stichnoth [Sat, 27 Jun 2015 13:38:08 +0000 (06:38 -0700)]
Subzero: Enable errors for unused parameters.

Uses pragmas when including problematic LLVM headers, so that clang
doesn't warn about unused parameters -- a rampant problem in the LLVM
code.  This way, we can increase clang's pickiness on Subzero code,
and also not drown in LLVM warnings.

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

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

9 years agoAdds X8664 Condition codes.
John Porto [Fri, 26 Jun 2015 21:41:40 +0000 (14:41 -0700)]
Adds X8664 Condition codes.

Also fixes the X8664 Registers file.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=4077
R=kschimpf@google.com

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

9 years agoAdds the X8664 register definition.
John Porto [Fri, 26 Jun 2015 20:41:00 +0000 (13:41 -0700)]
Adds the X8664 register definition.

BUG=
R=stichnot@chromium.org

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

9 years agoFixes bug on conditional branch where the targets are the same.
Karl Schimpf [Fri, 26 Jun 2015 17:25:33 +0000 (10:25 -0700)]
Fixes bug on conditional branch where the targets are the same.

Fixes constructor InstBr when it is a conditional branch, and the
true and false branches are the same.

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

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

9 years agoFunction Layout, Global Variable Layout and Pooled Constants Layout Reordering
Qining Lu [Fri, 26 Jun 2015 16:36:00 +0000 (09:36 -0700)]
Function Layout, Global Variable Layout and Pooled Constants Layout Reordering

PURPOSE:
The purpose of function layout reordering is to defend against code-reuse attacks as the location of code blocks will be various among different binaries. The layout reordering for global variables and pooled constants can be considered as static data randomization. This is to stop memory corruption attacks by randomizing the locations of the static data. After function layout reordering, the order of function blocks in TEXT section will be randomized. Global variable reordering randomize the order of global variables, and pooled constant reordering randomize the order of pooled constants. Note the order of constant pools won’t be affected and all pooled constants will remain in their original constant pools.

USAGE:
-reorder-functions: bool type command line option, enables function layout shuffling in TEXT section. Note when -threads=0 is set, function reordering will be forced off.

-reorder-functions-window-size: uint32 type command line option, specify the length of the shuffling queue. Note -reorder-functions-window-size=0 or 1 means no shuffling applied to functions.

-reorder-global-variables: bool type command line option, enables global variables shuffling.

-reorder-pooled-constants: bool type command line option, enables pooled constants shuffling.

APPROACH:
Randomization is introduced at the code emission time. We use a shuffling method to randomize the emission of function code, global variables and pooled constants. For function code emission, we also introduce “window size” as a parameter to control the size of the function holding buffer for shuffling. Window size 1 and 0 mean no shuffling applied, and a value higher than the number of translated functions means holding all the functions and shuffling them before emitting any of them.

IMPLEMENTATION:
    Function reordering:
        GlobalContext::emitItems(): Call RandomShuffle() routine to shuffle a specific part of the Pending vector.

    Global variable reorder:
        GlobalContext::lowerGlobals(const IceString &SectionSuffix): Call RandomShuffle() routine upon declaration list: Globals.

    Pooled constant reordering:
        TargetDataX8632::emitConstantPool(GlobalContext *Ctx): Add call to RandomShuffle() to shuffle the constant pool to be emitted. This is for asm output.

        ELFObjectWriter::writeConstantPool(Type Tu): Add call to RandomShuffle() to shuffle the constant pool before emitting it. This is only for elf output.

ISSUES:
    The initialization of global variables are emitted along with function code, all of them are considered as EmitterWorkItem. However, we do need to first emit global variables to keep the block profiling workflow untouched. To fulfill this, a “kind” check is added in the while loop of GlobalContext::emitItems(). The “if” statement at line 480 shows the workaround of this issue.
BUG=
R=jpp@chromium.org, jvoung@chromium.org, stichnot@chromium.org

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

9 years agoIncludes module header first.
John Porto [Thu, 25 Jun 2015 17:14:17 +0000 (10:14 -0700)]
Includes module header first.

This "include module header first" is part of the llvm style guide.

This change exposes "broken" headers that were accessing undefined types, or
even using types without forward declaring them.

BUG=
R=stichnot@chromium.org

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

9 years agoSubzero: Fix cmake build.
Jim Stichnoth [Thu, 25 Jun 2015 00:52:51 +0000 (17:52 -0700)]
Subzero: Fix cmake build.

Also fixes a set of warnings that only show up for the cmake build.

BUG= none
R=jpp@chromium.org

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

9 years agoFixes the X86 Base template.
John Porto [Wed, 24 Jun 2015 23:16:13 +0000 (16:16 -0700)]
Fixes the X86 Base template.

It turns out that using using TargetLowering::<member> causes problems when compiling with g++. The problem was fixed by using
Machine:: instead, where Machine is the template parameter. With name-dependent identifier, g++ does the right thing.

BUG= None
R=stichnot@chromium.org

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

9 years agoSubzero: Reduce the amount of #ifdef'd code.
Jim Stichnoth [Wed, 24 Jun 2015 22:52:24 +0000 (15:52 -0700)]
Subzero: Reduce the amount of #ifdef'd code.

Try to make most #ifdef'd code be compiled under all configurations,
to catch code rot earlier.  When #ifdef code is required, try to use
it only to guard trivial code like "return;".

BUG= none
R=jpp@chromium.org

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

9 years agoRemove unnecessary TEXTBC_LIBS makefile definition.
Karl Schimpf [Wed, 24 Jun 2015 16:32:40 +0000 (09:32 -0700)]
Remove unnecessary TEXTBC_LIBS makefile definition.

Jan correctly pointed out that this makefie definition was redundant
since -lLLVMNaClBitTestUtils was already defined in LLVM_LIBS_LIST.
Removing the definition and simplifying makefile.

BUG=None
R=jpp@chromium.org

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

9 years agoSubzero. Adds x86-64 to the list of supported Subzero targets.
John Porto [Tue, 23 Jun 2015 22:55:17 +0000 (15:55 -0700)]
Subzero. Adds x86-64 to the list of supported Subzero targets.

Related changes:
NaCl change: https://codereview.chromium.org/1201483005
LLVM change: https://codereview.chromium.org/1193843016

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

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

9 years agoSubzero: Make life a little easier for emacs users.
Jim Stichnoth [Tue, 23 Jun 2015 18:16:11 +0000 (11:16 -0700)]
Subzero: Make life a little easier for emacs users.

Emacs will try to execute .dir-locals.el whenever loading a file under
the subzero directory.  It sets local variables depending on the mode.

Set the fill-column to 80 for c++-mode, c-mode, and python-mode.  The
main use is when using M-q to reformat multi-line comments.

Disable tabs (use spaces instead) in c++-mode, c-mode, and
python-mode.

Set the tab-width to 2 spaces in python-mode.  (The tab-width doesn't
really matter in c++-mode or c-mode thanks to clang-format.)

BUG= none
R=kschimpf@google.com

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

9 years agoFix handling of TYPE_CODE_NUMENTRY record when size large.
Karl Schimpf [Tue, 23 Jun 2015 18:05:01 +0000 (11:05 -0700)]
Fix handling of TYPE_CODE_NUMENTRY record when size large.

Fixes how (very) large size entries in the TYPE_CODE_NUMENTRY is
handled when reading bitcode. Makes sure that we con't call
vector.resize() with too large a value (replacing an allocation
exception with a parse error).

Also tries to clean up type modeling of bitcode indices (references to
values etc in the bitcode). Uses common type NaClBcIndexSize_t and
NaClRelBcIndexSize_t (defined in nacl) to describe these (32-bit)
values.

Note: We use cast truncation of 64-bit values to NaClBcIndexSize_t and
NaClRelBcIndexSize_t, since negative value indices are stored both as
32 and 64 bit values. The truncation cast handles this differences
correctly (and efficiently).

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

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

9 years agoExtracts an TargetX86Base target which will be used as the common X86{32,64} implemen...
John Porto [Tue, 23 Jun 2015 17:58:57 +0000 (10:58 -0700)]
Extracts an TargetX86Base target which will be used as the common X86{32,64} implementation.

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

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

9 years agoSubzero: Use more "= default;" for ctors and dtors.
Jim Stichnoth [Mon, 22 Jun 2015 22:49:04 +0000 (15:49 -0700)]
Subzero: Use more "= default;" for ctors and dtors.

Look for "() override {}" and "() final {}" patterns.

Don't touch IceTargetLoweringX8632.* to spare a refactoring in
progress.

BUG= none
R=jpp@chromium.org

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

9 years agoFix llvm makefile to handle macro INPUT_IS_TEXTUAL_BITCODE.
Karl Schimpf [Mon, 22 Jun 2015 21:19:32 +0000 (14:19 -0700)]
Fix llvm makefile to handle macro INPUT_IS_TEXTUAL_BITCODE.

BUG=None
R=stichnot@chromium.org

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

9 years agoAllow pnacl-sz to be compiled to textual bitcode records.
Karl Schimpf [Mon, 22 Jun 2015 20:20:23 +0000 (13:20 -0700)]
Allow pnacl-sz to be compiled to textual bitcode records.

This has been added to allow fuzzing to be applied to textual bitcode
records. When built with make option TEXTUAL_BITCODE=1, the
corresponding generated pnacl-sz will preprocess the input file
(containing the textual form of bitcode records) and generate
a corresponding data stream with the binary form.

Note that the texual form of bitcode records is not LLVM assembly
(i.e. .ll files). Rather, it is sequences of texual integers
corresponding to bitcode records.

Dependent on: https://codereview.chromium.org/1191393004

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

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

9 years agoSubzero: Fix "make -f Makefile.standalone MINIMAL=1 check".
Jim Stichnoth [Mon, 22 Jun 2015 20:04:10 +0000 (13:04 -0700)]
Subzero: Fix "make -f Makefile.standalone MINIMAL=1 check".

Some recent ARM changes turned out to break the lit tests for the MINIMAL build.  Two main issues:

1. ARM tests are currently asm-only, so allow_dump needs to be required.

2. GlobalContext::emitFileHeader() needs to return gracefully instead of calling report_fatal_error(), to allow error tests to produce the right error output.

BUG= none
R=kschimpf@google.com

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

9 years agoSubzero. Fixes memory leaks.
John Porto [Mon, 22 Jun 2015 17:51:13 +0000 (10:51 -0700)]
Subzero. Fixes memory leaks.

Adds named constructors to initialzers. Removes destructor from Inst.

BUG= None
R=stichnot@chromium.org

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

9 years agoSubzero: Apply commutativity to the RMW optimization.
Jim Stichnoth [Mon, 22 Jun 2015 17:36:42 +0000 (10:36 -0700)]
Subzero: Apply commutativity to the RMW optimization.

The read-modify-write (RMW) optimization looks for patterns like this:

  a = Load addr
  b = <op> a, other
  Store b, addr

and essentially transforms them into this:

  RMW <op>, addr, other

This CL also applies the transformation when the middle instruction is
  b = <op> other, a
and <op> is commutative.

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

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

9 years agoSubzero: Use C++11 member initializers where practical.
Jim Stichnoth [Mon, 22 Jun 2015 17:35:22 +0000 (10:35 -0700)]
Subzero: Use C++11 member initializers where practical.

Also change the pattern "foo() {}" into "foo() = default;" for ctors and dtors.

Generally avoids initializing unique_ptr<> members to nullptr in a .h file, because that requires knowing the definition of the underlying class which may not be available to all includers.

BUG= none
R=jpp@chromium.org

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

9 years agoAdd constant blinding/pooling option for X8632 code translation.
Qining Lu [Mon, 22 Jun 2015 17:10:23 +0000 (10:10 -0700)]
Add constant blinding/pooling option for X8632 code translation.

GOAL:
The goal is to remove the ability of an attacker to control immediates emitted into the text section.

OPTION:
The option -randomize-pool-immediates is set to none by default (-randomize-pool-immediates=none). To turn on constant blinding, set -randomize-pool-immediates=randomize; to turn on constant pooling, use -randomize-pool-immediates=pool.

Not all constant integers in the input pexe file will be randomized or pooled. The signed representation of a candidate constant integer must be between -randomizeOrPoolImmediatesThreshold/2 and +randomizeOrPoolImmediatesThreshold/2. This threshold value can be set with command line option: "-randomize-pool-threshold". By default this threshold is set to 0xffff.

The constants introduced by instruction lowering (e.g. constants in shifting, masking) and argument lowering are not blinded in this way. The mask used for sandboxing is not affected either.

APPROACH:
We use GAS syntax in these examples.

Constant blinding for immediates:
Original:
    add 0x1234, eax
After:
    mov 0x1234+cookie, temp_reg
    lea -cookie[temp_reg], temp_reg
    add temp_reg, eax

Constant blinding for memory addressing offsets:
Original:
  mov 0x1234(eax, esi, 1), ebx
After:
  lea 0x1234+cookie(eax), temp_reg
  mov -cookie(temp_reg, esi, 1), ebx

We use "lea" here because it won't affect flag register, so it is safer to transform immediate-involved instructions.

Constant pooling for immediates:
Original:
    add 0x1234, eax
After:
    mov [memory label of 0x1234], temp_reg
    add temp_reg, eax

Constant pooling for addressing offsets:
Original:
  mov 0x1234, eax
After:
  mov [memory label of 0x1234], temp_reg
  mov temp_reg, eax

Note in both cases, temp_reg may be assigned with "eax" here, depends on the
liveness analysis. So this approach may not require extra register.

IMPLEMENTATION:
  Processing:
   TargetX8632::randomizeOrPoolImmediate(Constant *Immediate, int32_t RegNum);
   TargetX8632::randomizeOrPoolImmediate(OperandX8632Mem *Memoperand, int32_t RegNum);

  Checking eligibility:
    ConstantInteger32::shouldBeRandomizedOrPooled(const GlobalContext *Ctx);

ISSUES:
1. bool Ice::TargetX8632::RandomizationPoolingPaused is used to guard some translation phases to disable constant blinding/pooling temporally. Helper class BoolFlagSaver is added to latch the value of RandomizationPoolingPaused.

Known phases that need to be guarded are: doLoadOpt() and advancedPhiLowering(). However, during advancedPhiLowering(), if the destination variable has a physical register allocated, constant blinding and pooling are allowed. Stopping blinding/pooling for doLoadOpt() won't hurt our randomization or pooling as the optimized addressing operands will be processed again in genCode() phase.

2. i8 and i16 constants are collected with different constant pools now, instead of sharing a same constant pool with i32 constants. This requires emitting two more pools during constants lowering, hence create two more read-only data sections in the resulting ELF and ASM. No runtime issues have been observed so far.

BUG=
R=stichnot@chromium.org

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

9 years agoARM: Assign "actuals" at call site to the appropriate GPR/stack slot.
Jan Voung [Thu, 18 Jun 2015 22:00:14 +0000 (15:00 -0700)]
ARM: Assign "actuals" at call site to the appropriate GPR/stack slot.

Actually assign arguments to r0-r3 at the call site. Previously
this was left unhandled. There was only logic for pulling
formal parameters out of r0-r3.

Refactor the GPR counter and move it into a class so that the
rounding up for i64 arguments is in one place for callsites
and for pulling out of parameters. We might be able to use a
similar pattern to count the FP/SIMD registers later.

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

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

9 years agoSubzero: Add more kinds of RMW lowering.
Jim Stichnoth [Thu, 18 Jun 2015 19:48:58 +0000 (12:48 -0700)]
Subzero: Add more kinds of RMW lowering.

Specifically: sub, and, or, xor; for all integer types.

Turns out that RMW is not possible for fadd/fsub/fmul/fdiv as well as operations on vector types, because the corresponding x86 instructions require the result to be in a physical register.

Refactors the assembler's implementations of add/or/adc/sbb/and/sub/xor/cmp to avoid repetition.

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

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

9 years agoSubzero: Correct the cross test's diagnostic message for a test failure.
Jim Stichnoth [Thu, 18 Jun 2015 05:16:57 +0000 (22:16 -0700)]
Subzero: Correct the cross test's diagnostic message for a test failure.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Transform suitable Load/Arith/Store sequences into RMW ops.
Jim Stichnoth [Thu, 18 Jun 2015 05:16:02 +0000 (22:16 -0700)]
Subzero: Transform suitable Load/Arith/Store sequences into RMW ops.

Search for sequences of Load/Arith/Store instructions that can be transformed into single non-atomic Read-Modify-Write instructions.  Corresponding operands must match up, and it is limited to the operator/type combinations that have simple lowerings.

For suitable sequences, an RMW pseudo-instruction is added.  Extra variables are attached to the RMW instruction and the original Store instruction, to make it easy to figure out whether to retain the original Store instruction or the new RMW instruction (but never both).

The RMW instructions are similar to their non-RMW counterparts, except that the RMW instruction has no Dest variable - the Src[0] operand doubles as the memory-operand dest.

The x86-32 integrated assembler has some new forms of existing instructions added.

Note: this CL puts the machinery in place to identify, lower, and emit RMW operations only for the "add" instruction operating on i32/i16/i8 operands.  The next CL will fill in the rest of the options.

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

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

9 years agoFix a bug that would cause subzero to fail when --threads=0.
John Porto [Wed, 17 Jun 2015 20:20:08 +0000 (13:20 -0700)]
Fix a bug that would cause subzero to fail when --threads=0.

Creates a single TargetDataLowering.

BUG= None
R=stichnot@chromium.org

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

9 years agoSet up crosstest to run simple loop in Om1 on ARM.
Jan Voung [Wed, 17 Jun 2015 17:16:23 +0000 (10:16 -0700)]
Set up crosstest to run simple loop in Om1 on ARM.

We can't run O2 yet because some of the advanced Phi lowering
hooks aren't implemented for O2 yet.

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

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

9 years agoAdd a basic enum for ARM InstructionSet / cpu features.
Jan Voung [Tue, 16 Jun 2015 00:17:31 +0000 (17:17 -0700)]
Add a basic enum for ARM InstructionSet / cpu features.

That way, we don't have to use -mattr=sse2 for ARM in
cross tests, etc.

Default to NEON for now. Also put in an entry for HW
divide in ARM mode. There's bunches of features that are
possible though, e.g.,:

https://github.com/llvm-mirror/llvm/blob/master/lib/Target/ARM/ARM.td

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

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

9 years agoMove lowerGlobal() from target-specific code to emitGlobal() in generic code.
Jan Voung [Mon, 15 Jun 2015 22:11:56 +0000 (15:11 -0700)]
Move lowerGlobal() from target-specific code to emitGlobal() in generic code.

Emitting the global initializers is mostly the same across
each architecture (same filling, alignment, etc.). The only difference
is in assembler-directive quirks. E.g., on ARM for ".align N" N is
the exponent for a power of 2, while on x86 N is the actual number
of bytes. To avoid target-specific directives, use .p2align which
is always a power of 2. Similarly, use % instead of @. Either one
may be a comment character for *some* architecture, but for the
architectures we care about % is not a comment character while @
is sometimes (ARM).

Usually MIPS uses ".space N" for ".zero", but the assembler seems
to accept ".zero" so don't change that for now.

May need to adjust .long in the future too.
.word for AArch64 and .4byte for MIPS?

Potentially we can refactor the lowerGlobals() dispatcher
(ELF vs ASM vs IASM). The only thing target-specific about that
is *probably* just the relocation type.

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

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

9 years agoRemoves const qualification for two methods in TargetDataLowering.
John Porto [Mon, 15 Jun 2015 14:44:27 +0000 (07:44 -0700)]
Removes const qualification for two methods in TargetDataLowering.

Removes const qualifier for TargetDataLowering::lowerGlobals() and TargetDataLowering::lowerConstants()

BUG= None
R=stichnot@chromium.org

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

9 years agoBuild ARM SZ runtime files. Use le32-nacl-objcopy in various places.
Jan Voung [Fri, 12 Jun 2015 22:12:05 +0000 (15:12 -0700)]
Build ARM SZ runtime files. Use le32-nacl-objcopy in various places.

Use PNaCl built binutils, which is known to support ARM and MIPS.
Otherwise the system-provided binutils may or may not have that
support (mine did not and perhaps expected a prefix like
arm-xxx-objcopy for the version that did support arm).

Split off from CL to run crosstests for ARM under qemu.

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

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

9 years agoSubzero: Strength-reduce mul by certain constants.
Jim Stichnoth [Fri, 12 Jun 2015 17:41:16 +0000 (10:41 -0700)]
Subzero: Strength-reduce mul by certain constants.

These all appear to some degree in spec2k.

This is implemented for i8/i16/i32 types.  It is done as part of core lowering, so in theory all optimization levels could benefit, but it is explicitly disabled for Om1/O0 to keep things simple there.

While clang appears to strength-reduce udiv/urem by a constant power of 2, for some reason it does not always strength-reduce multiplies (given that they appear in the spec2k bitcode).

For multiplies by 3, 5, or 9, we can make use of the lea instruction.  We can do combinations of shift and lea to multiply by other constants, e.g. 100=5*5*4.  If too many operations would be required, just give up and use the mul instruction.

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

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

9 years agoSubzero: Fix compilation error in MINIMAL=1 or NOASSERT=1 mode.
Jim Stichnoth [Fri, 12 Jun 2015 00:52:53 +0000 (17:52 -0700)]
Subzero: Fix compilation error in MINIMAL=1 or NOASSERT=1 mode.

BUG= none
R=jpp@chromium.org

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

9 years agoEmit ARM build-attributes in the file scope (as header).
Jan Voung [Thu, 11 Jun 2015 22:27:50 +0000 (15:27 -0700)]
Emit ARM build-attributes in the file scope (as header).

The ARM linker will check that .o files declare compatible
build attributes (e.g., all claim hard-float calling convention,
all claim VFP-vX ,etc.). Thus, in order to set up cross tests that
link LLC generated code against and Subzero generated code,
we need the build attributes to be compatible.

Pick ARMv7, hard-float calling convention, and neon, etc. which
we use for PNaCl LLVM.

Will probably have to reorganize to keep in sync once the ELF
writer also emits this.

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

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

9 years agoUnittest fixes.
John Porto [Thu, 11 Jun 2015 22:14:37 +0000 (15:14 -0700)]
Unittest fixes.

Adjusts the expected unittest output.

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

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

9 years agoFirst patch for Mips subzero compiler
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

9 years agoSubzero: Fix lit and cross tests broken in f8b4cc8.
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

9 years agoFixes a bug in that caused IceAssembler to use Allocator before it was initialized.
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.

9 years agoRenames the assembler* files.
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.

9 years agoSubzero: Basic Block Profiler.
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.

9 years agoClean up unit munging unit tests using common NaCl API.
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

9 years agoMerge branch 'master' of https://chromium.googlesource.com/native_client/pnacl-subzer...
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

9 years agoSubzero: adding jpp@chromium.org to OWNERS.
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

9 years agoSubzero: adding jpp@chromium.org to OWNERS.
John Porto [Fri, 5 Jun 2015 18:27:56 +0000 (11:27 -0700)]
Subzero: adding jpp@chromium.org to OWNERS.

9 years agoSubzero ARM32: Lower shift and zext, sext, and trunc.
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

9 years agoSubzero: Legalize FP constants directly into memory operands.
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

9 years agoUse report_fatal_error before destroying input object on error.
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

9 years agoSubzero: Improve/refactor folding loads into the next instruction.
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

9 years agoSubzero: Change pnacl_newlib ==> pnacl_newlib_raw in scripts.
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

9 years agoSubzero ARM: lowerLoad and lowerStore.
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

9 years agoSubzero: Changes needed for LLVM 3.7 integration.
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

9 years agoSubzero: Remove a compile-time warning.
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

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