[llvm-commits] [dragonegg] r131288 - in /dragonegg/trunk: include/dragonegg/Internals.h src/Convert.cpp

Duncan Sands baldrick at free.fr
Fri May 13 00:57:05 PDT 2011


Author: baldrick
Date: Fri May 13 02:57:05 2011
New Revision: 131288

URL: http://llvm.org/viewvc/llvm-project?rev=131288&view=rev
Log:
Rename UselesslyTypeConvert to TriviallyTypeConvert, and tighten it up:
it should do nothing except for pointer types, because except for pointer
types equivalent GCC middle-end scalar types map to the same LLVM type.
Stop using this method when we know we are dealing with pointer types
(just bitcast directly in that case).

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=131288&r1=131287&r2=131288&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Internals.h (original)
+++ dragonegg/trunk/include/dragonegg/Internals.h Fri May 13 02:57:05 2011
@@ -654,15 +654,16 @@
 
   //===---------- EmitReg* - Convert register expression to LLVM ----------===//
 
-  /// UselesslyTypeConvert - The useless_type_conversion_p predicate implicitly
-  /// defines the GCC middle-end type system.  For scalar GCC types inner_type
-  /// and outer_type, if 'useless_type_conversion_p(outer_type, inner_type)' is
-  /// true then the corresponding LLVM inner and outer types (see getRegType)
-  /// are equal except possibly if they are both pointer types (casts to 'void*'
-  /// are considered useless for example) or types derived from pointer types
-  /// (vector types with pointer element type are the only possibility here).
-  /// This method converts LLVM values of the inner type to the outer type.
-  Value *UselesslyTypeConvert(Value *V, const Type *Ty) {
+  /// TriviallyTypeConvert - Convert the given value to the given type, assuming
+  /// that the original and target types are LLVM register types that correspond
+  /// to GCC scalar types t1 and t2 satisfying useless_type_conversion_p(t1, t2)
+  /// or useless_type_conversion_p(t2, t1).
+  Value *TriviallyTypeConvert(Value *V, const Type *Ty) {
+    // If useless_type_conversion_p(t1, t2) holds then the corresponding LLVM
+    // register types are either equal or are both pointer types.
+    if (V->getType() == Ty)
+      return V;
+    assert(V->getType()->isPointerTy() && Ty->isPointerTy() && "Not trivial!");
     return Builder.CreateBitCast(V, Ty);
   }
 

Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=131288&r1=131287&r2=131288&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Fri May 13 02:57:05 2011
@@ -5754,10 +5754,10 @@
 LValue TreeToLLVM::EmitLV_INDIRECT_REF(tree exp) {
   // The lvalue is just the address.
   LValue LV = LValue(EmitRegister(TREE_OPERAND(exp, 0)), expr_align(exp) / 8);
-  // May need a useless type conversion (useless_type_conversion_p), for example
-  // when INDIRECT_REF is applied to a void*, resulting in a non-void type.
-  LV.Ptr = UselesslyTypeConvert(LV.Ptr,
-                                ConvertType(TREE_TYPE(exp))->getPointerTo());
+  // May need to change pointer type, for example when INDIRECT_REF is applied
+  // to a void*, resulting in a non-void type.
+  LV.Ptr = Builder.CreateBitCast(LV.Ptr,
+                                 ConvertType(TREE_TYPE(exp))->getPointerTo());
   return LV;
 }
 
@@ -5770,10 +5770,10 @@
   if (!Alignment) Alignment = 8;
   assert(!(Alignment & 7) && "Alignment not in octets!");
   LValue LV = LValue(EmitRegister(TREE_OPERAND(exp, 0)), Alignment / 8);
-  // May need a useless type conversion (useless_type_conversion_p), for example
-  // when INDIRECT_REF is applied to a void*, resulting in a non-void type.
-  LV.Ptr = UselesslyTypeConvert(LV.Ptr,
-                                ConvertType(TREE_TYPE(exp))->getPointerTo());
+  // May need to change pointer type, for example when MISALIGNED_INDIRECT_REF
+  // is applied to a void*, resulting in a non-void type.
+  LV.Ptr = Builder.CreateBitCast(LV.Ptr,
+                                 ConvertType(TREE_TYPE(exp))->getPointerTo());
   return LV;
 }
 
@@ -5854,8 +5854,8 @@
   }
 
   // The result can be of a different pointer type even if we didn't advance it.
-  Ref.Ptr = UselesslyTypeConvert(Ref.Ptr,
-                                 ConvertType(TREE_TYPE(exp))->getPointerTo());
+  Ref.Ptr = Builder.CreateBitCast(Ref.Ptr,
+                                  ConvertType(TREE_TYPE(exp))->getPointerTo());
 
   return Ref;
 }
@@ -6361,7 +6361,7 @@
 /// The result is an i1 boolean.
 Value *TreeToLLVM::EmitCompare(tree lhs, tree rhs, unsigned code) {
   Value *LHS = EmitRegister(lhs);
-  Value *RHS = UselesslyTypeConvert(EmitRegister(rhs), LHS->getType());
+  Value *RHS = TriviallyTypeConvert(EmitRegister(rhs), LHS->getType());
 
   // Compute the LLVM opcodes corresponding to the GCC comparison.
   CmpInst::Predicate UIPred = CmpInst::BAD_ICMP_PREDICATE;
@@ -6446,8 +6446,8 @@
                                       unsigned UIPred, unsigned SIPred,
                                       unsigned FPPred, bool isMax) {
   const Type *Ty = getRegType(type);
-  Value *LHS = UselesslyTypeConvert(EmitRegister(op0), Ty);
-  Value *RHS = UselesslyTypeConvert(EmitRegister(op1), Ty);
+  Value *LHS = TriviallyTypeConvert(EmitRegister(op0), Ty);
+  Value *RHS = TriviallyTypeConvert(EmitRegister(op1), Ty);
 
   Value *Compare;
   if (FLOAT_TYPE_P(type))
@@ -6763,7 +6763,7 @@
     Builder.CreateInBoundsGEP(Ptr, Idx) : Builder.CreateGEP(Ptr, Idx);
 
   // The result may be of a different pointer type.
-  return UselesslyTypeConvert(GEP, getRegType(type));
+  return Builder.CreateBitCast(GEP, getRegType(type));
 }
 
 Value *TreeToLLVM::EmitReg_RDIV_EXPR(tree op0, tree op1) {
@@ -8128,8 +8128,8 @@
 
 /// WriteScalarToLHS - Store RHS, a non-aggregate value, into the given LHS.
 void TreeToLLVM::WriteScalarToLHS(tree lhs, Value *RHS) {
-  // Perform a useless type conversion (useless_type_conversion_p).
-  RHS = UselesslyTypeConvert(RHS, getRegType(TREE_TYPE(lhs)));
+  // May need a useless type conversion (useless_type_conversion_p).
+  RHS = TriviallyTypeConvert(RHS, getRegType(TREE_TYPE(lhs)));
 
   // If this is the definition of an ssa name, record it in the SSANames map.
   if (TREE_CODE(lhs) == SSA_NAME) {





More information about the llvm-commits mailing list