2020-06-14 05:43:10 +08:00
|
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
|
|
|
|
from typing import *
|
2020-12-30 05:22:18 +08:00
|
|
|
from mlir import ir as _ir
|
|
|
|
|
|
|
|
from ..utils.mlir_utils import *
|
2020-06-14 05:43:10 +08:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
"GenericTarget32",
|
|
|
|
"GenericTarget64",
|
|
|
|
"Target",
|
|
|
|
"TargetFactory",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class Target:
|
|
|
|
"""
|
|
|
|
Abstract class providing configuration and hooks for a specific compilation
|
|
|
|
target.
|
|
|
|
"""
|
|
|
|
__slots__ = [
|
2020-12-30 05:22:18 +08:00
|
|
|
"ic",
|
2020-06-14 05:43:10 +08:00
|
|
|
]
|
|
|
|
|
2020-12-30 05:22:18 +08:00
|
|
|
def __init__(self, ic):
|
|
|
|
self.ic = ic
|
2020-06-14 05:43:10 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target_name(self) -> str:
|
|
|
|
return NotImplementedError()
|
|
|
|
|
|
|
|
@property
|
2020-12-30 05:22:18 +08:00
|
|
|
def impl_int_type(self) -> _ir.Type:
|
2020-06-14 05:43:10 +08:00
|
|
|
"""Gets the default int type for the backend for the Python 'int' type."""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
@property
|
2020-12-30 05:22:18 +08:00
|
|
|
def impl_float_type(self) -> _ir.Type:
|
2020-06-14 05:43:10 +08:00
|
|
|
"""Gets the implementation's type for the python 'float' type."""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
|
class GenericTarget64(Target):
|
|
|
|
"""A generic 64 bit target."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_name(self) -> str:
|
|
|
|
return "generic64"
|
|
|
|
|
|
|
|
@property
|
2020-12-30 05:22:18 +08:00
|
|
|
def impl_int_type(self) -> _ir.Type:
|
2020-06-14 05:43:10 +08:00
|
|
|
"""Gets the default int type for the backend for the Python 'int' type."""
|
2020-12-30 05:22:18 +08:00
|
|
|
return _ir.IntegerType.get_signless(64, context=self.ic.context)
|
2020-06-14 05:43:10 +08:00
|
|
|
|
|
|
|
@property
|
2020-12-30 05:22:18 +08:00
|
|
|
def impl_float_type(self) -> _ir.Type:
|
2020-06-14 05:43:10 +08:00
|
|
|
"""Gets the implementation's type for the python 'float' type."""
|
2020-12-30 05:22:18 +08:00
|
|
|
return _ir.F64Type.get(context=self.ic.context)
|
2020-06-14 05:43:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
class GenericTarget32(Target):
|
|
|
|
"""A generic 32 bit target (uses 32bit ints and floats)."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_name(self) -> str:
|
|
|
|
return "generic32"
|
|
|
|
|
|
|
|
@property
|
2020-12-30 05:22:18 +08:00
|
|
|
def impl_int_type(self) -> _ir.Type:
|
2020-06-14 05:43:10 +08:00
|
|
|
"""Gets the default int type for the backend for the Python 'int' type."""
|
2020-12-30 05:22:18 +08:00
|
|
|
return _ir.IntegerType.get_signless(32, context=self.ic.context)
|
2020-06-14 05:43:10 +08:00
|
|
|
|
|
|
|
@property
|
2020-12-30 05:22:18 +08:00
|
|
|
def impl_float_type(self) -> _ir.Type:
|
2020-06-14 05:43:10 +08:00
|
|
|
"""Gets the implementation's type for the python 'float' type."""
|
2020-12-30 05:22:18 +08:00
|
|
|
return _ir.F32Type.get(context=self.ic.context)
|
2020-06-14 05:43:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Factory for producing a target (matches the Target constructor).
|
2020-12-30 05:22:18 +08:00
|
|
|
TargetFactory = Callable[[ImportContext], Target]
|