forked from OSchip/llvm-project
parent
a1d7516cb7
commit
3e44ea1917
|
@ -260,7 +260,7 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
|
||||||
bool LowerRd = !S.customReadBarrier();
|
bool LowerRd = !S.customReadBarrier();
|
||||||
bool InitRoots = S.initializeRoots();
|
bool InitRoots = S.initializeRoots();
|
||||||
|
|
||||||
SmallVector<AllocaInst*,32> Roots;
|
SmallVector<AllocaInst*, 32> Roots;
|
||||||
|
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
|
||||||
|
@ -271,7 +271,8 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
|
||||||
case Intrinsic::gcwrite:
|
case Intrinsic::gcwrite:
|
||||||
if (LowerWr) {
|
if (LowerWr) {
|
||||||
// Replace a write barrier with a simple store.
|
// Replace a write barrier with a simple store.
|
||||||
Value *St = new StoreInst(CI->getArgOperand(0), CI->getArgOperand(2), CI);
|
Value *St = new StoreInst(CI->getArgOperand(0),
|
||||||
|
CI->getArgOperand(2), CI);
|
||||||
CI->replaceAllUsesWith(St);
|
CI->replaceAllUsesWith(St);
|
||||||
CI->eraseFromParent();
|
CI->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,7 +481,8 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
||||||
Value *Ops[3];
|
Value *Ops[3];
|
||||||
Ops[0] = CI->getArgOperand(0);
|
Ops[0] = CI->getArgOperand(0);
|
||||||
// Extend the amount to i32.
|
// Extend the amount to i32.
|
||||||
Ops[1] = Builder.CreateIntCast(CI->getArgOperand(1), Type::getInt32Ty(Context),
|
Ops[1] = Builder.CreateIntCast(CI->getArgOperand(1),
|
||||||
|
Type::getInt32Ty(Context),
|
||||||
/* isSigned */ false);
|
/* isSigned */ false);
|
||||||
Ops[2] = Size;
|
Ops[2] = Size;
|
||||||
ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
|
ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
|
||||||
|
|
|
@ -1412,7 +1412,8 @@ void CppWriter::printInstruction(const Instruction *I,
|
||||||
nl(Out);
|
nl(Out);
|
||||||
}
|
}
|
||||||
Out << "CallInst* " << iName << " = CallInst::Create("
|
Out << "CallInst* " << iName << " = CallInst::Create("
|
||||||
<< opNames[call->getNumArgOperands()] << ", " << iName << "_params.begin(), "
|
<< opNames[call->getNumArgOperands()] << ", "
|
||||||
|
<< iName << "_params.begin(), "
|
||||||
<< iName << "_params.end(), \"";
|
<< iName << "_params.end(), \"";
|
||||||
} else if (call->getNumArgOperands() == 1) {
|
} else if (call->getNumArgOperands() == 1) {
|
||||||
Out << "CallInst* " << iName << " = CallInst::Create("
|
Out << "CallInst* " << iName << " = CallInst::Create("
|
||||||
|
|
|
@ -2303,7 +2303,8 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
||||||
if (isa<InlineAsm>(CI->getCalledValue())) return false;
|
if (isa<InlineAsm>(CI->getCalledValue())) return false;
|
||||||
|
|
||||||
// Resolve function pointers.
|
// Resolve function pointers.
|
||||||
Function *Callee = dyn_cast<Function>(getVal(Values, CI->getCalledValue()));
|
Function *Callee = dyn_cast<Function>(getVal(Values,
|
||||||
|
CI->getCalledValue()));
|
||||||
if (!Callee) return false; // Cannot resolve.
|
if (!Callee) return false; // Cannot resolve.
|
||||||
|
|
||||||
SmallVector<Constant*, 8> Formals;
|
SmallVector<Constant*, 8> Formals;
|
||||||
|
|
|
@ -630,8 +630,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||||
cast<VectorType>(II->getArgOperand(0)->getType())->getNumElements();
|
cast<VectorType>(II->getArgOperand(0)->getType())->getNumElements();
|
||||||
APInt DemandedElts(VWidth, 1);
|
APInt DemandedElts(VWidth, 1);
|
||||||
APInt UndefElts(VWidth, 0);
|
APInt UndefElts(VWidth, 0);
|
||||||
if (Value *V = SimplifyDemandedVectorElts(II->getArgOperand(0), DemandedElts,
|
if (Value *V = SimplifyDemandedVectorElts(II->getArgOperand(0),
|
||||||
UndefElts)) {
|
DemandedElts, UndefElts)) {
|
||||||
II->setArgOperand(0, V);
|
II->setArgOperand(0, V);
|
||||||
return II;
|
return II;
|
||||||
}
|
}
|
||||||
|
@ -655,8 +655,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||||
|
|
||||||
if (AllEltsOk) {
|
if (AllEltsOk) {
|
||||||
// Cast the input vectors to byte vectors.
|
// Cast the input vectors to byte vectors.
|
||||||
Value *Op0 = Builder->CreateBitCast(II->getArgOperand(0), Mask->getType());
|
Value *Op0 = Builder->CreateBitCast(II->getArgOperand(0),
|
||||||
Value *Op1 = Builder->CreateBitCast(II->getArgOperand(1), Mask->getType());
|
Mask->getType());
|
||||||
|
Value *Op1 = Builder->CreateBitCast(II->getArgOperand(1),
|
||||||
|
Mask->getType());
|
||||||
Value *Result = UndefValue::get(Op0->getType());
|
Value *Result = UndefValue::get(Op0->getType());
|
||||||
|
|
||||||
// Only extract each element once.
|
// Only extract each element once.
|
||||||
|
@ -772,13 +774,15 @@ protected:
|
||||||
NewInstruction = IC->ReplaceInstUsesWith(*CI, With);
|
NewInstruction = IC->ReplaceInstUsesWith(*CI, With);
|
||||||
}
|
}
|
||||||
bool isFoldable(unsigned SizeCIOp, unsigned SizeArgOp, bool isString) const {
|
bool isFoldable(unsigned SizeCIOp, unsigned SizeArgOp, bool isString) const {
|
||||||
if (ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp))) {
|
if (ConstantInt *SizeCI =
|
||||||
|
dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp))) {
|
||||||
if (SizeCI->isAllOnesValue())
|
if (SizeCI->isAllOnesValue())
|
||||||
return true;
|
return true;
|
||||||
if (isString)
|
if (isString)
|
||||||
return SizeCI->getZExtValue() >=
|
return SizeCI->getZExtValue() >=
|
||||||
GetStringLength(CI->getArgOperand(SizeArgOp));
|
GetStringLength(CI->getArgOperand(SizeArgOp));
|
||||||
if (ConstantInt *Arg = dyn_cast<ConstantInt>(CI->getArgOperand(SizeArgOp)))
|
if (ConstantInt *Arg = dyn_cast<ConstantInt>(
|
||||||
|
CI->getArgOperand(SizeArgOp)))
|
||||||
return SizeCI->getZExtValue() >= Arg->getZExtValue();
|
return SizeCI->getZExtValue() >= Arg->getZExtValue();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1140,7 +1144,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) {
|
||||||
IntrinsicInst *Tramp =
|
IntrinsicInst *Tramp =
|
||||||
cast<IntrinsicInst>(cast<BitCastInst>(Callee)->getOperand(0));
|
cast<IntrinsicInst>(cast<BitCastInst>(Callee)->getOperand(0));
|
||||||
|
|
||||||
Function *NestF = cast<Function>(Tramp->getArgOperand(1)->stripPointerCasts());
|
Function *NestF =cast<Function>(Tramp->getArgOperand(1)->stripPointerCasts());
|
||||||
const PointerType *NestFPTy = cast<PointerType>(NestF->getType());
|
const PointerType *NestFPTy = cast<PointerType>(NestF->getType());
|
||||||
const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType());
|
const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType());
|
||||||
|
|
||||||
|
|
|
@ -743,7 +743,8 @@ bool MemCpyOpt::processMemMove(MemMoveInst *M) {
|
||||||
const Type *ArgTys[3] = { M->getRawDest()->getType(),
|
const Type *ArgTys[3] = { M->getRawDest()->getType(),
|
||||||
M->getRawSource()->getType(),
|
M->getRawSource()->getType(),
|
||||||
M->getLength()->getType() };
|
M->getLength()->getType() };
|
||||||
M->setCalledFunction(Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, ArgTys, 3));
|
M->setCalledFunction(Intrinsic::getDeclaration(Mod, Intrinsic::memcpy,
|
||||||
|
ArgTys, 3));
|
||||||
|
|
||||||
// MemDep may have over conservative information about this instruction, just
|
// MemDep may have over conservative information about this instruction, just
|
||||||
// conservatively flush it from the cache.
|
// conservatively flush it from the cache.
|
||||||
|
|
|
@ -566,8 +566,8 @@ struct StrStrOpt : public LibCallOptimization {
|
||||||
|
|
||||||
// fold strstr(x, "y") -> strchr(x, 'y').
|
// fold strstr(x, "y") -> strchr(x, 'y').
|
||||||
if (HasStr2 && ToFindStr.size() == 1)
|
if (HasStr2 && ToFindStr.size() == 1)
|
||||||
return B.CreateBitCast(EmitStrChr(CI->getArgOperand(0), ToFindStr[0], B, TD),
|
return B.CreateBitCast(EmitStrChr(CI->getArgOperand(0),
|
||||||
CI->getType());
|
ToFindStr[0], B, TD), CI->getType());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -681,8 +681,8 @@ struct MemSetOpt : public LibCallOptimization {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// memset(p, v, n) -> llvm.memset(p, v, n, 1)
|
// memset(p, v, n) -> llvm.memset(p, v, n, 1)
|
||||||
Value *Val = B.CreateIntCast(CI->getArgOperand(1), Type::getInt8Ty(*Context),
|
Value *Val = B.CreateIntCast(CI->getArgOperand(1),
|
||||||
false);
|
Type::getInt8Ty(*Context), false);
|
||||||
EmitMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), false, B, TD);
|
EmitMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), false, B, TD);
|
||||||
return CI->getArgOperand(0);
|
return CI->getArgOperand(0);
|
||||||
}
|
}
|
||||||
|
@ -1042,9 +1042,9 @@ struct SPrintFOpt : public LibCallOptimization {
|
||||||
if (!TD) return 0;
|
if (!TD) return 0;
|
||||||
|
|
||||||
// sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1)
|
// sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1)
|
||||||
EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), // Copy the nul byte.
|
EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), // Copy the
|
||||||
ConstantInt::get(TD->getIntPtrType(*Context),
|
ConstantInt::get(TD->getIntPtrType(*Context), // nul byte.
|
||||||
FormatStr.size()+1), 1, false, B, TD);
|
FormatStr.size() + 1), 1, false, B, TD);
|
||||||
return ConstantInt::get(CI->getType(), FormatStr.size());
|
return ConstantInt::get(CI->getType(), FormatStr.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1080,7 +1080,8 @@ struct SPrintFOpt : public LibCallOptimization {
|
||||||
Value *IncLen = B.CreateAdd(Len,
|
Value *IncLen = B.CreateAdd(Len,
|
||||||
ConstantInt::get(Len->getType(), 1),
|
ConstantInt::get(Len->getType(), 1),
|
||||||
"leninc");
|
"leninc");
|
||||||
EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(2), IncLen, 1, false, B, TD);
|
EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(2),
|
||||||
|
IncLen, 1, false, B, TD);
|
||||||
|
|
||||||
// The sprintf result is the unincremented number of bytes in the string.
|
// The sprintf result is the unincremented number of bytes in the string.
|
||||||
return B.CreateIntCast(Len, CI->getType(), false);
|
return B.CreateIntCast(Len, CI->getType(), false);
|
||||||
|
|
|
@ -422,8 +422,8 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isFoldable(3, 2, false)) {
|
if (isFoldable(3, 2, false)) {
|
||||||
EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
|
EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
|
||||||
1, false, B, TD);
|
CI->getArgOperand(2), 1, false, B, TD);
|
||||||
replaceCall(CI->getArgOperand(0));
|
replaceCall(CI->getArgOperand(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -445,8 +445,8 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isFoldable(3, 2, false)) {
|
if (isFoldable(3, 2, false)) {
|
||||||
EmitMemMove(CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2),
|
EmitMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
|
||||||
1, false, B, TD);
|
CI->getArgOperand(2), 1, false, B, TD);
|
||||||
replaceCall(CI->getArgOperand(0));
|
replaceCall(CI->getArgOperand(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,8 @@ bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const TargetData *TD) {
|
||||||
if (isFoldable(3, 2, false)) {
|
if (isFoldable(3, 2, false)) {
|
||||||
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
|
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
|
||||||
false);
|
false);
|
||||||
EmitMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), false, B, TD);
|
EmitMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2),
|
||||||
|
false, B, TD);
|
||||||
replaceCall(CI->getArgOperand(0));
|
replaceCall(CI->getArgOperand(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -398,7 +398,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
|
||||||
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
|
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
|
||||||
} else if (isShufPD) {
|
} else if (isShufPD) {
|
||||||
Value *Op1 = CI->getArgOperand(1);
|
Value *Op1 = CI->getArgOperand(1);
|
||||||
unsigned MaskVal = cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue();
|
unsigned MaskVal =
|
||||||
|
cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue();
|
||||||
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), MaskVal & 1));
|
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), MaskVal & 1));
|
||||||
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C),
|
Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C),
|
||||||
((MaskVal >> 1) & 1)+2));
|
((MaskVal >> 1) & 1)+2));
|
||||||
|
|
Loading…
Reference in New Issue