本文整理汇总了C++中LLValue类的典型用法代码示例。如果您正苦于以下问题:C++ LLValue类的具体用法?C++ LLValue怎么用?C++ LLValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LLValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DtoInitClass
void DtoInitClass(TypeClass* tc, LLValue* dst)
{
tc->sym->codegen(Type::sir);
uint64_t n = tc->sym->structsize - PTRSIZE * 2;
// set vtable field seperately, this might give better optimization
LLValue* tmp = DtoGEPi(dst,0,0,"vtbl");
LLValue* val = DtoBitCast(tc->sym->ir.irStruct->getVtblSymbol(), tmp->getType()->getContainedType(0));
DtoStore(val, tmp);
// monitor always defaults to zero
tmp = DtoGEPi(dst,0,1,"monitor");
val = LLConstant::getNullValue(tmp->getType()->getContainedType(0));
DtoStore(val, tmp);
// done?
if (n == 0)
return;
// copy the rest from the static initializer
LLValue* dstarr = DtoGEPi(dst,0,2,"tmp");
// init symbols might not have valid types
LLValue* initsym = tc->sym->ir.irStruct->getInitSymbol();
initsym = DtoBitCast(initsym, DtoType(tc));
LLValue* srcarr = DtoGEPi(initsym,0,2,"tmp");
DtoMemCpy(dstarr, srcarr, DtoConstSize_t(n));
}
示例2: DtoBinFloatsEquals
LLValue* DtoBinFloatsEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op)
{
LLValue* res = 0;
#if DMDV2
if (op == TOKequal) {
res = gIR->ir->CreateFCmpOEQ(lhs->getRVal(), rhs->getRVal(), "tmp");
} else if (op == TOKnotequal) {
res = gIR->ir->CreateFCmpUNE(lhs->getRVal(), rhs->getRVal(), "tmp");
} else {
llvm::ICmpInst::Predicate cmpop;
if (op == TOKidentity)
cmpop = llvm::ICmpInst::ICMP_EQ;
else
cmpop = llvm::ICmpInst::ICMP_NE;
LLValue* sz = DtoConstSize_t(getTypeStoreSize(DtoType(lhs->getType())));
LLValue* val = DtoMemCmp(makeLValue(loc, lhs), makeLValue(loc, rhs), sz);
res = gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp");
}
#else
LLValue* lv = lhs->getRVal();
LLValue* rv = rhs->getRVal();
res = (op == TOKidentity || op == TOKequal) ?
gIR->ir->CreateFCmpOEQ(lv, rv, "tmp") :
gIR->ir->CreateFCmpUNE(lv, rv, "tmp");
#endif
assert(res);
return res;
}
示例3: DtoInitClass
void DtoInitClass(TypeClass* tc, LLValue* dst)
{
DtoResolveClass(tc->sym);
// Set vtable field. Doing this seperately might be optimized better.
LLValue* tmp = DtoGEPi(dst, 0, 0, "vtbl");
LLValue* val = DtoBitCast(getIrAggr(tc->sym)->getVtblSymbol(),
tmp->getType()->getContainedType(0));
DtoStore(val, tmp);
// For D classes, set the monitor field to null.
const bool isCPPclass = tc->sym->isCPPclass() ? true : false;
if (!isCPPclass)
{
tmp = DtoGEPi(dst, 0, 1, "monitor");
val = LLConstant::getNullValue(tmp->getType()->getContainedType(0));
DtoStore(val, tmp);
}
// Copy the rest from the static initializer, if any.
unsigned const firstDataIdx = isCPPclass ? 1 : 2;
uint64_t const dataBytes = tc->sym->structsize - Target::ptrsize * firstDataIdx;
if (dataBytes == 0)
return;
LLValue* dstarr = DtoGEPi(dst, 0, firstDataIdx);
// init symbols might not have valid types
LLValue* initsym = getIrAggr(tc->sym)->getInitSymbol();
initsym = DtoBitCast(initsym, DtoType(tc));
LLValue* srcarr = DtoGEPi(initsym, 0, firstDataIdx);
DtoMemCpy(dstarr, srcarr, DtoConstSize_t(dataBytes));
}
示例4: DtoDynamicCastObject
DValue* DtoDynamicCastObject(DValue* val, Type* _to)
{
// call:
// Object _d_dynamic_cast(Object o, ClassInfo c)
ClassDeclaration::object->codegen(Type::sir);
ClassDeclaration::classinfo->codegen(Type::sir);
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast");
LLFunctionType* funcTy = func->getFunctionType();
// Object o
LLValue* obj = val->getRVal();
obj = DtoBitCast(obj, funcTy->getParamType(0));
assert(funcTy->getParamType(0) == obj->getType());
// ClassInfo c
TypeClass* to = static_cast<TypeClass*>(_to->toBasetype());
to->sym->codegen(Type::sir);
LLValue* cinfo = to->sym->ir.irAggr->getClassInfoSymbol();
// unfortunately this is needed as the implementation of object differs somehow from the declaration
// this could happen in user code as well :/
cinfo = DtoBitCast(cinfo, funcTy->getParamType(1));
assert(funcTy->getParamType(1) == cinfo->getType());
// call it
LLValue* ret = gIR->CreateCallOrInvoke2(func, obj, cinfo, "tmp").getInstruction();
// cast return value
ret = DtoBitCast(ret, DtoType(_to));
return new DImValue(_to, ret);
}
示例5: if
static LLValue *call_string_switch_runtime(llvm::Value *table, Expression *e) {
Type *dt = e->type->toBasetype();
Type *dtnext = dt->nextOf()->toBasetype();
TY ty = dtnext->ty;
const char *fname;
if (ty == Tchar) {
fname = "_d_switch_string";
} else if (ty == Twchar) {
fname = "_d_switch_ustring";
} else if (ty == Tdchar) {
fname = "_d_switch_dstring";
} else {
llvm_unreachable("not char/wchar/dchar");
}
llvm::Function *fn = getRuntimeFunction(e->loc, gIR->module, fname);
IF_LOG {
Logger::cout() << *table->getType() << '\n';
Logger::cout() << *fn->getFunctionType()->getParamType(0) << '\n';
}
assert(table->getType() == fn->getFunctionType()->getParamType(0));
DValue *val = toElemDtor(e);
LLValue *llval = val->getRVal();
assert(llval->getType() == fn->getFunctionType()->getParamType(1));
LLCallSite call = gIR->CreateCallOrInvoke(fn, table, llval);
return call.getInstruction();
}
示例6: DtoRawAlloca
LLValue *prepareVaStart(DLValue *ap) override {
// Since the user only created a char* pointer (ap) on the stack before
// invoking va_start, we first need to allocate the actual __va_list struct
// and set `ap` to its address.
LLValue *valistmem = DtoRawAlloca(getValistType(), 0, "__va_list_mem");
DtoStore(valistmem,
DtoBitCast(DtoLVal(ap), getPtrToType(valistmem->getType())));
// Pass a i8* pointer to the actual struct to LLVM's va_start intrinsic.
return DtoBitCast(valistmem, getVoidPtrType());
}
示例7: vaCopy
void vaCopy(DLValue *dest, DValue *src) override {
// Analog to va_start, we first need to allocate a new __va_list struct on
// the stack and set `dest` to its address.
LLValue *valistmem = DtoRawAlloca(getValistType(), 0, "__va_list_mem");
DtoStore(valistmem,
DtoBitCast(DtoLVal(dest), getPtrToType(valistmem->getType())));
// Then fill the new struct with a bitcopy of the source struct.
// `src` is a char* pointer to the source struct.
DtoMemCpy(valistmem, DtoRVal(src));
}
示例8: DtoAAIn
DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key)
{
// D1:
// call:
// extern(C) void* _aaIn(AA aa*, TypeInfo keyti, void* pkey)
// D2:
// call:
// extern(C) void* _aaInX(AA aa*, TypeInfo keyti, void* pkey)
// first get the runtime function
#if DMDV2
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaInX");
#else
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaIn");
#endif
LLFunctionType* funcTy = func->getFunctionType();
if (Logger::enabled())
Logger::cout() << "_aaIn = " << *func << '\n';
// aa param
LLValue* aaval = aa->getRVal();
if (Logger::enabled())
{
Logger::cout() << "aaval: " << *aaval << '\n';
Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\n';
}
aaval = DtoBitCast(aaval, funcTy->getParamType(0));
// keyti param
#if DMDV2
LLValue* keyti = to_keyti(aa);
#else
LLValue* keyti = to_keyti(key);
#endif
keyti = DtoBitCast(keyti, funcTy->getParamType(1));
// pkey param
LLValue* pkey = makeLValue(loc, key);
pkey = DtoBitCast(pkey, getVoidPtrType());
// call runtime
LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in").getInstruction();
// cast return value
LLType* targettype = DtoType(type);
if (ret->getType() != targettype)
ret = DtoBitCast(ret, targettype);
return new DImValue(type, ret);
}
示例9: llvm_unreachable
LLValue *DLValue::getRVal() {
if (DtoIsInMemoryOnly(type->toBasetype())) {
llvm_unreachable("getRVal() for memory-only type");
return nullptr;
}
LLValue *rawValue = DtoLoad(val);
if (type->toBasetype()->ty != Tbool)
return rawValue;
assert(rawValue->getType() == llvm::Type::getInt8Ty(gIR->context()));
return gIR->ir->CreateTrunc(rawValue, llvm::Type::getInt1Ty(gIR->context()));
}
示例10: get
// Get struct from ABI-mangled representation
LLValue* get(Type* dty, DValue* v)
{
LLValue* lval;
if (v->isLVal()) {
lval = v->getLVal();
} else {
// No memory location, create one.
LLValue* rval = v->getRVal();
lval = DtoRawAlloca(rval->getType(), 0);
DtoStore(rval, lval);
}
LLType* pTy = getPtrToType(DtoType(dty));
return DtoLoad(DtoBitCast(lval, pTy), "get-result");
}
示例11: DtoResolveNestedContext
void DtoResolveNestedContext(Loc loc, ClassDeclaration *decl, LLValue *value)
#endif
{
Logger::println("Resolving nested context");
LOG_SCOPE;
// get context
LLValue* nest = DtoNestedContext(loc, decl);
// store into right location
if (!llvm::dyn_cast<llvm::UndefValue>(nest)) {
size_t idx = decl->vthis->ir.irField->index;
LLValue* gep = DtoGEPi(value,0,idx,".vthis");
DtoStore(DtoBitCast(nest, gep->getType()->getContainedType(0)), gep);
}
}
示例12: DtoStructEquals
LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs)
{
Type* t = lhs->getType()->toBasetype();
assert(t->ty == Tstruct);
// set predicate
llvm::ICmpInst::Predicate cmpop;
if (op == TOKequal || op == TOKidentity)
cmpop = llvm::ICmpInst::ICMP_EQ;
else
cmpop = llvm::ICmpInst::ICMP_NE;
// call memcmp
size_t sz = getTypePaddedSize(DtoType(t));
LLValue* val = DtoMemCmp(lhs->getRVal(), rhs->getRVal(), DtoConstSize_t(sz));
return gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp");
}
示例13: put
// Turn a struct into an ABI-mangled representation
LLValue* put(Type* dty, DValue* v)
{
LLValue* lval;
if (v->isLVal()) {
lval = v->getLVal();
} else {
// No memory location, create one.
LLValue* rval = v->getRVal();
lval = DtoRawAlloca(rval->getType(), 0);
DtoStore(rval, lval);
}
LLType* abiTy = getAbiType(dty);
assert(abiTy && "Why are we rewriting a non-rewritten type?");
LLType* pTy = getPtrToType(abiTy);
return DtoLoad(DtoBitCast(lval, pTy), "put-result");
}
示例14: emitPointerOffset
DValue *binMin(Loc &loc, Type *type, DValue *lhs, Expression *rhs,
bool loadLhsAfterRhs) {
Type *lhsType = lhs->type->toBasetype();
Type *rhsType = rhs->type->toBasetype();
if (lhsType != rhsType && lhsType->ty == Tpointer && rhsType->isintegral()) {
Logger::println("Subtracting integer from pointer");
return emitPointerOffset(loc, lhs, rhs, true, type, loadLhsAfterRhs);
}
auto rvals = evalSides(lhs, rhs, loadLhsAfterRhs);
if (lhsType->ty == Tpointer && rhsType->ty == Tpointer) {
LLValue *l = DtoRVal(rvals.lhs);
LLValue *r = DtoRVal(rvals.rhs);
LLType *llSizeT = DtoSize_t();
l = gIR->ir->CreatePtrToInt(l, llSizeT);
r = gIR->ir->CreatePtrToInt(r, llSizeT);
LLValue *diff = gIR->ir->CreateSub(l, r);
LLType *llType = DtoType(type);
if (diff->getType() != llType)
diff = gIR->ir->CreateIntToPtr(diff, llType);
return new DImValue(type, diff);
}
if (type->ty == Tnull)
return DtoNullValue(type, loc);
if (type->iscomplex())
return DtoComplexMin(loc, type, rvals.lhs, rvals.rhs);
LLValue *l = DtoRVal(DtoCast(loc, rvals.lhs, type));
LLValue *r = DtoRVal(DtoCast(loc, rvals.rhs, type));
if (auto aa = isAssociativeArrayAndNull(type, l, r))
return aa;
LLValue *res = (type->isfloating() ? gIR->ir->CreateFSub(l, r)
: gIR->ir->CreateSub(l, r));
return new DImValue(type, res);
}
示例15: DtoStructEquals
LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs)
{
Type* t = lhs->getType()->toBasetype();
assert(t->ty == Tstruct);
// set predicate
llvm::ICmpInst::Predicate cmpop;
if (op == TOKequal || op == TOKidentity)
cmpop = llvm::ICmpInst::ICMP_EQ;
else
cmpop = llvm::ICmpInst::ICMP_NE;
// empty struct? EQ always true, NE always false
if (static_cast<TypeStruct*>(t)->sym->fields.dim == 0)
return DtoConstBool(cmpop == llvm::ICmpInst::ICMP_EQ);
// call memcmp
size_t sz = getTypePaddedSize(DtoType(t));
LLValue* val = DtoMemCmp(lhs->getRVal(), rhs->getRVal(), DtoConstSize_t(sz));
return gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false));
}