Class: RLTK::CG::PassManager

Inherits:
Object
  • Object
show all
Includes:
BindingClass
Defined in:
lib/rltk/cg/pass_manager.rb

Overview

A PassManager is responsible for scheduling and running optimization passes on modules.

Direct Known Subclasses

FunctionPassManager

Constant Summary collapse

PASSES =

A list of passes that are available to be added to the pass manager via the #add method.

{
	:ADCE			=> :agressive_dce,
	:AlwaysInline		=> :always_inliner,
	:ArgPromote		=> :argument_promotion,
	:BasicAliasAnalysis	=> :basic_alias_analysis,
	:CFGSimplify		=> :cfg_simplification,
	:ConstMerge		=> :constant_merge,
	:ConstProp		=> :constant_propagation,
	:CorValProp		=> :correlated_value_propagation,
	:DAE				=> :dead_arg_elimination,
	:DSE				=> :dead_store_elimination,
	:DemoteMemToReg	=> :demote_memory_to_register,
	:EarlyCSE			=> :early_cse,
	:FunctionAttrs		=> :function_attrs,
	:FunctionInline	=> :function_inlining,
	:GDCE			=> :global_dce,
	:GlobalOpt		=> :global_optimizer,
	:GVN				=> :gvn,
	:Internalize		=> :internalize,
	:IndVarSimplify	=> :ind_var_simplify,
	:InstCombine		=> :instruction_combining,
	:IPConstProp		=> :ip_constant_propagation,
	:IPSCCP			=> :ipsccp,
	:JumpThreading		=> :jump_threading,
	:LICM			=> :licm,
	:LoopDeletion		=> :loop_deletion,
	:LoopIdiom		=> :loop_idiom,
	:LoopRotate		=> :loop_rotate,
	:LoopUnroll		=> :loop_unroll,
	:LoopUnswitch		=> :loop_unswitch,
	:LEI				=> :lower_expect_intrinsics,
	:MemCopyOpt		=> :mem_cpy_opt,
	:PromoteMemToReg	=> :promote_memory_to_register,
	:PruneEH			=> :prune_eh,
	:Reassociate		=> :reassociate,
	:SCCP			=> :sccp,
	:ScalarRepl		=> :scalar_repl_aggregates,
	:SimplifyLibCalls	=> :simplify_lib_calls,
	:StripDeadProtos	=> :strip_dead_prototypes,
	:StripSymbols		=> :strip_symbols,
	:TailCallElim		=> :tail_call_elimination,
	:TBAA			=> :type_based_alias_analysis,
	:Verifier			=> :verifier
}

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods included from BindingClass

#==

Constructor Details

#initialize(mod) ⇒ PassManager

Create a new pass manager. You should never have to do this as Modules should create PassManagers for you whenever they are requested.

Parameters:

  • mod (Module)

    Module this pass manager belongs to.

See Also:



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rltk/cg/pass_manager.rb', line 78

def initialize(mod)
	# LLVM Initialization
	@ptr = Bindings.create_pass_manager
	@mod = mod
	
	# Set the target data if the module is associated with a execution engine.
	self.target_data = mod.engine.target_data if mod.engine
	
	# RLTK Initialization
	@enabled = Array.new
end

Instance Method Details

#add(*names) ⇒ PassManager Also known as: <<

Add a pass or passes to this pass manager. Passes may either be specified via the keys for the PASSES hash or any string that will be turned into a string (via the Bindings.get_bname method) appearing as a value of the PASSES hash.

Parameters:

  • names (Array<Symbol>)

    Passes to add to the pass manager.

Returns:

See Also:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rltk/cg/pass_manager.rb', line 113

def add(*names)
	names.each do |name|
		name = name.to_sym
		
		if PASSES.has_key?(name)
			next if @enabled.include?(name)
		
			Bindings.send("add_#{PASSES[name]}_pass", @ptr)
		
			@enabled << name
		
		elsif PASSES.has_value?(bname = Bindings.get_bname(name))
			next if @enabled.include?(PASSES.key(bname))
		
			Bindings.send("add_#{bname}_pass", @ptr)
		
			@enabled << PASSES.key(bname)
		
		else
			raise "Unknown pass: #{name}"
		end
	end
	
	self
end

#disposevoid

This method returns an undefined value.

Frees the resources used by LLVM for this pass manager.



93
94
95
96
97
98
99
100
101
# File 'lib/rltk/cg/pass_manager.rb', line 93

def dispose
	if @ptr
		self.finalize
		
		Bindings.dispose_pass_manager(@ptr)
		
		@ptr = nil
	end
end

#enabledArray<Symbol>

Returns List of passes that have been enabled.

Returns:

  • (Array<Symbol>)

    List of passes that have been enabled.



141
142
143
# File 'lib/rltk/cg/pass_manager.rb', line 141

def enabled
	@enabled.clone
end

#enabled?(name) ⇒ Boolean

Returns Weather the pass has been enabled or not.

Returns:

  • (Boolean)

    Weather the pass has been enabled or not.



146
147
148
# File 'lib/rltk/cg/pass_manager.rb', line 146

def enabled?(name)
	@enabled.include?(name) or @enabled.include?(PASSES.key(Bindings.get_bname(name)))
end

#runvoid

This method returns an undefined value.

Run the enabled passes on the execution engine’s module.



153
154
155
# File 'lib/rltk/cg/pass_manager.rb', line 153

def run
	Bindings.run_pass_manager(@ptr, @mod).to_bool
end

#target_data=(data) ⇒ void

This method returns an undefined value.

Set the target data for this pass manager.

Parameters:



162
163
164
# File 'lib/rltk/cg/pass_manager.rb', line 162

def target_data=(data)
	Bindings.add_target_data(check_type(data, TargetData, 'data'), @ptr)
end