pub struct InsertBuilder<'f, IIB: InstInserterBase<'f>> { /* private fields */ }
Expand description

Builder that inserts an instruction at the current position.

An InsertBuilder is a wrapper for an InstInserterBase that turns it into an instruction builder with some additional facilities for creating instructions that reuse existing values as their results.

Implementations§

Create a new builder which inserts instructions at pos. The dfg and pos.layout references should be from the same Function.

Examples found in repository?
src/cursor.rs (line 597)
596
597
598
    pub fn ins(&mut self) -> ir::InsertBuilder<&mut FuncCursor<'f>> {
        ir::InsertBuilder::new(self)
    }

Reuse result values in reuse.

Convert this builder into one that will reuse the provided result values instead of allocating new ones. The provided values for reuse must not be attached to anything. Any missing result values will be allocated as normal.

The reuse argument is expected to be an array of Option<Value>.

Examples found in repository?
src/ir/builder.rs (line 112)
109
110
111
112
113
    pub fn with_result(self, v: Value) -> InsertReuseBuilder<'f, IIB, [Option<Value>; 1]> {
        // TODO: Specialize this to return a different builder that just attaches `v` instead of
        // calling `make_inst_results_reusing()`.
        self.with_results([Some(v)])
    }

Reuse a single result value.

Convert this into a builder that will reuse v as the single result value. The reused result value v must not be attached to anything.

This method should only be used when building an instruction with exactly one result. Use with_results() for the more general case.

Examples found in repository?
src/nan_canonicalization.rs (line 69)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst) {
    // Select the instruction result, result type. Replace the instruction
    // result and step forward before inserting the canonicalization sequence.
    let val = pos.func.dfg.first_result(inst);
    let val_type = pos.func.dfg.value_type(val);
    let new_res = pos.func.dfg.replace_result(val, val_type);
    let _next_inst = pos.next_inst().expect("block missing terminator!");

    // Insert a comparison instruction, to check if `inst_res` is NaN. Select
    // the canonical NaN value if `val` is NaN, assign the result to `inst`.
    let is_nan = pos.ins().fcmp(FloatCC::NotEqual, new_res, new_res);

    let scalar_select = |pos: &mut FuncCursor, canon_nan: Value| {
        pos.ins()
            .with_result(val)
            .select(is_nan, canon_nan, new_res);
    };
    let vector_select = |pos: &mut FuncCursor, canon_nan: Value| {
        pos.ins()
            .with_result(val)
            .vselect(is_nan, canon_nan, new_res);
    };

    match val_type {
        types::F32 => {
            let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
            scalar_select(pos, canon_nan);
        }
        types::F64 => {
            let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
            scalar_select(pos, canon_nan);
        }
        types::F32X4 => {
            let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
            let canon_nan = pos.ins().splat(types::F32X4, canon_nan);
            vector_select(pos, canon_nan);
        }
        types::F64X2 => {
            let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
            let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
            vector_select(pos, canon_nan);
        }
        _ => {
            // Panic if the type given was not an IEEE floating point type.
            panic!("Could not canonicalize NaN: Unexpected result type found.");
        }
    }

    pos.prev_inst(); // Step backwards so the pass does not skip instructions.
}

Trait Implementations§

Get an immutable reference to the data flow graph that will hold the constructed instructions.
Get a mutable reference to the data flow graph that will hold the constructed instructions.
Insert an instruction and return a reference to it, consuming the builder. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.