@@ -121,7 +121,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
121
121
122
122
// If there are no write operations outside loops, initialize the stack variable now
123
123
Variable *variable = var;
124
- auto it = std::find_if (m_variableInstructions.begin (), m_variableInstructions.end (), [variable](const std::shared_ptr< LLVMInstruction> & ins) {
124
+ auto it = std::find_if (m_variableInstructions.begin (), m_variableInstructions.end (), [variable](const LLVMInstruction * ins) {
125
125
return ins->type == LLVMInstruction::Type::WriteVariable && ins->workVariable == variable && !ins->loopScope ;
126
126
});
127
127
@@ -743,7 +743,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
743
743
LLVMVariablePtr &varPtr = m_variablePtrs[step.workVariable ];
744
744
varPtr.changed = true ;
745
745
746
- const bool safe = isVarOrListTypeSafe (insPtr, varPtr.type );
746
+ const bool safe = isVarOrListTypeSafe (insPtr. get () , varPtr.type );
747
747
748
748
// Initialize stack variable on first assignment
749
749
if (!varPtr.onStack ) {
@@ -778,7 +778,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
778
778
assert (step.args .size () == 0 );
779
779
LLVMVariablePtr &varPtr = m_variablePtrs[step.workVariable ];
780
780
781
- if (!isVarOrListTypeSafe (insPtr, varPtr.type ))
781
+ if (!isVarOrListTypeSafe (insPtr. get () , varPtr.type ))
782
782
varPtr.type = Compiler::StaticType::Unknown;
783
783
784
784
step.functionReturnReg ->value = varPtr.onStack && !(step.loopCondition && !m_warp) ? varPtr.stackPtr : varPtr.heapPtr ;
@@ -806,7 +806,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
806
806
const auto &arg = step.args [0 ];
807
807
LLVMListPtr &listPtr = m_listPtrs[step.workList ];
808
808
809
- if (!isVarOrListTypeSafe (insPtr, listPtr.type ))
809
+ if (!isVarOrListTypeSafe (insPtr. get () , listPtr.type ))
810
810
listPtr.type = Compiler::StaticType::Unknown;
811
811
812
812
// Range check
@@ -846,7 +846,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
846
846
typeMap[&listPtr] = listPtr.type ;
847
847
}
848
848
849
- if (!isVarOrListTypeSafe (insPtr, listPtr.type ))
849
+ if (!isVarOrListTypeSafe (insPtr. get () , listPtr.type ))
850
850
listPtr.type = Compiler::StaticType::Unknown;
851
851
852
852
// Check if enough space is allocated
@@ -894,7 +894,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
894
894
typeMap[&listPtr] = listPtr.type ;
895
895
}
896
896
897
- if (!isVarOrListTypeSafe (insPtr, listPtr.type ))
897
+ if (!isVarOrListTypeSafe (insPtr. get () , listPtr.type ))
898
898
listPtr.type = Compiler::StaticType::Unknown;
899
899
900
900
llvm::Value *oldAllocatedSize = m_builder.CreateLoad (m_builder.getInt64Ty (), listPtr.allocatedSizePtr );
@@ -933,7 +933,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
933
933
Compiler::StaticType type = optimizeRegisterType (valueArg.second );
934
934
LLVMListPtr &listPtr = m_listPtrs[step.workList ];
935
935
936
- if (!isVarOrListTypeSafe (insPtr, listPtr.type ))
936
+ if (!isVarOrListTypeSafe (insPtr. get () , listPtr.type ))
937
937
listPtr.type = Compiler::StaticType::Unknown;
938
938
939
939
// Range check
@@ -981,7 +981,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
981
981
const auto &arg = step.args [0 ];
982
982
LLVMListPtr &listPtr = m_listPtrs[step.workList ];
983
983
984
- if (!isVarOrListTypeSafe (insPtr, listPtr.type ))
984
+ if (!isVarOrListTypeSafe (insPtr. get () , listPtr.type ))
985
985
listPtr.type = Compiler::StaticType::Unknown;
986
986
987
987
llvm::Value *min = llvm::ConstantFP::get (m_llvmCtx, llvm::APFloat (0.0 ));
@@ -1012,7 +1012,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
1012
1012
const auto &arg = step.args [0 ];
1013
1013
LLVMListPtr &listPtr = m_listPtrs[step.workList ];
1014
1014
1015
- if (!isVarOrListTypeSafe (insPtr, listPtr.type ))
1015
+ if (!isVarOrListTypeSafe (insPtr. get () , listPtr.type ))
1016
1016
listPtr.type = Compiler::StaticType::Unknown;
1017
1017
1018
1018
step.functionReturnReg ->value = m_builder.CreateSIToFP (getListItemIndex (listPtr, arg.second ), m_builder.getDoubleTy ());
@@ -1024,7 +1024,7 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
1024
1024
const auto &arg = step.args [0 ];
1025
1025
LLVMListPtr &listPtr = m_listPtrs[step.workList ];
1026
1026
1027
- if (!isVarOrListTypeSafe (insPtr, listPtr.type ))
1027
+ if (!isVarOrListTypeSafe (insPtr. get () , listPtr.type ))
1028
1028
listPtr.type = Compiler::StaticType::Unknown;
1029
1029
1030
1030
llvm::Value *index = getListItemIndex (listPtr, arg.second );
@@ -1460,7 +1460,7 @@ CompilerValue *LLVMCodeBuilder::addVariableValue(Variable *variable)
1460
1460
1461
1461
m_instructions.addInstruction (ins);
1462
1462
m_instructionList.push_back (ins);
1463
- m_variableInstructions.push_back (m_instructionList. back ());
1463
+ m_variableInstructions.push_back (ins. get ());
1464
1464
return addReg (ret, ins);
1465
1465
}
1466
1466
@@ -1491,7 +1491,7 @@ CompilerValue *LLVMCodeBuilder::addListItem(List *list, CompilerValue *index)
1491
1491
1492
1492
m_instructions.addInstruction (ins);
1493
1493
m_instructionList.push_back (ins);
1494
- m_listInstructions.push_back (m_instructionList. back ());
1494
+ m_listInstructions.push_back (ins. get ());
1495
1495
return addReg (ret, ins);
1496
1496
}
1497
1497
@@ -1504,7 +1504,7 @@ CompilerValue *LLVMCodeBuilder::addListItemIndex(List *list, CompilerValue *item
1504
1504
m_listPtrs[list] = LLVMListPtr ();
1505
1505
1506
1506
auto ret = createOp (ins, Compiler::StaticType::Number, Compiler::StaticType::Unknown, { item });
1507
- m_listInstructions.push_back (m_instructionList. back ());
1507
+ m_listInstructions.push_back (m_instructions. last ());
1508
1508
return ret;
1509
1509
}
1510
1510
@@ -1517,7 +1517,7 @@ CompilerValue *LLVMCodeBuilder::addListContains(List *list, CompilerValue *item)
1517
1517
m_listPtrs[list] = LLVMListPtr ();
1518
1518
1519
1519
auto ret = createOp (ins, Compiler::StaticType::Bool, Compiler::StaticType::Unknown, { item });
1520
- m_listInstructions.push_back (m_instructionList. back ());
1520
+ m_listInstructions.push_back (m_instructions. last ());
1521
1521
return ret;
1522
1522
}
1523
1523
@@ -1745,7 +1745,7 @@ void LLVMCodeBuilder::createVariableWrite(Variable *variable, CompilerValue *val
1745
1745
m_variablePtrs[variable].loopVariableWrites [scope.get ()].push_back (m_instructionList.back ());
1746
1746
}
1747
1747
1748
- m_variableInstructions.push_back (m_instructionList. back ());
1748
+ m_variableInstructions.push_back (m_instructions. last ());
1749
1749
}
1750
1750
1751
1751
void LLVMCodeBuilder::createListClear (List *list)
@@ -1782,7 +1782,7 @@ void LLVMCodeBuilder::createListAppend(List *list, CompilerValue *item)
1782
1782
m_listPtrs[list].loopListWrites [scope.get ()].push_back (m_instructionList.back ());
1783
1783
}
1784
1784
1785
- m_listInstructions.push_back (m_instructionList. back ());
1785
+ m_listInstructions.push_back (m_instructions. last ());
1786
1786
}
1787
1787
1788
1788
void LLVMCodeBuilder::createListInsert (List *list, CompilerValue *index, CompilerValue *item)
@@ -1799,7 +1799,7 @@ void LLVMCodeBuilder::createListInsert(List *list, CompilerValue *index, Compile
1799
1799
m_listPtrs[list].loopListWrites [scope.get ()].push_back (m_instructionList.back ());
1800
1800
}
1801
1801
1802
- m_listInstructions.push_back (m_instructionList. back ());
1802
+ m_listInstructions.push_back (m_instructions. last ());
1803
1803
}
1804
1804
1805
1805
void LLVMCodeBuilder::createListReplace (List *list, CompilerValue *index, CompilerValue *item)
@@ -1816,7 +1816,7 @@ void LLVMCodeBuilder::createListReplace(List *list, CompilerValue *index, Compil
1816
1816
m_listPtrs[list].loopListWrites [scope.get ()].push_back (m_instructionList.back ());
1817
1817
}
1818
1818
1819
- m_listInstructions.push_back (m_instructionList. back ());
1819
+ m_listInstructions.push_back (m_instructions. last ());
1820
1820
}
1821
1821
1822
1822
void LLVMCodeBuilder::beginIfStatement (CompilerValue *cond)
@@ -2528,14 +2528,14 @@ void LLVMCodeBuilder::updateListDataPtr(const LLVMListPtr &listPtr)
2528
2528
m_builder.CreateStore (m_builder.getInt1 (false ), listPtr.dataPtrDirty );
2529
2529
}
2530
2530
2531
- bool LLVMCodeBuilder::isVarOrListTypeSafe (std::shared_ptr< LLVMInstruction> ins, Compiler::StaticType expectedType) const
2531
+ bool LLVMCodeBuilder::isVarOrListTypeSafe (LLVMInstruction * ins, Compiler::StaticType expectedType) const
2532
2532
{
2533
2533
std::unordered_set<LLVMInstruction *> processed;
2534
2534
int counter = 0 ;
2535
2535
return isVarOrListTypeSafe (ins, expectedType, processed, counter);
2536
2536
}
2537
2537
2538
- bool LLVMCodeBuilder::isVarOrListTypeSafe (std::shared_ptr< LLVMInstruction> ins, Compiler::StaticType expectedType, std::unordered_set<LLVMInstruction *> &log, int &c) const
2538
+ bool LLVMCodeBuilder::isVarOrListTypeSafe (LLVMInstruction * ins, Compiler::StaticType expectedType, std::unordered_set<LLVMInstruction *> &log, int &c) const
2539
2539
{
2540
2540
/*
2541
2541
* The main part of the loop type analyzer.
@@ -2571,12 +2571,12 @@ bool LLVMCodeBuilder::isVarOrListTypeSafe(std::shared_ptr<LLVMInstruction> ins,
2571
2571
*
2572
2572
* Increment counter to ignore last n write operations.
2573
2573
*/
2574
- if (log.find (ins. get () ) != log.cend ())
2574
+ if (log.find (ins) != log.cend ())
2575
2575
c++;
2576
2576
else
2577
- log.insert (ins. get () );
2577
+ log.insert (ins);
2578
2578
2579
- assert (std::find (m_instructionList. begin (), m_instructionList. end (), ins) != m_instructionList. end ( ));
2579
+ assert (m_instructions. containsInstruction ( ins));
2580
2580
const LLVMVariablePtr *varPtr = ins->workVariable ? &m_variablePtrs.at (ins->workVariable ) : nullptr ;
2581
2581
const LLVMListPtr *listPtr = ins->workList ? &m_listPtrs.at (ins->workList ) : nullptr ;
2582
2582
assert ((varPtr || listPtr) && !(varPtr && listPtr));
@@ -2590,7 +2590,7 @@ bool LLVMCodeBuilder::isVarOrListTypeSafe(std::shared_ptr<LLVMInstruction> ins,
2590
2590
if (scope->containsYield && !m_warp)
2591
2591
return false ;
2592
2592
2593
- std::shared_ptr< LLVMInstruction> write;
2593
+ LLVMInstruction * write = nullptr ;
2594
2594
const auto &instructions = varPtr ? m_variableInstructions : m_listInstructions;
2595
2595
2596
2596
// Find this instruction
@@ -2646,7 +2646,7 @@ bool LLVMCodeBuilder::isVarOrListTypeSafe(std::shared_ptr<LLVMInstruction> ins,
2646
2646
}
2647
2647
2648
2648
// Get all write operations in all loop scopes (from the root loop scope)
2649
- std::vector<std::shared_ptr< LLVMInstruction> > lastWrites;
2649
+ std::vector<LLVMInstruction * > lastWrites;
2650
2650
2651
2651
while (checkScope) {
2652
2652
auto it = loopWrites.find (checkScope);
@@ -2656,7 +2656,7 @@ bool LLVMCodeBuilder::isVarOrListTypeSafe(std::shared_ptr<LLVMInstruction> ins,
2656
2656
const auto &writes = it->second ;
2657
2657
2658
2658
for (auto w : writes)
2659
- lastWrites.push_back (w);
2659
+ lastWrites.push_back (w. get () );
2660
2660
}
2661
2661
2662
2662
if (checkScope->childScopes .empty ())
@@ -2693,8 +2693,7 @@ bool LLVMCodeBuilder::isVarOrListTypeSafe(std::shared_ptr<LLVMInstruction> ins,
2693
2693
return false ;
2694
2694
}
2695
2695
2696
- bool LLVMCodeBuilder::isVarOrListWriteResultTypeSafe (std::shared_ptr<LLVMInstruction> ins, Compiler::StaticType expectedType, bool ignoreSavedType, std::unordered_set<LLVMInstruction *> &log, int &c)
2697
- const
2696
+ bool LLVMCodeBuilder::isVarOrListWriteResultTypeSafe (LLVMInstruction *ins, Compiler::StaticType expectedType, bool ignoreSavedType, std::unordered_set<LLVMInstruction *> &log, int &c) const
2698
2697
{
2699
2698
const LLVMVariablePtr *varPtr = ins->workVariable ? &m_variablePtrs.at (ins->workVariable ) : nullptr ;
2700
2699
const LLVMListPtr *listPtr = ins->workList ? &m_listPtrs.at (ins->workList ) : nullptr ;
@@ -2705,7 +2704,7 @@ bool LLVMCodeBuilder::isVarOrListWriteResultTypeSafe(std::shared_ptr<LLVMInstruc
2705
2704
auto argIns = arg->instruction ;
2706
2705
2707
2706
if (argIns && (argIns->type == LLVMInstruction::Type::ReadVariable || argIns->type == LLVMInstruction::Type::GetListItem))
2708
- return isVarOrListTypeSafe (argIns, expectedType, log, c);
2707
+ return isVarOrListTypeSafe (argIns. get () , expectedType, log, c);
2709
2708
2710
2709
// Check written type
2711
2710
const bool typeMatches = (optimizeRegisterType (arg) == expectedType);
0 commit comments