X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=lib%2FTransforms%2FExprTypeConvert.cpp;h=85f9bb0714cf09b8d657fbe17f80c73bcf329fb6;hb=b91b657e026e86082b665cc875c2881ed075b68d;hp=aa183d24ebf5facf5467a8df2a2ee1d421677f66;hpb=38dc4f06af12a16efb52ee09d63182cd6a1775c6;p=oota-llvm.git diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp index aa183d24ebf..85f9bb0714c 100644 --- a/lib/Transforms/ExprTypeConvert.cpp +++ b/lib/Transforms/ExprTypeConvert.cpp @@ -285,6 +285,24 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty, return false; // No match, maybe next time. } + case Instruction::Call: { + if (isa(I->getOperand(0))) + return false; // Don't even try to change direct calls. + + // If this is a function pointer, we can convert the return type if we can + // convert the source function pointer. + // + const PointerType *PT = cast(I->getOperand(0)->getType()); + const FunctionType *FT = cast(PT->getElementType()); + std::vector ArgTys(FT->getParamTypes().begin(), + FT->getParamTypes().end()); + const FunctionType *NewTy = + FunctionType::get(Ty, ArgTys, FT->isVarArg()); + if (!ExpressionConvertableToType(I->getOperand(0), + PointerType::get(NewTy), CTMap)) + return false; + break; + } default: return false; } @@ -320,7 +338,7 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) { Instruction *I = dyn_cast(V); if (I == 0) { - Constant *CPV = cast(V)) { + Constant *CPV = cast(V); // Constants are converted by constant folding the cast that is required. // We assume here that all casts are implemented for constant prop. Value *Result = ConstantFoldCastInstruction(CPV, Ty); @@ -477,9 +495,30 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) { assert(Res && "Didn't find match!"); - break; // No match, maybe next time. + break; } + case Instruction::Call: { + assert(!isa(I->getOperand(0))); + + // If this is a function pointer, we can convert the return type if we can + // convert the source function pointer. + // + const PointerType *PT = cast(I->getOperand(0)->getType()); + const FunctionType *FT = cast(PT->getElementType()); + std::vector ArgTys(FT->getParamTypes().begin(), + FT->getParamTypes().end()); + const FunctionType *NewTy = + FunctionType::get(Ty, ArgTys, FT->isVarArg()); + const PointerType *NewPTy = PointerType::get(NewTy); + + Res = new CallInst(Constant::getNullValue(NewPTy), + std::vector(I->op_begin()+1, I->op_end()), + Name); + VMC.ExprMap[I] = Res; + Res->setOperand(0, ConvertExpressionToType(I->getOperand(0), NewPTy, VMC)); + break; + } default: assert(0 && "Expression convertable, but don't know how to convert?"); return 0;