static void *AcquireBlock(size_t size) { register size_t i; register void *block; /* Find free block. */ size=(size_t) (size+sizeof(size_t)+6*sizeof(size_t)-1) & -(4U*sizeof(size_t)); i=AllocationPolicy(size); block=memory_pool.blocks[i]; while ((block != (void *) NULL) && (SizeOfBlock(block) < size)) block=NextBlockInList(block); if (block == (void *) NULL) { i++; while (memory_pool.blocks[i] == (void *) NULL) i++; block=memory_pool.blocks[i]; if (i >= MaxBlocks) return((void *) NULL); } assert((*BlockHeader(NextBlock(block)) & PreviousBlockBit) == 0); assert(SizeOfBlock(block) >= size); RemoveFreeBlock(block,AllocationPolicy(SizeOfBlock(block))); if (SizeOfBlock(block) > size) { size_t blocksize; void *next; /* Split block. */ next=(char *) block+size; blocksize=SizeOfBlock(block)-size; *BlockHeader(next)=blocksize; *BlockFooter(next,blocksize)=blocksize; InsertFreeBlock(next,AllocationPolicy(blocksize)); *BlockHeader(block)=size | (*BlockHeader(block) & ~SizeMask); } assert(size == SizeOfBlock(block)); *BlockHeader(NextBlock(block))|=PreviousBlockBit; memory_pool.allocation+=size; return(block); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + E x p a n d H e a p % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ExpandHeap() get more memory from the system. It returns MagickTrue on % success otherwise MagickFalse. % % The format of the ExpandHeap method is: % % MagickBooleanType ExpandHeap(size_t size) % % A description of each parameter follows: % % o size: the size of the memory in bytes we require. % */ static MagickBooleanType ExpandHeap(size_t size) { DataSegmentInfo *segment_info; MagickBooleanType mapped; register ssize_t i; register void *block; size_t blocksize; void *segment; blocksize=((size+12*sizeof(size_t))+SegmentSize-1) & -SegmentSize; assert(memory_pool.number_segments < MaxSegments); segment=MapBlob(-1,IOMode,0,blocksize); mapped=segment != (void *) NULL ? MagickTrue : MagickFalse; if (segment == (void *) NULL) segment=(void *) memory_methods.acquire_memory_handler(blocksize); if (segment == (void *) NULL) return(MagickFalse); segment_info=(DataSegmentInfo *) free_segments; free_segments=segment_info->next; segment_info->mapped=mapped; segment_info->length=blocksize; segment_info->allocation=segment; segment_info->bound=(char *) segment+blocksize; i=(ssize_t) memory_pool.number_segments-1; for ( ; (i >= 0) && (memory_pool.segments[i]->allocation > segment); i--) memory_pool.segments[i+1]=memory_pool.segments[i]; memory_pool.segments[i+1]=segment_info; memory_pool.number_segments++; size=blocksize-12*sizeof(size_t); block=(char *) segment_info->allocation+4*sizeof(size_t); *BlockHeader(block)=size | PreviousBlockBit; *BlockFooter(block,size)=size; InsertFreeBlock(block,AllocationPolicy(size)); block=NextBlock(block); assert(block < segment_info->bound); *BlockHeader(block)=2*sizeof(size_t); *BlockHeader(NextBlock(block))=PreviousBlockBit; return(MagickTrue); }
static void *RemoveBlockAfter(PPMdMemoryBlockVariantI *self,PPMdSubAllocatorVariantI *alloc) { PPMdMemoryBlockVariantI *p=NextBlock(self,alloc); UnlinkBlockAfter(self,alloc); self->Stamp--; return p; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool RecursionElimination::AnalyzeCalls() { // Scan all instructions and search for tail-recursive calls. bool hasTailCall = false; for(auto block = funct_->FirstBlock(); block; block = block->NextBlock()) { for(auto instr = block->FirstInstruction(); instr; instr = instr->NextInstruction()) { if(auto callInstr = instr->As<CallInstr>()) { TailCallInfo info; if(IsTailCall(callInstr, info)) { // We process it later. Mark the 'ret' instruction as visited. tailCalls_.Add(info); processedReturns_.Add(info.TailReturn, true); hasTailCall = true; } } else if(auto retInstr = instr->As<ReturnInstr>()) { // Add the 'ret' to the list if it isn't // part of a tail-call. if(processedReturns_.ContainsKey(retInstr) == false) { returnInstrs_.Add(retInstr); } } } } return hasTailCall; }
int64 MediaBlockMapReader::ReadFrames(void* buffer, int64 frameCount) { MediaBlock* block = CurrentBlock(); int64 remaining = frameCount; int64 readSize = 0; int64 totalRead = 0; while (remaining != 0) { if (block == NULL || fMap->CountBlocks()-1 > fCurrentIndex) block = NextBlock(); else return -1; int64 toRead = block->CountFrames(); if (toRead < remaining) { readSize = toRead; remaining -= toRead; } else { readSize = remaining; remaining -= readSize; } totalRead += block->ReadFrames(buffer, readSize); buffer += readSize; } return totalRead; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AggregateCopyPropagation::InitializeAnalysis() { // Create the 'out' sets that are attached to the blocks. // The sets are initialized with the universal set // (all copies are available). for(auto block = funct_->FirstBlock(); block; block = block->NextBlock()) { outSets_.Add(block, BitVector(infoList_.Count(), true)); } }
void UpdateAllSTimes(void){ struct Blocks *block=root->song->blocks; while(block!=NULL){ UpdateSTimes(block); block=NextBlock(block); } }
void Execute(Function* function) { funct_ = function; ComputeOperandRanks(function); for(auto block = function->FirstBlock(); block; block = block->NextBlock()) { ProcessBlock(block); } }
void *FixedSizeAllocator::Allocate(void) { // free list empty, create new page if (!m_freeList) { // allocate new page PageHeader *newPage = reinterpret_cast<PageHeader *>(AllocatePage()); ++m_numPages; m_numBlocks += m_blocksPerPage; m_numFreeBlocks += m_blocksPerPage; FillFreePage(newPage); // page list not empty, link new page if (m_pageList) { newPage->Next = m_pageList; } // push new page m_pageList = newPage; // link new free blocks BlockHeader *currBlock = newPage->Blocks(); for (unsigned i = 0; i < m_blocksPerPage - 1; ++i) { currBlock->Next = NextBlock(currBlock); currBlock = NextBlock(currBlock); } currBlock->Next = nullptr; // last block // push new blocks m_freeList = newPage->Blocks(); } // pop free block BlockHeader *freeBlock = m_freeList; m_freeList = m_freeList->Next; --m_numFreeBlocks; FillAllocatedBlock(freeBlock); return freeBlock; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickMemory() zeros memory that has been allocated, frees it for % reuse. % % The format of the RelinquishMagickMemory method is: % % void *RelinquishMagickMemory(void *memory) % % A description of each parameter follows: % % o memory: A pointer to a block of memory to free for reuse. % */ MagickExport void *RelinquishMagickMemory(void *memory) { if (memory == (void *) NULL) return((void *) NULL); #if !defined(UseEmbeddableMagick) free(memory); #else assert((SizeOfBlock(memory) % (4*sizeof(size_t))) == 0); assert((*BlockHeader(NextBlock(memory)) & PreviousBlockBit) != 0); AcquireSemaphoreInfo(&memory_semaphore); if ((*BlockHeader(memory) & PreviousBlockBit) == 0) { void *previous; /* Coalesce with previous adjacent block. */ previous=PreviousBlock(memory); RemoveFreeBlock(previous,AllocationPolicy(SizeOfBlock(previous))); *BlockHeader(previous)=(SizeOfBlock(previous)+SizeOfBlock(memory)) | (*BlockHeader(previous) & ~SizeMask); memory=previous; } if ((*BlockHeader(NextBlock(NextBlock(memory))) & PreviousBlockBit) == 0) { void *next; /* Coalesce with next adjacent block. */ next=NextBlock(memory); RemoveFreeBlock(next,AllocationPolicy(SizeOfBlock(next))); *BlockHeader(memory)=(SizeOfBlock(memory)+SizeOfBlock(next)) | (*BlockHeader(memory) & ~SizeMask); } *BlockFooter(memory,SizeOfBlock(memory))=SizeOfBlock(memory); *BlockHeader(NextBlock(memory))&=(~PreviousBlockBit); InsertFreeBlock(memory,AllocationPolicy(SizeOfBlock(memory))); RelinquishSemaphoreInfo(memory_semaphore); #endif return((void *) NULL); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickMemory() frees memory acquired with AcquireMagickMemory() % or AcquireQuantumMemory() for reuse. % % The format of the RelinquishMagickMemory method is: % % void *RelinquishMagickMemory(void *memory) % % A description of each parameter follows: % % o memory: A pointer to a block of memory to free for reuse. % */ MagickExport void *RelinquishMagickMemory(void *memory) { if (memory == (void *) NULL) return((void *) NULL); #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) memory_methods.destroy_memory_handler(memory); #else LockSemaphoreInfo(memory_semaphore); assert((SizeOfBlock(memory) % (4*sizeof(size_t))) == 0); assert((*BlockHeader(NextBlock(memory)) & PreviousBlockBit) != 0); if ((*BlockHeader(memory) & PreviousBlockBit) == 0) { void *previous; /* Coalesce with previous adjacent block. */ previous=PreviousBlock(memory); RemoveFreeBlock(previous,AllocationPolicy(SizeOfBlock(previous))); *BlockHeader(previous)=(SizeOfBlock(previous)+SizeOfBlock(memory)) | (*BlockHeader(previous) & ~SizeMask); memory=previous; } if ((*BlockHeader(NextBlock(NextBlock(memory))) & PreviousBlockBit) == 0) { void *next; /* Coalesce with next adjacent block. */ next=NextBlock(memory); RemoveFreeBlock(next,AllocationPolicy(SizeOfBlock(next))); *BlockHeader(memory)=(SizeOfBlock(memory)+SizeOfBlock(next)) | (*BlockHeader(memory) & ~SizeMask); } *BlockFooter(memory,SizeOfBlock(memory))=SizeOfBlock(memory); *BlockHeader(NextBlock(memory))&=(~PreviousBlockBit); InsertFreeBlock(memory,AllocationPolicy(SizeOfBlock(memory))); UnlockSemaphoreInfo(memory_semaphore); #endif return((void *) NULL); }
int CSysinfo::GetPIDs (ExtArray<pid_t> & dest) { #if 0 // This code is deprecated in favor of using supported functions below int s=0; pid_t curpid = 0; DWORD *startblock = memptr; Refresh(); while (startblock) { curpid = *(startblock + 17); dest[s++] = curpid; startblock = NextBlock (startblock); if ( startblock == (DWORD*)1 ) { startblock = memptr; s = 0; } } return (s); #endif HANDLE hProcessSnap; PROCESSENTRY32 pe32; int s; s = 0; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); if( hProcessSnap == INVALID_HANDLE_VALUE ) { return 0; } // Set the size of the structure before using it. pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, // and exit if unsuccessful if( !Process32First( hProcessSnap, &pe32 ) ) { CloseHandle( hProcessSnap ); // Must clean up the snapshot object! return 0; } // Now walk the snapshot of processes, and // stick each one in our ExtArray to form our Pid list. do { dest[s++] = pe32.th32ProcessID; } while( Process32Next( hProcessSnap, &pe32 ) ); // Don't forget to clean up the snapshot object! CloseHandle( hProcessSnap ); return s; // return the number of PIDs we got }
nsresult mozSpellChecker::SetupDoc(int32_t *outBlockOffset) { nsresult rv; nsITextServicesDocument::TSDBlockSelectionStatus blockStatus; int32_t selOffset; int32_t selLength; *outBlockOffset = 0; if (!mFromStart) { rv = mTsDoc->LastSelectedBlock(&blockStatus, &selOffset, &selLength); if (NS_SUCCEEDED(rv) && (blockStatus != nsITextServicesDocument::eBlockNotFound)) { switch (blockStatus) { case nsITextServicesDocument::eBlockOutside: // No TB in S, but found one before/after S. case nsITextServicesDocument::eBlockPartial: // S begins or ends in TB but extends outside of TB. // the TS doc points to the block we want. *outBlockOffset = selOffset + selLength; break; case nsITextServicesDocument::eBlockInside: // S extends beyond the start and end of TB. // we want the block after this one. rv = mTsDoc->NextBlock(); *outBlockOffset = 0; break; case nsITextServicesDocument::eBlockContains: // TB contains entire S. *outBlockOffset = selOffset + selLength; break; case nsITextServicesDocument::eBlockNotFound: // There is no text block (TB) in or before the selection (S). default: NS_NOTREACHED("Shouldn't ever get this status"); } } else //failed to get last sel block. Just start at beginning { rv = mTsDoc->FirstBlock(); *outBlockOffset = 0; } } else // we want the first block { rv = mTsDoc->FirstBlock(); mFromStart = false; } return rv; }
void *CRingBufferBase::Next(void *pCurrent) { CItem *pItem = ((CItem *)pCurrent) - 1; while(1) { pItem = NextBlock(pItem); if(pItem == m_pProduce) return 0; if(!pItem->m_Free) return pItem+1; } }
void *NextUnit(MemryBlock *block) { void *nextFree= block->freeList; y_net_blocks++; if (nextFree) { /* (void**)<->(void*) typecast in next line is equivalent to list->next if list is a struct List {struct List *next;}... */ block->freeList= *(void **)nextFree; return nextFree; } else { return NextBlock(block); } }
void FixedSizeAllocator::FillFreePage(PageHeader *p) { // page header p->Next = nullptr; // blocks BlockHeader *currBlock = p->Blocks(); for (unsigned i = 0; i < m_blocksPerPage; ++i) { FillFreeBlock(currBlock); currBlock = NextBlock(currBlock); } }
__inline DWORD* CSysinfo::FindBlock (DWORD pid) { DWORD *startblock = memptr; while (startblock) { if (*(startblock+17) == pid) return startblock; startblock = NextBlock (startblock); if ( startblock == (DWORD*)1 ) startblock = memptr; } return NULL; }
void DialogTranslation::OnActiveLineChanged(AssDialogue *new_line) { if (switching_lines) return; active_line = new_line; blocks = active_line->ParseTags(); cur_block = 0; line_number = count_if(c->ass->Line.begin(), c->ass->Line.iterator_to(*new_line), cast<AssDialogue*>()) + 1; if (bad_block(blocks[cur_block]) && !NextBlock()) { wxMessageBox(_("No more lines to translate.")); EndModal(1); } }
void ExpandTextAreaVariantI(PPMdSubAllocatorVariantI *self) { PPMdMemoryBlockVariantI *p; unsigned int Count[N_INDEXES]; memset(Count,0,sizeof(Count)); while((p=(PPMdMemoryBlockVariantI *)self->UnitsStart)->Stamp==0xffffffff) { PPMdMemoryBlockVariantI *pm=p; self->UnitsStart=(uint8_t *)(pm+pm->NU); Count[self->Units2Index[pm->NU-1]]++; pm->Stamp=0; } for(int i=0;i<N_INDEXES;i++) for(p=&self->BList[i];Count[i]!=0;p=NextBlock(p,self)) while(!NextBlock(p,self)->Stamp) { UnlinkBlockAfter(p,self); self->BList[i].Stamp--; if (!--Count[i]) break; } }
void DeleteBlock( NInt blockpos ){ struct Tracker_Windows *window=root->song->tracker_windows; struct WBlocks *wblock; struct Blocks *removed_block=ListFindElement1(&root->song->blocks->l,blockpos); struct Blocks *nextblock=NextBlock(removed_block); ListRemoveElement1(&root->song->blocks,&removed_block->l); { struct Blocks *block = nextblock; while(block!=NULL){ block->l.num--; block=NextBlock(block); } } root->song->num_blocks--; while(window!=NULL){ wblock=ListFindElement1(&window->wblocks->l,blockpos); ListRemoveElement1( &window->wblocks, &wblock->l ); wblock=NextWBlock(wblock); while(wblock!=NULL){ wblock->l.num--; wblock=NextWBlock(wblock); } window=NextWindow(window); } // Call BL_removeBlockFromPlaylist after blocklist is updated. BL_removeBlockFromPlaylist(removed_block); }
int CRingBufferBase::PopFirst() { if(m_pConsume->m_Free) return 0; // set the free flag m_pConsume->m_Free = 1; // previous block is also free, merge them m_pConsume = MergeBack(m_pConsume); // advance the consume pointer m_pConsume = NextBlock(m_pConsume); while(m_pConsume->m_Free && m_pConsume != m_pProduce) { m_pConsume = MergeBack(m_pConsume); m_pConsume = NextBlock(m_pConsume); } // in the case that we have catched up with the produce pointer // we might stand on a free block so merge em MergeBack(m_pConsume); return 1; }
// Called after loading and undo. Can be called at any time. void FX_update_all_slider_automation_visuals(void){ struct Blocks *block = root->song->blocks; while(block!=NULL){ struct Tracks *track = block->tracks; while(track!=NULL){ struct FXs *fxs=track->fxs; while(fxs!=NULL){ fxs->fx->slider_automation_value = OS_SLIDER_obtain_automation_value_pointer(track->patch,fxs->fx->effect_num); fxs->fx->slider_automation_color = OS_SLIDER_obtain_automation_color_pointer(track->patch,fxs->fx->effect_num); fxs = NextFX(fxs); } track = NextTrack(track); } block = NextBlock(block); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AggregateCopyPropagation::RemovedDeadCopySetCalls() { // We count how many times each copy is used in the function. // All copies that are not used anymore can be removed, // allowing Dead Code Elimination to do it's job. List<int> copyCount(infoList_.Count()); for(int i = 0; i < infoList_.Count(); i++) { copyCount.Add(0); } // Scan all instructions in the function. for(auto block = funct_->FirstBlock(); block; block = block->NextBlock()) { for(auto instr = block->FirstInstruction(); instr; instr = instr->NextInstruction()) { // We check 'store', 'load' and 'call' instructions only, // because they're the ones that can access the copy. if(auto loadInstr = instr->As<LoadInstr>()) { VisitedDict visited; MarkUsedCopies(loadInstr->SourceOp(), copyCount, visited); } else if(auto storeInstr = instr->As<StoreInstr>()) { VisitedDict visited1; MarkUsedCopies(storeInstr->DestinationOp(), copyCount, visited1, true /* ignoreLocals */); VisitedDict visited2; MarkUsedCopies(storeInstr->SourceOp(), copyCount, visited2, true /* ignoreLocals */); } else if(auto callInstr = instr->As<CallInstr>()) { for(int i = 0; i < callInstr->ArgumentCount(); i++) { VisitedDict visited; MarkUsedCopies(callInstr->GetArgument(i), copyCount, visited); } } } } // Remove any copy that is definitely dead. for(int i = 0; i < copyCount.Count(); i++) { if((copyCount[i] - infoList_[i].Replacements) < 2) { infoList_[i].CopySetCall->RemoveFromBlock(true /* free */); } } }
int64 MediaBlockMapWriter::WriteFrames(void* buffer, int64 frameCount) { MediaBlock* block = CurrentBlock(); int64 remaining = frameCount; int64 totalWrite = 0; int64 offset = 0; while (remaining > 0) { if (block == NULL || block->CurrentFrame() == MEDIA_BLOCK_MAX_FRAMES) { block = NextBlock(); if (block == NULL) block = RequestBlock(); } int64 writeSize = 0; int64 freeSize = MEDIA_BLOCK_MAX_FRAMES-block->CurrentFrame(); printf("Got a block %d available space from block %" B_PRId64 " we want to write %" B_PRId64 "\n", (int)fCurrentIndex, freeSize, remaining); if (freeSize < remaining) { writeSize = freeSize; remaining -= freeSize; } else { writeSize = remaining; remaining -= writeSize; } totalWrite += block->WriteFrames(buffer+offset, writeSize); offset += writeSize; block->SetFlushed(false); printf("Data written %" B_PRId64 "available %" B_PRId64 "\n", writeSize, MEDIA_BLOCK_MAX_FRAMES - block->CurrentFrame()); } return totalWrite; }
NS_IMETHODIMP mozSpellChecker::NextMisspelledWord(nsAString &aWord, nsTArray<nsString> *aSuggestions) { if(!aSuggestions||!mConverter) return NS_ERROR_NULL_POINTER; int32_t selOffset; int32_t begin,end; nsresult result; result = SetupDoc(&selOffset); bool isMisspelled,done; if (NS_FAILED(result)) return result; while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) { nsString str; result = mTsDoc->GetCurrentTextBlock(&str); if (NS_FAILED(result)) return result; do{ result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end); if(NS_SUCCEEDED(result)&&(begin != -1)){ const nsAString &currWord = Substring(str, begin, end - begin); result = CheckWord(currWord, &isMisspelled, aSuggestions); if(isMisspelled){ aWord = currWord; mTsDoc->SetSelection(begin, end-begin); // After ScrollSelectionIntoView(), the pending notifications might // be flushed and PresShell/PresContext/Frames may be dead. // See bug 418470. mTsDoc->ScrollSelectionIntoView(); return NS_OK; } } selOffset = end; }while(end != -1); mTsDoc->NextBlock(); selOffset=0; } return NS_OK; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AggregateCopyPropagation::PropagateCopies() { TOperandToIdDict availableCopies; TCopyInfoList* infoList = &infoList_; for(auto block = funct_->FirstBlock(); block; block = block->NextBlock()) { // Based on the copies found in the 'in' set we build // a dictionary with the available copies at the entry of the block. availableCopies.Clear(); auto& inSet = inSets_[block]; inSet.ForEachSet([&availableCopies, infoList](int index) -> bool { availableCopies.Add((*infoList)[index].Destination, index); return true; }); // Run the local propagation algorithm if we have available copies. if(availableCopies.Count() > 0) { LocalCopyPropagation(block, availableCopies); } } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AddressLowering::Execute(Function* function) { irGen_ = IRGenerator(function->ParentUnit()); // Process each instruction in the function. for(auto block = function->FirstBlock(); block; block = block->NextBlock()) { auto instr = block->FirstInstruction(); while(instr) { if(auto indexInstr = instr->As<IndexInstr>()) { instr = LowerIndex(indexInstr); } else if(auto addrInstr = instr->As<AddressInstr>()) { instr = LowerAddress(addrInstr); } else if(auto elemInstr = instr->As<ElementInstr>()) { instr = LowerElement(elemInstr); } else instr = instr->NextInstruction(); } } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void VariableAnalysis::ComputeLiveBlocks(Dictionary<Block*, BitVector>& exposedSets) { // Each block that uses a variable will be added to the set. for(auto block = funct_->FirstBlock(); block; block = block->NextBlock()) { int varIndex = -1; BitVector& exposedSet = exposedSets[block]; do { varIndex = exposedSet.FirstSetBit(varIndex + 1); if(varIndex != -1) { // Add the block to the set associated with the variable. if(liveBlocks_.ContainsKey(varIndex) == false) { liveBlocks_.Add(varIndex, SparseBitVector()); } liveBlocks_[varIndex].SetBit(block->Id()); } } while(varIndex != -1); } }
void checkIfWBlocksAreDirty(void) { bool is_dirty = false; struct Blocks *block=root->song->blocks; while(block!=NULL){ if (block->is_dirty==true){ handleDirtyBlock(block->l.num); block->is_dirty = false; is_dirty = true; } block = NextBlock(block); } if(is_dirty==true){ struct Tracker_Windows *window=root->song->tracker_windows; while(window!=NULL){ //DrawUpTrackerWindow(window); window->must_redraw = true; window=NextWindow(window); } } }
void VariableAnalysis::ComputeAddressTakenAndDefinitions(Function* function) { DebugValidator::IsNotNull(function); // We consider that the variable has it's address taken // if it's used in any instruction that depends on it's address. // This includes storing the address, passing it as a parameter to a function, // converting it to an integer or another pointer type, etc. funct_ = function; // Initialize the map from block-id to block. for(auto block = function->FirstBlock(); block; block = block->NextBlock()) { idToBlock_.Add(block->Id(), block); } for(Block* block = funct_->FirstBlock(); block; block = block->NextBlock()) { for(auto instr = block->FirstInstruction(); instr; instr = instr->NextInstruction()) { MarkAddressTaken(instr); MarkDefinition(instr); } } }