本文整理汇总了C++中rc::ConstHandle::llvmLValueToRValue方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstHandle::llvmLValueToRValue方法的具体用法?C++ ConstHandle::llvmLValueToRValue怎么用?C++ ConstHandle::llvmLValueToRValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rc::ConstHandle
的用法示例。
在下文中一共展示了ConstHandle::llvmLValueToRValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildExprValue
CG::ExprValue CreateConstValue::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const
{
if ( usage == CG::USAGE_LVALUE )
throw Exception( "cannot be used as l-values" );
CG::ExprType childExprType = m_child->getExprType( basicBlockBuilder );
RC::ConstHandle<CG::ValueProducerAdapter> valueProducerAdapter = basicBlockBuilder.getManager()->getValueProducerOf( childExprType.getAdapter() );
RC::Handle<CG::Context> context = basicBlockBuilder.getContext();
llvm::LLVMContext &llvmContext = context->getLLVMContext();
std::vector<llvm::Type const *> argTypes;
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) );
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) );
argTypes.push_back( valueProducerAdapter->llvmLType( context ) );
llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateConstValue", funcType );
CG::ExprValue childExprRValue = m_child->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
llvm::Value *childExprLValue = childExprType.getAdapter()->llvmRValueToLValue( basicBlockBuilder, childExprRValue.getValue() );
llvm::Value *resultLValue = valueProducerAdapter->llvmAlloca( basicBlockBuilder, "result" );
valueProducerAdapter->llvmInit( basicBlockBuilder, resultLValue );
basicBlockBuilder.getScope().put(
CG::VariableSymbol::Create(
CG::ExprValue(
valueProducerAdapter,
CG::USAGE_LVALUE,
context,
resultLValue
)
)
);
basicBlockBuilder->CreateCall3(
func,
valueProducerAdapter->llvmAdapterPtr( basicBlockBuilder ),
basicBlockBuilder->CreatePointerCast(
childExprLValue,
llvm::Type::getInt8PtrTy( llvmContext )
),
resultLValue
);
return CG::ExprValue(
valueProducerAdapter,
CG::USAGE_RVALUE,
context,
valueProducerAdapter->llvmLValueToRValue( basicBlockBuilder, resultLValue )
);
}
示例2: buildExprValue
CG::ExprValue CreateValueCache::buildExprValue( CG::BasicBlockBuilder &basicBlockBuilder, CG::Usage usage, std::string const &lValueErrorDesc ) const
{
if ( usage == CG::USAGE_LVALUE )
throw Exception( "cannot be used as l-values" );
RC::Handle<CG::Context> context = basicBlockBuilder.getContext();
llvm::LLVMContext &llvmContext = context->getLLVMContext();
CG::ExprType inputExprType = m_input->getExprType( basicBlockBuilder );
if ( !RT::isValueProducer( inputExprType.getAdapter()->getType() ) )
throw CG::Error( getLocation(), "input must be a value producer" );
RC::ConstHandle<CG::ValueProducerAdapter> valueProducerAdapter = RC::ConstHandle<CG::ValueProducerAdapter>::StaticCast( inputExprType.getAdapter() );
RC::ConstHandle<CG::Adapter> valueAdapter = valueProducerAdapter->getValueAdapter();
CG::ExprValue inputExprRValue = m_input->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
llvm::Value *resultLValue = valueProducerAdapter->llvmAlloca( basicBlockBuilder, "result" );
valueProducerAdapter->llvmInit( basicBlockBuilder, resultLValue );
basicBlockBuilder.getScope().put(
CG::VariableSymbol::Create(
CG::ExprValue(
valueProducerAdapter,
CG::USAGE_LVALUE,
context,
resultLValue
)
)
);
std::vector<llvm::Type const *> argTypes;
argTypes.push_back( valueProducerAdapter->llvmLType( context ) );
argTypes.push_back( valueProducerAdapter->llvmLType( context ) );
llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateValueCache", funcType );
basicBlockBuilder->CreateCall2(
func,
inputExprRValue.getValue(),
resultLValue
);
return CG::ExprValue(
valueProducerAdapter,
CG::USAGE_RVALUE,
context,
valueProducerAdapter->llvmLValueToRValue( basicBlockBuilder, resultLValue )
);
}
示例3: llvmThrowOutOfRangeException
//.........这里部分代码省略.........
subBasicBlockBuilder->CreateBr( goBB );
subBasicBlockBuilder->SetInsertPoint( goBB );
llvm::PHINode *errorDescConstStringRValue = subBasicBlockBuilder->CreatePHI( haveErrorDescConstStringRValue->getType(), "errorDescConstStringRValue" );
errorDescConstStringRValue->addIncoming( haveErrorDescConstStringRValue, haveErrorDescBB );
errorDescConstStringRValue->addIncoming( noErrorDescConstStringRValue, noErrorDescBB );
llvm::Value *errorMsg0RValue = stringAdapter->llvmCast(
subBasicBlockBuilder,
ExprValue( constStringAdapter, USAGE_RVALUE, context, errorDescConstStringRValue )
);
llvm::Value *errorMsgARValue = stringAdapter->llvmCast( subBasicBlockBuilder,
ExprValue( constStringAdapter, USAGE_RVALUE, context, constStringAdapter->llvmConst( subBasicBlockBuilder, ": " ) )
);
llvm::Value *errorMsgALValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsgA" );
stringAdapter->llvmInit( subBasicBlockBuilder, errorMsgALValue );
stringAdapter->llvmCallConcat(
subBasicBlockBuilder,
errorMsg0RValue,
errorMsgARValue,
errorMsgALValue
);
llvm::Value *errorMsgBRValue = stringAdapter->llvmCast( subBasicBlockBuilder,
ExprValue( constStringAdapter, USAGE_RVALUE, context, itemRValue )
);
llvm::Value *errorMsgBLValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsgB" );
stringAdapter->llvmInit( subBasicBlockBuilder, errorMsgBLValue );
stringAdapter->llvmCallConcat(
subBasicBlockBuilder,
stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsgALValue ),
errorMsgBRValue,
errorMsgBLValue
);
stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsgALValue );
llvm::Value *errorMsgCRValue = stringAdapter->llvmCast( subBasicBlockBuilder,
ExprValue( constStringAdapter, USAGE_RVALUE, context, constStringAdapter->llvmConst( subBasicBlockBuilder, " (" ) )
);
llvm::Value *errorMsgCLValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsgC" );
stringAdapter->llvmInit( subBasicBlockBuilder, errorMsgCLValue );
stringAdapter->llvmCallConcat(
subBasicBlockBuilder,
stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsgBLValue ),
errorMsgCRValue,
errorMsgCLValue
);
stringAdapter->llvmDispose( subBasicBlockBuilder, errorMsgBLValue );
llvm::Value *indexStringRValue = stringAdapter->llvmCast(
subBasicBlockBuilder,
ExprValue( sizeAdapter, USAGE_RVALUE, context, indexRValue )
);
llvm::Value *errorMsg1PlusIndexLValue = stringAdapter->llvmAlloca( subBasicBlockBuilder, "errorMsg1PlusIndex" );
stringAdapter->llvmInit( subBasicBlockBuilder, errorMsg1PlusIndexLValue );
stringAdapter->llvmCallConcat(
subBasicBlockBuilder,
stringAdapter->llvmLValueToRValue( subBasicBlockBuilder, errorMsgCLValue ),
indexStringRValue,
errorMsg1PlusIndexLValue
);
示例4: buildExprValue
//.........这里部分代码省略.........
CG::USAGE_LVALUE,
context,
resultLValue
)
)
);
bool needCall = true;
if ( operatorParams.size() >= 2 )
{
if ( operatorParams[1].getAdapter() != sizeAdapter )
throw CG::Error( getLocation(), "operator index parameter type (" + operatorParams[1].getAdapter()->getUserName() + ") must be 'Size'" );
if ( operatorParams[1].getUsage() != CG::USAGE_RVALUE )
throw CG::Error( getLocation(), "operator index parameter must be an 'in' parameter" );
if ( operatorParams.size() >= 3 )
{
if ( operatorParams[2].getAdapter() != sizeAdapter )
throw CG::Error( getLocation(), "operator index parameter type (" + operatorParams[2].getAdapter()->getUserName() + ") must be 'Size'" );
if ( operatorParams[2].getUsage() != CG::USAGE_RVALUE )
throw CG::Error( getLocation(), "operator index parameter must be an 'in' parameter" );
if ( operatorParams.size() >= 4 )
{
if ( operatorParams.size() > 4 )
throw MR::ArrayGeneratorOperator::GetPrototypeException();
if ( !m_shared )
throw CG::Error( getLocation(), "operator takes a shared value but no shared value is provided" );
CG::ExprType sharedExprType = m_shared->getExprType( basicBlockBuilder );
if ( !RT::isValueProducer( sharedExprType.getAdapter()->getType() ) )
throw CG::Error( getLocation(), "shared value must be a value producer" );
RC::ConstHandle<CG::ValueProducerAdapter> sharedValueProducerAdapter = RC::ConstHandle<CG::ValueProducerAdapter>::StaticCast( sharedExprType.getAdapter() );
RC::ConstHandle<CG::Adapter> sharedAdapter = sharedValueProducerAdapter->getValueAdapter();
if ( operatorParams[3].getAdapter() != sharedAdapter )
throw CG::Error( getLocation(), "operator shared value parameter type (" + operatorParams[3].getAdapter()->getUserName() + ") does not match shared value type (" + sharedAdapter->getUserName() + ")" );
if ( operatorParams[3].getUsage() != CG::USAGE_RVALUE )
throw CG::Error( getLocation(), "operator shared value parameter must be an 'in' parameter" );
CG::ExprValue sharedExprRValue = m_shared->buildExprValue( basicBlockBuilder, CG::USAGE_RVALUE, lValueErrorDesc );
std::vector<llvm::Type const *> argTypes;
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // function
argTypes.push_back( sizeAdapter->llvmRType( context ) ); // numParams
argTypes.push_back( countValueProducerAdapter->llvmLType( context ) ); // count value producer
argTypes.push_back( sharedValueProducerAdapter->llvmLType( context ) ); // shared value producer
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // output array producer adapter
argTypes.push_back( outputArrayProducerAdapter->llvmLType( context ) ); // output array producer
llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateArrayGenerator_4", funcType );
std::vector<llvm::Value *> args;
args.push_back( basicBlockBuilder->CreateBitCast(
function->getLLVMFunction(),
llvm::Type::getInt8PtrTy( llvmContext )
) );
args.push_back( sizeAdapter->llvmConst( context, operatorParams.size() ) );
args.push_back( countValueProducerExprValue.getValue() );
args.push_back( sharedExprRValue.getValue() );
args.push_back( outputArrayProducerAdapter->llvmAdapterPtr( basicBlockBuilder ) );
args.push_back( resultLValue );
basicBlockBuilder->CreateCall( func, args.begin(), args.end() );
needCall = false;
}
}
}
if ( needCall )
{
std::vector<llvm::Type const *> argTypes;
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // function
argTypes.push_back( sizeAdapter->llvmRType( context ) ); // numParams
argTypes.push_back( countValueProducerAdapter->llvmLType( context ) ); // count value producer
argTypes.push_back( llvm::Type::getInt8PtrTy( llvmContext ) ); // output array producer adapter
argTypes.push_back( outputArrayProducerAdapter->llvmLType( context ) ); // output array producer
llvm::FunctionType const *funcType = llvm::FunctionType::get( llvm::Type::getVoidTy( llvmContext ), argTypes, false );
llvm::Constant *func = basicBlockBuilder.getModuleBuilder()->getOrInsertFunction( "__MR_CreateArrayGenerator_3", funcType );
std::vector<llvm::Value *> args;
args.push_back( basicBlockBuilder->CreateBitCast(
function->getLLVMFunction(),
llvm::Type::getInt8PtrTy( llvmContext )
) );
args.push_back( sizeAdapter->llvmConst( context, operatorParams.size() ) );
args.push_back( countValueProducerExprValue.getValue() );
args.push_back( outputArrayProducerAdapter->llvmAdapterPtr( basicBlockBuilder ) );
args.push_back( resultLValue );
basicBlockBuilder->CreateCall( func, args.begin(), args.end() );
}
return CG::ExprValue(
outputArrayProducerAdapter,
CG::USAGE_RVALUE,
context,
outputArrayProducerAdapter->llvmLValueToRValue( basicBlockBuilder, resultLValue )
);
}
示例5: llvmCompileToBuilder
void ContainerLoop::llvmCompileToBuilder( CG::BasicBlockBuilder &parentBasicBlockBuilder, CG::Diagnostics &diagnostics ) const
{
try
{
CG::BasicBlockBuilder &basicBlockBuilder = parentBasicBlockBuilder;
RC::Handle<CG::Context> context = parentBasicBlockBuilder.getContext();
CG::ExprValue dictExprValue = m_dictExpr->buildExprValue( parentBasicBlockBuilder, CG::USAGE_UNSPECIFIED, "" );
RC::ConstHandle<CG::Adapter> adapter = dictExprValue.getAdapter();
if ( !RT::isDict( adapter->getType() ) )
throw CG::Error( m_dictExpr->getLocation(), "must be a dictionary" );
RC::ConstHandle<CG::DictAdapter> dictAdapter = RC::ConstHandle<CG::DictAdapter>::StaticCast( adapter );
RC::ConstHandle<CG::ComparableAdapter> keyAdapter = dictAdapter->getKeyAdapter();
RC::ConstHandle<CG::Adapter> valueAdapter = dictAdapter->getValueAdapter();
llvm::Type *nodePtrType = dictAdapter->getLLVMNodePtrType( context );
llvm::Instruction *nodePtrPtr = new llvm::AllocaInst( nodePtrType );
nodePtrPtr->setName( m_keyName );
// [pzion 20111019] We allocate variables at the top of the function
CG::FunctionBuilder &functionBuilder = parentBasicBlockBuilder.getFunctionBuilder();
llvm::BasicBlock &entryBB = functionBuilder->getEntryBlock();
llvm::BasicBlock::iterator it = entryBB.begin();
while ( it != entryBB.end() )
{
if ( !llvm::isa<llvm::AllocaInst>(*it) )
break;
++it;
}
entryBB.getInstList().insert( it, nodePtrPtr );
llvm::Value *bitsPtr = basicBlockBuilder->CreateLoad( dictExprValue.getValue() );
llvm::BasicBlock *startBB = parentBasicBlockBuilder.getFunctionBuilder().createBasicBlock( "containerLoopStart" );
llvm::BasicBlock *checkBB = parentBasicBlockBuilder.getFunctionBuilder().createBasicBlock( "containerLoopCheck" );
llvm::BasicBlock *bodyBB = parentBasicBlockBuilder.getFunctionBuilder().createBasicBlock( "containerLoopBody" );
llvm::BasicBlock *stepBB = parentBasicBlockBuilder.getFunctionBuilder().createBasicBlock( "containerLoopStep" );
llvm::BasicBlock *endBB = parentBasicBlockBuilder.getFunctionBuilder().createBasicBlock( "containerLoopEnd" );
basicBlockBuilder->CreateCondBr(
basicBlockBuilder->CreateIsNotNull( bitsPtr ),
startBB,
endBB
);
// [pzion 20111019] Load bits->firstNode into llvmNodePtrPtr
basicBlockBuilder->SetInsertPoint( startBB );
llvm::Value *firstNodePtrPtr = basicBlockBuilder->CreateStructGEP( bitsPtr, 3 );
llvm::Value *firstNodePtr = basicBlockBuilder->CreateLoad( firstNodePtrPtr );
basicBlockBuilder->CreateStore( firstNodePtr, nodePtrPtr );
basicBlockBuilder->CreateBr( checkBB );
basicBlockBuilder->SetInsertPoint( checkBB );
llvm::Value *nodePtr = basicBlockBuilder->CreateLoad( nodePtrPtr );
basicBlockBuilder->CreateCondBr(
basicBlockBuilder->CreateIsNull( nodePtr ),
endBB,
bodyBB
);
basicBlockBuilder->SetInsertPoint( bodyBB );
llvm::Value *bitsNextNodePtrPtr = basicBlockBuilder->CreateStructGEP( nodePtr, 1 );
llvm::Value *bitsNextNodePtr = basicBlockBuilder->CreatePointerCast(
basicBlockBuilder->CreateLoad( bitsNextNodePtrPtr ),
nodePtrType
);
{
CG::LoopScope loopScope( parentBasicBlockBuilder.getScope(), endBB, stepBB );
llvm::Value *keyLValue = basicBlockBuilder->CreatePointerCast(
basicBlockBuilder->CreateStructGEP( nodePtr, 5 ),
keyAdapter->llvmLType( context )
);
llvm::Value *keyRValue = keyAdapter->llvmLValueToRValue( basicBlockBuilder, keyLValue );
loopScope.put( m_keyName, CG::ParameterSymbol::Create( CG::ExprValue( keyAdapter, CG::USAGE_RVALUE, context, keyRValue ) ) );
llvm::Value *valueRValue = 0;
if ( m_valueName.length() > 0 )
{
llvm::Value *valueLValue = basicBlockBuilder->CreatePointerCast(
basicBlockBuilder->CreateConstGEP2_32(
basicBlockBuilder->CreateStructGEP( nodePtr, 5 ),
0,
keyAdapter->getImpl()->getAllocSize()
),
valueAdapter->llvmLType( context )
);
switch ( dictExprValue.getUsage() )
{
case CG::USAGE_RVALUE:
{
valueRValue = valueAdapter->llvmLValueToRValue( basicBlockBuilder, valueLValue );
loopScope.put( m_valueName, CG::ParameterSymbol::Create( CG::ExprValue( valueAdapter, CG::USAGE_RVALUE, context, valueRValue ) ) );
}
break;
case CG::USAGE_LVALUE:
{
loopScope.put( m_valueName, CG::ParameterSymbol::Create( CG::ExprValue( valueAdapter, CG::USAGE_LVALUE, context, valueLValue ) ) );
}
break;
//.........这里部分代码省略.........