native_client/pnacl-llvm.git
2 days agoPNaCl: Add support for GCC/LLVM vector extensions master
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

2 days 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

3 days agoAdd a text formatter to NaClObjDumpStream to handle long lines.
Karl Schimpf [Tue, 15 Apr 2014 21:29:42 +0000 (14:29 -0700)]
Add a text formatter to NaClObjDumpStream to handle long lines.

Provide a simple facility to NaClObjDumpStream to handle long
lines. This is done by only requiring the user of an text formatter to
tokenize the printed text, and let the text formatter class
automatically handle insertion of newlines (and beginning of line
indentation).

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

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

4 days agoRemove LLVM's StreamInit/StreamInitWithOverrides. No longer used.
Jan Voung [Mon, 14 Apr 2014 21:53:23 +0000 (14:53 -0700)]
Remove LLVM's StreamInit/StreamInitWithOverrides. No longer used.

The drivers and chrome have changed to only use the
version that can support split modules (1 up to 16 threads).
E.g., from https://codereview.chromium.org/197023007

BUG=none
R=dschuff@chromium.org

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

2 weeks agoPNaCl bitcode reader: restrict some record sizes
JF Bastien [Wed, 2 Apr 2014 23:25:43 +0000 (16:25 -0700)]
PNaCl bitcode reader: restrict some record sizes

The PNaCl bitcode reader allows too many entries in some records, and
these extra entries never happen in practice. This change makes sure we
don't allow and then ignore too many things in the bitcode format.

This came up in:
  https://codereview.chromium.org/221693002/

R=kschimpf@google.com, jvoung@chromium.org, kschimpf@chromium.org
TEST= ./scons small_tests medium_tests bitcode=1
BUG= none

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

2 weeks agoFlattenGlobals: Only check size and alignment for non-opaque variables.
Jan Voung [Tue, 1 Apr 2014 17:55:04 +0000 (10:55 -0700)]
FlattenGlobals: Only check size and alignment for non-opaque variables.

For opaque-typed variables leave it as zero sized.

After the 3.4 merge, some libcxx tests with dead
variables have opaque types after linking instead of
having real types. In 3.3 the dead variable did link in
the actual type.

The dead variable would be removed after the FlattenGlobals
pass, but before that it ends up asserting in DataLayout
while trying to determine the size and alignment.

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

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

3 weeks agoPNaCl: Remove all whitespace-only localmods
Mark Seaborn [Fri, 28 Mar 2014 21:29:38 +0000 (14:29 -0700)]
PNaCl: Remove all whitespace-only localmods

This removes all localmod patch hunks that only add or remove empty
lines, since these can cause merge conflicts when merging from
upstream and they don't provide any benefit.

These changes were presumably left behind from localmods that were
later removed (either explicitly or as a result of merging an
upstreamed patch).

BUG=none
TEST=git diff $(git merge-base upstream/master HEAD) | python find_whitespace_patches.py
R=jvoung@chromium.org

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

3 weeks agoFix two trivial bugs in pnacl tools.
Karl Schimpf [Thu, 27 Mar 2014 19:47:52 +0000 (12:47 -0700)]
Fix two trivial bugs in pnacl tools.

1) Fix format string from "\%" to "%%", so that it prints "%"
   in pnacl-bccompress.cpp.

2) Add return value to Error method of naclbitc::ObjDumpStream.

BUG=None
R=jvoung@chromium.org

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

3 weeks agoAdd ability to print abbreviation usage in pnacl-bccompress.
Karl Schimpf [Thu, 27 Mar 2014 17:10:11 +0000 (10:10 -0700)]
Add ability to print abbreviation usage in pnacl-bccompress.

This is being added so that we can analyze common (compressed)
PNaCl bitcode files, to find common abbreviations that could
be moved into the bitcode writer.

BUG= None
R=jvoung@chromium.org

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

3 weeks agoCreate notion of objdump stream for PNaCl bitcode files.
Karl Schimpf [Thu, 27 Mar 2014 17:05:14 +0000 (10:05 -0700)]
Create notion of objdump stream for PNaCl bitcode files.

Creates a objdump stream for use with dumping PNaCl bitcode files.

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

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

3 weeks agoPNaCl bitcode writer: improve error message.
JF Bastien [Thu, 27 Mar 2014 16:33:10 +0000 (09:33 -0700)]
PNaCl bitcode writer: improve error message.

The error message when writing an instruction the NaCl writer didn't like was 'LLVM ERROR: Illegal instruction' which ins't quite true since the instruction is legal for LLVM, just not for the reduced NaCl ABI. Make that clearer.

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

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

3 weeks agoAdd PNaCl intrinsic declarations up front, before the function passes.
Jan Voung [Wed, 26 Mar 2014 22:40:14 +0000 (15:40 -0700)]
Add PNaCl intrinsic declarations up front, before the function passes.

Remove extra checks that were thrown off by adding decls during
the function passes.

BUG=http://code.google.com/p/nativeclient/issues/detail?id=3823
R=jfb@chromium.org, stichnot@chromium.org

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

4 weeks agoRevert localmods to llvm-extract and ExtractGV.
Jan Voung [Sat, 22 Mar 2014 00:53:21 +0000 (17:53 -0700)]
Revert localmods to llvm-extract and ExtractGV.

This reverts https://chromiumcodereview.appspot.com/10581042/
which was an early experiment for splitting modules (but done
on the developer side).

BUG= none
R=jfb@chromium.org

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

4 weeks agoFix the PNaCl cmake ninja build
JF Bastien [Fri, 21 Mar 2014 23:03:54 +0000 (16:03 -0700)]
Fix the PNaCl cmake ninja build

The build was broken with an inverted dependency, and a missing dependency.

R=jvoung@chromium.org, kschimpf@chromium.org
TEST= ./toolchain_build/toolchain_build_pnacl.py --verbose --cmake --install ./toolchain/pnacl_linux_x86/
BUG= none

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

4 weeks agoPNaCl ABI module verifier doesn't accept ConstantDataVector
JF Bastien [Fri, 21 Mar 2014 22:12:59 +0000 (15:12 -0700)]
PNaCl ABI module verifier doesn't accept ConstantDataVector

The check on isSimpleElement already precludes anything that isn't an
ArrayType, it seems like a simple oversight to check for
ConstantDataSequential (the supertype of ConstantDataArray and
ConstantDataVector).

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

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

4 weeks agoPNaCl/LLVM: add support for symbol wrapping through -Wl,--wrap
JF Bastien [Fri, 21 Mar 2014 16:57:53 +0000 (09:57 -0700)]
PNaCl/LLVM: add support for symbol wrapping through -Wl,--wrap

Support was removed a while ago because it was only used in the
now-deprecated nacl-mounts, otherwise completely untested, and based on
local modifications to Gold and LLVM.

Symbol wrapping is nonetheless used by some SDK users, and works with
GCC and regular LLVM, it would therefore be nice for it to work with
PNaCl.

The reverts, from which I cherry-picked the symbol wrapping code and
rebased to the latest Gold and LLVM:
  https://codereview.chromium.org/22831032
  https://codereview.chromium.org/119203005
  https://codereview.chromium.org/23398002

The latest bug in which this code was changed (before deletion):
  https://code.google.com/p/nativeclient/issues/detail?id=2359

For reference, nacl_io wraps Newlib APIs in a completely different way:
  https://chromium.googlesource.com/experimental/chromium/src/+/refs/heads/master/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc

This is a four part change:
  LLVM: https://codereview.chromium.org/203623007
  Gold: https://codereview.chromium.org/197883026
  NaCl test: https://codereview.chromium.org/196943027
  pnacl-ld: https://codereview.chromium.org/205153004

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3818
TEST= ./scons run_wrap_test bitcode=0 && ./scons run_wrap_test bitcode=1
R=jvoung@chromium.org

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

4 weeks agoMoves abbreviation size computations to abbreviation blocks.
Karl Schimpf [Fri, 21 Mar 2014 16:03:11 +0000 (09:03 -0700)]
Moves abbreviation size computations to abbreviation blocks.

That is, from class NaClBitcodeCopyParser to BlockAbbreviations. This
cleans up and localizes these compuations to the best fitting class.

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

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

4 weeks agoAdd self-scheduling to threaded translation (vs static)
Jan Voung [Thu, 20 Mar 2014 23:16:54 +0000 (16:16 -0700)]
Add self-scheduling to threaded translation (vs static)

For the x86-64 sandboxed translator it makes about a 5%
difference over a set of 13 pexes from the web / webstore.
For python.pexe this reduces the translation time w/ 4
threads from 43 seconds to 37 seconds. Most of the other
web benchmarks only get slight improvements (if any).

For the ARM sandboxed translator, it's about 4.5%
aggregate difference for on the a15. Again, most of the
apps are a wash except for python, gamecake and the
gameboy emulator.

For the unsandboxed translator, this is often a wash,
except on a few benchmarks.

Testing on spec2k: Same or better for sandboxed translator.
Notably, crafty translation time drops from 1.59 secs to
1.19 secs w/ CPU utilization going from 1.8 to 2.7
w/ 4 threads. With two threads it's 2.1 secs to 1.6 secs
and CPU utilization from 1.2 to 1.7. Crafty was one of
the benchmarks that regressed after switching from 3.3
to 3.4 and perhaps part of it was bad scheduling.
The gcc and eon benchmarks also get a nice boost.
Similar on ARM: crafty drops from 5.7 to 4.8 w/ 2 threads.

Use a ChunkSize of 8, to reduce the synchronization
overhead somewhat, hopefully without hurting streaming
translation. This tapers off to 1 when there are
few functions remaining to attempt finer grained load
balancing near the end.

For some idea of how this affects streaming translation
the average function size for the benchmarks range
from 160 bytes to 1700 bytes. So 8 times that is
about 1.3KB to 14KB. Geomean of average func size is
570 bytes. For that geomean, 4 threads times 8 functions
would grab ~18KB at a time on geo-average-ish.

BUG= http://code.google.com/p/nativeclient/issues/detail?id=3777
R=jfb@chromium.org, stichnot@chromium.org

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

4 weeks agoRemoves untracked values distribution from the value size distribution.
Karl Schimpf [Wed, 19 Mar 2014 20:29:58 +0000 (13:29 -0700)]
Removes untracked values distribution from the value size distribution.

Removes the untracked values distribution from the value size
distribution, because it is never used. This speeds up pnacl-compress
by 5 to 8%.

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

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

4 weeks agoMove bitcode analysis files to corresponding library.
Karl Schimpf [Wed, 19 Mar 2014 19:50:57 +0000 (12:50 -0700)]
Move bitcode analysis files to corresponding library.

Moves analysis files from lib/Bitcode/NaCl/Reader to
lib/Bitcode/NaCl/Analysis.

BUG= None
R=jvoung@chromium.org

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

4 weeks agoFix the PNaCl ninja build
JF Bastien [Wed, 19 Mar 2014 00:24:34 +0000 (17:24 -0700)]
Fix the PNaCl ninja build

The abbrev tries test patch (https://codereview.chromium.org/183513002/) was missing two dependencies, which failed compilation (see comment in that codereview thread). This patch fixes the problem.

R=jvoung@chromium.org, kschimpf@chromium.org
TEST= ./toolchain_build/toolchain_build_pnacl.py --verbose --cmake --install ./toolchain/pnacl_linux_x86/ llvm_i686_linux
BUG= none

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

5 weeks agoSpeed up abbreviation index selection in pnacl-bccompress.
Karl Schimpf [Wed, 12 Mar 2014 14:45:27 +0000 (07:45 -0700)]
Speed up abbreviation index selection in pnacl-bccompress.

The old implementation would try every abbreviation in a block to
find the best abbreviation to apply. This works well when there
are only a few dozen abbreviations. However, after applying
pnacl-bccompress, the number of abbreviations can exceed 1000 for
a block. Hence, a better solution is needed. This code builds
tries, based on constants that appear in abbreviations, to filter
down what abbreviations can be applied to a bitcode record.

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

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

5 weeks agoLink LLVM bitcode reader into the sandboxed PNaCl for debug support.
Jan Voung [Tue, 11 Mar 2014 18:30:52 +0000 (11:30 -0700)]
Link LLVM bitcode reader into the sandboxed PNaCl for debug support.

Having both the PNaCl reader and the LLVM reader allows
developers to debug LLVM-flavored bitcode files with debug
metadata directly in the browser once developers opt-in.

Unify the interface of get*StreamedBitcodeModule between
NaCl and LLVM to both take a StreamingMemoryObject. For
LLVM, this must be a StreamingMemoryObject instead of a
StreamableMemoryObject, since LLVM uses the extra couple of
methods to skip through bitcode wrappers.

Disable Metadata ABI check when user opts in to LLVMFormat
(default is PNaClFormat for sandboxed translator).

Adds about 150KB (BitcodeReader, BitstreamReader, and
extra data, etc.) to each translator nexe.

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

TEST= coming up, but:

pnacl/test.sh test-x86-32-sbtc gdb_tests
pnacl/test.sh test-x86-64-sbtc gdb_tests
pnacl/test.sh test-arm-sbtc gdb_tests

w/ the following hacky patch: https://codereview.chromium.org/193403002/

Also try manually compiling chromium/src/out/Release/ppapi_nacl_tests_newlib.pexe.debug

R=jfb@chromium.org, kschimpf@google.com

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

6 weeks agoOne more mention of reduce-memory-footprint to remove.
Jan Voung [Tue, 4 Mar 2014 22:48:41 +0000 (14:48 -0800)]
One more mention of reduce-memory-footprint to remove.

Forgot to remove from previous CL.
Also reduce set of flags used to just -relocation-model
and -sfi-disable-cp, etc. to disable constant pools.
Clean up a bit too, now that CHECK-LABEL and llvm-objdump
are nicer.

BUG=none
R=jfb@chromium.org

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

6 weeks agoMake ReduceMemoryFootprint the default when streaming (w/ LazyBitcode).
Jan Voung [Tue, 4 Mar 2014 21:34:20 +0000 (13:34 -0800)]
Make ReduceMemoryFootprint the default when streaming (w/ LazyBitcode).

This overlaps mostly with LazyBitcode, and LazyBitcode
is flipped on in most cases we care about. Also reducing
memory footprint is a good thing to have by default
(already set by default for pnacl-translate.py, but
not for in-browser translator).

The driver change https://codereview.chromium.org/178043007/
must go in before this, otherwise there will still be
a reference to the flag. See driver CL description for more
notes...

BUG=none
R=jfb@chromium.org

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

6 weeks agoFix PNaCl-local files after merging LLVM 3.4 mseaborn/merge-34-squashed
Mark Seaborn [Sat, 1 Mar 2014 18:34:38 +0000 (10:34 -0800)]
Fix PNaCl-local files after merging LLVM 3.4

These are mostly compile fixes:

 * Update for interface changes:
    * readBytes() (unused arg was removed)
    * tool_output_file takes different flags
    * Materialize() uses error_code instead of bool + string
 * Remove uses of case ranges, which were removed in 3.4
 * pnacl-llc: Some TargetOptions fields were removed in 3.4

Also update test expectations.  LLVM's 'not' tool now treats crashes
as a failure unless '--crash' is passed.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=PNaCl toolchain trybots

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

6 weeks agoMerge LLVM 3.4 into PNaCl's branch
Mark Seaborn [Sat, 1 Mar 2014 18:34:38 +0000 (10:34 -0800)]
Merge LLVM 3.4 into PNaCl's branch

This fixes up numerous merge conflicts.  Note that this does not
update files that are specific to the PNaCl branch -- compile fixes
for these files will be done in a separate commit.

Note that since the PNaCl branch contained a lot of changes
cherry-picked from between 3.3 and 3.4, these changes go away --
generally these are the ones without 'LOCALMOD' markers.  This
includes:

 * Various ARM changes, including tests in test/CodeGen/ARM
 * Various MIPS changes

There were large merge conflicts in:

 * lib/Support/Unix: This was refactored upstream.
    * Removed the Mac debugging localmod for getcwd() in
      lib/Support/Unix/Path.inc.

 * SelectionDAG code: DebugLoc was changed to SDLoc in many places.

 * ARMFrameLowering.cpp, ARMMCTargetDesc.cpp: I've reworked the
   localmods for implementing DWARF CFI generation.  They now use
   addFrameInst().

 * lib/Target/ARM/ARMInstrInfo.td, test/CodeGen/ARM/prefetch.ll:
   Dropped these localmods because of merge conflicts.  This doesn't
   affect ABI-stable pexes since the PNaCl ABI doesn't support the
   llvm.prefetch intrinsic.

 * lib/Target/Mips/MipsInstrFPU.td: This was refactored upstream.

 * lib/Target/X86/X86FastISel.cpp: Big conflict with refactoring that
   adds handleConstantAddresses().

 * lib/Transforms/IPO/GlobalOpt.cpp: The localmod was patching an
   optimisation that was removed in r191834, so it goes away.

 * Localmods applying to tools/lto were moved to lib/LTO.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=Only testable with following fixup change

Review URL: https://groups.google.com/forum/#!topic/native-client-reviews/TBEjmKlq5uc

6 weeks agoMerge r202570: Fix RWMutex to be thread-safe when pthread_rwlock is not available
Mark Seaborn [Sat, 1 Mar 2014 04:30:32 +0000 (04:30 +0000)]
Merge r202570: Fix RWMutex to be thread-safe when pthread_rwlock is not available

lib/Support/RWMutex.cpp contains an implementation of RWMutex that
uses pthread_rwlock, but when pthread_rwlock is not available (such as
under NaCl, when using newlib), it silently falls back to using the
no-op definition in lib/Support/Unix/RWMutex.inc, which is not
thread-safe.

Fix this case to be thread-safe by using a normal mutex.

Differential Revision: http://llvm-reviews.chandlerc.com/D2892

6 weeks agoPrep for merging 3.4: Undo changes from 3.3 branch
Mark Seaborn [Tue, 18 Feb 2014 19:18:44 +0000 (11:18 -0800)]
Prep for merging 3.4: Undo changes from 3.3 branch

In order to cleanly merge LLVM 3.4, we must first undo the various
changes we've merged from LLVM's 3.3 branch, for two reasons:

 * To avoid merge conflicts where the same (or slightly different)
   changes appear in both LLVM's 3.3 branch and LLVM trunk.

 * To remove changes that were applied in the 3.3 branch and not on
   trunk, such as updating config scripts to refer to "3.3".

I made this change by doing:

git diff $(git merge-base upstream/master upstream/release_33)..$(git merge-base upstream/release_33 origin/master) > tmp_patch
git apply --index --reverse tmp_patch

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=none

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

8 weeks agoPrep for merging 3.4: Strip unrecognised attributes instead of complaining
Mark Seaborn [Tue, 18 Feb 2014 20:53:06 +0000 (12:53 -0800)]
Prep for merging 3.4: Strip unrecognised attributes instead of complaining

This is in preparation for the LLVM 3.4 merge.  I found I had to add
"Cold" and "Builtin" to the list of attributes to strip.

When I originally wrote StripAttributes, it seemed like a good idea to
force OK-to-remove attributes to be listed, but now it seems like a
nuisance, because the vast majority of attributes are just hints.
It's a nuisance to have to update StripAttributes' list after a merge.

If any new attributes appear that break programs when naively removed,
it should be OK to rely on testing to discover that.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested earlier version with 3.4 merged
R=jvoung@chromium.org

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

8 weeks agoPrep for merging 3.4: Define isOSLinux() for sandboxed translator's localmod
Mark Seaborn [Tue, 18 Feb 2014 19:11:04 +0000 (11:11 -0800)]
Prep for merging 3.4: Define isOSLinux() for sandboxed translator's localmod

This function is defined in the #else branch, post-merge.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested earlier version with 3.4 merged
R=jvoung@chromium.org

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

8 weeks agoPrep for merging 3.4: Reset LangRef to the version from the 3.3 branch
Mark Seaborn [Tue, 18 Feb 2014 19:06:14 +0000 (11:06 -0800)]
Prep for merging 3.4: Reset LangRef to the version from the 3.3 branch

Before this change, LangRef contains some localmods which are
differences from both LLVM 3.3 and LLVM trunk (introduced by Eli's
merge commit, c6cf05cb5108f356dde97c01ee4188b0671d4542, where Eli
resolved some merge conflicts).

Reverting those localmods will make it easier to cleanly undo all the
changes we've merged from LLVM's 3.3 branch, which in turn makes it
easier to cleanly merge LLVM 3.4.

I made this change by doing:

$ git merge-base origin/master upstream/release_33
7dfcb84fc16b3bf6b2379713b53090757f0a45f9
$ git checkout 7dfcb84fc16b3bf6b2379713b53090757f0a45f9 docs/LangRef.rst

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

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

2 months agoMerge r201497: Use 16 byte stack alignment for NaCl on ARM
Mark Seaborn [Sun, 16 Feb 2014 18:59:48 +0000 (18:59 +0000)]
Merge r201497: Use 16 byte stack alignment for NaCl on ARM

NaCl's ARM ABI uses 16 byte stack alignment, so set that in
ARMSubtarget.cpp.

Using 16 byte alignment exposes an issue in code generation in which a
varargs function leaves a 4 byte gap between the values of r1-r3 saved
to the stack and the following arguments that were passed on the
stack.  (Previously, this code only needed to support 4 byte and 8
byte alignment.)

With this issue, llc generated:

varargs_func:
        sub     sp, sp, #16
        push    {lr}
        sub     sp, sp, #12
        add     r0, sp, #16   // Should be 20
        stm     r0, {r1, r2, r3}
        ldr     r0, .LCPI0_0  // Address of va_list
        add     r1, sp, #16
        str     r1, [r0]
        bl      external_func

Fix the bug by checking for "Align > 4".  Also simplify the code by
using OffsetToAlignment(), and update comments.

Differential Revision: http://llvm-reviews.chandlerc.com/D2677

2 months agoPrep for merging 3.4: Relax test expectations for memcpy/memmove attributes
Mark Seaborn [Sat, 15 Feb 2014 03:02:08 +0000 (19:02 -0800)]
Prep for merging 3.4: Relax test expectations for memcpy/memmove attributes

In LLVM 3.4, these intrinsics gain "readonly" attributes.  Change the
test to work before and after the merge.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested earlier version with 3.4 merged
R=jvoung@chromium.org

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

2 months agoPNaCl: Update negative-addend.ll tests to pass after the LLVM 3.4 merge
Mark Seaborn [Sat, 15 Feb 2014 01:11:11 +0000 (17:11 -0800)]
PNaCl: Update negative-addend.ll tests to pass after the LLVM 3.4 merge

With the upstream change r182908, llvm-objdump changed so that it will print:
  RELOCATION RECORDS FOR [.rel.data]:
instead of:
  RELOCATION RECORDS FOR [.data]:

Relax the test expectations so that either passes.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested with 3.4 merged
R=jvoung@chromium.org

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

2 months agoMerge r200090: Fix "llvm-objdump -d -r" to show relocations inline for ELF files
Mark Seaborn [Sat, 25 Jan 2014 17:38:19 +0000 (17:38 +0000)]
Merge r200090: Fix "llvm-objdump -d -r" to show relocations inline for ELF files

This fixes a regression introduced by r182908, which broke
llvm-objdump's ability to display relocations inline in a disassembly
dump for ELF object files.

That change removed a SectionRelocMap from Object/ELF.h, which we
recreate in llvm-objdump.cpp.

I discovered this regression via an out-of-tree test
(test/NaCl/X86/pnacl-hides-sandbox-x86-64.ll) which used llvm-objdump.

Note that the "Unknown" string in the test output on i386 isn't quite
right, but this appears to be a pre-existing bug.

Differential Revision: http://llvm-reviews.chandlerc.com/D2559

2 months agoMerge r200053: llvm-objdump: Some style cleanups to follow LLVM coding style
Mark Seaborn [Sat, 25 Jan 2014 00:32:01 +0000 (00:32 +0000)]
Merge r200053: llvm-objdump: Some style cleanups to follow LLVM coding style

Rename "ec" to "EC", and rename some iterators.

Then fix whitespace using clang-format-diff.

(As requested in http://llvm-reviews.chandlerc.com/D2559)

Differential Revision: http://llvm-reviews.chandlerc.com/D2594

2 months agoMerge r200259: Fix the "#ifndef HAVE_SYS_WAIT_H" code path in Program.inc to compile
Mark Seaborn [Mon, 27 Jan 2014 22:53:07 +0000 (22:53 +0000)]
Merge r200259: Fix the "#ifndef HAVE_SYS_WAIT_H" code path in Program.inc to compile

Without this fix, WaitResult is not defined.

2 months agoPNaCl LLVM LLVMNaClBitWriter CMake file: fix typo
JF Bastien [Thu, 13 Feb 2014 19:18:55 +0000 (11:18 -0800)]
PNaCl LLVM LLVMNaClBitWriter CMake file: fix typo

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

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

2 months agoAdd threading support for sandboxed SRPC translation
Derek Schuff [Wed, 12 Feb 2014 19:17:29 +0000 (11:17 -0800)]
Add threading support for sandboxed SRPC translation

Add a new RPC, StreamInitWithSplit, to initiate the module-splitting
code path, and pass as many descriptors as necessary. To keep the
translator code simple, all the descriptors are passed in one RPC.

Introduce ThreadedStreamingCache to manage the threads' access to the
streaming bitcode object.

Instead of passing a DataStreamer to the bitcode reader and having the
bitcode reader allocate the StreamingMemoryObject, just pass a
StreamableMemoryObject to it directly. This keeps its logic unchanged
and allows the caller to set up the shared streaming

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

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

2 months agoMake pnacl-bccompress add abbreviations for obvious constants.
Karl Schimpf [Mon, 10 Feb 2014 16:46:43 +0000 (08:46 -0800)]
Make pnacl-bccompress add abbreviations for obvious constants.

Updates pnacl-bccompress to add abbreviations by inserting
constants into existing abbreviations, when the generated
distribution maps show that a particular record element, the
same value is used in a large number of records.

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

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

2 months agoAllow disabling of libxml in the cmake build
Derek Schuff [Fri, 7 Feb 2014 19:31:04 +0000 (11:31 -0800)]
Allow disabling of libxml in the cmake build

Ubuntu doesn't have a 32-bit build of libxml, so building 32-bit llvm
with cmake fails. (It actually finds the 64-bit version and tries to
use it, rather than failing to find it).
This CL allows disabling the check for it.

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

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

2 months agoRemove StreamInitWithCommandLine RPC handler
Derek Schuff [Fri, 7 Feb 2014 00:29:36 +0000 (16:29 -0800)]
Remove StreamInitWithCommandLine RPC handler

It is no longer used, having been replaced by StreamInitWithOverrides
R=jfb@chromium.org, jvoung@chromium.org
BUG=cleanup

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

2 months agoCreate a new context for main thread instead of using the global context
Derek Schuff [Thu, 6 Feb 2014 23:41:44 +0000 (15:41 -0800)]
Create a new context for main thread instead of using the global context

This is to work around a bug in lib/CodeGen/PseudoSourceValue.cpp which
gets a type from the global context rather than using the context of its
module. It uses a lock to synchronize its own use of the context, but
races with any other code's use.
Rather than plumb the type or context that it needs through all the
necessary layers, we use a new context instead of the global context
for the main module, leaving PseudoSourceValue as the only user of
the global context. This is sufficient for PseudoSourceValue's limited
use of the context, and does not require invasive changes.

We should consider fixing this upstream.

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

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

2 months agoRemove static variables from MC expansion code
Derek Schuff [Thu, 6 Feb 2014 20:50:34 +0000 (12:50 -0800)]
Remove static variables from MC expansion code

Replace thread-unfriendly static variables with state contained in the MCAsmBackends

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

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

2 months agoFix pathnames to run LLVM regressions with msys make
Derek Schuff [Wed, 5 Feb 2014 00:15:22 +0000 (16:15 -0800)]
Fix pathnames to run LLVM regressions with msys make

Msys ulimit exits with an error when used to modify limits, so don't use
it.
Also fix up msys pathnames (used by msys make) for Win32 python (used
for lit)

R=stichnot@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3719
TEST= just local testing until I land the switchiver

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

2 months agoparallelize pnacl-llc's module splitting with pthreads.
Derek Schuff [Tue, 4 Feb 2014 21:50:35 +0000 (13:50 -0800)]
parallelize pnacl-llc's module splitting with pthreads.

This also moves several of the initialization steps onto each thread rather than doing them in the main thread.
This works on all of our platforms because our minGW comes
with a windows pthread wrapper library.

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

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

2 months agoNormalize abbreviation ids in pnacl-bccompress.
Karl Schimpf [Mon, 3 Feb 2014 23:01:20 +0000 (15:01 -0800)]
Normalize abbreviation ids in pnacl-bccompress.

Pnacl-bccompress reads a pnacl bitcode file and builds distribution
maps from the records in the file. This includes mapping abbreviations
indices in the records. However, this tool converts all abbreviations
to global, including local abbreviations, which are not unique. This
code fixes the distribution maps so they all refer to the (new)
globalized abbreviations.

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

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

2 months agoMake local symbol tables only allowed using command-line arguments.
Karl Schimpf [Mon, 3 Feb 2014 21:06:00 +0000 (13:06 -0800)]
Make local symbol tables only allowed using command-line arguments.

Adds command-line argument to allow local (function) value symbol
tables. Fixes writing of value symbol tables to PNaCl bitcode to
remove symbols with elided code. Fixes tests to use local value
symbol tables when needed to make the assembly easier to maintain.

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

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

2 months agopnacl-llc: Allow splitting a PNaCl file into multiple LLVM Modules
Derek Schuff [Wed, 29 Jan 2014 17:58:26 +0000 (09:58 -0800)]
pnacl-llc: Allow splitting a PNaCl file into multiple LLVM Modules

Add a flag that causes the input bitcode module to be cloned into N
output modules. Each output module has all function and data declarations.
Only the first one has data initializers, and for now each output module
compiles 1/N of the functions in statically-striped order.
This is implemented by re-parsing the bitcode blocks containing the
declarations, and then having each output module only materialize the
functions it will compile.

Also factor pnacl-llc a bit into a structure that more closely resembles
what we will need for multithreading. It shows which data structures
are common but does not attempt to share or duplicate them yet.

R=jvoung@chromium.org
BUG= (TBA)

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

2 months agoRemove out-of-date PNaCl localmod in ARMFrameLowering.h
Mark Seaborn [Mon, 27 Jan 2014 23:42:55 +0000 (15:42 -0800)]
Remove out-of-date PNaCl localmod in ARMFrameLowering.h

The 5th argument to TargetFrameLowering is a bool, StackReal:

  TargetFrameLowering(StackDirection D, unsigned StackAl, int LAO,
                      unsigned TransAl = 1, bool StackReal = true)

Passing 4 here doesn't make sense but shouldn't make a difference.

This localmod is left over from earlier changes (see
5dbcc7e0c9c12f4a4042fb4a226654aee927999c) that were later removed in
aa0fa8a8df25807f784ec9ca9deeb40328636595.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=PNaCl toolchain trybots
R=jvoung@chromium.org

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

2 months agoReduce the search space for finding abbreviations in pnacl-bccompress.
Karl Schimpf [Mon, 27 Jan 2014 22:45:00 +0000 (14:45 -0800)]
Reduce the search space for finding abbreviations in pnacl-bccompress.

Reduces the search space by:

(1) Limit size and value index distributions, based on predefined
constant.

(2) Track bitcode record values using ranges, rather than individual
values.

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

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

2 months agoPNaCl: Fix ReplacePtrsWithInts' handling of llvm.invariant.end
Mark Seaborn [Mon, 27 Jan 2014 21:01:39 +0000 (13:01 -0800)]
PNaCl: Fix ReplacePtrsWithInts' handling of llvm.invariant.end

Before this change, replace-ptrs-with-ints.ll makes 'opt' abort with:

  Attribute after last parameter!
  void (i64, i8*)* @llvm.invariant.end
  Broken module found, compilation aborted!

In LLVM 3.3, llvm-lit doesn't check opt's exit status, and this abort
happens after printing the transformed IR, so this goes unnoticed.  In
LLVM 3.4, llvm-lit is stricter.

This abort happens because the test declares llvm.invariant.end
wrongly.  It actually has 3 args, not 2.  Fixing this means we also
have to fix the pass's handling of llvm.invariant.end.
llvm.invariant.end refers to the result of llvm.invariant.start, so we
have to remove calls to these in the right order.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested with LLVM 3.4 merged
R=dschuff@chromium.org

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

2 months agoPNaCl: Change memory intrinsics test to pass under LLVM 3.4
Mark Seaborn [Tue, 21 Jan 2014 21:47:52 +0000 (13:47 -0800)]
PNaCl: Change memory intrinsics test to pass under LLVM 3.4

In 3.4, memcpy/memmove gained a "readonly" argument attribute.

So the declarations in these tests no longer match, but there's no
need to check for the declarations anyway.  The test checks for calls
to the intrinsics, and these imply that the declarations are present.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested with LLVM 3.4 merged
R=jvoung@chromium.org

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

2 months agoPNaCl: Fix ambiguity in reference to PassManager
Mark Seaborn [Tue, 21 Jan 2014 18:38:45 +0000 (10:38 -0800)]
PNaCl: Fix ambiguity in reference to PassManager

In LLVM 3.4, PassManager is defined by "using legacy::PassManager", so
forward-declaring it no longer works.  When compiling with Clang 3.4
(for the sandboxed translator), it gave this error:

include/llvm/Transforms/NaCl.h:54:38: error: reference to 'PassManager' is ambiguous
void PNaClABISimplifyAddPreOptPasses(PassManager &PM);
include/llvm/Transforms/NaCl.h:21:7: note: candidate found by name lookup is 'llvm::PassManager'
class PassManager;
include/llvm/PassManager.h:34:15: note: candidate found by name lookup is 'llvm::PassManager'
using legacy::PassManager;

(However, gcc 4.6.3 didn't complain.)

Fix this by using PassManagerBase in the same way that addPass() in
opt.cpp does.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested with LLVM 3.4 merged
R=jvoung@chromium.org

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

2 months agoPNaCl: Add "not" to various test commands, to pass under LLVM 3.4
Mark Seaborn [Tue, 21 Jan 2014 18:36:55 +0000 (10:36 -0800)]
PNaCl: Add "not" to various test commands, to pass under LLVM 3.4

In LLVM 3.4, llvm-lit got stricter, so that the command "X | Y" is
treated as failing if X returns a non-zero exit status.  (llvm-lit
sets "pipefail" in Bash.)  The way to fix this is to write "not X | Y"
instead.

Mostly fixed with:

perl -pi -e 's/RUN: pnacl-abicheck/RUN: not pnacl-abicheck/' $(git ls-files test/NaCl/PNaClABI/)

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested with LLVM 3.4 merged
R=dschuff@chromium.org

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

2 months agoPNaCl: Fix mistake in flatten-globals.ll test
Mark Seaborn [Tue, 21 Jan 2014 18:23:40 +0000 (10:23 -0800)]
PNaCl: Fix mistake in flatten-globals.ll test

The mistake meant that this CHECK line wasn't being checked.

In LLVM 3.4, lit got stricter so that it caught this mistake, with the
error:

  error: no check strings found with prefix 'CLEANED:'

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=tested with LLVM 3.4 merged
R=jvoung@chromium.org

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

2 months agoPNaCl: Remove declarations for intrinsics that I missed in the previous change
Mark Seaborn [Sun, 19 Jan 2014 16:02:32 +0000 (08:02 -0800)]
PNaCl: Remove declarations for intrinsics that I missed in the previous change

I removed these methods' definitions in the previous change.

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

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

3 months agoAdd (nested) distribution maps to pnacl-bccompress.
Karl Schimpf [Fri, 17 Jan 2014 22:01:21 +0000 (14:01 -0800)]
Add (nested) distribution maps to pnacl-bccompress.

Adds distribution maps to pnacl-bccompress that will be used to find
abbreviation refinements of the current set of abbreviations.

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

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

3 months agoRefactor pnacl-bcanalyzer and pnacl-benchmark to use same distribution.
Karl Schimpf [Tue, 14 Jan 2014 17:07:07 +0000 (09:07 -0800)]
Refactor pnacl-bcanalyzer and pnacl-benchmark to use same distribution.

The previous CL removed building block/record distributions from
NaClBitcodeAnalyzer.cpp. This accidentally removed building block
and record distributions from pnacl-benchmark. This refactors the
code to put the distributions back into pnacl-benchmark.

It also removes record dumping from pnacl-benchmark, since the
dumping code does not reflect parse time.

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

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

3 months agoPNaCl: Remove the TLS layout and llvm.nacl.target.arch intrinsics
Mark Seaborn [Tue, 14 Jan 2014 03:44:40 +0000 (19:44 -0800)]
PNaCl: Remove the TLS layout and llvm.nacl.target.arch intrinsics

I have removed the uses of these intrinsics in other changes.

This removes some localmods that would otherwise have required
updating for SelectionDAG changes when merging LLVM 3.4.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3760
TEST=PNaCl toolchain trybots
R=jvoung@chromium.org

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

3 months agoPNaCl: Fix ReplacePtrsWithInts to preserve the "tail" attribute on calls
Mark Seaborn [Mon, 13 Jan 2014 22:17:01 +0000 (14:17 -0800)]
PNaCl: Fix ReplacePtrsWithInts to preserve the "tail" attribute on calls

"tail" is allowed in PNaCl bitcode, but so far we have been omitting
it because ReplacePtrsWithInts accidentally stripped it from all
calls.

BUG=none
TEST=*.ll tests
R=dschuff@chromium.org

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

3 months agoRefactor pnacl bitcode analysis to update distribution map.
Karl Schimpf [Mon, 13 Jan 2014 21:52:23 +0000 (13:52 -0800)]
Refactor pnacl bitcode analysis to update distribution map.

Modify the bitcode analyzer to update a passed distribution map,
allowing the caller to define the map and how it is updated.

Also modifies pnacl-bcanalyzer to define it distribution map
as a map of bitcode blocks, with nested subblock and record
code distributions.

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

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

3 months agoPNaCl: Fix handling of va_arg on structs in simplification passes
Mark Seaborn [Mon, 13 Jan 2014 17:30:07 +0000 (09:30 -0800)]
PNaCl: Fix handling of va_arg on structs in simplification passes

Without this ordering change, ExpandStructRegs will fail with:

Value:   %val = va_arg i8* %va_list, %MyStruct
LLVM ERROR: Unrecognized struct value

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

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

3 months agoPNaCl: Fix a use-after-free in the ExpandIndirectBr pass
Mark Seaborn [Sat, 11 Jan 2014 00:24:13 +0000 (16:24 -0800)]
PNaCl: Fix a use-after-free in the ExpandIndirectBr pass

Destroying uses of a function while iterating over the uses leads to a
use-after-free(), which Valgrind detects.  Fix this by making a
temporary copy of the use list.

This bug is probably what was causing the expand-indirectbr.ll test to
crash on Windows (on Cygwin) on the PNaCl toolchain bots.
Specifically, the @unused_blockaddress subtest was crashing on Cygwin.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3695
TEST=expand-indirectbr.ll under Valgrind
R=dschuff@chromium.org

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

3 months agoSeparate out bits distribution maps from bits and abbreviations.
Karl Schimpf [Fri, 10 Jan 2014 17:39:11 +0000 (09:39 -0800)]
Separate out bits distribution maps from bits and abbreviations.

Separate out bits distribution maps from bits and abbreviations
distribution maps, so that we can use the bits distribution map
to model blocks (which do not have a notion of abbreviations).

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

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

3 months agoRename files containing PNaCl bitcode distribution maps.
Karl Schimpf [Thu, 9 Jan 2014 17:03:21 +0000 (09:03 -0800)]
Rename files containing PNaCl bitcode distribution maps.

Class names in various PNaCl bitcode distribution maps got renamed
in previous CL's. Fix the filenames to better reflect the distribution
maps they define.

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

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

3 months agoTrace abbreviations use to compressed file in pnacl-bccompress.
Karl Schimpf [Thu, 9 Jan 2014 16:58:25 +0000 (08:58 -0800)]
Trace abbreviations use to compressed file in pnacl-bccompress.

Adds commmand-line flag to trace abbreviations used in generated
compressed file when running pnacl-bccompress. Fixes warning about
unused PrintAbbrev() function.

BUG=None
TEST=compile
R=jvoung@chromium.org

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

3 months agoFix compiler warning about non-virtual destructor.
Karl Schimpf [Tue, 7 Jan 2014 21:44:16 +0000 (13:44 -0800)]
Fix compiler warning about non-virtual destructor.

CL 123983002 was checked in with the compiler warning that
class NaClBitcodeDist has virtual fucntions and accessible
non-virtual destructor. This CL fixes that issue.

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

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

3 months agoPNaCl: Allow ExpandTls pass to define __nacl_tp_{tdb,tls}_offset() functions
Mark Seaborn [Tue, 7 Jan 2014 17:25:33 +0000 (17:25 +0000)]
PNaCl: Allow ExpandTls pass to define __nacl_tp_{tdb,tls}_offset() functions

Currently these functions are declared in tls_params.h as:

ptrdiff_t __nacl_tp_tls_offset(size_t tls_size) asm("llvm.nacl.tp.tls.offset");
ptrdiff_t __nacl_tp_tdb_offset(size_t tdb_size) asm("llvm.nacl.tp.tdb.offset");

This change will allow ExpandTls to work if the asm() part is removed
so that these are no longer treated as intrinsics.

Add some checks because non-intrinsic functions might be local or
already defined.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3760
TEST=tested with NaCl-side change

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

3 months agoPNaCl: Implement computed gotos (indirectbr) by expanding out to switches
Mark Seaborn [Tue, 7 Jan 2014 10:35:54 +0000 (10:35 +0000)]
PNaCl: Implement computed gotos (indirectbr) by expanding out to switches

Add the ExpandIndirectBr pass for expanding out indirectbr and
blockaddress into switch instructions, so that programs using computed
gotos can work with PNaCl's stable ABI.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3695
TEST=*.ll tests + GCC torture tests

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

3 months agoClean up hanlding of nested bitcode record distributions.
Karl Schimpf [Mon, 6 Jan 2014 22:57:01 +0000 (14:57 -0800)]
Clean up hanlding of nested bitcode record distributions.

Also cleans up printing of distributions, and separates out adding
blocks and records to a distribution map.

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

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

3 months agoPNaCl: Simplify PromoteIntegers pass to not convert pointer types
Mark Seaborn [Mon, 6 Jan 2014 22:29:34 +0000 (22:29 +0000)]
PNaCl: Simplify PromoteIntegers pass to not convert pointer types

This fixes handling of GEPs on types like [2 x i40]*, which was used
in an Emscripten test case.

This change simplifies the pass and makes it a bit more robust.

BUG=none
TEST=*.ll test

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

3 months agoPNaCl: Remove some more uses of switch case ranges
Mark Seaborn [Mon, 6 Jan 2014 17:16:37 +0000 (17:16 +0000)]
PNaCl: Remove some more uses of switch case ranges

This is to prepare for merging LLVM 3.4.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3758
TEST=trybots

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

3 months agoPNaCl bitcode: Remove unused code for reading wide integers in switch cases
Mark Seaborn [Mon, 6 Jan 2014 17:06:03 +0000 (17:06 +0000)]
PNaCl bitcode: Remove unused code for reading wide integers in switch cases

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3758
TEST=trybots

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

3 months agoPNaCl bitcode: Remove support for reading/writing case ranges in switches
Mark Seaborn [Sat, 4 Jan 2014 17:55:48 +0000 (17:55 +0000)]
PNaCl bitcode: Remove support for reading/writing case ranges in switches

This is in preparation for merging LLVM 3.4, because support for case
ranges was removed upstream in r190328
(http://llvm.org/viewvc/llvm-project?view=revision&revision=190328).

Nothing ever generated case ranges, so removing support won't break
anything.  This change restricts the bitcode format so that the
NumItems and IsSingleNumber fields are both always 1.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3758
TEST=trybots

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

3 months agoRemove the use of templates for bitcode record distributions.
Karl Schimpf [Fri, 3 Jan 2014 15:50:45 +0000 (07:50 -0800)]
Remove the use of templates for bitcode record distributions.

Since templates do not represent inheritance well, remove the use of
templates to define bitcode record distributions. Rather, use LLVM's
(dynamic) casting operators to handle the casting that was formerly
handled by template arguments.

Also moves many bodies of methods in header files, to the
corresponding implementation files.

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

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

3 months agoPNaCl: Remove references to LinkOnceODRAutoHideLinkage, removed upstream
Mark Seaborn [Fri, 3 Jan 2014 09:35:35 +0000 (09:35 +0000)]
PNaCl: Remove references to LinkOnceODRAutoHideLinkage, removed upstream

This is in preparation for merging LLVM 3.4.  The linkage type
LinkOnceODRAutoHideLinkage was removed upstream in r193865:
http://llvm.org/viewvc/llvm-project?view=revision&revision=193865

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=build

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

3 months agoPrepare for merging LLVM 3.4: add missing #include
Mark Seaborn [Thu, 2 Jan 2014 21:35:36 +0000 (21:35 +0000)]
Prepare for merging LLVM 3.4: add missing #include

The newer headers are stricter, so llvm/IR/Constants.h is required to
get ConstantInt and ConstantExpr.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=none

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

3 months agoAdd block bit tracking to NaClBitcodeParser.
Karl Schimpf [Thu, 2 Jan 2014 21:05:25 +0000 (13:05 -0800)]
Add block bit tracking to NaClBitcodeParser.

Simplify NaClBitcodeParser so that tracking of bits in blocks are
stored in class NaClBitcodeRecord, and are (automatically) updated by
class NaClBitcodeParser.

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

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

3 months agoRemove PNaCl localmod: Decl of createNaClCcRewritePass(), which isn't defined
Mark Seaborn [Thu, 2 Jan 2014 20:51:07 +0000 (20:51 +0000)]
Remove PNaCl localmod: Decl of createNaClCcRewritePass(), which isn't defined

This function is not defined anywhere.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=none

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

3 months agoRemove unused PNaCl localmods in IR/Module
Mark Seaborn [Thu, 2 Jan 2014 19:50:44 +0000 (19:50 +0000)]
Remove unused PNaCl localmods in IR/Module

These were part of PNaCl's old glibc/ELF-based dynamic linking
support, which we are removing.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3520
TEST=trybots

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

3 months agoRemove PNaCl localmod for using OSABI_NACL in ELF files
Mark Seaborn [Tue, 31 Dec 2013 09:34:34 +0000 (09:34 +0000)]
Remove PNaCl localmod for using OSABI_NACL in ELF files

sel_ldr doesn't require OSABI_NACL, and the binutils version currently
being used by all the NaCl toolchains doesn't use OSABI_NACL either,
so we can remove this localmod.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=trybots

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

3 months agoRemove various uses of PNaCl's old IR/Module localmods
Mark Seaborn [Tue, 31 Dec 2013 00:15:15 +0000 (00:15 +0000)]
Remove various uses of PNaCl's old IR/Module localmods

These were part of PNaCl's old glibc/ELF-based dynamic linking
support, which we are removing.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3520
TEST=trybots

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

3 months agoRemove some unused PNaCl localmods related to ELF symbol versioning
Mark Seaborn [Tue, 31 Dec 2013 00:12:23 +0000 (00:12 +0000)]
Remove some unused PNaCl localmods related to ELF symbol versioning

These were part of PNaCl's old glibc/ELF-based dynamic linking
support, which we are removing.

Normally, symbols with an "@" version will never appear in LLVM IR,
because symbol versions are added by linker when linking an ELF DSO or
executable.  So this localmod is not useful in upstream LLVM.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3520
TEST=trybots

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

3 months agoRemove old PNaCl localmods for instruction bundling
Mark Seaborn [Tue, 31 Dec 2013 00:10:57 +0000 (00:10 +0000)]
Remove old PNaCl localmods for instruction bundling

This code isn't used any more.  It was superseded by the bundle
handling code that was upstreamed.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=trybots

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

3 months agoRemove unused PNaCl localmods in JITCodeEmitter.h
Mark Seaborn [Mon, 30 Dec 2013 21:03:50 +0000 (21:03 +0000)]
Remove unused PNaCl localmods in JITCodeEmitter.h

getCurrentPCOffset() is not overridden anywhere in PNaCl's LLVM
changes, so it doesn't need to be made virtual.  The other methods are
not referenced anywhere.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=trybots

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

3 months agoRemove PNaCl's unused localmods in GlobalValue.h and Globals.cpp
Mark Seaborn [Mon, 30 Dec 2013 21:03:07 +0000 (21:03 +0000)]
Remove PNaCl's unused localmods in GlobalValue.h and Globals.cpp

This was part of PNaCl's old glibc/ELF-based dynamic linking support,
which we are removing.

This will allow us to remove localmods in IR/Module.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3520
TEST=trybots

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

3 months agoRemove PNaCl's unused "IsPlainObject" localmod in AsmPrinter
Mark Seaborn [Mon, 30 Dec 2013 21:01:56 +0000 (21:01 +0000)]
Remove PNaCl's unused "IsPlainObject" localmod in AsmPrinter

This was part of PNaCl's old glibc/ELF-based dynamic linking support,
which we are removing.

This will allow us to remove the getOutputFormat() localmod in
IR/Module.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3520
TEST=trybots

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

3 months agoRemove various PNaCl localmods in lib/Support/Unix
Mark Seaborn [Mon, 30 Dec 2013 21:00:24 +0000 (21:00 +0000)]
Remove various PNaCl localmods in lib/Support/Unix

These are no longer necessary because nacl-newlib now provides various
functions, such as access(), by default (since libnosys was merged
into libnacl).

I prepared this change by reverting the lib/Support/Unix localmods and
reapplying the ones that were required to make these files compile and
link with pnacl-clang, plus a Mac debugging change.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=trybots

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

3 months agoRemove PNaCl localmod: Remove unused header file, support_macros.h
Mark Seaborn [Fri, 27 Dec 2013 23:11:35 +0000 (23:11 +0000)]
Remove PNaCl localmod: Remove unused header file, support_macros.h

This file was added in "Diff from hg rev 0b098ca44de7"
(4f429c8b4e06d750b5464b6eafdd102af5196bdd), but the users of it
(include/llvm/Wrap/bitcode_wrapperer.h etc.) have since been removed.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3757
TEST=trybots

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

3 months agoRemove PNaCl localmod: Remove unused tools/pso-stub/
Mark Seaborn [Fri, 27 Dec 2013 23:10:27 +0000 (23:10 +0000)]
Remove PNaCl localmod: Remove unused tools/pso-stub/

This was part of PNaCl's old glibc/ELF-based dynamic linking support,
which we have been gradually removing.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3520
TEST=trybots

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

3 months agoFix signature of Error methods in NaClBitcodeAnalyzer.cpp.
Karl Schimpf [Fri, 27 Dec 2013 23:07:41 +0000 (15:07 -0800)]
Fix signature of Error methods in NaClBitcodeAnalyzer.cpp.

This fixes an compiler inheritance warning that these
methods are hiding the inherited virtual function.

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

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

3 months agoCreate test to verify that record distributions remain the same.
Karl Schimpf [Wed, 18 Dec 2013 21:20:56 +0000 (13:20 -0800)]
Create test to verify that record distributions remain the same.

Adds simple pnacl-bcanalyzer test that shows the record distributions
for each type of block. This test is intended to check that these
record distributions do not change, when code is modified.

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

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

3 months agoAdd ability to print out abbreviations in PNaCl bitcode files.
Karl Schimpf [Wed, 18 Dec 2013 21:10:12 +0000 (13:10 -0800)]
Add ability to print out abbreviations in PNaCl bitcode files.

Adds ability to print out abbreviations in pnacl-bcanalyzer, so
that we can interogate abbreviations to be added by pnacl-bccompress.

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

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

4 months agoAdds notion of value distributions for PNaCl bitcode files.
Karl Schimpf [Fri, 13 Dec 2013 19:05:59 +0000 (11:05 -0800)]
Adds notion of value distributions for PNaCl bitcode files.

Adds notion of value distributiones for PNaCl bitcode files, to allow
analysis of how well abbreviations are being applied to records in
PNaCl bitcode files.

Updates pnacl-bcanalyzer to use the value distributions for
record codes, to demonstrate its usage.

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

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

4 months agoCreate initial implementation of pnacl-bccompress.
Karl Schimpf [Thu, 12 Dec 2013 22:02:49 +0000 (14:02 -0800)]
Create initial implementation of pnacl-bccompress.

Create initial implementation of pnacl-bccompress. This version
simply copies abbreviations in the input PNaCl bitcode file to the
corresponding output PNaCl bitcode file as global abbreviations.  Then
chooses best fitting (glboal) abbreviation for each record in the
input PNaCl bitcode file.

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

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

4 months ago[MIPS] Add instruction BAL to direct calls
Petar Jovanovic [Thu, 12 Dec 2013 00:29:06 +0000 (01:29 +0100)]
[MIPS] Add instruction BAL to direct calls

IsDirectCall() function missed to recognize BAL as a direct call.
This caused instruction BAL not to be placed correctly on 3rd position in a
bundle, which was later detected by validator.
Found while building pnacl-llc.nexe.

BUG= pnacl-llc.nexe fails on validation
TEST= build and run pnacl-llc.nexe for MIPS
R=mseaborn@chromium.org

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

4 months agoMake EmitRecord nondestructive in the PNaCl bitcode writer.
Karl Schimpf [Mon, 9 Dec 2013 17:00:54 +0000 (09:00 -0800)]
Make EmitRecord nondestructive in the PNaCl bitcode writer.

Fixes undocumented destructive behavior of EmitRecord in the PNaCl
bitcode writer. This allows the callers to be able to assume that the
passed vector of values is unmodified when writing. This allows
pnacl-bccompress to not have to explicitly copy value records before
emitting.

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

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

4 months agoDon't add fast-mode flags into PNaCl bitcode files.
Karl Schimpf [Fri, 6 Dec 2013 20:49:19 +0000 (12:49 -0800)]
Don't add fast-mode flags into PNaCl bitcode files.

Changes the PNaCl bitcode writer to ignore fast-mode flags (i.e.
flags fast, nnan, ninf, nsz, and arcp) and not write them into
the corresponding PNaCl bitcode file.

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

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