Skip to content

Commit

Permalink
fix bug and restore some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tlively committed Oct 21, 2023
1 parent 024ef4f commit dd4546f
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/analysis/monotone-analyzer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ inline void MonotoneCFGAnalyzer<L, TxFn>::evaluate() {
for (auto& dep : txfn.getDependents(cfg[i])) {
// If the input state for the dependent block changes, we need to
// re-analyze it.
if (states[i].makeLeastUpperBound(state)) {
if (states[dep.getIndex()].makeLeastUpperBound(state)) {
worklist.push(dep.getIndex());
}
}
Expand Down
138 changes: 137 additions & 1 deletion test/gtest/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ TEST_F(CFGTest, CallBlock) {
EXPECT_EQ(ss.str(), cfgText);
}


TEST_F(CFGTest, FinitePowersetLatticeFunctioning) {

std::vector<std::string> initialSet = {"a", "b", "c", "d", "e", "f"};
Expand Down Expand Up @@ -275,6 +274,143 @@ TEST_F(CFGTest, LinearReachingDefinitions) {
EXPECT_EQ(expectedResult, getSetses);
}

TEST_F(CFGTest, ReachingDefinitionsIf) {
auto moduleText = R"wasm(
(module
(func $bar
(local $a (i32))
(local $b (i32))
(local.set $a
(i32.const 1)
)
(if
(i32.eq
(local.get $a)
(i32.const 2)
)
(local.set $b
(i32.const 3)
)
(local.set $a
(i32.const 4)
)
)
(drop
(local.get $b)
)
(drop
(local.get $a)
)
)
)
)wasm";

Module wasm;
parseWast(wasm, moduleText);

Function* func = wasm.getFunction("bar");
CFG cfg = CFG::fromFunction(func);

LocalGraph::GetSetses getSetses;
LocalGraph::Locations locations;
ReachingDefinitionsTransferFunction transferFunction(
func, getSetses, locations);

MonotoneCFGAnalyzer<FinitePowersetLattice<LocalSet*>,
ReachingDefinitionsTransferFunction>
analyzer(transferFunction.lattice, transferFunction, cfg);
analyzer.evaluateFunctionEntry(func);
analyzer.evaluateAndCollectResults();

FindAll<LocalSet> foundSets(func->body);
FindAll<LocalGet> foundGets(func->body);

LocalGet* getA1 = foundGets.list[0];
LocalGet* getB = foundGets.list[1];
LocalGet* getA2 = foundGets.list[2];
LocalSet* setA1 = foundSets.list[0];
LocalSet* setB = foundSets.list[1];
LocalSet* setA2 = foundSets.list[2];

LocalGraph::GetSetses expectedResult;
expectedResult[getA1].insert(setA1);
expectedResult[getB].insert(nullptr);
expectedResult[getB].insert(setB);
expectedResult[getA2].insert(setA1);
expectedResult[getA2].insert(setA2);

EXPECT_EQ(expectedResult, getSetses);
}

TEST_F(CFGTest, ReachingDefinitionsLoop) {
auto moduleText = R"wasm(
(module
(func $bar (param $a (i32)) (param $b (i32))
(loop $loop
(drop
(local.get $a)
)
(local.set $a
(i32.add
(i32.const 1)
(local.get $a)
)
)
(br_if $loop
(i32.le_u
(local.get $a)
(i32.const 7)
)
)
)
(local.set $b
(i32.sub
(local.get $b)
(local.get $a)
)
)
)
)
)wasm";

Module wasm;
parseWast(wasm, moduleText);

Function* func = wasm.getFunction("bar");
CFG cfg = CFG::fromFunction(func);

LocalGraph::GetSetses getSetses;
LocalGraph::Locations locations;
ReachingDefinitionsTransferFunction transferFunction(
func, getSetses, locations);

MonotoneCFGAnalyzer<FinitePowersetLattice<LocalSet*>,
ReachingDefinitionsTransferFunction>
analyzer(transferFunction.lattice, transferFunction, cfg);
analyzer.evaluateFunctionEntry(func);
analyzer.evaluateAndCollectResults();

FindAll<LocalSet> foundSets(func->body);
FindAll<LocalGet> foundGets(func->body);

LocalGet* getA1 = foundGets.list[0];
LocalGet* getA2 = foundGets.list[1];
LocalGet* getA3 = foundGets.list[2];
LocalGet* getB = foundGets.list[3];
LocalGet* getA4 = foundGets.list[4];
LocalSet* setA = foundSets.list[0];

LocalGraph::GetSetses expectedResult;
expectedResult[getA1].insert(nullptr);
expectedResult[getA1].insert(setA);
expectedResult[getA2].insert(nullptr);
expectedResult[getA2].insert(setA);
expectedResult[getA3].insert(setA);
expectedResult[getB].insert(nullptr);
expectedResult[getA4].insert(setA);

EXPECT_EQ(expectedResult, getSetses);
}

TEST_F(CFGTest, StackLatticeFunctioning) {
FiniteIntPowersetLattice contentLattice(4);
Expand Down

0 comments on commit dd4546f

Please sign in to comment.