Skip to content

Commit 184ac28

Browse files
Krzysztof Parzyszektrevor-m
authored andcommitted
[LLVM] Add target feature string to function attributes (apache#6763)
1 parent 040e23f commit 184ac28

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/target/llvm/codegen_llvm.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ void CodeGenLLVM::AddFunctionInternal(const PrimFunc& f, bool ret_void) {
172172
}
173173
#endif
174174

175+
llvm::StringRef fs = target_machine_->getTargetFeatureString();
176+
if (!fs.empty()) {
177+
function_->addFnAttr("target-features", fs);
178+
}
179+
175180
if (ret_void) {
176181
builder_->CreateRetVoid();
177182
} else {

tests/python/unittest/test_target_codegen_hexagon.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ def check_add(offload):
6363
check_add(False)
6464

6565

66+
def test_llvm_target_features():
67+
if not check_prereq_and_setup():
68+
return
69+
target = tvm.target.hexagon("v66", hvx=128)
70+
# Define some trivial compute
71+
A = tvm.te.placeholder((128,), dtype="uint8", name="A")
72+
C = tvm.te.compute((128,), lambda i: A[i] + 1, name="C")
73+
s = tvm.te.create_schedule(C.op)
74+
m = tvm.build(s, [C, A], target=target, target_host=target, name="add_one")
75+
llvm_ir = m.get_source("ll")
76+
# Make sure we find +hvx-length128b in "attributes".
77+
fs = re.findall(r"attributes.*\+hvx-length128b", llvm_ir)
78+
assert fs # Check that it's non-empty
79+
80+
6681
def test_alloc_vtcm():
6782
if not check_prereq_and_setup():
6883
return
@@ -92,4 +107,5 @@ def test_alloc_vtcm():
92107

93108
if __name__ == "__main__":
94109
test_basic()
110+
test_llvm_target_features()
95111
test_alloc_vtcm()

0 commit comments

Comments
 (0)