Recursively rename each variable from block

block The starting basic block counter The key is the variable, the value the number of assignment into the variable

Property definitions

nitc :: ssa $ APropdef :: rename
	# Recursively rename each variable from `block`
	# *`block` The starting basic block
	# *`counter` The key is the variable, the value the number of assignment into the variable
	fun rename(block: BasicBlock, counter: HashMap[Variable, Int], ssa: SSA)
	do
		if block.is_renaming then return

		block.is_renaming = true

		# For each phi-function of this block
		for phi in block.phi_functions do
			generate_name(phi, counter, block.first, ssa)

			# Replace the phi into the block
			block.phi_functions[block.phi_functions.index_of(phi)] = phi.original_variable.stack.last.as(PhiFunction)
		end

		# For each variable read in `block`
		for vread in block.read_sites do
			# Replace the old variable in AST
			vread.variable = vread.variable.original_variable.stack.last
		end

		# For each variable write
		for vwrite in block.write_sites do
			generate_name(vwrite.variable.as(not null), counter, vwrite, ssa)

			var new_version = vwrite.variable.original_variable.stack.last

			# Set dependence of the new variable
			if vwrite isa AVarReassignExpr then
				new_version.dep_exprs.add(vwrite.n_value)
			else if vwrite isa AVarAssignExpr then
				new_version.dep_exprs.add(vwrite.n_value)
			end

			# Replace the old variable by the last created
			vwrite.variable = new_version
		end

		# Rename occurrence of old names in phi-function
		for successor in block.dominance_frontier do
			for sphi in successor.phi_functions do
				# Go over the couples in the phi dependences to rename variables
				for couple in sphi.dependences do
					if couple.second == block then
						# Rename this variable
						couple.first = couple.first.original_variable.stack.last
					end
				end
			end
		end

		# Recurse in successor blocks
		for successor in block.successors do
			rename(successor, counter, ssa)
		end

		# Pop old names off the stack for each phi-function
		for phi in block.phi_functions do
			if not phi.stack.is_empty then phi.stack.pop
		end
	end
src/ssa.nit:311,2--373,4