本文整理汇总了C++中VectorType::getBitWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ VectorType::getBitWidth方法的具体用法?C++ VectorType::getBitWidth怎么用?C++ VectorType::getBitWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VectorType
的用法示例。
在下文中一共展示了VectorType::getBitWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: num
static void replaceShuffleVectorWithByteSwap64(
ShuffleVectorInst *SI, SmallVector<int, 16> &RefMasks)
{
Value *LHS = SI->getOperand(0);
Value *RHS = SI->getOperand(1);
VectorType *LHSType = cast<VectorType>(LHS->getType());
VectorType *RHSType = cast<VectorType>(RHS->getType());
unsigned LHSWidth = LHSType->getBitWidth();
errs() << "In Replace: " << LHSWidth << "\n";
unsigned RHSWidth = RHSType->getBitWidth();
//ReplaceWork begins
//TODO:Make it automatic and compact
unsigned ITEMNUM = LHSWidth / 64;
VectorType *Ty1 = VectorType::get(
Type::getInt64Ty(SI->getContext()),
ITEMNUM);
BitCastInst *BCI1 = new BitCastInst(
LHS, Ty1, "", SI);
//TODO:Remove ShuffleVectorInst
SmallVector<Constant *, 16> BigMasks;
for (unsigned i = 0; i < ITEMNUM; ++i) {
APInt num(32, ITEMNUM - i - 1);
BigMasks.push_back(
Constant::getIntegerValue(
Type::getInt32Ty(SI->getContext()),
num));
}
Constant *Masks = ConstantVector::get(BigMasks);
ShuffleVectorInst *SVI = new ShuffleVectorInst(
BCI1, UndefValue::get(BCI1->getType()),
Masks,//Mask is ConstantVector
"",
SI);
SmallVector<CallInst *, 16> CIS;
for (unsigned i = 0; i < ITEMNUM; ++i) {
ConstantInt *CI =
ConstantInt::get(
Type::getInt32Ty(
SI->getContext()), i);
ExtractElementInst *EEI = ExtractElementInst::Create(
SVI, CI, "", SI);
//EVIS.push_back(EEI);
Module *M = SI->getParent()->getParent()->getParent();
Constant *Int = Intrinsic::getDeclaration(
M, Intrinsic::bswap, EEI->getType());
Value *Op = EEI;
CallInst *CaI = CallInst::Create(Int, Op, "", SI);
CIS.push_back(CaI);
}
VectorType *Ty2 = VectorType::get(
Type::getInt64Ty(SI->getContext()),
1);
BitCastInst *BCIW = new BitCastInst(
CIS[0], Ty2, "", SI);
Value *V = BCIW;
for (unsigned i = 1; i < CIS.size(); ++i) {
Value *Elt = CIS[i];
InsertElementInst *IEI =
InsertElementInst::Create(
V, Elt,
ConstantInt::get(Type::getInt32Ty(SI->getContext()), 0),
"", SI);
V = IEI;
}
return ;
}
示例2: replaceInstUsesWith
//.........这里部分代码省略.........
// a non-vector type. We can instead bitcast the original vector followed by
// an extract of the desired element:
//
// %sroa = shufflevector <16 x i8> %in, <16 x i8> undef,
// <4 x i32> <i32 0, i32 1, i32 2, i32 3>
// %1 = bitcast <4 x i8> %sroa to i32
// Becomes:
// %bc = bitcast <16 x i8> %in to <4 x i32>
// %ext = extractelement <4 x i32> %bc, i32 0
//
// If the shuffle is extracting a contiguous range of values from the input
// vector then each use which is a bitcast of the extracted size can be
// replaced. This will work if the vector types are compatible, and the begin
// index is aligned to a value in the casted vector type. If the begin index
// isn't aligned then we can shuffle the original vector (keeping the same
// vector type) before extracting.
//
// This code will bail out if the target type is fundamentally incompatible
// with vectors of the source type.
//
// Example of <16 x i8>, target type i32:
// Index range [4,8): v-----------v Will work.
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// <16 x i8>: | | | | | | | | | | | | | | | | |
// <4 x i32>: | | | | |
// +-----------+-----------+-----------+-----------+
// Index range [6,10): ^-----------^ Needs an extra shuffle.
// Target type i40: ^--------------^ Won't work, bail.
if (isShuffleExtractingFromLHS(SVI, Mask)) {
Value *V = LHS;
unsigned MaskElems = Mask.size();
unsigned BegIdx = Mask.front();
VectorType *SrcTy = cast<VectorType>(V->getType());
unsigned VecBitWidth = SrcTy->getBitWidth();
unsigned SrcElemBitWidth = DL.getTypeSizeInBits(SrcTy->getElementType());
assert(SrcElemBitWidth && "vector elements must have a bitwidth");
unsigned SrcNumElems = SrcTy->getNumElements();
SmallVector<BitCastInst *, 8> BCs;
DenseMap<Type *, Value *> NewBCs;
for (User *U : SVI.users())
if (BitCastInst *BC = dyn_cast<BitCastInst>(U))
if (!BC->use_empty())
// Only visit bitcasts that weren't previously handled.
BCs.push_back(BC);
for (BitCastInst *BC : BCs) {
Type *TgtTy = BC->getDestTy();
unsigned TgtElemBitWidth = DL.getTypeSizeInBits(TgtTy);
if (!TgtElemBitWidth)
continue;
unsigned TgtNumElems = VecBitWidth / TgtElemBitWidth;
bool VecBitWidthsEqual = VecBitWidth == TgtNumElems * TgtElemBitWidth;
bool BegIsAligned = 0 == ((SrcElemBitWidth * BegIdx) % TgtElemBitWidth);
if (!VecBitWidthsEqual)
continue;
if (!VectorType::isValidElementType(TgtTy))
continue;
VectorType *CastSrcTy = VectorType::get(TgtTy, TgtNumElems);
if (!BegIsAligned) {
// Shuffle the input so [0,NumElements) contains the output, and
// [NumElems,SrcNumElems) is undef.
SmallVector<Constant *, 16> ShuffleMask(SrcNumElems,
UndefValue::get(Int32Ty));
for (unsigned I = 0, E = MaskElems, Idx = BegIdx; I != E; ++Idx, ++I)
ShuffleMask[I] = ConstantInt::get(Int32Ty, Idx);
V = Builder->CreateShuffleVector(V, UndefValue::get(V->getType()),
ConstantVector::get(ShuffleMask),