Skip to content

Commit 9e3060d

Browse files
committed
Support LLVM "range" parameter attribute kinds in bitcode parser.
1 parent 9c1e4f4 commit 9e3060d

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -51,8 +51,11 @@ public class ParameterAttributes implements ParserListener {
5151
private static final int WELL_KNOWN_INTEGER_ATTRIBUTE_KIND = 1;
5252
private static final int STRING_ATTRIBUTE_KIND = 3;
5353
private static final int STRING_VALUE_ATTRIBUTE_KIND = 4;
54+
// unfortunately undocumented, see llvm/lib/Bitcode/Reader/BitcodeReader.cpp
5455
private static final int BYVAL_ATTRIBUTE_KIND = 5;
5556
private static final int TYPED_BYVAL_ATTRIBUTE_KIND = 6;
57+
private static final int CONSTANT_RANGE_ATTRIBUTE_KIND = 7;
58+
private static final int CONSTANT_RANGE_LIST_ATTRIBUTE_KIND = 8;
5659

5760
// stores attributes defined in PARAMATTR_GRP_CODE_ENTRY
5861
private final List<AttributesGroup> attributes = new ArrayList<>();
@@ -264,12 +267,44 @@ private void decodeGroupCodeEntry(RecordBuffer buffer) {
264267
break;
265268
}
266269

270+
case CONSTANT_RANGE_ATTRIBUTE_KIND: {
271+
// these attributes are not actually used by Sulong, skip over them
272+
Attribute.Kind.decode(buffer.read());
273+
long bitWidth = buffer.read();
274+
skipConstantRange(buffer, bitWidth);
275+
break;
276+
}
277+
278+
case CONSTANT_RANGE_LIST_ATTRIBUTE_KIND: {
279+
// these attributes are not actually used by Sulong, skip over them
280+
Attribute.Kind.decode(buffer.read());
281+
long rangeSize = buffer.read();
282+
long bitWidth = buffer.read();
283+
for (int i = 0; i < rangeSize; i++) {
284+
skipConstantRange(buffer, bitWidth);
285+
}
286+
break;
287+
}
288+
267289
default:
268290
throw new LLVMParserException("Unexpected code of attribute group: " + type);
269291
}
270292
}
271293
}
272294

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+
273308
private static String readString(RecordBuffer buffer) {
274309
StringBuilder sb = new StringBuilder();
275310
while (true) {

sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/model/attributes/Attribute.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -33,6 +33,7 @@
3333

3434
public abstract class Attribute {
3535

36+
// see llvm/include/llvm/Bitcode/LLVMBitCodes.h, enum AttributeKindCodes
3637
public enum Kind {
3738

3839
NONE,
@@ -114,7 +115,31 @@ public enum Kind {
114115
SWIFT_ASYNC,
115116
NO_SANITIZE_COVERAGE,
116117
ELEMENTTYPE,
117-
DISABLE_SANITIZER_INSTRUMENTATION;
118+
DISABLE_SANITIZER_INSTRUMENTATION,
119+
NO_SANITIZE_BOUNDS,
120+
ALLOC_ALIGN,
121+
ALLOCATED_POINTER,
122+
ALLOC_KIND,
123+
PRESPLIT_COROUTINE,
124+
FNRETTHUNK_EXTERN,
125+
SKIP_PROFILE,
126+
MEMORY,
127+
NOFPCLASS,
128+
OPTIMIZE_FOR_DEBUGGING,
129+
WRITABLE,
130+
CORO_ONLY_DESTROY_WHEN_COMPLETE,
131+
DEAD_ON_UNWIND,
132+
RANGE,
133+
SANITIZE_NUMERICAL_STABILITY,
134+
INITIALIZES,
135+
HYBRID_PATCHABLE,
136+
SANITIZE_REALTIME,
137+
SANITIZE_REALTIME_BLOCKING,
138+
CORO_ELIDE_SAFE,
139+
NO_EXT,
140+
NO_DIVERGENCE_SOURCE,
141+
SANITIZE_TYPE,
142+
CAPTURES;
118143

119144
private static final Kind[] VALUES = values();
120145

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -108,6 +108,10 @@ public void skip() {
108108
index++;
109109
}
110110

111+
public void skip(long nr) {
112+
index += nr;
113+
}
114+
111115
public void setIndex(int index) {
112116
this.index = index;
113117
}

0 commit comments

Comments
 (0)