@Override public Type getWithoutQualifiers() { return targetType.getWithoutQualifiers(); }
private boolean isUsedStructType(Type type) { if (!(type.getWithoutQualifiers() instanceof StructDefinitionType)) { return false; } final StructDefinitionType sdt = (StructDefinitionType) type.getWithoutQualifiers(); return !unusedStructs.contains(sdt); }
public InlineStructifiedFieldReductionOpportunity(StructDefinitionType outerStruct, StructDefinitionType innerStruct, String fieldToInline, TranslationUnit tu, VisitationDepth depth) { super(depth); this.outerStruct = outerStruct; this.innerStruct = innerStruct; this.fieldToInline = fieldToInline; this.tu = tu; assert outerStruct != innerStruct; assert fieldToInline.startsWith(Constants.STRUCTIFICATION_FIELD_PREFIX); assert outerStruct.getFieldType(fieldToInline).getWithoutQualifiers() instanceof StructNameType : "Can only inline a struct field of a struct"; }
boolean typeRefersToUniform(Type type) { if (type.hasQualifier(TypeQualifier.UNIFORM)) { return true; } if (!(type.getWithoutQualifiers() instanceof ArrayType)) { return false; } return typeRefersToUniform(((ArrayType) type.getWithoutQualifiers()).getBaseType()); }
public MergeSet(ScopeEntry entry) { this.elementType = ((BasicType) entry.getType().getWithoutQualifiers()).getElementType(); this.entries = new ArrayList<>(); entries.add(entry); }
@Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { if (variablesDeclaration.getBaseType().getWithoutQualifiers() instanceof StructDefinitionType) { final StructDefinitionType sdt = (StructDefinitionType) variablesDeclaration.getBaseType().getWithoutQualifiers(); if (sdt.hasStructNameType()) { // Initially, assume it is unused unusedStructs.add(sdt); } } super.visitVariablesDeclaration(variablesDeclaration); }
private int getWidth(ScopeEntry entry) { return ((BasicType) entry.getType().getWithoutQualifiers()).getNumElements(); }
private boolean referencesArray(Expr rhs) { return getReferencedVariables(rhs).stream() .anyMatch(item -> scopeOfStmt.lookupType(item) != null && scopeOfStmt.lookupType(item).getWithoutQualifiers() instanceof ArrayType); }
public boolean canAccept(ScopeEntry entry) { BasicType basicType = (BasicType) entry.getType().getWithoutQualifiers(); if (!(basicType.getElementType().equals(elementType))) { return false; } if (entries.stream() .anyMatch(x -> x.getVariablesDeclaration() == entry.getVariablesDeclaration())) { return false; } return currentWidth() + basicType.getNumElements() <= MAX_WIDTH; }
private void findFoldAddZeroOpportunities(IAstNode parent, Expr child, Expr thisHandSide, Expr thatHandSide) { if (isZeroFloat(thisHandSide)) { addReplaceWithExpr(parent, child, thatHandSide); } final Type childType = typer.lookupType(child); final Type thatHandSideType = typer.lookupType(thatHandSide); if (childType != null && thatHandSideType != null && childType.getWithoutQualifiers().equals(thatHandSideType.getWithoutQualifiers())) { if (isZeroFloatVecOrSquareMat(thisHandSide)) { addReplaceWithExpr(parent, child, thatHandSide); } } }
private void findFoldSomethingSubZeroOpportunities(IAstNode parent, Expr child, Expr lhs, Expr rhs) { if (isZeroFloat(rhs)) { addReplaceWithExpr(parent, child, lhs); } final Type childType = typer.lookupType(child); final Type lhsType = typer.lookupType(lhs); if (childType != null && lhsType != null && childType.getWithoutQualifiers().equals(lhsType.getWithoutQualifiers())) { if (isZeroFloatVecOrSquareMat(rhs)) { addReplaceWithExpr(parent, child, lhs); } } }
private void findFoldMulIdentityOpportunities(IAstNode parent, Expr child, Expr thisHandSide, Expr thatHandSide) { if (isOneFloat(thisHandSide)) { addReplaceWithExpr(parent, child, thatHandSide); } final Type childType = typer.lookupType(child); final Type thisHandSideType = typer.lookupType(thisHandSide); if (childType != null && thisHandSideType != null && childType.getWithoutQualifiers().equals(thisHandSideType.getWithoutQualifiers())) { if (isOneFloatVec(thisHandSide) || isIdentityMatrix(thisHandSide)) { addReplaceWithExpr(parent, child, thatHandSide); } } }
@Override public void visitDeclarationStmt(DeclarationStmt declarationStmt) { super.visitDeclarationStmt(declarationStmt); if (!(declarationStmt.getVariablesDeclaration().getBaseType() .getWithoutQualifiers() instanceof StructNameType)) { return; } getOpportunitiesForStruct((StructNameType) declarationStmt.getVariablesDeclaration() .getBaseType().getWithoutQualifiers(), getVistitationDepth()); }
private StructifiedVariableInfo findOriginalVariableInfo() { return findOriginalVariableInfo( (StructNameType) declaration.getVariablesDeclaration().getBaseType() .getWithoutQualifiers(), Optional.ofNullable((ScalarInitializer) declaration.getVariablesDeclaration() .getDeclInfo(0).getInitializer())) .get(); }
@Override public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); Type type = enclosingScope.lookupType(variableIdentifierExpr.getName()); if (type != null && type.getWithoutQualifiers() instanceof ArrayType) { predicateHolds(); } }
/** * Yields the basic type that the component we are pulling out should have. * @return The basic type of the component. */ public BasicType getComponentType() { return BasicType.makeVectorType( ((BasicType) vectorVariablesDeclaration.getBaseType().getWithoutQualifiers()) .getElementType(), componentData.getWidth()); }
@Override public void visitDeclarationStmt(DeclarationStmt declarationStmt) { super.visitDeclarationStmt(declarationStmt); if (!Util.isStructifiedDeclaration(declarationStmt)) { return; } final StructNameType structType = (StructNameType) declarationStmt.getVariablesDeclaration().getBaseType() .getWithoutQualifiers(); findInliningOpportunities(structType); }
private Type stripQualifiers(Type type) { // TODO: when implementing this the only compound type I considered was ArrayType. if (type instanceof QualifiedType) { return stripQualifiers(type.getWithoutQualifiers()); } if (type instanceof ArrayType) { return new ArrayType(stripQualifiers(((ArrayType) type).getBaseType()), ((ArrayType) type).getArrayInfo()); } return type; }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { super.visitFunctionPrototype(functionPrototype); for (int i = 0; i < functionPrototype.getNumParameters(); i++) { if (functionPrototype.getParameter(i).getType().getWithoutQualifiers() .equals(declaration.getVariablesDeclaration().getBaseType().getWithoutQualifiers())) { assert declaration.getVariablesDeclaration().getDeclInfo(0).getName() .equals(functionPrototype.getParameter(i).getName()); functionPrototype.getParameter(i).setName(originalVariableInfo.getName()); functionPrototype.getParameter(i).setType(originalVariableInfo.getType()); } } }
private void addSpecialDeclarations() { if (fd.getPrototype().getReturnType().getWithoutQualifiers() != VoidType.VOID) { fd.getBody().insertStmt(0, new DeclarationStmt( new VariablesDeclaration(fd.getPrototype().getReturnType().getWithoutQualifiers(), new VariableDeclInfo(makeReturnValueName(), null, null)))); fd.getBody().addStmt(new ReturnStmt(makeReturnValue())); } fd.getBody().insertStmt(0, new DeclarationStmt( new VariablesDeclaration(BasicType.BOOL, new VariableDeclInfo(makeHasReturnedName(), null, new ScalarInitializer(BoolConstantExpr.FALSE))))); }