Skip to content

Commit b1bbc7f

Browse files
committed
LLVMCodeBuilder: Drop m_instructionList
1 parent d87d6f0 commit b1bbc7f

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

src/engine/internal/llvm/llvmcodebuilder.cpp

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
5353
{
5454
if (!m_warp) {
5555
// 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+
})) {
6159
m_warp = true;
60+
}
6261

6362
// Only create coroutines in scripts
6463
if (m_codeType != Compiler::CodeType::Script)
@@ -1340,21 +1339,21 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
13401339

13411340
case Compiler::CodeType::Reporter: {
13421341
// 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;
13451344
llvm::Value *copy = createNewValue(ret);
13461345
m_builder.CreateRet(m_builder.CreateLoad(m_valueDataType, copy));
13471346
break;
13481347
}
13491348

13501349
case Compiler::CodeType::HatPredicate:
13511350
// Use last instruction return value (or last constant)
1352-
assert(!m_instructionList.empty() || m_lastConstValue);
1351+
assert(!m_instructions.empty() || m_lastConstValue);
13531352

1354-
if (m_instructionList.empty())
1353+
if (m_instructions.empty())
13551354
m_builder.CreateRet(castValue(m_lastConstValue, Compiler::StaticType::Bool));
13561355
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));
13581357
break;
13591358
}
13601359

@@ -1396,25 +1395,23 @@ CompilerValue *LLVMCodeBuilder::addFunctionCall(const std::string &functionName,
13961395
auto reg = std::make_shared<LLVMRegister>(returnType);
13971396
reg->isRawValue = true;
13981397
ins->functionReturnReg = reg.get();
1399-
m_instructionList.push_back(ins);
14001398
return addReg(reg, ins);
14011399
}
14021400

1403-
m_instructionList.push_back(ins);
14041401
return nullptr;
14051402
}
14061403

14071404
CompilerValue *LLVMCodeBuilder::addTargetFunctionCall(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
14081405
{
14091406
CompilerValue *ret = addFunctionCall(functionName, returnType, argTypes, args);
1410-
m_instructionList.back()->functionTargetArg = true;
1407+
m_instructions.last()->functionTargetArg = true;
14111408
return ret;
14121409
}
14131410

14141411
CompilerValue *LLVMCodeBuilder::addFunctionCallWithCtx(const std::string &functionName, Compiler::StaticType returnType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
14151412
{
14161413
CompilerValue *ret = addFunctionCall(functionName, returnType, argTypes, args);
1417-
m_instructionList.back()->functionCtxArg = true;
1414+
m_instructions.last()->functionCtxArg = true;
14181415
return ret;
14191416
}
14201417

@@ -1459,7 +1456,6 @@ CompilerValue *LLVMCodeBuilder::addVariableValue(Variable *variable)
14591456
ins->functionReturnReg = ret.get();
14601457

14611458
m_instructions.addInstruction(ins);
1462-
m_instructionList.push_back(ins);
14631459
m_variableInstructions.push_back(ins.get());
14641460
return addReg(ret, ins);
14651461
}
@@ -1490,7 +1486,6 @@ CompilerValue *LLVMCodeBuilder::addListItem(List *list, CompilerValue *index)
14901486
ins->functionReturnReg = ret.get();
14911487

14921488
m_instructions.addInstruction(ins);
1493-
m_instructionList.push_back(ins);
14941489
m_listInstructions.push_back(ins.get());
14951490
return addReg(ret, ins);
14961491
}
@@ -1554,7 +1549,6 @@ CompilerValue *LLVMCodeBuilder::addProcedureArgument(const std::string &name)
15541549
ins->procedureArgIndex = index;
15551550

15561551
m_instructions.addInstruction(ins);
1557-
m_instructionList.push_back(ins);
15581552
return addReg(ret, ins);
15591553
}
15601554

@@ -1824,21 +1818,18 @@ void LLVMCodeBuilder::beginIfStatement(CompilerValue *cond)
18241818
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginIf, currentLoopScope(), m_loopCondition);
18251819
ins->args.push_back({ Compiler::StaticType::Bool, dynamic_cast<LLVMRegister *>(cond) });
18261820
m_instructions.addInstruction(ins);
1827-
m_instructionList.push_back(ins);
18281821
}
18291822

18301823
void LLVMCodeBuilder::beginElseBranch()
18311824
{
18321825
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginElse, currentLoopScope(), m_loopCondition);
18331826
m_instructions.addInstruction(ins);
1834-
m_instructionList.push_back(ins);
18351827
}
18361828

18371829
void LLVMCodeBuilder::endIf()
18381830
{
18391831
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndIf, currentLoopScope(), m_loopCondition);
18401832
m_instructions.addInstruction(ins);
1841-
m_instructionList.push_back(ins);
18421833
}
18431834

18441835
void LLVMCodeBuilder::beginRepeatLoop(CompilerValue *count)
@@ -1848,7 +1839,6 @@ void LLVMCodeBuilder::beginRepeatLoop(CompilerValue *count)
18481839
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatLoop, currentLoopScope(), m_loopCondition);
18491840
ins->args.push_back({ Compiler::StaticType::Number, dynamic_cast<LLVMRegister *>(count) });
18501841
m_instructions.addInstruction(ins);
1851-
m_instructionList.push_back(ins);
18521842
pushLoopScope(false);
18531843
}
18541844

@@ -1860,7 +1850,6 @@ void LLVMCodeBuilder::beginWhileLoop(CompilerValue *cond)
18601850
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginWhileLoop, currentLoopScope(), m_loopCondition);
18611851
ins->args.push_back({ Compiler::StaticType::Bool, dynamic_cast<LLVMRegister *>(cond) });
18621852
m_instructions.addInstruction(ins);
1863-
m_instructionList.push_back(ins);
18641853
pushLoopScope(false);
18651854
}
18661855

@@ -1872,7 +1861,6 @@ void LLVMCodeBuilder::beginRepeatUntilLoop(CompilerValue *cond)
18721861
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatUntilLoop, currentLoopScope(), m_loopCondition);
18731862
ins->args.push_back({ Compiler::StaticType::Bool, dynamic_cast<LLVMRegister *>(cond) });
18741863
m_instructions.addInstruction(ins);
1875-
m_instructionList.push_back(ins);
18761864
pushLoopScope(false);
18771865
}
18781866

@@ -1882,7 +1870,6 @@ void LLVMCodeBuilder::beginLoopCondition()
18821870

18831871
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, currentLoopScope(), m_loopCondition);
18841872
m_instructions.addInstruction(ins);
1885-
m_instructionList.push_back(ins);
18861873
m_loopCondition = true;
18871874
}
18881875

@@ -1891,20 +1878,17 @@ void LLVMCodeBuilder::endLoop()
18911878
if (!m_warp) {
18921879
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope(), m_loopCondition);
18931880
m_instructions.addInstruction(ins);
1894-
m_instructionList.push_back(ins);
18951881
}
18961882

18971883
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, currentLoopScope(), m_loopCondition);
18981884
m_instructions.addInstruction(ins);
1899-
m_instructionList.push_back(ins);
19001885
popLoopScope();
19011886
}
19021887

19031888
void LLVMCodeBuilder::yield()
19041889
{
19051890
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope(), m_loopCondition);
19061891
m_instructions.addInstruction(ins);
1907-
m_instructionList.push_back(ins);
19081892

19091893
if (m_loopScope >= 0)
19101894
m_loopScopes[m_loopScope]->containsYield = true;
@@ -1914,7 +1898,6 @@ void LLVMCodeBuilder::createStop()
19141898
{
19151899
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Stop, currentLoopScope(), m_loopCondition);
19161900
m_instructions.addInstruction(ins);
1917-
m_instructionList.push_back(ins);
19181901
}
19191902

19201903
void LLVMCodeBuilder::createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args)
@@ -2740,7 +2723,6 @@ LLVMRegister *LLVMCodeBuilder::createOp(const LLVMInstruction &ins, Compiler::St
27402723
{
27412724
auto createdIns = std::make_shared<LLVMInstruction>(ins);
27422725
m_instructions.addInstruction(createdIns);
2743-
m_instructionList.push_back(createdIns);
27442726

27452727
for (size_t i = 0; i < args.size(); i++)
27462728
createdIns->args.push_back({ argTypes[i], dynamic_cast<LLVMRegister *>(args[i]) });

src/engine/internal/llvm/llvmcodebuilder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ class LLVMCodeBuilder : public ICodeBuilder
235235
llvm::StructType *m_stringPtrType = nullptr;
236236
llvm::FunctionType *m_resumeFuncType = nullptr;
237237

238-
[[deprecated]] std::vector<std::shared_ptr<LLVMInstruction>> m_instructionList; // TODO: Remove this
239238
LLVMInstructionList m_instructions;
240239
std::vector<std::shared_ptr<LLVMRegister>> m_regs;
241240
std::vector<std::shared_ptr<CompilerLocalVariable>> m_localVars;

0 commit comments

Comments
 (0)