Skip to content

X86 regalloc legalize

x86_regalloc_legalize

X86RegallocLegalizePass dataclass

Bases: ModulePass

Legalize x86 code before register allocation by inserting copies when an inout use is not the last use of a value.

Source code in xdsl/transforms/x86_regalloc_legalize.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@dataclass(frozen=True)
class X86RegallocLegalizePass(ModulePass):
    """
    Legalize x86 code before register allocation by inserting copies when an
    inout use is not the last use of a value.
    """

    name = "x86-regalloc-legalize"
    arch: str | None = None

    def apply(self, ctx: Context, op: builtin.ModuleOp) -> None:
        arch = X86Arch.arch_for_name(self.arch)
        for func in op.walk():
            if not isinstance(func, x86_func.FuncOp):
                continue
            if not func.body.blocks:
                # External declaration
                continue
            if len(func.body.blocks) != 1:
                raise PassFailedException(
                    "Cannot yet legalize func with multiple blocks."
                )
            legalize_ctx = LegalizationContext(
                set(),
                arch,
                Builder(InsertPoint.at_end(func.body.block)),
            )
            legalize_ctx.process_block(func.body.block)

name = 'x86-regalloc-legalize' class-attribute instance-attribute

arch: str | None = None class-attribute instance-attribute

__init__(arch: str | None = None) -> None

apply(ctx: Context, op: builtin.ModuleOp) -> None

Source code in xdsl/transforms/x86_regalloc_legalize.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def apply(self, ctx: Context, op: builtin.ModuleOp) -> None:
    arch = X86Arch.arch_for_name(self.arch)
    for func in op.walk():
        if not isinstance(func, x86_func.FuncOp):
            continue
        if not func.body.blocks:
            # External declaration
            continue
        if len(func.body.blocks) != 1:
            raise PassFailedException(
                "Cannot yet legalize func with multiple blocks."
            )
        legalize_ctx = LegalizationContext(
            set(),
            arch,
            Builder(InsertPoint.at_end(func.body.block)),
        )
        legalize_ctx.process_block(func.body.block)