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
| @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)
|
Source code in xdsl/transforms/x86_regalloc_legalize.py
| 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)
|