private boolean isEmptyAndUnreferencedDeclaration(DeclarationStmt stmt) { if (stmt.getVariablesDeclaration().getNumDecls() != 0) { return false; } return !StructUtils.declaresReferencedStruct(tu, stmt.getVariablesDeclaration()); }
@Override public DeclarationStmt clone() { return new DeclarationStmt(variablesDeclaration.clone()); }
public DestructifyReductionOpportunity(DeclarationStmt declaration, TranslationUnit tu, BlockStmt block, VisitationDepth depth) { super(depth); assert declaration.getVariablesDeclaration().getNumDecls() == 1; this.declaration = declaration; this.tu = tu; this.block = block; this.originalNumVariables = declaration.getVariablesDeclaration().getNumDecls(); }
@Override public DeclarationStmt visitDeclaration_statement(Declaration_statementContext ctx) { if (ctx.declaration().init_declarator_list() == null) { throw new RuntimeException("Error at line " + ctx.start.getLine() + ": Only variable declarations are supported in declaration statements"); } return new DeclarationStmt( visitInit_declarator_list(ctx.declaration().init_declarator_list())); }
private static boolean isOutVariableBackup(DeclarationStmt declarationStmt) { return declarationStmt.getVariablesDeclaration().getDeclInfos() .stream().map(VariableDeclInfo::getName) .anyMatch(LiveOutputVariableWriteReductionOpportunities::isOutVariableBackup); }
private void addComponentVariableIfNotPresent() { if (getAllVariableDeclInfosInBlock() .stream() .anyMatch(item -> item.getName().equals(getComponentName()))) { return; } block.insertStmt(0, new DeclarationStmt(new VariablesDeclaration( getComponentType(), new VariableDeclInfo(getComponentName(), null, null)))); }
@Override public void visitDeclarationStmt(DeclarationStmt declarationStmt) { visitChildFromParent(this::visitVariablesDeclaration, declarationStmt.getVariablesDeclaration(), declarationStmt); }
private DeclarationStmt fuzzDeclarationStmt() { final Type baseType = fuzzType(); final int numDeclsInGroup = generator.nextPositiveInt(MAX_LOCALS_IN_DECL_GROUP); List<VariableDeclInfo> decls = new ArrayList<>(); for (int i = 0; i < numDeclsInGroup; i++) { final String name = createName("v"); ArrayInfo arrayInfo = null; if (generator.nextInt(10) < 3) { // TODO Hack for now, needs thought arrayInfo = new ArrayInfo(generator.nextPositiveInt(MAX_ARRAY_SIZE)); } fuzzingContext.addLocal(name, arrayInfo == null ? baseType : getType(baseType, arrayInfo)); decls.add(new VariableDeclInfo(name, arrayInfo, null)); // TODO: no initializer for now } return new DeclarationStmt(new VariablesDeclaration(baseType, decls)); }
private List<VariableDeclInfo> getAllVariableDeclInfosInBlock() { return block.getStmts() .stream() .filter(item -> item instanceof DeclarationStmt) .map(item -> (DeclarationStmt) item) .map(item -> item.getVariablesDeclaration()) .map(item -> item.getDeclInfos()) .reduce(Arrays.asList(), ListConcat::concatenate); }
generator, shadingLanguageVersion); donatedStmts.add(new DeclarationStmt( new VariablesDeclaration(type, new VariableDeclInfo(vars.getKey(), null, initializer))));
private static Optional<String> containsOutVariableBackup(BlockStmt block) { return block.getStmts().stream() .filter(item -> item instanceof DeclarationStmt) .map(item -> (DeclarationStmt) item) .filter(LiveOutputVariableWriteReductionOpportunities::isOutVariableBackup) .findFirst() .map(vdi -> vdi.getVariablesDeclaration().getDeclInfos() .stream().map(item -> item.getName()).findFirst().get()); }
shadingLanguageVersion); donatedStmts.add(new DeclarationStmt( new VariablesDeclaration(dropQualifiersThatCannotBeUsedForLocalVariable(type), new VariableDeclInfo(newName, null,
static boolean isStructifiedDeclaration(DeclarationStmt declarationStmt) { return declarationStmt.getVariablesDeclaration().getNumDecls() == 1 && declarationStmt.getVariablesDeclaration().getDeclInfo(0).getName() .startsWith(Constants.STRUCTIFICATION_STRUCT_PREFIX); }
new BlockStmt(inlinedStmts, true)); if (returnVariableName.isPresent()) { currentBlockStmt.insertStmt(currentIndex, new DeclarationStmt( new VariablesDeclaration( clonedFunctionDefinition.getPrototype().getReturnType()
public StructificationOpportunity(DeclarationStmt declToTransform, BlockStmt block, TranslationUnit tu, ShadingLanguageVersion shadingLanguageVersion) { assert declToTransform.getVariablesDeclaration().getNumDecls() == 1 : "Only solo declarations can be structified"; assert !declToTransform.getVariablesDeclaration().getDeclInfo(0).hasArrayInfo() : "Structification of arrays not supported"; this.declToTransform = declToTransform; this.block = block; this.tu = tu; this.shadingLanguageVersion = shadingLanguageVersion; }
public void apply() { if (blockAlreadyDeclaresVector()) { return; } for (ScopeEntry se : mergeSet.getIndidualScopeEntries()) { new VectorizerVisitor(se).visit(block); } block.insertStmt(0, new DeclarationStmt(new VariablesDeclaration( mergeSet.getMergedType(), new VariableDeclInfo(mergeSet.getMergedName(), null, null)))); }
private boolean isOutVariableBackup(DeclarationStmt declarationStmt) { return declarationStmt.getVariablesDeclaration().getDeclInfos() .stream().anyMatch(vdi -> vdi.getName().equals(backupName)); }
counter++; final DeclarationStmt limiterDeclaration = new DeclarationStmt( new VariablesDeclaration(BasicType.INT, new VariableDeclInfo(limiterName, null,
private boolean blockAlreadyDeclaresVector() { // When we do multiple transformation passes, the same vectorization attempt might be applied // multiple times. If we would create a vector whose name is already declared in this block, // we bail out. return block.getStmts().stream().filter(item -> item instanceof DeclarationStmt) .map(item -> ((DeclarationStmt) item).getVariablesDeclaration().getDeclInfos()) .reduce(new ArrayList<>(), ListConcat::concatenate) .stream() .anyMatch(item -> item.getName().equals(mergeSet.getMergedName())); }
private List<Stmt> getInlinedStmts(FunctionDefinition functionDefinition, Optional<String> returnVariableName) { final List<Stmt> inlinedStmts = new ArrayList<>(); for (int i = 0; i < functionDefinition.getPrototype().getNumParameters(); i++) { ParameterDecl pd = functionDefinition.getPrototype().getParameter(i); inlinedStmts.add(new DeclarationStmt( new VariablesDeclaration( pd.getType().getWithoutQualifiers(), new VariableDeclInfo(pd.getName(), null, new ScalarInitializer(call.getArg(i).clone()))))); } for (Stmt stmt : functionDefinition.getBody().getStmts()) { if (stmt instanceof ReturnStmt) { if (((ReturnStmt) stmt).hasExpr()) { inlinedStmts.add(new ExprStmt( new BinaryExpr( new VariableIdentifierExpr(returnVariableName.get()), (((ReturnStmt) stmt).getExpr()), BinOp.ASSIGN))); } } else { inlinedStmts.add(stmt); } } return inlinedStmts; }