Revert IRBuilder CC propagation. Fix SimplifyLibCalls instead.
llvm-svn: 73715
This commit is contained in:
parent
d830eb8365
commit
6ee547bb1b
|
@ -154,10 +154,8 @@ public:
|
||||||
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
|
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
|
||||||
BasicBlock *UnwindDest, InputIterator ArgBegin,
|
BasicBlock *UnwindDest, InputIterator ArgBegin,
|
||||||
InputIterator ArgEnd, const char *Name = "") {
|
InputIterator ArgEnd, const char *Name = "") {
|
||||||
return Insert(TransferAttributes(InvokeInst::Create(Callee,
|
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest,
|
||||||
NormalDest, UnwindDest,
|
ArgBegin, ArgEnd), Name);
|
||||||
ArgBegin, ArgEnd),
|
|
||||||
Callee), Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnwindInst *CreateUnwind() {
|
UnwindInst *CreateUnwind() {
|
||||||
|
@ -589,61 +587,32 @@ public:
|
||||||
return Insert(PHINode::Create(Ty), Name);
|
return Insert(PHINode::Create(Ty), Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallInst *TransferAttributes(CallInst *CI, const Value* Callee) const {
|
|
||||||
if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(Callee))
|
|
||||||
Callee = GA->getAliasedGlobal();
|
|
||||||
|
|
||||||
if (const Function *F = dyn_cast<Function>(Callee)) {
|
|
||||||
CI->setCallingConv(F->getCallingConv());
|
|
||||||
CI->setAttributes(F->getAttributes());
|
|
||||||
}
|
|
||||||
|
|
||||||
return CI;
|
|
||||||
}
|
|
||||||
|
|
||||||
InvokeInst *TransferAttributes(InvokeInst *II, const Value* Callee) const {
|
|
||||||
if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(Callee))
|
|
||||||
Callee = GA->getAliasedGlobal();
|
|
||||||
|
|
||||||
if (const Function *F = dyn_cast<Function>(Callee)) {
|
|
||||||
II->setCallingConv(F->getCallingConv());
|
|
||||||
II->setAttributes(F->getAttributes());
|
|
||||||
}
|
|
||||||
|
|
||||||
return II;
|
|
||||||
}
|
|
||||||
|
|
||||||
CallInst *CreateCall(Value *Callee, const char *Name = "") {
|
CallInst *CreateCall(Value *Callee, const char *Name = "") {
|
||||||
return Insert(TransferAttributes(CallInst::Create(Callee), Callee), Name);
|
return Insert(CallInst::Create(Callee), Name);
|
||||||
}
|
}
|
||||||
CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") {
|
CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") {
|
||||||
return Insert(TransferAttributes(CallInst::Create(Callee, Arg),
|
return Insert(CallInst::Create(Callee, Arg), Name);
|
||||||
Callee), Name);
|
|
||||||
}
|
}
|
||||||
CallInst *CreateCall2(Value *Callee, Value *Arg1, Value *Arg2,
|
CallInst *CreateCall2(Value *Callee, Value *Arg1, Value *Arg2,
|
||||||
const char *Name = "") {
|
const char *Name = "") {
|
||||||
Value *Args[] = { Arg1, Arg2 };
|
Value *Args[] = { Arg1, Arg2 };
|
||||||
return Insert(TransferAttributes(CallInst::Create(Callee, Args, Args+2),
|
return Insert(CallInst::Create(Callee, Args, Args+2), Name);
|
||||||
Callee), Name);
|
|
||||||
}
|
}
|
||||||
CallInst *CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
|
CallInst *CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
|
||||||
const char *Name = "") {
|
const char *Name = "") {
|
||||||
Value *Args[] = { Arg1, Arg2, Arg3 };
|
Value *Args[] = { Arg1, Arg2, Arg3 };
|
||||||
return Insert(TransferAttributes(CallInst::Create(Callee, Args, Args+3),
|
return Insert(CallInst::Create(Callee, Args, Args+3), Name);
|
||||||
Callee), Name);
|
|
||||||
}
|
}
|
||||||
CallInst *CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
|
CallInst *CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
|
||||||
Value *Arg4, const char *Name = "") {
|
Value *Arg4, const char *Name = "") {
|
||||||
Value *Args[] = { Arg1, Arg2, Arg3, Arg4 };
|
Value *Args[] = { Arg1, Arg2, Arg3, Arg4 };
|
||||||
return Insert(TransferAttributes(CallInst::Create(Callee, Args, Args+4),
|
return Insert(CallInst::Create(Callee, Args, Args+4), Name);
|
||||||
Callee), Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
CallInst *CreateCall(Value *Callee, InputIterator ArgBegin,
|
CallInst *CreateCall(Value *Callee, InputIterator ArgBegin,
|
||||||
InputIterator ArgEnd, const char *Name = "") {
|
InputIterator ArgEnd, const char *Name = "") {
|
||||||
return Insert(TransferAttributes(CallInst::Create(Callee, ArgBegin, ArgEnd),
|
return Insert(CallInst::Create(Callee, ArgBegin, ArgEnd), Name);
|
||||||
Callee), Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *CreateSelect(Value *C, Value *True, Value *False,
|
Value *CreateSelect(Value *C, Value *True, Value *False,
|
||||||
|
|
|
@ -135,7 +135,11 @@ Value *LibCallOptimization::EmitStrLen(Value *Ptr, IRBuilder<> &B) {
|
||||||
TD->getIntPtrType(),
|
TD->getIntPtrType(),
|
||||||
PointerType::getUnqual(Type::Int8Ty),
|
PointerType::getUnqual(Type::Int8Ty),
|
||||||
NULL);
|
NULL);
|
||||||
return B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen");
|
CallInst *CI = B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen");
|
||||||
|
if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(F->getCallingConv());
|
||||||
|
|
||||||
|
return CI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitMemCpy - Emit a call to the memcpy function to the builder. This always
|
/// EmitMemCpy - Emit a call to the memcpy function to the builder. This always
|
||||||
|
@ -164,7 +168,12 @@ Value *LibCallOptimization::EmitMemChr(Value *Ptr, Value *Val,
|
||||||
PointerType::getUnqual(Type::Int8Ty),
|
PointerType::getUnqual(Type::Int8Ty),
|
||||||
Type::Int32Ty, TD->getIntPtrType(),
|
Type::Int32Ty, TD->getIntPtrType(),
|
||||||
NULL);
|
NULL);
|
||||||
return B.CreateCall3(MemChr, CastToCStr(Ptr, B), Val, Len, "memchr");
|
CallInst *CI = B.CreateCall3(MemChr, CastToCStr(Ptr, B), Val, Len, "memchr");
|
||||||
|
|
||||||
|
if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(F->getCallingConv());
|
||||||
|
|
||||||
|
return CI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitMemCmp - Emit a call to the memcmp function.
|
/// EmitMemCmp - Emit a call to the memcmp function.
|
||||||
|
@ -182,8 +191,13 @@ Value *LibCallOptimization::EmitMemCmp(Value *Ptr1, Value *Ptr2,
|
||||||
PointerType::getUnqual(Type::Int8Ty),
|
PointerType::getUnqual(Type::Int8Ty),
|
||||||
PointerType::getUnqual(Type::Int8Ty),
|
PointerType::getUnqual(Type::Int8Ty),
|
||||||
TD->getIntPtrType(), NULL);
|
TD->getIntPtrType(), NULL);
|
||||||
return B.CreateCall3(MemCmp, CastToCStr(Ptr1, B), CastToCStr(Ptr2, B),
|
CallInst *CI = B.CreateCall3(MemCmp, CastToCStr(Ptr1, B), CastToCStr(Ptr2, B),
|
||||||
Len, "memcmp");
|
Len, "memcmp");
|
||||||
|
|
||||||
|
if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(F->getCallingConv());
|
||||||
|
|
||||||
|
return CI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitMemSet - Emit a call to the memset function
|
/// EmitMemSet - Emit a call to the memset function
|
||||||
|
@ -221,16 +235,26 @@ Value *LibCallOptimization::EmitUnaryFloatFnCall(Value *Op, const char *Name,
|
||||||
Module *M = Caller->getParent();
|
Module *M = Caller->getParent();
|
||||||
Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
|
Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
|
||||||
Op->getType(), NULL);
|
Op->getType(), NULL);
|
||||||
return B.CreateCall(Callee, Op, Name);
|
CallInst *CI = B.CreateCall(Callee, Op, Name);
|
||||||
|
|
||||||
|
if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(F->getCallingConv());
|
||||||
|
|
||||||
|
return CI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitPutChar - Emit a call to the putchar function. This assumes that Char
|
/// EmitPutChar - Emit a call to the putchar function. This assumes that Char
|
||||||
/// is an integer.
|
/// is an integer.
|
||||||
void LibCallOptimization::EmitPutChar(Value *Char, IRBuilder<> &B) {
|
void LibCallOptimization::EmitPutChar(Value *Char, IRBuilder<> &B) {
|
||||||
Module *M = Caller->getParent();
|
Module *M = Caller->getParent();
|
||||||
Value *F = M->getOrInsertFunction("putchar", Type::Int32Ty,
|
Value *PutChar = M->getOrInsertFunction("putchar", Type::Int32Ty,
|
||||||
Type::Int32Ty, NULL);
|
Type::Int32Ty, NULL);
|
||||||
B.CreateCall(F, B.CreateIntCast(Char, Type::Int32Ty, "chari"), "putchar");
|
CallInst *CI = B.CreateCall(PutChar,
|
||||||
|
B.CreateIntCast(Char, Type::Int32Ty, "chari"),
|
||||||
|
"putchar");
|
||||||
|
|
||||||
|
if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(F->getCallingConv());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitPutS - Emit a call to the puts function. This assumes that Str is
|
/// EmitPutS - Emit a call to the puts function. This assumes that Str is
|
||||||
|
@ -241,10 +265,14 @@ void LibCallOptimization::EmitPutS(Value *Str, IRBuilder<> &B) {
|
||||||
AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
|
AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture);
|
||||||
AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
|
AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
|
||||||
|
|
||||||
Value *F = M->getOrInsertFunction("puts", AttrListPtr::get(AWI, 2),
|
Value *PutS = M->getOrInsertFunction("puts", AttrListPtr::get(AWI, 2),
|
||||||
Type::Int32Ty,
|
Type::Int32Ty,
|
||||||
PointerType::getUnqual(Type::Int8Ty), NULL);
|
PointerType::getUnqual(Type::Int8Ty),
|
||||||
B.CreateCall(F, CastToCStr(Str, B), "puts");
|
NULL);
|
||||||
|
CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts");
|
||||||
|
if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(F->getCallingConv());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitFPutC - Emit a call to the fputc function. This assumes that Char is
|
/// EmitFPutC - Emit a call to the fputc function. This assumes that Char is
|
||||||
|
@ -258,12 +286,14 @@ void LibCallOptimization::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B) {
|
||||||
if (isa<PointerType>(File->getType()))
|
if (isa<PointerType>(File->getType()))
|
||||||
F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI, 2), Type::Int32Ty,
|
F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI, 2), Type::Int32Ty,
|
||||||
Type::Int32Ty, File->getType(), NULL);
|
Type::Int32Ty, File->getType(), NULL);
|
||||||
|
|
||||||
else
|
else
|
||||||
F = M->getOrInsertFunction("fputc", Type::Int32Ty, Type::Int32Ty,
|
F = M->getOrInsertFunction("fputc", Type::Int32Ty, Type::Int32Ty,
|
||||||
File->getType(), NULL);
|
File->getType(), NULL);
|
||||||
Char = B.CreateIntCast(Char, Type::Int32Ty, "chari");
|
Char = B.CreateIntCast(Char, Type::Int32Ty, "chari");
|
||||||
B.CreateCall2(F, Char, File, "fputc");
|
CallInst *CI = B.CreateCall2(F, Char, File, "fputc");
|
||||||
|
|
||||||
|
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(Fn->getCallingConv());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitFPutS - Emit a call to the puts function. Str is required to be a
|
/// EmitFPutS - Emit a call to the puts function. Str is required to be a
|
||||||
|
@ -283,7 +313,10 @@ void LibCallOptimization::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B) {
|
||||||
F = M->getOrInsertFunction("fputs", Type::Int32Ty,
|
F = M->getOrInsertFunction("fputs", Type::Int32Ty,
|
||||||
PointerType::getUnqual(Type::Int8Ty),
|
PointerType::getUnqual(Type::Int8Ty),
|
||||||
File->getType(), NULL);
|
File->getType(), NULL);
|
||||||
B.CreateCall2(F, CastToCStr(Str, B), File, "fputs");
|
CallInst *CI = B.CreateCall2(F, CastToCStr(Str, B), File, "fputs");
|
||||||
|
|
||||||
|
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(Fn->getCallingConv());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is
|
/// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is
|
||||||
|
@ -307,8 +340,11 @@ void LibCallOptimization::EmitFWrite(Value *Ptr, Value *Size, Value *File,
|
||||||
PointerType::getUnqual(Type::Int8Ty),
|
PointerType::getUnqual(Type::Int8Ty),
|
||||||
TD->getIntPtrType(), TD->getIntPtrType(),
|
TD->getIntPtrType(), TD->getIntPtrType(),
|
||||||
File->getType(), NULL);
|
File->getType(), NULL);
|
||||||
B.CreateCall4(F, CastToCStr(Ptr, B), Size,
|
CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size,
|
||||||
ConstantInt::get(TD->getIntPtrType(), 1), File);
|
ConstantInt::get(TD->getIntPtrType(), 1), File);
|
||||||
|
|
||||||
|
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(Fn->getCallingConv());
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -1056,13 +1092,16 @@ struct VISIBILITY_HIDDEN Exp2Opt : public LibCallOptimization {
|
||||||
Module *M = Caller->getParent();
|
Module *M = Caller->getParent();
|
||||||
Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
|
Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
|
||||||
Op->getType(), Type::Int32Ty,NULL);
|
Op->getType(), Type::Int32Ty,NULL);
|
||||||
return B.CreateCall2(Callee, One, LdExpArg);
|
CallInst *CI = B.CreateCall2(Callee, One, LdExpArg);
|
||||||
|
if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
|
||||||
|
CI->setCallingConv(F->getCallingConv());
|
||||||
|
|
||||||
|
return CI;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===---------------------------------------===//
|
//===---------------------------------------===//
|
||||||
// Double -> Float Shrinking Optimizations for Unary Functions like 'floor'
|
// Double -> Float Shrinking Optimizations for Unary Functions like 'floor'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue