diff options
Diffstat (limited to 'src/passes')
-rw-r--r-- | src/passes/AlignmentLowering.cpp | 20 | ||||
-rw-r--r-- | src/passes/Asyncify.cpp | 19 | ||||
-rw-r--r-- | src/passes/DeNaN.cpp | 4 | ||||
-rw-r--r-- | src/passes/I64ToI32Lowering.cpp | 94 | ||||
-rw-r--r-- | src/passes/InstrumentLocals.cpp | 22 | ||||
-rw-r--r-- | src/passes/InstrumentMemory.cpp | 34 | ||||
-rw-r--r-- | src/passes/LogExecution.cpp | 3 | ||||
-rw-r--r-- | src/passes/MemoryPacking.cpp | 20 | ||||
-rw-r--r-- | src/passes/PostEmscripten.cpp | 5 | ||||
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 33 |
10 files changed, 117 insertions, 137 deletions
diff --git a/src/passes/AlignmentLowering.cpp b/src/passes/AlignmentLowering.cpp index 18fe46398..818189056 100644 --- a/src/passes/AlignmentLowering.cpp +++ b/src/passes/AlignmentLowering.cpp @@ -56,7 +56,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { 1, builder.makeLocalGet(temp, Type::i32), Type::i32), - builder.makeConst(Literal(int32_t(8))))); + builder.makeConst(int32_t(8)))); if (curr->signed_) { ret = Bits::makeSignExt(ret, 2, *getModule()); } @@ -80,7 +80,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { 1, builder.makeLocalGet(temp, Type::i32), Type::i32), - builder.makeConst(Literal(int32_t(8))))), + builder.makeConst(int32_t(8)))), builder.makeBinary( OrInt32, builder.makeBinary( @@ -91,7 +91,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { 1, builder.makeLocalGet(temp, Type::i32), Type::i32), - builder.makeConst(Literal(int32_t(16)))), + builder.makeConst(int32_t(16))), builder.makeBinary( ShlInt32, builder.makeLoad(1, @@ -100,7 +100,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { 1, builder.makeLocalGet(temp, Type::i32), Type::i32), - builder.makeConst(Literal(int32_t(24)))))); + builder.makeConst(int32_t(24))))); } else if (curr->align == 2) { ret = builder.makeBinary( OrInt32, @@ -118,7 +118,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { 2, builder.makeLocalGet(temp, Type::i32), Type::i32), - builder.makeConst(Literal(int32_t(16))))); + builder.makeConst(int32_t(16)))); } else { WASM_UNREACHABLE("invalid alignment"); } @@ -160,7 +160,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { builder.makeLocalGet(tempPtr, Type::i32), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), - builder.makeConst(Literal(int32_t(8)))), + builder.makeConst(int32_t(8))), Type::i32)); } else if (curr->bytes == 4) { if (curr->align == 1) { @@ -178,7 +178,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { builder.makeLocalGet(tempPtr, Type::i32), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), - builder.makeConst(Literal(int32_t(8)))), + builder.makeConst(int32_t(8))), Type::i32)); block->list.push_back(builder.makeStore( 1, @@ -187,7 +187,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { builder.makeLocalGet(tempPtr, Type::i32), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), - builder.makeConst(Literal(int32_t(16)))), + builder.makeConst(int32_t(16))), Type::i32)); block->list.push_back(builder.makeStore( 1, @@ -196,7 +196,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { builder.makeLocalGet(tempPtr, Type::i32), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), - builder.makeConst(Literal(int32_t(24)))), + builder.makeConst(int32_t(24))), Type::i32)); } else if (curr->align == 2) { block->list.push_back( @@ -213,7 +213,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { builder.makeLocalGet(tempPtr, Type::i32), builder.makeBinary(ShrUInt32, builder.makeLocalGet(tempValue, Type::i32), - builder.makeConst(Literal(int32_t(16)))), + builder.makeConst(int32_t(16))), Type::i32)); } else { WASM_UNREACHABLE("invalid alignment"); diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp index d4a788adb..61c1f0ff4 100644 --- a/src/passes/Asyncify.cpp +++ b/src/passes/Asyncify.cpp @@ -998,7 +998,7 @@ private: // avoid saving/restoring that local later) curr = builder->makeIf( builder->makeIf(builder->makeStateCheck(State::Normal), - builder->makeConst(Literal(int32_t(1))), + builder->makeConst(int32_t(1)), makeCallIndexPeek(index)), builder->makeSequence(curr, makePossibleUnwind(index, set))); return curr; @@ -1011,9 +1011,8 @@ 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)))}, - Type::none), + builder->makeCall( + ASYNCIFY_UNWIND, {builder->makeConst(int32_t(index))}, Type::none), ifNotUnwinding); } @@ -1021,7 +1020,7 @@ private: // 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_CHECK_CALL_INDEX, - {builder->makeConst(Literal(int32_t(index)))}, + {builder->makeConst(int32_t(index))}, Type::i32); } @@ -1489,11 +1488,11 @@ private: Builder builder(*module); module->addGlobal(builder.makeGlobal(ASYNCIFY_STATE, Type::i32, - builder.makeConst(Literal(int32_t(0))), + builder.makeConst(int32_t(0)), Builder::Mutable)); module->addGlobal(builder.makeGlobal(ASYNCIFY_DATA, Type::i32, - builder.makeConst(Literal(int32_t(0))), + builder.makeConst(int32_t(0)), Builder::Mutable)); } @@ -1506,7 +1505,7 @@ private: } auto* body = builder.makeBlock(); body->list.push_back(builder.makeGlobalSet( - ASYNCIFY_STATE, builder.makeConst(Literal(int32_t(state))))); + ASYNCIFY_STATE, builder.makeConst(int32_t(state)))); if (setData) { body->list.push_back(builder.makeGlobalSet( ASYNCIFY_DATA, builder.makeLocalGet(0, Type::i32))); @@ -1617,7 +1616,7 @@ struct ModAsyncify value = 1 - value; } Builder builder(*this->getModule()); - this->replaceCurrent(builder.makeConst(Literal(int32_t(value)))); + this->replaceCurrent(builder.makeConst(int32_t(value))); } void visitSelect(Select* curr) { @@ -1630,7 +1629,7 @@ struct ModAsyncify // we know we'll never rewind, we can optimize this. if (neverRewind) { Builder builder(*this->getModule()); - curr->condition = builder.makeConst(Literal(int32_t(0))); + curr->condition = builder.makeConst(int32_t(0)); } } diff --git a/src/passes/DeNaN.cpp b/src/passes/DeNaN.cpp index c894cb3f1..8d0462718 100644 --- a/src/passes/DeNaN.cpp +++ b/src/passes/DeNaN.cpp @@ -51,13 +51,13 @@ struct DeNaN : public WalkerPass< auto* c = expr->dynCast<Const>(); if (expr->type == Type::f32) { if (c && c->value.isNaN()) { - replacement = builder.makeConst(Literal(float(0))); + replacement = builder.makeConst(float(0)); } else { replacement = builder.makeCall("deNan32", {expr}, Type::f32); } } else if (expr->type == Type::f64) { if (c && c->value.isNaN()) { - replacement = builder.makeConst(Literal(double(0))); + replacement = builder.makeConst(double(0)); } else { replacement = builder.makeCall("deNan64", {expr}, Type::f64); } diff --git a/src/passes/I64ToI32Lowering.cpp b/src/passes/I64ToI32Lowering.cpp index 912d6336c..78f15fcad 100644 --- a/src/passes/I64ToI32Lowering.cpp +++ b/src/passes/I64ToI32Lowering.cpp @@ -116,7 +116,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { curr->type = Type::i32; auto* high = builder->makeGlobal(makeHighName(curr->name), Type::i32, - builder->makeConst(Literal(int32_t(0))), + builder->makeConst(int32_t(0)), Builder::Mutable); module->addGlobal(high); if (curr->imported()) { @@ -126,7 +126,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { uint64_t value = c->value.geti64(); c->value = Literal(uint32_t(value)); c->type = Type::i32; - high->init = builder->makeConst(Literal(uint32_t(value >> 32))); + high->init = builder->makeConst(uint32_t(value >> 32)); } else if (auto* get = curr->init->dynCast<GlobalGet>()) { high->init = builder->makeGlobalGet(makeHighName(get->name), Type::i32); @@ -142,7 +142,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { auto* highBits = new Global(); highBits->type = Type::i32; highBits->name = INT64_TO_32_HIGH_BITS; - highBits->init = builder->makeConst(Literal(int32_t(0))); + highBits->init = builder->makeConst(int32_t(0)); highBits->mutable_ = true; module->addGlobal(highBits); PostWalker<I64ToI32Lowering>::doWalkModule(module); @@ -387,10 +387,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { highBits, builder->makeBinary(ShrSInt32, builder->makeLocalGet(lowBits, Type::i32), - builder->makeConst(Literal(int32_t(31))))); + builder->makeConst(int32_t(31)))); } else { - loadHigh = builder->makeLocalSet(highBits, - builder->makeConst(Literal(int32_t(0)))); + loadHigh = + builder->makeLocalSet(highBits, builder->makeConst(int32_t(0))); } curr->type = Type::i32; curr->bytes = std::min(curr->bytes, uint8_t(4)); @@ -445,9 +445,9 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { TempVar highBits = getTemp(); auto* getLow = builder->makeCall( ABI::wasm2js::ATOMIC_RMW_I64, - {builder->makeConst(Literal(int32_t(curr->op))), - builder->makeConst(Literal(int32_t(curr->bytes))), - builder->makeConst(Literal(int32_t(curr->offset))), + {builder->makeConst(int32_t(curr->op)), + builder->makeConst(int32_t(curr->bytes)), + builder->makeConst(int32_t(curr->offset)), curr->ptr, curr->value, builder->makeLocalGet(fetchOutParam(curr->value), Type::i32)}, @@ -487,11 +487,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { } TempVar highBits = getTemp(); Const* lowVal = - builder->makeConst(Literal(int32_t(curr->value.geti64() & 0xffffffff))); - LocalSet* setHigh = - builder->makeLocalSet(highBits, - builder->makeConst(Literal( - int32_t(uint64_t(curr->value.geti64()) >> 32)))); + builder->makeConst(int32_t(curr->value.geti64() & 0xffffffff)); + LocalSet* setHigh = builder->makeLocalSet( + highBits, + builder->makeConst(int32_t(uint64_t(curr->value.geti64()) >> 32))); Block* result = builder->blockify(setHigh, lowVal); setOutParam(result, std::move(highBits)); replaceCurrent(result); @@ -511,7 +510,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { void lowerExtendUInt32(Unary* curr) { TempVar highBits = getTemp(); Block* result = builder->blockify( - builder->makeLocalSet(highBits, builder->makeConst(Literal(int32_t(0)))), + builder->makeLocalSet(highBits, builder->makeConst(int32_t(0))), curr->value); setOutParam(result, std::move(highBits)); replaceCurrent(result); @@ -526,7 +525,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { highBits, builder->makeBinary(ShrSInt32, builder->makeLocalGet(lowBits, Type::i32), - builder->makeConst(Literal(int32_t(31))))); + builder->makeConst(int32_t(31)))); Block* result = builder->blockify( setLow, setHigh, builder->makeLocalGet(lowBits, Type::i32)); @@ -548,13 +547,12 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { Block* result = builder->blockify( builder->makeCall( ABI::wasm2js::SCRATCH_STORE_F64, {curr->value}, Type::none), - builder->makeLocalSet( - highBits, - builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_I32, - {builder->makeConst(Literal(int32_t(1)))}, - Type::i32)), + builder->makeLocalSet(highBits, + builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_I32, + {builder->makeConst(int32_t(1))}, + Type::i32)), builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_I32, - {builder->makeConst(Literal(int32_t(0)))}, + {builder->makeConst(int32_t(0))}, Type::i32)); setOutParam(result, std::move(highBits)); replaceCurrent(result); @@ -568,10 +566,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { TempVar highBits = fetchOutParam(curr->value); Block* result = builder->blockify( builder->makeCall(ABI::wasm2js::SCRATCH_STORE_I32, - {builder->makeConst(Literal(int32_t(0))), curr->value}, + {builder->makeConst(int32_t(0)), curr->value}, Type::none), builder->makeCall(ABI::wasm2js::SCRATCH_STORE_I32, - {builder->makeConst(Literal(int32_t(1))), + {builder->makeConst(int32_t(1)), builder->makeLocalGet(highBits, Type::i32)}, Type::none), builder->makeCall(ABI::wasm2js::SCRATCH_LOAD_F64, {}, Type::f64)); @@ -676,7 +674,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { builder->makeUnary(abs, builder->makeLocalGet(f, localType)), builder->makeConst(litOne)), highBitsCalc, - builder->makeConst(Literal(int32_t(0)))); + builder->makeConst(int32_t(0))); Block* result = builder->blockify( builder->makeLocalSet(f, curr->value), builder->makeLocalSet(highBits, highBitsVal), @@ -718,15 +716,14 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { Expression* result = builder->blockify( builder->makeLocalSet(lowBits, curr->value), - builder->makeLocalSet(highResult, - builder->makeConst(Literal(int32_t(0)))), + builder->makeLocalSet(highResult, builder->makeConst(int32_t(0))), builder->makeBinary( AddFloat64, builder->makeUnary(ConvertUInt32ToFloat64, builder->makeLocalGet(lowBits, Type::i32)), builder->makeBinary( MulFloat64, - builder->makeConst(Literal((double)UINT_MAX + 1)), + builder->makeConst((double)UINT_MAX + 1), builder->makeUnary(convertHigh, builder->makeLocalGet(highBits, Type::i32))))); @@ -757,18 +754,18 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { Binary* check = builder->makeBinary(EqInt32, builder->makeLocalGet(firstResult, Type::i32), - builder->makeConst(Literal(int32_t(32)))); + builder->makeConst(int32_t(32))); If* conditional = builder->makeIf( check, builder->makeBinary( AddInt32, builder->makeUnary(op32, builder->makeLocalGet(second, Type::i32)), - builder->makeConst(Literal(int32_t(32)))), + builder->makeConst(int32_t(32))), builder->makeLocalGet(firstResult, Type::i32)); - LocalSet* setHigh = builder->makeLocalSet( - highResult, builder->makeConst(Literal(int32_t(0)))); + LocalSet* setHigh = + builder->makeLocalSet(highResult, builder->makeConst(int32_t(0))); setOutParam(result, std::move(highResult)); @@ -890,7 +887,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { highResult, builder->makeBinary(AddInt32, builder->makeLocalGet(highResult, Type::i32), - builder->makeConst(Literal(int32_t(1))))); + builder->makeConst(int32_t(1)))); If* checkOverflow = builder->makeIf( builder->makeBinary(LtUInt32, builder->makeLocalGet(lowResult, Type::i32), @@ -978,7 +975,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { builder->makeBinary(ShlInt32, builder->makeLocalGet(leftLow, Type::i32), builder->makeLocalGet(shift, Type::i32))), - builder->makeConst(Literal(int32_t(0)))); + builder->makeConst(int32_t(0))); } // a >> b where `b` >= 32 @@ -993,7 +990,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { highBits, builder->makeBinary(ShrSInt32, builder->makeLocalGet(leftHigh, Type::i32), - builder->makeConst(Literal(int32_t(31))))), + builder->makeConst(int32_t(31)))), builder->makeBinary(ShrSInt32, builder->makeLocalGet(leftHigh, Type::i32), builder->makeLocalGet(shift, Type::i32))); @@ -1001,7 +998,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { Block* makeLargeShrU(Index highBits, Index leftHigh, Index shift) { return builder->blockify( - builder->makeLocalSet(highBits, builder->makeConst(Literal(int32_t(0)))), + builder->makeLocalSet(highBits, builder->makeConst(int32_t(0))), builder->makeBinary(ShrUInt32, builder->makeLocalGet(leftHigh, Type::i32), builder->makeLocalGet(shift, Type::i32))); @@ -1103,13 +1100,13 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { shift, builder->makeBinary(AndInt32, builder->makeLocalGet(rightLow, Type::i32), - builder->makeConst(Literal(int32_t(32 - 1))))); + builder->makeConst(int32_t(32 - 1)))); Binary* isLargeShift = builder->makeBinary( LeUInt32, - builder->makeConst(Literal(int32_t(32))), + builder->makeConst(int32_t(32)), builder->makeBinary(AndInt32, builder->makeLocalGet(rightLow, Type::i32), - builder->makeConst(Literal(int32_t(64 - 1))))); + builder->makeConst(int32_t(64 - 1)))); Block* largeShiftBlock; switch (op) { case ShlInt64: @@ -1127,12 +1124,12 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { Binary* shiftMask = builder->makeBinary( SubInt32, builder->makeBinary(ShlInt32, - builder->makeConst(Literal(int32_t(1))), + builder->makeConst(int32_t(1)), builder->makeLocalGet(shift, Type::i32)), - builder->makeConst(Literal(int32_t(1)))); + builder->makeConst(int32_t(1))); Binary* widthLessShift = builder->makeBinary(SubInt32, - builder->makeConst(Literal(int32_t(32))), + builder->makeConst(int32_t(32)), builder->makeLocalGet(shift, Type::i32)); Block* smallShiftBlock; switch (op) { @@ -1283,13 +1280,12 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { builder->makeBinary(lowOp, builder->makeLocalGet(leftLow, Type::i32), builder->makeLocalGet(rightLow, Type::i32)); - If* lowIf = builder->makeIf(compLow, - builder->makeConst(Literal(int32_t(0))), - builder->makeConst(Literal(int32_t(1)))); - If* highIf2 = builder->makeIf( - compHigh2, lowIf, builder->makeConst(Literal(int32_t(0)))); - If* highIf1 = builder->makeIf( - compHigh1, builder->makeConst(Literal(int32_t(1))), highIf2); + If* lowIf = builder->makeIf( + compLow, builder->makeConst(int32_t(0)), builder->makeConst(int32_t(1))); + If* highIf2 = + builder->makeIf(compHigh2, lowIf, builder->makeConst(int32_t(0))); + If* highIf1 = + builder->makeIf(compHigh1, builder->makeConst(int32_t(1)), highIf2); return builder->blockify(result, highIf1); } diff --git a/src/passes/InstrumentLocals.cpp b/src/passes/InstrumentLocals.cpp index 2c74e5794..0bf22d29b 100644 --- a/src/passes/InstrumentLocals.cpp +++ b/src/passes/InstrumentLocals.cpp @@ -107,12 +107,11 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { case Type::unreachable: WASM_UNREACHABLE("unexpected type"); } - replaceCurrent( - builder.makeCall(import, - {builder.makeConst(Literal(int32_t(id++))), - builder.makeConst(Literal(int32_t(curr->index))), - curr}, - curr->type)); + replaceCurrent(builder.makeCall(import, + {builder.makeConst(int32_t(id++)), + builder.makeConst(int32_t(curr->index)), + curr}, + curr->type)); } void visitLocalSet(LocalSet* curr) { @@ -157,12 +156,11 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { case Type::none: WASM_UNREACHABLE("unexpected type"); } - curr->value = - builder.makeCall(import, - {builder.makeConst(Literal(int32_t(id++))), - builder.makeConst(Literal(int32_t(curr->index))), - curr->value}, - curr->value->type); + curr->value = builder.makeCall(import, + {builder.makeConst(int32_t(id++)), + builder.makeConst(int32_t(curr->index)), + curr->value}, + curr->value->type); } void visitModule(Module* curr) { diff --git a/src/passes/InstrumentMemory.cpp b/src/passes/InstrumentMemory.cpp index 4db409c10..10574350b 100644 --- a/src/passes/InstrumentMemory.cpp +++ b/src/passes/InstrumentMemory.cpp @@ -78,13 +78,12 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> { void visitLoad(Load* curr) { id++; Builder builder(*getModule()); - curr->ptr = - builder.makeCall(load_ptr, - {builder.makeConst(Literal(int32_t(id))), - builder.makeConst(Literal(int32_t(curr->bytes))), - builder.makeConst(Literal(int32_t(curr->offset.addr))), - curr->ptr}, - Type::i32); + curr->ptr = builder.makeCall(load_ptr, + {builder.makeConst(int32_t(id)), + builder.makeConst(int32_t(curr->bytes)), + builder.makeConst(int32_t(curr->offset.addr)), + curr->ptr}, + Type::i32); Name target; switch (curr->type.getSingle()) { case Type::i32: @@ -103,19 +102,18 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> { return; // TODO: other types, unreachable, etc. } replaceCurrent(builder.makeCall( - target, {builder.makeConst(Literal(int32_t(id))), curr}, curr->type)); + target, {builder.makeConst(int32_t(id)), curr}, curr->type)); } void visitStore(Store* curr) { id++; Builder builder(*getModule()); - curr->ptr = - builder.makeCall(store_ptr, - {builder.makeConst(Literal(int32_t(id))), - builder.makeConst(Literal(int32_t(curr->bytes))), - builder.makeConst(Literal(int32_t(curr->offset.addr))), - curr->ptr}, - Type::i32); + curr->ptr = builder.makeCall(store_ptr, + {builder.makeConst(int32_t(id)), + builder.makeConst(int32_t(curr->bytes)), + builder.makeConst(int32_t(curr->offset.addr)), + curr->ptr}, + Type::i32); Name target; switch (curr->value->type.getSingle()) { case Type::i32: @@ -133,10 +131,8 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> { default: return; // TODO: other types, unreachable, etc. } - curr->value = - builder.makeCall(target, - {builder.makeConst(Literal(int32_t(id))), curr->value}, - curr->value->type); + curr->value = builder.makeCall( + target, {builder.makeConst(int32_t(id)), curr->value}, curr->value->type); } void visitModule(Module* curr) { diff --git a/src/passes/LogExecution.cpp b/src/passes/LogExecution.cpp index a6caf1c1f..ebc1c5636 100644 --- a/src/passes/LogExecution.cpp +++ b/src/passes/LogExecution.cpp @@ -71,8 +71,7 @@ private: static Index id = 0; Builder builder(*getModule()); return builder.makeSequence( - builder.makeCall( - LOGGER, {builder.makeConst(Literal(int32_t(id++)))}, Type::none), + builder.makeCall(LOGGER, {builder.makeConst(int32_t(id++))}, Type::none), curr); } }; diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp index c6b8a281a..1a1e87502 100644 --- a/src/passes/MemoryPacking.cpp +++ b/src/passes/MemoryPacking.cpp @@ -79,7 +79,7 @@ namespace { Expression* makeShiftedMemorySize(Builder& builder) { return builder.makeBinary(ShlInt32, builder.makeHost(MemorySize, Name(), {}), - builder.makeConst(Literal(int32_t(16)))); + builder.makeConst(int32_t(16))); } } // anonymous namespace @@ -437,8 +437,7 @@ void MemoryPacking::createSplitSegments(Builder& builder, Expression* offset = nullptr; if (!segment.isPassive) { if (auto* c = segment.offset->dynCast<Const>()) { - offset = - builder.makeConst(Literal(int32_t(c->value.geti32() + range.start))); + offset = builder.makeConst(int32_t(c->value.geti32() + range.start)); } else { assert(ranges.size() == 1); offset = segment.offset; @@ -497,7 +496,7 @@ void MemoryPacking::createReplacements(Module* module, std::to_string(dropStateGlobalCount++)); module->addGlobal(builder.makeGlobal(dropStateGlobal, Type::i32, - builder.makeConst(Literal(int32_t(0))), + builder.makeConst(int32_t(0)), Builder::Mutable)); return dropStateGlobal; }; @@ -576,21 +575,20 @@ void MemoryPacking::createReplacements(Module* module, // Calculate dest, either as a const or as an addition to the dest local Expression* dest; if (auto* c = init->dest->dynCast<Const>()) { - dest = - builder.makeConst(Literal(int32_t(c->value.geti32() + bytesWritten))); + dest = builder.makeConst(int32_t(c->value.geti32() + bytesWritten)); } else { auto* get = builder.makeLocalGet(-1, Type::i32); getVars.push_back(&get->index); dest = get; if (bytesWritten > 0) { - Const* addend = builder.makeConst(Literal(int32_t(bytesWritten))); + Const* addend = builder.makeConst(int32_t(bytesWritten)); dest = builder.makeBinary(AddInt32, dest, addend); } } // How many bytes are read from this range size_t bytes = std::min(range.end, end) - std::max(range.start, start); - Expression* size = builder.makeConst(Literal(int32_t(bytes))); + Expression* size = builder.makeConst(int32_t(bytes)); bytesWritten += bytes; // Create new memory.init or memory.fill @@ -600,7 +598,7 @@ void MemoryPacking::createReplacements(Module* module, appendResult(builder.makeMemoryFill(dest, value, size)); } else { size_t offsetBytes = std::max(start, range.start) - range.start; - Expression* offset = builder.makeConst(Literal(int32_t(offsetBytes))); + Expression* offset = builder.makeConst(int32_t(offsetBytes)); appendResult(builder.makeMemoryInit(initIndex, dest, offset, size)); initIndex++; } @@ -634,8 +632,8 @@ void MemoryPacking::createReplacements(Module* module, // Track drop state in a global only if some memory.init required it if (dropStateGlobal != Name()) { - appendResult(builder.makeGlobalSet( - dropStateGlobal, builder.makeConst(Literal(int32_t(1))))); + appendResult( + builder.makeGlobalSet(dropStateGlobal, builder.makeConst(int32_t(1)))); } size_t dropIndex = segmentIndex; for (auto range : ranges) { diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 68f0c06e0..00fb30b51 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -91,8 +91,7 @@ struct PostEmscripten : public Pass { auto oldValue = stackPointer->init->cast<Const>()->value; BYN_TRACE("updating __stack_pointer: " << oldValue.geti32() << " -> " << stackPtr << "\n"); - stackPointer->init = - Builder(*module).makeConst(Literal(int32_t(stackPtr))); + stackPointer->init = Builder(*module).makeConst(int32_t(stackPtr)); } } @@ -105,7 +104,7 @@ struct PostEmscripten : public Pass { auto* func = imports.getImportedFunction(ENV, "emscripten_get_sbrk_ptr"); if (func) { Builder builder(*module); - func->body = builder.makeConst(Literal(int32_t(sbrkPtr))); + func->body = builder.makeConst(int32_t(sbrkPtr)); func->module = func->base = Name(); } // Apply the sbrk ptr value, if it was provided. This lets emscripten set diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 5d1b70ad5..9d4575bb7 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -235,10 +235,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { } curr->targets.resize(curr->targets.size() - removable); Builder builder(*getModule()); - curr->condition = - builder.makeBinary(SubInt32, - curr->condition, - builder.makeConst(Literal(int32_t(removable)))); + curr->condition = builder.makeBinary( + SubInt32, curr->condition, builder.makeConst(int32_t(removable))); } // when there isn't a value, we can do some trivial optimizations without // worrying about the value being executed before the condition @@ -287,17 +285,16 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { Builder builder(*getModule()); auto temp = builder.addVar(getFunction(), Type::i32); Expression* z; - replaceCurrent( - z = builder.makeIf( - builder.makeLocalTee(temp, curr->condition, Type::i32), - builder.makeIf( - builder.makeBinary( - EqInt32, - builder.makeLocalGet(temp, Type::i32), - builder.makeConst(Literal(int32_t(curr->targets.size() - 1)))), - builder.makeBreak(curr->targets.back()), - builder.makeBreak(curr->default_)), - builder.makeBreak(curr->targets.front()))); + replaceCurrent(z = builder.makeIf( + builder.makeLocalTee(temp, curr->condition, Type::i32), + builder.makeIf(builder.makeBinary( + EqInt32, + builder.makeLocalGet(temp, Type::i32), + builder.makeConst( + int32_t(curr->targets.size() - 1))), + builder.makeBreak(curr->targets.back()), + builder.makeBreak(curr->default_)), + builder.makeBreak(curr->targets.front()))); } } } @@ -1262,10 +1259,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { Builder builder(*getModule()); // the table and condition are offset by the min if (min != 0) { - conditionValue = - builder.makeBinary(SubInt32, - conditionValue, - builder.makeConst(Literal(int32_t(min)))); + conditionValue = builder.makeBinary( + SubInt32, conditionValue, builder.makeConst(int32_t(min))); } list[end - 1] = builder.makeBlock( defaultName, |