15 #include "llvm/MC/TargetRegistry.h"
16 #include "llvm/Support/DebugLog.h"
17 #include "llvm/Support/TargetSelect.h"
18 #include "llvm/Target/TargetMachine.h"
20 #define DEBUG_TYPE "mlir-llvm-target-utils"
26 static const auto initOnce = [] {
29 llvm::InitializeAllTargets();
30 llvm::InitializeAllTargetMCs();
36 FailureOr<std::unique_ptr<llvm::TargetMachine>>
38 StringRef triple = attr.getTriple();
39 StringRef chipAKAcpu = attr.getChip();
43 llvm::cast_if_present<LLVM::TargetFeaturesAttr>(attr.getFeatures());
44 std::string features = featuresAttr ? featuresAttr.getFeaturesString() :
"";
47 const llvm::Target *target =
48 llvm::TargetRegistry::lookupTarget(triple, error);
49 if (!target || !error.empty()) {
50 LDBG() <<
"Looking up target '" << triple <<
"' failed: " << error <<
"\n";
54 return std::unique_ptr<llvm::TargetMachine>(target->createTargetMachine(
55 llvm::Triple(triple), chipAKAcpu, features, {}, {}));
58 FailureOr<llvm::DataLayout>
60 FailureOr<std::unique_ptr<llvm::TargetMachine>> targetMachine =
62 if (
failed(targetMachine)) {
63 LDBG() <<
"Failed to retrieve the target machine for data layout.\n";
66 return (targetMachine.value())->createDataLayout();
FailureOr< std::unique_ptr< llvm::TargetMachine > > getTargetMachine(mlir::LLVM::TargetAttrInterface attr)
Helper to obtain the TargetMachine specified by the properties of the TargetAttrInterface-implementin...
FailureOr< llvm::DataLayout > getDataLayout(mlir::LLVM::TargetAttrInterface attr)
Helper to obtain the DataLayout of the target specified by the properties of the TargetAttrInterface-...
void initializeBackendsOnce()
Idempotent helper to register/initialize all backends that LLVM has been configured to support.
Include the generated interface declarations.