755 switch (ins.opcode) {
769 simulationStack.push(compilerCtx->getShortObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.shortV);
773 simulationStack.push(compilerCtx->getUnsignedObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.unsignedV);
777 simulationStack.push(compilerCtx->getStrObjectType(), {currentCodeBlockIndex, {insIndex}});
781 simulationStack.push(
782 compilerCtx->getCharObjectType(), {currentCodeBlockIndex, {insIndex}},
static_cast<char>(ins.operands[0].value.character));
786 auto value = simulationStack.peek(0);
787 simulationStack.pop();
788 if (
value.hasPossibleValue) {
789 switch (
value.type->type) {
791 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.deciValue);
794 value.possibleValue.charValue =
value.possibleValue.boolValue ? 1 : 0;
797 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.intValue);
800 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.shortValue);
803 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.unsignedValue);
808 value.type = compilerCtx->getCharObjectType();
809 insIndex = reduce(
value.contributedInstructions, insIndex);
811 insIndex = generatePushOp(value, insIndex);
813 simulationStack.push(compilerCtx->getCharObjectType(),
814 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
815 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
820 auto value = simulationStack.peek(0);
821 simulationStack.pop();
823 if (
value.hasPossibleValue) {
824 switch (
value.type->type) {
826 value.possibleValue.boolValue =
value.possibleValue.intValue != 0;
829 value.possibleValue.boolValue =
value.possibleValue.deciValue != 0.0;
832 value.possibleValue.boolValue =
value.possibleValue.charValue != 0;
835 value.possibleValue.boolValue =
value.possibleValue.shortValue != 0;
838 value.possibleValue.boolValue =
value.possibleValue.unsignedValue != 0;
843 value.type = compilerCtx->getBoolObjectType();
844 insIndex = reduce(
value.contributedInstructions, insIndex);
846 insIndex = generatePushOp(value, insIndex);
848 simulationStack.push(compilerCtx->getBoolObjectType(),
849 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
850 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
855 auto value = simulationStack.peek(0);
856 simulationStack.pop();
857 if (
value.hasPossibleValue) {
858 switch (
value.type->type) {
860 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.deciValue);
863 value.possibleValue.intValue =
value.possibleValue.boolValue ? 1 : 0;
866 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.charValue);
869 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.shortValue);
872 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.unsignedValue);
877 value.type = compilerCtx->getIntObjectType();
878 insIndex = reduce(
value.contributedInstructions, insIndex);
880 insIndex = generatePushOp(value, insIndex);
882 simulationStack.push(compilerCtx->getIntObjectType(),
883 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
884 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
889 auto value = simulationStack.peek(0);
890 simulationStack.pop();
892 if (
value.hasPossibleValue) {
893 switch (
value.type->type) {
895 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.intValue);
898 value.possibleValue.deciValue =
value.possibleValue.boolValue ? 1.0 : 0.0;
901 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.charValue);
904 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.unsignedValue);
907 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.shortValue);
912 value.type = compilerCtx->getDeciObjectType();
913 insIndex = reduce(
value.contributedInstructions, insIndex);
915 insIndex = generatePushOp(value, insIndex);
917 simulationStack.push(compilerCtx->getDeciObjectType(),
918 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
919 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
924 auto value = simulationStack.peek(0);
925 simulationStack.pop();
927 if (
value.hasPossibleValue) {
928 switch (
value.type->type) {
930 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.intValue);
933 value.possibleValue.shortValue =
value.possibleValue.boolValue;
936 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.charValue);
939 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.unsignedValue);
942 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.deciValue);
947 value.type = compilerCtx->getShortObjectType();
948 insIndex = reduce(
value.contributedInstructions, insIndex);
950 insIndex = generatePushOp(value, insIndex);
952 simulationStack.push(compilerCtx->getShortObjectType(),
953 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
954 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
959 auto value = simulationStack.peek(0);
960 simulationStack.pop();
962 if (
value.hasPossibleValue) {
963 switch (
value.type->type) {
965 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.intValue);
968 value.possibleValue.unsignedValue =
value.possibleValue.boolValue;
971 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.charValue);
974 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.shortValue);
977 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.deciValue);
982 value.type = compilerCtx->getUnsignedObjectType();
983 insIndex = reduce(
value.contributedInstructions, insIndex);
985 insIndex = generatePushOp(value, insIndex);
987 simulationStack.push(compilerCtx->getUnsignedObjectType(),
988 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
989 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
994 auto right = simulationStack.peek(0);
995 auto left = simulationStack.peek(1);
996 simulationStack.pop();
997 simulationStack.pop();
999 auto result = add(left, right);
1002 if (result.hasPossibleValue) {
1003 insIndex = reduce(left.contributedInstructions, insIndex);
1004 insIndex = reduce(right.contributedInstructions, insIndex);
1006 insIndex = generatePushOp(result, insIndex);
1009 simulationStack.push(
1011 left.contributedInstructions + right.contributedInstructions +
1012 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1017 auto right = simulationStack.peek(0);
1018 auto left = simulationStack.peek(1);
1019 simulationStack.pop();
1020 simulationStack.pop();
1022 auto result = sub(left, right);
1025 if (result.hasPossibleValue) {
1026 insIndex = reduce(left.contributedInstructions, insIndex);
1027 insIndex = reduce(right.contributedInstructions, insIndex);
1029 insIndex = generatePushOp(result, insIndex);
1032 simulationStack.push(
1034 left.contributedInstructions + right.contributedInstructions +
1035 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1040 auto right = simulationStack.peek(0);
1041 auto left = simulationStack.peek(1);
1042 simulationStack.pop();
1043 simulationStack.pop();
1045 auto result = mul(left, right);
1048 if (result.hasPossibleValue) {
1049 insIndex = reduce(left.contributedInstructions, insIndex);
1050 insIndex = reduce(right.contributedInstructions, insIndex);
1052 insIndex = generatePushOp(result, insIndex);
1055 simulationStack.push(
1057 left.contributedInstructions + right.contributedInstructions +
1058 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1063 auto right = simulationStack.peek(0);
1064 auto left = simulationStack.peek(1);
1065 simulationStack.pop();
1066 simulationStack.pop();
1068 auto result = div(left, right);
1071 if (result.hasPossibleValue) {
1072 insIndex = reduce(left.contributedInstructions, insIndex);
1073 insIndex = reduce(right.contributedInstructions, insIndex);
1075 insIndex = generatePushOp(result, insIndex);
1078 simulationStack.push(
1080 left.contributedInstructions + right.contributedInstructions +
1081 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1086 auto right = simulationStack.peek(0);
1087 auto left = simulationStack.peek(1);
1088 simulationStack.pop();
1089 simulationStack.pop();
1091 auto result = mod(left, right);
1092 if (result.hasPossibleValue) {
1093 insIndex = reduce(left.contributedInstructions, insIndex);
1094 insIndex = reduce(right.contributedInstructions, insIndex);
1096 insIndex = generatePushOp(result, insIndex);
1099 simulationStack.push(
1101 left.contributedInstructions + right.contributedInstructions +
1102 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1107 auto value = simulationStack.peek(0);
1108 simulationStack.pop();
1110 auto result = negate(value);
1111 if (result.hasPossibleValue) {
1112 insIndex = reduce(
value.contributedInstructions, insIndex);
1114 insIndex = generatePushOp(result, insIndex);
1117 simulationStack.push(result.type,
1118 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
1119 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1124 auto right = simulationStack.peek(0);
1125 auto left = simulationStack.peek(1);
1126 simulationStack.pop();
1127 simulationStack.pop();
1129 auto result = bitwiseAnd(left, right);
1130 if (result.hasPossibleValue) {
1131 insIndex = reduce(left.contributedInstructions, insIndex);
1132 insIndex = reduce(right.contributedInstructions, insIndex);
1134 insIndex = generatePushOp(result, insIndex);
1137 simulationStack.push(
1139 left.contributedInstructions + right.contributedInstructions +
1140 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1145 auto right = simulationStack.peek(0);
1146 auto left = simulationStack.peek(1);
1147 simulationStack.pop();
1148 simulationStack.pop();
1150 auto result = bitwiseOr(left, right);
1151 if (result.hasPossibleValue) {
1152 insIndex = reduce(left.contributedInstructions, insIndex);
1153 insIndex = reduce(right.contributedInstructions, insIndex);
1155 insIndex = generatePushOp(result, insIndex);
1158 simulationStack.push(
1160 left.contributedInstructions + right.contributedInstructions +
1161 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1166 auto right = simulationStack.peek(0);
1167 auto left = simulationStack.peek(1);
1168 simulationStack.pop();
1169 simulationStack.pop();
1171 auto result = bitwiseXor(left, right);
1172 if (result.hasPossibleValue) {
1173 insIndex = reduce(left.contributedInstructions, insIndex);
1174 insIndex = reduce(right.contributedInstructions, insIndex);
1176 insIndex = generatePushOp(result, insIndex);
1179 simulationStack.push(
1181 left.contributedInstructions + right.contributedInstructions +
1182 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1187 auto value = simulationStack.peek(0);
1188 simulationStack.pop();
1190 auto result = bitwiseNot(value);
1191 if (result.hasPossibleValue) {
1192 insIndex = reduce(
value.contributedInstructions, insIndex);
1193 insIndex = generatePushOp(result, insIndex);
1196 simulationStack.push(result.type,
1197 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
1198 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1203 auto shift = simulationStack.peek(0);
1204 auto value = simulationStack.peek(1);
1205 simulationStack.pop();
1206 simulationStack.pop();
1208 auto result = bitwiseShiftLeft(value, shift);
1209 if (result.hasPossibleValue) {
1210 insIndex = reduce(
value.contributedInstructions, insIndex);
1211 insIndex = reduce(shift.contributedInstructions, insIndex);
1213 insIndex = generatePushOp(result, insIndex);
1216 simulationStack.push(
1218 value.contributedInstructions + shift.contributedInstructions +
1219 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1224 auto shift = simulationStack.peek(0);
1225 auto value = simulationStack.peek(1);
1226 simulationStack.pop();
1227 simulationStack.pop();
1229 auto result = bitwiseShiftRight(value, shift);
1230 if (result.hasPossibleValue) {
1231 insIndex = reduce(
value.contributedInstructions, insIndex);
1232 insIndex = reduce(shift.contributedInstructions, insIndex);
1234 insIndex = generatePushOp(result, insIndex);
1237 simulationStack.push(
1239 value.contributedInstructions + shift.contributedInstructions +
1240 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1245 auto right = simulationStack.peek(0);
1246 auto left = simulationStack.peek(1);
1247 simulationStack.pop();
1248 simulationStack.pop();
1250 auto result = lessThan(left, right);
1251 if (result.hasPossibleValue) {
1252 insIndex = reduce(left.contributedInstructions, insIndex);
1253 insIndex = reduce(right.contributedInstructions, insIndex);
1255 insIndex = generatePushOp(result, insIndex);
1258 simulationStack.push(
1260 left.contributedInstructions + right.contributedInstructions +
1261 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1266 auto right = simulationStack.peek(0);
1267 auto left = simulationStack.peek(1);
1268 simulationStack.pop();
1269 simulationStack.pop();
1271 auto result = greaterThan(left, right);
1272 if (result.hasPossibleValue) {
1273 insIndex = reduce(left.contributedInstructions, insIndex);
1274 insIndex = reduce(right.contributedInstructions, insIndex);
1276 insIndex = generatePushOp(result, insIndex);
1279 simulationStack.push(
1281 left.contributedInstructions + right.contributedInstructions +
1282 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1287 auto right = simulationStack.peek(0);
1288 auto left = simulationStack.peek(1);
1289 simulationStack.pop();
1290 simulationStack.pop();
1292 auto result = greaterThanOrEqual(left, right);
1293 if (result.hasPossibleValue) {
1294 insIndex = reduce(left.contributedInstructions, insIndex);
1295 insIndex = reduce(right.contributedInstructions, insIndex);
1297 insIndex = generatePushOp(result, insIndex);
1300 simulationStack.push(
1302 left.contributedInstructions + right.contributedInstructions +
1303 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1308 auto right = simulationStack.peek(0);
1309 auto left = simulationStack.peek(1);
1310 simulationStack.pop();
1311 simulationStack.pop();
1313 auto result = greaterThanOrEqual(left, right);
1314 if (result.hasPossibleValue) {
1315 insIndex = reduce(left.contributedInstructions, insIndex);
1316 insIndex = reduce(right.contributedInstructions, insIndex);
1318 insIndex = generatePushOp(result, insIndex);
1321 simulationStack.push(
1323 left.contributedInstructions + right.contributedInstructions +
1324 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1329 auto right = simulationStack.peek(0);
1330 auto left = simulationStack.peek(1);
1331 simulationStack.pop();
1332 simulationStack.pop();
1334 auto result = equal(left, right);
1335 if (result.hasPossibleValue) {
1336 insIndex = reduce(left.contributedInstructions, insIndex);
1337 insIndex = reduce(right.contributedInstructions, insIndex);
1339 insIndex = generatePushOp(result, insIndex);
1342 simulationStack.push(
1344 left.contributedInstructions + right.contributedInstructions +
1345 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1350 auto right = simulationStack.peek(0);
1351 auto left = simulationStack.peek(1);
1352 simulationStack.pop();
1353 simulationStack.pop();
1355 auto result = notEqual(left, right);
1356 if (result.hasPossibleValue) {
1357 insIndex = reduce(left.contributedInstructions, insIndex);
1358 insIndex = reduce(right.contributedInstructions, insIndex);
1360 insIndex = generatePushOp(result, insIndex);
1363 simulationStack.push(
1365 left.contributedInstructions + right.contributedInstructions +
1366 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1371 if (
auto it = variablesExtraInfo.find(ins.operands[0].value.symbolIndex); it != variablesExtraInfo.end()) {
1373 if (it->second.hasPossibleValue && it->second.possibleValue.contributedInstructions.codeBlockIndex == currentCodeBlockIndex) {
1375 simulationStack.push(it->second.possibleValue.type,
1376 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
1377 it->second.isReadAfterStore =
false;
1381 auto type = targetFunction->getVariableTable().get(ins.operands[0].value.symbolIndex);
1382 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
1383 it->second.isReadAfterStore =
true;
1388 auto type = targetFunction->getVariableTable().get(ins.operands[0].value.symbolIndex);
1389 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
1390 variablesExtraInfo[ins.operands[0].value.symbolIndex] = {
false,
true, {}};
1400 auto definitionType = targetFunction->getVariableTable().get(ins.operands[0].value.symbolIndex);
1401 auto value = simulationStack.peek(0);
1403 if (
value.type->isForeignBasicType()) {
1404 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
1409 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::reduceRedundantConstantExpr(): store_local: type mismatch");
1412 simulationStack.pop();
1413 if (
auto it = variablesExtraInfo.find(ins.operands[0].value.symbolIndex);
1414 it != variablesExtraInfo.end() && it->second.hasPossibleValue && !it->second.isReadAfterStore &&
1415 it->second.possibleValue.contributedInstructions.codeBlockIndex == currentCodeBlockIndex) {
1417 insIndex = reduce(it->second.possibleValue.contributedInstructions, insIndex);
1418 variablesExtraInfo[ins.operands[0].value.symbolIndex] = {
value.hasPossibleValue,
false,
value};
1420 value.contributedInstructions =
1421 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}};
1422 variablesExtraInfo[ins.operands[0].value.symbolIndex] = {
value.hasPossibleValue,
false,
value};
1428 auto moduleIndex = ins.operands[0].value.symbolIndex;
1429 auto type = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
1430 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
1435 auto moduleIndex = ins.operands[0].value.symbolIndex;
1436 auto definitionType = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
1437 auto value = simulationStack.peek(0);
1439 if (
value.type->isForeignBasicType()) {
1440 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
1446 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::reduceRedundantConstantExpr(): store_global: type mismatch");
1449 simulationStack.pop();
1454 auto value = simulationStack.peek(0);
1455 auto type =
value.type->typeIndex;
1456 auto targetModule = compilerCtx->getImportedModule(
value.type->typeAffiliateModule);
1457 auto structDef = targetModule->structTable[type];
1458 auto memberIndex = ins.operands[0].value.symbolIndex;
1459 auto memberDef =
managedPtr(*structDef->fieldTypes[memberIndex]);
1460 simulationStack.pop();
1461 simulationStack.push(memberDef,
1462 value.contributedInstructions +
1463 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
1468 auto value = simulationStack.peek(1);
1469 auto type = simulationStack.peek(0).type->typeIndex;
1470 auto structDef = compilerCtx->getImportedModule(simulationStack.peek(0).type->typeAffiliateModule)->structTable[type];
1471 auto memberIndex = ins.operands[0].value.symbolIndex;
1472 auto memberDef = structDef->fieldTypes[memberIndex];
1474 if (
value.type->isForeignBasicType()) {
1475 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
1481 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::reduceRedundantConstantExpr(): store_member: type mismatch");
1484 simulationStack.pop();
1485 simulationStack.pop();
1492 auto moduleIndex = ins.operands[0].value.symbolIndex;
1493 auto function = compilerCtx->getImportedModule(moduleIndex)->functionTable[ins.operands[1].value.symbolIndex];
1495 auto argTypes = function->argumentTypes;
1496 auto argCount = function->argumentTypes.size();
1497 SimulationStack::Item::ContributedInstructionSet contributedInstructions = {currentCodeBlockIndex, {insIndex},
false};
1498 for (
int i = 0; i < argCount; i++) {
1499 contributedInstructions = contributedInstructions + simulationStack.peek(0).contributedInstructions;
1500 simulationStack.pop();
1502 simulationStack.push(returnType, contributedInstructions);
1506 auto function = compilerCtx->getIRFFITable()
1507 ->importedLibraries[ins.operands[0].value.symbolIndex]
1508 .importedFunctionTable[ins.operands[1].value.symbolIndex];
1509 auto returnType = function->returnType;
1510 auto argTypes = function->argumentTypes;
1511 auto argCount = function->argumentTypes.size();
1512 for (
int i = 0; i < argCount; i++) {
1513 simulationStack.pop();
1515 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
1519 auto argCount = ins.operands[3].value.symbolIndex;
1520 for (
int i = 0; i < argCount - 1; i++) {
1521 simulationStack.pop();
1523 auto returnType = compilerCtx->getImportedModule(ins.operands[0].value.symbolIndex)
1524 ->interfaceTable[ins.operands[1].value.symbolIndex]
1525 ->methodMap[ins.operands[2].value.symbolIndex]
1528 simulationStack.pop();
1529 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
1533 auto moduleIndex = ins.operands[0].value.symbolIndex;
1534 auto structDef = compilerCtx->getImportedModule(moduleIndex)->structTable[ins.operands[1].value.symbolIndex];
1535 simulationStack.push(
1537 {currentCodeBlockIndex, {insIndex},
false});
1541 auto moduleIndex = ins.operands[0].value.symbolIndex;
1542 auto interfaceImplDef =
1543 compilerCtx->getImportedModule(moduleIndex)->interfaceImplementationTable[ins.operands[1].value.symbolIndex];
1545 interfaceImplDef->implInterfaceIndex.first,
1546 interfaceImplDef->implInterfaceIndex.second});
1547 simulationStack.pop();
1548 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
1552 auto condition = simulationStack.peek(0);
1553 simulationStack.pop();
1554 if (condition.hasPossibleValue) {
1555 if (condition.possibleValue.boolValue) {
1558 insIndex = reduce(condition.contributedInstructions, insIndex);
1562 insIndex = reduce(condition.contributedInstructions, insIndex);
1563 insIndex = reduce(SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}}, insIndex);
1573 auto condition = simulationStack.peek(0);
1574 simulationStack.pop();
1575 if (condition.hasPossibleValue) {
1576 if (!condition.possibleValue.boolValue) {
1579 insIndex = reduce(condition.contributedInstructions, insIndex);
1583 insIndex = reduce(condition.contributedInstructions, insIndex);
1584 insIndex = reduce(SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}}, insIndex);
1595 simulationStack.pop();
1607 std::shared_ptr<IRValueType> baseType;
1608 switch (ins.opcode) {
1610 baseType = compilerCtx->getIntObjectType();
1613 baseType = compilerCtx->getBoolObjectType();
1616 baseType = compilerCtx->getCharObjectType();
1619 baseType = compilerCtx->getDeciObjectType();
1622 baseType = compilerCtx->getStrObjectType();
1625 baseType = compilerCtx->getShortObjectType();
1628 baseType = compilerCtx->getUnsignedObjectType();
1637 for (
auto i = 1; i < ins.operands.size(); i++) {
1638 size *= ins.operands[i].value.symbolIndex;
1639 dims.push_back(ins.operands[i].value.symbolIndex);
1641 for (
yoi::indexT i = 0; i < ins.operands[0].value.symbolIndex; i++) {
1642 simulationStack.pop();
1644 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
1649 auto moduleIndex = ins.operands[0].value.symbolIndex;
1650 auto typeIndex = ins.operands[1].value.symbolIndex;
1659 for (
yoi::indexT i = 3; i < ins.operands.size(); i++) {
1660 size *= ins.operands[i].value.symbolIndex;
1661 dims.push_back(ins.operands[i].value.symbolIndex);
1663 for (
yoi::indexT i = 0; i < ins.operands[2].value.symbolIndex; i++) {
1664 simulationStack.pop();
1666 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
1671 auto index = simulationStack.peek(0);
1672 auto array = simulationStack.peek(1);
1673 simulationStack.pop();
1674 simulationStack.pop();
1675 simulationStack.push(
managedPtr(array.type->getElementType()),
1676 array.contributedInstructions + index.contributedInstructions +
1677 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
1682 auto index = simulationStack.peek(0);
1683 auto value = simulationStack.peek(1);
1684 auto array = simulationStack.peek(2);
1685 simulationStack.pop();
1686 simulationStack.pop();
1687 simulationStack.pop();
1691 auto rhs = simulationStack.peek(0);
1692 auto lhs = simulationStack.peek(1);
1693 simulationStack.pop();
1694 simulationStack.pop();
1695 simulationStack.push(lhs.type,
1696 lhs.contributedInstructions + rhs.contributedInstructions +
1697 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
1701 auto array = simulationStack.peek(0);
1702 simulationStack.pop();
1703 if (array.type->isArrayType()) {
1705 for (
auto &dim : array.type->dimensions) {
1709 insIndex = reduce(array.contributedInstructions, insIndex);
1712 insIndex = generatePushOp({compilerCtx->getIntObjectType(),
true,
static_cast<int64_t
>(size)}, insIndex);
1714 }
else if (array.type->isDynamicArrayType()) {
1716 simulationStack.push(compilerCtx->getIntObjectType(),
1717 array.contributedInstructions +
1718 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
1723 auto rhs = simulationStack.peek(0);
1724 if (rhs.contributedInstructions.optimizable) {
1725 insIndex = reduce(rhs.contributedInstructions, insIndex);
1728 simulationStack.pop();
1733 ins.operands[1].value.symbolIndex,
1734 ins.operands[2].value.symbolIndex,
1735 ins.operands[3].value.symbolIndex
1738 simulationStack.pop();
1739 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
1743 simulationStack.pop();
1760 std::shared_ptr<IRValueType> baseType;
1761 switch (ins.opcode) {
1763 baseType = compilerCtx->getIntObjectType();
1766 baseType = compilerCtx->getBoolObjectType();
1769 baseType = compilerCtx->getCharObjectType();
1772 baseType = compilerCtx->getDeciObjectType();
1775 baseType = compilerCtx->getShortObjectType();
1778 baseType = compilerCtx->getUnsignedObjectType();
1781 baseType = compilerCtx->getStrObjectType();
1796 simulationStack.pop();
1798 simulationStack.push(
managedPtr(baseType->getDynamicArrayType()), {currentCodeBlockIndex, {insIndex},
false});
1803 auto interfaceType = simulationStack.peek(0).type;
1804 auto objectType = simulationStack.peek(1).type;
1805 simulationStack.pop();
1806 simulationStack.pop();
1807 simulationStack.push(compilerCtx->getBoolObjectType(), {currentCodeBlockIndex, {insIndex},
false});
1811 simulationStack.push(compilerCtx->getIntObjectType(), {currentCodeBlockIndex, {insIndex},
false});
1815 handleInstruction(ins, insIndex, currentCodeBlockIndex);
3484 simulationStack.push(compilerCtx->getDeciObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.decimal);
3488 simulationStack.push(compilerCtx->getShortObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.shortV);
3492 simulationStack.push(compilerCtx->getUnsignedObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.unsignedV);
3496 simulationStack.push(compilerCtx->getStrObjectType(), {currentCodeBlockIndex, {insIndex}});
3500 simulationStack.push(
3501 compilerCtx->getCharObjectType(), {currentCodeBlockIndex, {insIndex}},
static_cast<char>(ins.operands[0].value.character));
3505 auto value = simulationStack.peek(0);
3506 simulationStack.pop();
3508 if (
value.hasPossibleValue) {
3509 switch (
value.type->type) {
3511 value.possibleValue.boolValue =
value.possibleValue.intValue != 0;
3514 value.possibleValue.boolValue =
value.possibleValue.unsignedValue != 0;
3517 value.possibleValue.boolValue =
value.possibleValue.shortValue != 0;
3520 value.possibleValue.boolValue =
value.possibleValue.deciValue != 0.0;
3523 value.possibleValue.boolValue =
value.possibleValue.charValue != 0;
3528 value.type = compilerCtx->getBoolObjectType();
3529 simulationStack.push(value);
3531 simulationStack.push(compilerCtx->getBoolObjectType(),
3532 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3533 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3538 auto value = simulationStack.peek(0);
3539 simulationStack.pop();
3540 if (
value.hasPossibleValue) {
3541 switch (
value.type->type) {
3543 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.deciValue);
3546 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.unsignedValue);
3549 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.shortValue);
3552 value.possibleValue.intValue =
value.possibleValue.boolValue ? 1 : 0;
3555 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.charValue);
3560 value.type = compilerCtx->getIntObjectType();
3561 simulationStack.push(value);
3563 simulationStack.push(compilerCtx->getIntObjectType(),
3564 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3565 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3570 auto value = simulationStack.peek(0);
3571 simulationStack.pop();
3573 if (
value.hasPossibleValue) {
3574 switch (
value.type->type) {
3576 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.intValue);
3579 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.unsignedValue);
3582 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.shortValue);
3585 value.possibleValue.deciValue =
value.possibleValue.boolValue ? 1.0 : 0.0;
3588 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.charValue);
3593 value.type = compilerCtx->getDeciObjectType();
3594 simulationStack.push(value);
3596 simulationStack.push(compilerCtx->getDeciObjectType(),
3597 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3598 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3603 auto value = simulationStack.peek(0);
3604 simulationStack.pop();
3605 if (
value.hasPossibleValue) {
3606 switch (
value.type->type) {
3608 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.intValue);
3611 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.unsignedValue);
3614 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.deciValue);
3617 value.possibleValue.shortValue =
value.possibleValue.boolValue ? 1 : 0;
3620 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.charValue);
3625 value.type = compilerCtx->getShortObjectType();
3626 simulationStack.push(value);
3628 simulationStack.push(compilerCtx->getShortObjectType(),
3629 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3630 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3635 auto value = simulationStack.peek(0);
3636 simulationStack.pop();
3637 if (
value.hasPossibleValue) {
3638 switch (
value.type->type) {
3640 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.intValue);
3643 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.shortValue);
3646 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.deciValue);
3649 value.possibleValue.unsignedValue =
value.possibleValue.boolValue ? 1 : 0;
3652 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.charValue);
3657 value.type = compilerCtx->getUnsignedObjectType();
3658 simulationStack.push(value);
3660 simulationStack.push(compilerCtx->getUnsignedObjectType(),
3661 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3662 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3667 auto value = simulationStack.peek(0);
3668 simulationStack.pop();
3669 if (
value.hasPossibleValue) {
3670 switch (
value.type->type) {
3672 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.deciValue);
3675 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.unsignedValue);
3678 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.shortValue);
3681 value.possibleValue.charValue =
value.possibleValue.boolValue ? 1 : 0;
3684 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.intValue);
3689 value.type = compilerCtx->getCharObjectType();
3690 simulationStack.push(value);
3692 simulationStack.push(compilerCtx->getCharObjectType(),
3693 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3694 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3700 auto array = simulationStack.peek(0);
3701 simulationStack.pop();
3702 for (
auto i = 0; i < ins.operands[0].value.symbolIndex; ++i) {
3703 simulationStack.push(
managedPtr(array.type->getElementType()),
3704 array.contributedInstructions +
3705 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
3711 auto structVal = simulationStack.peek(0);
3712 simulationStack.pop();
3713 auto structDef = compilerCtx->getImportedModule(structVal.type->typeAffiliateModule)->structTable[structVal.type->typeIndex];
3716 yoi::indexT endPos = startPos + ins.operands[0].value.symbolIndex;
3717 for (
auto i = startPos; i < endPos; ++i) {
3718 auto fieldType = structDef->fieldTypes[i];
3719 simulationStack.push(fieldType,
3720 structVal.contributedInstructions +
3721 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
3726 auto right = simulationStack.peek(0);
3727 auto left = simulationStack.peek(1);
3728 simulationStack.pop();
3729 simulationStack.pop();
3731 auto result = add(left, right);
3734 simulationStack.push(result);
3738 auto right = simulationStack.peek(0);
3739 auto left = simulationStack.peek(1);
3740 simulationStack.pop();
3741 simulationStack.pop();
3743 auto result = sub(left, right);
3744 simulationStack.push(result);
3748 auto right = simulationStack.peek(0);
3749 auto left = simulationStack.peek(1);
3750 simulationStack.pop();
3751 simulationStack.pop();
3753 auto result = mul(left, right);
3754 simulationStack.push(result);
3758 auto right = simulationStack.peek(0);
3759 auto left = simulationStack.peek(1);
3760 simulationStack.pop();
3761 simulationStack.pop();
3763 auto result = div(left, right);
3766 simulationStack.push(result);
3770 auto right = simulationStack.peek(0);
3771 auto left = simulationStack.peek(1);
3772 simulationStack.pop();
3773 simulationStack.pop();
3775 auto result = mod(left, right);
3776 simulationStack.push(result);
3780 auto value = simulationStack.peek(0);
3781 simulationStack.pop();
3783 auto result = negate(value);
3784 simulationStack.push(result);
3788 auto right = simulationStack.peek(0);
3789 auto left = simulationStack.peek(1);
3790 simulationStack.pop();
3791 simulationStack.pop();
3793 auto result = bitwiseAnd(left, right);
3794 simulationStack.push(result);
3798 auto right = simulationStack.peek(0);
3799 auto left = simulationStack.peek(1);
3800 simulationStack.pop();
3801 simulationStack.pop();
3803 auto result = bitwiseOr(left, right);
3804 simulationStack.push(result);
3808 auto right = simulationStack.peek(0);
3809 auto left = simulationStack.peek(1);
3810 simulationStack.pop();
3811 simulationStack.pop();
3813 auto result = bitwiseXor(left, right);
3814 simulationStack.push(result);
3818 auto value = simulationStack.peek(0);
3819 simulationStack.pop();
3821 auto result = bitwiseNot(value);
3823 simulationStack.push(result.type,
value.contributedInstructions);
3827 auto shift = simulationStack.peek(0);
3828 auto value = simulationStack.peek(1);
3829 simulationStack.pop();
3830 simulationStack.pop();
3832 auto result = bitwiseShiftLeft(value, shift);
3833 simulationStack.push(result);
3837 auto shift = simulationStack.peek(0);
3838 auto value = simulationStack.peek(1);
3839 simulationStack.pop();
3840 simulationStack.pop();
3842 auto result = bitwiseShiftRight(value, shift);
3843 simulationStack.push(result);
3847 auto right = simulationStack.peek(0);
3848 auto left = simulationStack.peek(1);
3849 simulationStack.pop();
3850 simulationStack.pop();
3852 auto result = lessThan(left, right);
3853 simulationStack.push(result);
3857 auto right = simulationStack.peek(0);
3858 auto left = simulationStack.peek(1);
3859 simulationStack.pop();
3860 simulationStack.pop();
3862 auto result = greaterThan(left, right);
3863 simulationStack.push(result);
3867 auto right = simulationStack.peek(0);
3868 auto left = simulationStack.peek(1);
3869 simulationStack.pop();
3870 simulationStack.pop();
3872 auto result = greaterThanOrEqual(left, right);
3873 simulationStack.push(result);
3877 auto right = simulationStack.peek(0);
3878 auto left = simulationStack.peek(1);
3879 simulationStack.pop();
3880 simulationStack.pop();
3882 auto result = greaterThanOrEqual(left, right);
3883 simulationStack.push(result);
3887 auto right = simulationStack.peek(0);
3888 auto left = simulationStack.peek(1);
3889 simulationStack.pop();
3890 simulationStack.pop();
3892 auto result = equal(left, right);
3893 simulationStack.push(result);
3897 auto right = simulationStack.peek(0);
3898 auto left = simulationStack.peek(1);
3899 simulationStack.pop();
3900 simulationStack.pop();
3902 auto result = notEqual(left, right);
3903 simulationStack.push(result);
3907 auto varIndex = ins.operands[0].value.symbolIndex;
3908 auto varType = targetFunction->getVariableTable().get(varIndex);
3910 if (
auto it = variablesExtraInfo.find(varIndex); it != variablesExtraInfo.end() && it->second.hasPossibleValue) {
3911 simulationStack.push(it->second.possibleValue);
3913 simulationStack.push(varType, {currentCodeBlockIndex, {insIndex}});
3916 if (
auto it = variablesExtraInfo.find(varIndex); it != variablesExtraInfo.end()) {
3917 it->second.isReadAfterStore =
true;
3919 variablesExtraInfo[varIndex] = {
false,
true, {}};
3924 auto varIndex = ins.operands[0].value.symbolIndex;
3925 auto value = simulationStack.peek(0);
3926 simulationStack.pop();
3928 variablesExtraInfo[varIndex] = {
value.hasPossibleValue,
false,
value};
3933 auto moduleIndex = ins.operands[0].value.symbolIndex;
3934 auto type = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
3935 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
3940 auto moduleIndex = ins.operands[0].value.symbolIndex;
3941 auto definitionType = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
3942 auto value = simulationStack.peek(0);
3944 if (
value.type->isForeignBasicType()) {
3945 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
3951 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::analyzeBlock(): store_global: type mismatch");
3954 simulationStack.pop();
3959 auto value = simulationStack.peek(0);
3960 auto type =
value.type->typeIndex;
3961 auto targetModule = compilerCtx->getImportedModule(
value.type->typeAffiliateModule);
3962 auto structDef = targetModule->structTable[type];
3963 auto memberIndex = ins.operands[0].value.symbolIndex;
3964 auto memberDef =
managedPtr(*structDef->fieldTypes[memberIndex]);
3965 if (memberDef->metadata.hasMetadata(L
"STRUCT_DATAFIELD")) {
3968 simulationStack.pop();
3969 simulationStack.push(
3970 memberDef,
value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
3975 auto value = simulationStack.peek(1);
3976 auto type = simulationStack.peek(0).type->typeIndex;
3977 auto structDef = compilerCtx->getImportedModule(simulationStack.peek(0).type->typeAffiliateModule)->structTable[type];
3978 auto memberIndex = ins.operands[0].value.symbolIndex;
3979 auto memberDef = structDef->fieldTypes[memberIndex];
3981 if (
value.type->isForeignBasicType()) {
3982 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
3988 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::analyzeBlock(): store_member: type mismatch");
3991 simulationStack.pop();
3992 simulationStack.pop();
3999 auto moduleIndex = ins.operands[0].value.symbolIndex;
4000 auto function = compilerCtx->getImportedModule(moduleIndex)->functionTable[ins.operands[1].value.symbolIndex];
4001 auto returnType = function->returnType;
4002 auto argTypes = function->argumentTypes;
4003 auto argCount = function->argumentTypes.size();
4004 SimulationStack::Item::ContributedInstructionSet contributedInstructions = {currentCodeBlockIndex, {insIndex},
false};
4005 for (
int i = 0; i < argCount; i++) {
4006 contributedInstructions = contributedInstructions + simulationStack.peek(0).contributedInstructions;
4007 simulationStack.pop();
4009 simulationStack.push(returnType, contributedInstructions);
4013 auto function = compilerCtx->getIRFFITable()
4014 ->importedLibraries[ins.operands[0].value.symbolIndex]
4015 .importedFunctionTable[ins.operands[1].value.symbolIndex];
4016 auto returnType = function->returnType;
4017 auto argTypes = function->argumentTypes;
4018 auto argCount = function->argumentTypes.size();
4019 for (
int i = 0; i < argCount; i++) {
4020 simulationStack.pop();
4022 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
4026 auto argCount = ins.operands[3].value.symbolIndex;
4027 for (
int i = 0; i < argCount - 1; i++) {
4028 simulationStack.pop();
4030 auto returnType = compilerCtx->getImportedModule(ins.operands[0].value.symbolIndex)
4031 ->interfaceTable[ins.operands[1].value.symbolIndex]
4032 ->methodMap[ins.operands[2].value.symbolIndex]
4034 simulationStack.pop();
4035 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
4039 auto moduleIndex = ins.operands[0].value.symbolIndex;
4040 auto structDef = compilerCtx->getImportedModule(moduleIndex)->structTable[ins.operands[1].value.symbolIndex];
4042 {currentCodeBlockIndex, {insIndex},
false});
4046 auto moduleIndex = ins.operands[0].value.symbolIndex;
4047 auto interfaceImplDef = compilerCtx->getImportedModule(moduleIndex)->interfaceImplementationTable[ins.operands[1].value.symbolIndex];
4049 interfaceImplDef->implInterfaceIndex.first,
4050 interfaceImplDef->implInterfaceIndex.second});
4051 simulationStack.pop();
4052 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
4058 simulationStack.pop();
4070 std::shared_ptr<IRValueType> baseType;
4071 switch (ins.opcode) {
4073 baseType = compilerCtx->getIntObjectType();
4076 baseType = compilerCtx->getBoolObjectType();
4079 baseType = compilerCtx->getCharObjectType();
4082 baseType = compilerCtx->getDeciObjectType();
4085 baseType = compilerCtx->getStrObjectType();
4088 baseType = compilerCtx->getShortObjectType();
4091 baseType = compilerCtx->getUnsignedObjectType();
4099 for (
auto i = 1; i < ins.operands.size(); i++) {
4100 size *= ins.operands[i].value.symbolIndex;
4101 dims.push_back(ins.operands[i].value.symbolIndex);
4103 for (
yoi::indexT i = 0; i < ins.operands[0].value.symbolIndex; i++) {
4104 simulationStack.pop();
4106 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
4111 auto moduleIndex = ins.operands[0].value.symbolIndex;
4112 auto typeIndex = ins.operands[1].value.symbolIndex;
4121 for (
yoi::indexT i = 3; i < ins.operands.size(); i++) {
4122 size *= ins.operands[i].value.symbolIndex;
4123 dims.push_back(ins.operands[i].value.symbolIndex);
4125 for (
yoi::indexT i = 0; i < ins.operands[2].value.symbolIndex; i++) {
4126 simulationStack.pop();
4128 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
4140 std::shared_ptr<IRValueType> baseType;
4141 switch (ins.opcode) {
4143 baseType = compilerCtx->getIntObjectType();
4146 baseType = compilerCtx->getBoolObjectType();
4149 baseType = compilerCtx->getCharObjectType();
4152 baseType = compilerCtx->getDeciObjectType();
4155 baseType = compilerCtx->getShortObjectType();
4158 baseType = compilerCtx->getUnsignedObjectType();
4161 baseType = compilerCtx->getStrObjectType();
4176 simulationStack.pop();
4178 simulationStack.pop();
4179 simulationStack.push(
managedPtr(baseType->getDynamicArrayType()), {currentCodeBlockIndex, {insIndex},
false});
4184 auto index = simulationStack.peek(0);
4185 auto array = simulationStack.peek(1);
4186 simulationStack.pop();
4187 simulationStack.pop();
4188 simulationStack.push(
managedPtr(array.type->getElementType()),
4189 array.contributedInstructions + index.contributedInstructions +
4190 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
4195 auto index = simulationStack.peek(0);
4196 auto value = simulationStack.peek(1);
4197 auto array = simulationStack.peek(2);
4198 simulationStack.pop();
4199 simulationStack.pop();
4200 simulationStack.pop();
4204 simulationStack.pop();
4208 auto rhs = simulationStack.peek(0);
4209 auto lhs = simulationStack.peek(1);
4211 if (rhs.type->isForeignBasicType()) {
4212 *rhs.type = rhs.type->getNormalizedForeignBasicType();
4214 yoi_assert(*lhs.type == *rhs.type, 0, 0,
"IROptimizer::analyzeBlock(): direct_assign: type mismatch");
4215 simulationStack.pop();
4216 simulationStack.pop();
4217 simulationStack.push(lhs.type,
4218 lhs.contributedInstructions + rhs.contributedInstructions +
4219 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
4224 ins.operands[1].value.symbolIndex,
4225 ins.operands[2].value.symbolIndex,
4226 ins.operands[3].value.symbolIndex
4230 simulationStack.pop();
4231 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
4235 simulationStack.pop();
4244 auto array = simulationStack.peek(0);
4245 simulationStack.pop();
4246 if (array.type->isArrayType()) {
4248 for (
auto dim : array.type->dimensions) {
4251 simulationStack.push(compilerCtx->getIntObjectType(),
4252 array.contributedInstructions +
4253 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}},
4254 static_cast<int64_t
>(size));
4255 }
else if (array.type->isDynamicArrayType()) {
4256 simulationStack.push(compilerCtx->getIntObjectType(),
4257 array.contributedInstructions +
4258 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
4264 auto interfaceType = simulationStack.peek(0).type;
4265 auto objectType = simulationStack.peek(1).type;
4266 simulationStack.pop();
4267 simulationStack.pop();
4268 simulationStack.push(compilerCtx->getBoolObjectType(), {currentCodeBlockIndex, {insIndex},
false});
4272 simulationStack.push(compilerCtx->getIntObjectType(), {currentCodeBlockIndex, {insIndex},
false});
4276 auto typeMod = ins.operands[0].value.symbolIndex;
4277 auto typeIndex = ins.operands[1].value.symbolIndex;
4279 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
4283 for (
yoi::indexT i = 0; i < ins.operands[0].value.symbolIndex; i++) {
4284 simulationStack.pop();
4289 simulationStack.pop();
4290 simulationStack.pop();
4294 auto type = simulationStack.peek(0).type;
4295 simulationStack.pop();
4296 for (
auto &operand : ins.operands) {
4297 auto def = compilerCtx->getImportedModule(type->typeAffiliateModule)->dataStructTable[type->typeIndex];
4298 type = def->fieldTypes[operand.value.symbolIndex];
4300 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
4304 simulationStack.pop();
4305 simulationStack.pop();
4309 simulationStack.pop();
4313 simulationStack.pop();