当前位置: 首页>>代码示例>>C++>>正文


C++ DataLayout::getABITypeAlignment方法代码示例

本文整理汇总了C++中DataLayout::getABITypeAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ DataLayout::getABITypeAlignment方法的具体用法?C++ DataLayout::getABITypeAlignment怎么用?C++ DataLayout::getABITypeAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataLayout的用法示例。


在下文中一共展示了DataLayout::getABITypeAlignment方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getRuntimeMDForKernelArg

static KernelArg::Metadata getRuntimeMDForKernelArg(const DataLayout &DL,
    Type *T, KernelArg::Kind Kind, StringRef BaseTypeName = "",
    StringRef TypeName = "", StringRef ArgName = "", StringRef TypeQual = "",
    StringRef AccQual = "") {
  KernelArg::Metadata Arg;

  // Set ArgSize and ArgAlign.
  Arg.Size = DL.getTypeAllocSize(T);
  Arg.Align = DL.getABITypeAlignment(T);
  if (auto PT = dyn_cast<PointerType>(T)) {
    auto ET = PT->getElementType();
    if (PT->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS && ET->isSized())
      Arg.PointeeAlign = DL.getABITypeAlignment(ET);
  }

  // Set ArgTypeName.
  Arg.TypeName = TypeName;

  // Set ArgName.
  Arg.Name = ArgName;

  // Set ArgIsVolatile, ArgIsRestrict, ArgIsConst and ArgIsPipe.
  SmallVector<StringRef, 1> SplitQ;
  TypeQual.split(SplitQ, " ", -1, false /* Drop empty entry */);

  for (StringRef KeyName : SplitQ) {
    auto *P = StringSwitch<uint8_t *>(KeyName)
      .Case("volatile", &Arg.IsVolatile)
      .Case("restrict", &Arg.IsRestrict)
      .Case("const",    &Arg.IsConst)
      .Case("pipe",     &Arg.IsPipe)
      .Default(nullptr);
    if (P)
      *P = 1;
  }

  // Set ArgKind.
  Arg.Kind = Kind;

  // Set ArgValueType.
  Arg.ValueType = getRuntimeMDValueType(T, BaseTypeName);

  // Set ArgAccQual.
  if (!AccQual.empty()) {
    Arg.AccQual = StringSwitch<KernelArg::AccessQualifer>(AccQual)
      .Case("read_only",  KernelArg::ReadOnly)
      .Case("write_only", KernelArg::WriteOnly)
      .Case("read_write", KernelArg::ReadWrite)
      .Default(KernelArg::AccNone);
  }

  // Set ArgAddrQual.
  if (auto *PT = dyn_cast<PointerType>(T)) {
    Arg.AddrQual = getRuntimeAddrSpace(static_cast<AMDGPUAS::AddressSpaces>(
        PT->getAddressSpace()));
  }

  return Arg;
}
开发者ID:bugsnag,项目名称:llvm,代码行数:59,代码来源:AMDGPURuntimeMD.cpp

示例2: findCommonAlignment

static unsigned findCommonAlignment(const DataLayout &DL, const StoreInst *SI,
                                     const LoadInst *LI) {
  unsigned StoreAlign = SI->getAlignment();
  if (!StoreAlign)
    StoreAlign = DL.getABITypeAlignment(SI->getOperand(0)->getType());
  unsigned LoadAlign = LI->getAlignment();
  if (!LoadAlign)
    LoadAlign = DL.getABITypeAlignment(LI->getType());

  return std::min(StoreAlign, LoadAlign);
}
开发者ID:DanishKhakwani,项目名称:llvm,代码行数:11,代码来源:MemCpyOptimizer.cpp

示例3: getPointerAlignment

unsigned Value::getPointerAlignment(const DataLayout &DL) const {
  assert(getType()->isPointerTy() && "must be pointer");

  unsigned Align = 0;
  if (auto *GO = dyn_cast<GlobalObject>(this)) {
    // Don't make any assumptions about function pointer alignment. Some
    // targets use the LSBs to store additional information.
    if (isa<Function>(GO))
      return 0;
    Align = GO->getAlignment();
    if (Align == 0) {
      if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
        Type *ObjectType = GVar->getValueType();
        if (ObjectType->isSized()) {
          // If the object is defined in the current Module, we'll be giving
          // it the preferred alignment. Otherwise, we have to assume that it
          // may only have the minimum ABI alignment.
          if (GVar->isStrongDefinitionForLinker())
            Align = DL.getPreferredAlignment(GVar);
          else
            Align = DL.getABITypeAlignment(ObjectType);
        }
      }
    }
  } else if (const Argument *A = dyn_cast<Argument>(this)) {
    Align = A->getParamAlignment();

    if (!Align && A->hasStructRetAttr()) {
      // An sret parameter has at least the ABI alignment of the return type.
      Type *EltTy = cast<PointerType>(A->getType())->getElementType();
      if (EltTy->isSized())
        Align = DL.getABITypeAlignment(EltTy);
    }
  } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
    Align = AI->getAlignment();
    if (Align == 0) {
      Type *AllocatedType = AI->getAllocatedType();
      if (AllocatedType->isSized())
        Align = DL.getPrefTypeAlignment(AllocatedType);
    }
  } else if (auto CS = ImmutableCallSite(this))
    Align = CS.getAttributes().getRetAlignment();
  else if (const LoadInst *LI = dyn_cast<LoadInst>(this))
    if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
      ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
      Align = CI->getLimitedValue();
    }

  return Align;
}
开发者ID:crabtw,项目名称:llvm,代码行数:50,代码来源:Value.cpp

示例4: isDereferenceableAndAlignedPointer

bool llvm::isDereferenceableAndAlignedPointer(const Value *V, unsigned Align,
        const DataLayout &DL,
        const Instruction *CtxI,
        const DominatorTree *DT,
        const TargetLibraryInfo *TLI) {
    // When dereferenceability information is provided by a dereferenceable
    // attribute, we know exactly how many bytes are dereferenceable. If we can
    // determine the exact offset to the attributed variable, we can use that
    // information here.
    Type *VTy = V->getType();
    Type *Ty = VTy->getPointerElementType();

    // Require ABI alignment for loads without alignment specification
    if (Align == 0)
        Align = DL.getABITypeAlignment(Ty);

    if (Ty->isSized()) {
        APInt Offset(DL.getTypeStoreSizeInBits(VTy), 0);
        const Value *BV = V->stripAndAccumulateInBoundsConstantOffsets(DL, Offset);

        if (Offset.isNonNegative())
            if (isDereferenceableFromAttribute(BV, Offset, Ty, DL, CtxI, DT, TLI) &&
                    isAligned(BV, Offset, Align, DL))
                return true;
    }

    SmallPtrSet<const Value *, 32> Visited;
    return ::isDereferenceableAndAlignedPointer(V, Align, DL, CtxI, DT, TLI,
            Visited);
}
开发者ID:AlexDenisov,项目名称:llvm,代码行数:30,代码来源:Loads.cpp

示例5: assert

StructLayout::StructLayout(StructType *ST, const DataLayout &DL) {
  assert(!ST->isOpaque() && "Cannot get layout of opaque structs");
  StructAlignment = 0;
  StructSize = 0;
  NumElements = ST->getNumElements();

  // Loop over each of the elements, placing them in memory.
  for (unsigned i = 0, e = NumElements; i != e; ++i) {
    Type *Ty = ST->getElementType(i);
    unsigned TyAlign = ST->isPacked() ? 1 : DL.getABITypeAlignment(Ty);

    // Add padding if necessary to align the data element properly.
    if ((StructSize & (TyAlign-1)) != 0)
      StructSize = RoundUpToAlignment(StructSize, TyAlign);

    // Keep track of maximum alignment constraint.
    StructAlignment = std::max(TyAlign, StructAlignment);

    MemberOffsets[i] = StructSize;
    StructSize += DL.getTypeAllocSize(Ty); // Consume space for this data item
  }

  // Empty structures have alignment of 1 byte.
  if (StructAlignment == 0) StructAlignment = 1;

  // Add padding to the end of the struct so that it could be put in an array
  // and all array elements would be aligned correctly.
  if ((StructSize & (StructAlignment-1)) != 0)
    StructSize = RoundUpToAlignment(StructSize, StructAlignment);
}
开发者ID:0x00evil,项目名称:llvm,代码行数:30,代码来源:DataLayout.cpp

示例6: isAligned

static bool isAligned(const Value *Base, APInt Offset, unsigned Align,
                      const DataLayout &DL) {
    APInt BaseAlign(Offset.getBitWidth(), Base->getPointerAlignment(DL));

    if (!BaseAlign) {
        Type *Ty = Base->getType()->getPointerElementType();
        if (!Ty->isSized())
            return false;
        BaseAlign = DL.getABITypeAlignment(Ty);
    }

    APInt Alignment(Offset.getBitWidth(), Align);

    assert(Alignment.isPowerOf2() && "must be a power of 2!");
    return BaseAlign.uge(Alignment) && !(Offset & (Alignment-1));
}
开发者ID:AlexDenisov,项目名称:llvm,代码行数:16,代码来源:Loads.cpp

示例7: getPointeeAlignment

/// getPointeeAlignment - Compute the minimum alignment of the value pointed
/// to by the given pointer.
static unsigned getPointeeAlignment(Value *V, const DataLayout &TD) {
  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
    if (CE->getOpcode() == Instruction::BitCast ||
        (CE->getOpcode() == Instruction::GetElementPtr &&
         cast<GEPOperator>(CE)->hasAllZeroIndices()))
      return getPointeeAlignment(CE->getOperand(0), TD);

  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
    if (!GV->isDeclaration())
      return TD.getPreferredAlignment(GV);

  if (PointerType *PT = dyn_cast<PointerType>(V->getType()))
    return TD.getABITypeAlignment(PT->getElementType());

  return 0;
}
开发者ID:C0deZLee,项目名称:IntFlow,代码行数:18,代码来源:InstCombineLoadStoreAlloca.cpp

示例8: getVectorLayout

// Try to fill in Layout from Ty, returning true on success.  Alignment is
// the alignment of the vector, or 0 if the ABI default should be used.
bool Scalarizer::getVectorLayout(Type *Ty, unsigned Alignment,
                                 VectorLayout &Layout, const DataLayout &DL) {
  // Make sure we're dealing with a vector.
  Layout.VecTy = dyn_cast<VectorType>(Ty);
  if (!Layout.VecTy)
    return false;

  // Check that we're dealing with full-byte elements.
  Layout.ElemTy = Layout.VecTy->getElementType();
  if (DL.getTypeSizeInBits(Layout.ElemTy) !=
      DL.getTypeStoreSizeInBits(Layout.ElemTy))
    return false;

  if (Alignment)
    Layout.VecAlign = Alignment;
  else
    Layout.VecAlign = DL.getABITypeAlignment(Layout.VecTy);
  Layout.ElemSize = DL.getTypeStoreSize(Layout.ElemTy);
  return true;
}
开发者ID:julaiti-graphsql,项目名称:llvm,代码行数:22,代码来源:Scalarizer.cpp

示例9: isDereferenceableAndAlignedPointer

bool llvm::isDereferenceableAndAlignedPointer(const Value *V, unsigned Align,
                                              const DataLayout &DL,
                                              const Instruction *CtxI,
                                              const DominatorTree *DT) {
  // When dereferenceability information is provided by a dereferenceable
  // attribute, we know exactly how many bytes are dereferenceable. If we can
  // determine the exact offset to the attributed variable, we can use that
  // information here.
  Type *VTy = V->getType();
  Type *Ty = VTy->getPointerElementType();

  // Require ABI alignment for loads without alignment specification
  if (Align == 0)
    Align = DL.getABITypeAlignment(Ty);

  if (!Ty->isSized())
    return false;

  SmallPtrSet<const Value *, 32> Visited;
  return ::isDereferenceableAndAlignedPointer(
      V, Align, APInt(DL.getIndexTypeSizeInBits(VTy), DL.getTypeStoreSize(Ty)), DL,
      CtxI, DT, Visited);
}
开发者ID:CTSRD-CHERI,项目名称:llvm,代码行数:23,代码来源:Loads.cpp

示例10: isSafeToLoadUnconditionally

/// Check if executing a load of this pointer value cannot trap.
///
/// If DT and ScanFrom are specified this method performs context-sensitive
/// analysis and returns true if it is safe to load immediately before ScanFrom.
///
/// If it is not obviously safe to load from the specified pointer, we do
/// a quick local scan of the basic block containing \c ScanFrom, to determine
/// if the address is already accessed.
///
/// This uses the pointee type to determine how many bytes need to be safe to
/// load from the pointer.
bool llvm::isSafeToLoadUnconditionally(Value *V, unsigned Align,
                                       const DataLayout &DL,
                                       Instruction *ScanFrom,
                                       const DominatorTree *DT) {
  // Zero alignment means that the load has the ABI alignment for the target
  if (Align == 0)
    Align = DL.getABITypeAlignment(V->getType()->getPointerElementType());
  assert(isPowerOf2_32(Align));

  // If DT is not specified we can't make context-sensitive query
  const Instruction* CtxI = DT ? ScanFrom : nullptr;
  if (isDereferenceableAndAlignedPointer(V, Align, DL, CtxI, DT))
    return true;

  int64_t ByteOffset = 0;
  Value *Base = V;
  Base = GetPointerBaseWithConstantOffset(V, ByteOffset, DL);

  if (ByteOffset < 0) // out of bounds
    return false;

  Type *BaseType = nullptr;
  unsigned BaseAlign = 0;
  if (const AllocaInst *AI = dyn_cast<AllocaInst>(Base)) {
    // An alloca is safe to load from as load as it is suitably aligned.
    BaseType = AI->getAllocatedType();
    BaseAlign = AI->getAlignment();
  } else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
    // Global variables are not necessarily safe to load from if they are
    // interposed arbitrarily. Their size may change or they may be weak and
    // require a test to determine if they were in fact provided.
    if (!GV->isInterposable()) {
      BaseType = GV->getType()->getElementType();
      BaseAlign = GV->getAlignment();
    }
  }

  PointerType *AddrTy = cast<PointerType>(V->getType());
  uint64_t LoadSize = DL.getTypeStoreSize(AddrTy->getElementType());

  // If we found a base allocated type from either an alloca or global variable,
  // try to see if we are definitively within the allocated region. We need to
  // know the size of the base type and the loaded type to do anything in this
  // case.
  if (BaseType && BaseType->isSized()) {
    if (BaseAlign == 0)
      BaseAlign = DL.getPrefTypeAlignment(BaseType);

    if (Align <= BaseAlign) {
      // Check if the load is within the bounds of the underlying object.
      if (ByteOffset + LoadSize <= DL.getTypeAllocSize(BaseType) &&
          ((ByteOffset % Align) == 0))
        return true;
    }
  }

  if (!ScanFrom)
    return false;

  // Otherwise, be a little bit aggressive by scanning the local block where we
  // want to check to see if the pointer is already being loaded or stored
  // from/to.  If so, the previous load or store would have already trapped,
  // so there is no harm doing an extra load (also, CSE will later eliminate
  // the load entirely).
  BasicBlock::iterator BBI = ScanFrom->getIterator(),
                       E = ScanFrom->getParent()->begin();

  // We can at least always strip pointer casts even though we can't use the
  // base here.
  V = V->stripPointerCasts();

  while (BBI != E) {
    --BBI;

    // If we see a free or a call which may write to memory (i.e. which might do
    // a free) the pointer could be marked invalid.
    if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
        !isa<DbgInfoIntrinsic>(BBI))
      return false;

    Value *AccessedPtr;
    unsigned AccessedAlign;
    if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
      AccessedPtr = LI->getPointerOperand();
      AccessedAlign = LI->getAlignment();
    } else if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
      AccessedPtr = SI->getPointerOperand();
      AccessedAlign = SI->getAlignment();
    } else
//.........这里部分代码省略.........
开发者ID:CTSRD-CHERI,项目名称:llvm,代码行数:101,代码来源:Loads.cpp

示例11: emitRuntimeMetadataForKernelArg

void AMDGPUTargetStreamer::emitRuntimeMetadataForKernelArg(const DataLayout &DL,
    Type *T, RuntimeMD::KernelArg::Kind Kind,
    StringRef BaseTypeName, StringRef TypeName,
    StringRef ArgName, StringRef TypeQual, StringRef AccQual) {
  auto &S = getStreamer();

  // Emit KeyArgBegin.
  S.EmitIntValue(RuntimeMD::KeyArgBegin, 1);

  // Emit KeyArgSize and KeyArgAlign.
  emitRuntimeMDIntValue(RuntimeMD::KeyArgSize,
                        DL.getTypeAllocSize(T), 4);
  emitRuntimeMDIntValue(RuntimeMD::KeyArgAlign,
                        DL.getABITypeAlignment(T), 4);
  if (auto PT = dyn_cast<PointerType>(T)) {
    auto ET = PT->getElementType();
    if (PT->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS && ET->isSized())
      emitRuntimeMDIntValue(RuntimeMD::KeyArgPointeeAlign,
                            DL.getABITypeAlignment(ET), 4);
  }

  // Emit KeyArgTypeName.
  if (!TypeName.empty())
    emitRuntimeMDStringValue(RuntimeMD::KeyArgTypeName, TypeName);

  // Emit KeyArgName.
  if (!ArgName.empty())
    emitRuntimeMDStringValue(RuntimeMD::KeyArgName, ArgName);

  // Emit KeyArgIsVolatile, KeyArgIsRestrict, KeyArgIsConst and KeyArgIsPipe.
  SmallVector<StringRef, 1> SplitQ;
  TypeQual.split(SplitQ, " ", -1, false /* Drop empty entry */);

  for (StringRef KeyName : SplitQ) {
    auto Key = StringSwitch<RuntimeMD::Key>(KeyName)
      .Case("volatile", RuntimeMD::KeyArgIsVolatile)
      .Case("restrict", RuntimeMD::KeyArgIsRestrict)
      .Case("const",    RuntimeMD::KeyArgIsConst)
      .Case("pipe",     RuntimeMD::KeyArgIsPipe)
      .Default(RuntimeMD::KeyNull);
    S.EmitIntValue(Key, 1);
  }

  // Emit KeyArgKind.
  emitRuntimeMDIntValue(RuntimeMD::KeyArgKind, Kind, 1);

  // Emit KeyArgValueType.
  emitRuntimeMDIntValue(RuntimeMD::KeyArgValueType,
                        getRuntimeMDValueType(T, BaseTypeName), 2);

  // Emit KeyArgAccQual.
  if (!AccQual.empty()) {
    auto AQ = StringSwitch<RuntimeMD::KernelArg::AccessQualifer>(AccQual)
      .Case("read_only",  RuntimeMD::KernelArg::ReadOnly)
      .Case("write_only", RuntimeMD::KernelArg::WriteOnly)
      .Case("read_write", RuntimeMD::KernelArg::ReadWrite)
      .Default(RuntimeMD::KernelArg::None);
    emitRuntimeMDIntValue(RuntimeMD::KeyArgAccQual, AQ, 1);
  }

  // Emit KeyArgAddrQual.
  if (auto *PT = dyn_cast<PointerType>(T))
    emitRuntimeMDIntValue(RuntimeMD::KeyArgAddrQual,
        getRuntimeAddrSpace(static_cast<AMDGPUAS::AddressSpaces>(
            PT->getAddressSpace())), 1);

  // Emit KeyArgEnd
  S.EmitIntValue(RuntimeMD::KeyArgEnd, 1);
}
开发者ID:anupam128,项目名称:llvm,代码行数:69,代码来源:AMDGPUTargetStreamer.cpp


注:本文中的DataLayout::getABITypeAlignment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。