Browse Source

Switch SECTION.Relocs from list-type operations to tree-type operations.

git-svn-id: file:///var/svn/tigccpp/branches/ld-tigcc-optimization@1289 9552661e-59e3-4036-b4f2-dbe53926924f
debrouxl 15 years ago
parent
commit
dc463b63c9
14 changed files with 47 additions and 47 deletions
  1. 1 1
      bincode/cutrange.c
  2. 4 4
      bincode/fix_m68k.c
  3. 1 1
      dump.c
  4. 2 2
      export/exp_data.c
  5. 6 6
      export/exp_dbg.c
  6. 2 2
      export/exp_farg.c
  7. 4 4
      export/exp_ndll.c
  8. 2 2
      export/exp_os.c
  9. 6 6
      export/exp_tios.c
  10. 1 1
      gcunused.c
  11. 2 2
      insert/model/list.c
  12. 9 9
      manip.c
  13. 3 3
      reorder.c
  14. 4 4
      special.c

+ 1 - 1
bincode/cutrange.c

@@ -125,7 +125,7 @@ void CutRange (SECTION *Section, OFFSET Start, OFFSET End)
 			RELOC *Reloc;
 			
 			// For each reloc...
-			for_each (Reloc, RelocSection->Relocs)
+			tree_for_each (Reloc, RelocSection->Relocs)
 			{
 				// Only adjust relocs targeting this section.
 				if (Reloc->Target.Symbol && (Reloc->Target.Symbol->Parent == Section))

+ 4 - 4
bincode/fix_m68k.c

@@ -48,9 +48,9 @@ void M68kFixCodePreMerge (SECTION *Dest, SECTION *Src, SIZE DestSize)
 		RELOC *Reloc, *NextReloc;
 		
 		// For each reloc...
-		for (Reloc = (DestSize ? GetFirst (Dest->Relocs) : GetLast (Dest->Relocs)); Reloc; Reloc = NextReloc)
+		for (Reloc = (DestSize ? TreeFirst (Dest->Relocs) : TreeLast (Dest->Relocs)); Reloc; Reloc = NextReloc)
 		{
-			NextReloc = (DestSize ? GetNext (Reloc) : GetPrev (Reloc));
+			NextReloc = (DestSize ? TreeNext (Reloc) : TreePrev (Reloc));
 			
 			// Completely ignore builtin relocs. Also ignore relation-relative
 			// relocs, since the only relative relocs we can optimize further
@@ -813,13 +813,13 @@ COUNT M68kGetSectionRelationship (const SECTION *Section1, const SECTION *Sectio
 	COUNT Result = 0;
 	
 	const RELOC *Reloc;
-	for_each (Reloc, Section1->Relocs)
+	tree_for_each (Reloc, Section1->Relocs)
 	{
 		const SYMBOL *TargetSymbol = Reloc->Target.Symbol;
 		if (TargetSymbol && TargetSymbol->Parent == Section2)
 			Result += M68kGetRelocImportance (Reloc, Section1->Size - Reloc->Location + TargetSymbol->Location + Reloc->Target.Offset + Reloc->FixedOffset);
 	}
-	for_each (Reloc, Section2->Relocs)
+	tree_for_each (Reloc, Section2->Relocs)
 	{
 		const SYMBOL *TargetSymbol = Reloc->Target.Symbol;
 		if (TargetSymbol && TargetSymbol->Parent == Section1)

+ 1 - 1
dump.c

@@ -95,7 +95,7 @@ void DumpSection (FILE *File, const char *Indent, const SECTION *Section)
 	{
 		const SEGMENT  *NextSegment = GetFirst (Section->Segments);
 		const SYMBOL   *NextSymbol  = GetFirst (Section->Symbols);
-		const RELOC    *NextReloc   = GetFirst (Section->Relocs);
+		const RELOC    *NextReloc   = TreeFirst(Section->Relocs);
 		const ROM_CALL *NextROMCall = GetFirst (Section->ROMCalls);
 		const RAM_CALL *NextRAMCall = GetFirst (Section->RAMCalls);
 		const LIB_CALL *NextLibCall = GetFirst (Section->LibCalls);

+ 2 - 2
export/exp_data.c

@@ -61,11 +61,11 @@ BOOLEAN ExportDataFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize AT
 	DataStart = ExportTell (File);
 	ExportWrite (File, DataSection->Data, DataSection->Size, 1);
 	
-	if (!(IsEmpty (DataSection->Relocs)))
+	if (!(TreeIsEmpty (DataSection->Relocs)))
 	{
 		RELOC *Reloc;
 		
-		for_each (Reloc, DataSection->Relocs)
+		tree_for_each (Reloc, DataSection->Relocs)
 		{
 			// If this can be resolved to a calculator-dependent value, write the
 			// value into the section data.

+ 6 - 6
export/exp_dbg.c

@@ -125,7 +125,7 @@ static void CountSectionCOFFSize (const SECTION *Section, void *UserData)
 			Size += NameLen + 1;
 	}
 
-	for_each (Reloc, Section->Relocs)
+	tree_for_each (Reloc, Section->Relocs)
 	{
 		// If this can be resolved to a calculator-dependent value, ignore the
 		// reloc for now.
@@ -191,7 +191,7 @@ static void CountSymbolTableOffset (const SECTION *Section, void *UserData)
 	if (Section->Data)
 		Size = Section->Size;
 
-	for_each (Reloc, Section->Relocs)
+	tree_for_each (Reloc, Section->Relocs)
 	{
 		// If this can be resolved to a calculator-dependent value, ignore the
 		// reloc for now.
@@ -229,7 +229,7 @@ static void WriteSectionHeader (const SECTION *Section, void *UserData)
 	if (Section->Data)
 		Size = Section->Size;
 
-	for_each (Reloc, Section->Relocs)
+	tree_for_each (Reloc, Section->Relocs)
 	{
 		// If this can be resolved to a calculator-dependent value, ignore the
 		// reloc for now.
@@ -321,7 +321,7 @@ static void PatchRelocOffsetsIn (const SECTION *Section, void *UserData ATTRIBUT
 {
 	const RELOC *Reloc;
 
-	for_each (Reloc, Section->Relocs)
+	tree_for_each (Reloc, Section->Relocs)
 	{
 		// If this can be resolved to a calculator-dependent value, ignore the
 		// reloc for now.
@@ -351,7 +351,7 @@ static void WriteSectionContents (const SECTION *Section, void *UserData)
 		ExportWrite (((SectionOffsets *)UserData)->File, Section->Data, Section->Size, 1);
 
 	// Write reloc table.
-	for_each (Reloc, Section->Relocs)
+	tree_for_each (Reloc, Section->Relocs)
 	{
 		COFF_RELOC COFFReloc;
 
@@ -372,7 +372,7 @@ static void PatchRelocOffsetsOut (const SECTION *Section, void *UserData ATTRIBU
 {
 	const RELOC *Reloc;
 
-	for_each (Reloc, Section->Relocs)
+	tree_for_each (Reloc, Section->Relocs)
 	{
 		// If this can be resolved to a calculator-dependent value, ignore the
 		// reloc for now.

+ 2 - 2
export/exp_farg.c

@@ -87,11 +87,11 @@ BOOLEAN ExportFargoFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize A
 	// Write out the TI-BASIC fork.
 	ExportWrite (File, FARGO_TIBASIC_FORK, sizeof (FARGO_TIBASIC_FORK), 1);
 
-	if (!(IsEmpty (MainSection->Relocs)))
+	if (!(TreeIsEmpty (MainSection->Relocs)))
 	{
 		RELOC *Reloc;
 		
-		for_each (Reloc, MainSection->Relocs)
+		tree_for_each (Reloc, MainSection->Relocs)
 		{
 			// If this can be resolved to a calculator-dependent value, write the
 			// value into the section data.

+ 4 - 4
export/exp_ndll.c

@@ -42,12 +42,12 @@ SIZE GetNostubDLLFileSize (const PROGRAM *Program)
 		// Add 2 for the two null bytes at the beginning of the reloc table.
 		SIZE Size = 2 + MainSection->Size + 2;
 		
-		if (!(IsEmpty (MainSection->Relocs)))
+		if (!(TreeIsEmpty (MainSection->Relocs)))
 		{
 			RELOC *Reloc;
 			
 			// Add the size needed for the relocs.
-			for_each (Reloc, MainSection->Relocs)
+			tree_for_each (Reloc, MainSection->Relocs)
 			{
 				// If this can be resolved to a calculator-dependent value, ignore the
 				// reloc for now.
@@ -107,12 +107,12 @@ BOOLEAN ExportNostubDLLFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSi
 	// Write out two zero bytes as a separator.
 	ExportWriteTI2 (File, 0);
 	
-	if (!(IsEmpty (MainSection->Relocs)))
+	if (!(TreeIsEmpty (MainSection->Relocs)))
 	{
 		RELOC *Reloc;
 		
 		// Write out the relocation table.
-		for (Reloc = GetLast (MainSection->Relocs); Reloc; Reloc = GetPrev (Reloc))
+		for (Reloc = TreeLast (MainSection->Relocs); Reloc; Reloc = TreePrev (Reloc))
 		{
 			// Get the current file name for error messages.
 			const char *CurFileName = GetFileName (MainSection, Reloc->Location);

+ 2 - 2
export/exp_os.c

@@ -102,12 +102,12 @@ BOOLEAN ExportFlashOSFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize
 		ExportWrite (File, &ZeroByte, 1, 1);
 	DataEnd = ExportTell (File);
 	
-	if (!(IsEmpty (MainSection->Relocs)))
+	if (!(TreeIsEmpty (MainSection->Relocs)))
 	{
 		RELOC *Reloc;
 		
 		// Write out the relocation entries.
-		for (Reloc = GetLast (MainSection->Relocs); Reloc; Reloc = GetPrev (Reloc))
+		for (Reloc = TreeLast (MainSection->Relocs); Reloc; Reloc = TreePrev (Reloc))
 		{
 			// Get the current file name for error messages.
 			const char *CurFileName = GetFileName (MainSection, Reloc->Location);

+ 6 - 6
export/exp_tios.c

@@ -45,12 +45,12 @@ SIZE GetTIOSFileSize (const PROGRAM *Program)
 		// Add 2 for the two null bytes at the beginning of the reloc table.
 		SIZE Size = MainSection->Size + 2;
 		
-		if (!(IsEmpty (MainSection->Relocs)))
+		if (!(TreeIsEmpty (MainSection->Relocs)))
 		{
 			RELOC *Reloc;
 			
 			// Add the size needed for the relocs.
-			for_each (Reloc, MainSection->Relocs)
+			tree_for_each (Reloc, MainSection->Relocs)
 			{
 				// If this can be resolved to a calculator-dependent value, ignore the
 				// reloc for now.
@@ -111,12 +111,12 @@ BOOLEAN ExportTIOSFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize, P
 	// Write out two zero bytes as a separator.
 	ExportWriteTI2 (File, 0);
 	
-	if (!(IsEmpty (MainSection->Relocs)))
+	if (!(TreeIsEmpty (MainSection->Relocs)))
 	{
 		RELOC *Reloc;
 		
 		// Write out the relocation table.
-		for (Reloc = GetLast (MainSection->Relocs); Reloc; Reloc = GetPrev (Reloc))
+		for (Reloc = TreeLast (MainSection->Relocs); Reloc; Reloc = TreePrev (Reloc))
 		{
 			// Get the current file name for error messages.
 			const char *CurFileName = GetFileName (MainSection, Reloc->Location);
@@ -223,12 +223,12 @@ BOOLEAN ExportPackedTIOSFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileS
 	// Write out two zero bytes as a separator.
 	BufferWriteTI2 (0);
 	
-	if (!(IsEmpty (MainSection->Relocs)))
+	if (!(TreeIsEmpty (MainSection->Relocs)))
 	{
 		RELOC *Reloc;
 		
 		// Write out the relocation table.
-		for (Reloc = GetLast (MainSection->Relocs); Reloc; Reloc = GetPrev (Reloc))
+		for (Reloc = TreeLast (MainSection->Relocs); Reloc; Reloc = TreePrev (Reloc))
 		{
 			// Get the current file name for error messages.
 			const char *CurFileName = GetFileName (MainSection, Reloc->Location);

+ 1 - 1
gcunused.c

@@ -48,7 +48,7 @@ static void MarkSection (SECTION *Section)
 
 	// Recursively mark the target section and the relation section of all
 	// relocs in this section
-	for_each (Reloc, Section->Relocs)
+	tree_for_each (Reloc, Section->Relocs)
 	{
 		MarkLocation (&(Reloc->Target));
 		MarkLocation (Reloc->Relation);

+ 2 - 2
insert/model/list.c

@@ -65,13 +65,13 @@ OFFSET RelocListModel (SECTION *SourceSection, RELOC **NextItem, RELOC_USER_DATA
 	// with this SourceSection. The caller cannot fill *NextItem because it does
 	// not know how to get the first item.
 	if (!(*NextItem))
-		*NextItem = GetFirst (SourceSection->Relocs);
+		*NextItem = TreeFirst (SourceSection->Relocs);
 	
 	// Loop until we are done with counting or can return the next reloc that is
 	// important for us.
 	while ((CurReloc = *NextItem))
 	{
-		*NextItem = GetNext (CurReloc);
+		*NextItem = TreeNext (CurReloc);
 		
 		// Returning a location < 0 would be fatal, since it means we are done.
 		if ((CurReloc->Location >= 0) && (CurReloc->Location + CurReloc->Size <= SourceSection->Size))

+ 9 - 9
manip.c

@@ -107,9 +107,9 @@ void FreeSection (SECTION *Section)
 	
 	{
 		RELOC *Reloc, *NextReloc;
-		for (Reloc = GetLast (Section->Relocs); Reloc; Reloc = NextReloc)
+		for (Reloc = TreeLast (Section->Relocs); Reloc; Reloc = NextReloc)
 		{
-			NextReloc = GetPrev (Reloc);
+			NextReloc = TreePrev (Reloc);
 			FreeReloc (Reloc);
 		}
 	}
@@ -133,7 +133,7 @@ void FreeSection (SECTION *Section)
 void FreeReloc (RELOC *Reloc)
 {
 	SECTION *Section = Reloc->Parent;
-	Unlink (Section->Relocs, Reloc);
+	TreeUnlink (Section->Relocs, Reloc);
 	// Need to free the symbol name, if it is not a reference to Symbol->Name.
 	FreeLocationSymbolName (Section, &(Reloc->Target));
 	// Need to free the relation if it exists.
@@ -329,7 +329,7 @@ static void IncRefCounts (SECTION *SourceSection, SECTION *TargetSection, const
 void InsertReloc (SECTION *Section, RELOC *Reloc)
 {
 	const RELOC *NextReloc = FindRelocAtPos (Section, Reloc->Location, TRUE);
-	InsertBefore (Section->Relocs, Reloc, NextReloc);
+	TreeInsertBefore (Section->Relocs, Reloc, NextReloc);
 	HandleLocation (Reloc, &(Reloc->Target));
 	HandleLocation (Reloc, Reloc->Relation);
 	{
@@ -711,9 +711,9 @@ BOOLEAN ResolveRelocs (PROGRAM *Program, BOOLEAN Force)
 			RELOC *Reloc, *NextReloc;
 			
 			// For each reloc...
-			for (Reloc = GetFirst (Section->Relocs); Reloc; Reloc = NextReloc)
+			for (Reloc = TreeFirst (Section->Relocs); Reloc; Reloc = NextReloc)
 			{
-				NextReloc = GetNext (Reloc);
+				NextReloc = TreeNext (Reloc);
 				
 				// Try to resolve it.
 				if (!(ResolveReloc (Reloc, Force)))
@@ -760,7 +760,7 @@ void OptimizeRelocs (PROGRAM *Program)
 		RELOC *Reloc;
 		
 		// For each reloc...
-		for_each (Reloc, Section->Relocs)
+		tree_for_each (Reloc, Section->Relocs)
 		{
 			// Optimize the target.
 			OptimizeLocation (&(Reloc->Target));
@@ -1068,10 +1068,10 @@ BOOLEAN FixupRelativeRelocs (PROGRAM *Program)
 			RELOC *Reloc, *NextReloc;
 			
 			// For each reloc in the section...
-			for (Reloc = GetFirst (Section->Relocs); Reloc; Reloc = NextReloc)
+			for (Reloc = TreeFirst (Section->Relocs); Reloc; Reloc = NextReloc)
 			{
 				// Get the next reloc now because we might remove this one.
-				NextReloc = GetNext (Reloc);
+				NextReloc = TreeNext (Reloc);
 				
 				if (Reloc->Relative)
 				{

+ 3 - 3
reorder.c

@@ -61,7 +61,7 @@ static COUNT GetRelocCountFromTo (const SECTION *Src, const SECTION *Dest)
 {
 	COUNT Result = 0;
 	RELOC *Reloc;
-	for_each (Reloc, Src->Relocs)
+	tree_for_each (Reloc, Src->Relocs)
 	{
 		SYMBOL *TargetSymbol = Reloc->Target.Symbol;
 		if (TargetSymbol && TargetSymbol->Parent == Dest && M68kIsRelocOptimizable (Reloc))
@@ -575,7 +575,7 @@ static COUNT ComputeGoodness(SECTION **Sections, COUNT RecursionDepth,
 		RELOC *Reloc;
 		HandledSection = *PHandledSection;
 		// Look for references FROM the handled section TO the current section.
-		for_each (Reloc, HandledSection->Relocs)
+		tree_for_each (Reloc, HandledSection->Relocs)
 		{
 			if (!Reloc->Relation && Reloc->Target.Symbol
 			    && Reloc->Target.Symbol->Parent == CurrentSection)
@@ -592,7 +592,7 @@ static COUNT ComputeGoodness(SECTION **Sections, COUNT RecursionDepth,
 			}
 		}
 		// Look for references TO the handled section FROM the current section.
-		for_each (Reloc, CurrentSection->Relocs)
+		tree_for_each (Reloc, CurrentSection->Relocs)
 		{
 			if (!Reloc->Relation && Reloc->Target.Symbol
 			    && Reloc->Target.Symbol->Parent == HandledSection)

+ 4 - 4
special.c

@@ -362,7 +362,7 @@ BOOLEAN CreateSpecialGlobalImports (PROGRAM *Program)
 	{
 		BOOLEAN Done = FALSE;
 		RELOC *TempReloc;
-		for_each (TempReloc, TempSection->Relocs)
+		tree_for_each (TempReloc, TempSection->Relocs)
 		{
 			if ((!(TempReloc->Relative || TempReloc->Target.Builtin || (TempReloc->Target.Symbol && (TempReloc->Target.Symbol->Parent->Handled)))))
 			{
@@ -981,7 +981,7 @@ BOOLEAN GetBuiltinValue (PROGRAM *Program, const char *SymName, SIZE SymNameLeng
 			// is false, do not handle TrueValue.
 			if ((!TrueValue) || Program->ResolveAllBuiltins)
 			{
-				for_each (TempReloc, TempSection->Relocs)
+				tree_for_each (TempReloc, TempSection->Relocs)
 					if (!(TempReloc->Relative || TempReloc->Target.Builtin || (TempReloc->Target.Symbol && (TempReloc->Target.Symbol->Parent->Handled))))
 						IncreaseCounter (1);
 			}
@@ -993,7 +993,7 @@ BOOLEAN GetBuiltinValue (PROGRAM *Program, const char *SymName, SIZE SymNameLeng
 		{
 			// Count all absolute relocs to the data section.
 			for_each (TempSection, Program->Sections)
-				for_each (TempReloc, TempSection->Relocs)
+				tree_for_each (TempReloc, TempSection->Relocs)
 					if (TempReloc->Target.Symbol && (TempReloc->Target.Symbol->Parent == Program->DataSection) && (!(TempReloc->Relative || TempReloc->Target.Builtin)))
 						IncreaseCounter (1);
 		}
@@ -1004,7 +1004,7 @@ BOOLEAN GetBuiltinValue (PROGRAM *Program, const char *SymName, SIZE SymNameLeng
 		{
 			// Count all absolute relocs to the BSS section.
 			for_each (TempSection, Program->Sections)
-				for_each (TempReloc, TempSection->Relocs)
+				tree_for_each (TempReloc, TempSection->Relocs)
 					if (TempReloc->Target.Symbol && (TempReloc->Target.Symbol->Parent == Program->BSSSection) && (!(TempReloc->Relative || TempReloc->Target.Builtin)))
 						IncreaseCounter (1);
 		}