Target Triple Registry Lookup
I'm trying to write a function that needs to lookup a target triple from the LLVM registry (llvm::TargetRegistry::lookupTarget). I see this in https://llvm.org/doxygen/TargetRegistry_8h_source.html, but not in the bindings (using v100.x.x).
Is the function/module not exposed?
For some context. I'm a LLVM newbie, trying to learn LLVM by porting Gandiva (https://github.com/apache/arrow/tree/master/cpp/src/gandiva) to Rust. There's the below code:
// This method was modified from its original version for a part of MLIR
// Original source from
// https://github.com/llvm/llvm-project/blob/9f2ce5b915a505a5488a5cf91bb0a8efa9ddfff7/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
// The original copyright notice follows.
// 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
static void SetDataLayout(llvm::Module* module) {
auto target_triple = llvm::sys::getDefaultTargetTriple();
std::string error_message;
auto target = llvm::TargetRegistry::lookupTarget(target_triple, error_message);
if (!target) {
return;
}
std::string cpu(llvm::sys::getHostCPUName());
llvm::SubtargetFeatures features;
llvm::StringMap<bool> host_features;
if (llvm::sys::getHostCPUFeatures(host_features)) {
for (auto& f : host_features) {
features.AddFeature(f.first(), f.second);
}
}
std::unique_ptr<llvm::TargetMachine> machine(
target->createTargetMachine(target_triple, cpu, features.getString(), {}, {}));
module->setDataLayout(machine->createDataLayout());
}
From the comments on the function, it sounds like llvm::TargetRegistry might be some internal module that's not exposed by default, but I'm currently aiming in the dark.
Thanks