AMDGPU: Mark test as XFAIL in expensive_checks builds
[llvm-project.git] / llvm / lib / ExecutionEngine / Orc / JITTargetMachineBuilder.cpp
blob6dad7124a88e245de8c78bd19302eb3827bee11c
1 //===----- JITTargetMachineBuilder.cpp - Build TargetMachines for JIT -----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
11 #include "llvm/MC/TargetRegistry.h"
12 #include "llvm/Support/raw_ostream.h"
13 #include "llvm/TargetParser/Host.h"
15 namespace llvm {
16 namespace orc {
18 JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
19 : TT(std::move(TT)) {
20 Options.EmulatedTLS = true;
21 Options.UseInitArray = true;
24 Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() {
25 JITTargetMachineBuilder TMBuilder((Triple(sys::getProcessTriple())));
27 // Retrieve host CPU name and sub-target features and add them to builder.
28 // Relocation model, code model and codegen opt level are kept to default
29 // values.
30 for (const auto &Feature : llvm::sys::getHostCPUFeatures())
31 TMBuilder.getFeatures().AddFeature(Feature.first(), Feature.second);
33 TMBuilder.setCPU(std::string(llvm::sys::getHostCPUName()));
35 return TMBuilder;
38 Expected<std::unique_ptr<TargetMachine>>
39 JITTargetMachineBuilder::createTargetMachine() {
41 std::string ErrMsg;
42 auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
43 if (!TheTarget)
44 return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
46 if (!TheTarget->hasJIT())
47 return make_error<StringError>("Target has no JIT support",
48 inconvertibleErrorCode());
50 auto *TM =
51 TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(),
52 Options, RM, CM, OptLevel, /*JIT*/ true);
53 if (!TM)
54 return make_error<StringError>("Could not allocate target machine",
55 inconvertibleErrorCode());
57 return std::unique_ptr<TargetMachine>(TM);
60 JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures(
61 const std::vector<std::string> &FeatureVec) {
62 for (const auto &F : FeatureVec)
63 Features.AddFeature(F);
64 return *this;
67 #ifndef NDEBUG
68 void JITTargetMachineBuilderPrinter::print(raw_ostream &OS) const {
69 OS << Indent << "{\n"
70 << Indent << " Triple = \"" << JTMB.TT.str() << "\"\n"
71 << Indent << " CPU = \"" << JTMB.CPU << "\"\n"
72 << Indent << " Features = \"" << JTMB.Features.getString() << "\"\n"
73 << Indent << " Options = <not-printable>\n"
74 << Indent << " Relocation Model = ";
76 if (JTMB.RM) {
77 switch (*JTMB.RM) {
78 case Reloc::Static:
79 OS << "Static";
80 break;
81 case Reloc::PIC_:
82 OS << "PIC_";
83 break;
84 case Reloc::DynamicNoPIC:
85 OS << "DynamicNoPIC";
86 break;
87 case Reloc::ROPI:
88 OS << "ROPI";
89 break;
90 case Reloc::RWPI:
91 OS << "RWPI";
92 break;
93 case Reloc::ROPI_RWPI:
94 OS << "ROPI_RWPI";
95 break;
97 } else
98 OS << "unspecified (will use target default)";
100 OS << "\n"
101 << Indent << " Code Model = ";
103 if (JTMB.CM) {
104 switch (*JTMB.CM) {
105 case CodeModel::Tiny:
106 OS << "Tiny";
107 break;
108 case CodeModel::Small:
109 OS << "Small";
110 break;
111 case CodeModel::Kernel:
112 OS << "Kernel";
113 break;
114 case CodeModel::Medium:
115 OS << "Medium";
116 break;
117 case CodeModel::Large:
118 OS << "Large";
119 break;
121 } else
122 OS << "unspecified (will use target default)";
124 OS << "\n"
125 << Indent << " Optimization Level = ";
126 switch (JTMB.OptLevel) {
127 case CodeGenOptLevel::None:
128 OS << "None";
129 break;
130 case CodeGenOptLevel::Less:
131 OS << "Less";
132 break;
133 case CodeGenOptLevel::Default:
134 OS << "Default";
135 break;
136 case CodeGenOptLevel::Aggressive:
137 OS << "Aggressive";
138 break;
141 OS << "\n" << Indent << "}\n";
143 #endif // NDEBUG
145 } // End namespace orc.
146 } // End namespace llvm.