class RCGTK::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

new(mod) click to toggle source

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/rcgtk/pass_manager.rb, line 88
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

<<(*names)
Alias for: add
add(*names) click to toggle source

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/rcgtk/pass_manager.rb, line 114
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
Also aliased as: <<
enabled() click to toggle source

@return [Array<Symbol>] List of passes that have been enabled.

# File lib/rcgtk/pass_manager.rb, line 142
def enabled
        @enabled.clone
end
enabled?(name) click to toggle source

@return [Boolean] Whether the pass has been enabled or not.

# File lib/rcgtk/pass_manager.rb, line 147
def enabled?(name)
        @enabled.include?(name) or @enabled.include?(PASSES.key(Bindings.get_bname(name)))
end
run() click to toggle source

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

@return [void]

# File lib/rcgtk/pass_manager.rb, line 154
def run
        Bindings.run_pass_manager(@ptr, @mod).to_bool
end
target_data=(data) click to toggle source

Set the target data for this pass manager.

@param [TargetData] data

@return [void]

# File lib/rcgtk/pass_manager.rb, line 163
def target_data=(data)
        Bindings.add_target_data(check_type(data, TargetData, 'data'), @ptr)
end

Protected Instance Methods

finalize() click to toggle source

Empty method used by {FunctionPassManager} to clean up resources.

# File lib/rcgtk/pass_manager.rb, line 169
def finalize
end