use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.
the class ScaForward method analyzeForward.
/**
* Analyze the directive when it is used just before a function call.
*
* @param xcodeml Current XcodeML file unit.
* @return True if the analysis succeed. False otherwise.
*/
private boolean analyzeForward(XcodeProgram xcodeml) {
final Context context = xcodeml.context();
if (_fCall == null) {
xcodeml.addError("Directive is not followed by a fct call.", _claw.getPragma());
return false;
}
detectParameterMapping(context, _fCall);
_calledFctName = _fCall.getFctName();
FfunctionDefinition fctDef = xcodeml.getGlobalDeclarationsTable().getFunctionDefinition(_calledFctName);
FfunctionDefinition parentFctDef = _claw.getPragma().findParentFunction();
if (parentFctDef == null) {
xcodeml.addError("SCA directive is not nested in a " + "function/subroutine.", _claw.getPragma());
return false;
}
FmoduleDefinition parentModule = parentFctDef.findParentModule();
if (_fCall.isTbpCall()) {
/*
* If type is a FbasicType element for a type-bound procedure, we have to
* matchSeq the correct function in the typeTable. TODO if there is a rename.
* TODO generic call
*/
Xid id = parentModule.getSymbolTable().get(_calledFctName);
if (id == null) {
List<Xnode> uses = parentFctDef.getDeclarationTable().uses();
uses.addAll(parentModule.getDeclarationTable().uses());
if (!findInModule(context, uses)) {
xcodeml.addError("Function definition not found in module ", _claw.getPragma());
return false;
}
} else {
_fctType = xcodeml.getTypeTable().getFunctionType(id);
}
} else {
if (xcodeml.getTypeTable().isFunctionType(_fCall)) {
_fctType = xcodeml.getTypeTable().getFunctionType(_fCall);
} else {
xcodeml.addError("Unsupported type of XcodeML/F element for the function " + _calledFctName, _claw.getPragma());
return false;
}
}
/*
* Workaround for a bug in OMNI Compiler. Look at test case claw/abstraction10.
* In this test case, the XcodeML/F intermediate representation for the function
* call points to a FfunctionType element with no parameters. Thus, we have to
* matchSeq the correct FfunctionType for the same function/subroutine with the
* same name in the module symbol table.
*/
if (_fctType.getParameters().isEmpty()) {
/*
* If not, try to matchSeq the correct FfunctionType in the module definitions
*/
Xid id = (parentModule == null) ? null : parentModule.getSymbolTable().get(_calledFctName);
if (id == null) {
// Function is not located in the current module.
List<Xnode> uses = parentFctDef.getDeclarationTable().uses();
if (parentModule != null) {
uses.addAll(parentModule.getDeclarationTable().uses());
}
if (!findInModule(context, uses)) {
xcodeml.addError(String.format("Function definition %s not found in module.", _calledFctName), _claw.getPragma());
return false;
}
} else {
_fctType = xcodeml.getTypeTable().getFunctionType(id);
if (_fctType == null) {
xcodeml.addError("Called function cannot be found in the same module ", _claw.getPragma());
return false;
}
}
}
// end of workaround
_callingFctName = parentFctDef.getName();
if (_fctType != null && fctDef != null) {
_localFct = true;
} else {
// Has been found already
if (_fctType != null && _calledFctName == null) {
return true;
}
// Get all the use statements in the fct and module definitions
List<Xnode> uses = parentFctDef.getDeclarationTable().uses();
if (parentModule != null) {
uses.addAll(parentModule.getDeclarationTable().uses());
}
// Try to locate the fct in the modules defined in use statements
if (findInModule(context, uses)) {
return true;
}
xcodeml.addError("Function signature not found in the current module.", _claw.getPragma());
return false;
}
return true;
}
use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.
the class FieldTest method promoteTest.
@Test
public void promoteTest() {
DimensionDefinition dim1 = new DimensionDefinition("dim1", "1", "30");
DimensionDefinition dim2 = new DimensionDefinition("dim2", "1", "40");
List<DimensionDefinition> dimensions1 = Collections.singletonList(dim1);
List<DimensionDefinition> dimensions2 = Arrays.asList(dim1, dim2);
Context context = new TestContext();
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_PROMOTION, context);
assertNotNull(xcodeml);
List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
assertEquals(1, fctDefs.size());
FfunctionDefinition fctDef = fctDefs.get(0);
assertEquals("sub1", fctDef.getName());
// Scalar to array promotion with 1 additional dimension
dim1.setInsertionPosition(InsertionPosition.BEFORE);
performAndAssertPromotion("s1", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
performAndAssertPromotion("s2", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
dim1.setInsertionPosition(InsertionPosition.AFTER);
performAndAssertPromotion("s3", dimensions1, fctDef, xcodeml, 0, 1, new int[] { 1, 30 });
// Scalar to array promotion with 2 additional dimension
dim1.setInsertionPosition(InsertionPosition.BEFORE);
dim2.setInsertionPosition(InsertionPosition.BEFORE);
performAndAssertPromotion("s4", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
performAndAssertPromotion("s5", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
dim1.setInsertionPosition(InsertionPosition.AFTER);
dim2.setInsertionPosition(InsertionPosition.AFTER);
performAndAssertPromotion("s6", dimensions2, fctDef, xcodeml, 0, 2, new int[] { 1, 30, 1, 40 });
// Promotion with 1 additional dimension
dim1.setInsertionPosition(InsertionPosition.BEFORE);
performAndAssertPromotion("a", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 30, 1, 10, 1, 20 });
dim1.setInsertionPosition(InsertionPosition.AFTER);
performAndAssertPromotion("b", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 20, 1, 30 });
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
performAndAssertPromotion("c", dimensions1, fctDef, xcodeml, 2, 3, new int[] { 1, 10, 1, 30, 1, 20 });
// Promotion with 2 additional dimensions at the same position
dim1.setInsertionPosition(InsertionPosition.BEFORE);
dim2.setInsertionPosition(InsertionPosition.BEFORE);
performAndAssertPromotion("d", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 40, 1, 10, 1, 20 });
dim1.setInsertionPosition(InsertionPosition.AFTER);
dim2.setInsertionPosition(InsertionPosition.AFTER);
performAndAssertPromotion("e", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 20, 1, 30, 1, 40 });
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
performAndAssertPromotion("f", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 40, 1, 20 });
// Promotion with 2 additional dimensions at different position
dim1.setInsertionPosition(InsertionPosition.IN_MIDDLE);
dim2.setInsertionPosition(InsertionPosition.AFTER);
performAndAssertPromotion("g", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 10, 1, 30, 1, 20, 1, 40 });
dim1.setInsertionPosition(InsertionPosition.BEFORE);
dim2.setInsertionPosition(InsertionPosition.IN_MIDDLE);
performAndAssertPromotion("h", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 40, 1, 20 });
dim1.setInsertionPosition(InsertionPosition.BEFORE);
dim2.setInsertionPosition(InsertionPosition.AFTER);
performAndAssertPromotion("i", dimensions2, fctDef, xcodeml, 2, 4, new int[] { 1, 30, 1, 10, 1, 20, 1, 40 });
}
use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.
the class PragmaTest method getCompilerDirectiveTest.
@Test
public void getCompilerDirectiveTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
Xnode n1 = xcodeml.createNode(Xcode.F_DO_STATEMENT);
p1.setValue("claw loop-fusion");
assertEquals(CompilerDirective.CLAW, Pragma.getCompilerDirective(p1));
p1.setValue("omp teams distribute");
assertEquals(CompilerDirective.OPENMP, Pragma.getCompilerDirective(p1));
p1.setValue("acc parallel");
assertEquals(CompilerDirective.OPENACC, Pragma.getCompilerDirective(p1));
p1.setValue("ivdep");
assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(p1));
assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(null));
assertEquals(CompilerDirective.NONE, Pragma.getCompilerDirective(n1));
}
use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.
the class PragmaTest method splitByContTest.
@Test
public void splitByContTest() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
assertFalse(fctDefs.isEmpty());
FfunctionDefinition fd = fctDefs.get(0);
assertNotNull(fd.body());
List<Xnode> previous = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
fd.body().append(p1);
p1.setValue("acc data present(q,acc& p,acc& h)acc& create(pt)");
try {
Pragma.splitByCont(p1, CompilerDirective.OPENACC.getPrefix(), xcodeml);
List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(previous.size() + 4, splittedPragma.size());
} catch (IllegalTransformationException e) {
fail();
}
Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
fd.body().append(p2);
p2.setValue("omp target teams omp& distribute simd");
try {
Pragma.splitByCont(p2, CompilerDirective.OPENMP.getPrefix(), xcodeml);
List<Xnode> splittedPragma = fd.matchAll(Xcode.F_PRAGMA_STATEMENT);
assertEquals(previous.size() + 6, splittedPragma.size());
} catch (IllegalTransformationException e) {
fail();
}
}
use of claw.tatsu.common.Context in project claw-compiler by C2SM-RCM.
the class PragmaTest method splitTest.
@Test
public void splitTest() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
String p1 = "acc data present(var1,var2,var3,var4,var5,var6,var7,var8," + "var10,var11,var12,var13,var14,var15,var16)";
int maxCol = 40;
// Just commas
List<String> splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
checkSplitted(splitted, 5, maxCol);
// Just spaces
p1 = "acc data present(var1, var2, var3, var4, var5, var6, var7, " + "var8, var10, var11, var12, var13, var14, var15, var16)";
splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
checkSplitted(splitted, 4, maxCol);
// Mixed spaces and commas
p1 = "acc data present(var1, var2,var3,var4, var5, var6, var7, " + "var8,var10,var11, var12,var13,var14, var15,var16, var17, var18)";
splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENACC.getPrefix());
checkSplitted(splitted, 5, maxCol);
p1 = "omp target teams distribute parallel do simd";
splitted = Pragma.split(p1, maxCol, CompilerDirective.OPENMP.getPrefix());
checkSplitted(splitted, 2, maxCol);
}
Aggregations