本文整理汇总了C++中DataLayout类的典型用法代码示例。如果您正苦于以下问题:C++ DataLayout类的具体用法?C++ DataLayout怎么用?C++ DataLayout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dp_to_di
void ciMethodData::print_data_on(outputStream* st) {
ResourceMark rm;
ciProfileData* data;
for (data = first_data(); is_valid(data); data = next_data(data)) {
st->print("%d", dp_to_di(data->dp()));
st->fill_to(6);
data->print_data_on(st);
}
st->print_cr("--- Extra data:");
DataLayout* dp = data_layout_at(data_size());
DataLayout* end = data_layout_at(data_size() + extra_data_size());
for (; dp < end; dp = methodDataOopDesc::next_extra(dp)) {
if (dp->tag() == DataLayout::no_tag) continue;
if (dp->tag() == DataLayout::bit_data_tag) {
data = new BitData(dp);
} else {
assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
data = new ciArgInfoData(dp);
dp = end; // ArgInfoData is at the end of extra data section.
}
st->print("%d", dp_to_di(data->dp()));
st->fill_to(6);
data->print_data_on(st);
}
}
示例2: isDenselyPacked
/// \brief Checks if a type could have padding bytes.
bool ArgPromotion::isDenselyPacked(Type *type, const DataLayout &DL) {
// There is no size information, so be conservative.
if (!type->isSized())
return false;
// If the alloc size is not equal to the storage size, then there are padding
// bytes. For x86_fp80 on x86-64, size: 80 alloc size: 128.
if (DL.getTypeSizeInBits(type) != DL.getTypeAllocSizeInBits(type))
return false;
if (!isa<CompositeType>(type))
return true;
// For homogenous sequential types, check for padding within members.
if (SequentialType *seqTy = dyn_cast<SequentialType>(type))
return isa<PointerType>(seqTy) ||
isDenselyPacked(seqTy->getElementType(), DL);
// Check for padding within and between elements of a struct.
StructType *StructTy = cast<StructType>(type);
const StructLayout *Layout = DL.getStructLayout(StructTy);
uint64_t StartPos = 0;
for (unsigned i = 0, E = StructTy->getNumElements(); i < E; ++i) {
Type *ElTy = StructTy->getElementType(i);
if (!isDenselyPacked(ElTy, DL))
return false;
if (StartPos != Layout->getElementOffsetInBits(i))
return false;
StartPos += DL.getTypeAllocSizeInBits(ElTy);
}
return true;
}
示例3: data_before
// Translate a bci to its corresponding data, or NULL.
ciProfileData* ciMethodData::bci_to_data(int bci) {
ciProfileData* data = data_before(bci);
for ( ; is_valid(data); data = next_data(data)) {
if (data->bci() == bci) {
set_hint_di(dp_to_di(data->dp()));
return data;
} else if (data->bci() > bci) {
break;
}
}
// bci_to_extra_data(bci) ...
DataLayout* dp = data_layout_at(data_size());
DataLayout* end = data_layout_at(data_size() + extra_data_size());
for (; dp < end; dp = methodDataOopDesc::next_extra(dp)) {
if (dp->tag() == DataLayout::no_tag) {
_saw_free_extra_data = true; // observed an empty slot (common case)
return NULL;
}
if (dp->tag() == DataLayout::arg_info_data_tag) {
break; // ArgInfoData is at the end of extra data section.
}
if (dp->bci() == bci) {
assert(dp->tag() == DataLayout::bit_data_tag, "sane");
return new ciBitData(dp);
}
}
return NULL;
}
示例4: 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);
}
示例5: DataLayout
bool MemorySafetyChecker::runOnModule(Module& m) {
DataLayout* dataLayout = new DataLayout(&m);
Function* memorySafetyFunction = m.getFunction(Naming::MEMORY_SAFETY_FUNCTION);
assert(memorySafetyFunction != NULL && "Couldn't find memory safety function");
for (auto& F : m) {
if (!Naming::isSmackName(F.getName())) {
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
Value* pointer = NULL;
if (LoadInst* li = dyn_cast<LoadInst>(&*I)) {
pointer = li->getPointerOperand();
} else if (StoreInst* si = dyn_cast<StoreInst>(&*I)) {
pointer = si->getPointerOperand();
}
if (pointer) {
// Finding the exact type of the second argument to our memory safety function
Type* sizeType = memorySafetyFunction->getFunctionType()->getParamType(1);
PointerType* pointerType = cast<PointerType>(pointer->getType());
uint64_t storeSize = dataLayout->getTypeStoreSize(pointerType->getPointerElementType());
Value* size = ConstantInt::get(sizeType, storeSize);
Type *voidPtrTy = PointerType::getUnqual(IntegerType::getInt8Ty(F.getContext()));
CastInst* castPointer = CastInst::Create(Instruction::BitCast, pointer, voidPtrTy, "", &*I);
Value* args[] = {castPointer, size};
CallInst::Create(memorySafetyFunction, ArrayRef<Value*>(args, 2), "", &*I);
}
}
}
}
return true;
}
示例6: getAllocatedSize
/**
* Get size of allocated type.
* @param I instruction.
* @param M module.
* @return size of allocated type.
*/
uint64_t getAllocatedSize(Instruction *I, Module* M){
DataLayout* DL = new DataLayout(M);
Type* Ty;
if(const AllocaInst *AI = dyn_cast<AllocaInst>(I)){
Ty = AI->getAllocatedType();
}
else if(const StoreInst *SI = dyn_cast<StoreInst>(I)){
Ty = SI->getOperand(0)->getType();
}
else if(const LoadInst *LI = dyn_cast<LoadInst>(I)){
Ty = LI->getType();
}
else{
return 0;
}
if(!Ty->isSized())
return 0;
uint64_t size = DL->getTypeAllocSize(Ty);
delete DL;
return size;
}
示例7: ComputeValueVTs
/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
/// EVTs that represent all the individual underlying
/// non-aggregate types that comprise it.
///
/// If Offsets is non-null, it points to a vector to be filled in
/// with the in-memory offsets of each of the individual values.
///
void llvm::ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
SmallVectorImpl<uint64_t> *Offsets,
uint64_t StartingOffset) {
// Given a struct type, recursively traverse the elements.
if (StructType *STy = dyn_cast<StructType>(Ty)) {
const StructLayout *SL = DL.getStructLayout(STy);
for (StructType::element_iterator EB = STy->element_begin(),
EI = EB,
EE = STy->element_end();
EI != EE; ++EI)
ComputeValueVTs(TLI, DL, *EI, ValueVTs, Offsets,
StartingOffset + SL->getElementOffset(EI - EB));
return;
}
// Given an array type, recursively traverse the elements.
if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
Type *EltTy = ATy->getElementType();
uint64_t EltSize = DL.getTypeAllocSize(EltTy);
for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
ComputeValueVTs(TLI, DL, EltTy, ValueVTs, Offsets,
StartingOffset + i * EltSize);
return;
}
// Interpret void as zero return values.
if (Ty->isVoidTy())
return;
// Base case: we can get an EVT for this LLVM IR type.
ValueVTs.push_back(TLI.getValueType(DL, Ty));
if (Offsets)
Offsets->push_back(StartingOffset);
}
示例8: 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);
}
示例9: GetOffsetFromIndex
static int64_t GetOffsetFromIndex(const GEPOperator *GEP, unsigned Idx,
bool &VariableIdxFound,
const DataLayout &DL) {
// Skip over the first indices.
gep_type_iterator GTI = gep_type_begin(GEP);
for (unsigned i = 1; i != Idx; ++i, ++GTI)
/*skip along*/;
// Compute the offset implied by the rest of the indices.
int64_t Offset = 0;
for (unsigned i = Idx, e = GEP->getNumOperands(); i != e; ++i, ++GTI) {
ConstantInt *OpC = dyn_cast<ConstantInt>(GEP->getOperand(i));
if (!OpC)
return VariableIdxFound = true;
if (OpC->isZero()) continue; // No offset.
// Handle struct indices, which add their field offset to the pointer.
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
Offset += DL.getStructLayout(STy)->getElementOffset(OpC->getZExtValue());
continue;
}
// Otherwise, we have a sequential type like an array or vector. Multiply
// the index by the ElementSize.
uint64_t Size = DL.getTypeAllocSize(GTI.getIndexedType());
Offset += Size*OpC->getSExtValue();
}
return Offset;
}
示例10: getNameWithPrefixx
static void getNameWithPrefixx(raw_ostream &OS, const Twine &GVName,
Mangler::ManglerPrefixTy PrefixTy,
const DataLayout &DL, char Prefix) {
SmallString<256> TmpData;
StringRef Name = GVName.toStringRef(TmpData);
assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
// No need to do anything special if the global has the special "do not
// mangle" flag in the name.
if (Name[0] == '\1') {
OS << Name.substr(1);
return;
}
if (PrefixTy == Mangler::Private)
OS << DL.getPrivateGlobalPrefix();
else if (PrefixTy == Mangler::LinkerPrivate)
OS << DL.getLinkerPrivateGlobalPrefix();
if (Prefix != '\0')
OS << Prefix;
// If this is a simple string that doesn't need escaping, just append it.
OS << Name;
}
示例11: accumulateConstantOffset
bool GEPOperator::accumulateConstantOffset(const DataLayout &DL,
APInt &Offset) const {
assert(Offset.getBitWidth() ==
DL.getPointerBaseSizeInBits(getPointerAddressSpace()) &&
"The offset must have exactly as many bits as our pointer.");
for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this);
GTI != GTE; ++GTI) {
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand());
if (!OpC)
return false;
if (OpC->isZero())
continue;
// Handle a struct index, which adds its field offset to the pointer.
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
unsigned ElementIdx = OpC->getZExtValue();
const StructLayout *SL = DL.getStructLayout(STy);
Offset += APInt(Offset.getBitWidth(), SL->getElementOffset(ElementIdx));
continue;
}
// For array or vector indices, scale the index by the size of the type.
APInt Index = OpC->getValue().sextOrTrunc(Offset.getBitWidth());
Offset += Index * APInt(Offset.getBitWidth(),
DL.getTypeAllocSize(GTI.getIndexedType()));
}
return true;
}
示例12: first_data
void methodDataOopDesc::print_data_on(outputStream* st) {
ResourceMark rm;
ProfileData* data = first_data();
for ( ; is_valid(data); data = next_data(data)) {
st->print("%d", dp_to_di(data->dp()));
st->fill_to(6);
data->print_data_on(st);
}
st->print_cr("--- Extra data:");
DataLayout* dp = extra_data_base();
DataLayout* end = extra_data_limit();
for (; dp < end; dp = next_extra(dp)) {
// No need for "OrderAccess::load_acquire" ops,
// since the data structure is monotonic.
if (dp->tag() == DataLayout::no_tag) continue;
if (dp->tag() == DataLayout::bit_data_tag) {
data = new BitData(dp);
} else {
assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
data = new ArgInfoData(dp);
dp = end; // ArgInfoData is at the end of extra data section.
}
st->print("%d", dp_to_di(data->dp()));
st->fill_to(6);
data->print_data_on(st);
}
}
示例13: extra_data_base
void ciMethodData::dump_replay_data_extra_data_helper(outputStream* out, int round, int& count) {
DataLayout* dp = extra_data_base();
DataLayout* end = args_data_limit();
for (;dp < end; dp = MethodData::next_extra(dp)) {
switch(dp->tag()) {
case DataLayout::no_tag:
case DataLayout::arg_info_data_tag:
return;
case DataLayout::bit_data_tag:
break;
case DataLayout::speculative_trap_data_tag: {
ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
ciMethod* m = data->method();
if (m != NULL) {
if (round == 0) {
count++;
} else {
out->print(" %d ", (int)(dp_to_di(((address)dp) + in_bytes(ciSpeculativeTrapData::method_offset())) / sizeof(intptr_t)));
m->dump_name_as_ascii(out);
}
}
break;
}
default:
fatal(err_msg("bad tag = %d", dp->tag()));
}
}
}
示例14: 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;
}
示例15: AssertM
LayoutedBlob::LayoutedBlob(const DataLayout & layout, Blob && blob)
: m_layout(layout), m_data(std::move(blob))
{
AssertM(
blob.size() % layout.stride() == 0,
"Layout can't be matched to Blob size");
m_count = blob.size() / layout.stride();
}