[Vm-dev] VM Maker: VMMaker.oscog-cb.1827.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Apr 21 11:48:31 UTC 2016


ClementBera uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-cb.1827.mcz

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

Name: VMMaker.oscog-cb.1827
Author: cb
Time: 21 April 2016, 1:47:12.506717 pm
UUID: 49226588-0bfd-4e00-88c3-dfaefc9c0e57
Ancestors: VMMaker.oscog-nice.1826

(Ohm's law publication year)

- split compileAbstractInstruction in sub methods to understand what is going on.

- Fix a bug in genUpArrowReturn (deadCode should be set to true for non local return). Fixing this allow to remove:
(descriptor notNil and: [descriptor isReturn])
	ifTrue: [deadCode := true].
from compileAbstractInstruction.

=============== Diff against VMMaker.oscog-nice.1826 ===============

Item was added:
+ ----- Method: Cogit>>assertExtsAreConsumed: (in category 'compile abstract instructions') -----
+ assertExtsAreConsumed: descriptor
+ 	 "extended bytecodes must consume their extensions"
+ 	 <inline: true>
+ 	 descriptor isExtension ifFalse:
+ 		[self assert: (extA = 0 and: [extB = 0])].!

Item was changed:
  ----- Method: Cogit>>compileAbstractInstructionsFrom:through: (in category 'compile abstract instructions') -----
  compileAbstractInstructionsFrom: start through: end
  	"Loop over bytecodes, dispatching to the generator for each bytecode, handling fixups in due course."
  	| nextOpcodeIndex descriptor fixup result nExts |
  	<var: #descriptor type: #'BytecodeDescriptor *'>
  	<var: #fixup type: #'BytecodeFixup *'>
  	bytecodePC := start.
  	nExts := result := 0.
+ 	descriptor := nil.
+ 	[self cCode: '' inSmalltalk: [self isDebugPC ifTrue: [self halt]].
+ 	 descriptor := self loadBytesAndGetDescriptor.
- 	[self cCode: '' inSmalltalk:
- 		[(debugBytecodePointers includes: bytecodePC) ifTrue: [self halt]].
- 	 byte0 := (objectMemory fetchByte: bytecodePC ofObject: methodObj)  + bytecodeSetOffset.
- 	 descriptor := self generatorAt: byte0.
- 	 self loadSubsequentBytesForDescriptor: descriptor at: bytecodePC.
  	 nextOpcodeIndex := opcodeIndex.
  	 result := self perform: descriptor generator.
+ 	 self assertExtsAreConsumed: descriptor.
- 	 descriptor isExtension ifFalse: "extended bytecodes must consume their extensions"
- 		[self assert: (extA = 0 and: [extB = 0])].
  	 fixup := self fixupAt: bytecodePC - initialPC.
+ 	 self patchFixupTargetIfNeeded: fixup nextOpcodeIndex: nextOpcodeIndex.
- 	 fixup needsFixup ifTrue:
- 		["There is a fixup for this bytecode.  It must point to the first generated
- 		   instruction for this bytecode.  If there isn't one we need to add a label."
- 		 opcodeIndex = nextOpcodeIndex ifTrue: [self Label].
- 		 fixup targetInstruction: (self abstractInstructionAt: nextOpcodeIndex)].
  	 self maybeDumpLiterals: descriptor.
+ 	 bytecodePC := self nextBytecodePCFor: descriptor exts: nExts.
- 	 bytecodePC := self nextBytecodePCFor: descriptor at: bytecodePC exts: nExts in: methodObj.
  	 result = 0 and: [bytecodePC <= end]]
  		whileTrue:
  			[nExts := descriptor isExtension ifTrue: [nExts + 1] ifFalse: [0]].
  	self checkEnoughOpcodes.
  	^result!

Item was added:
+ ----- Method: Cogit>>isDebugPC (in category 'compile abstract instructions') -----
+ isDebugPC 
+ 	<doNotGenerate>
+ 	^ debugBytecodePointers includes: bytecodePC!

Item was added:
+ ----- Method: Cogit>>loadBytesAndGetDescriptor (in category 'compile abstract instructions') -----
+ loadBytesAndGetDescriptor
+ 	<var: #descriptor type: #'BytecodeDescriptor *'>
+ 	| descriptor |
+ 	byte0 := (objectMemory fetchByte: bytecodePC ofObject: methodObj)  + bytecodeSetOffset.
+ 	descriptor := self generatorAt: byte0.
+ 	self loadSubsequentBytesForDescriptor: descriptor at: bytecodePC.
+ 	^ descriptor
+ 	
+ 	!

Item was added:
+ ----- Method: Cogit>>nextBytecodePCFor:exts: (in category 'compile abstract instructions') -----
+ nextBytecodePCFor: descriptor exts: nExts
+ 	<inline: true>
+ 	<var: #descriptor type: #'BytecodeDescriptor *'>
+ 	 ^ self nextBytecodePCFor: descriptor at: bytecodePC exts: nExts in: methodObj!

Item was added:
+ ----- Method: Cogit>>patchFixupTargetIfNeeded:nextOpcodeIndex: (in category 'compile abstract instructions') -----
+ patchFixupTargetIfNeeded: fixup nextOpcodeIndex: nextOpcodeIndex
+ 	<var: #fixup type: #'BytecodeFixup *'>
+ 	<inline: true>
+ 	 fixup needsFixup ifTrue:
+ 		["There is a fixup for this bytecode.  It must point to the first generated
+ 		   instruction for this bytecode.  If there isn't one we need to add a label."
+ 		 opcodeIndex = nextOpcodeIndex ifTrue: [self Label].
+ 		 fixup targetInstruction: (self abstractInstructionAt: nextOpcodeIndex)].!

Item was added:
+ ----- Method: StackToRegisterMappingCogit>>assertCorrectSimStackPtr (in category 'compile abstract instructions') -----
+ assertCorrectSimStackPtr
+ 	<inline: true> "generates nothing anyway"
+ 	 self cCode: '' inSmalltalk:
+ 		[deadCode ifFalse:
+ 			[self assert: simStackPtr + (needsFrame ifTrue: [0] ifFalse: [1])
+ 						= (self debugStackPointerFor: bytecodePC)]].
+ 	!

Item was changed:
  ----- Method: StackToRegisterMappingCogit>>compileAbstractInstructionsFrom:through: (in category 'compile abstract instructions') -----
  compileAbstractInstructionsFrom: start through: end
  	"Loop over bytecodes, dispatching to the generator for each bytecode, handling fixups in due course."
  	| nextOpcodeIndex descriptor nExts fixup result |
  	<var: #descriptor type: #'BytecodeDescriptor *'>
  	<var: #fixup type: #'BytecodeFixup *'>
  	self traceSimStack.
  	bytecodePC := start.
+ 	nExts := result := 0.
- 	nExts := 0.
  	descriptor := nil.
  	deadCode := false.
+ 	[self cCode: '' inSmalltalk: [self isDebugPC ifTrue: [self halt]].
- 	[self cCode: '' inSmalltalk:
- 		[(debugBytecodePointers includes: bytecodePC) ifTrue: [self halt]].
  	 fixup := self fixupAt: bytecodePC - initialPC.
- 	 "If there's no fixup following a return there's no jump to that code and it is dead."
- 	 (descriptor notNil and: [descriptor isReturn]) ifTrue: [deadCode := true].
  	 self mergeWithFixupIfRequired: fixup.
+ 	 self assertCorrectSimStackPtr.
+ 	 descriptor := self loadBytesAndGetDescriptor.
- 	 self cCode: '' inSmalltalk:
- 		[deadCode ifFalse:
- 			[self assert: simStackPtr + (needsFrame ifTrue: [0] ifFalse: [1])
- 						= (self debugStackPointerFor: bytecodePC)]].
- 	 byte0 := (objectMemory fetchByte: bytecodePC ofObject: methodObj) + bytecodeSetOffset.
- 	 descriptor := self generatorAt: byte0.
- 	 self loadSubsequentBytesForDescriptor: descriptor at: bytecodePC.
  	 nextOpcodeIndex := opcodeIndex.
  	 result := deadCode
+ 				ifTrue: [self mapDeadDescriptorIfNeeded: descriptor]
+ 				ifFalse: [self perform: descriptor generator].
+ 	 self assertExtsAreConsumed: descriptor.
- 				ifTrue: "insert nops for dead code that is mapped so that bc to mc mapping is not many to one"
- 					[(descriptor isMapped
- 					  or: [inBlock and: [descriptor isMappedInBlock]]) ifTrue:
- 						[self annotateBytecode: self Nop].
- 						0]
- 				ifFalse:
- 					[self perform: descriptor generator].
- 	 descriptor isExtension ifFalse: "extended bytecodes must consume their extensions"
- 		[self assert: (extA = 0 and: [extB = 0])].
  	 self traceDescriptor: descriptor; traceSimStack.
+ 	 self patchFixupTargetIfNeeded: fixup nextOpcodeIndex: nextOpcodeIndex.
- 	 fixup needsFixup ifTrue:
- 		["There is a fixup for this bytecode.  It must point to the first generated
- 		   instruction for this bytecode.  If there isn't one we need to add a label."
- 		 opcodeIndex = nextOpcodeIndex ifTrue: [self Label].
- 		 fixup targetInstruction: (self abstractInstructionAt: nextOpcodeIndex)].
  	 self maybeDumpLiterals: descriptor.
+ 	 bytecodePC := self nextBytecodePCFor: descriptor exts: nExts.
- 	 bytecodePC := self nextBytecodePCFor: descriptor at: bytecodePC exts: nExts in: methodObj.
  	 result = 0 and: [bytecodePC <= end]] whileTrue:
  		[nExts := descriptor isExtension ifTrue: [nExts + 1] ifFalse: [0]].
  	self checkEnoughOpcodes.
  	^result!

Item was changed:
  ----- Method: StackToRegisterMappingCogit>>genUpArrowReturn (in category 'bytecode generators') -----
  genUpArrowReturn
  	"Generate a method return from within a method or a block.
  	 Frameless method activation looks like
  	 CISCs (x86):
  				receiver
  				args
  		sp->	ret pc.
  	 RISCs (ARM):
  				receiver
  				args
  				ret pc in LR.
  	 A fully framed activation is described in CoInterpreter class>initializeFrameIndices.
  	 Return pops receiver and arguments off the stack.  Callee pushes the result."
+ 	deadCode := true. "can't fall through"
  	inBlock ifTrue:
  		[self assert: needsFrame. 
  		 self CallRT: ceNonLocalReturnTrampoline.
  		 self annotateBytecode: self Label.
  		 ^0].
  	needsFrame
  		ifTrue:
  			[self MoveR: FPReg R: SPReg.
  			 self PopR: FPReg.
  			 backEnd hasLinkRegister ifTrue:
  				[self PopR: LinkReg].
  			 self RetN: methodOrBlockNumArgs + 1 * objectMemory wordSize]
  		ifFalse:
  			[self RetN: ((methodOrBlockNumArgs > self numRegArgs
  						"A method with an interpreter prim will push its register args for the prim.  If the failure
  						 body is frameless the args must still be popped, see e.g. Behavior>>nextInstance."
  						or: [regArgsHaveBeenPushed])
  							ifTrue: [methodOrBlockNumArgs + 1 * objectMemory wordSize]
  							ifFalse: [0])].
- 	deadCode := true. "can't fall through"
  	^0!

Item was added:
+ ----- Method: StackToRegisterMappingCogit>>mapDeadDescriptorIfNeeded: (in category 'compile abstract instructions') -----
+ mapDeadDescriptorIfNeeded: descriptor 
+ 	"insert nops for dead code that is mapped so that bc 
+ 	 to mc mapping is not many to one"
+ 	<var: #descriptor type: #'BytecodeDescriptor *'>
+ 	self flag: #annotateInstruction .
+ 	(descriptor isMapped
+ 		or: [inBlock and: [descriptor isMappedInBlock]]) 
+ 		ifTrue: [self annotateBytecode: self Nop].
+ 	^ 0!



More information about the Vm-dev mailing list