[llvm-commits] [dragonegg] r155192 - in /dragonegg/trunk: include/dragonegg/Internals.h src/Convert.cpp test/compilator/local/c/ test/compilator/local/c/2012-04-20-PointerBIT_AND_EXPR.c

Duncan Sands baldrick at free.fr
Fri Apr 20 02:07:50 PDT 2012


Author: baldrick
Date: Fri Apr 20 04:07:50 2012
New Revision: 155192

URL: http://llvm.org/viewvc/llvm-project?rev=155192&view=rev
Log:
In gcc-4.7 BIT_AND_EXPR can work on pointer types.

Added:
    dragonegg/trunk/test/compilator/local/c/
    dragonegg/trunk/test/compilator/local/c/2012-04-20-PointerBIT_AND_EXPR.c
Modified:
    dragonegg/trunk/include/dragonegg/Internals.h
    dragonegg/trunk/src/Convert.cpp

Modified: dragonegg/trunk/include/dragonegg/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Internals.h?rev=155192&r1=155191&r2=155192&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Internals.h (original)
+++ dragonegg/trunk/include/dragonegg/Internals.h Fri Apr 20 04:07:50 2012
@@ -328,15 +328,13 @@
   /// of the types involved. This is an inferred cast.
   Value *CastToAnyType (Value *V, bool VSigned, Type *Ty, bool TySigned);
 
-  /// CastToUIntType - Cast the specified value to the specified type assuming
-  /// that V's type and Ty are integral types. This arbitrates between BitCast,
-  /// Trunc and ZExt.
-  Value *CastToUIntType(Value *V, Type *Ty);
-
-  /// CastToSIntType - Cast the specified value to the specified type assuming
-  /// that V's type and Ty are integral types. This arbitrates between BitCast,
-  /// Trunc and SExt.
-  Value *CastToSIntType(Value *V, Type *Ty);
+  /// CastFromSameSizeInteger - Cast an integer value to the given scalar type
+  /// of the same bitwidth.
+  Value *CastFromSameSizeInteger(Value *V, Type *Ty);
+
+  /// CastToSameSizeInteger - Cast the specified scalar value to an integer of
+  /// the same bit width.
+  Value *CastToSameSizeInteger(Value *V);
 
   /// CastToFPType - Cast the specified value to the specified type assuming
   /// that V's type and Ty are floating point types. This arbitrates between

Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=155192&r1=155191&r2=155192&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Fri Apr 20 04:07:50 2012
@@ -1782,7 +1782,42 @@
   return Builder.CreateCast(opc, V, DestTy);
 }
 
-/// CastToFPType - Cast the specified value to the specified type assuming
+/// CastFromSameSizeInteger - Cast an integer value to the given scalar type
+/// of the same bitwidth.
+Value *TreeToLLVM::CastFromSameSizeInteger(Value *V, Type *Ty) {
+  assert(V->getType()->isIntegerTy() && "Expected an integer type!");
+  if (Ty->isIntegerTy()) {
+    // Already an integer - nothing to do.
+    assert(V->getType() == Ty && "Integer type not same size!");
+    return V;
+  }
+  if (Ty->isPointerTy()) {
+    // A pointer - use inttoptr.
+    assert(V->getType()->getPrimitiveSizeInBits() ==
+           TD.getPointerSizeInBits() && "Pointer type not same size!");
+    return Builder.CreateIntToPtr(V, Ty);
+  }
+  // Everything else.
+  assert(Ty->isFloatingPointTy() && "Not a scalar type?");
+  return Builder.CreateBitCast(V, Ty); // Will catch any size mismatch.
+}
+
+/// CastToSameSizeInteger - Cast the specified scalar value to an integer of
+/// the same bit width.
+Value *TreeToLLVM::CastToSameSizeInteger(Value *V) {
+  Type *Ty = V->getType();
+  if (Ty->isIntegerTy())
+    // Already an integer - nothing to do.
+    return V;
+  if (Ty->isPointerTy())
+    // A pointer - use a same size ptrtoint.
+    return Builder.CreatePtrToInt(V, TD.getIntPtrType(Context));
+  // Everything else.
+  assert(Ty->isFloatingPointTy() && "Not a scalar type?");
+  unsigned BitWidth = Ty->getPrimitiveSizeInBits();
+  return Builder.CreateBitCast(V, IntegerType::get(Context, BitWidth));
+}
+
 /// that the value and type are floating point.
 Value *TreeToLLVM::CastToFPType(Value *V, Type* Ty) {
   unsigned SrcBits = V->getType()->getPrimitiveSizeInBits();
@@ -7117,15 +7152,24 @@
 }
 
 Value *TreeToLLVM::EmitReg_BIT_AND_EXPR(tree op0, tree op1) {
-  return Builder.CreateAnd(EmitRegister(op0), EmitRegister(op1));
+  Value *LHS = CastToSameSizeInteger(EmitRegister(op0));
+  Value *RHS = CastToSameSizeInteger(EmitRegister(op1));
+  Value *Res = Builder.CreateAnd(LHS, RHS);
+  return CastFromSameSizeInteger(Res, getRegType(TREE_TYPE(op0)));
 }
 
 Value *TreeToLLVM::EmitReg_BIT_IOR_EXPR(tree op0, tree op1) {
-  return Builder.CreateOr(EmitRegister(op0), EmitRegister(op1));
+  Value *LHS = CastToSameSizeInteger(EmitRegister(op0));
+  Value *RHS = CastToSameSizeInteger(EmitRegister(op1));
+  Value *Res = Builder.CreateOr(LHS, RHS);
+  return CastFromSameSizeInteger(Res, getRegType(TREE_TYPE(op0)));
 }
 
 Value *TreeToLLVM::EmitReg_BIT_XOR_EXPR(tree op0, tree op1) {
-  return Builder.CreateXor(EmitRegister(op0), EmitRegister(op1));
+  Value *LHS = CastToSameSizeInteger(EmitRegister(op0));
+  Value *RHS = CastToSameSizeInteger(EmitRegister(op1));
+  Value *Res = Builder.CreateXor(LHS, RHS);
+  return CastFromSameSizeInteger(Res, getRegType(TREE_TYPE(op0)));
 }
 
 Value *TreeToLLVM::EmitReg_COMPLEX_EXPR(tree op0, tree op1) {

Added: dragonegg/trunk/test/compilator/local/c/2012-04-20-PointerBIT_AND_EXPR.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/compilator/local/c/2012-04-20-PointerBIT_AND_EXPR.c?rev=155192&view=auto
==============================================================================
--- dragonegg/trunk/test/compilator/local/c/2012-04-20-PointerBIT_AND_EXPR.c (added)
+++ dragonegg/trunk/test/compilator/local/c/2012-04-20-PointerBIT_AND_EXPR.c Fri Apr 20 04:07:50 2012
@@ -0,0 +1,8 @@
+testvacld (int n, ...)
+{
+  __builtin_va_list ap;
+  __builtin_va_start (ap, n);
+  _Complex long double t =
+    __builtin_va_arg (ap, _Complex long double);
+  __builtin_va_end (ap);
+}





More information about the llvm-commits mailing list