Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/large primitive arrays #489

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.parallel=true
org.gradle.jvmargs='-Dfile.encoding=UTF-8'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.renjin.gcc.codegen.vptr.VPtrStrategy;
import org.renjin.gcc.gimple.GimpleVarDecl;
import org.renjin.gcc.gimple.expr.GimpleConstructor;
import org.renjin.gcc.gimple.expr.GimpleIntegerConstant;
import org.renjin.gcc.gimple.type.GimpleArrayType;
import org.renjin.repackaged.asm.Type;
import org.renjin.repackaged.guava.base.Preconditions;
Expand Down Expand Up @@ -172,25 +171,13 @@ public FatArrayExpr constructorExpr(ExprFactory exprFactory, MethodGenerator mv,
}

private void addElementConstructors(List<JExpr> values, ExprFactory exprFactory, GimpleConstructor constructor) {
int index = 0;
for (GimpleConstructor.Element element : constructor.getElements()) {
for (GimpleConstructor.Element element : constructor.normalizeArrayElements()) {

if(element.getField() instanceof GimpleIntegerConstant) {
int elementIndex = ((GimpleIntegerConstant) element.getField()).getValue().intValue();
if(elementIndex < index) {
throw new IllegalStateException("index = " + index + ", elementIndex = " + elementIndex);
if(element == null) {
for (int i = 0; i < elementValueFunction.getElementLength(); ++i) {
values.add(null);
}
// Some arrays have jagged initialization (looking at you, Fortran!)
// so we may need to skip a few elements
while(index < elementIndex) {
for(int i = 0; i < elementValueFunction.getElementLength(); ++i) {
values.add(null);
}
index++;
}
}

if(element.getValue() instanceof GimpleConstructor &&
} else if(element.getValue() instanceof GimpleConstructor &&
element.getValue().getType() instanceof GimpleArrayType) {
GimpleConstructor elementConstructor = (GimpleConstructor) element.getValue();

Expand All @@ -201,7 +188,6 @@ private void addElementConstructors(List<JExpr> values, ExprFactory exprFactory,
List<JExpr> arrayValues = elementValueFunction.toArrayValues(elementExpr);
values.addAll(arrayValues);
}
index++;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.renjin.gcc.codegen.constructors;

import org.renjin.gcc.codegen.MethodGenerator;
import org.renjin.gcc.codegen.ResourceWriter;
import org.renjin.gcc.codegen.expr.GExpr;
import org.renjin.gcc.gimple.expr.GimpleConstructor;

import static org.renjin.gcc.codegen.constructors.Constructors.*;

public class ConstructorFactory {
public static GExpr tryCreate(MethodGenerator mv, ResourceWriter resourceWriter, GimpleConstructor value) {
for (ConstructorInterface instance : instances) {
GExpr result = instance.tryCreate(mv, resourceWriter, value);
if (result != null) {
return result;
}
}
return null;
}

private static Constructors.ConstructorInterface[] instances = {
// mitigate `Method code too large` errors for large constant array expressions
largeShortArray,
largeIntArray,
largeLongArray,
largeFloatArray,
largeDoubleArray,
// store large string arrays either in the string pool, or in a resource for very large arrays
stringArray,
// store char arrays as a string in the constant pool
charArray, // n.b., this should be _after_ `largeShortArray`
Constructors::int32Array2d
};
}
Loading