Skip to content

Commit b497e77

Browse files
committed
Read variable/list type from LLVMInstruction
1 parent b2aeaa0 commit b497e77

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

src/engine/internal/llvm/instructions/lists.cpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ LLVMInstruction *Lists::buildAppendToList(LLVMInstruction *ins)
109109
Compiler::StaticType type = m_utils.optimizeRegisterType(arg.second);
110110
LLVMListPtr &listPtr = m_utils.listPtr(ins->workList);
111111

112-
Compiler::StaticType listType = Compiler::StaticType::Unknown;
113-
114-
/*if (m_utils.warp())
115-
listType = m_utils.typeAnalyzer().listType(ins->workList, ins, Compiler::StaticType::Unknown, false);*/
112+
Compiler::StaticType listType = ins->targetType;
116113

117114
// Check if enough space is allocated
118115
llvm::Value *allocatedSize = m_builder.CreateLoad(m_builder.getInt64Ty(), listPtr.allocatedSizePtr);
@@ -151,10 +148,7 @@ LLVMInstruction *Lists::buildInsertToList(LLVMInstruction *ins)
151148
Compiler::StaticType type = m_utils.optimizeRegisterType(valueArg.second);
152149
LLVMListPtr &listPtr = m_utils.listPtr(ins->workList);
153150

154-
Compiler::StaticType listType = Compiler::StaticType::Unknown;
155-
156-
/*if (m_utils.warp())
157-
listType = m_utils.typeAnalyzer().listType(ins->workList, ins, Compiler::StaticType::Unknown, false);*/
151+
Compiler::StaticType listType = ins->targetType;
158152

159153
// Range check
160154
llvm::Value *size = m_builder.CreateLoad(m_builder.getInt64Ty(), listPtr.sizePtr);
@@ -189,10 +183,7 @@ LLVMInstruction *Lists::buildListReplace(LLVMInstruction *ins)
189183
Compiler::StaticType type = m_utils.optimizeRegisterType(valueArg.second);
190184
LLVMListPtr &listPtr = m_utils.listPtr(ins->workList);
191185

192-
Compiler::StaticType listType = Compiler::StaticType::Unknown;
193-
194-
/*if (m_utils.warp())
195-
listType = m_utils.typeAnalyzer().listType(ins->workList, ins, Compiler::StaticType::Unknown, false);*/
186+
Compiler::StaticType listType = ins->targetType;
196187

197188
// Range check
198189
llvm::Value *min = llvm::ConstantFP::get(llvmCtx, llvm::APFloat(0.0));
@@ -232,10 +223,7 @@ LLVMInstruction *Lists::buildGetListItem(LLVMInstruction *ins)
232223
const auto &arg = ins->args[0];
233224
LLVMListPtr &listPtr = m_utils.listPtr(ins->workList);
234225

235-
Compiler::StaticType listType = Compiler::StaticType::Unknown;
236-
237-
/*if (m_utils.warp())
238-
listType = m_utils.typeAnalyzer().listType(ins->workList, ins, Compiler::StaticType::Unknown, false);*/
226+
Compiler::StaticType listType = ins->functionReturnReg->type();
239227

240228
llvm::Value *min = llvm::ConstantFP::get(m_utils.llvmCtx(), llvm::APFloat(0.0));
241229
llvm::Value *size = m_builder.CreateLoad(m_builder.getInt64Ty(), listPtr.sizePtr);
@@ -248,7 +236,6 @@ LLVMInstruction *Lists::buildGetListItem(LLVMInstruction *ins)
248236

249237
index = m_builder.CreateFPToUI(index, m_builder.getInt64Ty());
250238
ins->functionReturnReg->value = m_builder.CreateSelect(inRange, m_utils.getListItem(listPtr, index), null);
251-
ins->functionReturnReg->setType(listType);
252239

253240
return ins->next;
254241
}
@@ -269,10 +256,7 @@ LLVMInstruction *Lists::buildGetListItemIndex(LLVMInstruction *ins)
269256
const auto &arg = ins->args[0];
270257
LLVMListPtr &listPtr = m_utils.listPtr(ins->workList);
271258

272-
Compiler::StaticType listType = Compiler::StaticType::Unknown;
273-
274-
/*if (m_utils.warp())
275-
listType = m_utils.typeAnalyzer().listType(ins->workList, ins, Compiler::StaticType::Unknown, false);*/
259+
Compiler::StaticType listType = ins->targetType;
276260

277261
ins->functionReturnReg->value = m_builder.CreateSIToFP(m_utils.getListItemIndex(listPtr, listType, arg.second), m_builder.getDoubleTy());
278262
return ins->next;
@@ -284,10 +268,7 @@ LLVMInstruction *Lists::buildListContainsItem(LLVMInstruction *ins)
284268
const auto &arg = ins->args[0];
285269
LLVMListPtr &listPtr = m_utils.listPtr(ins->workList);
286270

287-
Compiler::StaticType listType = Compiler::StaticType::Unknown;
288-
289-
/*if (m_utils.warp())
290-
listType = m_utils.typeAnalyzer().listType(ins->workList, ins, Compiler::StaticType::Unknown, false);*/
271+
Compiler::StaticType listType = ins->targetType;
291272

292273
llvm::Value *index = m_utils.getListItemIndex(listPtr, listType, arg.second);
293274
ins->functionReturnReg->value = m_builder.CreateICmpSGT(index, llvm::ConstantInt::get(m_builder.getInt64Ty(), -1, true));

src/engine/internal/llvm/instructions/variables.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ LLVMInstruction *Variables::buildWriteVariable(LLVMInstruction *ins)
113113
LLVMVariablePtr &varPtr = m_utils.variablePtr(ins->workVariable);
114114
varPtr.changed = true; // TODO: Handle loops and if statements
115115

116-
Compiler::StaticType varType = Compiler::StaticType::Unknown;
117-
118-
/*if (m_utils.warp())
119-
varType = m_utils.typeAnalyzer().variableType(ins->workVariable, ins, Compiler::StaticType::Unknown);*/
120-
121116
// Initialize stack variable on first assignment
122117
// TODO: Use stack in the top level (outside loops and if statements)
123118
/*if (!varPtr.onStack) {
@@ -139,20 +134,15 @@ LLVMInstruction *Variables::buildWriteVariable(LLVMInstruction *ins)
139134
m_builder.CreateStore(m_builder.getInt32(static_cast<uint32_t>(mappedType)), typeField);
140135
}*/
141136

142-
m_utils.createValueStore(arg.second, varPtr.stackPtr, argType, varType);
137+
m_utils.createValueStore(arg.second, varPtr.stackPtr, argType, ins->targetType);
143138
return ins->next;
144139
}
145140

146141
LLVMInstruction *Variables::buildReadVariable(LLVMInstruction *ins)
147142
{
148143
assert(ins->args.size() == 0);
149144
LLVMVariablePtr &varPtr = m_utils.variablePtr(ins->workVariable);
150-
Compiler::StaticType type = Compiler::StaticType::Unknown;
151-
152-
/*if (m_utils.warp())
153-
type = m_utils.typeAnalyzer().variableType(ins->workVariable, ins, Compiler::StaticType::Unknown);*/
154145

155146
ins->functionReturnReg->value = varPtr.onStack && !(ins->loopCondition && !m_utils.warp()) ? varPtr.stackPtr : varPtr.heapPtr;
156-
ins->functionReturnReg->setType(type);
157147
return ins->next;
158148
}

0 commit comments

Comments
 (0)