Implement MachODumper::printFileHeaders

Patch by Chilledheart.

Differential Revision: http://reviews.llvm.org/D6163

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222115 91177308-0d34-0410-b5e6-96231b3b80d8
Add back r222061 with a fix.

This adds back r222061, but now calls initializePAEvalPass from the correct
library to avoid link problems.

Original message:

Don't make assumptions about the name of private global variables.

Private variables are can be renamed, so it is not reliable to make
decisions on the name.

The name is also dropped by the assembler before getting to the
linker, so using the name causes a disconnect between how llvm makes a
decision (var name) and how the linker makes a decision (section it is
in).

This patch changes one case where we were looking at the variable name to use
the section instead.

Test tuning by Michael Gottesman.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222117 91177308-0d34-0410-b5e6-96231b3b80d8
Move register class name strings to a single array in MCRegisterInfo to reduce static table size and number of relocation entries.

Indices into the table are stored in each MCRegisterClass instead of a pointer. A new method, getRegClassName, is added to MCRegisterInfo and TargetRegisterInfo to lookup the string in the table.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222118 91177308-0d34-0410-b5e6-96231b3b80d8
Add missing semicolon from r222118.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222119 91177308-0d34-0410-b5e6-96231b3b80d8
Fix CR/LF line endings in test case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222120 91177308-0d34-0410-b5e6-96231b3b80d8
Optimize switch lookup tables with linear mapping.

This is a simple optimization for switch table lookup:
It computes the output value directly with an (optional) mul and add if there is a linear mapping between index and output.
Example:

int f1(int x) {
  switch (x) {
    case 0: return 10;
    case 1: return 11;
    case 2: return 12;
    case 3: return 13;
  }
  return 0;
}

generates:

define i32 @f1(i32 %x) #0 {
entry:
  %0 = icmp ult i32 %x, 4
  br i1 %0, label %switch.lookup, label %return

switch.lookup:
  %switch.offset = add i32 %x, 10
  ret i32 %switch.offset

return:
  ret i32 0
}



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222121 91177308-0d34-0410-b5e6-96231b3b80d8
silence gcc 4.9.1 warning in /llvm/lib/Support/Windows/Path.inc:564:39:
warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if (ec = widenPath(path, path_utf16))



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222122 91177308-0d34-0410-b5e6-96231b3b80d8
Fix optimisations of SELECT_CC which assumed result is boolean

Some optimisations in DAGCombiner cause miscompilations for targets that use
TargetLowering::UndefinedBooleanContent, because they assume that the results
of a SELECT_CC node are boolean values, and can be safely ANDed, ORed and
XORed. These optimisations are only valid for targets that use
ZeroOrOneBooleanContent or ZeroOrNegativeOneBooleanContent.

This is a follow-up to D6210/r221693.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222123 91177308-0d34-0410-b5e6-96231b3b80d8
Object, COFF: Tighten the object file parser

We were a little lax in a few areas:
- We pretended that import libraries were like any old COFF file, they
  are not.  In fact, they aren't really COFF files at all, we should
  probably grow some specialized functionality to handle them smarter.
- Our symbol iterators were more than happy to attempt to go past the
  end of the symbol table if you had a symbol with a bad list of
  auxiliary symbols.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222124 91177308-0d34-0410-b5e6-96231b3b80d8
[Thumb1] Re-write emitThumbRegPlusImmediate

This was motivated by a bug which caused code like this to be
miscompiled:
  declare void @take_ptr(i8*)
  define void @test() {
    %addr1.32 = alloca i8
    %addr2.32 = alloca i32, i32 1028
    call void @take_ptr(i8* %addr1)
    ret void
  }

This was emitting the following assembly to get the value of %addr1:
  add r0, sp, #1020
  add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
  add r0, sp, #1020
  add r0, sp, #8

This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222125 91177308-0d34-0410-b5e6-96231b3b80d8
ScalarEvolution: Construct SCEVDivision's Derived type instead of itself

SCEVDivision::divide constructed an object of SCEVDivision<Derived>
instead of Derived.  divide would call visit which would cast the
SCEVDivision<Derived> to type Derived.  As it happens,
SCEVDivision<Derived> and Derived currently have the same layout but
this is fragile and grounds for UB.

Instead, just construct Derived.  No functional change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222126 91177308-0d34-0410-b5e6-96231b3b80d8
Fix ARM triple parsing

The triple parser should only accept existing architecture names
when the triple starts with armv, armebv, thumbv or thumbebv.

Patch by Gabor Ballabas.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222129 91177308-0d34-0410-b5e6-96231b3b80d8
Use a more canonical way of computing a mask with N trailing 1s. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222137 91177308-0d34-0410-b5e6-96231b3b80d8
[Reassociate] Canonicalize constants to RHS operand.

Fix a thinko where the RHS was already a constant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222139 91177308-0d34-0410-b5e6-96231b3b80d8
[X86] Use ADD/SUB instead of INC/DEC for Haswell and Broadwell CPUs

Differential Revision: http://reviews.llvm.org/D5934



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222141 91177308-0d34-0410-b5e6-96231b3b80d8
[Reassociate] As the expression tree is rewritten make sure the operands are
emitted in canonical form.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222142 91177308-0d34-0410-b5e6-96231b3b80d8
Avoid undefined behavior by masking the shift amount.

Should hopefully fix the mips bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222146 91177308-0d34-0410-b5e6-96231b3b80d8
Fix GraphTraits for "const CallGraphNode *" and "const CallGraph *"

The specializations were broken. For example,

void foo(const CallGraph *G) {
  auto I = GraphTraits<const CallGraph *>::nodes_begin(G);
  auto K = I++;

  ...
}

or

void bar(const CallGraphNode *N) {
  auto I = GraphTraits<const CallGraphNode *>::nodes_begin(G);
  auto K = I++;

  ....
}

would not compile.

Patch by Speziale Ettore!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222149 91177308-0d34-0410-b5e6-96231b3b80d8
Revert commits r222146 and r222137.

They were producing the wrong result if NumBits == BitsInWord. The old mask
produced -1, the new mask 0.

This should fix the 32 bit bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222166 91177308-0d34-0410-b5e6-96231b3b80d8
[SimplifyCFG] Make the value type of the hole check bitmask a power-of-2.

When converting a switch to a lookup table we might have to generate a bitmaks
to encode and check for holes in the original switch statement.

The type of this mask depends on the number of switch statements, which can
result in illegal types for pretty much all architectures.

To avoid unnecessary type legalization and help FastISel this commit increases
the size of the bitmask to next power-of-2 value when necessary.

This fixes rdar://problem/18984639.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222168 91177308-0d34-0410-b5e6-96231b3b80d8