bool IfConversionPass2::ConvertArrayStoreIf(IfStatement* toConvert) { Statement* thenPart = Denormalize(toConvert->get_then_part()) ; Statement* elsePart = Denormalize(toConvert->get_else_part()) ; StoreStatement* thenStore = dynamic_cast<StoreStatement*>(thenPart) ; StoreStatement* elseStore = dynamic_cast<StoreStatement*>(elsePart) ; assert(thenStore != NULL) ; assert(elseStore != NULL) ; ArrayReferenceExpression* thenRef = dynamic_cast<ArrayReferenceExpression*>(thenStore->get_destination_address()) ; ArrayReferenceExpression* elseRef = dynamic_cast<ArrayReferenceExpression*>(elseStore->get_destination_address()) ; assert(thenRef != NULL) ; assert(elseRef != NULL) ; // Verify that these array references are to the same location. if (!EquivalentExpressions(thenRef, elseRef)) { return false ; } // This will hopefully be scalar replaced later, but for now we just need // to do something... // What I need is the qualified element type of the array. QualifiedType* qualType = create_qualified_type(theEnv, thenRef->get_result_type()) ; StoreStatement* replacement = CreateBoolCall(thenRef) ; // Append the arguments to the call expression CallExpression* callExpr = dynamic_cast<CallExpression*>(replacement->get_value()) ; assert(callExpr != NULL) ; Expression* thenStoreValue = thenStore->get_value() ; thenStore->set_value(NULL) ; callExpr->append_argument(thenStoreValue) ; Expression* elseStoreValue = elseStore->get_value() ; elseStore->set_value(NULL) ; callExpr->append_argument(elseStoreValue) ; Expression* condition = toConvert->get_condition() ; toConvert->set_condition(NULL) ; callExpr->append_argument(condition) ; // Replace the if toConvert->get_parent()->replace(toConvert, replacement) ; return true ; }
bool IfConversionPass2::ConvertStructStoreIf(IfStatement* toConvert) { Statement* thenPart = Denormalize(toConvert->get_then_part()) ; Statement* elsePart = Denormalize(toConvert->get_else_part()) ; StoreStatement* thenStore = dynamic_cast<StoreStatement*>(thenPart) ; StoreStatement* elseStore = dynamic_cast<StoreStatement*>(elsePart) ; assert(thenStore != NULL) ; assert(elseStore != NULL) ; FieldAccessExpression* thenField = dynamic_cast<FieldAccessExpression*>(thenStore->get_destination_address()); FieldAccessExpression* elseField = dynamic_cast<FieldAccessExpression*>(elseStore->get_destination_address()); assert(thenField != NULL) ; assert(elseField != NULL) ; // Check to make sure that each field access is accessing the same field if (thenField->get_field() != elseField->get_field()) { return false ; } CallStatement* replacement = CreateBoolCall(thenField->get_field()) ; // Append the arguments Expression* thenStoreValue = thenStore->get_value() ; thenStore->set_value(NULL) ; replacement->append_argument(thenStoreValue) ; Expression* elseStoreValue = elseStore->get_value() ; elseStore->set_value(NULL) ; replacement->append_argument(elseStoreValue) ; Expression* condition = toConvert->get_condition() ; toConvert->set_condition(NULL) ; replacement->append_argument(condition) ; toConvert->get_parent()->replace(toConvert, replacement) ; return true ; }