summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2015-04-21 23:26:57 +0000
committerDavid Blaikie <dblaikie@gmail.com>2015-04-21 23:26:57 +0000
commit506993636e7300bedd7555ebd4c820b10ffd9017 (patch)
treeb21b9ca1bf999f79d01ac2333bc5fc2c9cc81f67 /llvm/lib
parentb8854d01a6ef9524448b5a34771383cf4d969870 (diff)
downloadbcm5719-llvm-506993636e7300bedd7555ebd4c820b10ffd9017.tar.gz
bcm5719-llvm-506993636e7300bedd7555ebd4c820b10ffd9017.zip
[opaque pointer type] Avoid using PointerType::getElementType for a few cases of CallInst
Calls to llvm::Value::mutateType are becoming extra-sensitive now that instructions have extra type information that will not be derived from operands or result type (alloca, gep, load, call/invoke, etc... ). The special-handling for mutateType will get more complicated as this work continues - it might be worth making mutateType virtual & pushing the complexity down into the classes that need special handling. But with only two significant uses of mutateType (vectorization and linking) this seems OK for now. Totally open to ideas/suggestions/improvements, of course. With this, and a bunch of exceptions, we can roundtrip an indirect call site through bitcode and IR. (a direct call site is actually trickier... I haven't figured out how to deal with the IR deserializer's lazy construction of Function/GlobalVariable decl's based on the type of the entity which means looking through the "pointer to T" type referring to the global) llvm-svn: 235458
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp2
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp13
-rw-r--r--llvm/lib/IR/Instructions.cpp37
-rw-r--r--llvm/lib/IR/Verifier.cpp6
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp13
-rw-r--r--llvm/lib/Transforms/Vectorize/BBVectorize.cpp12
6 files changed, 51 insertions, 32 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index be098c1b128..2e8008b96e7 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -5224,7 +5224,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
// Finish off the Attribute and check them
AttributeSet PAL = AttributeSet::get(Context, Attrs);
- CallInst *CI = CallInst::Create(Callee, Args);
+ CallInst *CI = CallInst::Create(Ty, Callee, Args);
CI->setTailCallKind(TCK);
CI->setCallingConv(CC);
CI->setAttributes(PAL);
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index bc78a71efad..f3446b73f93 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4184,12 +4184,11 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
PointerType *OpTy = dyn_cast<PointerType>(Callee->getType());
if (!OpTy)
return Error("Callee is not a pointer type");
- FunctionType *PFTy = dyn_cast<FunctionType>(OpTy->getElementType());
- if (!PFTy)
- return Error("Callee is not of pointer to function type");
- if (!FTy)
- FTy = PFTy;
- if (PFTy != FTy)
+ if (!FTy) {
+ FTy = dyn_cast<FunctionType>(OpTy->getElementType());
+ if (!FTy)
+ return Error("Callee is not of pointer to function type");
+ } else if (OpTy->getElementType() != FTy)
return Error("Explicit call type does not match pointee type of "
"callee operand");
if (Record.size() < FTy->getNumParams() + OpNum)
@@ -4220,7 +4219,7 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
}
}
- I = CallInst::Create(Callee, Args);
+ I = CallInst::Create(FTy, Callee, Args);
InstructionList.push_back(I);
cast<CallInst>(I)->setCallingConv(
static_cast<CallingConv::ID>((~(1U << 14) & CCInfo) >> 1));
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index b2898429239..aa878ea436e 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -263,14 +263,13 @@ void LandingPadInst::addClause(Constant *Val) {
CallInst::~CallInst() {
}
-void CallInst::init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr) {
+void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
+ const Twine &NameStr) {
+ this->FTy = FTy;
assert(NumOperands == Args.size() + 1 && "NumOperands not set up?");
Op<-1>() = Func;
#ifndef NDEBUG
- FunctionType *FTy =
- cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
-
assert((Args.size() == FTy->getNumParams() ||
(FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
"Calling a function with bad signature!");
@@ -286,15 +285,12 @@ void CallInst::init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr) {
}
void CallInst::init(Value *Func, const Twine &NameStr) {
+ FTy =
+ cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
assert(NumOperands == 1 && "NumOperands not set up?");
Op<-1>() = Func;
-#ifndef NDEBUG
- FunctionType *FTy =
- cast<FunctionType>(cast<PointerType>(Func->getType())->getElementType());
-
assert(FTy->getNumParams() == 0 && "Calling a function with bad signature");
-#endif
setName(NameStr);
}
@@ -320,10 +316,10 @@ CallInst::CallInst(Value *Func, const Twine &Name,
}
CallInst::CallInst(const CallInst &CI)
- : Instruction(CI.getType(), Instruction::Call,
- OperandTraits<CallInst>::op_end(this) - CI.getNumOperands(),
- CI.getNumOperands()) {
- setAttributes(CI.getAttributes());
+ : Instruction(CI.getType(), Instruction::Call,
+ OperandTraits<CallInst>::op_end(this) - CI.getNumOperands(),
+ CI.getNumOperands()),
+ AttributeList(CI.AttributeList), FTy(CI.FTy) {
setTailCallKind(CI.getTailCallKind());
setCallingConv(CI.getCallingConv());
@@ -543,15 +539,14 @@ Instruction* CallInst::CreateFree(Value* Source, BasicBlock *InsertAtEnd) {
void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, const Twine &NameStr) {
+ FTy = cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
+
assert(NumOperands == 3 + Args.size() && "NumOperands not set up?");
Op<-3>() = Fn;
Op<-2>() = IfNormal;
Op<-1>() = IfException;
#ifndef NDEBUG
- FunctionType *FTy =
- cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
-
assert(((Args.size() == FTy->getNumParams()) ||
(FTy->isVarArg() && Args.size() > FTy->getNumParams())) &&
"Invoking a function with bad signature");
@@ -567,11 +562,11 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
}
InvokeInst::InvokeInst(const InvokeInst &II)
- : TerminatorInst(II.getType(), Instruction::Invoke,
- OperandTraits<InvokeInst>::op_end(this)
- - II.getNumOperands(),
- II.getNumOperands()) {
- setAttributes(II.getAttributes());
+ : TerminatorInst(II.getType(), Instruction::Invoke,
+ OperandTraits<InvokeInst>::op_end(this) -
+ II.getNumOperands(),
+ II.getNumOperands()),
+ AttributeList(II.AttributeList), FTy(II.FTy) {
setCallingConv(II.getCallingConv());
std::copy(II.op_begin(), II.op_end(), op_begin());
SubclassOptionalData = II.SubclassOptionalData;
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e14f1036912..7001c556d20 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2120,7 +2120,11 @@ void Verifier::VerifyCallSite(CallSite CS) {
Assert(FPTy->getElementType()->isFunctionTy(),
"Called function is not pointer to function type!", I);
- FunctionType *FTy = cast<FunctionType>(FPTy->getElementType());
+
+ Assert(FPTy->getElementType() == CS.getFunctionType(),
+ "Called function is not the same type as the call!", I);
+
+ FunctionType *FTy = CS.getFunctionType();
// Verify that the correct number of arguments are being passed
if (FTy->isVarArg())
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 54c76887234..a70d6d769b7 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/ValueMapper.h"
+#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InlineAsm.h"
@@ -384,6 +385,16 @@ void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap,
}
// If the instruction's type is being remapped, do so now.
- if (TypeMapper)
+ if (auto CS = CallSite(I)) {
+ SmallVector<Type *, 3> Tys;
+ FunctionType *Old = CS.getFunctionType();
+ unsigned NumOld = Old->getNumParams();
+ assert(NumOld <= CS.arg_size());
+ for (unsigned i = 0; i != NumOld; ++i)
+ Tys.push_back(CS.getArgument(i)->getType());
+ CS.mutateFunctionType(FunctionType::get(
+ TypeMapper ? TypeMapper->remapType(I->getType()) : I->getType(), Tys,
+ Old->isVarArg()));
+ } else if (TypeMapper)
I->mutateType(TypeMapper->remapType(I->getType()));
}
diff --git a/llvm/lib/Transforms/Vectorize/BBVectorize.cpp b/llvm/lib/Transforms/Vectorize/BBVectorize.cpp
index 29fb01f1b2e..6f0180e7db0 100644
--- a/llvm/lib/Transforms/Vectorize/BBVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/BBVectorize.cpp
@@ -3103,7 +3103,17 @@ namespace {
else if (H->hasName())
K->takeName(H);
- if (!isa<StoreInst>(K))
+ if (auto CS = CallSite(K)) {
+ SmallVector<Type *, 3> Tys;
+ FunctionType *Old = CS.getFunctionType();
+ unsigned NumOld = Old->getNumParams();
+ assert(NumOld <= ReplacedOperands.size());
+ for (unsigned i = 0; i != NumOld; ++i)
+ Tys.push_back(ReplacedOperands[i]->getType());
+ CS.mutateFunctionType(
+ FunctionType::get(getVecTypeForPair(L->getType(), H->getType()),
+ Tys, Old->isVarArg()));
+ } else if (!isa<StoreInst>(K))
K->mutateType(getVecTypeForPair(L->getType(), H->getType()));
unsigned KnownIDs[] = {
OpenPOWER on IntegriCloud