aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-11-13 06:54:20 +0000
committerChris Lattner <sabre@nondot.org>2002-11-13 06:54:20 +0000
commit12ae297cbdc4b456923b6e8aa60d2a6e42f6dc3f (patch)
treef504ef4befe5cf4dd87e11978c3b44cc7eaf9d19 /lib/Transforms
parent64c8d3cfb7236cda0eceb165421866b12bf58cb3 (diff)
downloadexternal_llvm-12ae297cbdc4b456923b6e8aa60d2a6e42f6dc3f.zip
external_llvm-12ae297cbdc4b456923b6e8aa60d2a6e42f6dc3f.tar.gz
external_llvm-12ae297cbdc4b456923b6e8aa60d2a6e42f6dc3f.tar.bz2
Fix bug: 2002-11-13-PointerFunction.ll
This should fix codegen on vortex to work much better git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/ExprTypeConvert.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp
index 860b950..85f9bb0 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<Function>(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<PointerType>(I->getOperand(0)->getType());
+ const FunctionType *FT = cast<FunctionType>(PT->getElementType());
+ std::vector<const Type *> 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;
}
@@ -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<Function>(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<PointerType>(I->getOperand(0)->getType());
+ const FunctionType *FT = cast<FunctionType>(PT->getElementType());
+ std::vector<const Type *> 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<Value*>(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;