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

CLASS_FINALIZER =

The Proc object called by the garbage collector to free resources used by LLVM.

Proc.new { |id| Bindings.dispose_pass_manager(ptr) if ptr = ObjectSpace._id2ref(id).ptr }
PASSES =

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

{
	:ADCE               => :aggressive_dce,
	:AlwaysInline       => :always_inliner,
	:ArgPromote         => :argument_promotion,
	:BasicAliasAnalysis => :basic_alias_analysis,
	:BBVectorize        => :bb_vectorize,
	: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,
	:LoopReroll         => :loop_reroll,
	:LoopRotate         => :loop_rotate,
	:LoopUnroll         => :loop_unroll,
	:LoopUnswitch       => :loop_unswitch,
	:LoopVectorize      => :loop_vectorize,
	:LEI                => :lower_expect_intrinsics,
	:MemCopyOpt         => :mem_cpy_opt,
	:PILC               => :partially_inline_lib_calls,
	:PromoteMemToReg    => :promote_memory_to_register,
	:PruneEH            => :prune_eh,
	:Reassociate        => :reassociate,
	:SCCP               => :sccp,
	:ScalarRepl         => :scalar_repl_aggregates,
	:SimplifyLibCalls   => :simplify_lib_calls,
	:SLPVectorize       => :slp_vectorize,
	: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:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rltk/cg/pass_manager.rb', line 86

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
	
	# Define a finalizer to free the memory used by LLVM for this
	# pass manager.
	ObjectSpace.define_finalizer(self, CLASS_FINALIZER)
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:



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

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

#enabledArray<Symbol>

Returns List of passes that have been enabled.

Returns:

  • (Array<Symbol>)

    List of passes that have been enabled.



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

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.



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

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.



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

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:



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

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