1//===-- X86TargetMachine.h - Define TargetMachine for the X86 ---*- C++ -*-===//
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//===----------------------------------------------------------------------===//
8//
9// This file declares the X86 specific subclass of TargetMachine.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_X86_X86TARGETMACHINE_H
14#define LLVM_LIB_TARGET_X86_X86TARGETMACHINE_H
15
16#include "X86Subtarget.h"
17#include "llvm/ADT/StringMap.h"
18#include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
19#include "llvm/Support/CodeGen.h"
20#include <memory>
21#include <optional>
22
23namespace llvm {
24
25class StringRef;
26class TargetTransformInfo;
27
28class X86TargetMachine final : public CodeGenTargetMachineImpl {
29 const X86Options &CLOpts;
30 std::unique_ptr<TargetLoweringObjectFile> TLOF;
31 mutable StringMap<std::unique_ptr<X86Subtarget>> SubtargetMap;
32 // True if this is used in JIT.
33 bool IsJIT;
34
35 /// Reset internal state.
36 void reset() override;
37
38public:
39 X86TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
40 StringRef FS, const TargetOptions &Options,
41 std::optional<Reloc::Model> RM,
42 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
43 bool JIT);
44 ~X86TargetMachine() override;
45
46 const X86Options &getCLOpts() const { return CLOpts; }
47
48 const X86Subtarget *getSubtargetImpl(const Function &F) const override;
49 // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
50 // subtargets are per-function entities based on the target-specific
51 // attributes of each function.
52 const X86Subtarget *getSubtargetImpl() const = delete;
53
54 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
55
56 // Set up the pass pipeline.
57 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
58
59 TargetLoweringObjectFile *getObjFileLowering() const override {
60 return TLOF.get();
61 }
62
63 MachineFunctionInfo *
64 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
65 const TargetSubtargetInfo *STI) const override;
66
67 yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
68 yaml::MachineFunctionInfo *
69 convertFuncInfoToYAML(const MachineFunction &MF) const override;
70 bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
71 PerFunctionMIParsingState &PFS,
72 SMDiagnostic &Error,
73 SMRange &SourceRange) const override;
74
75 void registerPassBuilderCallbacks(PassBuilder &PB) override;
76
77 Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM,
78 raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
79 CodeGenFileType FileType,
80 const CGPassBuilderOption &Opt, MCContext &Ctx,
81 PassInstrumentationCallbacks *PIC) override;
82
83 bool isJIT() const { return IsJIT; }
84
85 bool isNoopAddrSpaceCast(const DataLayout &DL, unsigned SrcAS,
86 unsigned DestAS) const override;
87 ScheduleDAGInstrs *
88 createMachineScheduler(MachineSchedContext *C) const override;
89 ScheduleDAGInstrs *
90 createPostMachineScheduler(MachineSchedContext *C) const override;
91
92 bool canLowerCondLoop() const override { return true; }
93};
94
95} // end namespace llvm
96
97#endif // LLVM_LIB_TARGET_X86_X86TARGETMACHINE_H
98