native_client/pnacl-llvm.git
3 days agoAdd missing unittest file NaClObjDumpTypesTest.cpp to CMakeLists.txt master
Karl Schimpf [Fri, 29 Aug 2014 20:05:44 +0000 (13:05 -0700)]
Add missing unittest file NaClObjDumpTypesTest.cpp to CMakeLists.txt

BUG=None
R=jvoung@chromium.org

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

4 days agoBuild test structure for unit testing pnacl-bcdis.
Karl Schimpf [Thu, 28 Aug 2014 20:06:24 +0000 (13:06 -0700)]
Build test structure for unit testing pnacl-bcdis.

Provides a facility to convert an array of integers into PNaCl records,
convert the PNaCl records into a memory buffer of bits, and then
run NaClObjDump on the memory buffer.

Also adds unit tests (using this test structure) for the "types" block.
Fix pnacl-bcdis abbreviation records.

Also fixes some minor bugs in pnacl-bcdis (mostly proper flushing
of the generated objdump, and fixing error message contents).

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

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

5 days agoExpandByVal: Increase the memcpy call's alignment, for Emscripten's benefit
Mark Seaborn [Wed, 27 Aug 2014 23:14:04 +0000 (16:14 -0700)]
ExpandByVal: Increase the memcpy call's alignment, for Emscripten's benefit

Use the alignment from the argument type -- the same alignment used
for the alloca.

Original patch by Alon Zakai (azakai@mozilla.com):
https://codereview.chromium.org/177293010/

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3798
TEST=expand-byval.ll

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

7 days agoAdd StripTls MinSFI LLVM pass
David Brazdil [Mon, 25 Aug 2014 21:52:15 +0000 (14:52 -0700)]
Add StripTls MinSFI LLVM pass

This pass removes the thread_local attribute from all global variables
until thread support is added into MinSFI.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
R=jvoung@chromium.org

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

10 days agoSpeed up flattening global variable initializers in PNaCl.
Karl Schimpf [Fri, 22 Aug 2014 19:33:09 +0000 (12:33 -0700)]
Speed up flattening global variable initializers in PNaCl.

Speeds up flattening of global variable initializers, by noting that
simple node replacements, within constant expresssions, can be
quadratic. To fix this, we flatten the original (global variable)
initializers, and then delete corresponding dead constants before
we do the replacements.

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

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

11 days agoAdded MinSFI RenameEntryPoint LLVM pass
David Brazdil [Fri, 22 Aug 2014 00:36:25 +0000 (17:36 -0700)]
Added MinSFI RenameEntryPoint LLVM pass

The pass renames the entry point in a PNaCl bitcode module in order to
avoid collisions when linking against standard C programs.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
R=jvoung@chromium.org

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

11 days agoPNaCl: Handle switch-ing on i1's in -nacl-promote-i1-ops.
Richard Diamond [Thu, 21 Aug 2014 21:51:35 +0000 (14:51 -0700)]
PNaCl: Handle switch-ing on i1's in -nacl-promote-i1-ops.

-nacl-promote-i1-ops simply transform these into branches.

This is for Rust, which generates these instructions in practice.

BUG= none
R=mseaborn@chromium.org, jfb@chromium.org
TEST= (cd toolchain_build/out/llvm_i686_linux_work && make check)

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

Patch from Richard Diamond <wichard@vitalitystudios.com>.

11 days agoFixed an integer overflow in MinSFI's utility function
David Brazdil [Thu, 21 Aug 2014 21:41:32 +0000 (14:41 -0700)]
Fixed an integer overflow in MinSFI's utility function

The computation of address subspace size was failing on machines
where 'long' is 32-bit. The type was replaced with 'long long'.

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

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

12 days agoWhitelist BitCasts in MinSFI's SandboxMemoryAccesses pass
David Brazdil [Wed, 20 Aug 2014 23:30:49 +0000 (16:30 -0700)]
Whitelist BitCasts in MinSFI's SandboxMemoryAccesses pass

The SandboxMemoryAccesses pass verifies that it has handled all
instructions with pointer-type operands. This patch adds support for
the previously unhandled BitCast instructions. Because they do not
need to have their operands sandboxed, they are merely whitelisted.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
R=jvoung@chromium.org

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

12 days agoClean up MinSFI
David Brazdil [Wed, 20 Aug 2014 18:18:48 +0000 (11:18 -0700)]
Clean up MinSFI

String constants were moved to the MinSFI header, alignment arithmetic
was replaced with LLVM's math functions, file names in build files sorted,
and some formatting was fixed. ExpandAllocas::runOnModule now also returns
true because it always creates a global variable.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
R=jvoung@chromium.org

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

13 days agoAdd SandboxIndirectCalls MinSFI LLVM pass
David Brazdil [Tue, 19 Aug 2014 22:04:11 +0000 (15:04 -0700)]
Add SandboxIndirectCalls MinSFI LLVM pass

This adds a pass which enforces basic control-flow integrity. It is
expected to be replaced by Tom Roeder's CFI once it is upstramed into
LLVM. See lib/Transforms/MinSFI/SandboxIndirectCalls.cpp for
implementation details.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
      manually tested on zlib compiled with PNaCl

R=jvoung@chromium.org

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

2 weeks agoAdd support for MinSFI address subspaces smaller than 32 bits.
David Brazdil [Fri, 15 Aug 2014 22:50:49 +0000 (15:50 -0700)]
Add support for MinSFI address subspaces smaller than 32 bits.

The prior implementation of MinSFI sandboxing assumed that the sandbox
will have access to 4GB of memory and hence cast pointers to i32.
This patch adds bit masking in order to further limit the size of
the addressable memory. This is necessary for supporting 32-bit
architectures.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
      manually tested on zlib compiled with PNaCl

R=jvoung@chromium.org

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

2 weeks agoRemove support for global forward references from PNaCl bitcode reader.
Karl Schimpf [Fri, 15 Aug 2014 20:27:51 +0000 (13:27 -0700)]
Remove support for global forward references from PNaCl bitcode reader.

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

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

2 weeks agoFix minor nits from CL https://codereview.chromium.org/477743002.
Karl Schimpf [Fri, 15 Aug 2014 15:56:48 +0000 (08:56 -0700)]
Fix minor nits from CL https://codereview.chromium.org/477743002.

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

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

2 weeks agoSimplify handling of forward (global) references in global initializers.
Karl Schimpf [Thu, 14 Aug 2014 22:59:55 +0000 (15:59 -0700)]
Simplify handling of forward (global) references in global initializers.

Fixes blocking issue where forward references (relocations) in global
initializers can slow. This fix does this by processing the PNaCl
globals block in two passes. The first pass generates the global
variables. The second pass adds the initializers. Since all global
variables are defined by the end of the first pass, no forward references
need be built for initializers.

Note: Due to release time constraints, cleaning up the code to
not generate placeholders has not been cleaned up. Rather, it
will be done in a separate CL.

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

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

2 weeks agoPNaCl: Add missing dependency and inits to bugpoint
David Brazdil [Thu, 14 Aug 2014 18:39:06 +0000 (11:39 -0700)]
PNaCl: Add missing dependency and inits to bugpoint

Previous commit a9f45cbf did not add MinSFI into CMake
dependencies and only initialized one of the MinSFI passes.

BUG= none
R=jvoung@chromium.org

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

2 weeks agoPNaCl: Zero extend or truncate alloca array sizes to i32.
Richard Diamond [Thu, 14 Aug 2014 15:30:23 +0000 (08:30 -0700)]
PNaCl: Zero extend or truncate alloca array sizes to i32.

Rust sometimes generates i64 array sizes. I also took the liberty of handling
< i32 arrays sizes for completeness, though Rust doesn't actually generate such.

BUG= none
TEST= (cd toolchain_build/out/llvm_i686_linux_work && make check)
R=mseaborn@chromium.org, jfb@chromium.org

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

Patch from Richard Diamond <wichard@vitalitystudios.com>.

2 weeks agoPNaCl: Initialize our passes in bugpoint.
Richard Diamond [Thu, 14 Aug 2014 00:34:55 +0000 (17:34 -0700)]
PNaCl: Initialize our passes in bugpoint.

No other functionality added.

BUG= none
R=jfb@chromium.org

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

Patch from Richard Diamond <wichard@vitalitystudios.com>.

2 weeks agoRe-order the PNaClABISimplifyPreOpt pass injection to be before opts.
Jan Voung [Wed, 13 Aug 2014 21:45:57 +0000 (14:45 -0700)]
Re-order the PNaClABISimplifyPreOpt pass injection to be before opts.

Put Pre earlier. Otherwise, the pre passes run after inlining, and other
std-link-opts, which ends up making the eh throw SJLJ tests crash when
we attempt to combine all the passes into one opt run:
https://codereview.chromium.org/324853003/

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

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

2 weeks agoFix an issue which allowed memory access outside a MinSFI sandbox.
David Brazdil [Wed, 13 Aug 2014 19:51:20 +0000 (12:51 -0700)]
Fix an issue which allowed memory access outside a MinSFI sandbox.

Applying the ExpandGEP optimization on memory intrinsics would allow to
set the src/dest addresses at the end of the guard region and access
the following 4GB of memory. The optimization is now applied only on
instructions manipulating first class values and the offset is limited
so that access beyond the guard region is not possible.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
R=jvoung@chromium.org

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

3 weeks agoAdd ExpandAllocas MinSFI LLVM pass
David Brazdil [Tue, 12 Aug 2014 00:39:05 +0000 (17:39 -0700)]
Add ExpandAllocas MinSFI LLVM pass

This pass expands out alloca instructions to operate on an untrusted
stack located inside the sandbox.
See lib/Transforms/MinSFI/ExpandAllocas.cpp for more details.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
      manually tested on zlib compiled with PNaCl

R=jvoung@chromium.org

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

3 weeks agoAdd AllocateDataSegment MinSFI LLVM pass
David Brazdil [Mon, 11 Aug 2014 22:34:21 +0000 (15:34 -0700)]
Add AllocateDataSegment MinSFI LLVM pass

This pass modifies the module so that the runtime can easily access its
data segment and copy it into the address subspace of the sandbox. See
lib/Transforms/MinSFI/AllocateDataSegment.cpp for details.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
R=jvoung@chromium.org

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

3 weeks agoConvert MinSFI's SandboxMemoryAccesses to a ModulePass
David Brazdil [Fri, 8 Aug 2014 20:31:35 +0000 (13:31 -0700)]
Convert MinSFI's SandboxMemoryAccesses to a ModulePass

The pass was crashing because the pass manager invokes doInitialize
prior to running the scheduled passes. When executed after data segment
allocation, its global variable had been removed.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
      manually tested on zlib compiled with PNaCl

R=mseaborn@chromium.org

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

4 weeks agoSpeed up construction of global initialzers in the PNaCl bitcode reader.
Karl Schimpf [Wed, 30 Jul 2014 17:29:41 +0000 (10:29 -0700)]
Speed up construction of global initialzers in the PNaCl bitcode reader.

Discovered that the replacement stategy for placeholder forward address
references for global variables, when parsing the bitcode, can be
very non-linear. This is due to the fact that LLVM IR creates unique
constants (i.e. no duplicates). As a result, the same initializer
may be copied several times, as each instance of a placeholder is
replaced.

This change guarantees that we only generate one copy of each
initializer, no matter how many placeholders appear in the
initializer.

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

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

4 weeks agoAdd SandboxMemoryAccesses MinSFI LLVM pass
David Brazdil [Tue, 29 Jul 2014 17:35:23 +0000 (10:35 -0700)]
Add SandboxMemoryAccesses MinSFI LLVM pass

This pass sandboxes all pointer-type arguments of memory access instructions. See the comments in lib/Transforms/MinSFI/SandboxMemoryAccesses.cpp for details.

Creates new MinSFI directories and modifies corresponding build files.

BUG= https://code.google.com/p/chromium/issues/detail?id=397177
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
      manually tested on zlib compiled with PNaCl

R=jvoung@chromium.org, mseaborn@chromium.org

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

6 weeks agoPNaCl atomics: clean up some of the code
JF Bastien [Mon, 21 Jul 2014 20:18:53 +0000 (13:18 -0700)]
PNaCl atomics: clean up some of the code

One of the class' methods isn't used anymore, and the ordering of error messages
can be slightly improved by refactoring some of the code to explicitly check for
invalid overloads.

R=dschuff@chromium.org
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
BUG= none

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

6 weeks agoFix pnacl-bcdis abbreviation records.
Karl Schimpf [Fri, 18 Jul 2014 22:27:30 +0000 (15:27 -0700)]
Fix pnacl-bcdis abbreviation records.

Due to a bug in NaClBitcodeParser::SetBID, the record values were not
cleared, resulting in the block ID of the SetBID being left in the
succeeding abbreviation record. This CL fixes this problem.

BUG=None
R=jvoung@chromium.org

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

7 weeks agoImprove atomic tests
JF Bastien [Tue, 15 Jul 2014 01:16:28 +0000 (18:16 -0700)]
Improve atomic tests

The testing for atomics was somewhat insufficient, and the file was getting too big. I split up the file and added more tests:
 - Use CHECK-LABEL, which we didn't have back when the tests were written.
 - Move the CHECK-NEXT for ret to the same line as the ret instruction, to make things more readable.
 - The atomic.ll file is now split up in 5 files.
 - Add the atomic_seq_cst.ll file which performs the same tests as volatile.ll but on sequentially-consistent atomics.
 - Add the atomic_others.ll file, which checks that the other atomic operations get promoted to seq_cst. This isn't as thorough as seq_cst and volatile testing because everything currently gets rewritten to seq_cst.

R=dschuff@chromium.org
TEST= self

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

7 weeks agoRefactor code so that intrinsics checks can be used by pnacl-bcdis.
Karl Schimpf [Mon, 14 Jul 2014 22:26:34 +0000 (15:26 -0700)]
Refactor code so that intrinsics checks can be used by pnacl-bcdis.

Moves code about intrinsic checks into a separate file, so that
it can be used by a) the PNaCl ABI verifier; b) pnacl-bcdis, and
c) NaClBitcodeReader can use to process signatures of intrinsics.

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

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

7 weeks agoTranslator: rematerialize constant vector loads
JF Bastien [Fri, 11 Jul 2014 23:36:58 +0000 (16:36 -0700)]
Translator: rematerialize constant vector loads

PNaCl's ABI doesn't contain constant vectors, they therefore need to be
rematerialized by the translator if we want to get the best optimizations
possible.

The CL also renames CombineVectorInstructions.cpp to BackendCanonicalize.cpp to
be more accurate about what the pass does: it can now affect more than vectors
because the above change affects bitcasts and loads in general (since it doesn't
make sense to only stick with vectors). Things should stay in this one pass so
that the translator can restrict itself to what's important to optimize, and do
so as fast as it can.

R=dschuff@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3893
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)

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

7 weeks agoReduce redundancy created by PNaCl's vector globalization pass
JF Bastien [Wed, 9 Jul 2014 20:31:19 +0000 (13:31 -0700)]
Reduce redundancy created by PNaCl's vector globalization pass

This change makes it easier to reconstruct shuffles, and reduces the pass'
reliance on constant merging. It's a toolchain only fix, meaning that no
translator update is needed, only a recompile.

The loads of constant vectors are still present and will be handled in a
separate change.

R=dschuff@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3893
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)

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

2 months agoTurn off type signature checking in pnacl-bcdis.
Karl Schimpf [Wed, 2 Jul 2014 18:37:36 +0000 (11:37 -0700)]
Turn off type signature checking in pnacl-bcdis.

Removes bug caused by inconsistency in PNaCl ABI document. States that
integral function parameter/return values must only be i32/i64.
However, for calls to (whitelisted) intrinsic funtions, type signatures can
have any integral size.

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

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

2 months agoGlobalizeConstantVectors: set Unnamed addr
JF Bastien [Wed, 2 Jul 2014 17:52:48 +0000 (10:52 -0700)]
GlobalizeConstantVectors: set Unnamed addr

The globalized vectors can be merged by constant merge when it knows that the
address doesn't matter, only the content does.

R=dschuff@chromium.org
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
BUG= none

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

2 months agoPNaClABIErrorReporter: remove last virtual
JF Bastien [Wed, 2 Jul 2014 17:38:22 +0000 (10:38 -0700)]
PNaClABIErrorReporter: remove last virtual

The previous CL:
  https://codereview.chromium.org/349683004/

Left one virtual method in PNaClABIErrorReporter.

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

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

2 months agoPNaCl SIMD: don't perform constant propagation in expand-shufflevector
JF Bastien [Tue, 1 Jul 2014 16:16:22 +0000 (09:16 -0700)]
PNaCl SIMD: don't perform constant propagation in expand-shufflevector

Using the IR builder leads to extra optimizations which usually would be useful,
but in the case of shufflevector they make reconstructing the shuffles harder
when translating. This change therefore uses manual instruction insertion, and
adjusts the tests accordingly.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3893
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
R=dschuff@chromium.org

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

2 months agoAdd skip block method to NaCl bitcode parser.
Karl Schimpf [Mon, 30 Jun 2014 17:55:17 +0000 (10:55 -0700)]
Add skip block method to NaCl bitcode parser.

This is needed by Subzero, to be able to skip blocks.

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

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

2 months agoFix comments about PIC return address calculation
Derek Schuff [Mon, 30 Jun 2014 16:00:23 +0000 (09:00 -0700)]
Fix comments about PIC return address calculation

The previous commit failed to update them to match the code.

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

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

2 months agoMake x86-64 sandbox-base-hiding call sequence work with PIC
Derek Schuff [Fri, 27 Jun 2014 23:16:37 +0000 (16:16 -0700)]
Make x86-64 sandbox-base-hiding call sequence work with PIC

The call sequence used on x86-64 to avoid storing the sandbox base
address on the stack was not PIC-friendly because it pushed the return
address as an immediate. When generating PIC code, manually calculate
the return address into a register and push that.

This includes a tiny cherry-pick of upstream r202418, which adds an
accessor for the relocation model to MCObjectFileInfo

R=mseaborn@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3873
TEST= LLVM regression

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

2 months agoFix Ninja/CMake build, broken by earlier change
Mark Seaborn [Fri, 27 Jun 2014 21:31:15 +0000 (14:31 -0700)]
Fix Ninja/CMake build, broken by earlier change

The earlier change, ed7a64c4217699967be9991e3a92df2826399ef7, added a
dependency from lib/Bitcode/NaCl/Analysis/ on the PNaCl ABI checker,
which wasn't declared.  This caused lib/libLLVMNaClBitAnalysis.so to
fail to link.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3814
TEST=build using Ninja
R=dschuff@chromium.org, jvoung@chromium.org

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

2 months agoAllow one module block in pnacl bitcode files for pnacl-bcdis.
Karl Schimpf [Thu, 26 Jun 2014 16:10:14 +0000 (09:10 -0700)]
Allow one module block in pnacl bitcode files for pnacl-bcdis.

Also adds operator<< for class NaClBitcodeRecord.

BUG=None
R=jvoung@chromium.org

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

2 months agoFinish removing the finer grained Sfi* control flags
Jan Voung [Wed, 25 Jun 2014 19:28:09 +0000 (12:28 -0700)]
Finish removing the finer grained Sfi* control flags

Commit d021e666574ea564460a84588edc272eb65a4cd6 changed
checks to key off of NaCl instead, to be consistent with
X86. So nothing actually uses the flags anymore.

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

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

2 months agoRemove llvm -pnaclabi-allow-dev-intrinsics flag.
Jan Voung [Wed, 25 Jun 2014 19:16:30 +0000 (12:16 -0700)]
Remove llvm -pnaclabi-allow-dev-intrinsics flag.

Last users appear to have been removed and it's removed from the
driver plumbing in: https://codereview.chromium.org/333033002/

BUG=none
R=mseaborn@chromium.org

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

2 months agoFix issues with verifying PNaCl ABI conditions in pnacl-bcdis.
Karl Schimpf [Tue, 24 Jun 2014 18:26:43 +0000 (11:26 -0700)]
Fix issues with verifying PNaCl ABI conditions in pnacl-bcdis.

Does several things:

(1) Factors out common support functions from PNaClABIVerfiyFunctions
and PNaClABIVerifyModules, so that they can be used without a pass
manager.

(2) Fixes DataLayout used by pnacl-bcdis to match NaClBitcodeReader.

(3) Uses the functions factored out of (1) in pnacl-bcdis.

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

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

2 months agoRemove special nacltrap handling from X86 NaCl.
Jan Voung [Mon, 23 Jun 2014 17:26:53 +0000 (10:26 -0700)]
Remove special nacltrap handling from X86 NaCl.

I believe it was added previously to work around the validator not
accepting ud2, so it would emit a null pointer deref instead.

However the validator is fixed now:
https://code.google.com/p/nativeclient/issues/detail?id=2094

There was some asm parsing support for parsing a "nacltrap" pseudo-inst,
but the -filetype=asm path never emitted a "nacltrap" since the nacl-as
didn't support that pseudo-inst. I.e., it was supported on the parsing
side but not the writing side. It doesn't look like anything used this
parsing support, and it wouldn't have worked with nacl-as anyway.

BUG=none
R=dschuff@chromium.org

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

2 months agoPNaCl dynamic loading: Allow the "__pnacl_pso_root" symbol as an entry point
Mark Seaborn [Fri, 20 Jun 2014 23:11:23 +0000 (16:11 -0700)]
PNaCl dynamic loading: Allow the "__pnacl_pso_root" symbol as an entry point

Whereas pexes will allow a single external function called "_start",
PSOs (PNaCl dynamically loadable objects) will allow a single external
global variable called "__pnacl_pso_root".

Change PNaClABISimplify.cpp to allow "__pnacl_pso_root" to be left as
external.

Change the ABI verifier to allow "__pnacl_pso_root" to be defined (but
not at the same time as "_start").

Extend some tests to cover GlobalVariables as well as functions.  Make
one CHECK-NOT test stricter.

Note that this will effectively be inaccessible by PNaCl apps, until we
add an IRT interface and browser-side plumbing for loading PSOs.  If an
app were to try to load a PSO as an executable pexe, the ABI verifier
would allow the PSO, but the native-link of the PSO would fail because
the PSO wouldn't define "_start" (it would only define
"__pnacl_pso_root").

This means the change doesn't really expose any functionality to web
apps, so I don't think it's necessary to put this behind a flag.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3873
TEST=lit tests
R=dschuff@chromium.org

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

2 months agoAdd assembly text to function blocks in pnacl-bcdis.
Karl Schimpf [Thu, 19 Jun 2014 20:33:05 +0000 (13:33 -0700)]
Add assembly text to function blocks in pnacl-bcdis.

Adds assembly text to function blocks in pnacl-bcdis.

Also constraints vector types appearing in the types block, and
defines assembly for block in the valuesymtab block.

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

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

2 months agoPNaCl: Fix uninitialised StreamingMode field in PNaClABIVerifyModule
Mark Seaborn [Wed, 18 Jun 2014 15:25:39 +0000 (08:25 -0700)]
PNaCl: Fix uninitialised StreamingMode field in PNaClABIVerifyModule

This would be uninitialised when using "-verify-pnaclabi-module" with
"opt", but not when using "pnacl-abicheck".

BUG=none
TEST=ran "opt -verify-pnaclabi-module" under valgrind
R=dschuff@chromium.org

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

2 months agoPNaCl: Make PNaClABIVerifyModule complain if _start() isn't defined
Mark Seaborn [Tue, 17 Jun 2014 22:40:21 +0000 (15:40 -0700)]
PNaCl: Make PNaClABIVerifyModule complain if _start() isn't defined

Make the ABI checker stricter so that it complains if the module doesn't
contain an entry point.

If we mistakenly internalised _start() (but left its name in place),
previously we might not have caught that because pnacl-llc
re-externalises symbols when doing streaming translation.  This new
check would catch the mistake.

Update some tests to define _start() so that they still pass.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3873
TEST=lit tests
R=dschuff@chromium.org

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

2 months agoPNaCl translator: combine insertelement / extractelement patterns generated by the...
Derek Schuff [Tue, 17 Jun 2014 20:25:01 +0000 (13:25 -0700)]
PNaCl translator: combine insertelement / extractelement patterns generated by the toolchain into shufflevector
shufflevector isn't part of the PNaCl ABI, insertelement /
extractelement sequences are instead generated, but they help in
generating higher performance code. This pass recognizes the patterns at
translation time and reconstructs shufflevector, allowing the generated
code to perform better.

R=jvoung@chromium.org
TEST= ninja check
BUG= http://code.google.com/p/nativeclient/issues/detail?id=2205

This patch re-applies 1eecfea5ce

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

2 months agoUpdate default mcpu values to not use SSSE3 and tune for pre-sandybridge CPUs
Derek Schuff [Tue, 17 Jun 2014 16:30:48 +0000 (09:30 -0700)]
Update default mcpu values to not use SSSE3 and tune for pre-sandybridge CPUs

The "x86-64" value is the base 64-bit target which does not
use SSE3+ as core2 did.
The pentium4m mcpu value is the same as pentium4 but uses
x86.td's  FeatureSlowBTMem attribute meaning
"Bit testing of memory is slow" which is true for pre-sandybridge
CPUs (which are probably still prevalent, and in any case
matches the 64-bit code)
BUG=https://code.google.com/p/nativeclient/issues/detail?id=2205
R=jvoung@chromium.org

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

2 months agoMake PNaCl type checking visible so that pnacl-bcdis can use.
Karl Schimpf [Mon, 16 Jun 2014 22:04:08 +0000 (15:04 -0700)]
Make PNaCl type checking visible so that pnacl-bcdis can use.

BUG=None
R=jvoung@chromium.org

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

2 months agoPNaCl sandboxed translator: fix crash
JF Bastien [Fri, 13 Jun 2014 20:46:19 +0000 (13:46 -0700)]
PNaCl sandboxed translator: fix crash

I added a data layout usage to the translator [*] and broke the sandboxed
translator because the function ABI verification pass was added before the pass
manager contained a data layout, causing a default data layout to be constructed
(which errors out). This CL fixes the breakage by making it possible to use data
layout in the translator, even when sandboxed.

  [*]: https://codereview.chromium.org/321733002/

This CL also stubs out LLVM's current_path function because getcwd returns an
error when run inside the sandboxed translator (it does go through a NaCl
syscall, but we don't override it to anything meaningful for the
translator). This happens only in debug builds (which I was testing with) because
it's only asserted on (so release builds don't see this error).

R=jvoung@chromium.org, dschuff@chromium.org
TEST= ./pnacl/build.sh translator-all && ./scons bitcode=1 use_sandboxed_translator=1 small_tests
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3870

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

2 months agoFactor out NaCl bitcode value decoders from bitcode reader.
Karl Schimpf [Thu, 12 Jun 2014 17:41:06 +0000 (10:41 -0700)]
Factor out NaCl bitcode value decoders from bitcode reader.

Factor out NaCl bitcode value decoders into a separate file, so
that both the bitcode reader and pnacl-bcdis can use them.

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

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

2 months agoPNaCl SIMD: allow element-aligned vector load/store
JF Bastien [Wed, 11 Jun 2014 16:23:54 +0000 (09:23 -0700)]
PNaCl SIMD: allow element-aligned vector load/store

PNaCl currently breaks up vector load/store instructions into the corresponding
sub-elements of the vector using {insert/extract}element followed by scalar
load/store. This was originally done so that version 0 of PNaCl SIMD wouldn't
have to bother with vector load/store (especially their alignment), punting all
complexity to existing scalar instructions. This is very suboptimal
performance-wise, and re-creating the vector load/store on the translator side
isn't a trivial matter and has several caveats.

Add support for vector load/store, aligned to their element size, in PNaCl's
ABI.

R=jvoung@chromium.org
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3870

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

2 months agoPNaCl: run constantmerge after globalizing constant vectors
JF Bastien [Wed, 11 Jun 2014 00:36:58 +0000 (17:36 -0700)]
PNaCl: run constantmerge after globalizing constant vectors

This should help reduce the number of global constants, thereby reducing the
pexe size.

R=jvoung@chromium.org
BUG= none

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

2 months agoFix forward reference bug in pnacl-bcdis.
Karl Schimpf [Tue, 10 Jun 2014 21:09:27 +0000 (14:09 -0700)]
Fix forward reference bug in pnacl-bcdis.

Fixes bug where relocation records in the globals block can
refer to global addresses not yet defined. Previously,
the Bitcode Id for such references were incorrectly labeled
as function-level identifiers. Now, they correctly refer
to the forward referenced global address ID.

BUG=None
R=jvoung@chromium.org

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

2 months agoAdd PassManager to pnacl-abicheck and pnacl-llc
JF Bastien [Mon, 9 Jun 2014 23:28:09 +0000 (16:28 -0700)]
Add PassManager to pnacl-abicheck and pnacl-llc

I need to get a DataLayout in the translator (to deal with vector alignment),
and this requires a PassManager. There are other unexpected dependencies that
crop up when trying to go halfway without adding a PassManager (e.g. the
AsmPrinter is null and crashes on the mangler), but in the end the following
line is the one that requires the PassManager:
  include/llvm/PassAnalysisSupport.h:200

R=jvoung@chromium.org, dschuff@chromium.org
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3870
NOTRY=true

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

2 months agoFix block bug in "pnacl-bccompress --remove-abbreviations".
Karl Schimpf [Fri, 6 Jun 2014 21:24:07 +0000 (14:24 -0700)]
Fix block bug in "pnacl-bccompress --remove-abbreviations".

If we are removing abbreviations from a PNaCl bitcode file
(in pnacl-bccompress), be sure to reduce block abbreviation size
to only allow default abbreviations.

BUG=None
R=jvoung@chromium.org

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

2 months agoRetry reverting defs list for naclcalls x86-64
Jan Voung [Wed, 4 Jun 2014 23:03:58 +0000 (16:03 -0700)]
Retry reverting defs list for naclcalls x86-64

This retries the x86-64 version of commit:
bd61bacb04eaac6fdc3107136413b6ccdb9273e5.

The original change tickled a stack corruption/memory bug
exercised by an SDK test. After the test code runs and
returns, the test harness needs to get the gtest "this"
pointer from rbx. Usually rbx is saved/restored on/from
the stack.

With calls like (a) early_gtest_func -> (b) gtest_framework_func
-> (c) actual_test_func -> (d)..., the pre-patched code
used rbx in both (b) and (c), so stored a copy of rbx at
both (b) and (c). The stack corruption corrupted (c).
Since the pre-patched code still had a copy in (b), it
could use rbx fine in (a). However, the newer code
would use the corrupted version from (c) in (a).

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

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

3 months agoPNaCl: Remove warnings about TLS/init_array variables being unreferenced
Mark Seaborn [Mon, 2 Jun 2014 17:13:51 +0000 (10:13 -0700)]
PNaCl: Remove warnings about TLS/init_array variables being unreferenced

For example:

Warning: Variable __fini_array_start not referenced
Warning: Variable __fini_array_end not referenced
Warning: Variable __tls_template_start not referenced
Warning: Variable __tls_template_tdata_end not referenced
Warning: Variable __tls_template_end not referenced
Warning: Variable __tls_template_alignment not referenced

These warnings often occur when building libc-free programs.  This is
actually fairly common, so it makes sense to drop these warnings.
They're too noisy -- they hardly ever indicate a problem.

BUG=none
TEST=none
R=jvoung@chromium.org

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

3 months agoAdd assembly for abbreviations in pnacl-bcdis.
Karl Schimpf [Mon, 2 Jun 2014 16:15:34 +0000 (09:15 -0700)]
Add assembly for abbreviations in pnacl-bcdis.

Adds assembly syntax for abbreviations, and the corresponding abbreviation
index when the abbreviation is used.

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

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

3 months agoRevert tablegen localmods for 32-bit naclcalls. Use normal calls.
Jan Voung [Fri, 30 May 2014 16:31:06 +0000 (09:31 -0700)]
Revert tablegen localmods for 32-bit naclcalls. Use normal calls.

There isn't much reason for these extra TD nodes.
Unlike 64-bit nacl, there isn't a difference in
pointer size in the data layout. Moreover, there are
separate non-codegen nodes for the assembler's convenience
"isAsmParserOnly = 1" nodes. Those are for parsing
"naclcall" (which aligns to end of bundle) vs "call" (which
does not align to end) in .S files. We might move to a
model where NaCl always aligns any "call" instruction it
sees anyway.

The 64-bit naclcalls are a bit hairier since we have a
different pointer size from normal X86, so can't reuse the
normal 64-bit tablegen nodes. Either pattern matching will
fail, or register copies will fail w/ things like:

mov %edi, %rax // ???
jmp *%rax

This has a side-effect of redoing the "Remove the Defs list
in X86InstrNaCl naclcall, since calls now use regmask."
CL's effects for 32-bit, to regain some of the speedups.
This also makes the x86-32 backend more similar to the ARM
backend, in that NaCl did not need a special call node.

E.g., the dip from landing and the undip from reverting:
https://chromeperf.appspot.com/report?masters=NativeClient&bots=lucid_64-newlib-x86_32-pnacl-spec&tests=naclperf%2Fcompiletime_gcc&checked=core&start_rev=13220&end_rev=13252

How to get that for 64-bit calls still TBD.

BUG=none
R=stichnot@chromium.org

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

3 months agoRevert "Remove the Defs list in X86InstrNaCl naclcall, since calls now use regmask."
Jan Voung [Wed, 28 May 2014 02:12:25 +0000 (19:12 -0700)]
Revert "Remove the Defs list in X86InstrNaCl naclcall, since calls now use regmask."

This reverts commit bd61bacb04eaac6fdc3107136413b6ccdb9273e5.

It appears to be causing a miscompile in the SDK nacl_io_socket_test debug
build, leading to a segfault in some gtest code. Revert for now since
correct code is better than 5-10% faster compile time in O2.

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

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

3 months agoPNaCl: Fix setjmp() by adding the "returns_twice" attribute back
Mark Seaborn [Sun, 25 May 2014 00:21:02 +0000 (17:21 -0700)]
PNaCl: Fix setjmp() by adding the "returns_twice" attribute back

This fixes a bug in which stack slots could get reused by the backend.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3733
TEST=lit test + run_longjmp_stackslots_test being added to NaCl Scons tests
R=jfb@chromium.org

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

3 months agoNaCl: Fix memset() for Non-SFI ARM
Mark Seaborn [Fri, 23 May 2014 20:51:13 +0000 (13:51 -0700)]
NaCl: Fix memset() for Non-SFI ARM

The backend was calling memset() but using the calling conventions for
__aeabi_memset(), which swap two of the arguments.  We need to extend
the existing NaCl localmod to fix this.

Declare EnableARMAEABIFunctions so that another file can refer to it.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3809
TEST=run_memcpy_move_set_test_irt + new lit test
R=dschuff@chromium.org

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

3 months agoFix compiler error for mac-pnacl-x86_32 for CL 298803005.
Karl Schimpf [Fri, 23 May 2014 20:10:00 +0000 (13:10 -0700)]
Fix compiler error for mac-pnacl-x86_32 for CL 298803005.

src/llvm/lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp:1640:
error: no matching function for call to
'<unnamed>::SignRotatedInt::SignRotatedInt(<unnamed>::SignRotatedInt)'

BUG=None
R=jfb@chromium.org

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

3 months agoAdd assembly code for the constants block in pnacl-bcdis.
Karl Schimpf [Fri, 23 May 2014 17:49:04 +0000 (10:49 -0700)]
Add assembly code for the constants block in pnacl-bcdis.

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

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

3 months agoRemove writing useless abbreviation by the PNaCl bitcode writer.
Karl Schimpf [Fri, 23 May 2014 17:33:35 +0000 (10:33 -0700)]
Remove writing useless abbreviation by the PNaCl bitcode writer.

That is: TYPE_POINTER_ABBREV  [8, fixed(3), 0]

BUG=None
R=jvoung@chromium.org

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

3 months agoFix include file dependency in NaClObjDumpStream.h
Karl Schimpf [Fri, 23 May 2014 16:54:58 +0000 (09:54 -0700)]
Fix include file dependency in NaClObjDumpStream.h

BUG= None
R=jvoung@chromium.org

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

3 months agoAdd support for building subzero with LLVM
Derek Schuff [Thu, 22 May 2014 23:22:13 +0000 (16:22 -0700)]
Add support for building subzero with LLVM

Since subzero depends on LLVM components, it makes sense to build it
along with the LLVM build. Also, toolchain_build doesn't have support
for a target to depend on another target's working directory. We may want
to fix that in the future, but for now it's simpler to do the build
together with LLVM.

This CL allows subzero to be built from an external directory similar to
the way clang is. However we just use a Make variable directly insetad
of a configure flag to avoid regenerating autoconf files.

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

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

3 months agoAbstract out memory pool notion from PNaCl text formatter.
Karl Schimpf [Thu, 22 May 2014 22:34:31 +0000 (15:34 -0700)]
Abstract out memory pool notion from PNaCl text formatter.

The PNaCl bitcode objdumper defines several simple memory pools for
different kinds of token directives. Abstracts out this concept
with a template, simplifying the code.

BUG=None
R=jvoung@chromium.org

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

3 months agoRemoving FlagSfi* in LLVM -- check Subtarget->isTargetNaCl() instead.
Jan Voung [Thu, 22 May 2014 22:27:28 +0000 (15:27 -0700)]
Removing FlagSfi* in LLVM -- check Subtarget->isTargetNaCl() instead.

We can't remove the flags just yet because the driver still refers to them.
So, as a first step just don't use the flag. Then after a deps roll, I'll remove
the references from the driver, and then we can remove the flags themselves.

For the constant pool disabling, check useConstIslands
instead of FlagSfiDisableCP, and initialize UseConstIslands
appropriately for NaCl.

Had to adjust some of the tests slightly:
(*) some did not expect sandboxing, but expected a specific instruction seq
(*) one fast-isel case only handled static relocations w/ constant islands disabled.

Remove FlagSfiZeroMask right now, since there are no users
in NaCl repo. The other flags are still there because the
NaCl repo's pnacl-translate.py still refers to them.

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

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

3 months agoAdd recognition of abbreviation records in pnacl-bcdis.
Karl Schimpf [Wed, 21 May 2014 21:36:55 +0000 (14:36 -0700)]
Add recognition of abbreviation records in pnacl-bcdis.

Adds code to uses a listener to capture abbreviations in
pnacl-bcdis.

Also discovered that ExitBlock's were not being handled
very consistenly (between using a Listener or not) when
using class NaClBitcodeParser. Cleaned up this issue.

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

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

3 months agoRemove the Defs list in X86InstrNaCl naclcall, since calls now use regmask.
Jan Voung [Wed, 21 May 2014 15:27:47 +0000 (08:27 -0700)]
Remove the Defs list in X86InstrNaCl naclcall, since calls now use regmask.

LLVM r150638 made it so that call instructions no longer need the list
of all call-clobbered registers:
https://llvm.org/viewvc/llvm-project?view=revision&revision=150638

Make the NaCl variants of calls more like the LLVM
variants. At some point perhaps the special calls
can be removed an just use the normal calls w/ the
appropriate operand types.

This should make things a bit faster w/ NaCl (get the gains of switching
to the regmask vs the long list of defs). E.g.,:

0.38  seconds to  compile gzip vs 0.4 seconds.

BUG=none (misc cleanup)
R=dschuff@chromium.org

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

3 months agoExtract out PNaCl objdumper into a library file.
Karl Schimpf [Tue, 20 May 2014 20:51:57 +0000 (13:51 -0700)]
Extract out PNaCl objdumper into a library file.

This is in preparation of adding error examples for the PNaCl
objdumper. By being in a library, we can add unit tests that
mangle a sequence of records in the bitcode file, and see
what happens when dumped.

BUG= https://codereview.chromium.org/279523004
R=jvoung@chromium.org

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

3 months agoGeneralize pnacl-bccompress to be able to remove existing abbreviations.
Karl Schimpf [Tue, 20 May 2014 20:45:35 +0000 (13:45 -0700)]
Generalize pnacl-bccompress to be able to remove existing abbreviations.

Adds a flag to pnacl-bccompress. When true, the input file is copied but
all abbreviations are removed. This allows us to generate simple
bitcode files (for examples in the PNaCl bitcode file ABI), as well
as determine how effective existing abbreviations are in pnacl-freeze.

BUG=None
R=jvoung@chromium.org

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

3 months agoRevert "PNaCl translator: combine insertelement / extractelement patterns generated...
Derek Schuff [Tue, 20 May 2014 16:47:47 +0000 (09:47 -0700)]
Revert "PNaCl translator: combine insertelement / extractelement patterns generated by the toolchain into shufflevector"

This reverts commit 1eecfea5ce79d611558e8c132944fe752cca8278.

Many (most?) try jobs are failing the shufflevector test now, whereas they were
mostly (all?) passing before.

Original review:
  https://codereview.chromium.org/282553003/

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

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

3 months agoAdd abbreviation index to records in pnacl-bcdis output.
Karl Schimpf [Mon, 19 May 2014 16:47:17 +0000 (09:47 -0700)]
Add abbreviation index to records in pnacl-bcdis output.

The objdumper did not show the abbreviation index used. Add
this information into the output. To make sure that abbreviation
indices are not confused with record address, the record addresses
are put in a separate column.

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

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

3 months agoImprove readability of valuesymtab blocks in PNaCl bitcode.
Karl Schimpf [Mon, 19 May 2014 16:13:57 +0000 (09:13 -0700)]
Improve readability of valuesymtab blocks in PNaCl bitcode.

If the name of a symbol is not alphanumeric (i.e. Char6) in a
valuesymtab block of PNaClBitcode. Print all Char6 characters
as characters, so that it is easier to read.

BUG=None
R=dschuff@chromium.org

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

3 months agoAdd assembly code for the globals block in pnacl-bcdis.
Karl Schimpf [Mon, 19 May 2014 16:08:17 +0000 (09:08 -0700)]
Add assembly code for the globals block in pnacl-bcdis.

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

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

3 months agoGenerate assembly instructions for value symtab block in pnacl-bcdis.
Karl Schimpf [Fri, 16 May 2014 17:41:11 +0000 (10:41 -0700)]
Generate assembly instructions for value symtab block in pnacl-bcdis.

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

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

3 months agoRemove nosys from llvm sandboxed build.
Jan Voung [Fri, 16 May 2014 17:07:22 +0000 (10:07 -0700)]
Remove nosys from llvm sandboxed build.

It's just an empty library now. It might be the last
reference to libnosys in scons. (sdk still references gyp)

Also remove -lnacl and -lm since those will automatically get
pulled in by pnacl-clang++ when linking.

BUG=none
R=dschuff@chromium.org

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

3 months agoPNaCl translator: combine insertelement / extractelement patterns generated by the...
JF Bastien [Mon, 12 May 2014 22:48:17 +0000 (15:48 -0700)]
PNaCl translator: combine insertelement / extractelement patterns generated by the toolchain into shufflevector

shufflevector isn't part of the PNaCl ABI, insertelement /
extractelement sequences are instead generated, but they help in
generating higher performance code. This pass recognizes the patterns at
translation time and reconstructs shufflevector, allowing the generated
code to perform better.

R=dschuff@chromium.org
TEST= ninja check
BUG= http://code.google.com/p/nativeclient/issues/detail?id=2205

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

3 months agoNaClAbbrevListener: add missing virtual dtor
JF Bastien [Wed, 7 May 2014 22:29:00 +0000 (15:29 -0700)]
NaClAbbrevListener: add missing virtual dtor

It was generating a warning at build time.

R= kschimpf@chromium.org
BUG= warning at build time

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

3 months agoPNaCl SIMD: allow the bitcode reader to read select instructions properly
JF Bastien [Wed, 7 May 2014 18:33:52 +0000 (11:33 -0700)]
PNaCl SIMD: allow the bitcode reader to read select instructions properly

Vector selects weren't handled properly by the NaCl bitcode reader but
were handled properly by the LLVM one: the addition of vectors was
missing tests for select with a vector mask, which had (correctly) been
removed from the NaCl bitcode reader but not added back when vector
support was added.

R=dschuff@chromium.org, kschimpf@chromium.org
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check-all)
BUG= https://code.google.com/p/nativeclient/issues/detail?id=2205

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

3 months agoAdd check that expected number of types match found types in pnacl-bcdis
Karl Schimpf [Tue, 6 May 2014 20:46:03 +0000 (13:46 -0700)]
Add check that expected number of types match found types in pnacl-bcdis

BUG=None
R=dschuff@chromium.org

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

3 months agoAdd virtual destructor to class NaClBitcodeParserListener.
Karl Schimpf [Tue, 6 May 2014 20:43:57 +0000 (13:43 -0700)]
Add virtual destructor to class NaClBitcodeParserListener.

Removes compliation warning message about the class using
virtual methods, but not defining a virtual destructor.

BUG=None
R=dschuff@chromium.org

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

3 months agoLLVM biased sandbox build: fix build issues
JF Bastien [Tue, 6 May 2014 17:31:44 +0000 (10:31 -0700)]
LLVM biased sandbox build: fix build issues

All minor issues: missing else, signed/unsigned mismatch warning, unused
variable, and lack of __clear_cache function (which shouldn't be called
from NaCl anyways).

The goal of a biased sandbox build is to allow the sandboxed translator
to call CPUID on x86 so that it can figure which SIMD instructions can
be generated.

R=dschuff@chromium.org, jvoung@chromium.org
TEST= ./pnacl/build.sh translator-all
BUG= https://code.google.com/p/nativeclient/issues/detail?id=2205

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

3 months agoPNaCl: Add option to turn off use of __aeabi_* functions for Non-SFI NaCl
Mark Seaborn [Mon, 5 May 2014 23:18:09 +0000 (16:18 -0700)]
PNaCl: Add option to turn off use of __aeabi_* functions for Non-SFI NaCl

Currently, PNaCl's arm-nonsfi target uses the triple
"armv7a-linux-none", which uses soft-float, which isn't the right ABI
for Non-SFI NaCl.

Switching to a triple that uses hard-float
(e.g. "armv7a-linux-gnueabihf") has the side effect of causing llc to
generate uses of __aeabi_* functions, which PNaCl's libgcc.a (from
compiler-rt) doesn't provide.

In the longer term, the cleaner way to address that is to build
compiler-rt to provide __aeabi_* functions, but doing that for SFI NaCl
would involve porting some ARM assembly code to SFI NaCl, and that might
be a minor performance regression -- e.g. lib/arm/aeabi_uidivmod.S
defines __aeabi_uidivmod() as a wrapper for __udivmodsi4().

For now, just extend the existing localmod so that we can use it for
Non-SFI NaCl too.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3809
TEST=also tested with pnacl-translate.py change
R=dschuff@chromium.org

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

4 months agoFix bug introduced by method rename for pnacl-bcdis.
Karl Schimpf [Thu, 1 May 2014 21:39:12 +0000 (14:39 -0700)]
Fix bug introduced by method rename for pnacl-bcdis.

Fix bug introduced into pnacl-bcdis, due to separate CL landing near the
same time, and that CL renamed method to ProcessBlockInfo.

BUG=None
R=jvoung@chromium.org

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

4 months agoInitial implementation of pnacl-bcdis.
Karl Schimpf [Thu, 1 May 2014 15:52:14 +0000 (08:52 -0700)]
Initial implementation of pnacl-bcdis.

Defines a text form for records in PNaCl bitcode. Currently excludes
adding abbreviation information. Text of instructions etc. are based
on LLVM usage.

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

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

4 months agoAdd listener to PNaCl bitstream reader to capture abbreviations.
Karl Schimpf [Wed, 30 Apr 2014 21:38:58 +0000 (14:38 -0700)]
Add listener to PNaCl bitstream reader to capture abbreviations.

Defines a listener to capture abbreviations read by the PNaCl
bitstream reader, so that PNaCl bitcode parsers can use this
information during analysis.

Also simplifies pnacl-bccompress by using this API to capture
abbreviations as they are read.

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

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

4 months agoPNaCl SIMD: expand shufflevector
JF Bastien [Wed, 30 Apr 2014 01:27:44 +0000 (18:27 -0700)]
PNaCl SIMD: expand shufflevector

This allows hand writing code that used __builtin_shufflevector or
generating LLVM bitcode that uses shufflevector.

Corresponding end-to-end test:
  https://codereview.chromium.org/255213002

R=dschuff@chromium.org, nfullagar@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=2205
TEST=  (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check) && ./scons run_vector_shuffle_test bitcode=1

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

4 months agoAllow nested clustering in the NaCl text formatter.
Karl Schimpf [Mon, 28 Apr 2014 15:41:09 +0000 (08:41 -0700)]
Allow nested clustering in the NaCl text formatter.

Generalizes the notion of one level clustering to arbitrarily nested
clustering in the NaCl text formatter. Also fixes bad interaction
between local indentations and clustering in the old implementation.

Includes unit tests for NaCl text formatter.

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

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

4 months agoPNaCl vectors: disallow zeroinitializer, globalize them instead
JF Bastien [Tue, 22 Apr 2014 20:25:36 +0000 (13:25 -0700)]
PNaCl vectors: disallow zeroinitializer, globalize them instead

The bitcode reader/write didn't allow them, and small tests hadn't run into this issue yet.

R=jvoung@chromium.org, dschuff@chromium.org
TEST= make check
BUG= https://code.google.com/p/nativeclient/issues/detail?id=2205

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

4 months agopnacl-abicheck: initialize function pass before running it
JF Bastien [Mon, 21 Apr 2014 18:58:19 +0000 (11:58 -0700)]
pnacl-abicheck: initialize function pass before running it

PNaClABIVerifyFunctionsPass wasn being initialized, causing it to crash.

R=dschuff@chromium.org
TEST= pnacl-abicheck *.pexe
BUG= none

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

4 months agoRevert localmod for re-ordering -lLTO on link line for gold plugin.
Jan Voung [Mon, 21 Apr 2014 18:28:23 +0000 (11:28 -0700)]
Revert localmod for re-ordering -lLTO on link line for gold plugin.

We had a localmod fix for moving -lLTO to the end of the link line
but that was also done upstream, so the localmod is redundant:
http://llvm.org/bugs/show_bug.cgi?id=13262

vs

https://codereview.chromium.org/10693178/

BUG=none
R=dschuff@chromium.org

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

4 months agoRevert localmod workaround for dangling debug info assertion.
Jan Voung [Mon, 21 Apr 2014 16:22:09 +0000 (09:22 -0700)]
Revert localmod workaround for dangling debug info assertion.

Underlying problem may have been fixed with LLVM 3.4
http://llvm.org/bugs/show_bug.cgi?id=11225.

Was able to link, optimize, and translate pnacl-llc.pexe
and gold.pexe w/ -g, without asserting on shutdown as
before. Also tried dosbox and nacl SDK earth example,
but not the ARM IRT (previous test case) since that isn't
built by PNaCl anymore.

TEST=none (could never get a small repro because bugpoint
isn't useful for minimizing things with debug metadata).

BUG= http://code.google.com/p/nativeclient/issues/detail?id=2786
R=dschuff@chromium.org

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

4 months agoPNaCl: Add support for GCC/LLVM vector extensions
JF Bastien [Wed, 16 Apr 2014 23:18:02 +0000 (16:18 -0700)]
PNaCl: Add support for GCC/LLVM vector extensions

Add limited SIMD support for 128-bit wide SIMD for integers of size
8/16/32 and 32-bit floating-point, and operations that can be expressed
through GCC/LLVM vector extensions:
 *  http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html
 *  http://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors

64-bit integers and floating-point are currently missing and will be
added in a later CL.

Boolean vectors are represented as one bit per vector element, and the
number of elements in a boolean vector matches that of the supported
types (4, 8, 16).

256-bit and 512-bit vectors will take some work to support and may not
be supported in the near future.

Supported operations are:
  unary +, -
  ++, --
  +, -, *, /, %
  &, |, ^, ~
  >>, <<
  !, &&, ||
  ==, !=, >, <, >=, <=
  =

Vector types are usually defined in C/C++ with:
  __attribute__((vector_size(VEC_BYTES)))

Note that this includes some conversions, but only to/from supported
types.

Note that this CL doesn't specify all undefined behavior, and future CLs
will ensure that undefined behavior for vectors matches that of
scalars. Worth noting are div/mod by zero (specified in PNaCl as
trapping), shift by bitwidth or greater (currently unspecified, see bug
3604), out-of-bounds conversions, signed over/underflow.

The CL does ensure that undefined behavior due to alignment is the same
as for scalars by breaking up vector load/store into element-wise scalar
load/store. This pattern should be recognized by backends which support
unaligned vector load/store, but no effort was put into making sure that
this is the case.

Undefined behavior due to out-of-bounds vector indexing is eliminated by
going through the stack. This should also be recognized by backends.

Vector constant immediate aren't supported, and instead go through loads
from the constant global array.

No intrinsics on vectors are currently supported, they will be added by
later CLs.

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

Testing:
TEST= (cd ./toolchain_build/out/llvm_i686_linux_work/ && ninja check)
TEST= ./scons run_simd_ref_test bitcode=1 && ./scons run_simd_native_test bitcode=1
 * I also have an extra scons test for which I is in a separate CL:
   - https://codereview.chromium.org/222483002
 * We should also make sure that the GCC torture tests for vector extensions are enabled.

Reviewers:
 * For PNaCl bitcode reader/writer:
    - kschimpf
 * For PNaCl ABI and general passes:
    - jvoung, mseaborn, dschuff
 * For testing and vector support:
    - nfullagar
 * FYI on ABI change for Subzero:
    - stichnot, eliben, sehr

R=dschuff@chromium.org, jvoung@chromium.org, eliben@chromium.org, kschimpf@chromium.org, mseaborn@chromium.org, nfullagar@chromium.org, sehr@chromium.org, stichnot@chromium.org

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

4 months agoClean up handling of the previous token in NaCl Objdump.
Karl Schimpf [Wed, 16 Apr 2014 19:41:12 +0000 (12:41 -0700)]
Clean up handling of the previous token in NaCl Objdump.

Clean up the handling of the previous token in NaCl Objdump, by
having the top-level (directive) Apply method handle the text
in the token buffer, followed by a call to the directive specific
method MyApply.

Also removes access to several (otherwise protected) formatter methods,
since they are internals the directives should not be using.

BUG=None
R=jvoung@chromium.org

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