summaryrefslogtreecommitdiff
path: root/src/passes/Asyncify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/Asyncify.cpp')
-rw-r--r--src/passes/Asyncify.cpp88
1 files changed, 45 insertions, 43 deletions
diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp
index 8f929d9fe..b7e8c90e0 100644
--- a/src/passes/Asyncify.cpp
+++ b/src/passes/Asyncify.cpp
@@ -298,10 +298,10 @@ class GlobalHelper {
public:
GlobalHelper(Module& module) : module(module) {
- map[i32] = "asyncify_fake_call_global_i32";
- map[i64] = "asyncify_fake_call_global_i64";
- map[f32] = "asyncify_fake_call_global_f32";
- map[f64] = "asyncify_fake_call_global_f64";
+ map[Type::i32] = "asyncify_fake_call_global_i32";
+ map[Type::i64] = "asyncify_fake_call_global_i64";
+ map[Type::f32] = "asyncify_fake_call_global_f32";
+ map[Type::f64] = "asyncify_fake_call_global_f64";
Builder builder(module);
for (auto& pair : map) {
auto type = pair.first;
@@ -326,7 +326,7 @@ public:
if (iter != rev.end()) {
return iter->second;
}
- return none;
+ return Type::none;
}
private:
@@ -647,8 +647,8 @@ public:
false,
int32_t(DataOffset::BStackPos),
4,
- makeGlobalGet(ASYNCIFY_DATA, i32),
- i32);
+ makeGlobalGet(ASYNCIFY_DATA, Type::i32),
+ Type::i32);
}
Expression* makeIncStackPos(int32_t by) {
@@ -659,14 +659,14 @@ public:
4,
int32_t(DataOffset::BStackPos),
4,
- makeGlobalGet(ASYNCIFY_DATA, i32),
+ makeGlobalGet(ASYNCIFY_DATA, Type::i32),
makeBinary(AddInt32, makeGetStackPos(), makeConst(Literal(by))),
- i32);
+ Type::i32);
}
Expression* makeStateCheck(State value) {
return makeBinary(EqInt32,
- makeGlobalGet(ASYNCIFY_STATE, i32),
+ makeGlobalGet(ASYNCIFY_STATE, Type::i32),
makeConst(Literal(int32_t(value))));
}
@@ -810,11 +810,11 @@ private:
iff->finalize();
return iff;
}
- auto conditionTemp = builder->addVar(func, i32);
+ auto conditionTemp = builder->addVar(func, Type::i32);
// TODO: can avoid pre if the condition is a get or a const
auto* pre =
makeMaybeSkip(builder->makeLocalSet(conditionTemp, iff->condition));
- iff->condition = builder->makeLocalGet(conditionTemp, i32);
+ iff->condition = builder->makeLocalGet(conditionTemp, Type::i32);
iff->condition = builder->makeBinary(
OrInt32, iff->condition, builder->makeStateCheck(State::Rewinding));
iff->ifTrue = process(iff->ifTrue);
@@ -826,7 +826,7 @@ private:
builder->makeBinary(
OrInt32,
builder->makeUnary(EqZInt32,
- builder->makeLocalGet(conditionTemp, i32)),
+ builder->makeLocalGet(conditionTemp, Type::i32)),
builder->makeStateCheck(State::Rewinding)),
process(otherArm));
otherIf->finalize();
@@ -853,7 +853,7 @@ private:
// TODO: stop doing this after code can no longer reach a call that may
// change the state
assert(doesCall(curr));
- assert(curr->type == none);
+ assert(curr->type == Type::none);
// The case of a set is tricky: we must *not* execute the set when
// unwinding, since at that point we have a fake value for the return,
// and if we applied it to the local, it would end up saved and then
@@ -893,8 +893,9 @@ private:
// it when we add its contents, later.)
return builder->makeIf(
builder->makeStateCheck(State::Unwinding),
- builder->makeCall(
- ASYNCIFY_UNWIND, {builder->makeConst(Literal(int32_t(index)))}, none),
+ builder->makeCall(ASYNCIFY_UNWIND,
+ {builder->makeConst(Literal(int32_t(index)))},
+ Type::none),
ifNotUnwinding);
}
@@ -903,13 +904,13 @@ private:
// don't want it to be seen by asyncify itself.
return builder->makeCall(ASYNCIFY_CHECK_CALL_INDEX,
{builder->makeConst(Literal(int32_t(index)))},
- i32);
+ Type::i32);
}
Expression* makeCallIndexPop() {
// Emit an intrinsic for this, as we store the index into a local, and
// don't want it to be seen by asyncify itself.
- return builder->makeCall(ASYNCIFY_GET_CALL_INDEX, {}, none);
+ return builder->makeCall(ASYNCIFY_GET_CALL_INDEX, {}, Type::none);
}
// Given a function that is not instrumented - because we proved it doesn't
@@ -921,11 +922,11 @@ private:
// That is, if in an uninstrumented function, a sleep should not begin
// from any call.
void addAssertsInNonInstrumented(Function* func) {
- auto oldState = builder->addVar(func, i32);
+ auto oldState = builder->addVar(func, Type::i32);
// Add a check at the function entry.
func->body = builder->makeSequence(
builder->makeLocalSet(oldState,
- builder->makeGlobalGet(ASYNCIFY_STATE, i32)),
+ builder->makeGlobalGet(ASYNCIFY_STATE, Type::i32)),
func->body);
// Add a check around every call.
struct Walker : PostWalker<Walker> {
@@ -944,8 +945,8 @@ private:
void handleCall(Expression* call) {
auto* check = builder->makeIf(
builder->makeBinary(NeInt32,
- builder->makeGlobalGet(ASYNCIFY_STATE, i32),
- builder->makeLocalGet(oldState, i32)),
+ builder->makeGlobalGet(ASYNCIFY_STATE, Type::i32),
+ builder->makeLocalGet(oldState, Type::i32)),
builder->makeUnreachable());
Expression* rep;
if (call->type.isConcrete()) {
@@ -991,11 +992,12 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
builder->makeIncStackPos(-4),
builder->makeLocalSet(
rewindIndex,
- builder->makeLoad(4, false, 0, 4, builder->makeGetStackPos(), i32))));
+ builder->makeLoad(
+ 4, false, 0, 4, builder->makeGetStackPos(), Type::i32))));
} else if (curr->target == ASYNCIFY_CHECK_CALL_INDEX) {
replaceCurrent(builder->makeBinary(
EqInt32,
- builder->makeLocalGet(rewindIndex, i32),
+ builder->makeLocalGet(rewindIndex, Type::i32),
builder->makeConst(
Literal(int32_t(curr->operands[0]->cast<Const>()->value.geti32())))));
}
@@ -1003,7 +1005,7 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
void visitGlobalSet(GlobalSet* curr) {
auto type = analyzer->globals.getTypeOrNone(curr->name);
- if (type != none) {
+ if (type != Type::none) {
replaceCurrent(
builder->makeLocalSet(getFakeCallLocal(type), curr->value));
}
@@ -1011,7 +1013,7 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
void visitGlobalGet(GlobalGet* curr) {
auto type = analyzer->globals.getTypeOrNone(curr->name);
- if (type != none) {
+ if (type != Type::none) {
replaceCurrent(builder->makeLocalGet(getFakeCallLocal(type), type));
}
}
@@ -1038,8 +1040,8 @@ struct AsyncifyLocals : public WalkerPass<PostWalker<AsyncifyLocals>> {
// well as saving the locals.
// An index is needed for getting the unwinding and rewinding call indexes
// around TODO: can this be the same index?
- auto unwindIndex = builder->addVar(func, i32);
- rewindIndex = builder->addVar(func, i32);
+ auto unwindIndex = builder->addVar(func, Type::i32);
+ rewindIndex = builder->addVar(func, Type::i32);
// Rewrite the function body.
builder = make_unique<AsyncifyBuilder>(*getModule());
walk(func->body);
@@ -1095,7 +1097,7 @@ private:
}
auto* block = builder->makeBlock();
block->list.push_back(builder->makeIncStackPos(-total));
- auto tempIndex = builder->addVar(func, i32);
+ auto tempIndex = builder->addVar(func, Type::i32);
block->list.push_back(
builder->makeLocalSet(tempIndex, builder->makeGetStackPos()));
Index offset = 0;
@@ -1110,7 +1112,7 @@ private:
true,
offset,
STACK_ALIGN,
- builder->makeLocalGet(tempIndex, i32),
+ builder->makeLocalGet(tempIndex, Type::i32),
type)));
offset += size;
}
@@ -1124,7 +1126,7 @@ private:
}
auto* func = getFunction();
auto* block = builder->makeBlock();
- auto tempIndex = builder->addVar(func, i32);
+ auto tempIndex = builder->addVar(func, Type::i32);
block->list.push_back(
builder->makeLocalSet(tempIndex, builder->makeGetStackPos()));
Index offset = 0;
@@ -1137,7 +1139,7 @@ private:
builder->makeStore(size,
offset,
STACK_ALIGN,
- builder->makeLocalGet(tempIndex, i32),
+ builder->makeLocalGet(tempIndex, Type::i32),
builder->makeLocalGet(i, type),
type));
offset += size;
@@ -1154,8 +1156,8 @@ private:
0,
4,
builder->makeGetStackPos(),
- builder->makeLocalGet(tempIndex, i32),
- i32),
+ builder->makeLocalGet(tempIndex, Type::i32),
+ Type::i32),
builder->makeIncStackPos(4));
}
};
@@ -1281,11 +1283,11 @@ private:
void addGlobals(Module* module) {
Builder builder(*module);
module->addGlobal(builder.makeGlobal(ASYNCIFY_STATE,
- i32,
+ Type::i32,
builder.makeConst(Literal(int32_t(0))),
Builder::Mutable));
module->addGlobal(builder.makeGlobal(ASYNCIFY_DATA,
- i32,
+ Type::i32,
builder.makeConst(Literal(int32_t(0))),
Builder::Mutable));
}
@@ -1295,14 +1297,14 @@ private:
auto makeFunction = [&](Name name, bool setData, State state) {
std::vector<Type> params;
if (setData) {
- params.push_back(i32);
+ params.push_back(Type::i32);
}
auto* body = builder.makeBlock();
body->list.push_back(builder.makeGlobalSet(
ASYNCIFY_STATE, builder.makeConst(Literal(int32_t(state)))));
if (setData) {
- body->list.push_back(
- builder.makeGlobalSet(ASYNCIFY_DATA, builder.makeLocalGet(0, i32)));
+ body->list.push_back(builder.makeGlobalSet(
+ ASYNCIFY_DATA, builder.makeLocalGet(0, Type::i32)));
}
// Verify the data is valid.
auto* stackPos =
@@ -1310,15 +1312,15 @@ private:
false,
int32_t(DataOffset::BStackPos),
4,
- builder.makeGlobalGet(ASYNCIFY_DATA, i32),
- i32);
+ builder.makeGlobalGet(ASYNCIFY_DATA, Type::i32),
+ Type::i32);
auto* stackEnd =
builder.makeLoad(4,
false,
int32_t(DataOffset::BStackEnd),
4,
- builder.makeGlobalGet(ASYNCIFY_DATA, i32),
- i32);
+ builder.makeGlobalGet(ASYNCIFY_DATA, Type::i32),
+ Type::i32);
body->list.push_back(
builder.makeIf(builder.makeBinary(GtUInt32, stackPos, stackEnd),
builder.makeUnreachable()));