void LUTDetectionPass::do_procedure_definition(ProcedureDefinition* p) { procDef = p ; assert(procDef != NULL) ; OutputInformation("LUT Detection Pass begins") ; // LUTs can only exist in New Style Systems or Modules if (isLegacy(procDef)) { OutputInformation("Legacy code - No LUTs supported") ; return ; } // LUTs are defined to be arrays that are not parameter symbols SymbolTable* symTab = procDef->get_symbol_table() ; for (int i = 0 ; i < symTab->get_symbol_table_object_count() ; ++i) { SymbolTableObject* currentObject = symTab->get_symbol_table_object(i) ; VariableSymbol* currentVar = dynamic_cast<VariableSymbol*>(currentObject) ; ParameterSymbol* currentParam = dynamic_cast<ParameterSymbol*>(currentObject) ; if (currentVar != NULL && dynamic_cast<ArrayType*>(currentVar->get_type()->get_base_type()) != NULL && currentParam == NULL && currentVar->lookup_annote_by_name("ConstPropArray") == NULL) { // Found one! Let's mark it! currentObject->append_annote(create_brick_annote(theEnv, "LUT")) ; } } OutputInformation("LUT Detection Pass ends") ; }
void CopyPropagationPass2::Initialize() { // I don't want to delete any of the statements, but I must clear // out the list I was using to contain the statements if (!toBeRemoved.empty()) { while (toBeRemoved.begin() != toBeRemoved.end()) { toBeRemoved.pop_front() ; } } assert(procDef != NULL) ; InitializeMap() ; // Also, collect all of the feedback variables for later SymbolTable* procSymTable = procDef->get_symbol_table() ; assert(procSymTable != NULL) ; for (int i = 0 ; i < procSymTable->get_symbol_table_object_count() ; ++i) { if(dynamic_cast<VariableSymbol*>(procSymTable->get_symbol_table_object(i)) != NULL) { VariableSymbol* nextSymbol = dynamic_cast<VariableSymbol*>(procSymTable->get_symbol_table_object(i)); if (nextSymbol->lookup_annote_by_name("FeedbackVariable") != NULL) { feedbackVariables.push_back(nextSymbol) ; } } } }
void ExportPass::ConstructModuleSymbols() { CProcedureType* originalType = dynamic_cast<CProcedureType*>(originalProcedure->get_procedure_symbol()->get_type()) ; assert(originalType != NULL) ; // The original type takes and returns a struct. We need to change this // to a list of arguments. VoidType* newReturnType = create_void_type(theEnv, IInteger(0), 0) ; constructedType = create_c_procedure_type(theEnv, newReturnType, false, // has varargs true, // arguments_known 0, // bit alignment LString("ConstructedType")) ; StructType* returnType = dynamic_cast<StructType*>(originalType->get_result_type()) ; assert(returnType != NULL) ; SymbolTable* structSymTab = returnType->get_group_symbol_table() ; assert(structSymTab != NULL) ; for (int i = 0 ; i < structSymTab->get_symbol_table_object_count() ; ++i) { VariableSymbol* nextVariable = dynamic_cast<VariableSymbol*>(structSymTab->get_symbol_table_object(i)); if (nextVariable != NULL) { // Check to see if this is an output or not QualifiedType* cloneType ; DataType* cloneBase = dynamic_cast<DataType*>(nextVariable->get_type()->get_base_type()->deep_clone()) ; assert(cloneBase != NULL) ; cloneType = create_qualified_type(theEnv, cloneBase) ; if (nextVariable->lookup_annote_by_name("Output") != NULL) { cloneType->append_annote(create_brick_annote(theEnv, "Output")) ; // Why doesn't this stick around? } constructedType->append_argument(cloneType) ; } } constructedSymbol = create_procedure_symbol(theEnv, constructedType, originalProcedure->get_procedure_symbol()->get_name()) ; constructedSymbol->set_definition(NULL) ; }
void TransformUnrolledArraysPass::TransformNDIntoNMinusOneD(int N) { // Get all unique N-dimensional arrays CollectArrays(N) ; // For every array access that has a constant as one of its offsets, // we have to create a new array list<VariableSymbol*> arraysToRemove ; list<EquivalentReferences*>::iterator refIter = currentReferences.begin() ; while (refIter != currentReferences.end()) { VariableSymbol* originalSymbol = GetArrayVariable((*refIter)->original) ; // Lookup tables should not be transformed if (originalSymbol->lookup_annote_by_name("LUT") == NULL) { bool replaced = ReplaceNDReference(*refIter) ; if (replaced) { if (!InList(arraysToRemove, originalSymbol)) { arraysToRemove.push_back(originalSymbol) ; } } } ++refIter ; } // Remove all of the arrays that need to be removed list<VariableSymbol*>::iterator arrayIter = arraysToRemove.begin() ; while (arrayIter != arraysToRemove.end()) { procDef->get_symbol_table()->remove_symbol_table_object(*arrayIter) ; ++arrayIter ; } }
void ExportPass::ConstructSystemSymbols() { ProcedureSymbol* originalSymbol = originalProcedure->get_procedure_symbol() ; assert(originalSymbol != NULL) ; CProcedureType* originalType = dynamic_cast<CProcedureType*>(originalSymbol->get_type()) ; assert(originalType != NULL) ; constructedType = create_c_procedure_type(theEnv, dynamic_cast<DataType*>(originalType->get_result_type()->deep_clone()), false, // has variable arguments false, // arguments known 0) ; // bit alignment // The system has been written in one of two ways, either the old // way where there are no arguments, or the new way where everything // is put into the arguments. if (originalType->get_argument_count() > 0) { for (int i = 0 ; i < originalType->get_argument_count() ; ++i) { QualifiedType* originalArgument = originalType->get_argument(i) ; DataType* originalBase = originalArgument->get_base_type() ; DataType* constructedBase = CloneDataType(originalBase) ; QualifiedType* constructedArgument = create_qualified_type(theEnv, constructedBase) ; constructedType->append_argument(constructedArgument) ; // Go through the symbol table and find the parameter symbol // that matches the parameter number, and check to see if it // is an output or not... SymbolTable* symTab = originalProcedure->get_symbol_table() ; ParameterSymbol* correspondingSymbol = NULL ; for (int j = 0 ; j < symTab->get_symbol_table_object_count() ; ++j) { ParameterSymbol* currentSym = dynamic_cast<ParameterSymbol*>(symTab->get_symbol_table_object(j)) ; if (currentSym != NULL) { BrickAnnote* orderAnnote = dynamic_cast<BrickAnnote*>(currentSym->lookup_annote_by_name("ParameterOrder")) ; assert(orderAnnote != NULL) ; IntegerBrick* orderBrick = dynamic_cast<IntegerBrick*>(orderAnnote->get_brick(0)) ; assert(orderBrick != NULL) ; if (orderBrick->get_value().c_int() == i) { correspondingSymbol = currentSym ; break ; } } } if (correspondingSymbol != NULL) { if (correspondingSymbol->lookup_annote_by_name("OutputScalar") != NULL || correspondingSymbol->lookup_annote_by_name("OutputVariable") != NULL || correspondingSymbol->lookup_annote_by_name("OutputFifo") != NULL) { constructedArgument->append_annote(create_brick_annote(theEnv, "Output")) ; } } // if (dynamic_cast<ReferenceType*>(originalBase) != NULL) //{ // constructedArgument->append_annote(create_brick_annote(theEnv, // "Output")) ; // } } } else { SymbolTable* symTab = originalProcedure->get_symbol_table() ; assert(symTab != NULL) ; list<VariableSymbol*> inputScalars ; list<VariableSymbol*> inputFifos ; list<VariableSymbol*> outputScalars ; list<VariableSymbol*> outputFifos ; for (int i = 0 ; i < symTab->get_symbol_table_object_count() ; ++i) { VariableSymbol* currentVar = dynamic_cast<VariableSymbol*>(symTab->get_symbol_table_object(i)) ; if (currentVar != NULL && currentVar->lookup_annote_by_name("InputScalar") != NULL && currentVar->lookup_annote_by_name("TemporalFeedback") == NULL && currentVar->lookup_annote_by_name("NormalFeedback") == NULL && currentVar->lookup_annote_by_name("DebugRegister") == NULL) { inputScalars.push_back(currentVar) ; } if (currentVar != NULL && currentVar->lookup_annote_by_name("InputFifo") != NULL) { inputFifos.push_back(currentVar) ; } if (currentVar != NULL && currentVar->lookup_annote_by_name("OutputVariable") != NULL && currentVar->lookup_annote_by_name("Dummy") == NULL && currentVar->lookup_annote_by_name("FeedbackSource") == NULL) { outputScalars.push_back(currentVar) ; } if (currentVar != NULL && currentVar->lookup_annote_by_name("OutputFifo") != NULL) { outputFifos.push_back(currentVar) ; } } // Add the types of the input scalars, then the input fifos, // then the output scalars, and finally the output fifos. list<VariableSymbol*>::iterator varIter = inputScalars.begin() ; while (varIter != inputScalars.end()) { QualifiedType* originalQual = (*varIter)->get_type() ; assert(originalQual != NULL) ; DataType* originalBase = originalQual->get_base_type() ; assert(originalBase != NULL) ; DataType* constructedBase = dynamic_cast<DataType*>(originalBase->deep_clone()) ; QualifiedType* constructedQual = create_qualified_type(theEnv, constructedBase) ; constructedType->append_argument(constructedQual) ; ++varIter ; } varIter = inputFifos.begin() ; while (varIter != inputFifos.end()) { QualifiedType* originalQual = (*varIter)->get_type() ; assert(originalQual != NULL) ; DataType* originalBase = originalQual->get_base_type() ; assert(originalBase != NULL) ; // Fifos will have pointer types or reference types. A // simple deep clone will not suffice, I need to build up a // new type from the bottom up. DataType* constructedBase = CloneDataType(originalBase) ; assert(constructedBase != NULL) ; QualifiedType* constructedQual = create_qualified_type(theEnv, constructedBase) ; assert(constructedBase != NULL) ; assert(constructedType != NULL) ; constructedType->append_argument(constructedQual) ; ++varIter ; } varIter = outputScalars.begin() ; while (varIter != outputScalars.end()) { QualifiedType* originalQual = (*varIter)->get_type() ; DataType* originalBase = originalQual->get_base_type() ; DataType* constructedBase = CloneDataType(originalBase) ; QualifiedType* constructedQual = create_qualified_type(theEnv, constructedBase) ; constructedQual->append_annote(create_brick_annote(theEnv, "Output")) ; constructedType->append_argument(constructedQual) ; ++varIter ; } varIter = outputFifos.begin() ; while (varIter != outputFifos.end()) { QualifiedType* originalQual = (*varIter)->get_type() ; assert(originalQual != NULL) ; DataType* originalBase = originalQual->get_base_type() ; assert(originalBase != NULL) ; DataType* constructedBase = CloneDataType(originalBase) ; assert(constructedBase != NULL) ; QualifiedType* constructedQual = create_qualified_type(theEnv, constructedBase) ; assert(constructedQual != NULL) ; constructedQual->append_annote(create_brick_annote(theEnv, "Output")) ; assert(constructedType != NULL) ; constructedType->append_argument(constructedQual) ; ++varIter ; } } constructedSymbol = create_procedure_symbol(theEnv, constructedType, originalProcedure->get_procedure_symbol()->get_name()) ; }