1717"""Code generation related functions."""
1818from . import _ffi_api
1919from .target import Target
20+ from ..ir .container import Array
2021
2122
2223def build_module (mod , target ):
@@ -39,6 +40,30 @@ def build_module(mod, target):
3940 return _ffi_api .Build (mod , target )
4041
4142
43+ def target_has_features (cpu_features , target = None ):
44+ """Check CPU features for the target's `-mtriple` and `-mcpu` and `-mattr`.
45+
46+ Parameters
47+ ----------
48+ target : Target
49+ The TVM target.
50+ cpu_features : str or Array
51+ CPU Feature(s) to check.
52+
53+ Returns
54+ -------
55+ has_features : bool
56+ True if target has the feature(s).
57+ """
58+ assert isinstance (target , Target ) or target is None
59+ assert isinstance (cpu_features , (Array , list , tuple , str ))
60+ has_feats = True
61+ cpu_features = [cpu_features ] if isinstance (cpu_features , str ) else cpu_features
62+ for feat in cpu_features :
63+ has_feats &= _ffi_api .target_has_feature (feat , target )
64+ return has_feats
65+
66+
4267def llvm_lookup_intrinsic_id (name ):
4368 """Lookup LLVM intrinsic id by name.
4469
@@ -71,36 +96,76 @@ def llvm_get_intrinsic_name(intrin_id: int) -> str:
7196 return _ffi_api .llvm_get_intrinsic_name (intrin_id )
7297
7398
74- def llvm_x86_get_archlist (only64bit = False ):
75- """Get X86 CPU name list.
99+ def llvm_get_targets ():
100+ """Get LLVM target list.
101+
102+ Parameters
103+ ----------
104+
105+ Returns
106+ -------
107+ llvm_targets : list[str]
108+ List of available LLVM targets.
109+ """
110+ return _ffi_api .llvm_get_targets ()
111+
112+
113+ def llvm_get_cpu_archlist (target = None ):
114+ """Get CPU architectures for the target's `-mtriple`.
115+
116+ Parameters
117+ ----------
118+ target : Target
119+ The TVM target.
120+
121+ Returns
122+ -------
123+ cpu_archlist : list[str]
124+ List of available CPU architectures.
125+ """
126+ assert isinstance (target , Target ) or target is None
127+ return _ffi_api .llvm_get_cpu_archlist (target )
128+
129+
130+ def llvm_get_cpu_features (target = None ):
131+ """Get CPU features for the target's `-mtriple` and `-mcpu` and considering `-mattr`.
76132
77133 Parameters
78134 ----------
79- only64bit : bool
80- Filter 64bit architectures .
135+ target : Target
136+ The TVM target .
81137
82138 Returns
83139 -------
84- features : list[str]
85- String list of X86 architectures .
140+ cpu_features : list[str]
141+ List of available CPU features .
86142 """
87- return _ffi_api .llvm_x86_get_archlist (only64bit )
143+ assert isinstance (target , Target ) or target is None
144+ return _ffi_api .llvm_get_cpu_features (target )
88145
89146
90- def llvm_x86_get_features ( cpu_name ):
91- """Get X86 CPU features.
147+ def llvm_cpu_has_features ( cpu_features , target = None ):
148+ """Check CPU features for the target's `-mtriple` and `-mcpu` and considering `-mattr` .
92149
93150 Parameters
94151 ----------
95- cpu_name : string
96- X86 CPU name (e.g. "skylake").
152+ target : Target
153+ The TVM target.
154+ cpu_features : str or Array
155+ CPU Feature(s) to check.
97156
98157 Returns
99158 -------
100- features : list[str]
101- String list of X86 CPU features .
159+ has_features : bool
160+ True if target CPU has the feature(s) .
102161 """
103- return _ffi_api .llvm_x86_get_features (cpu_name )
162+ assert isinstance (target , Target ) or target is None
163+ assert isinstance (cpu_features , (Array , list , tuple , str ))
164+ has_feats = True
165+ cpu_features = [cpu_features ] if isinstance (cpu_features , str ) else cpu_features
166+ for feat in cpu_features :
167+ has_feats &= _ffi_api .llvm_cpu_has_feature (feat , target )
168+ return has_feats
104169
105170
106171def llvm_version_major (allow_none = False ):
0 commit comments