Eliot Miranda uploaded a new version of Cog to project VM Maker: http://source.squeak.org/VMMaker/Cog-eem.352.mcz ==================== Summary ==================== Name: Cog-eem.352 Author: eem Time: 14 January 2019, 8:25:40.537264 am UUID: c49bb105-3542-4a92-868f-1def30bf3e4c Ancestors: Cog-eem.351 Add a method that decides, using bytecode dominator discovery, if a method contains an optimized conditional used as either a message receiver or parameter, or a value to store or return. =============== Diff against Cog-eem.351 =============== Item was added: + ----- Method: DominatorFinder class>>containsOptimizedConditionalExpressionValue: (in category 'exploration') ----- + containsOptimizedConditionalExpressionValue: aCompiledMethod + "Answer if aCompiledMethod contains an optimized conditional expression which + is used as either a message receiver or parameter, or a value to store or return." + [:dominatingNodes + :anomalousNodes + :dominatedNodes + :dominatorMap + :newMethod| | encoderClass | + ^dominatorMap notEmpty + and: [(encoderClass := newMethod encoderClass) supportsFullBlocks + ifFalse: "simple; can look at the single method object" + [| sps | + sps := (StackDepthFinder on: newMethod) stackPointers. + dominatorMap associations anySatisfy: + [:a| "Filter out expr ifTrue: [...] ifFalse: [...]. Both arms share a single pop" + (encoderClass isJustPopAt: a value in: newMethod) not + and: [(sps at: a key) <= (sps at: a value)]]] + ifTrue: "complex; have to locate the reelevant sub-method" + [| asps | + asps := (StackDepthFinder on: newMethod) allStackPointers. + dominatorMap associations anySatisfy: + [:a| | dpc sps m | + a key isInteger + ifTrue: + [dpc := a key. + m := newMethod] + ifFalse: + [dpc := a key value. + m := a key key]. + sps := asps at: m. + "Filter out expr ifTrue: [...] ifFalse: [...]. Both arms share a single pop" + (encoderClass isJustPopAt: a value in: m) not + and: [(sps at: dpc) <= (sps at: a value)]]]]] + valueWithArguments: (self dominatorTupleForMethod: aCompiledMethod)! Item was changed: ----- Method: DominatorFinder class>>dominatorTupleForMethod: (in category 'exploration') ----- dominatorTupleForMethod: aCompiledMethod "Answer a tuple of dominating optimized nodes, (inlined if's that are found by DominatorFinder) anomalous optimized nodes, (inlined if's that are not found by DominatorFinder) dominated nodes, (inlined if's nested within other inlined if's that occur at the end of a basic block and hence jump to the same place as their parent) dominator pcs (the dominator pcs found by the DominatorFinder) + recompiled method for aCompiledMethod. It is expected that the anomaloius nodes should be empty." | mn optimizedNodes dominators offenders dominated dominatorPCs | + aCompiledMethod isQuick ifTrue: + [^#(#() #() #() #() #())]. mn := CompiledMethod noCheckSetPreferredBytecodeSetTo: aCompiledMethod encoderClass while: [[:c :s| [c compile:(c sourceCodeAt: s) environment: c environment notifying: nil trailer: aCompiledMethod trailer ifFail: [nil]] on: SyntaxErrorNotification + do: [^#(#() #() #() #() #())]] - do: [^#(#() #() #() #())]] value: aCompiledMethod methodClass value: aCompiledMethod selector]. "mn method ~= aCompiledMethod ifTrue: [Transcript cr; show: 'warning: recompilation of ', aCompiledMethod reference, ' generated different code'. + ^#(#() #() #() #() #())]." - ^#(#() #() #() #())]." dominatorPCs := (self on: mn method) dominators. dominated := IdentitySet new. "The last statement of an inlined if cannot dominate the join of its enclosing if" optimizedNodes := OrderedCollection new. "Avoid double traversal" mn node nodesDo: [:n| | lastStatement | (n isMessage and: [n isOptimized]) ifTrue: [optimizedNodes addLast: n. n isOptimizedConditional ifTrue: [lastStatement := n lastBlockOfOptimizedConditional statements last. (lastStatement isMessage and: [lastStatement isOptimizedConditional]) ifTrue: [dominated add: lastStatement]]]]. dominators := OrderedCollection new: optimizedNodes size. offenders := OrderedCollection new: optimizedNodes size. optimizedNodes do: [:n| (n isOptimizedLoop not "Loop CBs do dominate, but their target is not a join point" and: [n isSingleReturningIf not "ifTrue: [^foo] CBs do dominate but their target is not a join point" and: [n isEmptyIf not "ifTrue: [] generates no code" and: [n pc ~= 0 "caseOf: nodes get assigned a pc of 0; go figure..." and: [(dominated includes: n) not]]]]) ifTrue: [((dominatorPCs at: n pc ifAbsent: nil) ifNil: [offenders] ifNotNil: [dominators]) addLast: n]]. + ^{ dominators. offenders. dominated. dominatorPCs. mn method }! - ^{ dominators. offenders. dominated. dominatorPCs }! Item was added: + ----- Method: DominatorFinder class>>exampleMethod (in category 'exploration') ----- + exampleMethod + "(StackDepthFinder on: DominatorFinder class >> #exampleMethod) stackPointers. + DominatorFinder dominatorTupleForMethod: DominatorFinder class >> #exampleMethod. + (DominatorFinder class >> #exampleMethod) detailedSymbolic" + self isCollection + ifTrue: [self at: 1] + ifFalse: [self at: 2]. + self at: (self isCollection ifTrue: [1] ifFalse: [2]) put: self! |
Free forum by Nabble | Edit this page |