Skip to content

Commit 006181b

Browse files
authored
[validator] Remove indexType helper function (#6576)
It seems like that each of the callsites already has looked up the `Memory` object so this helper is not doing anything useful.
1 parent a816627 commit 006181b

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/wasm/wasm-validator.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,6 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
593593
void validateCallParamsAndResult(T* curr, HeapType sigType) {
594594
validateCallParamsAndResult(curr, sigType, curr);
595595
}
596-
597-
Type indexType(Name memoryName) {
598-
auto memory = getModule()->getMemory(memoryName);
599-
return memory->indexType;
600-
}
601596
};
602597

603598
void FunctionValidator::noteLabelName(Name name) {
@@ -1056,7 +1051,7 @@ void FunctionValidator::visitLoad(Load* curr) {
10561051
validateAlignment(curr->align, curr->type, curr->bytes, curr->isAtomic, curr);
10571052
shouldBeEqualOrFirstIsUnreachable(
10581053
curr->ptr->type,
1059-
indexType(curr->memory),
1054+
memory->indexType,
10601055
curr,
10611056
"load pointer type must match memory index type");
10621057
if (curr->isAtomic) {
@@ -1088,7 +1083,7 @@ void FunctionValidator::visitStore(Store* curr) {
10881083
curr->align, curr->valueType, curr->bytes, curr->isAtomic, curr);
10891084
shouldBeEqualOrFirstIsUnreachable(
10901085
curr->ptr->type,
1091-
indexType(curr->memory),
1086+
memory->indexType,
10921087
curr,
10931088
"store pointer must match memory index type");
10941089
shouldBeUnequal(curr->value->type,
@@ -1112,7 +1107,7 @@ void FunctionValidator::visitAtomicRMW(AtomicRMW* curr) {
11121107
validateMemBytes(curr->bytes, curr->type, curr);
11131108
shouldBeEqualOrFirstIsUnreachable(
11141109
curr->ptr->type,
1115-
indexType(curr->memory),
1110+
memory->indexType,
11161111
curr,
11171112
"AtomicRMW pointer type must match memory index type");
11181113
shouldBeEqualOrFirstIsUnreachable(curr->type,
@@ -1132,7 +1127,7 @@ void FunctionValidator::visitAtomicCmpxchg(AtomicCmpxchg* curr) {
11321127
validateMemBytes(curr->bytes, curr->type, curr);
11331128
shouldBeEqualOrFirstIsUnreachable(
11341129
curr->ptr->type,
1135-
indexType(curr->memory),
1130+
memory->indexType,
11361131
curr,
11371132
"cmpxchg pointer must match memory index type");
11381133
if (curr->expected->type != Type::unreachable &&
@@ -1166,7 +1161,7 @@ void FunctionValidator::visitAtomicWait(AtomicWait* curr) {
11661161
curr->type, Type(Type::i32), curr, "AtomicWait must have type i32");
11671162
shouldBeEqualOrFirstIsUnreachable(
11681163
curr->ptr->type,
1169-
indexType(curr->memory),
1164+
memory->indexType,
11701165
curr,
11711166
"AtomicWait pointer must match memory index type");
11721167
shouldBeIntOrUnreachable(
@@ -1192,7 +1187,7 @@ void FunctionValidator::visitAtomicNotify(AtomicNotify* curr) {
11921187
curr->type, Type(Type::i32), curr, "AtomicNotify must have type i32");
11931188
shouldBeEqualOrFirstIsUnreachable(
11941189
curr->ptr->type,
1195-
indexType(curr->memory),
1190+
memory->indexType,
11961191
curr,
11971192
"AtomicNotify pointer must match memory index type");
11981193
shouldBeEqualOrFirstIsUnreachable(
@@ -1354,7 +1349,7 @@ void FunctionValidator::visitSIMDLoad(SIMDLoad* curr) {
13541349
curr->type, Type(Type::v128), curr, "load_splat must have type v128");
13551350
shouldBeEqualOrFirstIsUnreachable(
13561351
curr->ptr->type,
1357-
indexType(curr->memory),
1352+
memory->indexType,
13581353
curr,
13591354
"load_splat address must match memory index type");
13601355
Type memAlignType = Type::none;
@@ -1395,7 +1390,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
13951390
}
13961391
shouldBeEqualOrFirstIsUnreachable(
13971392
curr->ptr->type,
1398-
indexType(curr->memory),
1393+
memory->indexType,
13991394
curr,
14001395
"loadX_lane or storeX_lane address must match memory index type");
14011396
shouldBeEqualOrFirstIsUnreachable(
@@ -1435,6 +1430,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
14351430
}
14361431

14371432
void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
1433+
auto* memory = getModule()->getMemoryOrNull(curr->memory);
14381434
shouldBeTrue(
14391435
getModule()->features.hasBulkMemory(),
14401436
curr,
@@ -1443,7 +1439,7 @@ void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
14431439
curr->type, Type(Type::none), curr, "memory.init must have type none");
14441440
shouldBeEqualOrFirstIsUnreachable(
14451441
curr->dest->type,
1446-
indexType(curr->memory),
1442+
memory->indexType,
14471443
curr,
14481444
"memory.init dest must match memory index type");
14491445
shouldBeEqualOrFirstIsUnreachable(curr->offset->type,
@@ -1452,7 +1448,6 @@ void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
14521448
"memory.init offset must be an i32");
14531449
shouldBeEqualOrFirstIsUnreachable(
14541450
curr->size->type, Type(Type::i32), curr, "memory.init size must be an i32");
1455-
auto* memory = getModule()->getMemoryOrNull(curr->memory);
14561451
if (!shouldBeTrue(!!memory, curr, "memory.init memory must exist")) {
14571452
return;
14581453
}
@@ -1486,27 +1481,28 @@ void FunctionValidator::visitMemoryCopy(MemoryCopy* curr) {
14861481
shouldBeTrue(!!sourceMemory, curr, "memory.copy sourceMemory must exist");
14871482
shouldBeEqualOrFirstIsUnreachable(
14881483
curr->dest->type,
1489-
indexType(curr->destMemory),
1484+
destMemory->indexType,
14901485
curr,
14911486
"memory.copy dest must match destMemory index type");
14921487
shouldBeEqualOrFirstIsUnreachable(
14931488
curr->source->type,
1494-
indexType(curr->sourceMemory),
1489+
sourceMemory->indexType,
14951490
curr,
14961491
"memory.copy source must match sourceMemory index type");
14971492
shouldBeEqualOrFirstIsUnreachable(
14981493
curr->size->type,
1499-
indexType(curr->destMemory),
1494+
destMemory->indexType,
15001495
curr,
15011496
"memory.copy size must match destMemory index type");
15021497
shouldBeEqualOrFirstIsUnreachable(
15031498
curr->size->type,
1504-
indexType(curr->sourceMemory),
1499+
sourceMemory->indexType,
15051500
curr,
15061501
"memory.copy size must match destMemory index type");
15071502
}
15081503

15091504
void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
1505+
auto* memory = getModule()->getMemoryOrNull(curr->memory);
15101506
shouldBeTrue(
15111507
getModule()->features.hasBulkMemory(),
15121508
curr,
@@ -1515,7 +1511,7 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
15151511
curr->type, Type(Type::none), curr, "memory.fill must have type none");
15161512
shouldBeEqualOrFirstIsUnreachable(
15171513
curr->dest->type,
1518-
indexType(curr->memory),
1514+
memory->indexType,
15191515
curr,
15201516
"memory.fill dest must match memory index type");
15211517
shouldBeEqualOrFirstIsUnreachable(curr->value->type,
@@ -1524,10 +1520,9 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
15241520
"memory.fill value must be an i32");
15251521
shouldBeEqualOrFirstIsUnreachable(
15261522
curr->size->type,
1527-
indexType(curr->memory),
1523+
memory->indexType,
15281524
curr,
15291525
"memory.fill size must match memory index type");
1530-
auto* memory = getModule()->getMemoryOrNull(curr->memory);
15311526
shouldBeTrue(!!memory, curr, "memory.fill memory must exist");
15321527
}
15331528

@@ -2162,7 +2157,7 @@ void FunctionValidator::visitMemoryGrow(MemoryGrow* curr) {
21622157
auto* memory = getModule()->getMemoryOrNull(curr->memory);
21632158
shouldBeTrue(!!memory, curr, "memory.grow memory must exist");
21642159
shouldBeEqualOrFirstIsUnreachable(curr->delta->type,
2165-
indexType(curr->memory),
2160+
memory->indexType,
21662161
curr,
21672162
"memory.grow must match memory index type");
21682163
}

0 commit comments

Comments
 (0)