forked from OSchip/llvm-project
reapply r148902:
"use the new ConstantVector::getSplat method where it makes sense." Also simplify a bunch of code to use the Builder->getInt32 instead of doing it the hard and ugly way. Much more progress could be made here, but I don't plan to do it. llvm-svn: 148926
This commit is contained in:
parent
29969cd86a
commit
2d6b7b91b9
|
@ -1212,8 +1212,7 @@ static llvm::VectorType *GetNeonType(LLVMContext &C, NeonTypeFlags TypeFlags) {
|
||||||
|
|
||||||
Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) {
|
Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) {
|
||||||
unsigned nElts = cast<llvm::VectorType>(V->getType())->getNumElements();
|
unsigned nElts = cast<llvm::VectorType>(V->getType())->getNumElements();
|
||||||
SmallVector<Constant*, 16> Indices(nElts, C);
|
Value* SV = llvm::ConstantVector::getSplat(nElts, C);
|
||||||
Value* SV = llvm::ConstantVector::get(Indices);
|
|
||||||
return Builder.CreateShuffleVector(V, V, SV, "lane");
|
return Builder.CreateShuffleVector(V, V, SV, "lane");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,13 +1232,11 @@ Value *CodeGenFunction::EmitNeonCall(Function *F, SmallVectorImpl<Value*> &Ops,
|
||||||
|
|
||||||
Value *CodeGenFunction::EmitNeonShiftVector(Value *V, llvm::Type *Ty,
|
Value *CodeGenFunction::EmitNeonShiftVector(Value *V, llvm::Type *Ty,
|
||||||
bool neg) {
|
bool neg) {
|
||||||
ConstantInt *CI = cast<ConstantInt>(V);
|
int SV = cast<ConstantInt>(V)->getSExtValue();
|
||||||
int SV = CI->getSExtValue();
|
|
||||||
|
|
||||||
llvm::VectorType *VTy = cast<llvm::VectorType>(Ty);
|
llvm::VectorType *VTy = cast<llvm::VectorType>(Ty);
|
||||||
llvm::Constant *C = ConstantInt::get(VTy->getElementType(), neg ? -SV : SV);
|
llvm::Constant *C = ConstantInt::get(VTy->getElementType(), neg ? -SV : SV);
|
||||||
SmallVector<llvm::Constant*, 16> CV(VTy->getNumElements(), C);
|
return llvm::ConstantVector::getSplat(VTy->getNumElements(), C);
|
||||||
return llvm::ConstantVector::get(CV);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetPointeeAlignment - Given an expression with a pointer type, find the
|
/// GetPointeeAlignment - Given an expression with a pointer type, find the
|
||||||
|
@ -1957,8 +1954,8 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
|
||||||
for (unsigned vi = 0; vi != 2; ++vi) {
|
for (unsigned vi = 0; vi != 2; ++vi) {
|
||||||
SmallVector<Constant*, 16> Indices;
|
SmallVector<Constant*, 16> Indices;
|
||||||
for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
|
for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
|
||||||
Indices.push_back(ConstantInt::get(Int32Ty, i+vi));
|
Indices.push_back(Builder.getInt32(i+vi));
|
||||||
Indices.push_back(ConstantInt::get(Int32Ty, i+e+vi));
|
Indices.push_back(Builder.getInt32(i+e+vi));
|
||||||
}
|
}
|
||||||
Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi);
|
Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi);
|
||||||
SV = llvm::ConstantVector::get(Indices);
|
SV = llvm::ConstantVector::get(Indices);
|
||||||
|
@ -2019,7 +2016,7 @@ BuildVector(const SmallVectorImpl<llvm::Value*> &Ops) {
|
||||||
|
|
||||||
// If this is a constant vector, create a ConstantVector.
|
// If this is a constant vector, create a ConstantVector.
|
||||||
if (AllConstants) {
|
if (AllConstants) {
|
||||||
std::vector<llvm::Constant*> CstOps;
|
SmallVector<llvm::Constant*, 16> CstOps;
|
||||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
||||||
CstOps.push_back(cast<Constant>(Ops[i]));
|
CstOps.push_back(cast<Constant>(Ops[i]));
|
||||||
return llvm::ConstantVector::get(CstOps);
|
return llvm::ConstantVector::get(CstOps);
|
||||||
|
@ -2030,8 +2027,7 @@ BuildVector(const SmallVectorImpl<llvm::Value*> &Ops) {
|
||||||
llvm::UndefValue::get(llvm::VectorType::get(Ops[0]->getType(), Ops.size()));
|
llvm::UndefValue::get(llvm::VectorType::get(Ops[0]->getType(), Ops.size()));
|
||||||
|
|
||||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
||||||
Result = Builder.CreateInsertElement(Result, Ops[i],
|
Result = Builder.CreateInsertElement(Result, Ops[i], Builder.getInt32(i));
|
||||||
llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), i));
|
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -952,10 +952,8 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV) {
|
||||||
unsigned NumResultElts = ExprVT->getNumElements();
|
unsigned NumResultElts = ExprVT->getNumElements();
|
||||||
|
|
||||||
SmallVector<llvm::Constant*, 4> Mask;
|
SmallVector<llvm::Constant*, 4> Mask;
|
||||||
for (unsigned i = 0; i != NumResultElts; ++i) {
|
for (unsigned i = 0; i != NumResultElts; ++i)
|
||||||
unsigned InIdx = getAccessedFieldNo(i, Elts);
|
Mask.push_back(Builder.getInt32(getAccessedFieldNo(i, Elts)));
|
||||||
Mask.push_back(llvm::ConstantInt::get(Int32Ty, InIdx));
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
|
llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
|
||||||
Vec = Builder.CreateShuffleVector(Vec, llvm::UndefValue::get(Vec->getType()),
|
Vec = Builder.CreateShuffleVector(Vec, llvm::UndefValue::get(Vec->getType()),
|
||||||
|
@ -1175,10 +1173,8 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
|
||||||
// elements and restore the vector mask since it is on the side it will be
|
// elements and restore the vector mask since it is on the side it will be
|
||||||
// stored.
|
// stored.
|
||||||
SmallVector<llvm::Constant*, 4> Mask(NumDstElts);
|
SmallVector<llvm::Constant*, 4> Mask(NumDstElts);
|
||||||
for (unsigned i = 0; i != NumSrcElts; ++i) {
|
for (unsigned i = 0; i != NumSrcElts; ++i)
|
||||||
unsigned InIdx = getAccessedFieldNo(i, Elts);
|
Mask[getAccessedFieldNo(i, Elts)] = Builder.getInt32(i);
|
||||||
Mask[InIdx] = llvm::ConstantInt::get(Int32Ty, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
|
llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
|
||||||
Vec = Builder.CreateShuffleVector(SrcVal,
|
Vec = Builder.CreateShuffleVector(SrcVal,
|
||||||
|
@ -1192,7 +1188,7 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
|
||||||
SmallVector<llvm::Constant*, 4> ExtMask;
|
SmallVector<llvm::Constant*, 4> ExtMask;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
for (i = 0; i != NumSrcElts; ++i)
|
for (i = 0; i != NumSrcElts; ++i)
|
||||||
ExtMask.push_back(llvm::ConstantInt::get(Int32Ty, i));
|
ExtMask.push_back(Builder.getInt32(i));
|
||||||
for (; i != NumDstElts; ++i)
|
for (; i != NumDstElts; ++i)
|
||||||
ExtMask.push_back(llvm::UndefValue::get(Int32Ty));
|
ExtMask.push_back(llvm::UndefValue::get(Int32Ty));
|
||||||
llvm::Value *ExtMaskV = llvm::ConstantVector::get(ExtMask);
|
llvm::Value *ExtMaskV = llvm::ConstantVector::get(ExtMask);
|
||||||
|
@ -1203,13 +1199,11 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
|
||||||
// build identity
|
// build identity
|
||||||
SmallVector<llvm::Constant*, 4> Mask;
|
SmallVector<llvm::Constant*, 4> Mask;
|
||||||
for (unsigned i = 0; i != NumDstElts; ++i)
|
for (unsigned i = 0; i != NumDstElts; ++i)
|
||||||
Mask.push_back(llvm::ConstantInt::get(Int32Ty, i));
|
Mask.push_back(Builder.getInt32(i));
|
||||||
|
|
||||||
// modify when what gets shuffled in
|
// modify when what gets shuffled in
|
||||||
for (unsigned i = 0; i != NumSrcElts; ++i) {
|
for (unsigned i = 0; i != NumSrcElts; ++i)
|
||||||
unsigned Idx = getAccessedFieldNo(i, Elts);
|
Mask[getAccessedFieldNo(i, Elts)] = Builder.getInt32(i+NumDstElts);
|
||||||
Mask[Idx] = llvm::ConstantInt::get(Int32Ty, i+NumDstElts);
|
|
||||||
}
|
|
||||||
llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
|
llvm::Value *MaskV = llvm::ConstantVector::get(Mask);
|
||||||
Vec = Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV);
|
Vec = Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1734,13 +1728,11 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
llvm::Constant *GenerateConstantVector(llvm::LLVMContext &VMContext,
|
llvm::Constant *GenerateConstantVector(llvm::IRBuilder<> &Builder,
|
||||||
SmallVector<unsigned, 4> &Elts) {
|
SmallVector<unsigned, 4> &Elts) {
|
||||||
SmallVector<llvm::Constant*, 4> CElts;
|
SmallVector<llvm::Constant*, 4> CElts;
|
||||||
|
|
||||||
llvm::Type *Int32Ty = llvm::Type::getInt32Ty(VMContext);
|
|
||||||
for (unsigned i = 0, e = Elts.size(); i != e; ++i)
|
for (unsigned i = 0, e = Elts.size(); i != e; ++i)
|
||||||
CElts.push_back(llvm::ConstantInt::get(Int32Ty, Elts[i]));
|
CElts.push_back(Builder.getInt32(Elts[i]));
|
||||||
|
|
||||||
return llvm::ConstantVector::get(CElts);
|
return llvm::ConstantVector::get(CElts);
|
||||||
}
|
}
|
||||||
|
@ -1783,7 +1775,7 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
|
||||||
E->getEncodedElementAccess(Indices);
|
E->getEncodedElementAccess(Indices);
|
||||||
|
|
||||||
if (Base.isSimple()) {
|
if (Base.isSimple()) {
|
||||||
llvm::Constant *CV = GenerateConstantVector(getLLVMContext(), Indices);
|
llvm::Constant *CV = GenerateConstantVector(Builder, Indices);
|
||||||
return LValue::MakeExtVectorElt(Base.getAddress(), CV, type);
|
return LValue::MakeExtVectorElt(Base.getAddress(), CV, type);
|
||||||
}
|
}
|
||||||
assert(Base.isExtVectorElt() && "Can only subscript lvalue vec elts here!");
|
assert(Base.isExtVectorElt() && "Can only subscript lvalue vec elts here!");
|
||||||
|
|
|
@ -610,12 +610,9 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
|
||||||
UnV = Builder.CreateInsertElement(UnV, Elt, Idx);
|
UnV = Builder.CreateInsertElement(UnV, Elt, Idx);
|
||||||
|
|
||||||
// Splat the element across to all elements
|
// Splat the element across to all elements
|
||||||
SmallVector<llvm::Constant*, 16> Args;
|
|
||||||
unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements();
|
unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements();
|
||||||
for (unsigned i = 0; i != NumElements; ++i)
|
llvm::Constant *Mask = llvm::ConstantVector::getSplat(NumElements,
|
||||||
Args.push_back(Builder.getInt32(0));
|
Builder.getInt32(0));
|
||||||
|
|
||||||
llvm::Constant *Mask = llvm::ConstantVector::get(Args);
|
|
||||||
llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat");
|
llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat");
|
||||||
return Yay;
|
return Yay;
|
||||||
}
|
}
|
||||||
|
@ -749,11 +746,8 @@ Value *ScalarExprEmitter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
|
||||||
(1 << llvm::Log2_32(LHSElts))-1);
|
(1 << llvm::Log2_32(LHSElts))-1);
|
||||||
|
|
||||||
// Mask off the high bits of each shuffle index.
|
// Mask off the high bits of each shuffle index.
|
||||||
SmallVector<llvm::Constant *, 32> MaskV;
|
Value *MaskBits = llvm::ConstantVector::getSplat(MTy->getNumElements(),
|
||||||
for (unsigned i = 0, e = MTy->getNumElements(); i != e; ++i)
|
EltMask);
|
||||||
MaskV.push_back(EltMask);
|
|
||||||
|
|
||||||
Value* MaskBits = llvm::ConstantVector::get(MaskV);
|
|
||||||
Mask = Builder.CreateAnd(Mask, MaskBits, "mask");
|
Mask = Builder.CreateAnd(Mask, MaskBits, "mask");
|
||||||
|
|
||||||
// newv = undef
|
// newv = undef
|
||||||
|
@ -1203,13 +1197,9 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
|
||||||
UnV = Builder.CreateInsertElement(UnV, Elt, Idx);
|
UnV = Builder.CreateInsertElement(UnV, Elt, Idx);
|
||||||
|
|
||||||
// Splat the element across to all elements
|
// Splat the element across to all elements
|
||||||
SmallVector<llvm::Constant*, 16> Args;
|
|
||||||
unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements();
|
unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements();
|
||||||
llvm::Constant *Zero = Builder.getInt32(0);
|
llvm::Constant *Zero = Builder.getInt32(0);
|
||||||
for (unsigned i = 0; i < NumElements; i++)
|
llvm::Constant *Mask = llvm::ConstantVector::getSplat(NumElements, Zero);
|
||||||
Args.push_back(Zero);
|
|
||||||
|
|
||||||
llvm::Constant *Mask = llvm::ConstantVector::get(Args);
|
|
||||||
llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat");
|
llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat");
|
||||||
return Yay;
|
return Yay;
|
||||||
}
|
}
|
||||||
|
@ -2596,11 +2586,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
|
||||||
unsigned numElem = vecTy->getNumElements();
|
unsigned numElem = vecTy->getNumElements();
|
||||||
llvm::Type *elemType = vecTy->getElementType();
|
llvm::Type *elemType = vecTy->getElementType();
|
||||||
|
|
||||||
std::vector<llvm::Constant*> Zvals;
|
llvm::Value *zeroVec = llvm::Constant::getNullValue(vecTy);
|
||||||
for (unsigned i = 0; i < numElem; ++i)
|
|
||||||
Zvals.push_back(llvm::ConstantInt::get(elemType, 0));
|
|
||||||
|
|
||||||
llvm::Value *zeroVec = llvm::ConstantVector::get(Zvals);
|
|
||||||
llvm::Value *TestMSB = Builder.CreateICmpSLT(CondV, zeroVec);
|
llvm::Value *TestMSB = Builder.CreateICmpSLT(CondV, zeroVec);
|
||||||
llvm::Value *tmp = Builder.CreateSExt(TestMSB,
|
llvm::Value *tmp = Builder.CreateSExt(TestMSB,
|
||||||
llvm::VectorType::get(elemType,
|
llvm::VectorType::get(elemType,
|
||||||
|
|
Loading…
Reference in New Issue