Skip to content

Commit

Permalink
* m1: other compiler fixes
Browse files Browse the repository at this point in the history
These issues were discovered during run against debug version of llvm lib and crashes happened on assertions:
* llvm: changed Load/Store atomic access ordering from `unordered` to `monotonic` as it was crashing during AtomicExpandPass for x86 target. Line of code where it crashing `getStrongestFailureOrdering`. In release build with assertions removed it falls down into `Monotonic` case anyway.
* bug fixed: wrong calculation of struct offset for Vectorized Structs. Root case is that vector was wrapped into single element struct like `{<2 x float>}` and any try to get offset for member 1+ returns garbage (or crash on assert in debug version of llvm). Workaround -- getting element storage size and multiply by index
  • Loading branch information
dkimitsa committed May 26, 2021
1 parent 46b421f commit 1ebe5e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions compiler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/libimobiledevice/target/
/libimobiledevice/target-libimobiledevice/
/llvm/target/
/llvm/target.llvm/
/libhfscompressor/target-libhfscompressor/
/objc/target/
/rt/target/
/vm/target/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ static Function createFieldGetter(Function fn, SootField field, List<SootField>
if (Modifier.isVolatile(field.getModifiers())) {
fn.add(new Fence(Ordering.seq_cst));
if (LongType.v().equals(field.getType())) {
fn.add(new Load(result, fieldPtr, false, Ordering.unordered, 8));
fn.add(new Load(result, fieldPtr, false, Ordering.monotonic, 8));
} else {
fn.add(new Load(result, fieldPtr));
}
Expand Down Expand Up @@ -1648,7 +1648,7 @@ static Function createFieldSetter(Function fn, SootField field, List<SootField>
}
if (Modifier.isVolatile(field.getModifiers()) || !field.isStatic() && Modifier.isFinal(field.getModifiers())) {
if (LongType.v().equals(field.getType())) {
fn.add(new Store(value, fieldPtr, false, Ordering.unordered, 8));
fn.add(new Store(value, fieldPtr, false, Ordering.monotonic, 8));
} else {
fn.add(new Store(value, fieldPtr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,22 @@ Integer doWithType(TargetMachine targetMachine, org.robovm.llvm.Type type) {
}

public int getOffsetOfElement(StructureType type, int idx) {
return runTypeQuery(type, new TypeCallback<Integer>() {
Integer doWithType(TargetMachine targetMachine, org.robovm.llvm.Type type) {
return (int) targetMachine.getDataLayout().getOffsetOfElement(type, idx);
}
});
if (type instanceof VectorStructureType) {
// special case handling for simple vector arrays like VectorFloat2 that has llvm signature as <2 x float>
// wrapping it into {<2 x float>} will fail on getting offset at index 1+ as there is only one element in
// the list
if (type.getOwnMembersOffset() != 0)
throw new IllegalArgumentException("Failed to process Vectorized struct. Probably it inherits another struct!");

// in this case just get storage size and multiply
return getStoreSize(type.getTypeAt(0)) * idx;
} else {
return runTypeQuery(type, new TypeCallback<Integer>() {
Integer doWithType(TargetMachine targetMachine, org.robovm.llvm.Type type) {
return (int) targetMachine.getDataLayout().getOffsetOfElement(type, idx);
}
});
}
}

private static abstract class TypeCallback<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public VectorStructureType(String alias, Type ... types) {

/**
* @return true if vector consists of another vector structs (not primitives)\
* and will be translated into stuct of array of primitive vector
* and will be translated into struct of array of primitive vector
* example is MatrixFloat2x2
*/
public boolean isVectorArray() {
Expand Down

0 comments on commit 1ebe5e2

Please sign in to comment.