本文整理汇总了C++中StructType类的典型用法代码示例。如果您正苦于以下问题:C++ StructType类的具体用法?C++ StructType怎么用?C++ StructType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StructType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SplitUpPHINode
static void SplitUpPHINode(PHINode *Phi) {
StructType *STy = cast<StructType>(Phi->getType());
Value *NewStruct = UndefValue::get(STy);
Instruction *NewStructInsertPt = Phi->getParent()->getFirstInsertionPt();
// Create a separate PHINode for each struct field.
for (unsigned Index = 0; Index < STy->getNumElements(); ++Index) {
SmallVector<unsigned, 1> EVIndexes;
EVIndexes.push_back(Index);
PHINode *NewPhi = PHINode::Create(
STy->getElementType(Index), Phi->getNumIncomingValues(),
Phi->getName() + ".index", Phi);
CopyDebug(NewPhi, Phi);
for (unsigned PhiIndex = 0; PhiIndex < Phi->getNumIncomingValues();
++PhiIndex) {
BasicBlock *IncomingBB = Phi->getIncomingBlock(PhiIndex);
Value *EV = CopyDebug(
ExtractValueInst::Create(
Phi->getIncomingValue(PhiIndex), EVIndexes,
Phi->getName() + ".extract", IncomingBB->getTerminator()), Phi);
NewPhi->addIncoming(EV, IncomingBB);
}
// Reconstruct the original struct value.
NewStruct = CopyDebug(
InsertValueInst::Create(NewStruct, NewPhi, EVIndexes,
Phi->getName() + ".insert", NewStructInsertPt),
Phi);
}
Phi->replaceAllUsesWith(NewStruct);
Phi->eraseFromParent();
}
示例2: isDenselyPacked
/// \brief Checks if a type could have padding bytes.
bool ArgPromotion::isDenselyPacked(Type *type) {
// 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 || 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());
// 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))
return false;
if (StartPos != Layout->getElementOffsetInBits(i))
return false;
StartPos += DL->getTypeAllocSizeInBits(ElTy);
}
return true;
}
示例3: switch
Value *AArch64TTIImpl::getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst,
Type *ExpectedType) {
switch (Inst->getIntrinsicID()) {
default:
return nullptr;
case Intrinsic::aarch64_neon_st2:
case Intrinsic::aarch64_neon_st3:
case Intrinsic::aarch64_neon_st4: {
// Create a struct type
StructType *ST = dyn_cast<StructType>(ExpectedType);
if (!ST)
return nullptr;
unsigned NumElts = Inst->getNumArgOperands() - 1;
if (ST->getNumElements() != NumElts)
return nullptr;
for (unsigned i = 0, e = NumElts; i != e; ++i) {
if (Inst->getArgOperand(i)->getType() != ST->getElementType(i))
return nullptr;
}
Value *Res = UndefValue::get(ExpectedType);
IRBuilder<> Builder(Inst);
for (unsigned i = 0, e = NumElts; i != e; ++i) {
Value *L = Inst->getArgOperand(i);
Res = Builder.CreateInsertValue(Res, L, i);
}
return Res;
}
case Intrinsic::aarch64_neon_ld2:
case Intrinsic::aarch64_neon_ld3:
case Intrinsic::aarch64_neon_ld4:
if (Inst->getType() == ExpectedType)
return Inst;
return nullptr;
}
}
示例4: getTypeName
string llvm_type::getTypeName() {
if (data->isStructTy()) {
StructType* st = (StructType*) data;
return st->getName().str();
}
return "";
}
示例5: getTypeAlignment
/// Returns the byte alignment of this type
unsigned getTypeAlignment(const llvm::Type* type)
{
using namespace llvm;
// Array types are aligned to their element type
if (const ArrayType* psAT = dyn_cast<ArrayType>(type))
{
return getTypeAlignment(psAT->getElementType());
}
// Struct alignment is the size of its largest contained type
if (const StructType* structT = dyn_cast<StructType>(type))
{
if (structT->isPacked())
return 1;
StructType* nonConstTy = const_cast<StructType*>(structT);
unsigned uAlign = 0, uMaxAlign = 1;
unsigned uCount = structT->getNumElements();
for (unsigned i = 0; i < uCount; i++)
{
const Type* psElemType = nonConstTy->getTypeAtIndex(i);
uAlign = getTypeAlignment(psElemType);
if (uAlign > uMaxAlign)
uMaxAlign = uAlign;
}
return uMaxAlign;
}
return getTypeSize(type);
}
示例6: SplitUpStore
static bool SplitUpStore(StoreInst *Store, const DataLayout *DL) {
StructType *STy = cast<StructType>(Store->getValueOperand()->getType());
bool NeedsAnotherPass = false;
// Create a separate store instruction for each struct field.
for (unsigned Index = 0; Index < STy->getNumElements(); ++Index) {
SmallVector<Value *, 2> Indexes;
Indexes.push_back(ConstantInt::get(Store->getContext(), APInt(32, 0)));
Indexes.push_back(ConstantInt::get(Store->getContext(), APInt(32, Index)));
Value *GEP =
CopyDebug(GetElementPtrInst::Create(STy,
Store->getPointerOperand(), Indexes,
Store->getPointerOperand()->getName() + ".index", Store),
Store);
NeedsAnotherPass =
NeedsAnotherPass || DoAnotherPass(GEP->getType()->getContainedType(0));
SmallVector<unsigned, 1> EVIndexes;
EVIndexes.push_back(Index);
Value *Field = ExtractValueInst::Create(Store->getValueOperand(), EVIndexes,
"", Store);
StoreInst *NewStore = new StoreInst(Field, GEP, Store);
ProcessLoadOrStoreAttrs(NewStore, Store, STy, Index, DL);
}
Store->eraseFromParent();
return NeedsAnotherPass;
}
示例7: SplitUpLoad
static void SplitUpLoad(LoadInst *Load) {
StructType *STy = cast<StructType>(Load->getType());
Value *NewStruct = UndefValue::get(STy);
// Create a separate load instruction for each struct field.
for (unsigned Index = 0; Index < STy->getNumElements(); ++Index) {
SmallVector<Value *, 2> Indexes;
Indexes.push_back(ConstantInt::get(Load->getContext(), APInt(32, 0)));
Indexes.push_back(ConstantInt::get(Load->getContext(), APInt(32, Index)));
Value *GEP = CopyDebug(
GetElementPtrInst::Create(Load->getPointerOperand(), Indexes,
Load->getName() + ".index", Load), Load);
LoadInst *NewLoad = new LoadInst(GEP, Load->getName() + ".field", Load);
ProcessLoadOrStoreAttrs(NewLoad, Load);
// Reconstruct the struct value.
SmallVector<unsigned, 1> EVIndexes;
EVIndexes.push_back(Index);
NewStruct = CopyDebug(
InsertValueInst::Create(NewStruct, NewLoad, EVIndexes,
Load->getName() + ".insert", Load), Load);
}
Load->replaceAllUsesWith(NewStruct);
Load->eraseFromParent();
}
示例8: Visit
void TypeDeduction::Visit(MemberExpression* node)
{
//TODO: Finish it.
node->GetContainer()->Accept(this);
StructType *structType = dynamic_cast<StructType *>(node->GetContainer()->GetTag<Type>("Type"));
if (structType == NULL)
{
CompilationContext::GetInstance()->ReportError(node->SourceLocation, false, "Member expression requires struct type.");
}
std::vector<Declaration *> * fileds = structType->GetFieldList();
for (std::vector<Declaration *>::iterator it = fileds->begin(); it != fileds->end(); ++it)
{
Declaration *decl = *it;
if (decl->GetName() == node->GetFieldName())
{
Type *fieldType = decl->GetType();
node->SetTag<Type>("Type", fieldType);
return;
}
}
CompilationContext::GetInstance()->ReportError(node->SourceLocation, false, "%s is not a member of type %s", node->GetFieldName().c_str(), structType->ToString().c_str());
abort();
}
示例9: if
FunctionType* ArgumentRecovery::createFunctionType(TargetInfo& info, const CallInformation& callInfo, llvm::Module& module, StringRef returnTypeName, SmallVectorImpl<string>& parameterNames)
{
LLVMContext& ctx = module.getContext();
Type* integer = Type::getIntNTy(ctx, info.getPointerSize() * CHAR_BIT);
SmallVector<Type*, 8> parameterTypes;
for (const auto& param : callInfo.parameters())
{
if (param.type == ValueInformation::IntegerRegister)
{
parameterTypes.push_back(integer);
parameterNames.push_back(param.registerInfo->name);
}
else if (param.type == ValueInformation::Stack)
{
parameterTypes.push_back(integer);
parameterNames.emplace_back();
raw_string_ostream(parameterNames.back()) << "sp" << param.frameBaseOffset;
}
else
{
llvm_unreachable("not implemented");
}
}
SmallVector<Type*, 2> returnTypes;
for (const auto& ret : callInfo.returns())
{
if (ret.type == ValueInformation::IntegerRegister)
{
returnTypes.push_back(integer);
}
else
{
llvm_unreachable("not implemented");
}
}
Type* returnType;
if (returnTypes.size() == 0)
{
returnType = Type::getVoidTy(ctx);
}
else if (returnTypes.size() == 1)
{
returnType = returnTypes.front();
}
else
{
StructType* structTy = StructType::create(ctx, returnTypeName);
structTy->setBody(returnTypes);
md::setRecoveredReturnFieldNames(module, *structTy, callInfo);
returnType = structTy;
}
assert(!callInfo.isVararg() && "not implemented");
return FunctionType::get(returnType, parameterTypes, false);
}
示例10: assert
void GcInfo::getGcPointers(StructType *StructTy, const DataLayout &DataLayout,
SmallVector<uint32_t, 4> &Pointers) {
assert(StructTy->isSized());
const uint32_t PointerSize = DataLayout.getPointerSize();
const uint32_t TypeSize = DataLayout.getTypeStoreSize(StructTy);
const StructLayout *MainStructLayout = DataLayout.getStructLayout(StructTy);
// Walk through the type in pointer-sized jumps.
for (uint32_t GcOffset = 0; GcOffset < TypeSize; GcOffset += PointerSize) {
const uint32_t FieldIndex =
MainStructLayout->getElementContainingOffset(GcOffset);
Type *FieldTy = StructTy->getStructElementType(FieldIndex);
// If the field is a value class we need to dive in
// to its fields and so on, until we reach a primitive type.
if (FieldTy->isStructTy()) {
// Prepare to loop through the nesting.
const StructLayout *OuterStructLayout = MainStructLayout;
uint32_t OuterOffset = GcOffset;
uint32_t OuterIndex = FieldIndex;
while (FieldTy->isStructTy()) {
// Offset of the Inner class within the outer class
const uint32_t InnerBaseOffset =
OuterStructLayout->getElementOffset(OuterIndex);
// Inner class should start at or before the outer offset
assert(InnerBaseOffset <= OuterOffset);
// Determine target offset relative to this inner class.
const uint32_t InnerOffset = OuterOffset - InnerBaseOffset;
// Get the inner class layout
StructType *InnerStructTy = cast<StructType>(FieldTy);
const StructLayout *InnerStructLayout =
DataLayout.getStructLayout(InnerStructTy);
// Find the field at that target offset.
const uint32_t InnerIndex =
InnerStructLayout->getElementContainingOffset(InnerOffset);
// Update for next iteration.
FieldTy = InnerStructTy->getStructElementType(InnerIndex);
OuterStructLayout = InnerStructLayout;
OuterOffset = InnerOffset;
OuterIndex = InnerIndex;
}
}
if (GcInfo::isGcPointer(FieldTy)) {
Pointers.push_back(GcOffset);
}
}
}
示例11: AddStruct
void Library::AddStruct(const StructType &structType) {
if (m_RegisteredStruct.find(structType.GetName()) != m_RegisteredStruct.end()) {
return;
}
m_RegisteredStruct.insert(structType.GetName());
for (auto it : structType.GetArgs()) {
std::shared_ptr<StructType> st = it->GetStructType();
if (st.get() != nullptr) {
AddStruct(*st);
}
}
structType.EmitForwardDeclaration(m_Stream);
}
示例12: assert
void ExportPass::ConstructModuleSymbols()
{
CProcedureType* originalType = dynamic_cast<CProcedureType*>(originalProcedure->get_procedure_symbol()->get_type()) ;
assert(originalType != NULL) ;
// The original type takes and returns a struct. We need to change this
// to a list of arguments.
VoidType* newReturnType = create_void_type(theEnv, IInteger(0), 0) ;
constructedType = create_c_procedure_type(theEnv,
newReturnType,
false, // has varargs
true, // arguments_known
0, // bit alignment
LString("ConstructedType")) ;
StructType* returnType =
dynamic_cast<StructType*>(originalType->get_result_type()) ;
assert(returnType != NULL) ;
SymbolTable* structSymTab = returnType->get_group_symbol_table() ;
assert(structSymTab != NULL) ;
for (int i = 0 ; i < structSymTab->get_symbol_table_object_count() ; ++i)
{
VariableSymbol* nextVariable =
dynamic_cast<VariableSymbol*>(structSymTab->get_symbol_table_object(i));
if (nextVariable != NULL)
{
// Check to see if this is an output or not
QualifiedType* cloneType ;
DataType* cloneBase =
dynamic_cast<DataType*>(nextVariable->get_type()->get_base_type()->deep_clone()) ;
assert(cloneBase != NULL) ;
cloneType = create_qualified_type(theEnv, cloneBase) ;
if (nextVariable->lookup_annote_by_name("Output") != NULL)
{
cloneType->append_annote(create_brick_annote(theEnv, "Output")) ;
// Why doesn't this stick around?
}
constructedType->append_argument(cloneType) ;
}
}
constructedSymbol = create_procedure_symbol(theEnv,
constructedType,
originalProcedure->get_procedure_symbol()->get_name()) ;
constructedSymbol->set_definition(NULL) ;
}
示例13: StripTypeNames
// Strip any named types of their names.
static void StripTypeNames(Module &M, bool PreserveDbgInfo) {
std::vector<StructType*> StructTypes;
M.findUsedStructTypes(StructTypes);
for (unsigned i = 0, e = StructTypes.size(); i != e; ++i) {
StructType *STy = StructTypes[i];
if (STy->isAnonymous() || STy->getName().empty()) continue;
if (PreserveDbgInfo && STy->getName().startswith("llvm.dbg"))
continue;
STy->setName("");
}
}
示例14: insertCounterUpdate
bool EfficiencySanitizer::instrumentGetElementPtr(Instruction *I, Module &M) {
GetElementPtrInst *GepInst = dyn_cast<GetElementPtrInst>(I);
bool Res = false;
if (GepInst == nullptr || GepInst->getNumIndices() == 1) {
++NumIgnoredGEPs;
return false;
}
Type *SourceTy = GepInst->getSourceElementType();
StructType *StructTy = nullptr;
ConstantInt *Idx;
// Check if GEP calculates address from a struct array.
if (isa<StructType>(SourceTy)) {
StructTy = cast<StructType>(SourceTy);
Idx = dyn_cast<ConstantInt>(GepInst->getOperand(1));
if ((Idx == nullptr || Idx->getSExtValue() != 0) &&
!shouldIgnoreStructType(StructTy) && StructTyMap.count(StructTy) != 0)
Res |= insertCounterUpdate(I, StructTy, getArrayCounterIdx(StructTy));
}
// Iterate all (except the first and the last) idx within each GEP instruction
// for possible nested struct field address calculation.
for (unsigned i = 1; i < GepInst->getNumIndices(); ++i) {
SmallVector<Value *, 8> IdxVec(GepInst->idx_begin(),
GepInst->idx_begin() + i);
Type *Ty = GetElementPtrInst::getIndexedType(SourceTy, IdxVec);
unsigned CounterIdx = 0;
if (isa<ArrayType>(Ty)) {
ArrayType *ArrayTy = cast<ArrayType>(Ty);
StructTy = dyn_cast<StructType>(ArrayTy->getElementType());
if (shouldIgnoreStructType(StructTy) || StructTyMap.count(StructTy) == 0)
continue;
// The last counter for struct array access.
CounterIdx = getArrayCounterIdx(StructTy);
} else if (isa<StructType>(Ty)) {
StructTy = cast<StructType>(Ty);
if (shouldIgnoreStructType(StructTy) || StructTyMap.count(StructTy) == 0)
continue;
// Get the StructTy's subfield index.
Idx = cast<ConstantInt>(GepInst->getOperand(i+1));
assert(Idx->getSExtValue() >= 0 &&
Idx->getSExtValue() < StructTy->getNumElements());
CounterIdx = getFieldCounterIdx(StructTy) + Idx->getSExtValue();
}
Res |= insertCounterUpdate(I, StructTy, CounterIdx);
}
if (Res)
++NumInstrumentedGEPs;
else
++NumIgnoredGEPs;
return Res;
}
示例15: ParseConstraints
/// Verify - Verify that the specified constraint string is reasonable for the
/// specified function type, and otherwise validate the constraint string.
bool InlineAsm::Verify(FunctionType *Ty, StringRef ConstStr) {
if (Ty->isVarArg()) return false;
ConstraintInfoVector Constraints = ParseConstraints(ConstStr);
// Error parsing constraints.
if (Constraints.empty() && !ConstStr.empty()) return false;
unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0;
unsigned NumIndirect = 0;
for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
switch (Constraints[i].Type) {
case InlineAsm::isOutput:
if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0)
return false; // outputs before inputs and clobbers.
if (!Constraints[i].isIndirect) {
++NumOutputs;
break;
}
++NumIndirect;
// FALLTHROUGH for Indirect Outputs.
case InlineAsm::isInput:
if (NumClobbers) return false; // inputs before clobbers.
++NumInputs;
break;
case InlineAsm::isClobber:
++NumClobbers;
break;
}
}
switch (NumOutputs) {
case 0:
if (!Ty->getReturnType()->isVoidTy()) return false;
break;
case 1:
if (Ty->getReturnType()->isStructTy()) return false;
break;
default:
StructType *STy = dyn_cast<StructType>(Ty->getReturnType());
if (!STy || STy->getNumElements() != NumOutputs)
return false;
break;
}
if (Ty->getNumParams() != NumInputs) return false;
return true;
}