Skip to content

Commit 50f7c96

Browse files
committed
New LLVM constant getelementptr expression.
1 parent 847e7b5 commit 50f7c96

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/listeners/Constants.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2025, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -66,7 +66,7 @@ public final class Constants implements ParserListener {
6666
private static final int CONSTANT_CSTRING = 9;
6767
private static final int CONSTANT_CE_BINOP = 10;
6868
private static final int CONSTANT_CE_CAST = 11;
69-
private static final int CONSTANT_CE_GEP = 12;
69+
private static final int CONSTANT_CE_GEP_OLD = 12;
7070
private static final int CONSTANT_CE_SELECT = 13;
7171
// private static final int CONSTANT_CE_EXTRACTELT = 14;
7272
// private static final int CONSTANT_CE_INSERTELT = 15;
@@ -78,13 +78,16 @@ public final class Constants implements ParserListener {
7878
private static final int CONSTANT_BLOCKADDRESS = 21;
7979
private static final int CONSTANT_DATA = 22;
8080
private static final int CONSTANT_INLINEASM_OLD2 = 23;
81-
private static final int CONSTANT_CE_GEP_WITH_INRANGE_INDEX = 24;
81+
private static final int CONSTANT_CE_GEP_WITH_INRANGE_INDEX_OLD = 24;
8282
private static final int CONSTANT_CE_UNOP = 25;
8383
private static final int CONSTANT_POISON = 26;
8484
// private static final int CONSTANT_DSO_LOCAL_EQUIVALENT = 27;
8585
// private static final int CONSTANT_INLINEASM_OLD3 = 28;
8686
// private static final int CONSTANT_NO_CFI_VALUE = 29;
8787
private static final int CONSTANT_INLINEASM = 30;
88+
private static final int CONSTANT_CE_GEP_WITH_INRANGE = 31;
89+
private static final int CONSTANT_CE_GEP = 32;
90+
// private static final int CONSTANT_PTRAUTH = 30;
8891

8992
private static final BigInteger WIDE_INTEGER_MASK = BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE);
9093

@@ -207,9 +210,11 @@ public void record(RecordBuffer buffer) {
207210
scope.addSymbol(InlineAsmConstant.createFromData(type, fnType, buffer), type);
208211
return;
209212

210-
case CONSTANT_CE_GEP:
213+
case CONSTANT_CE_GEP_OLD:
211214
case CONSTANT_CE_INBOUNDS_GEP:
212-
case CONSTANT_CE_GEP_WITH_INRANGE_INDEX:
215+
case CONSTANT_CE_GEP_WITH_INRANGE_INDEX_OLD:
216+
case CONSTANT_CE_GEP_WITH_INRANGE:
217+
case CONSTANT_CE_GEP:
213218
createGetElementPointerExpression(buffer);
214219
return;
215220

@@ -229,12 +234,25 @@ public void record(RecordBuffer buffer) {
229234
private void createGetElementPointerExpression(RecordBuffer buffer) {
230235
int opCode = buffer.getId();
231236
Type gepType = null;
232-
if (opCode == CONSTANT_CE_GEP_WITH_INRANGE_INDEX || buffer.size() % 2 != 0) {
237+
if (opCode == CONSTANT_CE_GEP_WITH_INRANGE_INDEX_OLD ||
238+
opCode == CONSTANT_CE_GEP_WITH_INRANGE ||
239+
opCode == CONSTANT_CE_GEP || buffer.size() % 2 != 0) {
233240
gepType = types.get(buffer.read());
234241
}
235242

236243
boolean isInbounds;
237-
if (opCode == CONSTANT_CE_GEP_WITH_INRANGE_INDEX) {
244+
// structure of this if on purpose kept very similar to the code in LLVMs BitcodeReader.cpp
245+
if (opCode == CONSTANT_CE_GEP_WITH_INRANGE_INDEX_OLD) {
246+
long op = buffer.read();
247+
isInbounds = (op & 0x1) != 0;
248+
} else if (opCode == CONSTANT_CE_GEP_WITH_INRANGE) {
249+
long op = buffer.read();
250+
// ignore nuw and nusw flags
251+
isInbounds = (op & 0x1) != 0;
252+
// ignore the range
253+
long bitWidth = buffer.read();
254+
buffer.skipConstantRange(bitWidth);
255+
} else if (opCode == CONSTANT_CE_GEP) {
238256
long op = buffer.read();
239257
isInbounds = (op & 0x1) != 0;
240258
} else {

sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/listeners/ParameterAttributes.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private void decodeGroupCodeEntry(RecordBuffer buffer) {
271271
// these attributes are not actually used by Sulong, skip over them
272272
Attribute.Kind.decode(buffer.read());
273273
long bitWidth = buffer.read();
274-
skipConstantRange(buffer, bitWidth);
274+
buffer.skipConstantRange(bitWidth);
275275
break;
276276
}
277277

@@ -281,7 +281,7 @@ private void decodeGroupCodeEntry(RecordBuffer buffer) {
281281
long rangeSize = buffer.read();
282282
long bitWidth = buffer.read();
283283
for (int i = 0; i < rangeSize; i++) {
284-
skipConstantRange(buffer, bitWidth);
284+
buffer.skipConstantRange(bitWidth);
285285
}
286286
break;
287287
}
@@ -292,19 +292,6 @@ private void decodeGroupCodeEntry(RecordBuffer buffer) {
292292
}
293293
}
294294

295-
private static void skipConstantRange(RecordBuffer buffer, long bitWidth) {
296-
if (bitWidth > 64) {
297-
long activeWords = buffer.read();
298-
long lowerActiveWords = activeWords & ((1L << 32) - 1);
299-
long upperActiveWords = activeWords >>> 32;
300-
buffer.skip(lowerActiveWords);
301-
buffer.skip(upperActiveWords);
302-
} else {
303-
buffer.skip(); // start
304-
buffer.skip(); // end
305-
}
306-
}
307-
308295
private static String readString(RecordBuffer buffer) {
309296
StringBuilder sb = new StringBuilder();
310297
while (true) {

sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/scanner/RecordBuffer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ public void skip() {
108108
index++;
109109
}
110110

111+
public void skipConstantRange(long bitWidth) {
112+
if (bitWidth > 64) {
113+
long activeWords = read();
114+
long lowerActiveWords = activeWords & ((1L << 32) - 1);
115+
long upperActiveWords = activeWords >>> 32;
116+
skip(lowerActiveWords);
117+
skip(upperActiveWords);
118+
} else {
119+
skip(); // start
120+
skip(); // end
121+
}
122+
}
123+
111124
public void skip(long nr) {
112125
index += nr;
113126
}

0 commit comments

Comments
 (0)