@@ -53,12 +53,11 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
53
53
{
54
54
if (!m_warp) {
55
55
// Do not create coroutine if there are no yield instructions nor non-warp procedure calls
56
- auto it = std::find_if (m_instructionList.begin (), m_instructionList.end (), [](const std::shared_ptr<LLVMInstruction> &step) {
57
- return step->type == LLVMInstruction::Type::Yield || (step->type == LLVMInstruction::Type::CallProcedure && step->procedurePrototype && !step->procedurePrototype ->warp ());
58
- });
59
-
60
- if (it == m_instructionList.end ())
56
+ if (!m_instructions.containsInstruction ([](const LLVMInstruction *step) {
57
+ return step->type == LLVMInstruction::Type::Yield || (step->type == LLVMInstruction::Type::CallProcedure && step->procedurePrototype && !step->procedurePrototype ->warp ());
58
+ })) {
61
59
m_warp = true ;
60
+ }
62
61
63
62
// Only create coroutines in scripts
64
63
if (m_codeType != Compiler::CodeType::Script)
@@ -1340,21 +1339,21 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
1340
1339
1341
1340
case Compiler::CodeType::Reporter: {
1342
1341
// Use last instruction return value (or last constant) and create a ValueData instance
1343
- assert (!m_instructionList .empty () || m_lastConstValue);
1344
- LLVMRegister *ret = m_instructionList .empty () ? m_lastConstValue : m_instructionList. back ()->functionReturnReg ;
1342
+ assert (!m_instructions .empty () || m_lastConstValue);
1343
+ LLVMRegister *ret = m_instructions .empty () ? m_lastConstValue : m_instructions. last ()->functionReturnReg ;
1345
1344
llvm::Value *copy = createNewValue (ret);
1346
1345
m_builder.CreateRet (m_builder.CreateLoad (m_valueDataType, copy));
1347
1346
break ;
1348
1347
}
1349
1348
1350
1349
case Compiler::CodeType::HatPredicate:
1351
1350
// Use last instruction return value (or last constant)
1352
- assert (!m_instructionList .empty () || m_lastConstValue);
1351
+ assert (!m_instructions .empty () || m_lastConstValue);
1353
1352
1354
- if (m_instructionList .empty ())
1353
+ if (m_instructions .empty ())
1355
1354
m_builder.CreateRet (castValue (m_lastConstValue, Compiler::StaticType::Bool));
1356
1355
else
1357
- m_builder.CreateRet (castValue (m_instructionList. back ()->functionReturnReg , Compiler::StaticType::Bool));
1356
+ m_builder.CreateRet (castValue (m_instructions. last ()->functionReturnReg , Compiler::StaticType::Bool));
1358
1357
break ;
1359
1358
}
1360
1359
@@ -1396,25 +1395,23 @@ CompilerValue *LLVMCodeBuilder::addFunctionCall(const std::string &functionName,
1396
1395
auto reg = std::make_shared<LLVMRegister>(returnType);
1397
1396
reg->isRawValue = true ;
1398
1397
ins->functionReturnReg = reg.get ();
1399
- m_instructionList.push_back (ins);
1400
1398
return addReg (reg, ins);
1401
1399
}
1402
1400
1403
- m_instructionList.push_back (ins);
1404
1401
return nullptr ;
1405
1402
}
1406
1403
1407
1404
CompilerValue *LLVMCodeBuilder::addTargetFunctionCall (const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
1408
1405
{
1409
1406
CompilerValue *ret = addFunctionCall (functionName, returnType, argTypes, args);
1410
- m_instructionList. back ()->functionTargetArg = true ;
1407
+ m_instructions. last ()->functionTargetArg = true ;
1411
1408
return ret;
1412
1409
}
1413
1410
1414
1411
CompilerValue *LLVMCodeBuilder::addFunctionCallWithCtx (const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
1415
1412
{
1416
1413
CompilerValue *ret = addFunctionCall (functionName, returnType, argTypes, args);
1417
- m_instructionList. back ()->functionCtxArg = true ;
1414
+ m_instructions. last ()->functionCtxArg = true ;
1418
1415
return ret;
1419
1416
}
1420
1417
@@ -1459,7 +1456,6 @@ CompilerValue *LLVMCodeBuilder::addVariableValue(Variable *variable)
1459
1456
ins->functionReturnReg = ret.get ();
1460
1457
1461
1458
m_instructions.addInstruction (ins);
1462
- m_instructionList.push_back (ins);
1463
1459
m_variableInstructions.push_back (ins.get ());
1464
1460
return addReg (ret, ins);
1465
1461
}
@@ -1490,7 +1486,6 @@ CompilerValue *LLVMCodeBuilder::addListItem(List *list, CompilerValue *index)
1490
1486
ins->functionReturnReg = ret.get ();
1491
1487
1492
1488
m_instructions.addInstruction (ins);
1493
- m_instructionList.push_back (ins);
1494
1489
m_listInstructions.push_back (ins.get ());
1495
1490
return addReg (ret, ins);
1496
1491
}
@@ -1554,7 +1549,6 @@ CompilerValue *LLVMCodeBuilder::addProcedureArgument(const std::string &name)
1554
1549
ins->procedureArgIndex = index;
1555
1550
1556
1551
m_instructions.addInstruction (ins);
1557
- m_instructionList.push_back (ins);
1558
1552
return addReg (ret, ins);
1559
1553
}
1560
1554
@@ -1824,21 +1818,18 @@ void LLVMCodeBuilder::beginIfStatement(CompilerValue *cond)
1824
1818
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginIf, currentLoopScope (), m_loopCondition);
1825
1819
ins->args .push_back ({ Compiler::StaticType::Bool, dynamic_cast <LLVMRegister *>(cond) });
1826
1820
m_instructions.addInstruction (ins);
1827
- m_instructionList.push_back (ins);
1828
1821
}
1829
1822
1830
1823
void LLVMCodeBuilder::beginElseBranch ()
1831
1824
{
1832
1825
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginElse, currentLoopScope (), m_loopCondition);
1833
1826
m_instructions.addInstruction (ins);
1834
- m_instructionList.push_back (ins);
1835
1827
}
1836
1828
1837
1829
void LLVMCodeBuilder::endIf ()
1838
1830
{
1839
1831
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndIf, currentLoopScope (), m_loopCondition);
1840
1832
m_instructions.addInstruction (ins);
1841
- m_instructionList.push_back (ins);
1842
1833
}
1843
1834
1844
1835
void LLVMCodeBuilder::beginRepeatLoop (CompilerValue *count)
@@ -1848,7 +1839,6 @@ void LLVMCodeBuilder::beginRepeatLoop(CompilerValue *count)
1848
1839
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatLoop, currentLoopScope (), m_loopCondition);
1849
1840
ins->args .push_back ({ Compiler::StaticType::Number, dynamic_cast <LLVMRegister *>(count) });
1850
1841
m_instructions.addInstruction (ins);
1851
- m_instructionList.push_back (ins);
1852
1842
pushLoopScope (false );
1853
1843
}
1854
1844
@@ -1860,7 +1850,6 @@ void LLVMCodeBuilder::beginWhileLoop(CompilerValue *cond)
1860
1850
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginWhileLoop, currentLoopScope (), m_loopCondition);
1861
1851
ins->args .push_back ({ Compiler::StaticType::Bool, dynamic_cast <LLVMRegister *>(cond) });
1862
1852
m_instructions.addInstruction (ins);
1863
- m_instructionList.push_back (ins);
1864
1853
pushLoopScope (false );
1865
1854
}
1866
1855
@@ -1872,7 +1861,6 @@ void LLVMCodeBuilder::beginRepeatUntilLoop(CompilerValue *cond)
1872
1861
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatUntilLoop, currentLoopScope (), m_loopCondition);
1873
1862
ins->args .push_back ({ Compiler::StaticType::Bool, dynamic_cast <LLVMRegister *>(cond) });
1874
1863
m_instructions.addInstruction (ins);
1875
- m_instructionList.push_back (ins);
1876
1864
pushLoopScope (false );
1877
1865
}
1878
1866
@@ -1882,7 +1870,6 @@ void LLVMCodeBuilder::beginLoopCondition()
1882
1870
1883
1871
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, currentLoopScope (), m_loopCondition);
1884
1872
m_instructions.addInstruction (ins);
1885
- m_instructionList.push_back (ins);
1886
1873
m_loopCondition = true ;
1887
1874
}
1888
1875
@@ -1891,20 +1878,17 @@ void LLVMCodeBuilder::endLoop()
1891
1878
if (!m_warp) {
1892
1879
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope (), m_loopCondition);
1893
1880
m_instructions.addInstruction (ins);
1894
- m_instructionList.push_back (ins);
1895
1881
}
1896
1882
1897
1883
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, currentLoopScope (), m_loopCondition);
1898
1884
m_instructions.addInstruction (ins);
1899
- m_instructionList.push_back (ins);
1900
1885
popLoopScope ();
1901
1886
}
1902
1887
1903
1888
void LLVMCodeBuilder::yield ()
1904
1889
{
1905
1890
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope (), m_loopCondition);
1906
1891
m_instructions.addInstruction (ins);
1907
- m_instructionList.push_back (ins);
1908
1892
1909
1893
if (m_loopScope >= 0 )
1910
1894
m_loopScopes[m_loopScope]->containsYield = true ;
@@ -1914,7 +1898,6 @@ void LLVMCodeBuilder::createStop()
1914
1898
{
1915
1899
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Stop, currentLoopScope (), m_loopCondition);
1916
1900
m_instructions.addInstruction (ins);
1917
- m_instructionList.push_back (ins);
1918
1901
}
1919
1902
1920
1903
void LLVMCodeBuilder::createProcedureCall (BlockPrototype *prototype, const Compiler::Args &args)
@@ -2740,7 +2723,6 @@ LLVMRegister *LLVMCodeBuilder::createOp(const LLVMInstruction &ins, Compiler::St
2740
2723
{
2741
2724
auto createdIns = std::make_shared<LLVMInstruction>(ins);
2742
2725
m_instructions.addInstruction (createdIns);
2743
- m_instructionList.push_back (createdIns);
2744
2726
2745
2727
for (size_t i = 0 ; i < args.size (); i++)
2746
2728
createdIns->args .push_back ({ argTypes[i], dynamic_cast <LLVMRegister *>(args[i]) });
0 commit comments