本文整理汇总了C++中LLStructType::getContainedType方法的典型用法代码示例。如果您正苦于以下问题:C++ LLStructType::getContainedType方法的具体用法?C++ LLStructType::getContainedType怎么用?C++ LLStructType::getContainedType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LLStructType
的用法示例。
在下文中一共展示了LLStructType::getContainedType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: build_module_reference_and_ctor
// build ModuleReference and register function, to register the module info in the global linked list
static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo)
{
// build ctor type
LLFunctionType* fty = LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector<LLType*>(), false);
// build ctor name
std::string fname = "_D";
fname += gIR->dmodule->mangle();
fname += "16__moduleinfoCtorZ";
// build a function that registers the moduleinfo in the global moduleinfo linked list
LLFunction* ctor = LLFunction::Create(fty, LLGlobalValue::InternalLinkage, fname, gIR->module);
// provide the default initializer
LLStructType* modulerefTy = DtoModuleReferenceType();
LLConstant* mrefvalues[] = {
LLConstant::getNullValue(modulerefTy->getContainedType(0)),
llvm::ConstantExpr::getBitCast(moduleinfo, modulerefTy->getContainedType(1))
};
LLConstant* thismrefinit = LLConstantStruct::get(modulerefTy, llvm::ArrayRef<LLConstant*>(mrefvalues));
// create the ModuleReference node for this module
std::string thismrefname = "_D";
thismrefname += gIR->dmodule->mangle();
thismrefname += "11__moduleRefZ";
Loc loc;
LLGlobalVariable* thismref = getOrCreateGlobal(loc, *gIR->module,
modulerefTy, false, LLGlobalValue::InternalLinkage, thismrefinit,
thismrefname);
// make sure _Dmodule_ref is declared
LLConstant* mref = gIR->module->getNamedGlobal("_Dmodule_ref");
LLType *modulerefPtrTy = getPtrToType(modulerefTy);
if (!mref)
mref = new LLGlobalVariable(*gIR->module, modulerefPtrTy, false, LLGlobalValue::ExternalLinkage, NULL, "_Dmodule_ref");
mref = DtoBitCast(mref, getPtrToType(modulerefPtrTy));
// make the function insert this moduleinfo as the beginning of the _Dmodule_ref linked list
llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "moduleinfoCtorEntry", ctor);
IRBuilder<> builder(bb);
// debug info
gIR->DBuilder.EmitSubProgramInternal(fname.c_str(), fname.c_str());
// get current beginning
LLValue* curbeg = builder.CreateLoad(mref, "current");
// put current beginning as the next of this one
LLValue* gep = builder.CreateStructGEP(thismref, 0, "next");
builder.CreateStore(curbeg, gep);
// replace beginning
builder.CreateStore(thismref, mref);
// return
builder.CreateRetVoid();
return ctor;
}
示例2: DtoCreateNestedContext
void DtoCreateNestedContext(FuncDeclaration* fd) {
Logger::println("DtoCreateNestedContext for %s", fd->toChars());
LOG_SCOPE
DtoCreateNestedContextType(fd);
// construct nested variables array
if (!fd->nestedVars.empty())
{
IrFunction* irfunction = fd->ir.irFunc;
unsigned depth = irfunction->depth;
LLStructType *frameType = irfunction->frameType;
// Create frame for current function and append to frames list
// FIXME: alignment ?
LLValue* frame = 0;
if (fd->needsClosure())
frame = DtoGcMalloc(frameType, ".frame");
else
frame = DtoRawAlloca(frameType, 0, ".frame");
// copy parent frames into beginning
if (depth != 0) {
LLValue* src = irfunction->nestArg;
if (!src) {
assert(irfunction->thisArg);
assert(fd->isMember2());
LLValue* thisval = DtoLoad(irfunction->thisArg);
AggregateDeclaration* cd = fd->isMember2();
assert(cd);
assert(cd->vthis);
Logger::println("Indexing to 'this'");
if (cd->isStructDeclaration())
src = DtoExtractValue(thisval, cd->vthis->ir.irField->index, ".vthis");
else
src = DtoLoad(DtoGEPi(thisval, 0, cd->vthis->ir.irField->index, ".vthis"));
} else {
src = DtoLoad(src);
}
if (depth > 1) {
src = DtoBitCast(src, getVoidPtrType());
LLValue* dst = DtoBitCast(frame, getVoidPtrType());
DtoMemCpy(dst, src, DtoConstSize_t((depth-1) * PTRSIZE),
getABITypeAlign(getVoidPtrType()));
}
// Copy nestArg into framelist; the outer frame is not in the list of pointers
src = DtoBitCast(src, frameType->getContainedType(depth-1));
LLValue* gep = DtoGEPi(frame, 0, depth-1);
DtoAlignedStore(src, gep);
}
// store context in IrFunction
irfunction->nestedVar = frame;
// go through all nested vars and assign addresses where possible.
for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
{
VarDeclaration* vd = *i;
LLValue* gep = DtoGEPi(frame, 0, vd->ir.irLocal->nestedIndex, vd->toChars());
if (vd->isParameter()) {
Logger::println("nested param: %s", vd->toChars());
LOG_SCOPE
IrParameter* parm = vd->ir.irParam;
if (parm->arg->byref)
{
storeVariable(vd, gep);
}
else
{
Logger::println("Copying to nested frame");
// The parameter value is an alloca'd stack slot.
// Copy to the nesting frame and leave the alloca for
// the optimizers to clean up.
DtoStore(DtoLoad(parm->value), gep);
gep->takeName(parm->value);
parm->value = gep;
}
} else {
Logger::println("nested var: %s", vd->toChars());
assert(!vd->ir.irLocal->value);
vd->ir.irLocal->value = gep;
}
if (global.params.symdebug) {
LLSmallVector<LLValue*, 2> addr;
dwarfOpOffset(addr, frameType, vd->ir.irLocal->nestedIndex);
DtoDwarfLocalVariable(frame, vd, addr);
}
}
}
}
示例3: DtoCreateNestedContext
//.........这里部分代码省略.........
frame = DtoRawAlloca(frameType, 0, ".frame");
// copy parent frames into beginning
if (depth != 0) {
LLValue* src = irfunction->nestArg;
if (!src) {
assert(irfunction->thisArg);
assert(fd->isMember2());
LLValue* thisval = DtoLoad(irfunction->thisArg);
#if DMDV2
AggregateDeclaration* cd = fd->isMember2();
#else
ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
#endif
assert(cd);
assert(cd->vthis);
Logger::println("Indexing to 'this'");
#if DMDV2
if (cd->isStructDeclaration())
src = DtoExtractValue(thisval, cd->vthis->ir.irField->index, ".vthis");
else
#endif
src = DtoLoad(DtoGEPi(thisval, 0, cd->vthis->ir.irField->index, ".vthis"));
} else {
src = DtoLoad(src);
}
if (depth > 1) {
src = DtoBitCast(src, getVoidPtrType());
LLValue* dst = DtoBitCast(frame, getVoidPtrType());
DtoMemCpy(dst, src, DtoConstSize_t((depth-1) * PTRSIZE),
getABITypeAlign(getVoidPtrType()));
}
// Copy nestArg into framelist; the outer frame is not in the list of pointers
src = DtoBitCast(src, frameType->getContainedType(depth-1));
LLValue* gep = DtoGEPi(frame, 0, depth-1);
DtoAlignedStore(src, gep);
}
// store context in IrFunction
irfunction->nestedVar = frame;
// go through all nested vars and assign addresses where possible.
for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
{
VarDeclaration* vd = *i;
LLValue* gep = DtoGEPi(frame, 0, vd->ir.irLocal->nestedIndex, vd->toChars());
if (vd->isParameter()) {
Logger::println("nested param: %s", vd->toChars());
LOG_SCOPE
LLValue* value = vd->ir.irLocal->value;
if (llvm::isa<llvm::AllocaInst>(llvm::GetUnderlyingObject(value))) {
Logger::println("Copying to nested frame");
// The parameter value is an alloca'd stack slot.
// Copy to the nesting frame and leave the alloca for
// the optimizers to clean up.
assert(!vd->ir.irLocal->byref);
DtoStore(DtoLoad(value), gep);
gep->takeName(value);
vd->ir.irLocal->value = gep;
} else {
Logger::println("Adding pointer to nested frame");
// The parameter value is something else, such as a
// passed-in pointer (for 'ref' or 'out' parameters) or
// a pointer arg with byval attribute.
// Store the address into the frame.
assert(vd->ir.irLocal->byref);
storeVariable(vd, gep);
}
} else if (vd->isRef() || vd->isOut()) {
// This slot is initialized in DtoNestedInit, to handle things like byref foreach variables
// which move around in memory.
assert(vd->ir.irLocal->byref);
} else {
Logger::println("nested var: %s", vd->toChars());
if (vd->ir.irLocal->value)
Logger::cout() << "Pre-existing value: " << *vd->ir.irLocal->value << '\n';
assert(!vd->ir.irLocal->value);
vd->ir.irLocal->value = gep;
assert(!vd->ir.irLocal->byref);
}
if (global.params.symdebug) {
LLSmallVector<LLValue*, 2> addr;
dwarfOpOffset(addr, frameType, vd->ir.irLocal->nestedIndex);
DtoDwarfLocalVariable(frame, vd, addr);
}
}
} else if (FuncDeclaration* parFunc = getParentFunc(fd, true)) {
// Propagate context arg properties if the context arg is passed on unmodified.
DtoDeclareFunction(parFunc);
fd->ir.irFunc->frameType = parFunc->ir.irFunc->frameType;
fd->ir.irFunc->depth = parFunc->ir.irFunc->depth;
}
}
else {
assert(0 && "Not implemented yet");
}
}