@@ -34,9 +34,10 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
3434 if (curr->align == 0 || curr->align == curr->bytes ) {
3535 return curr;
3636 }
37+ auto indexType = getModule ()->memory .indexType ;
3738 Builder builder (*getModule ());
3839 assert (curr->type == Type::i32 );
39- auto temp = builder.addVar (getFunction (), Type:: i32 );
40+ auto temp = builder.addVar (getFunction (), indexType );
4041 Expression* ret;
4142 if (curr->bytes == 2 ) {
4243 ret = builder.makeBinary (
@@ -45,15 +46,15 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
4546 false ,
4647 curr->offset ,
4748 1 ,
48- builder.makeLocalGet (temp, Type:: i32 ),
49+ builder.makeLocalGet (temp, indexType ),
4950 Type::i32 ),
5051 builder.makeBinary (
5152 ShlInt32,
5253 builder.makeLoad (1 ,
5354 false ,
5455 curr->offset + 1 ,
5556 1 ,
56- builder.makeLocalGet (temp, Type:: i32 ),
57+ builder.makeLocalGet (temp, indexType ),
5758 Type::i32 ),
5859 builder.makeConst (int32_t (8 ))));
5960 if (curr->signed_ ) {
@@ -69,15 +70,15 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
6970 false ,
7071 curr->offset ,
7172 1 ,
72- builder.makeLocalGet (temp, Type:: i32 ),
73+ builder.makeLocalGet (temp, indexType ),
7374 Type::i32 ),
7475 builder.makeBinary (
7576 ShlInt32,
7677 builder.makeLoad (1 ,
7778 false ,
7879 curr->offset + 1 ,
7980 1 ,
80- builder.makeLocalGet (temp, Type:: i32 ),
81+ builder.makeLocalGet (temp, indexType ),
8182 Type::i32 ),
8283 builder.makeConst (int32_t (8 )))),
8384 builder.makeBinary (
@@ -88,7 +89,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
8889 false ,
8990 curr->offset + 2 ,
9091 1 ,
91- builder.makeLocalGet (temp, Type:: i32 ),
92+ builder.makeLocalGet (temp, indexType ),
9293 Type::i32 ),
9394 builder.makeConst (int32_t (16 ))),
9495 builder.makeBinary (
@@ -97,7 +98,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
9798 false ,
9899 curr->offset + 3 ,
99100 1 ,
100- builder.makeLocalGet (temp, Type:: i32 ),
101+ builder.makeLocalGet (temp, indexType ),
101102 Type::i32 ),
102103 builder.makeConst (int32_t (24 )))));
103104 } else if (curr->align == 2 ) {
@@ -107,15 +108,15 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
107108 false ,
108109 curr->offset ,
109110 2 ,
110- builder.makeLocalGet (temp, Type:: i32 ),
111+ builder.makeLocalGet (temp, indexType ),
111112 Type::i32 ),
112113 builder.makeBinary (
113114 ShlInt32,
114115 builder.makeLoad (2 ,
115116 false ,
116117 curr->offset + 2 ,
117118 2 ,
118- builder.makeLocalGet (temp, Type:: i32 ),
119+ builder.makeLocalGet (temp, indexType ),
119120 Type::i32 ),
120121 builder.makeConst (int32_t (16 ))));
121122 } else {
@@ -134,7 +135,8 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
134135 }
135136 Builder builder (*getModule ());
136137 assert (curr->value ->type == Type::i32 );
137- auto tempPtr = builder.addVar (getFunction (), Type::i32 );
138+ auto indexType = getModule ()->memory .indexType ;
139+ auto tempPtr = builder.addVar (getFunction (), indexType);
138140 auto tempValue = builder.addVar (getFunction (), Type::i32 );
139141 auto * block =
140142 builder.makeBlock ({builder.makeLocalSet (tempPtr, curr->ptr ),
@@ -144,14 +146,14 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
144146 builder.makeStore (1 ,
145147 curr->offset ,
146148 1 ,
147- builder.makeLocalGet (tempPtr, Type:: i32 ),
149+ builder.makeLocalGet (tempPtr, indexType ),
148150 builder.makeLocalGet (tempValue, Type::i32 ),
149151 Type::i32 ));
150152 block->list .push_back (builder.makeStore (
151153 1 ,
152154 curr->offset + 1 ,
153155 1 ,
154- builder.makeLocalGet (tempPtr, Type:: i32 ),
156+ builder.makeLocalGet (tempPtr, indexType ),
155157 builder.makeBinary (ShrUInt32,
156158 builder.makeLocalGet (tempValue, Type::i32 ),
157159 builder.makeConst (int32_t (8 ))),
@@ -162,14 +164,14 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
162164 builder.makeStore (1 ,
163165 curr->offset ,
164166 1 ,
165- builder.makeLocalGet (tempPtr, Type:: i32 ),
167+ builder.makeLocalGet (tempPtr, indexType ),
166168 builder.makeLocalGet (tempValue, Type::i32 ),
167169 Type::i32 ));
168170 block->list .push_back (builder.makeStore (
169171 1 ,
170172 curr->offset + 1 ,
171173 1 ,
172- builder.makeLocalGet (tempPtr, Type:: i32 ),
174+ builder.makeLocalGet (tempPtr, indexType ),
173175 builder.makeBinary (ShrUInt32,
174176 builder.makeLocalGet (tempValue, Type::i32 ),
175177 builder.makeConst (int32_t (8 ))),
@@ -178,7 +180,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
178180 1 ,
179181 curr->offset + 2 ,
180182 1 ,
181- builder.makeLocalGet (tempPtr, Type:: i32 ),
183+ builder.makeLocalGet (tempPtr, indexType ),
182184 builder.makeBinary (ShrUInt32,
183185 builder.makeLocalGet (tempValue, Type::i32 ),
184186 builder.makeConst (int32_t (16 ))),
@@ -187,7 +189,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
187189 1 ,
188190 curr->offset + 3 ,
189191 1 ,
190- builder.makeLocalGet (tempPtr, Type:: i32 ),
192+ builder.makeLocalGet (tempPtr, indexType ),
191193 builder.makeBinary (ShrUInt32,
192194 builder.makeLocalGet (tempValue, Type::i32 ),
193195 builder.makeConst (int32_t (24 ))),
@@ -197,14 +199,14 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
197199 builder.makeStore (2 ,
198200 curr->offset ,
199201 2 ,
200- builder.makeLocalGet (tempPtr, Type:: i32 ),
202+ builder.makeLocalGet (tempPtr, indexType ),
201203 builder.makeLocalGet (tempValue, Type::i32 ),
202204 Type::i32 ));
203205 block->list .push_back (builder.makeStore (
204206 2 ,
205207 curr->offset + 2 ,
206208 2 ,
207- builder.makeLocalGet (tempPtr, Type:: i32 ),
209+ builder.makeLocalGet (tempPtr, indexType ),
208210 builder.makeBinary (ShrUInt32,
209211 builder.makeLocalGet (tempValue, Type::i32 ),
210212 builder.makeConst (int32_t (16 ))),
@@ -254,14 +256,15 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
254256 break ;
255257 }
256258 // Load two 32-bit pieces, and combine them.
257- auto temp = builder.addVar (getFunction (), Type::i32 );
259+ auto indexType = getModule ()->memory .indexType ;
260+ auto temp = builder.addVar (getFunction (), indexType);
258261 auto * set = builder.makeLocalSet (temp, curr->ptr );
259262 Expression* low =
260263 lowerLoadI32 (builder.makeLoad (4 ,
261264 false ,
262265 curr->offset ,
263266 curr->align ,
264- builder.makeLocalGet (temp, Type:: i32 ),
267+ builder.makeLocalGet (temp, indexType ),
265268 Type::i32 ));
266269 low = builder.makeUnary (ExtendUInt32, low);
267270 // Note that the alignment is assumed to be the same here, even though
@@ -273,7 +276,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
273276 false ,
274277 curr->offset + 4 ,
275278 curr->align ,
276- builder.makeLocalGet (temp, Type:: i32 ),
279+ builder.makeLocalGet (temp, indexType ),
277280 Type::i32 ));
278281 high = builder.makeUnary (ExtendUInt32, high);
279282 high =
@@ -332,7 +335,8 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
332335 value = builder.makeUnary (ReinterpretFloat64, value);
333336 }
334337 // Store as two 32-bit pieces.
335- auto tempPtr = builder.addVar (getFunction (), Type::i32 );
338+ auto indexType = getModule ()->memory .indexType ;
339+ auto tempPtr = builder.addVar (getFunction (), indexType);
336340 auto * setPtr = builder.makeLocalSet (tempPtr, curr->ptr );
337341 auto tempValue = builder.addVar (getFunction (), Type::i64 );
338342 auto * setValue = builder.makeLocalSet (tempValue, value);
@@ -342,7 +346,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
342346 builder.makeStore (4 ,
343347 curr->offset ,
344348 curr->align ,
345- builder.makeLocalGet (tempPtr, Type:: i32 ),
349+ builder.makeLocalGet (tempPtr, indexType ),
346350 low,
347351 Type::i32 ));
348352 Expression* high =
@@ -358,7 +362,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
358362 builder.makeStore (4 ,
359363 curr->offset + 4 ,
360364 curr->align ,
361- builder.makeLocalGet (tempPtr, Type:: i32 ),
365+ builder.makeLocalGet (tempPtr, indexType ),
362366 high,
363367 Type::i32 ));
364368 replacement = builder.makeBlock ({setPtr, setValue, low, high});
0 commit comments