1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 04:52:54 +02:00
Commit Graph

35 Commits

Author SHA1 Message Date
Jordan Rose
50156aa1c0 [ADT] Update PointerIntPair to handle pointer types with more than 31 bits free.
Previously, the assertions in PointerIntPair would try to calculate the value
(1 << NumLowBitsAvailable); the inferred type here is 'int', so if there were
more than 31 bits available we'd get a shift overflow.

Also, add a rudimentary unit test file for PointerIntPair.

llvm-svn: 203273
2014-03-07 19:19:56 +00:00
Alp Toker
e89523ae73 [C++11] Expand and eliminate the LLVM_ENUM_INT_TYPE() macro
llvm-svn: 202607
2014-03-02 03:20:38 +00:00
Reid Kleckner
333fd129ac Explicitly request unsigned enum types when desired
The underlying type of all plain enums in MSVC is 'int', even if the
enumerator contains large 32-bit unsigned values or values greater than
UINT_MAX.  The only way to get a large or unsigned enum type is to
request it explicitly with the C++11 strong enum types feature.

However, since LLVM isn't C++11 yet, I had to add a conditional
LLVM_ENUM_INT_TYPE to Compiler.h to control its usage.

The motivating true positive for this change is compiling PointerIntPair
with MSVC for win64.  The PointerIntMask value is supposed to be pointer
sized value of all ones with some low zeros.  Instead, it's truncated to
32-bits!  We are only saved later because it is sign extended back in
the AND with int64_t, and we happen to want all ones.

This silences lots of -Wmicrosoft warnings during a clang self-host
targeting Windows.

llvm-svn: 191241
2013-09-23 23:26:57 +00:00
Joe Groff
36d7fb53e7 Fix PointerIntPair to be enum class compatible.
Some parts of PointerIntPair assumed that the IntType of the pair was implicitly
convertible to intptr_t, which is not the case for enum class values. Add a
static_cast<intptr_t> to make these conversions explicit and allow
PointerIntPair to be used with an enum class IntType. While we're here, rename
some of the argument values so we don't have variables named "Int" floating
around.

llvm-svn: 179073
2013-04-09 00:01:51 +00:00
Argyrios Kyrtzidis
ef5e4688df Eliminate redundant bitwise operations when using a llvm/ADT/PointerUnion.
For comparison, with this code sample:

PointerUnion<int *, char *> Data;
PointerUnion<int *, char *> foo1() {
	Data = new int;
	return new int;
}
PointerUnion<int *, char *> foo2() {
	Data = new char;
	return new char;
}

Before this patch we would get:

define i64 @_Z4foo1v() uwtable ssp {
  %1 = tail call noalias i8* @_Znwm(i64 4)
  %2 = ptrtoint i8* %1 to i64
  %3 = load i64* getelementptr inbounds (%"class.llvm::PointerUnion"* @Data, i64 0, i32 0, i32 0), align 8
  %4 = and i64 %3, 1
  %.masked.i = and i64 %2, -3
  %5 = or i64 %4, %.masked.i
  store i64 %5, i64* getelementptr inbounds (%"class.llvm::PointerUnion"* @Data, i64 0, i32 0, i32 0), align 8
  %6 = tail call noalias i8* @_Znwm(i64 4)
  %7 = ptrtoint i8* %6 to i64
  %8 = and i64 %7, -3
  ret i64 %8
}

define i64 @_Z4foo2v() uwtable ssp {
  %1 = tail call noalias i8* @_Znwm(i64 1)
  %2 = ptrtoint i8* %1 to i64
  %3 = load i64* getelementptr inbounds (%"class.llvm::PointerUnion"* @Data, i64 0, i32 0, i32 0), align 8
  %4 = and i64 %3, 1
  %5 = or i64 %2, %4
  %6 = or i64 %5, 2
  store i64 %6, i64* getelementptr inbounds (%"class.llvm::PointerUnion"* @Data, i64 0, i32 0, i32 0), align 8
  %7 = tail call noalias i8* @_Znwm(i64 1)
  %8 = ptrtoint i8* %7 to i64
  %9 = or i64 %8, 2
  ret i64 %9
}

After the patch:

define i64 @_Z4foo1v() uwtable ssp {
  %1 = tail call noalias i8* @_Znwm(i64 4)
  %2 = ptrtoint i8* %1 to i64
  store i64 %2, i64* getelementptr inbounds (%"class.llvm::PointerUnion"* @Data, i64 0, i32 0, i32 0), align 8
  %3 = tail call noalias i8* @_Znwm(i64 4)
  %4 = ptrtoint i8* %3 to i64
  ret i64 %4
}

declare noalias i8* @_Znwm(i64)

define i64 @_Z4foo2v() uwtable ssp {
  %1 = tail call noalias i8* @_Znwm(i64 1)
  %2 = ptrtoint i8* %1 to i64
  %3 = or i64 %2, 2
  store i64 %3, i64* getelementptr inbounds (%"class.llvm::PointerUnion"* @Data, i64 0, i32 0, i32 0), align 8
  %4 = tail call noalias i8* @_Znwm(i64 1)
  %5 = ptrtoint i8* %4 to i64
  %6 = or i64 %5, 2
  ret i64 %6
}

llvm-svn: 169147
2012-12-03 19:59:23 +00:00
Richard Smith
865f47cbb6 Fix integer undefined behavior due to signed left shift overflow in LLVM.
Reviewed offline by chandlerc.

llvm-svn: 162623
2012-08-24 23:29:28 +00:00
Jordan Rose
18d21debd3 Allow PointerIntPairs to be created from const void *.
For a measure of safety, this conversion is only permitted if the
stored pointer type can also be created from a const void *.

llvm-svn: 160456
2012-07-18 21:58:49 +00:00
Argyrios Kyrtzidis
267b14e42c PointerUnion::getAddrOf() does not need to be template since we can only
use the first pointer type for it. Rename it to getAddrOfPtr1().

llvm-svn: 152106
2012-03-06 07:14:54 +00:00
Argyrios Kyrtzidis
a3437f732e Allow getting the address of the value in a PointerUnion or PointerIntPair if one is
confident enough that he knows what he is doing.

llvm-svn: 126019
2011-02-19 03:55:58 +00:00
Chris Lattner
587962c667 Remove isPod() from DenseMapInfo, splitting it out to its own
isPodLike type trait.  This is a generally useful type trait for
more than just DenseMap, and we really care about whether something
acts like a pod, not whether it really is a pod.

llvm-svn: 91421
2009-12-15 07:26:43 +00:00
John McCall
f2c6ae3996 Fix a few places where PointerIntPair was using PointerLikeTypeTraits<PointerTy>
instead of the PtrTraits provided.  Allows PointerIntPair to contain a
PointerUnion safely, as long as the bits add up.

llvm-svn: 82163
2009-09-17 20:35:18 +00:00
Bill Wendling
07f3cdb8ba I cast, therefore I think I know what I'm doing.
llvm-svn: 70151
2009-04-26 20:12:38 +00:00
Bill Wendling
d0a7587da5 Use uint64_t instead of unsigned.
llvm-svn: 70148
2009-04-26 19:46:41 +00:00
Chris Lattner
4685a9682f revert an incorrect patch. This causes crashes all over the place on a
64-bit build.

llvm-svn: 70147
2009-04-26 19:44:20 +00:00
Bill Wendling
2233793a0f Suppress warnings about conversion shortening 64-bit to 32-bit.
llvm-svn: 70138
2009-04-26 18:10:20 +00:00
Chris Lattner
2d00a451cb fix the PointerLikeTypeTraits specialization for PointerIntPair to
allow the traits to be specified as well.

llvm-svn: 68055
2009-03-30 20:28:50 +00:00
Chris Lattner
8e83bd3891 add missing space.
llvm-svn: 67995
2009-03-29 13:26:05 +00:00
Chris Lattner
f3d562df05 When forming sentinels for empty/tombstone, make sure to respect the
pointer's expected number of zero low-bits.

This should fix the breakage I introduced recently.

llvm-svn: 67990
2009-03-29 06:33:22 +00:00
Chris Lattner
b71e26c380 Allow a specific PointerIntPair instance to use a specific Pointer trait:
some pointer instances have properties that not all of a type have.

llvm-svn: 67986
2009-03-29 06:02:20 +00:00
Chris Lattner
9dc97aa7bf Replace the PointerLikeTypeTraits::getNumLowBitsAvailable
function with a new NumLowBitsAvailable enum, which makes the
value available as an integer constant expression.

Add PointerLikeTypeTraits specializations for Instruction* and
Use** since they are only guaranteed 4-byte aligned.

Enhance PointerIntPair to know about (and enforce) the alignment
specified by PointerLikeTypeTraits.  This should allow things 
like PointerIntPair<PointerIntPair<void*, 1,bool>, 1, bool> 
because the inner one knows that 2 low bits are free.

llvm-svn: 67979
2009-03-29 04:32:37 +00:00
Chris Lattner
a78775615b rename PointerLikeTypeInto to PointerLikeTypeTraits, add trait for
# low bits free, and move to its own header.

llvm-svn: 67973
2009-03-29 00:39:30 +00:00
Chris Lattner
c512533ea0 teach SmallPtrSet that PointerIntPair is "basically a pointer".
llvm-svn: 67970
2009-03-29 00:18:42 +00:00
Duncan Sands
ecfbe4521c Get this building with gcc-4.4.
llvm-svn: 62322
2009-01-16 15:54:57 +00:00
Misha Brukman
da77da48f3 Removed trailing whitespace.
llvm-svn: 62000
2009-01-09 19:25:42 +00:00
Dan Gohman
c0280e8867 Move the conversion to intptr_t to a separate statement. This
avoids GCC's warning even on 64-bit hosts.

llvm-svn: 60706
2008-12-08 17:41:24 +00:00
Dan Gohman
42bd5cffc9 Use intptr_t instead of unsigned here, which is more appropriate
in a really obscure way, but more importantly has the side effect
of avoiding a GCC warning in the case that IntType is bool.

llvm-svn: 60677
2008-12-07 21:28:00 +00:00
Chris Lattner
ee7fbed62d add the rest of the comparison routines.
llvm-svn: 60303
2008-11-30 19:10:41 +00:00
Torok Edwin
7f54c665a2 protect against negative values that would exceed allowed bit width
llvm-svn: 60239
2008-11-29 08:52:45 +00:00
Chris Lattner
ce03bccd7e apparently GCC doesn't believe that I understand C
precedence rules.  Pacify it.

llvm-svn: 60237
2008-11-29 08:36:39 +00:00
Duncan Sands
845f6467ba Typo fix.
llvm-svn: 60236
2008-11-29 08:03:35 +00:00
Chris Lattner
7ae87447ed Fix sentinels to use correctly 'aligned' pointers.
llvm-svn: 60229
2008-11-29 01:36:16 +00:00
Chris Lattner
070df849e9 Fix spello, add DenseMapInfo specialization for PointerIntPair.
llvm-svn: 60228
2008-11-29 01:18:05 +00:00
Chris Lattner
b41c45dbdf fix comment typo
llvm-svn: 60227
2008-11-28 23:57:26 +00:00
Chris Lattner
507e71fce3 fix a bug.
llvm-svn: 60225
2008-11-28 23:36:15 +00:00
Chris Lattner
d8b755ed95 add a generic "bitmangled pointer" class, which allows a parameterized
pointer and integer type to be used.

llvm-svn: 60224
2008-11-28 23:31:44 +00:00