@@ -505,9 +505,19 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
505505 const auto &arg1 = step.args [0 ];
506506 const auto &arg2 = step.args [1 ];
507507 const auto &arg3 = step.args [2 ];
508+ auto type = arg2.first ;
508509 llvm::Value *cond = castValue (arg1.second , arg1.first );
509- llvm::Value *trueValue = castValue (arg2.second , arg2.first );
510- llvm::Value *falseValue = castValue (arg3.second , arg3.first );
510+ llvm::Value *trueValue;
511+ llvm::Value *falseValue;
512+
513+ if (type == Compiler::StaticType::Unknown) {
514+ trueValue = createValue (arg2.second );
515+ falseValue = createValue (arg3.second );
516+ } else {
517+ trueValue = castValue (arg2.second , type);
518+ falseValue = castValue (arg3.second , type);
519+ }
520+
511521 step.functionReturnReg ->value = m_builder.CreateSelect (cond, trueValue, falseValue);
512522 break ;
513523 }
@@ -1100,7 +1110,7 @@ CompilerConstant *LLVMCodeBuilder::addConstValue(const Value &value)
11001110{
11011111 auto constReg = std::make_shared<LLVMConstantRegister>(TYPE_MAP[value.type ()], value);
11021112 auto reg = std::reinterpret_pointer_cast<LLVMRegister>(constReg);
1103- return static_cast <CompilerConstant *>(addReg (reg));
1113+ return static_cast <CompilerConstant *>(static_cast <CompilerValue *>( addReg (reg) ));
11041114}
11051115
11061116CompilerValue *LLVMCodeBuilder::addLoopIndex ()
@@ -1317,7 +1327,12 @@ CompilerValue *LLVMCodeBuilder::createExp10(CompilerValue *num)
13171327
13181328CompilerValue *LLVMCodeBuilder::createSelect (CompilerValue *cond, CompilerValue *trueValue, CompilerValue *falseValue, Compiler::StaticType valueType)
13191329{
1320- return createOp (LLVMInstruction::Type::Select, valueType, { Compiler::StaticType::Bool, valueType, valueType }, { cond, trueValue, falseValue });
1330+ LLVMRegister *ret = createOp (LLVMInstruction::Type::Select, valueType, { Compiler::StaticType::Bool, valueType, valueType }, { cond, trueValue, falseValue });
1331+
1332+ if (valueType == Compiler::StaticType::Unknown)
1333+ ret->isRawValue = false ;
1334+
1335+ return ret;
13211336}
13221337
13231338CompilerLocalVariable *LLVMCodeBuilder::createLocalVariable (Compiler::StaticType type)
@@ -1569,7 +1584,7 @@ void LLVMCodeBuilder::optimize()
15691584 modulePassManager.run (*m_module, moduleAnalysisManager);
15701585}
15711586
1572- CompilerValue *LLVMCodeBuilder::addReg (std::shared_ptr<LLVMRegister> reg)
1587+ LLVMRegister *LLVMCodeBuilder::addReg (std::shared_ptr<LLVMRegister> reg)
15731588{
15741589 m_regs.push_back (reg);
15751590 return reg.get ();
@@ -1875,7 +1890,7 @@ void LLVMCodeBuilder::updateListDataPtr(const LLVMListPtr &listPtr, llvm::Functi
18751890 m_builder.CreateStore (m_builder.getInt1 (false ), listPtr.dataPtrDirty );
18761891}
18771892
1878- CompilerValue *LLVMCodeBuilder::createOp (const LLVMInstruction &ins, Compiler::StaticType retType, Compiler::StaticType argType, const Compiler::Args &args)
1893+ LLVMRegister *LLVMCodeBuilder::createOp (const LLVMInstruction &ins, Compiler::StaticType retType, Compiler::StaticType argType, const Compiler::Args &args)
18791894{
18801895 std::vector<Compiler::StaticType> types;
18811896 types.reserve (args.size ());
@@ -1886,7 +1901,7 @@ CompilerValue *LLVMCodeBuilder::createOp(const LLVMInstruction &ins, Compiler::S
18861901 return createOp (ins, retType, types, args);
18871902}
18881903
1889- CompilerValue *LLVMCodeBuilder::createOp (const LLVMInstruction &ins, Compiler::StaticType retType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
1904+ LLVMRegister *LLVMCodeBuilder::createOp (const LLVMInstruction &ins, Compiler::StaticType retType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
18901905{
18911906 m_instructions.push_back (ins);
18921907 LLVMInstruction &createdIns = m_instructions.back ();
0 commit comments