[Vm-dev] VM Maker: VMMaker.oscog-eem.455.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Oct 14 17:57:25 UTC 2013


Eliot Miranda uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-eem.455.mcz

==================== Summary ====================

Name: VMMaker.oscog-eem.455
Author: eem
Time: 14 October 2013, 10:54:31.148 am
UUID: aa5d9a84-c8f8-4bea-b3c6-3871153f8238
Ancestors: VMMaker.oscog-eem.454

Harvest any initializations of localised inst vars and add them to the
methods into which they're localised.

=============== Diff against VMMaker.oscog-eem.454 ===============

Item was added:
+ ----- Method: CCodeGenerator>>initializerForInstVar:in: (in category 'inlining') -----
+ initializerForInstVar: varName in: aClass
+ 	| instVarIndex |
+ 	instVarIndex := aClass instVarIndexFor: varName ifAbsent: [^nil].
+ 	aClass selectorsAndMethodsDo:
+ 		[:s :m| | tmeth |
+ 		((s beginsWith: 'initialize')
+ 		 and: [m writesField: instVarIndex]) ifTrue:
+ 			[tmeth := m methodNode asTranslationMethodOfClass: TMethod.
+ 			 tmeth parseTree nodesDo:
+ 				[:node| | exprOrAssignment |
+ 				(node isAssignment
+ 				 and: [node variable name = varName]) ifTrue:
+ 					[exprOrAssignment := node.
+ 					 [exprOrAssignment isAssignment] whileTrue:
+ 						[exprOrAssignment := exprOrAssignment expression].
+ 					 ^exprOrAssignment]]]].
+ 	^nil!

Item was added:
+ ----- Method: CCodeGenerator>>initializerForInstVar:inStartClass: (in category 'inlining') -----
+ initializerForInstVar: varName inStartClass: aClass
+ 	| allClasses sizeBefore |
+ 	(aClass inheritsFrom: VMClass) ifFalse:
+ 		[^false].
+ 	allClasses := (aClass withAllSuperclasses copyUpTo: VMClass) asSet.
+ 	[sizeBefore := allClasses size.
+ 	 allClasses copy do:
+ 		[:class|
+ 		(class ancilliaryClasses: optionsDictionary) do:
+ 			[:ancilliary|
+ 			allClasses addAll: (ancilliary withAllSuperclasses copyUpTo: VMClass)]].
+ 	 sizeBefore ~= allClasses size] whileTrue.
+ 	allClasses do:
+ 		[:class|
+ 		(self initializerForInstVar: varName in: class) ifNotNil:
+ 			[:initializer| ^initializer]].
+ 	^nil!

Item was changed:
  ----- Method: CCodeGenerator>>localizeGlobalVariables (in category 'utilities') -----
  localizeGlobalVariables
  	| candidates elected |
  
  	"find all globals used in only one method"
  	candidates := globalVariableUsage select: [:e | e size = 1].
  	(candidates keys select: [:k| vmClass mustBeGlobal: k]) do:
  		[:k| candidates removeKey: k].
  	elected := Set new.
  
  	"move any suitable global to be local to the single method using it"
  	candidates keysAndValuesDo:
+ 		[:key :targets |
- 		[:key :targets | 
  		targets do:
+ 			[:name | | procedure newDeclaration |
- 			[:name | | procedure |
  			procedure := methods at: name.
  			procedure isRealMethod ifTrue:
  				[logger notNil ifTrue:
  					[logger ensureCr; show: key, ' localised to ', name; cr].
  				elected add: (procedure locals add: key).
+ 				newDeclaration := variableDeclarations at: key ifAbsent: ['sqInt ', key].
+ 				(self initializerForInstVar: key inStartClass: (methods at: name) definingClass) ifNotNil:
+ 					[:initializerNode|
+ 					newDeclaration := String streamContents:
+ 											[:s|
+ 											 s nextPutAll: newDeclaration; nextPutAll: ' = '.
+ 											 initializerNode emitCCodeOn: s level: 0 generator: self]].
+ 				procedure declarationAt: key put: newDeclaration.
+ 				variableDeclarations removeKey: key ifAbsent: []]]].
- 				variableDeclarations at: key ifPresent:
- 					[:v |
- 					procedure declarationAt: key put: v.
- 					variableDeclarations removeKey: key]]]].
  	elected do: [:ea| (variables includes: ea) ifTrue: [self checkDeleteVariable: ea]].
  	variables removeAllFoundIn: elected!



More information about the Vm-dev mailing list