[llvm-commits] [dragonegg] r94959 - in /dragonegg/trunk: llvm-convert.cpp llvm-internal.h
Duncan Sands
baldrick at free.fr
Sun Jan 31 05:37:19 PST 2010
Author: baldrick
Date: Sun Jan 31 07:37:17 2010
New Revision: 94959
URL: http://llvm.org/viewvc/llvm-project?rev=94959&view=rev
Log:
Introduce a method UselesslyTypeConvert for performing useless type conversions
(this is a GCC concept) and make use of it. While there, fix EmitRegister which
might have been emitting code outside the entry block (I think OBJ_TYPE_REF won't
change the type, so no type conversion should be needed).
Modified:
dragonegg/trunk/llvm-convert.cpp
dragonegg/trunk/llvm-internal.h
Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=94959&r1=94958&r2=94959&view=diff
==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Sun Jan 31 07:37:17 2010
@@ -5614,8 +5614,8 @@
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 = Builder.CreateBitCast(LV.Ptr,
- ConvertType(TREE_TYPE(exp))->getPointerTo());
+ LV.Ptr = UselesslyTypeConvert(LV.Ptr,
+ ConvertType(TREE_TYPE(exp))->getPointerTo());
return LV;
}
@@ -5847,13 +5847,9 @@
/// EmitRegister - Convert the specified gimple register or local constant of
/// register type to an LLVM value. Only creates code in the entry block.
Value *TreeToLLVM::EmitRegister(tree reg) {
- tree original_type = TREE_TYPE(reg);
while (TREE_CODE(reg) == OBJ_TYPE_REF) reg = OBJ_TYPE_REF_EXPR(reg);
- Value *V = (TREE_CODE(reg) == SSA_NAME) ?
+ return (TREE_CODE(reg) == SSA_NAME) ?
EmitReg_SSA_NAME(reg) : EmitMinInvariant(reg);
- // May need a useless type conversion (useless_type_conversion_p) to the
- // original type.
- return Builder.CreateBitCast(V, GetRegType(original_type));
}
/// EmitReg_SSA_NAME - Return the defining value of the given SSA_NAME.
@@ -6015,7 +6011,7 @@
/// The result is an i1 boolean.
Value *TreeToLLVM::EmitCompare(tree lhs, tree rhs, tree_code code) {
Value *LHS = EmitRegister(lhs);
- Value *RHS = Builder.CreateBitCast(EmitRegister(rhs), LHS->getType());
+ Value *RHS = UselesslyTypeConvert(EmitRegister(rhs), LHS->getType());
// Compute the LLVM opcodes corresponding to the GCC comparison.
CmpInst::Predicate UIPred = CmpInst::BAD_ICMP_PREDICATE;
@@ -6128,8 +6124,8 @@
(isa<VectorType>(Ty) &&
cast<VectorType>(Ty)->getElementType()->isFloatingPoint()))) {
Ty = getSuitableBitCastIntType(Ty);
- LHS = Builder.CreateBitCast(LHS, Ty);
- RHS = Builder.CreateBitCast(RHS, Ty);
+ LHS = UselesslyTypeConvert(LHS, Ty);
+ RHS = UselesslyTypeConvert(RHS, Ty);
}
Value *V;
@@ -6143,9 +6139,8 @@
V = Builder.CreateNSWMul(LHS, RHS);
else
V = Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS, RHS);
- if (ResTy != Ty)
- V = Builder.CreateBitCast(V, ResTy);
- return V;
+
+ return UselesslyTypeConvert(V, ResTy);
}
Value *TreeToLLVM::EmitReg_MinMaxExpr(tree type, tree op0, tree op1,
@@ -6390,7 +6385,7 @@
Builder.CreateInBoundsGEP(Ptr, Idx) : Builder.CreateGEP(Ptr, Idx);
// The result may be of a different pointer type.
- return Builder.CreateBitCast(GEP, GetRegType(type));
+ return UselesslyTypeConvert(GEP, GetRegType(type));
}
Value *TreeToLLVM::EmitReg_ROUND_DIV_EXPR(tree type, tree op0, tree op1) {
@@ -7345,7 +7340,7 @@
/// 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 = Builder.CreateBitCast(RHS, GetRegType(TREE_TYPE(lhs)));
+ RHS = UselesslyTypeConvert(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) {
Modified: dragonegg/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-internal.h?rev=94959&r1=94958&r2=94959&view=diff
==============================================================================
--- dragonegg/trunk/llvm-internal.h (original)
+++ dragonegg/trunk/llvm-internal.h Sun Jan 31 07:37:17 2010
@@ -592,6 +592,18 @@
/// determine the LLVM type to return.
const Type *GetRegType(tree_node *type);
+ /// 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) {
+ return Builder.CreateBitCast(V, Ty);
+ }
+
/// EmitRegister - Convert the specified gimple register or local constant of
/// register type to an LLVM value. Only creates code in the entry block.
Value *EmitRegister(tree_node *reg);
More information about the llvm-commits
mailing list