Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3419
Browse files Browse the repository at this point in the history
Now that <inline: #always> is less affected by a less capricious inliner use
it to shed code from the generated BitBlt plugin, and the cogits.

Slang:
Change the record of inlining phase so that it is known when inlining has yet
to start, has started, and has finished, instead of only having begun or not.
Refactor the doFinalValidationsAndTransformations and make sure it is done
along all inlining code paths. Pull the check for required inlinability out of
inlineableFunctionCall:in: & inlineableSend:in: and into
doFinalValidationsAndTransformationsIn: where it is only performed once
inlining has finished.

Fix isFunctionalIn:. Fix the bug in hasReturnOnlyAtEnd that failed to find
returns with the blocks of a returning if that didn't come at the end of
those blocks.
Fix TStmtListNode>>#copyWithoutReturn to handle trailing returning if's
correctly.
Fix TStmtListNode>>#replaceNodesIn: to flatten inlined statement lists.
  • Loading branch information
eliotmiranda committed Jul 27, 2024
1 parent 277402c commit d87a39d
Show file tree
Hide file tree
Showing 81 changed files with 34,979 additions and 2,041 deletions.
2 changes: 1 addition & 1 deletion image/Slang Test Workspace.text
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"Here are some doits to get Slang to generate a single method to the transcript"CCodeGenerator classPool at: #BreakSrcSelectors put: nil.[Transcript show: [| sel vmm s cg | sel := #scavenge:. vmm := (VMMaker forPlatform: 'Cross') interpreterClass: StackInterpreter; options: #(ObjectMemory Spur64BitCoMemoryManager). cg := [vmm buildCodeGeneratorForInterpreter] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. "to break at inlining decisions or type inferrence uncomment the following. If src & dest are different selectors, breaks on inlining. If src & dest are the same selector, breaks on type inference in sel." "cg breakSrcInlineSelector: sel; breakDestInlineSelector: sel; breakOnInline: false". cg vmClass preGenerationHook: cg. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { sel }. cg prepareMethods. ((sel beginsWith: 'bytecode') or: [sel endsWith: 'Bytecode']) ifTrue: [cg doBasicInlining: true] ifFalse: [cg doInlining: true]. s := ReadWriteStream on: String new. (cg methodNamed: sel) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| sel vmm s cg | sel := #checkForEventsMayContextSwitch:"populate:from:to:". CCodeGenerator classPool at: #BreakSrcSelectors put: #(checkForEventsMayContextSwitch: checkInvokeIOProcessEvents:). vmm := (VMMaker forPlatform: 'Cross') interpreterClass: CoInterpreterMT; options: #(COGMTVM true ObjectMemory Spur64BitCoMemoryManager MULTIPLEBYTECODESETS true), {#Cogit. Cogit chooseCogitClass name}. cg := [vmm buildCodeGeneratorForInterpreter] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. cg vmClass preGenerationHook: cg. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { sel }. cg prepareMethods. ((sel beginsWith: 'bytecode') or: [sel endsWith: 'Bytecode']) ifTrue: [cg doBasicInlining: true] ifFalse: [cg doInlining: true]. s := ReadWriteStream on: String new. (cg methodNamed: sel) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| sel s vmm cg | sel := #compileEntry. vmm := VMMaker forPlatform: 'Cross'. cg := [vmm interpreterClass: CoInterpreter; options: {#Cogit. Cogit chooseCogitClass name}; buildCodeGeneratorForCogit] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. cg vmClass preGenerationHook: cg. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { #compactCogCompiledCode. sel }. cg prepareMethods. cg doInlining: cg vmClass doInlining. s := ReadWriteStream on: String new. (cg methodNamed: sel) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| tm s vmm cg | vmm := VMMaker forPlatform: 'Cross'. cg := [vmm interpreterClass: StackInterpreter; buildCodeGeneratorForInterpreter] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. cg vmClass preGenerationHook: cg. tm := (StackInterpreter compile: 'foo self cppIf: ''ARBITRARY'' ifTrue: [self cCode: ''arbi''] ifFalse: [self cCode: ''trary'']. self cppIf: (self cCode: ''ARBITRARY'') ifTrue: [self cCode: ''arbi''] ifFalse: [self cCode: ''trary'']' classified: nil notifying: nil trailer: CompiledMethodTrailer empty ifFail: []) node asTranslationMethodOfClass: cg translationMethodClass. cg addMethod: tm. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { #foo }. cg prepareMethods. cg doInlining: true. s := ReadWriteStream on: String new. (cg methodNamed: #foo) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| plugin sel s vmm cg | plugin := "ThreadedARM64FFIPlugin"UnixOSProcessPlugin. sel := #"primitiveCallout"setSignalNumber:handler:. vmm := VMMaker forPlatform: 'Cross'. cg := [plugin buildCodeGenerator] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. cg breakSrcInlineSelector: #cdigitMontgomery:len:times:len:modulo:len:mInvModB:into:; breakDestInlineSelector: sel; breakOnInline: "false"true. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { sel }. cg prepareMethods. cg doInlining: true. s := ReadWriteStream on: String new. (cg anyMethodNamed: sel) removeUnusedTempsAndNilIfRequiredIn: cg; halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| plugin s cg | plugin := FileCopyPlugin"UnixOSProcessPlugin". cg := plugin buildCodeGenerator. cg inferTypesForImplicitlyTypedVariablesAndMethods. plugin pruneUnusedInterpreterPluginMethodsIn: cg. s := ReadWriteStream on: String new. cg emitCCodeOn: s doInlining: true doAssertions: false. s contents] value].[| cg |cg := BitBltSimulation buildCodeGeneratorUpTo: BitBltSimulation.cg inferTypesForImplicitlyTypedVariablesAndMethods].
"Here are some doits to get Slang to generate a single method to the transcript"CCodeGenerator classPool at: #BreakSrcSelectors put: nil.[Transcript show: [| sel vmm s cg | sel := #interpret. vmm := (VMMaker forPlatform: 'Cross') interpreterClass: CoInterpreter; options: #(ObjectMemory Spur64BitCoMemoryManager MULTIPLEBYTECODESETS true). cg := [vmm buildCodeGeneratorForInterpreter] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. "to break at inlining decisions or type inferrence uncomment the following. If src & dest are different selectors, breaks on inlining. If src & dest are the same selector, breaks on type inference in sel." cg breakSrcInlineSelector: #commonSendOrdinary; breakSrcInlineSelector: #normalSend; breakSrcInlineSelector: #singleExtendedSendBytecode; breakDestInlineSelector: sel; breakOnInline: #access"true". cg vmClass preGenerationHook: cg. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { sel }. cg prepareMethods. ((sel beginsWith: 'bytecode') or: [sel endsWith: 'Bytecode']) ifTrue: [cg doBasicInlining: true] ifFalse: [cg doInlining: true]. s := ReadWriteStream on: String new. (cg methodNamed: sel) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| sel vmm s cg | sel := #primitiveFullGC"populate:from:to:". "CCodeGenerator classPool at: #BreakSrcSelectors put: #(checkForEventsMayContextSwitch: checkInvokeIOProcessEvents:)." vmm := (VMMaker forPlatform: 'Cross') interpreterClass: CoInterpreterMT; options: #(COGMTVM true ObjectMemory Spur64BitCoMemoryManager MULTIPLEBYTECODESETS true), {#Cogit. Cogit chooseCogitClass name}. cg := [vmm buildCodeGeneratorForInterpreter] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. cg vmClass preGenerationHook: cg. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { sel }. cg prepareMethods. ((sel beginsWith: 'bytecode') or: [sel endsWith: 'Bytecode']) ifTrue: [cg doBasicInlining: true] ifFalse: [cg doInlining: true]. s := ReadWriteStream on: String new. (cg methodNamed: sel) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| sel s vmm cg | sel := #genLoadCStackPointer. vmm := VMMaker forPlatform: 'Cross'. cg := [vmm interpreterClass: CoInterpreter; options: {#Cogit. Cogit chooseCogitClass name}, {#ISA. Cogit choose64BitISA}, #(ObjectMemory Spur64BitCoMemoryManager MULTIPLEBYTECODESETS true); buildCodeGeneratorForCogit] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. "to break at inlining decisions or type inferrence uncomment the following. If src & dest are different selectors, breaks on inlining. If src & dest are the same selector, breaks on type inference in sel." cg breakSrcInlineSelector: #checkLiteral:forInstruction:; breakSrcInlineSelector: #gen:literal:operand:; breakDestInlineSelector: #MoveAw:R:; breakDestInlineSelector: sel; breakOnInline: true. cg vmClass preGenerationHook: cg. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { #compactCogCompiledCode. sel }. cg prepareMethods. cg doInlining: cg vmClass doInlining. s := ReadWriteStream on: String new. (cg methodNamed: sel) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| tm s vmm cg | vmm := VMMaker forPlatform: 'Cross'. cg := [vmm interpreterClass: StackInterpreter; buildCodeGeneratorForInterpreter] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. cg vmClass preGenerationHook: cg. tm := (StackInterpreter compile: 'foo self cppIf: ''ARBITRARY'' ifTrue: [self cCode: ''arbi''] ifFalse: [self cCode: ''trary'']. self cppIf: (self cCode: ''ARBITRARY'') ifTrue: [self cCode: ''arbi''] ifFalse: [self cCode: ''trary'']' classified: nil notifying: nil trailer: CompiledMethodTrailer empty ifFail: []) node asTranslationMethodOfClass: cg translationMethodClass. cg addMethod: tm. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { #foo }. cg prepareMethods. cg doInlining: true. s := ReadWriteStream on: String new. (cg methodNamed: #foo) halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| plugin sel s vmm cg | plugin := "ThreadedARM64FFIPlugin"UnixOSProcessPlugin. sel := #"primitiveCallout"setSignalNumber:handler:. vmm := VMMaker forPlatform: 'Cross'. cg := [plugin buildCodeGenerator] on: Notification do: [:ex| ex tag == #getVMMaker ifTrue: [ex resume: vmm] ifFalse: [ex pass]]. cg breakSrcInlineSelector: #cdigitMontgomery:len:times:len:modulo:len:mInvModB:into:; breakDestInlineSelector: sel; breakOnInline: "false"true. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg retainMethods: { sel }. cg prepareMethods. cg doInlining: true. s := ReadWriteStream on: String new. (cg anyMethodNamed: sel) removeUnusedTempsAndNilIfRequiredIn: cg; halt; emitCCodeOn: s generator: cg. s contents] value].[Transcript show: [| plugin s cg | plugin := "FileCopyPlugin"UnixOSProcessPlugin. cg := plugin buildCodeGenerator. cg breakSrcInlineSelector: #sendSignal:toPid:; breakDestInlineSelector: #sendSignalToPids; breakOnInline: true. cg inferTypesForImplicitlyTypedVariablesAndMethods. cg doInlining: true. plugin pruneUnusedInterpreterPluginMethodsIn: cg. s := ReadWriteStream on: String new. #sendSignalToPids ifNotNil: [:sel| (cg methodNamed: sel) halt emitCCodeOn: s generator: cg] ifNil: [cg emitCCodeOn: s doInlining: true doAssertions: false]. s contents] value].[| cg |cg := BalloonEnginePlugin buildCodeGenerator.cg breakSrcInlineSelector: #getUsedPut:; breakDestInlineSelector: #addEdgeToGET:; breakOnInline: true.cg inferTypesForImplicitlyTypedVariablesAndMethods.cg doInlining: true.Transcript show: (String streamContents: [:s| (cg methodNamed: #addEdgeToGET:) halt; emitCCodeOn: s generator: cg])] on: TMethodValidationNotification do: [:ex| ex halt].[| cg |cg := ThreadedX64SysVFFIPlugin buildCodeGenerator.cg breakSrcInlineSelector: #ffiSupportsCallingConvention:; breakDestInlineSelector: #ffiCall:ArgArrayOrNil:NumArgs:; breakOnInline: true.cg inferTypesForImplicitlyTypedVariablesAndMethods.cg doInlining: true.Transcript show: (String streamContents: [:s| (cg methodNamed: #ffiCall:ArgArrayOrNil:NumArgs:"loadBitBltFrom:warping:") halt; emitCCodeOn: s generator: cg])] on: TMethodValidationNotification do: [:ex| ex halt].
Expand Down
Loading

0 comments on commit d87a39d

Please sign in to comment.