本文整理汇总了C++中IRGenFunction::getTypeInfoForUnlowered方法的典型用法代码示例。如果您正苦于以下问题:C++ IRGenFunction::getTypeInfoForUnlowered方法的具体用法?C++ IRGenFunction::getTypeInfoForUnlowered怎么用?C++ IRGenFunction::getTypeInfoForUnlowered使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRGenFunction
的用法示例。
在下文中一共展示了IRGenFunction::getTypeInfoForUnlowered方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: os
void
irgen::emitTypeLayoutVerifier(IRGenFunction &IGF,
ArrayRef<CanType> formalTypes) {
llvm::Type *verifierArgTys[] = {
IGF.IGM.TypeMetadataPtrTy,
IGF.IGM.Int8PtrTy,
IGF.IGM.Int8PtrTy,
IGF.IGM.SizeTy,
IGF.IGM.Int8PtrTy,
};
auto verifierFnTy = llvm::FunctionType::get(IGF.IGM.VoidTy,
verifierArgTys,
/*var arg*/ false);
auto verifierFn = IGF.IGM.Module.getOrInsertFunction(
"_swift_debug_verifyTypeLayoutAttribute",
verifierFnTy);
struct VerifierArgumentBuffers {
Address runtimeBuf, staticBuf;
};
llvm::DenseMap<llvm::Type *, VerifierArgumentBuffers>
verifierArgBufs;
auto getSizeConstant = [&](Size sz) -> llvm::Constant * {
return llvm::ConstantInt::get(IGF.IGM.SizeTy, sz.getValue());
};
auto getAlignmentMaskConstant = [&](Alignment a) -> llvm::Constant * {
return llvm::ConstantInt::get(IGF.IGM.SizeTy, a.getValue() - 1);
};
auto getBoolConstant = [&](bool b) -> llvm::Constant * {
return llvm::ConstantInt::get(IGF.IGM.Int1Ty, b);
};
SmallString<20> numberBuf;
for (auto formalType : formalTypes) {
// Runtime type metadata always represents the maximal abstraction level of
// the type.
auto anyTy = ProtocolCompositionType::get(IGF.IGM.Context, {});
auto openedAnyTy = ArchetypeType::getOpened(anyTy);
auto maxAbstraction = AbstractionPattern(openedAnyTy);
auto &ti = IGF.getTypeInfoForUnlowered(maxAbstraction, formalType);
// If there's no fixed type info, we rely on the runtime anyway, so there's
// nothing to verify.
// TODO: There are some traits of partially-fixed layouts we could check too.
auto *fixedTI = dyn_cast<FixedTypeInfo>(&ti);
if (!fixedTI)
return;
auto metadata = IGF.emitTypeMetadataRef(formalType);
auto verify = [&](llvm::Value *runtimeVal,
llvm::Value *staticVal,
const llvm::Twine &description) {
assert(runtimeVal->getType() == staticVal->getType());
// Get or create buffers for the arguments.
VerifierArgumentBuffers bufs;
auto foundBufs = verifierArgBufs.find(runtimeVal->getType());
if (foundBufs != verifierArgBufs.end()) {
bufs = foundBufs->second;
} else {
Address runtimeBuf = IGF.createAlloca(runtimeVal->getType(),
IGF.IGM.getPointerAlignment(),
"runtime");
Address staticBuf = IGF.createAlloca(staticVal->getType(),
IGF.IGM.getPointerAlignment(),
"static");
bufs = {runtimeBuf, staticBuf};
verifierArgBufs[runtimeVal->getType()] = bufs;
}
IGF.Builder.CreateStore(runtimeVal, bufs.runtimeBuf);
IGF.Builder.CreateStore(staticVal, bufs.staticBuf);
auto runtimePtr = IGF.Builder.CreateBitCast(bufs.runtimeBuf.getAddress(),
IGF.IGM.Int8PtrTy);
auto staticPtr = IGF.Builder.CreateBitCast(bufs.staticBuf.getAddress(),
IGF.IGM.Int8PtrTy);
auto count = llvm::ConstantInt::get(IGF.IGM.SizeTy,
IGF.IGM.DataLayout.getTypeStoreSize(runtimeVal->getType()));
auto msg
= IGF.IGM.getAddrOfGlobalString(description.str());
IGF.Builder.CreateCall(
verifierFn, {metadata, runtimePtr, staticPtr, count, msg});
};
// Check that the fixed layout matches the runtime layout.
SILType layoutType = SILType::getPrimitiveObjectType(formalType);
verify(emitLoadOfSize(IGF, layoutType),
getSizeConstant(fixedTI->getFixedSize()),
"size");
verify(emitLoadOfAlignmentMask(IGF, layoutType),
getAlignmentMaskConstant(fixedTI->getFixedAlignment()),
"alignment mask");
verify(emitLoadOfStride(IGF, layoutType),
getSizeConstant(fixedTI->getFixedStride()),
"stride");
verify(emitLoadOfIsInline(IGF, layoutType),
getBoolConstant(fixedTI->getFixedPacking(IGF.IGM)
//.........这里部分代码省略.........
示例2: emitBuiltinCall
//.........这里部分代码省略.........
if (origTy->isPointerTy())
value = IGF.Builder.CreateIntToPtr(value, origTy);
out.add(value);
return;
}
if (Builtin.ID == BuiltinValueKind::AtomicLoad
|| Builtin.ID == BuiltinValueKind::AtomicStore) {
using namespace llvm;
SmallVector<Type, 4> Types;
StringRef BuiltinName = getBuiltinBaseName(IGF.IGM.Context,
FnId.str(), Types);
auto underscore = BuiltinName.find('_');
BuiltinName = BuiltinName.substr(underscore+1);
underscore = BuiltinName.find('_');
auto ordering = decodeLLVMAtomicOrdering(BuiltinName.substr(0, underscore));
assert(ordering != llvm::AtomicOrdering::NotAtomic);
BuiltinName = BuiltinName.substr(underscore);
// Accept volatile and singlethread if present.
bool isVolatile = BuiltinName.startswith("_volatile");
if (isVolatile) BuiltinName = BuiltinName.drop_front(strlen("_volatile"));
bool isSingleThread = BuiltinName.startswith("_singlethread");
if (isSingleThread)
BuiltinName = BuiltinName.drop_front(strlen("_singlethread"));
assert(BuiltinName.empty() && "Mismatch with sema");
auto pointer = args.claimNext();
auto &valueTI = IGF.getTypeInfoForUnlowered(Types[0]);
auto schema = valueTI.getSchema();
assert(schema.size() == 1 && "not a scalar type?!");
auto origValueTy = schema[0].getScalarType();
// If the type is floating-point, then we need to bitcast to integer.
auto valueTy = origValueTy;
if (valueTy->isFloatingPointTy()) {
valueTy = llvm::IntegerType::get(IGF.IGM.LLVMContext,
valueTy->getPrimitiveSizeInBits());
}
pointer = IGF.Builder.CreateBitCast(pointer, valueTy->getPointerTo());
if (Builtin.ID == BuiltinValueKind::AtomicLoad) {
auto load = IGF.Builder.CreateLoad(pointer,
valueTI.getBestKnownAlignment());
load->setAtomic(ordering, isSingleThread ? llvm::SyncScope::SingleThread
: llvm::SyncScope::System);
load->setVolatile(isVolatile);
llvm::Value *value = load;
if (valueTy != origValueTy)
value = IGF.Builder.CreateBitCast(value, origValueTy);
out.add(value);
return;
} else if (Builtin.ID == BuiltinValueKind::AtomicStore) {
llvm::Value *value = args.claimNext();
if (valueTy != origValueTy)
value = IGF.Builder.CreateBitCast(value, valueTy);
auto store = IGF.Builder.CreateStore(value, pointer,
valueTI.getBestKnownAlignment());
store->setAtomic(ordering, isSingleThread ? llvm::SyncScope::SingleThread