OSDN Git Service

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

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

BUG=None
R=stichnot@chromium.org

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

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

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

BUG=none
R=stichnot@chromium.org

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

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

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

BUG=None
R=jvoung@chromium.org

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

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

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

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

BUG=none
R=stichnot@chromium.org

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

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

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

To reproduce the problem, try this:

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

This will print a line containing BitcodeMunge.cpp.

Now do:

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

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

Finally:

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

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

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

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

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

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

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

This should help the crosstests pass with --elf.

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

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

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

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

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

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

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

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

BUG= none
R=jfb@chromium.org

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

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

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

Haven't tried crosstests yet.

BUG=none
R=stichnot@chromium.org

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

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

This also implicitly applies to szbuild_spec2k.py.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Fix stats collection and output for multithreading.
Jim Stichnoth [Sat, 31 Jan 2015 18:48:11 +0000 (10:48 -0800)]
Subzero: Fix stats collection and output for multithreading.

Updates of current-function and cumulative stats are done entirely in TLS.  At the end, cumulative stats are merged across all threads' TLS into the global cumulative stats.

Printing of cumulative stats after every function is removed, since there's very little value from that.  It was probably done in the first place just to give partial cumulative information in the face of crashes or assertion failures.

BUG= none
R=jfb@chromium.org

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

9 years agoFix subzero Windows build
JF Bastien [Sat, 31 Jan 2015 18:13:25 +0000 (10:13 -0800)]
Fix subzero Windows build

MinGW's GCC 4.8.1 was sad because SectionType was shadowing the other SectionType. Also, the enum's values are in the ELFObjectWriter namespace, not ELFObjectWriter::SectionType.

R=stichnot@chromium.org, jvoung@chromium.org
BUG= Windows build is sad

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

9 years agoSubzero: Fix timers for multithreaded translation.
Jim Stichnoth [Fri, 30 Jan 2015 21:10:39 +0000 (13:10 -0800)]
Subzero: Fix timers for multithreaded translation.

Now that multithreaded parsing and translation is in place, timer operations have to be made thread-local.  After the non-main threads end, their thread-local timer data needs to be merged into the global timer data, which resides in the GlobalContext object.  The merge is a bit tricky because the internal timer stack structure is built up dynamically as items are pushed and popped.  Two threads may have radically different timing data:

1. The parser thread profile is completely different from a translator thread.

2. For -timing-funcs, two translator threads hold data for entirely different sets of functions.

A bit more tweaking will need to be done to make the timing output fully usable in a multithreaded run.  Because of multiple threads, times may add up to >100%.  Also, time spent blocked is being "unfairly" attributed to the caller of the blocking operation - we should either count the user time instead of wall-clock time, or add a special timer marker for blocking locking operations.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Minor Makefile fix.
Jim Stichnoth [Fri, 30 Jan 2015 17:34:05 +0000 (09:34 -0800)]
Subzero: Minor Makefile fix.

The problem showed up after the link step failed, in which case $(OBJDIR)/llvm2ice was deleted but the ./llvm2ice symlink still existed.  A subsequent "make check-lit" or "make check" would fail, so the basic "make" would have to be done first.

BUG= none
R=jvoung@chromium.org

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

9 years agoWrite out global initializers and data rel directly to ELF file.
Jan Voung [Thu, 29 Jan 2015 22:42:38 +0000 (14:42 -0800)]
Write out global initializers and data rel directly to ELF file.

The local symbol relocations are a bit different from
llvm-mc, which are section-relative. E.g., instead "bytes",
it will be ".data + offsetof(bytes, .data)". So the
contents of the text/data/rodata sections can also differ
since the offsets written in place are different.

Still need to fill the symbol table with undefined
symbols (e.g., memset, and szrt lib functions) before
trying to link.

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

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

9 years agoWork around GCC bug in constexpr to attributes
JF Bastien [Wed, 28 Jan 2015 23:07:38 +0000 (15:07 -0800)]
Work around GCC bug in constexpr to attributes

__attribute__((aligned(MaxCacheLineSize))) triggers a GCC bug because enum {MaxCacheLineSize = 64 }; isn't constant enough. Adding zero to it makes it that much more constant.

R= stichnot@chromium.org
BUG= https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55382

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

9 years agoAdd missing period
JF Bastien [Wed, 28 Jan 2015 22:32:28 +0000 (14:32 -0800)]
Add missing period

The period, it was missing

R= stichnot@chromium.org
BUG= none
.

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

9 years agoFix missing header include
JF Bastien [Wed, 28 Jan 2015 22:10:35 +0000 (14:10 -0800)]
Fix missing header include

<mutex> is already included from IceDefs.h (where GlobalLockType is defined) but <condition_variable> isn't included anywhere. It's probably included indirectly in some standard libraries and not others, causing build failures on Windows.

TBR= stichnot@chromium.org
BUG= none

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

9 years agoRemove unnecessary fields in top-level parser of Subzero.
Karl Schimpf [Wed, 28 Jan 2015 18:58:25 +0000 (10:58 -0800)]
Remove unnecessary fields in top-level parser of Subzero.

Cleans up code by removing unnecessary fields/data structures in top-level parser of Subzero. In particular:

1) Uses FunctionDeclarationList.size() instead of NumFunctionIds.

2) Removes the need for vector DefiningFunctionDeclarationList. Instead uses an (incremented) index NextDefiningFunctionID into vector
FunctionDeclarationList.

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

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

9 years agoAdd a missing #include, to fix the Windows build.
Jim Stichnoth [Wed, 28 Jan 2015 16:55:28 +0000 (08:55 -0800)]
Add a missing #include, to fix the Windows build.

BUG= none
R=jfb@chromium.org

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

9 years agoAdd -pedantic to Makefile.standalone to match production.
Jim Stichnoth [Wed, 28 Jan 2015 16:37:22 +0000 (08:37 -0800)]
Add -pedantic to Makefile.standalone to match production.

This also requires modifying the ICE_CACHELINE_BOUNDARY macro to avoid a warning about anonymous structs:

src/IceUtils.h:132:3: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

BUG= none
R=jfb@chromium.org

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

9 years agoFix pedantic build warnings;
JF Bastien [Tue, 27 Jan 2015 20:56:49 +0000 (12:56 -0800)]
Fix pedantic build warnings;

GCC 4.8.1 is sad;

There are extra semicolons in Subzero;

It removes the semicolons or it gets the build warning hose again;^H

R=stichnot@chromium.org
BUG= none

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

9 years agoSubzero: Use a "known" version of clang-format.
Jim Stichnoth [Tue, 27 Jan 2015 20:53:53 +0000 (12:53 -0800)]
Subzero: Use a "known" version of clang-format.

There are two problems with "make format" and "make format-diff" in
Makefile.standalone:

1. You have to make sure clang-format and clang-format-diff.py are
available in $PATH.

2. Different users may have different versions installed (even for the
same user on different machines), leading to whitespace wars.  Can't we
all just get along?

Since the normal LLVM build that Subzero depends on also exposes and
builds clang-format and friends, we might as well use it.  The
clang-format binary is found in $LLVM_BIN_PATH, and clang-format-diff.py
is found relative to $LLVM_SRC_PATH.  As long as the user's LLVM build
is fairly up to date, whitespace wars are unlikely.

Given this, there's a much higher incentive to use "make format"
regularly instead of "make format-diff".  In particular, inline comments
on variable/field declaration lists can get lined up more nicely by
looking at the entire context, rather than the small diff window.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Initial implementation of multithreaded translation.
Jim Stichnoth [Tue, 27 Jan 2015 13:06:03 +0000 (05:06 -0800)]
Subzero: Initial implementation of multithreaded translation.

Provides a single-producer, multiple-consumer translation queue where the number of translation threads is given by the -threads=N argument.  The producer (i.e., bitcode parser) blocks if the queue size is >=N, in order to control the memory footprint.  If N=0 (which is the default), execution is purely single-threaded.  If N=1, there is a single translation thread running in parallel with the parser thread.  "make check" succeeds with the default changed to N=1.

Currently emission is also done by the translation thread, which limits scalability since the emit stream has to be locked.  Also, since the ELF writer stream is not locked, it won't be safe to use N>1 with the ELF writer.  Furthermore, for N>1, emitted function ordering is nondeterministic and needs to be recombobulated.  This will all be fixed in a follow-on CL.

The -timing option is broken for N>0.  This will be fixed in a follow-on CL.

Verbose flags are now managed in the Cfg instead of (or in addition to) the GlobalContext, due to the -verbose-focus option which wants to temporarily change the verbose level for a particular function.

TargetLowering::emitConstants() and related methods are changed to be static, so that a valid TargetLowering object isn't required.  This is because the TargetLowering object wants to hold a valid Cfg, and none really exists after all functions are translated and the constant pool is ready for emission.

The Makefile.standalone now has a TSAN=1 option to enable ThreadSanitizer.

BUG= none
R=jfb@chromium.org

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

9 years agoSubzero: Second attempt at fixing MacOS 10.6 build.
Jim Stichnoth [Mon, 26 Jan 2015 19:10:03 +0000 (11:10 -0800)]
Subzero: Second attempt at fixing MacOS 10.6 build.

Manages thread_local pointer fields through a set of macros.  If ICE_THREAD_LOCAL_HACK is defined, the thread_local definitions and accesses are defined in terms of pthread operations.  This assumes that the underlying std::thread library is based on pthread.

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

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

9 years agoMake use of BSS more explicit in global initializers (vs a local .comm).
Jan Voung [Sun, 25 Jan 2015 18:46:00 +0000 (10:46 -0800)]
Make use of BSS more explicit in global initializers (vs a local .comm).

This reduces the number of conditionals, and will more closely reflect
the structure of the ELF writer's version of the same thing.
Without fdata-sections, the ELF writer version will have to batch all
initializers of a certain type so that they can be contiguous on the file
and the overall alignment can be determined.

A downside of this is that, .s files will be different from llc's output.
The spec .o and executables are identical before/after the change.

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

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

9 years agoSubzero: Make thread_local work under MacOS 10.6.
Jim Stichnoth [Fri, 23 Jan 2015 18:22:56 +0000 (10:22 -0800)]
Subzero: Make thread_local work under MacOS 10.6.

MacOS doesn't support the thread_local keyword until 10.7 or later, and our bots run 10.6.

Who knows whether Visual Studio supports it yet.

In the meantime, use the old-style syntax.

BUG= https://codereview.chromium.org/873443004/
R=jfb@chromium.org

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

9 years agoFix build warnings
JF Bastien [Thu, 22 Jan 2015 22:30:57 +0000 (14:30 -0800)]
Fix build warnings

The following CL enables -Werror:
  https://codereview.chromium.org/863093002/

There were two warnings left in our subzero build:
 - Dead default cases because all of an enum's values were handled by the switch.
 - Use of C99 VLA.

R=stichnot@chromium.org
TEST= make check
BUG= none

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

9 years agoFix the PNaCl translator to lock the dump stream when printing errors.
Karl Schimpf [Thu, 22 Jan 2015 18:00:07 +0000 (10:00 -0800)]
Fix the PNaCl translator to lock the dump stream when printing errors.

The previous code did not do this. Also localizes the lock to when
the error is actually printed.

Note: requires https://codereview.chromium.org/865963002

BUG=None
R=stichnot@chromium.org

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

9 years agoSubzero: Remove the GlobalContext::GlobalDeclarations vector.
Jim Stichnoth [Tue, 20 Jan 2015 22:53:57 +0000 (14:53 -0800)]
Subzero: Remove the GlobalContext::GlobalDeclarations vector.

Elements were added to this vector, but never inspected, so it is
essentially a useless field.  Plus, the removal allows us to remove a
couple of friend declarations.

BUG=none
R=kschimpf@google.com

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

9 years agoSubzero: Add locking to prepare for multithreaded translation.
Jim Stichnoth [Tue, 20 Jan 2015 20:52:51 +0000 (12:52 -0800)]
Subzero: Add locking to prepare for multithreaded translation.

This just gets the locking in place.  Actual multithreading will be added later.

Mutexes are added for accessing the GlobalContext allocator, the constant pool, the stats data, and the profiling timers.  These are managed via the LockedPtr<> helper.  Finer grain locks on the constant pool may be added later, i.e. a separate lock for each data type.

An vector of pointers to TLS objects is added to GlobalContext.  Each new thread will get its own TLS object, whose address is added to the vector.  (After threads complete, things like stats can be combined by iterating over the vector.)

The dump/emit streams are guarded by a separate lock, to avoid fine-grain interleaving of output by multiple threads.  E.g., lock the streams, emit an entire function, and unlock the streams.  This works for dumping too, though dump output for different passes on the same function may be interleaved with that of another thread.  There is an OstreamLocker helper class to keep this simple.

CodeStats is made an inner class of GlobalContext (this was missed on a previous CL).

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

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

9 years agoAdd instruction alignment tests to unit tests.
Karl Schimpf [Tue, 20 Jan 2015 20:19:15 +0000 (12:19 -0800)]
Add instruction alignment tests to unit tests.

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

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

9 years agoSubzero: Remove the IceV_RegManager enum value.
Jim Stichnoth [Thu, 15 Jan 2015 17:05:08 +0000 (09:05 -0800)]
Subzero: Remove the IceV_RegManager enum value.

This hasn't been used in a very long time, and there's no intention of using it again.

Originally there was the idea of a "fast" block-local register allocator for an O1-like configuration, which would allocate registers for infinite-weight temporaries during target lowering, using a "local register manager".  This verbose option was for tracing execution of this register manager.  However, by now it seems unlikely that this would do a better/faster job than the current Om1 register allocation approach, which reuses the linear-scan code quite effectively and does very well at separation of concerns.  So adios IceV_RegManager!

BUG= none
R=jvoung@chromium.org

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

9 years agoStart writing out some relocation sections (text).
Jan Voung [Tue, 13 Jan 2015 01:00:22 +0000 (17:00 -0800)]
Start writing out some relocation sections (text).

Pass the full assembler pointer to the elf writer, so
that it has access to both the text buffer and the fixups.

Remove some child classes of AssemblerFixups. They didn't
really do much, and were pretty much identical to the
original AssemblerFixup class. Dart had a virtual method
for fixups to do necessary patching, but we currently
don't do the patching and just emit the relocations.
TODO see if patching is more efficient than writing out
relocations and letting the linker do the work.

This CL also makes AssemblerFixups POD.

Change the fixup kind to be a plain unsigned int, which
the target can fill w/ target/container-specific values.

Move the fwd declaration of Assembler to IceDefs and remove
the others. Do similar for fwd declaration refactoring for
ELFWriter.

Make the createAssembler method return a std::unique_ptr.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Use SmallVector<> instead of vector<> in a couple places.
Jim Stichnoth [Mon, 12 Jan 2015 17:00:50 +0000 (09:00 -0800)]
Subzero: Use SmallVector<> instead of vector<> in a couple places.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Update the lowering documentation.
Jim Stichnoth [Mon, 12 Jan 2015 16:59:21 +0000 (08:59 -0800)]
Subzero: Update the lowering documentation.

BUG= none
R=jvoung@chromium.org

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

9 years agoMake fixups reference any constant (allow const float/double pool literals).
Jan Voung [Fri, 9 Jan 2015 22:57:32 +0000 (14:57 -0800)]
Make fixups reference any constant (allow const float/double pool literals).

This avoids doing getConstantSym to avoid hitting the global
context's getConstantSym during emitIAS(), which may be desirable for
multi-threading, since each function's emitIAS() should be able to happen
on a separate thread.

The stringification is moved till later, so it still happens, just without
creating a constant relocatable w/ offset of 0.

This ends up tickling an issue where -O0 on 252.eon now gets 2x as many
page faults, and I'm not sure exactly why. This makes the overall time
higher, though emit time is lower.

When translating with -O2 # of page faults is about the same before/after,
so that oddness is restricted to O0.

Before this change, tweaking the slab size at O0 doesn't
seem to affect as drastically as 2x swings either.

To work around this, I turned the slab size of the assembler down to 32KB.

===

Move all the .L$type$poolid into a function (replacing getPoolEntryID).

BUG=none
R=stichnot@chromium.org

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

9 years agoAdd ability to test parsing of bitcode records in Subzero.
Karl Schimpf [Fri, 9 Jan 2015 21:04:13 +0000 (13:04 -0800)]
Add ability to test parsing of bitcode records in Subzero.

Extends the NaCl bitcode munger so that the PNaClTranslator parser
can be applied to the defined sequence of record values.

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

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

9 years agoSubzero: Write float/double constant pools directly to the ELF file.
Jan Voung [Fri, 9 Jan 2015 21:01:42 +0000 (13:01 -0800)]
Subzero: Write float/double constant pools directly to the ELF file.

Create the section, write the data and define the symbols in
the symbol table.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Clean up a few areas.
Jim Stichnoth [Fri, 9 Jan 2015 19:43:26 +0000 (11:43 -0800)]
Subzero: Clean up a few areas.

1. Use a reverse_range() adaptor for range-based reverse iteration through containers.

2. Remove the emitting of the commented llvm-mc command line.

3. Remove a few TODOs.

4. For commented-out declarations within a class T like this:
   // T(const T&) = delete;
   // T &operator=(const T &) = delete;
Replace them with this:
   T(const T&) = default;
   T &operator=(const T &) = default;
And try to keep them private where possible.

5. Make LivenessNode and TimerTreeNode into internal classes.

BUG= none
R=jvoung@chromium.org

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

9 years agoRemove isPooled virtual method from IceOperand.
Jan Voung [Fri, 9 Jan 2015 18:15:43 +0000 (10:15 -0800)]
Remove isPooled virtual method from IceOperand.

It doesn't seem to be used?

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Use the CfgLocalAllocator for more vector types.
Jim Stichnoth [Fri, 9 Jan 2015 00:56:49 +0000 (16:56 -0800)]
Subzero: Use the CfgLocalAllocator for more vector types.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Use range-based for loops with llvm::ilist<Inst> lists.
Jim Stichnoth [Tue, 23 Dec 2014 20:26:24 +0000 (12:26 -0800)]
Subzero: Use range-based for loops with llvm::ilist<Inst> lists.

This reestablishes C++11 features lost after switching to llvm::ilist<> in two previous CLs:
https://codereview.chromium.org/709533002/
https://codereview.chromium.org/794923002/

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

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

9 years agoSubzero: Convert NULL->nullptr.
Jim Stichnoth [Sat, 20 Dec 2014 14:17:49 +0000 (06:17 -0800)]
Subzero: Convert NULL->nullptr.

This is limited to the src directory, and not (yet) the crosstest directory.

BUG= none
R=jfb@chromium.org

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

9 years agoSubzero: Use CFG-local arena allocation for relevant containers.
Jim Stichnoth [Fri, 19 Dec 2014 20:51:35 +0000 (12:51 -0800)]
Subzero: Use CFG-local arena allocation for relevant containers.

In particular, node lists for in and out edges of a CfgNode, and the live range segment list in a Variable.  This is done by making the Cfg allocator globally available through TLS, and providing the STL containers with an allocator struct that uses this.

This also cleans up some other allocation-related issues:

* The allocator is now hung off the Cfg via a pointer, rather than being embedded into the Cfg.  This allows a const Cfg pointer to be stored in TLS while still allowing its allocator to be mutated.

* Cfg is now created via a static create() method.

* The redundant Cfg::allocateInst<> methods are removed.

* The Variable::asType() method allocates a whole new Variable from the Cfg arena, rather than allocating it on the stack, removing the need for the move constructor in Variable and Operand.  This is OK since asType() is only used for textual asm emission.

* The same 1MB arena allocator is now used by the assembler as well.  The fact that it wasn't changed over to be the same as Cfg and GlobalContext was an oversight.  (It turns out this adds ~3MB to the translator memory footprint, so that could be tuned later.)

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

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

9 years agoSubzero: Randomize register assignment.
Jim Stichnoth [Fri, 19 Dec 2014 13:42:24 +0000 (05:42 -0800)]
Subzero: Randomize register assignment.

Randomize the order that registers appear in the free list.  Only
randomize fully "equivalent" registers to ensure no extra spills.

This adds the -randomize-regalloc option.

This is a continuation of https://codereview.chromium.org/456033003/ which Matt owns.

BUG= none
R=jfb@chromium.org

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

9 years agoRemove TypeConverter and Module from minimal subzero build.
Karl Schimpf [Mon, 15 Dec 2014 21:45:00 +0000 (13:45 -0800)]
Remove TypeConverter and Module from minimal subzero build.

Removes the need to model LLVM types from the minimal subzero build.
It isn't removed from the nonminimal build because IceConverter still needs
to be able to convert LLVM types to corresponding Ice types.

Note that this CL reduces the size of Release+Min/llvm2ice (after
strip) to about 638K bytes.

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

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

9 years agoRemove using LLVM tools to check correctness of cast operation.
Karl Schimpf [Mon, 15 Dec 2014 18:16:31 +0000 (10:16 -0800)]
Remove using LLVM tools to check correctness of cast operation.

Removes cast instruction checks (in PNaClTranslator.cpp) that used
LLVM utilities to use locally defined methods instead. Remove the need
to call naclbitc::DecodeCastOpcode and CastInst::castIsValid.

Also removes two more calls to convertToLLVMType.

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

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

9 years agoSubzero: Clean up live range construction.
Jim Stichnoth [Mon, 15 Dec 2014 17:58:51 +0000 (09:58 -0800)]
Subzero: Clean up live range construction.

Moves the deletion of newly dead instructions into the main liveness() routine.  The old livenessPostProcess() routine is renamed and now used purely for live range construction.

The hack is removed in which live in-args have a custom live range segment added to avoid an artifact of the live ranges.  It is replaced with a gentler hack that extends the instruction numbering range of the initial basic block to avoid the artifact.

Since special live range segments no longer need to be prepended, the live range representation is simplified and we can always assume that segments are being appended, never prepended (and as before, never added to the middle).

Some magic constants involving special instruction numbers are replaced with symbolic constants.

BUG= none
R=jvoung@chromium.org

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

9 years agoSimplify LLVM's APInt and APFloat for use in Subzero.
Karl Schimpf [Mon, 15 Dec 2014 17:52:26 +0000 (09:52 -0800)]
Simplify LLVM's APInt and APFloat for use in Subzero.

In Subzero, we only need to be able to convert 64 bit constants in
bitcode files to the corresponding Ice integer or floating type. This
CL extracts the minimal implementation needed for Subzero. The intent
of this change is to remove loading unnecessary LLVM code into
(minimal) llvm2ice.

BUG=None
R=stichnot@chromium.org

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

9 years agoSubzero: Don't store std::string objects inside Variable.
Jim Stichnoth [Thu, 11 Dec 2014 23:51:42 +0000 (15:51 -0800)]
Subzero: Don't store std::string objects inside Variable.

Instead, extend 668a7a333d6ddc3102b5b7c7c07448f6d259113c to include both CfgNode and Variable, keeping a pool of strings in the Cfg.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Add memory usage to "-szstats" output.
Jim Stichnoth [Thu, 11 Dec 2014 18:04:32 +0000 (10:04 -0800)]
Subzero: Add memory usage to "-szstats" output.

Requires the LLVM option -track-memory to get meaningful results.

BUG= none
R=kschimpf@google.com

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

9 years agoSubzero: Use llvm::ilist<> for PhiList and AssignList.
Jim Stichnoth [Thu, 11 Dec 2014 17:22:45 +0000 (09:22 -0800)]
Subzero: Use llvm::ilist<> for PhiList and AssignList.

This is toward the goal of pulling non-POD fields out of the CfgNode
class so that CfgNode can be arena-allocated and not leak memory.

For now, PhiList and AssignList are defined as InstList.  Ideally,
they would be ilist<> of InstPhi and InstAssign, but SFINAE happens.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Pull the node name out of the node structure.
Jim Stichnoth [Wed, 10 Dec 2014 23:32:25 +0000 (15:32 -0800)]
Subzero: Pull the node name out of the node structure.

Instead, non-empty node names are kept in a single vector in the Cfg
object.

This is toward the goal of pulling non-POD fields out of the CfgNode
class so that CfgNode can be arena-allocated and not leak memory.

Also, actual setting of the node name is now guarded by ALLOW_DUMP.

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

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

9 years agoReduce one layer of decoding for binary operations in bitcode reading.
Karl Schimpf [Wed, 10 Dec 2014 20:54:34 +0000 (12:54 -0800)]
Reduce one layer of decoding for binary operations in bitcode reading.

Removes the need to call function llvm::DecodeBinaryOp. In turn, this removes
the need for enum type llvm::Instruction::BinaryOps, llvm::Type.isFPOrFPVectorTy, and one call to llvm::convertToLLVMType.

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

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

9 years agoRemove call to PNaClABIProps::isAllowedAlignment from subzero.
Karl Schimpf [Tue, 9 Dec 2014 21:50:07 +0000 (13:50 -0800)]
Remove call to PNaClABIProps::isAllowedAlignment from subzero.

Also removes the need for DataLayout.

BUG=None
R=stichnot@chromium.org

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

9 years agoSubzero: Disable stats and timers under the MINIMAL build.
Jim Stichnoth [Mon, 8 Dec 2014 22:57:52 +0000 (14:57 -0800)]
Subzero: Disable stats and timers under the MINIMAL build.

Specifically, don't bother to collect "-timing" and "-szstats" information since they anyway don't get printed out under the MINIMAL build.  This is done by using the ALLOW_DUMP flag to guard whether code and timing stats are collected.  This ends up reducing the native translator size by about 3%.  ALLOW_DUMP is used as the guard since it already guards the output of the collected data - no sense collecting the data if it can never be printed out.

To minimize the number of ALLOW_DUMP tests, we push the tests into the timing/stats class methods.

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

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

9 years agoSubzero: Build with function/data sections and -gc-sections.
Jim Stichnoth [Sun, 7 Dec 2014 22:25:34 +0000 (14:25 -0800)]
Subzero: Build with function/data sections and -gc-sections.

This is consistent with how LLVM is built, and makes it easier to analyze the potential size of a translator build and what may be inappropriately brought into the build.

BUG= none
R=kschimpf@google.com

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

9 years agoSubzero: Improve performance by using llvm::SmallVector<>.
Jim Stichnoth [Sat, 6 Dec 2014 00:43:08 +0000 (16:43 -0800)]
Subzero: Improve performance by using llvm::SmallVector<>.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Disable asserts in the MINIMAL build.
Jim Stichnoth [Fri, 5 Dec 2014 22:16:07 +0000 (14:16 -0800)]
Subzero: Disable asserts in the MINIMAL build.

BUG= none
R=kschimpf@google.com

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

9 years agoSubzero: Fix the g++ build (e.g. Windows).
Jim Stichnoth [Thu, 4 Dec 2014 22:09:21 +0000 (14:09 -0800)]
Subzero: Fix the g++ build (e.g. Windows).

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

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

9 years agoSubzero: Use std::vector<> instead of std::list for live range segments.
Jim Stichnoth [Thu, 4 Dec 2014 19:45:03 +0000 (11:45 -0800)]
Subzero: Use std::vector<> instead of std::list for live range segments.

This generally uses less memory and fewer allocations.

Also removes the commented-out alternative implementation using std::set<>, which would almost certainly never be a good idea here.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Add llvm-readobj to lit.cfg.
Jim Stichnoth [Thu, 4 Dec 2014 17:11:48 +0000 (09:11 -0800)]
Subzero: Add llvm-readobj to lit.cfg.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Improve the memory-related performance of the register allocator.
Jim Stichnoth [Thu, 4 Dec 2014 04:30:34 +0000 (20:30 -0800)]
Subzero: Improve the memory-related performance of the register allocator.

Profiling indicated a noticeable amount of time spent on malloc/free related to the std::list<> implementation of UnorderedRanges.  Therefore, we change the implementation to be std::vector<>, and up-front reserve a conservative amount of space to avoid expansion.  The push_back() operation is always constant time with no allocation.  Removing an element from the middle of the vector is done by swapping with the last element and then popping the last element, which is reasonable in principle because it is used as an unordered collection.  Because of the swapping trick, the UnorderedRanges iterators are changed to iterate in reverse.

BUG= none
R=jvoung@chromium.org

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

9 years agoTry to fix mismatch between writeELFHeaderInternal def and decl.
Jan Voung [Wed, 3 Dec 2014 23:51:22 +0000 (15:51 -0800)]
Try to fix mismatch between writeELFHeaderInternal def and decl.

BUG=build failure
R=kschimpf@google.com

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

9 years agoFix PNaCl bitcode to LLVM IR reader to match new API.
Karl Schimpf [Wed, 3 Dec 2014 22:49:53 +0000 (14:49 -0800)]
Fix PNaCl bitcode to LLVM IR reader to match new API.

When LLVM 3.5 was merged, the handling of errors was broken. This
is being fixed in the CL listed below. This CL fixes Subzero's
call so that it will work with the CL listed below.

Relavant LLVM CL: https://codereview.chromium.org/770853002

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

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

9 years agoSubzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers).
Jan Voung [Tue, 2 Dec 2014 01:55:16 +0000 (17:55 -0800)]
Subzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers).

Able to write out the ELF file header w/ a text section,
a symbol table, and string table. Write text buffer
directly to file after translating each CFG.
This means that the header is written out early w/ fake
data and then we seek back and write the real header
at the very end.

Does not yet handle relocations, data, rodata, constant
pools, bss, or -ffunction-sections, more than 64K sections
or more than 2^24 symbols.

Numbers w/ current NOASSERT=1 build on 176.gcc:

w/out -elf-writer:
    0.233771 (21.1%): [ 1287] emit
    28MB .s file

w/ -elf-writer:
    0.051056 ( 5.6%): [ 1287] emit
    2.4MB .o file

BUG=none
R=stichnot@chromium.org

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

9 years agoCreate local config file for subzero reader tests.
Karl Schimpf [Mon, 1 Dec 2014 21:39:00 +0000 (13:39 -0800)]
Create local config file for subzero reader tests.

Using lit.local.cfg, don't allow reader tests unless dumping
of IR is allowed.

This was suggested by Jan in: https://codereview.chromium.org/686913005

BUG=None
R=jvoung@chromium.org

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

9 years agoSubzero: Fix a bug in postLower().
Jim Stichnoth [Mon, 1 Dec 2014 17:30:55 +0000 (09:30 -0800)]
Subzero: Fix a bug in postLower().

In -O2 mode, postLower() is supposed to iterate over just the
instructions that were most recently added.  Instead, it was iterating
all the way to the end of the block, also post-lowering high-level ICE
instructions that hadn't yet been lowered.  This was basically
harmless, given that the spec2k asm code is identical after this
patch, but it improves performance.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Improve malloc/free behavior.
Jim Stichnoth [Wed, 26 Nov 2014 22:11:53 +0000 (14:11 -0800)]
Subzero: Improve malloc/free behavior.

Use a bigger block size in the bump-pointer allocators, since we
basically know up front that we'll need lots of memory.  The 1MB value
(versus the default of 4KB) was chosen somewhat arbitrarily, and
succeeds in pretty much removing bump-pointer related mallocs from the
profile.

Pre-reserve the a priori known number of edges in getTerminatorEdges()
to avoid vector resizing.

BUG= none
R=kschimpf@google.com

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

9 years agoSubzero: Fix new issues after the LLVM 3.5 merge.
Jim Stichnoth [Mon, 24 Nov 2014 22:36:23 +0000 (14:36 -0800)]
Subzero: Fix new issues after the LLVM 3.5 merge.

We need to link with -lpthread now.

The CALLTARGETS workaround in our lit tests can be removed, since llvm-objdump has gotten more accurate than before with respect to symbols.

The -stats and -rng-seed options need to be renamed to avoid conflicting with the LLVM options being brought in.

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

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

9 years agoMerge remote-tracking branch 'origin/merge_35'
JF Bastien [Fri, 21 Nov 2014 18:02:17 +0000 (10:02 -0800)]
Merge remote-tracking branch 'origin/merge_35'

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

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

9 years agoSubzero: Simplify the constant pools.
Jim Stichnoth [Thu, 20 Nov 2014 19:24:42 +0000 (11:24 -0800)]
Subzero: Simplify the constant pools.

Internally, create a separate constant pool for each integer type, instead of a single i64 pool that uses the Ice::Type value as part of the key.  This means each constant pool key can be a simple primitive value, rather than a tuple.

Represent the pools using std::unordered_map instead of std::map since we're using C++11 now.

Use signed integers instead of unsigned integers for the integer constant pools, to benefit from sign extension and to be more consistent.

Remove the SuppressMangling field from hash and comparison functions on RelocatableTuple, since we'll never have two symbols with the same name but different values of SuppressMangling.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Update the README file.
Jim Stichnoth [Tue, 18 Nov 2014 17:16:31 +0000 (09:16 -0800)]
Subzero: Update the README file.

It's not meant to be comprehensive, but rather to help someone new get started, assuming they already have PNaCl working.

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

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

9 years agoTurn off dump/emit routines when building minimal subzero.
Karl Schimpf [Mon, 17 Nov 2014 18:58:39 +0000 (10:58 -0800)]
Turn off dump/emit routines when building minimal subzero.

Remove the dump/emit routines when ALLOW_DUMP=0. Also fixes some
verbosity messages to not print if ALLOW_DUMP=0. Note: emit routines
needed for emitIAS are not turned off.

BUG=None
R=stichnot@chromium.org

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

9 years agoSubzero: Use the linear-scan register allocator for Om1 as well.
Jim Stichnoth [Fri, 14 Nov 2014 23:53:46 +0000 (15:53 -0800)]
Subzero: Use the linear-scan register allocator for Om1 as well.

This removes the need for Om1's postLower() code which did its own ad-hoc register allocation.  And it actually speeds up Om1 translation significantly.

This mode of register allocation only allocates for infinite-weight Variables, while respecting live ranges of pre-colored Variables.

BUG= none
R=jvoung@chromium.org

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

9 years agoAdd irt_random to szbuild link line.
Jan Voung [Fri, 14 Nov 2014 21:49:55 +0000 (13:49 -0800)]
Add irt_random to szbuild link line.

Seems to be part of the non-sfi link now:
https://codereview.chromium.org/686723003/diff/180001/pnacl/driver/pnacl-translate.py

Otherwise I get:
x86-32-linux/lib/unsandboxed_irt.o:(.rodata+0x68): undefined reference to `nacl_secure_random'

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Simplify the FakeKill instruction.
Jim Stichnoth [Fri, 14 Nov 2014 18:27:29 +0000 (10:27 -0800)]
Subzero: Simplify the FakeKill instruction.

Even after earlier simplifications, FakeKill was still handled somewhat inefficiently for the register allocator.  For x86-32, any function containing call instructions would result in about 11 pre-colored Variables, each with an identical and relatively complex live range consisting of points.  They would start out on the UnhandledPrecolored list, then all move to the Inactive list, where they would be repeatedly compared against each register allocation candidate via overlapsRange().

We improve this by keeping around a single copy of that live range and directly masking out the Free[] register set when that live range overlaps the current candidate's live range.  This saves ~10 overlaps() calculations per candidate while FakeKills are still pending.

Also, slightly rearrange the initialization of the Unhandled etc. sets into a separate init routine, which will make it easier to reuse the register allocator in other situations such as Om1 post-lowering.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Auto-set -build-on-read=0 for .ll input files.
Jim Stichnoth [Fri, 14 Nov 2014 17:52:26 +0000 (09:52 -0800)]
Subzero: Auto-set -build-on-read=0 for .ll input files.

This is purely for convenience of personal testing/debugging.

To demonstrate its correctness in this CL, -build-on-read=0 is removed
from the two .ll lit tests that explicitly use it, and also from the
crosstest.py script.  The lit test wrapper run-llvm2ice.py is left
unchanged to be safe.

BUG= none
R=kschimpf@google.com

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

9 years agoSubzero: Remove Variable::NeedsStackSlot.
Jim Stichnoth [Tue, 11 Nov 2014 17:49:04 +0000 (09:49 -0800)]
Subzero: Remove Variable::NeedsStackSlot.

Instead, separately compute it during prolog generation via another
pass over the Cfg.

This may slow down translation by ~1%, but it greatly simplifies the
management of this flag/property.

The higher motivation is to pull this management out of register
allocation to make it easier to extend register allocation for other
uses.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Implement InstList in terms of llvm::ilist<> .
Jim Stichnoth [Thu, 6 Nov 2014 21:32:05 +0000 (13:32 -0800)]
Subzero: Implement InstList in terms of llvm::ilist<> .

Use LLVM's intrusive list ADT template to implement instruction lists.  This embeds prev/next pointers into the instruction, and as such, iterators essentially double as instruction pointers.  This means stripping off one level of indirection when dereferencing, and also the range-based for loop can't be used.

The performance difference in translation time seems to be 1-2%.

I tried to also do this for the much less used PhiList and AssignList, but ran into SFINAE problems.

BUG= none
R=jvoung@chromium.org

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

9 years agoDisable Subzero IR generation for performance testing.
Karl Schimpf [Thu, 6 Nov 2014 17:49:24 +0000 (09:49 -0800)]
Disable Subzero IR generation for performance testing.

This CL allows one to time Subzero's bitcode parsing without IR generation
(other than types, function declarations, and uninitialized global variables)
for performance testing.

BUG=None
R=jvoung@chromium.org

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

9 years agoRearrange emit vs emitIAS. Wait till function is done before dumping text.
Jan Voung [Thu, 6 Nov 2014 01:29:56 +0000 (17:29 -0800)]
Rearrange emit vs emitIAS. Wait till function is done before dumping text.

Eventually, I wanted to have a flag "UseELFWriter" like:
https://codereview.chromium.org/678533005/diff/120001/src/IceCfg.cpp

Where the emit OStream would not have text, and only have
binary. This refactor hopefully means fewer places to
check for a flag to disable the text version of IAS,
and be able to write binary. Otherwise, there are some
text labels for branches that are still being dumped out.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Improve the use of NodeList objects.
Jim Stichnoth [Thu, 6 Nov 2014 00:04:05 +0000 (16:04 -0800)]
Subzero: Improve the use of NodeList objects.

Currently NodeList is defined as std::vector<CfgNode*>, but in the future it may be desirable to change it to something like std::list<CfgNode*> so that it is easier to split edges and insert the new nodes at the right locations, rather than re-sorting them in a separate pass.

This gets us closer by using foo.front() instead of foo[0].  There are still a couple more places using the [] operator, but the changes would be more intrusive.

Also, a few instances of ".size()==0" are changed to the possibly more efficient ".empty()".

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

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

9 years agoSubzero: Use a common RelocOffsetType / RelocOffsetT.
Jan Voung [Wed, 5 Nov 2014 00:55:01 +0000 (16:55 -0800)]
Subzero: Use a common RelocOffsetType / RelocOffsetT.

There is one in IceDefs.h and one in IceGlobalInits.h. Can we just use one?

BUG=none (mini cleanup)
R=kschimpf@google.com, stichnot@chromium.org

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

9 years agoMore consistently use auto for emit*, nullptr in asm code.
Jan Voung [Tue, 4 Nov 2014 18:40:03 +0000 (10:40 -0800)]
More consistently use auto for emit*, nullptr in asm code.

More consistently use auto while doing llvm::dyn_cast/cast in the emit
and emitIAS routines.

BUG=none
R=stichnot@chromium.org

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

9 years agoSubzero: Delete szdiff.py tests and ERRORS tests.
Jim Stichnoth [Tue, 4 Nov 2014 18:08:51 +0000 (10:08 -0800)]
Subzero: Delete szdiff.py tests and ERRORS tests.

Also deletes a few entirely trivial test files.

These tests were useful in the early days of Subzero, but now mostly just clutter things up.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Improve the representation and handling of the FakeKill instruction.
Jim Stichnoth [Tue, 4 Nov 2014 17:10:01 +0000 (09:10 -0800)]
Subzero: Improve the representation and handling of the FakeKill instruction.

The FakeKill instruction is always used for killing scratch registers, and a fair amount of effort is spent building new copies of the same scratch register list each time (i.e., for each lowered call instruction).  As such, we can create one master list of scratch registers and share it among all FakeKill instructions.

Also, in all situations where an instruction's Srcs[] were considered for liveness, we had to either explicitly ignore an InstFakeKill instruction, or treat it specially.  Now that InstFakeKill lacks any Srcs[] (or Dest), it doesn't need to be specially ignored, and the code is simplified.

In addition, the text asm emitter no longer clutters the output with FakeKill comments (and FakeUse as well).

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Implement switch lowering for i64.
Jim Stichnoth [Tue, 4 Nov 2014 03:57:24 +0000 (19:57 -0800)]
Subzero: Implement switch lowering for i64.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Support multiple fixups in one instruction.
Jim Stichnoth [Mon, 3 Nov 2014 20:36:29 +0000 (12:36 -0800)]
Subzero: Support multiple fixups in one instruction.

The integrated assembler assumed there is at most one fixup per instruction.  For x86, there could actually be two fixups, for any instruction that allows memory and immediate operands at the same time.  Using the now-default -build-on-read flag, it happens in spec2k - the smallest function I found where this happens is 176.gcc and perm_tree_cons.

This changes the textual emission of integrated assembler code to allow for multiple consecutive fixups in a single instruction.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Allow non-hybrid binaries to be built.
Jim Stichnoth [Mon, 3 Nov 2014 20:31:28 +0000 (12:31 -0800)]
Subzero: Allow non-hybrid binaries to be built.

Build a pure-Subzero binary when neither --include nor --exclude is specified.

A pure-Subzero binary is built without flags:
  -externalize
  -ffunction-sections
  -fdata-sections
which is good because that configuration is closer to what real usage will be, and will get more testing during development.

BUG= none
R=kschimpf@google.com

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

9 years agoAdd timing of bitcode parser to Subzero.
Karl Schimpf [Mon, 3 Nov 2014 19:29:39 +0000 (11:29 -0800)]
Add timing of bitcode parser to Subzero.

Adds timers to each bitcode block parser in Subzero, to get a reading
on how much time is used by the bitcode parser.

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

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

9 years agoSubzero: Remove the LEAHACK workarounds.
Jim Stichnoth [Sun, 2 Nov 2014 17:41:45 +0000 (09:41 -0800)]
Subzero: Remove the LEAHACK workarounds.

They are no longer needed now that we aren't using the buggy llvm-mc parser for Intel syntax.

This also gets all spec2k components to work with -build-on-read.

Also, adds an emit-time check that infinite-weight Variables actually got a physical register.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Switch to AT&T asm syntax. I give up.
Jim Stichnoth [Sat, 1 Nov 2014 17:13:54 +0000 (10:13 -0700)]
Subzero: Switch to AT&T asm syntax.  I give up.

The main motivation is that -build-on-read introduces Intel-style asm output like:
  mov al, byte ptr [flags]
and llvm-mc misinterprets the global symbol "flags" as the flags register.  Further workarounds will likely cost more effort than switching over to AT&T syntax.

Most of the lit tests don't need changing, since the asm text is generated by assembling and disassembling the llvm2ice asm output.

There some LEAHACK TODOs that can be fixed, but that would change some of the instructions, so that can be a separate CL.

The Operand emit() routines really ought to be moved entirely into the target-specific source files.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Decorate the text asm output with register availability info.
Jim Stichnoth [Sat, 1 Nov 2014 17:10:18 +0000 (10:10 -0700)]
Subzero: Decorate the text asm output with register availability info.

The -asm-verbose flag adds comments to the text asm output about register availability.  Specifically, it prints the registers in use at the beginning and end of each block, and it prints which registers' live ranges end at each instruction.

This is extremely helpful when studying the output to find opportunities to improve the code quality.

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Remove a TODO comment about shld/shrd.
Jan Voung [Sat, 1 Nov 2014 16:40:20 +0000 (09:40 -0700)]
Subzero: Remove a TODO comment about shld/shrd.

The 32-bit validator is now consistent with the 64-bit
validator w.r.t. 16-bit shld/shrd and accepts it. We didn't
really use the 16-bit form in Subzero though, only the 32-bit
one for 64-bit ops, I think.

BUG=none
R=stichnot@chromium.org

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

9 years agoRemove -Werror from pnacl build, due to default switch error in subzero.
Karl Schimpf [Thu, 30 Oct 2014 22:11:11 +0000 (15:11 -0700)]
Remove -Werror from pnacl build, due to default switch error in subzero.

When compiling using toolchain_build_pnacl.py, we get errors of form:

  Don't use default labels in fully covered switches over enumerations

I tried different combinations of -Wno-covered-switch-default and
-Wno-error=covered-switch-default, but was not able to stop this
error from being generated. Hence, taking the simplier route of
removing -Werror from Makefile.

(see www.llvm.org/docs/CodingStandards.html for more details)

BUG=None
R=stichnot@chromium.org

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

9 years agoSubzero: Implementation of "advanced Phi lowering".
Jim Stichnoth [Thu, 30 Oct 2014 22:01:31 +0000 (15:01 -0700)]
Subzero: Implementation of "advanced Phi lowering".

Delays Phi lowering until after register allocation.  This lets the Phi assignment order take register allocation into account and avoid creating false dependencies.

All edges that lead to Phi instructions are split, and the new node gets mov instructions in the correct topological order, using available physical registers as needed.

This lowering style is controllable under -O2 using -phi-edge-split (enabled by default).

The result is faster translation time (due to fewer temporaries leading to faster liveness analysis and register allocation) as well as better code quality (due to better register allocation and fewer phi-based assignments).

BUG= none
R=jvoung@chromium.org

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

9 years agoSubzero: Fix broken lit tests.
Jim Stichnoth [Thu, 30 Oct 2014 01:51:56 +0000 (18:51 -0700)]
Subzero: Fix broken lit tests.

The file ifatts.py no longer exists.

BUG= none
R=jvoung@chromium.org

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

9 years agoRemove IceConverter when LLVM IR is not allowed.
Karl Schimpf [Wed, 29 Oct 2014 21:58:25 +0000 (14:58 -0700)]
Remove IceConverter when LLVM IR is not allowed.

BUG=
R=stichnot@chromium.org

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