int findgraphic( int argc, char **argv ) { int graphic = strtoul( argv[1], NULL, 0 ); cout << "Searching map for statics with graphic=" << hexint(graphic) << endl; open_uo_data_files(); read_uo_data(); for( u16 y = 0; y < 4095; ++y ) { for( u16 x = 0; x < 6143; ++x ) { StaticList statics; readallstatics( statics, x, y ); for( unsigned i = 0; i < statics.size(); ++i ) { StaticRec& rec = statics[i]; if (rec.graphic == graphic) { cout << x << "," << y << "," << rec.z << endl; } } } } clear_tiledata(); return 0; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Expression ValueNumber::CreatePhiExpression(PhiInstr* phiInstr) { // Sort the incoming values based on their block. This allows // 'phi {a, B1}, {b, B2}' and 'phi {b, B2}, {a, B1}' to be considered the same. Expression expr(phiInstr->GetOpcode()); StaticList<int, 16> valNumbs; StaticList<Block*, 16> blocks; int count = phiInstr->OperandCount(); for(int i = 0; i < count; i++) { valNumbs.Add(GetValueNumber(phiInstr->GetOperand(i))); blocks.Add(phiInstr->GetOperandBlock(i)->Target()); } // We use a simple selection sort, because 'phi' usually has few operands. for(int i = 0; i < count; i++) { for(int j = i + 1; j < count; j++) { if(blocks[i] > blocks[j]) { std::swap(valNumbs[i], valNumbs[j]); std::swap(blocks[i], blocks[j]); } } } for(int i = 0; i < count; i++) { expr.AddOperand(valNumbs[i]); } return expr; }
void projectGenerator::buildInterDependencies( const string & sProjectName, StaticList & vLibs ) { //Get the lib dependencies from the configure file if( sProjectName.find( "lib" ) == 0 ) { //get the dependency list from configure string sLibName = sProjectName.substr( 3 ) + "_deps"; vector<string> vLibDeps; if( m_ConfigHelper.getConfigList( sLibName, vLibDeps, false ) ) { for( vector<string>::iterator itI = vLibDeps.begin( ); itI < vLibDeps.end( ); itI++ ) { string sSearchTag = "lib" + *itI; if( find( vLibs.begin( ), vLibs.end( ), sSearchTag ) == vLibs.end( ) ) { vLibs.push_back( sSearchTag ); } } } } //Hard coded configuration checks for inter dependencies between different source libs. if( sProjectName.compare( "libavfilter" ) == 0 ) { buildInterDependenciesHelper( { "amovie_filter" }, { "avformat", "avcodec" }, vLibs ); buildInterDependenciesHelper( { "aresample_filter" }, { "swresample" }, vLibs ); buildInterDependenciesHelper( { "asyncts_filter" }, { "avresample" }, vLibs ); buildInterDependenciesHelper( { "atempo_filter" }, { "avcodec" }, vLibs ); buildInterDependenciesHelper( { "ebur128_filter", "swresample" }, { "swresample" }, vLibs ); buildInterDependenciesHelper( { "elbg_filter" }, { "avcodec" }, vLibs ); buildInterDependenciesHelper( { "fftfilt_filter" }, { "avcodec" }, vLibs ); buildInterDependenciesHelper( { "mcdeint_filter" }, { "avcodec" }, vLibs ); buildInterDependenciesHelper( { "movie_filter" }, { "avformat", "avcodec" }, vLibs ); buildInterDependenciesHelper( { "pan_filter" }, { "swresample" }, vLibs ); buildInterDependenciesHelper( { "pp_filter" }, { "postproc" }, vLibs ); buildInterDependenciesHelper( { "removelogo_filter" }, { "avformat", "avcodec", "swscale" }, vLibs ); buildInterDependenciesHelper( { "resample_filter" }, { "avresample" }, vLibs ); buildInterDependenciesHelper( { "sab_filter" }, { "swscale" }, vLibs ); buildInterDependenciesHelper( { "scale_filter" }, { "swscale" }, vLibs ); buildInterDependenciesHelper( { "showspectrum_filter" }, { "avcodec" }, vLibs ); buildInterDependenciesHelper( { "smartblur_filter" }, { "swscale" }, vLibs ); buildInterDependenciesHelper( { "subtitles_filter" }, { "avformat", "avcodec" }, vLibs ); buildInterDependenciesHelper( { "scale2ref_filter" }, { "swscale" }, vLibs ); } else if( sProjectName.compare( "libavdevice" ) == 0 ) { buildInterDependenciesHelper( { "lavfi_indev" }, { "avfilter" }, vLibs ); } else if( sProjectName.compare( "libavcodec" ) == 0 ) { buildInterDependenciesHelper( { "opus_decoder" }, { "swresample" }, vLibs ); } }
void IndirectCallPromotion::Execute(CallGraph* callGraph) { // Look at each call site and consider the ones // that call through a pointer. If we know any of the targets // we create specialized versions of the calls. For example, // if we known that 'p' can point to function 'a', 'b' or 'c' // we replace 'p(2)' with the following sequence: // if(p == a) a(2); // else if(p == b) b(2); // else c(2); callGraph_ = callGraph; auto& nodes = callGraph->GetCallNodes(); for(int i = 0; i < nodes.Count(); i++) { auto node = nodes[i]; // Ignore node groups. if(node->IsNodeGroup()) { continue; } // Process each call site. auto callNode = static_cast<CallNode*>(node); StaticList<CallSite*, 2> candidates; for(int j = 0; j < callNode->CallSiteCount(); j++) { // The call should be through a pointer. auto callSite = callNode->GetCallSite(j); auto callInstr = callSite->GetCallInstruction(); if((callInstr == nullptr) || callInstr->TargetOp()->IsFunctionReference()) { continue; } else candidates.Add(callSite); } for(int j = 0; j < candidates.Count(); j++) { auto callSite = candidates[j]; // At least one target should be known // (we don't consider the Unknown and External nodes). int ignored = (callSite->CallsUnknownFunctions() ? 1 : 0) + (callSite->CallsExternalFunctions() ? 1 : 0); int knownTargets = callSite->CalledFunctionsCount() - ignored; if(knownTargets > 0) { PromoteCall(callSite->GetCallInstruction(), callSite, knownTargets); } } } }
bool has_water( u16 x, u16 y ) { StaticList vec; vec.clear(); readstatics( vec, x, y ); for( StaticList::iterator itr = vec.begin(), end = vec.end(); itr != end; ++itr ) { const StaticRec& rec = *itr; if (is_water(rec.graphic)) return true; } return false; }
const TBlock* GetStartBlock(const TFunction* function) { // It's possible that the function has multiple exit blocks. // In this case we need to create a fake block that acts like an // "unique" exit block, whose predecessors are the real exit blocks. if(exitBlock_) { // A fake exit block has been already created. return exitBlock_; } StaticList<const TBlock*, 16> exitBlocks; const TBlock* block = function->FirstBlock(); while(block) { if(block->SuccessorCount() == 0) { // This is an exit block. exitBlocks.Add(block); returnBlocks_.SetBit(block->Id()); } block = block->NextBlock(); } // Now return the exit block. If there is no unique block // we create a "fake" one that has all the exit blocks // as its predecessors. This block will be deleted after the analysis. if(exitBlocks.Count() == 1) { // There is a single exit block. return exitBlocks[0]; } else if(exitBlocks.Count() > 1) { // There are multiple exit blocks, create a fake block. exitBlock_ = TBlock::GetBlock("#fakeBlock"); for(int i = 0; i < exitBlocks.Count(); i++) { exitBlock_->AddPredecessor(const_cast<TBlock*>(exitBlocks[i])); } return exitBlock_; } else { // There is no exit block. This can happen, for example, if the last // block represents an infinite loop. In this case return the last block. return function->LastBlock(); } }
int main() { StaticList<char> sl; sl.InsertElem('A'); sl.InsertElem('B'); sl.InsertElem('C'); sl.InsertElem(3,'D'); sl.Traverse(); cout<<endl; sl.DeleteElem(1); sl.Traverse(); return 0; }
int contour( int argc, char **argv ) { open_uo_data_files(); read_uo_data(); MapContour* mc = new MapContour; for( u16 y = 0; y < 4095; ++y ) { for( u16 x = 0; x < 6143; ++x ) { static StaticList vec; vec.clear(); readstatics( vec, x, y ); bool result; short newz; standheight(MOVEMODE_LAND, vec, x, y, 127, &result, &newz); if (result) { mc->z[x][y] = static_cast<signed char>(newz); } else { mc->z[x][y] = 127; } } } ofstream ofs( "contour.dat", ios::trunc|ios::out|ios::binary ); ofs.write( reinterpret_cast<const char*>(mc), sizeof(MapContour) ); clear_tiledata(); return 0; }
void elimdupes( StaticList& list ) { bool any = true; do { any = false; for( unsigned i = 0; !any && (i < list.size()); ++i ) { for( unsigned j = 0; !any && (j < list.size()); ++j ) { if (i == j) continue; if (tile_uoflags(list[i].graphic) == tile_uoflags(list[j].graphic) && tileheight(list[i].graphic) == tileheight(list[j].graphic) && list[i].z == list[j].z) { list[i] = list.back(); list.pop_back(); any = true; } } } } while (any); }
void ProjectGenerator::buildInterDependenciesHelper(const StaticList & vConfigOptions, const StaticList & vAddDeps, StaticList & vLibs) { bool bFound = false; for (StaticList::const_iterator itI = vConfigOptions.begin(); itI < vConfigOptions.end(); itI++) { ConfigGenerator::ValuesList::iterator itConfOpt = m_ConfigHelper.getConfigOption(*itI); bFound = ((itConfOpt != m_ConfigHelper.m_vConfigValues.end()) && (m_ConfigHelper.getConfigOption(*itI)->m_sValue.compare("1") == 0)); if (!bFound) { break; } } if (bFound) { for (StaticList::const_iterator itI = vAddDeps.begin(); itI < vAddDeps.end(); itI++) { string sSearchTag = "lib" + *itI; if (find(vLibs.begin(), vLibs.end(), sSearchTag) == vLibs.end()) { vLibs.push_back(sSearchTag); } } } }
void projectGenerator::buildProgramIncludes( const string & sProject, StaticList & vCIncludes, StaticList & vHIncludes, StaticList & vLibs, StaticList & vIncDirs, StaticList & vLib32Dirs, StaticList & vLib64Dirs ) { vCIncludes.clear( ); vHIncludes.clear( ); vLibs.clear( ); vIncDirs.clear( ); //All projects include cmdutils vCIncludes.push_back( "..\\cmdutils.c" ); if( m_ConfigHelper.getConfigOption( "opencl" )->m_sValue.compare( "1" ) == 0 ) { vCIncludes.push_back( "..\\cmdutils_opencl.c" ); //Need to check for the existence of environment variables if( GetEnvironmentVariable( "AMDAPPSDKROOT", NULL, 0 ) ) { vIncDirs.push_back( "$(AMDAPPSDKROOT)\\include\\" ); vLib32Dirs.push_back( "$(AMDAPPSDKROOT)\\lib\\Win32" ); vLib64Dirs.push_back( "$(AMDAPPSDKROOT)\\lib\\x64" ); } else if( GetEnvironmentVariable( "INTELOCLSDKROOT", NULL, 0 ) ) { vIncDirs.push_back( "$(INTELOCLSDKROOT)\\include\\" ); vLib32Dirs.push_back( "$(INTELOCLSDKROOT)\\lib\\x86" ); vLib64Dirs.push_back( "$(INTELOCLSDKROOT)\\lib\\x64" ); } else if( GetEnvironmentVariable( "CUDA_PATH", NULL, 0 ) ) { cout << " Warning: NVIDIA OpenCl currently is only 1.1. OpenCl 1.2 is needed for FFMpeg support" << endl; vIncDirs.push_back( "$(CUDA_PATH)\\include\\" ); vLib32Dirs.push_back( "$(CUDA_PATH)\\lib\\Win32" ); vLib64Dirs.push_back( "$(CUDA_PATH)\\lib\\x64" ); } vLibs.push_back( "OpenCL.lib" ); } vHIncludes.push_back( "..\\cmdutils.h" ); vHIncludes.push_back( "..\\cmdutils_common_opts.h" ); if( sProject.compare( "ffmpeg" ) == 0 ) { vCIncludes.push_back( "..\\ffmpeg.c" ); vCIncludes.push_back( "..\\ffmpeg_filter.c" ); vCIncludes.push_back( "..\\ffmpeg_opt.c" ); if( m_ConfigHelper.getConfigOption( "dxva2_lib" )->m_sValue.compare( "1" ) == 0 ) { vCIncludes.push_back( "..\\ffmpeg_dxva2.c" ); } vHIncludes.push_back( "..\\ffmpeg.h" ); } else if( sProject.compare( "ffplay" ) == 0 ) { vCIncludes.push_back( "..\\ffplay.c" ); vHIncludes.push_back( "..\\ffmpeg.h" ); vLibs.push_back( "SDL.lib" ); vIncDirs.push_back( "$(OutDir)\\include\\SDL" ); } else if( sProject.compare( "ffprobe" ) == 0 ) { vCIncludes.push_back( "..\\ffprobe.c" ); vHIncludes.push_back( "..\\ffmpeg.h" ); } else if( sProject.compare( "avconv" ) == 0 ) { vCIncludes.push_back( "..\\avconv.c" ); vCIncludes.push_back( "..\\avconv_filter.c" ); vCIncludes.push_back( "..\\avconv_opt.c" ); vHIncludes.push_back( "..\\avconv.h" ); } else if( sProject.compare( "avplay" ) == 0 ) { vCIncludes.push_back( "..\\avplay.c" ); vHIncludes.push_back( "..\\avconv.h" ); vLibs.push_back( "SDL.lib" ); vIncDirs.push_back( "$(OutDir)\\include\\SDL" ); } else if( sProject.compare( "avprobe" ) == 0 ) { vCIncludes.push_back( "..\\avprobe.c" ); vHIncludes.push_back( "..\\avconv.h" ); } }
int mapdump( int argc, char* argv[] ) { u16 wxl = 5485, wxh = 5500, wyl=0, wyh=30; if (argc >= 4) { wxl = wxh = static_cast<u16>(atoi( argv[2] )); wyl = wyh = static_cast<u16>(atoi( argv[3] )); } if (argc >= 6) { wxh = static_cast<u16>(atoi( argv[4] )); wyh = static_cast<u16>(atoi( argv[5] )); } open_uo_data_files(); read_uo_data(); ofstream ofs( "mapdump.html" ); ofs << "<table border=1 cellpadding=5 cellspacing=0>" << endl; ofs << "<tr><td> </td>"; for( u16 x = wxl; x <= wxh; ++x ) { ofs << "<td align=center>" << x << "</td>"; } ofs << "</tr>" << endl; for( u16 y = wyl; y <= wyh; ++y ) { ofs << "<tr><td valign=center>" << y << "</td>" << endl; for( u16 x = wxl; x <= wxh; ++x ) { ofs << "<td align=left valign=top>"; short z; USTRUCT_MAPINFO mi; safe_getmapinfo( x, y, &z, &mi ); USTRUCT_LAND_TILE landtile; readlandtile( mi.landtile, &landtile ); ofs << "z=" << z << "<br>"; ofs << "landtile=" << hexint(mi.landtile) << " " << landtile.name << "<br>"; ofs << " flags=" << hexint( landtile.flags ) << "<br>"; ofs << "mapz=" << (int)mi.z << "<br>"; StaticList statics; readallstatics( statics, x, y ); if (!statics.empty()) { ofs << "<table border=1 cellpadding=5 cellspacing=0>" << endl; ofs << "<tr><td>graphic</td><td>z</td><td>flags</td><td>ht</td>" << endl; for( unsigned i = 0; i < statics.size(); ++i ) { ofs << "<tr>"; StaticRec& rec = statics[i]; ofs << "<td>" << hexint( rec.graphic ) << "</td>"; ofs << "<td>" << int(rec.z) << "</td>"; ofs << "<td>" << hexint( rec.flags ) << "</td>"; ofs << "<td>" << int(rec.height) << "</td>"; ofs << "</tr>" << endl; } ofs << "</table>" << endl; } ofs << "</td>" << endl; } ofs << "</tr>" << endl; } ofs << "</table>" << endl; clear_tiledata(); return 0; }
void ProjectGenerator::buildDependencies(const string & sProjectName, StaticList & vLibs, StaticList & vAddLibs) { //Add any forced dependencies if (sProjectName.compare("libavformat") == 0) { vAddLibs.push_back("ws2_32"); //Add the additional required libs } //Determine only those dependencies that are valid for current project map<string, bool> mProjectDeps; buildProjectDependencies(sProjectName, mProjectDeps); //Loop through each known configuration option and add the required dependencies vector<string> vExternLibs; m_ConfigHelper.getConfigList("EXTERNAL_LIBRARY_LIST", vExternLibs); for (vector<string>::iterator vitLib = vExternLibs.begin(); vitLib < vExternLibs.end(); vitLib++) { //Check if enabled if (m_ConfigHelper.getConfigOption(*vitLib)->m_sValue.compare("1") == 0) { //Check if this dependency is valid for this project (if the dependency is not known default to enable) if (mProjectDeps.find(*vitLib) == mProjectDeps.end()) { cout << " Warning: Unknown dependency found (" << *vitLib << ")" << endl; } else if (!mProjectDeps[*vitLib]) { //This dependency is not valid for this project so skip it continue; } string sLib; if (vitLib->compare("avisynth") == 0) { //doesnt need any additional libs } else if (vitLib->compare("bzlib") == 0) { sLib = "libbz2"; } else if (vitLib->compare("libcdio") == 0) { sLib = "libcdio_paranoia"; } else if (vitLib->compare("libfdk_aac") == 0) { sLib = "libfdk-aac"; } else if (vitLib->compare("libnpp") == 0) { vAddLibs.push_back("nppi"); //Add the additional required libs //CUDA 7.5 onwards only provides npp for x64 } else if (vitLib->compare("libxvid") == 0) { sLib = "libxvidcore"; } else if (vitLib->compare("openssl") == 0) { //Needs ws2_32 but libavformat needs this even if not using openssl so it is already included sLib = "libssl"; } else if (vitLib->compare("decklink") == 0) { //doesnt need any additional libs } else if (vitLib->compare("opengl") == 0) { vAddLibs.push_back("Opengl32"); //Add the additional required libs } else if (vitLib->compare("opencl") == 0) { vAddLibs.push_back("OpenCL"); //Add the additional required libs } else if (vitLib->compare("openal") == 0) { vAddLibs.push_back("OpenAL32"); //Add the additional required libs } else if (vitLib->compare("nvenc") == 0) { //Doesnt require any additional libs } else if (vitLib->compare("cuda") == 0) { vAddLibs.push_back("cuda"); //Add the additional required libs } else if (vitLib->compare("schannel") == 0) { vAddLibs.push_back("Secur32"); //Add the additional required libs } else { //By default just use the lib name and prefix with lib if not already if (vitLib->find("lib") == 0) { sLib = *vitLib; } else { sLib = "lib" + *vitLib; } } if (sLib.length() > 0) { //Check already not in list vector<string>::iterator vitList = vLibs.begin(); for (vitList; vitList < vLibs.end(); vitList++) { if (vitList->compare(sLib) == 0) { break; } } if (vitList == vLibs.end()) { vLibs.push_back(sLib); } } } } //Add in extralibs used for various devices if (sProjectName.compare("libavdevice") == 0) { vExternLibs.resize(0); m_ConfigHelper.getConfigList("OUTDEV_LIST", vExternLibs); m_ConfigHelper.getConfigList("INDEV_LIST", vExternLibs); for (vector<string>::iterator vitLib = vExternLibs.begin(); vitLib < vExternLibs.end(); vitLib++) { //Check if enabled if (m_ConfigHelper.getConfigOption(*vitLib)->m_sValue.compare("1") == 0) { //Add the additional required libs if (vitLib->compare("dshow_indev") == 0) { vAddLibs.push_back("strmiids"); } else if (vitLib->compare("vfwcap_indev") == 0) { vAddLibs.push_back("vfw32"); vAddLibs.push_back("shlwapi"); } else if ((vitLib->compare("wasapi_indev") == 0) || (vitLib->compare("wasapi_outdev") == 0)) { vAddLibs.push_back("ksuser"); } } } } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AggregateCopyPropagation::IterateToFixedpoint() { // We use an iterative data-flow algorithm to propagate the copies // that are available on entry of each block. Add the blocks // in reverse-postorder, this minimizes the number of iterations. StaticList<Block*, 64> worklist; SparseBitVector inWorklist; CFGInfo<Block, Function> cfgInfo(funct_->FirstBlock(), false); auto& postorderList = cfgInfo.PostorderList(); int copyCount = infoList_.Count(); // Add all blocks to the worklist. for(int i = 0; i < postorderList.Count(); i++) { auto block = const_cast<Block*>(postorderList[i]); worklist.Add(block); inWorklist.SetBit(block->Id()); } while(worklist.IsNotEmpty()) { // Extract a block from the worklist. auto block = worklist.RemoveLast(); inWorklist.ResetBit(block->Id()); // Compute the 'in' set, which is the intersection // out the 'out' sets of the predecessors. BitVector inSet(copyCount, false); auto predecessorEnum = block->GetPredecessorEnum(); bool first = true; while(predecessorEnum.IsValid()) { auto predecessorBlock = predecessorEnum.Next(); if(first) { inSet = outSets_[predecessorBlock]; first = false; } else inSet.And(outSets_[predecessorBlock]); } // Save the 'in' set, it's needed later // when we want to eliminate the copies. inSets_.Add(block, inSet); // Now compute the new 'out' set, which is the union of the 'copy' set // with the 'in' set, from which the 'kill' set has been subtracted. // Out(B) = Copy(B) U (In(B) - Kill(B)) BitVector outSet = copySets_[block]; inSet.Difference(killSets_[block]); outSet.Or(inSet); if(outSets_[block] != outSet) { // The 'out' set must be updated, and all successors // must be added to the worklist and reprocessed. outSets_[block] = outSet; auto successorEnum = block->GetSuccessorEnum(); while(successorEnum.IsValid()) { auto successorBlock = successorEnum.Next(); if(inWorklist.IsSet(successorBlock->Id()) == false) { worklist.Add(successorBlock); inWorklist.IsSet(successorBlock->Id()); } } } } }
void ProjectGenerator::buildDependencyDirs(const string & sProjectName, StaticList & vIncludeDirs, StaticList & vLib32Dirs, StaticList & vLib64Dirs) { //Determine only those dependencies that are valid for current project map<string, bool> mProjectDeps; buildProjectDependencies(sProjectName, mProjectDeps); //Loop through each known configuration option and add the required dependencies for (map<string, bool>::iterator mitLib = mProjectDeps.begin(); mitLib != mProjectDeps.end(); mitLib++) { //Check if enabled//Check if optimised value is valid for current configuration ConfigGenerator::ValuesList::iterator vitProjectDep = m_ConfigHelper.getConfigOption(mitLib->first); if (mitLib->second && (vitProjectDep != m_ConfigHelper.m_vConfigValues.end()) && (vitProjectDep->m_sValue.compare("1") == 0)) { //Add in the additional include directories if (mitLib->first.compare("libopus") == 0) { vIncludeDirs.push_back("$(OutDir)/include/opus"); } else if (mitLib->first.compare("libfreetype") == 0) { vIncludeDirs.push_back("$(OutDir)/include/freetype2"); } else if (mitLib->first.compare("libfribidi") == 0) { vIncludeDirs.push_back("$(OutDir)/include/fribidi"); } else if (mitLib->first.compare("sdl") == 0) { vIncludeDirs.push_back("$(OutDir)/include/SDL"); } else if (mitLib->first.compare("opengl") == 0) { //Requires glext headers to be installed in include dir (does not require the libs) } else if (mitLib->first.compare("opencl") == 0) { //Need to check for the existence of environment variables if (GetEnvironmentVariable("AMDAPPSDKROOT", NULL, 0)) { vIncludeDirs.push_back("$(AMDAPPSDKROOT)/include/"); vLib32Dirs.push_back("$(AMDAPPSDKROOT)/lib/Win32"); vLib64Dirs.push_back("$(AMDAPPSDKROOT)/lib/x64"); } else if (GetEnvironmentVariable("INTELOCLSDKROOT", NULL, 0)) { vIncludeDirs.push_back("$(INTELOCLSDKROOT)/include/"); vLib32Dirs.push_back("$(INTELOCLSDKROOT)/lib/x86"); vLib64Dirs.push_back("$(INTELOCLSDKROOT)/lib/x64"); } else if (GetEnvironmentVariable("CUDA_PATH", NULL, 0)) { vIncludeDirs.push_back("$(CUDA_PATH)/include/"); vLib32Dirs.push_back("$(CUDA_PATH)/lib/Win32"); vLib64Dirs.push_back("$(CUDA_PATH)/lib/x64"); } else { cout << " Warning: Could not find an OpenCl SDK environment variable." << endl; cout << " Either an OpenCL SDK is not installed or the environment variables are missing." << endl; cout << " The location of the OpenCl files will have to be manually specified as otherwise the project will not compile." << endl; } } else if (mitLib->first.compare("openal") == 0) { if (!GetEnvironmentVariable("OPENAL_SDK", NULL, 0)) { cout << " Warning: Could not find the OpenAl SDK environment variable." << endl; cout << " Either the OpenAL SDK is not installed or the environment variable is missing." << endl; cout << " Using the default environment variable of 'OPENAL_SDK'." << endl; } vIncludeDirs.push_back("$(OPENAL_SDK)/include/"); vLib32Dirs.push_back("$(OPENAL_SDK)/libs/Win32"); vLib64Dirs.push_back("$(OPENAL_SDK)/lib/Win64"); } else if (mitLib->first.compare("nvenc") == 0) { //Need to check for the existence of environment variables if (!GetEnvironmentVariable("CUDA_PATH", NULL, 0)) { cout << " Warning: Could not find the CUDA SDK environment variable." << endl; cout << " Either the CUDA SDK is not installed or the environment variable is missing." << endl; cout << " NVENC requires CUDA to be installed with NVENC headers made available in the CUDA SDK include path." << endl; } vIncludeDirs.push_back("$(CUDA_PATH)/include/"); } else if (mitLib->first.compare("cuda") == 0) { //Need to check for the existence of environment variables if (!GetEnvironmentVariable("CUDA_PATH", NULL, 0)) { cout << " Warning: Could not find the CUDA SDK environment variable." << endl; cout << " Either the CUDA SDK is not installed or the environment variable is missing." << endl; } vIncludeDirs.push_back("$(CUDA_PATH)/include/"); vLib32Dirs.push_back("$(CUDA_PATH)/lib/Win32"); vLib64Dirs.push_back("$(CUDA_PATH)/lib/x64"); } } } }
void ProcessSolidBlock( unsigned short x_base, unsigned short y_base, MapWriter& mapwriter ) { unsigned int idx2_offset = 0; SOLIDX2_ELEM idx2_elem; memset( &idx2_elem, 0, sizeof idx2_elem ); idx2_elem.baseindex = mapwriter.NextSolidIndex(); unsigned short x_add_max = SOLIDX_X_SIZE, y_add_max = SOLIDX_Y_SIZE; if ( x_base + x_add_max > uo_map_width ) x_add_max = uo_map_width - x_base; if ( y_base + y_add_max > uo_map_height ) y_add_max = uo_map_height - y_base; for ( unsigned short x_add = 0; x_add < x_add_max; ++x_add ) { for ( unsigned short y_add = 0; y_add < y_add_max; ++y_add ) { unsigned short x = x_base + x_add; unsigned short y = y_base + y_add; StaticList statics; // read the map, and treat it like a static. short z; USTRUCT_MAPINFO mi; safe_getmapinfo( x, y, &z, &mi ); if ( mi.landtile > 0x3FFF ) INFO_PRINT.Format( "Tile 0x{:X} at ({},{},{}) is an invalid ID!\n" ) << mi.landtile << x << y << z; // for water, don't average with surrounding tiles. if ( landtile_uoflags( mi.landtile ) & USTRUCT_TILE::FLAG_LIQUID ) z = mi.z; short low_z = get_lowestadjacentz( x, y, z ); short lt_height = z - low_z; z = low_z; if ( mi.landtile > 0x3FFF ) INFO_PRINT.Format( "Tile 0x{:X} at ({},{},{}) is an invalid ID!\n" ) << mi.landtile << x << y << z; unsigned int lt_flags = landtile_uoflags( mi.landtile ); if ( ~lt_flags & USTRUCT_TILE::FLAG_BLOCKING ) { // this seems to be the default. lt_flags |= USTRUCT_TILE::FLAG_PLATFORM; } lt_flags |= USTRUCT_TILE::FLAG_NO_SHOOT; // added to make sure people using noshoot will have shapes // generated by this tile in future block LOS, shouldn't // affect people using old LOS method one way or another. lt_flags |= USTRUCT_TILE::FLAG_FLOOR; lt_flags |= USTRUCT_TILE::FLAG_HALF_HEIGHT; // the entire map is this way if ( lt_flags & USTRUCT_TILE::FLAG_WALL ) lt_height = 20; readstatics( statics, x, y, USTRUCT_TILE::FLAG_BLOCKING | USTRUCT_TILE::FLAG_PLATFORM | USTRUCT_TILE::FLAG_HALF_HEIGHT | USTRUCT_TILE::FLAG_LIQUID | USTRUCT_TILE::FLAG_HOVEROVER //USTRUCT_TILE::FLAG__WALK ); for ( unsigned i = 0; i < statics.size(); ++i ) { StaticRec srec = statics[i]; unsigned int polflags = polflags_from_tileflags( srec.graphic, srec.flags, cfg_use_no_shoot, cfg_LOS_through_windows ); if ( ( ~polflags & FLAG::MOVELAND ) && ( ~polflags & FLAG::MOVESEA ) && ( ~polflags & FLAG::BLOCKSIGHT ) && ( ~polflags & FLAG::BLOCKING ) && ( ~polflags & FLAG::OVERFLIGHT ) ) { // remove it. we'll re-sort later. statics.erase( statics.begin() + i ); --i; // do-over } if ( ( ~srec.flags & USTRUCT_TILE::FLAG_BLOCKING ) && ( ~srec.flags & USTRUCT_TILE::FLAG_PLATFORM ) && ( ~srec.flags & USTRUCT_TILE::FLAG_HALF_HEIGHT ) && ( ~srec.flags & USTRUCT_TILE::FLAG_LIQUID ) && ( ~srec.flags & USTRUCT_TILE::FLAG_HOVEROVER ) ) /*(~srec.flags & USTRUCT_TILE::FLAG__WALK)*/ { // remove it. we'll re-sort later. statics.erase( statics.begin() + i ); --i; // do-over } } bool addMap = true; for ( const auto &srec : statics ) { // Look for water tiles. If there are any, discard the map (which is usually at -15 anyway) if ( z + lt_height <= srec.z && ( ( srec.z - ( z + lt_height ) ) <= 10 ) && // only where the map is below or same Z as the static srec.graphic >= 0x1796 && srec.graphic <= 0x17B2 ) // FIXME hardcoded { // arr, there be water here addMap = false; } // if there's a static on top of one of these "wall" landtiles, make it override. if ( ( lt_flags & USTRUCT_TILE::FLAG_WALL ) && // wall? z <= srec.z && srec.z - z <= lt_height ) { lt_height = srec.z - z; } } // shadows above caves if ( is_cave_shadow( mi ) && !statics.empty() ) { addMap = false; } // If the map is a NODRAW tile, and there are statics, discard the map tile if ( mi.landtile == 2 && !statics.empty() ) addMap = false; if ( addMap ) statics.push_back( StaticRec( 0, static_cast<signed char>( z ), lt_flags, static_cast<char>( lt_height ) ) ); sort( statics.begin(), statics.end(), StaticsByZ() ); reverse( statics.begin(), statics.end() ); std::vector<MapShape> shapes; // try to consolidate like shapes, and discard ones we don't care about. while ( !statics.empty() ) { StaticRec srec = statics.back(); statics.pop_back(); unsigned int polflags = polflags_from_tileflags( srec.graphic, srec.flags, cfg_use_no_shoot, cfg_LOS_through_windows ); if ( ( ~polflags & FLAG::MOVELAND ) && ( ~polflags & FLAG::MOVESEA ) && ( ~polflags & FLAG::BLOCKSIGHT ) && ( ~polflags & FLAG::BLOCKING ) && ( ~polflags & FLAG::OVERFLIGHT ) ) { passert_always( 0 ); continue; } if ( ( ~srec.flags & USTRUCT_TILE::FLAG_BLOCKING ) && ( ~srec.flags & USTRUCT_TILE::FLAG_PLATFORM ) && ( ~srec.flags & USTRUCT_TILE::FLAG_HALF_HEIGHT ) && ( ~srec.flags & USTRUCT_TILE::FLAG_LIQUID ) && ( ~srec.flags & USTRUCT_TILE::FLAG_HOVEROVER ) ) /*(~srec.flags & USTRUCT_TILE::FLAG__WALK)*/ { passert_always( 0 ); continue; } if ( shapes.empty() ) { // this, whatever it is, is the map base. //TODO: look for water statics and use THOSE as the map. MapShape shape; shape.z = srec.z; //these will be converted below to shape.height = 0; //make the map "solid" shape.flags = static_cast<unsigned char>( polflags ); // no matter what, the lowest level is gradual shape.flags |= FLAG::GRADUAL; shapes.push_back( shape ); //for wall flag - map tile always height 0, at bottom. if map tile has height, add it as a static if ( srec.height != 0 ) { MapShape _shape; _shape.z = srec.z; _shape.height = srec.height; _shape.flags = polflags; shapes.push_back( _shape ); } continue; } MapShape& prev = shapes.back(); // we're adding it. MapShape shape; shape.z = srec.z; shape.height = srec.height; shape.flags = polflags; //always add the map shape seperately if ( shapes.size() == 1 ) { shapes.push_back( shape ); continue; } if ( shape.z < prev.z + prev.height ) { // things can't exist in the same place. // shrink the bottom part of this shape. // if that would give it negative height, then skip it. short height_remove = prev.z + prev.height - shape.z; if ( height_remove <= shape.height ) { shape.z += height_remove; shape.height -= height_remove; } else { // example: 5530, 14 continue; } } // sometimes water has "sand" a couple z-coords above it. // We'll try to detect this (really, anything that is up to 4 dist from water) // and extend the thing above downward. if ( ( prev.flags & FLAG::MOVESEA ) && ( shape.z > prev.z + prev.height ) && ( shape.z <= prev.z + prev.height + 4 ) ) { short height_add = shape.z - prev.z - prev.height; shape.z -= height_add; shape.height += height_add; } if ( ( prev.flags & FLAG::MOVESEA ) && ( prev.z + prev.height == -5 ) && ( shape.flags & FLAG::MOVESEA ) && ( shape.z == 25 ) ) { // oddly, there are some water tiles at z=25 in some places...I don't get it continue; } //string prevflags_s = flagstr(prev.flags); //const char* prevflags = prevflags_s.c_str(); //string shapeflags_s = flagstr(shape.flags); //const char* shapeflags = shapeflags_s.c_str(); if ( shape.z > prev.z + prev.height ) { // // elevated above what's below, must include separately // shapes.push_back( shape ); continue; } passert_always( shape.z == prev.z + prev.height ); if ( shape.z == prev.z + prev.height ) { // // sitting right on top of the previous solid // // standable atop non-standable: standable // nonstandable atop standable: nonstandable // etc bool can_combine = flags_match( prev.flags, shape.flags, FLAG::BLOCKSIGHT | FLAG::BLOCKING ); if ( prev.flags & FLAG::MOVELAND && ~shape.flags & FLAG::BLOCKING && ~shape.flags & FLAG::MOVELAND ) { can_combine = false; } if ( can_combine ) { prev.flags = shape.flags; prev.height += shape.height; } else // if one blocks LOS, but not the other, they can't be combined this way. { shapes.push_back( shape ); continue; } } } // the first StaticShape is the map base. MapShape base = shapes[0]; shapes.erase( shapes.begin() ); MAPCELL cell; passert_always( base.height == 0 ); cell.z = static_cast<signed char>( base.z ); //assume now map has height=1. a static was already added if it was >0 cell.flags = static_cast<u8>( base.flags ); if ( !shapes.empty() ) cell.flags |= FLAG::MORE_SOLIDS; mapwriter.SetMapCell( x, y, cell ); if ( !shapes.empty() ) { ++with_more_solids; total_statics += static_cast<unsigned int>( shapes.size() ); if ( idx2_offset == 0 ) idx2_offset = mapwriter.NextSolidx2Offset(); unsigned int addindex = mapwriter.NextSolidIndex() - idx2_elem.baseindex; if ( addindex > std::numeric_limits<unsigned short>::max() ) throw std::runtime_error("addoffset overflow"); idx2_elem.addindex[x_add][y_add] = static_cast<unsigned short>( addindex ); int count = static_cast<int>( shapes.size() ); for ( int j = 0; j < count; ++j ) { MapShape shape = shapes[j]; char _z, height, flags; _z = static_cast<char>( shapes[j].z ); height = static_cast<char>( shape.height ); flags = static_cast<u8>( shape.flags ); if ( !height )//make 0 height solid { --_z; ++height; } if ( j != count - 1 ) flags |= FLAG::MORE_SOLIDS; SOLIDS_ELEM solid; solid.z = _z; solid.height = height; solid.flags = flags; mapwriter.AppendSolid( solid ); } } } } if ( idx2_offset ) { ++nonempty; mapwriter.AppendSolidx2Elem( idx2_elem ); } else { ++empty; } mapwriter.SetSolidx2Offset( x_base, y_base, idx2_offset ); }
void SimpleDeadCodeElimination::Execute(Function* function) { StaticList<Instruction*, 512> worklist; Dictionary<Instruction*, bool> inWorklist; // If an instruction is in the worklist. // Try to remove 'store' instructions that have no effect. // The algorithm is really simple, but should catch cases like // arrays initialized with constants that were propagated already. RemoveDeadStores(function); // Try to remove copy/set operations that are unused, // because the aggregates they target are never referenced. RemoveDeadCopyOperations(function); // We process the blocks from last to first, and the instructions in the block // from last to first too; this allows removing more instructions on each // iteration that the usual first-last order. for(auto block = function->LastBlock(); block; block = block->PreviousBlock()) { // If the block is unreachable we remove all instructions from it, // but don't remove the block; this will be handled by the CFG Simplifier, // which knows how to repair the Dominator Tree. if(block->IsUnreachable() && (block->IsEmpty() == false)) { CleanUnreachableBlock(block); continue; } for(auto instr = block->LastInstruction(); instr; instr = instr->PreviousInstruction()) { if(GetSafetyInfo()->IsDefinitelyDead(instr)) { worklist.Add(instr); inWorklist.Add(instr, true); } } } // Process while we have instructions in the worklist. while(worklist.IsNotEmpty()) { auto instr = worklist.RemoveLast(); inWorklist.Remove(instr); // Remove the instruction if it's dead. if(GetSafetyInfo()->IsDefinitelyDead(instr)) { // All the instructions that where used by this one // may be dead now, add them to the worklist. for(int i = 0; i < instr->SourceOpCount(); i++) { auto sourceOp = instr->GetSourceOp(i); // Make sure we don't add an instruction in the worklist twice. if(auto definingInstr = sourceOp->DefiningInstruction()) { if(inWorklist.ContainsKey(definingInstr) == false) { worklist.Add(definingInstr); inWorklist.Add(definingInstr, true); } } } InstructionRemoved(instr); instr->RemoveFromBlock(true /* free */); } } // If there were removed stored we may now have variables // that are not used by any instruction. RemoveDeadVariables(function); }
void projectGenerator::buildDependencies( const string & sProjectName, StaticList & vLibs, StaticList & vAddLibs, StaticList & vIncludeDirs, StaticList & vLib32Dirs, StaticList & vLib64Dirs ) { //Add any forced dependencies if( sProjectName.compare( "libavformat" ) == 0 ) { vAddLibs.push_back( "ws2_32" ); //Add the additional required libs } //Determine only those dependencies that are valid for current project map<string,bool> mProjectDeps; buildProjectDependencies( sProjectName, mProjectDeps ); //Loop through each known configuration option and add the required dependencies vector<string> vExternLibs; m_ConfigHelper.getConfigList( "EXTERNAL_LIBRARY_LIST", vExternLibs ); //Add extra external libraries vExternLibs.push_back( "vfwcap_indev" ); vExternLibs.push_back( "dshow_indev" ); for( vector<string>::iterator vitLib=vExternLibs.begin(); vitLib<vExternLibs.end(); vitLib++ ) { //Check if enabled if( m_ConfigHelper.getConfigOption( *vitLib )->m_sValue.compare("1") == 0 ) { //Check if this dependency is valid for this project (if the dependency is not known default to enable) if( mProjectDeps.find( *vitLib ) == mProjectDeps.end() ) { cout << " Warning: Unknown dependency found (" << *vitLib << ")" << endl; } else { if( !mProjectDeps[*vitLib] ) { //This dependency is not valid for this project so skip it continue; } } string sLib; if( vitLib->compare("avisynth") == 0 ) { //doesnt need any additional libs } else if( vitLib->compare("bzlib") == 0 ) { sLib = "libbz2"; } else if( vitLib->compare("zlib") == 0 ) { sLib = "libz"; } else if( vitLib->compare( "libcdio" ) == 0 ) { sLib = "libcdio_paranoia"; } else if( vitLib->compare("libfdk_aac") == 0 ) { sLib = "libfdk-aac"; } else if( vitLib->compare("libxvid") == 0 ) { sLib = "libxvidcore"; } else if( vitLib->compare( "libmfx" ) == 0 ) { vAddLibs.push_back( "libmfx" ); //Only 1 lib for debug/release } else if( vitLib->compare("openssl") == 0 ) { //Needs ws2_32 but libavformat needs this even if not using openssl so it is already included sLib = "libopenssl"; } else if( vitLib->compare("vfwcap_indev") == 0 ) { vAddLibs.push_back( "vfw32" ); //Add the additional required libs vAddLibs.push_back( "shlwapi" ); } else if( vitLib->compare("dshow_indev") == 0 ) { vAddLibs.push_back( "strmiids" ); //Add the additional required libs } else if( vitLib->compare("decklink") == 0 ) { //doesnt need any additional libs } else if( vitLib->compare("sdl") == 0 ) { vAddLibs.push_back( "SDL" ); //Add the additional required libs } else if( vitLib->compare( "opengl" ) == 0 ) { vAddLibs.push_back( "Opengl32" ); //Add the additional required libs } else if( vitLib->compare( "opencl" ) == 0 ) { vAddLibs.push_back( "OpenCL" ); //Add the additional required libs } else if( vitLib->compare( "openal" ) == 0 ) { vAddLibs.push_back( "OpenAL32" ); //Add the additional required libs } else if( vitLib->compare( "nvenc" ) == 0 ) { //Doesnt require any additional libs } else { //By default just use the lib name and prefix with lib if not already if( vitLib->find( "lib" ) == 0 ) { sLib = *vitLib; } else { sLib = "lib" + *vitLib; } } if( sLib.length() > 0 ) { //Check already not in list vector<string>::iterator vitList=vLibs.begin(); for( vitList; vitList<vLibs.end(); vitList++ ) { if( vitList->compare( sLib ) == 0 ) { break; } } if( vitList == vLibs.end() ) { vLibs.push_back( sLib ); } } //Add in the additional include directories if( vitLib->compare("libopus") == 0 ) { vIncludeDirs.push_back("$(OutDir)\\include\\opus"); } else if( vitLib->compare("libfreetype") == 0 ) { vIncludeDirs.push_back("$(OutDir)\\include\\freetype2"); } else if( vitLib->compare( "libfribidi" ) == 0 ) { vIncludeDirs.push_back( "$(OutDir)\\include\\fribidi" ); } else if( vitLib->compare("sdl") == 0 ) { vIncludeDirs.push_back("$(OutDir)\\include\\SDL"); } else if( vitLib->compare( "opengl" ) == 0 ) { //Requires glext headers to be installed in include dir (does not require the libs) } else if( vitLib->compare( "opencl" ) == 0 ) { //Need to check for the existence of environment variables if( GetEnvironmentVariable( "AMDAPPSDKROOT", NULL, 0 ) ) { vIncludeDirs.push_back( "$(AMDAPPSDKROOT)\\include\\" ); vLib32Dirs.push_back( "$(AMDAPPSDKROOT)\\lib\\Win32" ); vLib64Dirs.push_back( "$(AMDAPPSDKROOT)\\lib\\x64" ); } else if( GetEnvironmentVariable( "INTELOCLSDKROOT", NULL, 0 ) ) { vIncludeDirs.push_back( "$(INTELOCLSDKROOT)\\include\\" ); vLib32Dirs.push_back( "$(INTELOCLSDKROOT)\\lib\\x86" ); vLib64Dirs.push_back( "$(INTELOCLSDKROOT)\\lib\\x64" ); } else if( GetEnvironmentVariable( "CUDA_PATH", NULL, 0 ) ) { cout << " Warning: NVIDIA OpenCl currently is only 1.1. OpenCl 1.2 is needed for FFMpeg support" << endl; vIncludeDirs.push_back( "$(CUDA_PATH)\\include\\" ); vLib32Dirs.push_back( "$(CUDA_PATH)\\lib\\Win32" ); vLib64Dirs.push_back( "$(CUDA_PATH)\\lib\\x64" ); } else { cout << " Warning: Could not find an OpenCl SDK environment variable." << endl; cout << " Either an OpenCL SDK is not installed or the environment variables are missing." << endl; } } else if( vitLib->compare( "openal" ) == 0 ) { if( !GetEnvironmentVariable( "OPENAL_SDK", NULL, 0 ) ) { cout << " Warning: Could not find the OpenAl SDK environment variable." << endl; cout << " Either the OpenAL SDK is not installed or the environment variable is missing." << endl; cout << " Using the default environment variable of 'OPENAL_SDK'." << endl; } vIncludeDirs.push_back( "$(OPENAL_SDK)\\include\\" ); vLib32Dirs.push_back( "$(OPENAL_SDK)\\libs\\Win32" ); vLib64Dirs.push_back( "$(CUDA_PATH)\\lib\\Win64" ); } else if( vitLib->compare( "nvenc" ) == 0 ) { //Need to check for the existence of environment variables if( !GetEnvironmentVariable( "CUDA_PATH", NULL, 0 ) ) { cout << " Warning: Could not find the CUDA SDK environment variable." << endl; cout << " Either the CUDA SDK is not installed or the environment variable is missing." << endl; cout << " NVENC requires CUDA to be installed with NVENC headers made available in the CUDA SDK include path." << endl; } vIncludeDirs.push_back( "$(CUDA_PATH)\\include\\" ); } else if( vitLib->compare( "libmfx" ) == 0 ) { if( !GetEnvironmentVariable( "INTELMEDIASDKROOT", NULL, 0 ) ) { cout << " Warning: Could not find the Intel Media SDK environment variable." << endl; cout << " Either the Intel Media is not installed or the environment variable is missing." << endl; cout << " Using the default environment variable of 'INTELMEDIASDKROOT'." << endl; } vIncludeDirs.push_back( "$(INTELMEDIASDKROOT)\\include\\" ); vLib32Dirs.push_back( "$(INTELMEDIASDKROOT)\\lib\\win32" ); vLib64Dirs.push_back( "$(INTELMEDIASDKROOT)\\lib\\x64" ); } } } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AddOperand(unsigned op) { ops_.Add(op); }