From 3fc5e6ec469d2f8da16f46feaf330d48b2a7cd88 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 6 Sep 2021 19:00:01 -0500 Subject: [PATCH] [Hexagon] Sort functions before adding to LLVM codegen PrimFuncs are stored in a map where the order of iteration is not deterministic. This can cause a different llvm::Module to be created each time, which can defeat debugging tools like -opt-bisect-limit. Sort the PrimFuncs in a deterministic way before adding them to the LLVM code generator. --- src/target/llvm/codegen_hexagon.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/target/llvm/codegen_hexagon.cc b/src/target/llvm/codegen_hexagon.cc index e9eacc27fc72..27ca86ada8f8 100644 --- a/src/target/llvm/codegen_hexagon.cc +++ b/src/target/llvm/codegen_hexagon.cc @@ -730,6 +730,12 @@ runtime::Module BuildHexagon(IRModule mod, Target target) { funcs.emplace_back(f); } + std::sort(funcs.begin(), funcs.end(), [](PrimFunc func_a, PrimFunc func_b) { + std::string name_a = func_a->GetAttr(tvm::attr::kGlobalSymbol).value(); + std::string name_b = func_b->GetAttr(tvm::attr::kGlobalSymbol).value(); + return name_a < name_b; + }); + cg->Init("TVMHexagonModule", tm.get(), ctx.get(), false, false, false); for (const PrimFunc& f : funcs) { cg->AddFunction(f);