Skip to content

Commit 411d5b4

Browse files
committed
LLVMCodeBuilder: Store instructions in LLVMInstructionList
1 parent 6e70e3f commit 411d5b4

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/engine/internal/llvm/llvmcodebuilder.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,8 @@ CompilerValue *LLVMCodeBuilder::addFunctionCall(const std::string &functionName,
13901390
for (size_t i = 0; i < args.size(); i++)
13911391
ins->args.push_back({ argTypes[i], dynamic_cast<LLVMRegister *>(args[i]) });
13921392

1393+
m_instructions.addInstruction(ins);
1394+
13931395
if (returnType != Compiler::StaticType::Void) {
13941396
auto reg = std::make_shared<LLVMRegister>(returnType);
13951397
reg->isRawValue = true;
@@ -1456,6 +1458,7 @@ CompilerValue *LLVMCodeBuilder::addVariableValue(Variable *variable)
14561458
ret->isRawValue = false;
14571459
ins->functionReturnReg = ret.get();
14581460

1461+
m_instructions.addInstruction(ins);
14591462
m_instructionList.push_back(ins);
14601463
m_variableInstructions.push_back(m_instructionList.back());
14611464
return addReg(ret, ins);
@@ -1486,6 +1489,7 @@ CompilerValue *LLVMCodeBuilder::addListItem(List *list, CompilerValue *index)
14861489
ret->isRawValue = false;
14871490
ins->functionReturnReg = ret.get();
14881491

1492+
m_instructions.addInstruction(ins);
14891493
m_instructionList.push_back(ins);
14901494
m_listInstructions.push_back(m_instructionList.back());
14911495
return addReg(ret, ins);
@@ -1549,6 +1553,7 @@ CompilerValue *LLVMCodeBuilder::addProcedureArgument(const std::string &name)
15491553
ins->functionReturnReg = ret.get();
15501554
ins->procedureArgIndex = index;
15511555

1556+
m_instructions.addInstruction(ins);
15521557
m_instructionList.push_back(ins);
15531558
return addReg(ret, ins);
15541559
}
@@ -1818,17 +1823,22 @@ void LLVMCodeBuilder::beginIfStatement(CompilerValue *cond)
18181823
{
18191824
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginIf, currentLoopScope(), m_loopCondition);
18201825
ins->args.push_back({ Compiler::StaticType::Bool, dynamic_cast<LLVMRegister *>(cond) });
1826+
m_instructions.addInstruction(ins);
18211827
m_instructionList.push_back(ins);
18221828
}
18231829

18241830
void LLVMCodeBuilder::beginElseBranch()
18251831
{
1826-
m_instructionList.push_back(std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginElse, currentLoopScope(), m_loopCondition));
1832+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginElse, currentLoopScope(), m_loopCondition);
1833+
m_instructions.addInstruction(ins);
1834+
m_instructionList.push_back(ins);
18271835
}
18281836

18291837
void LLVMCodeBuilder::endIf()
18301838
{
1831-
m_instructionList.push_back(std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndIf, currentLoopScope(), m_loopCondition));
1839+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndIf, currentLoopScope(), m_loopCondition);
1840+
m_instructions.addInstruction(ins);
1841+
m_instructionList.push_back(ins);
18321842
}
18331843

18341844
void LLVMCodeBuilder::beginRepeatLoop(CompilerValue *count)
@@ -1837,6 +1847,7 @@ void LLVMCodeBuilder::beginRepeatLoop(CompilerValue *count)
18371847

18381848
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatLoop, currentLoopScope(), m_loopCondition);
18391849
ins->args.push_back({ Compiler::StaticType::Number, dynamic_cast<LLVMRegister *>(count) });
1850+
m_instructions.addInstruction(ins);
18401851
m_instructionList.push_back(ins);
18411852
pushLoopScope(false);
18421853
}
@@ -1848,6 +1859,7 @@ void LLVMCodeBuilder::beginWhileLoop(CompilerValue *cond)
18481859

18491860
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginWhileLoop, currentLoopScope(), m_loopCondition);
18501861
ins->args.push_back({ Compiler::StaticType::Bool, dynamic_cast<LLVMRegister *>(cond) });
1862+
m_instructions.addInstruction(ins);
18511863
m_instructionList.push_back(ins);
18521864
pushLoopScope(false);
18531865
}
@@ -1859,37 +1871,50 @@ void LLVMCodeBuilder::beginRepeatUntilLoop(CompilerValue *cond)
18591871

18601872
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginRepeatUntilLoop, currentLoopScope(), m_loopCondition);
18611873
ins->args.push_back({ Compiler::StaticType::Bool, dynamic_cast<LLVMRegister *>(cond) });
1874+
m_instructions.addInstruction(ins);
18621875
m_instructionList.push_back(ins);
18631876
pushLoopScope(false);
18641877
}
18651878

18661879
void LLVMCodeBuilder::beginLoopCondition()
18671880
{
18681881
assert(!m_loopCondition);
1869-
m_instructionList.push_back(std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, currentLoopScope(), m_loopCondition));
1882+
1883+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::BeginLoopCondition, currentLoopScope(), m_loopCondition);
1884+
m_instructions.addInstruction(ins);
1885+
m_instructionList.push_back(ins);
18701886
m_loopCondition = true;
18711887
}
18721888

18731889
void LLVMCodeBuilder::endLoop()
18741890
{
1875-
if (!m_warp)
1876-
m_instructionList.push_back(std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope(), m_loopCondition));
1891+
if (!m_warp) {
1892+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope(), m_loopCondition);
1893+
m_instructions.addInstruction(ins);
1894+
m_instructionList.push_back(ins);
1895+
}
18771896

1878-
m_instructionList.push_back(std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, currentLoopScope(), m_loopCondition));
1897+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::EndLoop, currentLoopScope(), m_loopCondition);
1898+
m_instructions.addInstruction(ins);
1899+
m_instructionList.push_back(ins);
18791900
popLoopScope();
18801901
}
18811902

18821903
void LLVMCodeBuilder::yield()
18831904
{
1884-
m_instructionList.push_back(std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope(), m_loopCondition));
1905+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Yield, currentLoopScope(), m_loopCondition);
1906+
m_instructions.addInstruction(ins);
1907+
m_instructionList.push_back(ins);
18851908

18861909
if (m_loopScope >= 0)
18871910
m_loopScopes[m_loopScope]->containsYield = true;
18881911
}
18891912

18901913
void LLVMCodeBuilder::createStop()
18911914
{
1892-
m_instructionList.push_back(std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Stop, currentLoopScope(), m_loopCondition));
1915+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::Stop, currentLoopScope(), m_loopCondition);
1916+
m_instructions.addInstruction(ins);
1917+
m_instructionList.push_back(ins);
18931918
}
18941919

18951920
void LLVMCodeBuilder::createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args)
@@ -2715,6 +2740,7 @@ LLVMRegister *LLVMCodeBuilder::createOp(const LLVMInstruction &ins, Compiler::St
27152740
LLVMRegister *LLVMCodeBuilder::createOp(const LLVMInstruction &ins, Compiler::StaticType retType, const Compiler::ArgTypes &argTypes, const Compiler::Args &args)
27162741
{
27172742
auto createdIns = std::make_shared<LLVMInstruction>(ins);
2743+
m_instructions.addInstruction(createdIns);
27182744
m_instructionList.push_back(createdIns);
27192745

27202746
for (size_t i = 0; i < args.size(); i++)

src/engine/internal/llvm/llvmcodebuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "../icodebuilder.h"
1313
#include "llvminstruction.h"
14+
#include "llvminstructionlist.h"
1415
#include "llvmcoroutine.h"
1516
#include "llvmvariableptr.h"
1617
#include "llvmlistptr.h"
@@ -235,6 +236,7 @@ class LLVMCodeBuilder : public ICodeBuilder
235236
llvm::FunctionType *m_resumeFuncType = nullptr;
236237

237238
[[deprecated]] std::vector<std::shared_ptr<LLVMInstruction>> m_instructionList; // TODO: Remove this
239+
LLVMInstructionList m_instructions;
238240
std::vector<std::shared_ptr<LLVMRegister>> m_regs;
239241
std::vector<std::shared_ptr<CompilerLocalVariable>> m_localVars;
240242
LLVMRegister *m_lastConstValue = nullptr; // for reporters and hat predicates

0 commit comments

Comments
 (0)