class RLTK::CG::PassManager
A PassManager
is responsible for scheduling and running optimization passes on modules.
Constants
- CLASS_FINALIZER
The Proc object called by the garbage collector to free resources used by
LLVM
.- PASSES
A list of passes that are available to be added to the pass manager via the {PassManager#add} method.
Public Class Methods
Create a new pass manager. You should never have to do this as {Module Modules} should create PassManagers for you whenever they are requested.
@see Module#pass_manager
@param [Module] mod Module
this pass manager belongs to.
# 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
Public Instance Methods
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.
@see PASSES
@param [Array<Symbol>] names Passes to add to the pass manager.
@return [PassManager] self
# 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
@return [Array<Symbol>] List of passes that have been enabled.
# File lib/rltk/cg/pass_manager.rb, line 140 def enabled @enabled.clone end
@return [Boolean] Weather the pass has been enabled or not.
# 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
Run the enabled passes on the execution engine’s module.
@return [void]
# File lib/rltk/cg/pass_manager.rb, line 152 def run Bindings.run_pass_manager(@ptr, @mod).to_bool end
Set the target data for this pass manager.
@param [TargetData] data
@return [void]
# File lib/rltk/cg/pass_manager.rb, line 161 def target_data=(data) Bindings.add_target_data(check_type(data, TargetData, 'data'), @ptr) end
Protected Instance Methods
Empty method used by {FunctionPassManager} to clean up resources.
# File lib/rltk/cg/pass_manager.rb, line 167 def finalize end