// This function is responsible for creating the procedure symbol and // adding it to the appropriate symbol table. ProcedureSymbol* IfConversionPass2::CreateBoolSym(QualifiedType* qualType) { assert(procDef != NULL) ; assert(theEnv != NULL) ; assert(tb != NULL) ; // First, create the procedure type CProcedureType* cProcType = create_c_procedure_type(theEnv, qualType->get_base_type(), false, // has varargs true, // arguments known 0, // bit alignment, TempName("ROCCC_boolsel_type")) ; // Next, add all of the arguments. These should be two arguments with // the same type as the destination variable and one boolean argument. cProcType->append_argument(qualType) ; cProcType->append_argument(qualType) ; cProcType->append_argument(create_qualified_type(theEnv, tb->get_boolean_type())) ; // Now create the procedure symbol with this type and add it to // the external symbol table. ProcedureSymbol* procSym = create_procedure_symbol(theEnv, cProcType, TempName("ROCCC_boolsel")) ; procDef->get_symbol_table()->append_symbol_table_object(cProcType) ; procDef->get_symbol_table()->append_symbol_table_object(procSym) ; return procSym ; }
// This is a vastly simpler way to setup annotations that doesn't worry // or assume that all feedbacks come from a single store variable statement void SolveFeedbackVariablesPass3::SetupAnnotations() { assert(theEnv != NULL) ; // Go through the list of all feedback instances we have discovered. list<PossibleFeedbackPair>::iterator feedbackIter = actualFeedbacks.begin(); while (feedbackIter != actualFeedbacks.end()) { // For every feedback, we need to create a two variables // The first one is a replacement for the original use. // The second one is the variable used for feedback. LString replacementName = (*feedbackIter).varSym->get_name() ; replacementName = replacementName + "_replacementTmp" ; VariableSymbol* replacementVariable = create_variable_symbol(theEnv, (*feedbackIter).varSym->get_type(), TempName(replacementName)) ; procDef->get_symbol_table()->append_symbol_table_object(replacementVariable); VariableSymbol* feedbackVariable = create_variable_symbol(theEnv, (*feedbackIter).varSym->get_type(), TempName(LString("feedbackTmp"))) ; procDef->get_symbol_table()->append_symbol_table_object(feedbackVariable) ; // Replace the use with this new feedback variable (*feedbackIter).use->set_source(replacementVariable) ; // I am looking for the variable that originally defined me and // the variable that will replace me. Statement* definition = (*feedbackIter).definition ; VariableSymbol* definitionVariable = GetDefinedVariable(definition, (*feedbackIter).definitionLocation) ; assert(definitionVariable != NULL) ; // Finally, annotate the feedback variable SetupAnnotations(feedbackVariable, definitionVariable, replacementVariable) ; replacementVariable->append_annote(create_brick_annote(theEnv, "NonInputScalar")); ++feedbackIter ; } }
void FThreadSafeStaticStatBase::DoSetup(const char* InStatName, const TCHAR* InStatDesc, const char* InGroupName, const char* InGroupCategory, const TCHAR* InGroupDesc, bool bDefaultEnable, bool bShouldClearEveryFrame, EStatDataType::Type InStatType, bool bCycleStat, FPlatformMemory::EMemoryCounterRegion InMemoryRegion) const { FName TempName(InStatName); // send meta data, we don't use normal messages because the stats thread might not be running yet FStartupMessages::Get().AddMetadata(TempName, InStatDesc, InGroupName, InGroupCategory, InGroupDesc, bShouldClearEveryFrame, InStatType, bCycleStat, InMemoryRegion); TStatIdData const* LocalHighPerformanceEnable(IStatGroupEnableManager::Get().GetHighPerformanceEnableForStat(FName(InStatName), InGroupName, InGroupCategory, bDefaultEnable, bShouldClearEveryFrame, InStatType, InStatDesc, bCycleStat, InMemoryRegion).GetRawPointer()); TStatIdData const* OldHighPerformanceEnable = (TStatIdData const*)FPlatformAtomics::InterlockedCompareExchangePointer((void**)&HighPerformanceEnable, (void*)LocalHighPerformanceEnable, NULL); check(!OldHighPerformanceEnable || HighPerformanceEnable == OldHighPerformanceEnable); // we are assigned two different groups? }
void DotLock::Lock(const char *lockfile) { Unlock(); unsigned nseconds=GetLockSleep(); unsigned timeout=GetLockTimeout(); const char *q, *r; refresh_interval=GetLockRefresh(); for (q=r=lockfile; *q; q++) if (*q == '/') r=q+1; q= TempName( r-lockfile ? lockfile:"", r-lockfile); struct stat last_stat; int has_last_stat=0; AlarmTimer stat_timer; memset(&last_stat, 0, sizeof(last_stat)); while (attemptlock(q, lockfile)) { struct stat current_stat; if (stat(lockfile, ¤t_stat) == 0) { if (!has_last_stat || current_stat.st_ino != last_stat.st_ino || current_stat.st_ctime != last_stat.st_ctime || current_stat.st_atime != last_stat.st_atime) { has_last_stat=1; last_stat=current_stat; stat_timer.Set(timeout); } else if (stat_timer.Expired()) { unlink(lockfile); } } AlarmSleep sleep(nseconds); } if (refresh_interval >= 10) refresh.Set(refresh_interval); }
void CleanupRedundantVotes::ProcessCall(CallStatement* c) { assert(c != NULL) ; SymbolAddressExpression* symAddress = dynamic_cast<SymbolAddressExpression*>(c->get_callee_address()) ; assert(symAddress != NULL) ; Symbol* sym = symAddress->get_addressed_symbol() ; assert(sym != NULL) ; if (sym->get_name() == LString("ROCCCTripleVote") || sym->get_name() == LString("ROCCCDoubleVote") ) { LoadVariableExpression* errorVariableExpression = dynamic_cast<LoadVariableExpression*>(c->get_argument(0)) ; assert(errorVariableExpression != NULL) ; VariableSymbol* currentError = errorVariableExpression->get_source() ; assert(currentError != NULL) ; if (InList(currentError)) { // Create a new variable VariableSymbol* errorDupe = create_variable_symbol(theEnv, currentError->get_type(), TempName(LString("UnrolledRedundantError"))) ; errorDupe->append_annote(create_brick_annote(theEnv, "DebugRegister")) ; procDef->get_symbol_table()->append_symbol_table_object(errorDupe) ; usedVariables.push_back(errorDupe) ; errorVariableExpression->set_source(errorDupe) ; } else { usedVariables.push_back(currentError) ; } } }
void ScalarReplacementPass2::CollectArrayReferences() { assert(procDef != NULL) ; list<ArrayReferenceExpression*>* allRefs = collect_objects<ArrayReferenceExpression>(procDef->get_body()) ; list<ArrayReferenceExpression*>::iterator refIter = allRefs->begin() ; while (refIter != allRefs->end()) { // If this is not the topmost array reference, skip it. if (dynamic_cast<ArrayReferenceExpression*>((*refIter)->get_parent()) != NULL) { ++refIter ; continue ; } // Also, skip lookup tables if (IsLookupTable(GetArrayVariable(*refIter))) { ++refIter ; continue ; } bool found = false ; std::pair<Expression*, VariableSymbol*> toAdd ; list<std::pair<Expression*, VariableSymbol*> >::iterator identIter = Identified.begin() ; while (identIter != Identified.end()) { if (EquivalentExpressions((*identIter).first, *refIter)) { found = true ; toAdd = (*identIter) ; break ; } ++identIter ; } if (!found) { VariableSymbol* replacement = create_variable_symbol(theEnv, GetQualifiedTypeOfElement(*refIter), TempName(LString("suifTmp"))) ; replacement->append_annote(create_brick_annote(theEnv, "ScalarReplacedVariable")) ; procDef->get_symbol_table()->append_symbol_table_object(replacement) ; toAdd.first = (*refIter) ; toAdd.second = replacement ; Identified.push_back(toAdd) ; } if (dynamic_cast<LoadExpression*>((*refIter)->get_parent()) != NULL) { found = false ; identIter = IdentifiedLoads.begin() ; while (identIter != IdentifiedLoads.end()) { if (EquivalentExpressions((*identIter).first, *refIter)) { found = true ; break ; } ++identIter ; } if (!found) { IdentifiedLoads.push_back(toAdd) ; } } else if (dynamic_cast<StoreStatement*>((*refIter)->get_parent()) != NULL) { found = false ; identIter = IdentifiedStores.begin() ; while (identIter != IdentifiedStores.end()) { if (EquivalentExpressions((*identIter).first, *refIter)) { found = true ; break ; } ++identIter ; } if (!found) { IdentifiedStores.push_back(toAdd) ; } } else { assert(0 && "Improperly formatted array reference!") ; } ++refIter ; } delete allRefs ; }
// All of the array references expressions in the passed in the struct are // equivalent, so we can determine types of the original and use that // to create a new expression with which to replace everything. bool TransformUnrolledArraysPass::ReplaceNDReference(EquivalentReferences* a) { assert(a != NULL) ; assert(a->original != NULL) ; // Check to see if the reference at this stage is a constant or not IntConstant* constantIndex = dynamic_cast<IntConstant*>(a->original->get_index()) ; if (constantIndex == NULL) { // There was no replacement made return false ; } Expression* baseAddress = a->original->get_base_array_address() ; assert(baseAddress != NULL) ; assert(constantIndex != NULL) ; // Create a replacement expression for this value. This will either // be another array reference expression or a single variable. Expression* replacementExp = NULL ; // QualifiedType* elementType = GetQualifiedTypeOfElement(a->original) ; VariableSymbol* originalSymbol = GetArrayVariable(a->original) ; assert(originalSymbol != NULL) ; LString replacementName = GetReplacementName(originalSymbol->get_name(), constantIndex->get_value().c_int()) ; int dimensionality = GetDimensionality(a->original) ; QualifiedType* elementType = originalSymbol->get_type() ; while (dynamic_cast<ArrayType*>(elementType->get_base_type()) != NULL) { elementType = dynamic_cast<ArrayType*>(elementType->get_base_type())->get_element_type() ; } // There is a special case for one dimensional arrays as opposed to all // other dimensional arrays. It only should happen if we are truly // replacing an array with a one dimensional array. if (dimensionality == 1 && dynamic_cast<ArrayReferenceExpression*>(a->original->get_parent())==NULL) { VariableSymbol* replacementVar = create_variable_symbol(theEnv, GetQualifiedTypeOfElement(a->original), TempName(replacementName)) ; procDef->get_symbol_table()->append_symbol_table_object(replacementVar) ; replacementExp = create_load_variable_expression(theEnv, elementType->get_base_type(), replacementVar) ; } else { // Create a new array with one less dimension. This requires a new // array type. ArrayType* varType = dynamic_cast<ArrayType*>(originalSymbol->get_type()->get_base_type()) ; assert(varType != NULL) ; ArrayType* replacementArrayType = create_array_type(theEnv, varType->get_element_type()->get_base_type()->get_bit_size(), 0, // bit alignment OneLessDimension(originalSymbol->get_type(), dimensionality), dynamic_cast<Expression*>(varType->get_lower_bound()->deep_clone()), dynamic_cast<Expression*>(varType->get_upper_bound()->deep_clone()), TempName(varType->get_name())) ; procDef->get_symbol_table()->append_symbol_table_object(replacementArrayType) ; VariableSymbol* replacementArraySymbol = create_variable_symbol(theEnv, create_qualified_type(theEnv, replacementArrayType, TempName(LString("qualType"))), TempName(replacementName)) ; procDef->get_symbol_table()->append_symbol_table_object(replacementArraySymbol) ; // Create a new symbol address expression for this variable symbol SymbolAddressExpression* replacementAddrExp = create_symbol_address_expression(theEnv, replacementArrayType, replacementArraySymbol) ; // Now, replace the symbol address expression in the base // array address with this symbol. ReplaceSymbol(a->original, replacementAddrExp) ; // And replace this reference with the base array address. replacementExp = a->original->get_base_array_address() ; a->original->set_base_array_address(NULL) ; replacementExp->set_parent(NULL) ; } // Replace all of the equivalent expressions with the newly generated // replacement expression. assert(replacementExp != NULL) ; a->original->get_parent()->replace(a->original, replacementExp) ; // ReplaceChildExpression(a->original->get_parent(), // a->original, // replacementExp) ; list<ArrayReferenceExpression*>::iterator equivIter = a->allEquivalent.begin() ; while (equivIter != a->allEquivalent.end()) { (*equivIter)->get_parent()->replace((*equivIter), dynamic_cast<Expression*>(replacementExp->deep_clone())) ; // ReplaceChildExpression((*equivIter)->get_parent(), // (*equivIter), // dynamic_cast<Expression*>(replacementExp->deep_clone())) ; ++equivIter ; } return true ; }
TempFile::TempFile(void) : File(TempName(), TruncateReadWrite) { }
void TransformSystemsToModules::Transform() { assert(procDef != NULL) ; // Collect all the input scalars and output scalars list<VariableSymbol*> ports ; SymbolTable* procSymTab = procDef->get_symbol_table() ; bool foundInputs = false ; bool foundOutputs = false ; for (int i = 0 ; i < procSymTab->get_symbol_table_object_count() ; ++i) { SymbolTableObject* nextObject = procSymTab->get_symbol_table_object(i) ; if (nextObject->lookup_annote_by_name("InputScalar") != NULL) { VariableSymbol* toConvert = dynamic_cast<VariableSymbol*>(nextObject) ; assert(toConvert != NULL) ; LString inputName = toConvert->get_name() ; inputName = inputName + "_in" ; toConvert->set_name(inputName) ; ports.push_back(toConvert) ; foundInputs = true ; } if (nextObject->lookup_annote_by_name("OutputVariable") != NULL) { VariableSymbol* toConvert = dynamic_cast<VariableSymbol*>(nextObject) ; assert(toConvert != NULL) ; LString outputName = toConvert->get_name() ; outputName = outputName + "_out" ; toConvert->set_name(outputName) ; ports.push_back(toConvert) ; foundOutputs = true ; } } assert(foundInputs && "Could not identify inputs. Were they removed via optimizations?") ; assert(foundOutputs && "Could not identify outputs. Were they removed via optimizations?") ; // Determine the bit size and add everything to a new symbol table int bitSize = 0 ; GroupSymbolTable* structTable = create_group_symbol_table(theEnv, procDef->get_symbol_table()) ; std::map<VariableSymbol*, FieldSymbol*> replacementFields ; bool portsRemoved = false ; // If this was actually a new style module, we should make sure to // put these in the correct order. if (isModule(procDef)) { // Go through the original symbol table and remove any parameter // symbols that originally existed SymbolTable* originalSymTab = procDef->get_symbol_table() ; Iter<SymbolTableObject*> originalIter = originalSymTab->get_symbol_table_object_iterator() ; while (originalIter.is_valid()) { SymbolTableObject* currentObj = originalIter.current() ; originalIter.next() ; if (dynamic_cast<ParameterSymbol*>(currentObj) != NULL) { originalSymTab->remove_symbol_table_object(currentObj) ; } } portsRemoved = true ; // Sort the variable symbols in parameter order. This is just an // insertion sort, so it could be done faster. list<VariableSymbol*> sortedPorts ; for (int i = 0 ; i < ports.size() ; ++i) { list<VariableSymbol*>::iterator portIter = ports.begin() ; while (portIter != ports.end()) { BrickAnnote* orderAnnote = dynamic_cast<BrickAnnote*>((*portIter)-> lookup_annote_by_name("ParameterOrder")) ; if (orderAnnote == NULL) { ++portIter ; continue ; } IntegerBrick* orderBrick = dynamic_cast<IntegerBrick*>(orderAnnote->get_brick(0)) ; assert(orderBrick != NULL) ; if (orderBrick->get_value().c_int() == i) { sortedPorts.push_back(*portIter) ; break ; } ++portIter ; } } if (sortedPorts.size() != ports.size()) { OutputWarning("Warning! Analysis detected some input scalars not in" " the parameter list") ; } // Replace ports with sortedPorts ports = sortedPorts ; } list<VariableSymbol*>::iterator portIter = ports.begin() ; while (portIter != ports.end()) { bitSize += (*portIter)->get_type()->get_base_type()->get_bit_size().c_int() ; LString dupeName = (*portIter)->get_name() ; // Create offset expression: IntConstant* offset = create_int_constant(theEnv, create_data_type(theEnv, IInteger(32), 0), IInteger(bitSize)) ; QualifiedType* dupeType = (*portIter)->get_type() ; // Deal with the case where reference types were passed in ReferenceType* refType = dynamic_cast<ReferenceType*>(dupeType->get_base_type()) ; while (refType != NULL) { dupeType = dynamic_cast<QualifiedType*>(refType->get_reference_type()) ; assert(dupeType != NULL) ; refType = dynamic_cast<ReferenceType*>(dupeType->get_base_type()) ; } // Create a new variable symbol clone FieldSymbol* dupe = create_field_symbol(theEnv, dupeType, offset, dupeName) ; structTable->append_symbol_table_object(dupe) ; // Make the connection with the duplicated symbol replacementFields[(*portIter)] = dupe ; // Remove the original variable symbol from the procedure definition // symbol table. if (!portsRemoved) { procDef->get_symbol_table()->remove_symbol_table_object(*portIter) ; } ++portIter ; } assert(bitSize != 0); StructType* moduleStruct = create_struct_type(theEnv, IInteger(bitSize), 0, // bit_alignment TempName(procDef->get_procedure_symbol()->get_name()), 0, // is_complete structTable) ; Iter<FileBlock*> fBlocks = theEnv->get_file_set_block()->get_file_block_iterator() ; assert(fBlocks.is_valid()) ; (fBlocks.current())->get_symbol_table()->append_symbol_table_object(moduleStruct) ; // This is commented out because it is in the file state block //procDef->get_symbol_table()->append_symbol_table_object(moduleStruct) ; QualifiedType* qualifiedModuleStruct = create_qualified_type(theEnv, moduleStruct, TempName(LString("qualifiedModuleStruct"))) ; procDef->get_symbol_table()->append_symbol_table_object(qualifiedModuleStruct) ; // Create an instance of this type and add it to the symbol table. ParameterSymbol* structInstance = create_parameter_symbol(theEnv, qualifiedModuleStruct, TempName(LString("structInstance"))) ; procDef->get_symbol_table()->append_symbol_table_object(structInstance) ; // Now, set up the procedure symbol to take the struct and return the // struct. assert(procDef != NULL) ; ProcedureSymbol* procSym = procDef->get_procedure_symbol() ; assert(procSym != NULL) ; ProcedureType* procType = procSym->get_type() ; assert(procType != NULL) ; CProcedureType* cProcType = dynamic_cast<CProcedureType*>(procType) ; assert(cProcType != NULL) ; // Instead of appending the struct argument, we need to replace all of the // arguments with the struct. while (cProcType->get_argument_count() > 0) { cProcType->remove_argument(0) ; } cProcType->set_result_type(moduleStruct) ; cProcType->append_argument(qualifiedModuleStruct) ; // Now go through all load variable expressions and replace them all with // field symbol values if appropriate list<LoadVariableExpression*>* allLoads = collect_objects<LoadVariableExpression>(procDef->get_body()) ; list<LoadVariableExpression*>::iterator loadIter = allLoads->begin() ; while (loadIter != allLoads->end()) { VariableSymbol* currentVariable = (*loadIter)->get_source() ; if (replacementFields.find(currentVariable) != replacementFields.end()) { (*loadIter)->set_source(replacementFields[currentVariable]) ; } ++loadIter ; } delete allLoads ; // Also replace all of the definitions with the field symbol list<StoreVariableStatement*>* allStoreVars = collect_objects<StoreVariableStatement>(procDef->get_body()) ; list<StoreVariableStatement*>::iterator storeVarIter = allStoreVars->begin(); while (storeVarIter != allStoreVars->end()) { VariableSymbol* currentDest = (*storeVarIter)->get_destination() ; if (replacementFields.find(currentDest) != replacementFields.end()) { (*storeVarIter)->set_destination(replacementFields[currentDest]) ; } ++storeVarIter ; } delete allStoreVars ; list<SymbolAddressExpression*>* allSymAddr = collect_objects<SymbolAddressExpression>(procDef->get_body()) ; list<SymbolAddressExpression*>::iterator symAddrIter = allSymAddr->begin() ; while (symAddrIter != allSymAddr->end()) { VariableSymbol* currentVar = dynamic_cast<VariableSymbol*>((*symAddrIter)->get_addressed_symbol()) ; if (currentVar != NULL && replacementFields.find(currentVar) != replacementFields.end()) { (*symAddrIter)->set_addressed_symbol(replacementFields[currentVar]) ; } ++symAddrIter ; } delete allSymAddr ; // One final for bool selects list<CallStatement*>* allCalls = collect_objects<CallStatement>(procDef->get_body()) ; list<CallStatement*>::iterator callIter = allCalls->begin() ; while(callIter != allCalls->end()) { VariableSymbol* currentVar = (*callIter)->get_destination() ; if (currentVar != NULL && replacementFields.find(currentVar) != replacementFields.end()) { (*callIter)->set_destination(replacementFields[currentVar]) ; } ++callIter ; } delete allCalls ; }