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 "llvm/Target/LastSubtargetCache.h"
21#include <memory>
22#include <optional>
23
24namespace llvm {
25
26class StringRef;
27class TargetTransformInfo;
28
29class X86TargetMachine final : public CodeGenTargetMachineImpl {
30 const X86Options &CLOpts;
31 std::unique_ptr<TargetLoweringObjectFile> TLOF;
32 mutable StringMap<std::unique_ptr<X86Subtarget>> SubtargetMap;
33
34 /// The attributes that select a subtarget. This must cover every function
35 /// attribute read by getSubtargetImpl.
36 struct SubtargetAttrs {
37 Attribute CPU, TuneCPU, FS, PreferVecWidth, MinLegalVecWidth, SoftFloat;
38
39 bool operator==(const SubtargetAttrs &RHS) const {
40 return CPU == RHS.CPU && TuneCPU == RHS.TuneCPU && FS == RHS.FS &&
41 PreferVecWidth == RHS.PreferVecWidth &&
42 MinLegalVecWidth == RHS.MinLegalVecWidth &&
43 SoftFloat == RHS.SoftFloat;
44 }
45
46 bool operator!=(const SubtargetAttrs &RHS) const { return !(*this == RHS); }
47 };
48 mutable LastSubtargetCache<X86Subtarget, SubtargetAttrs> LastSubtarget;
49 // True if this is used in JIT.
50 bool IsJIT;
51
52 /// Reset internal state.
53 void reset() override;
54
55public:
56 X86TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
57 StringRef FS, const TargetOptions &Options,
58 std::optional<Reloc::Model> RM,
59 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
60 bool JIT);
61 ~X86TargetMachine() override;
62
63 const X86Options &getCLOpts() const { return CLOpts; }
64
65 const X86Subtarget *getSubtargetImpl(const Function &F) const override;
66 // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
67 // subtargets are per-function entities based on the target-specific
68 // attributes of each function.
69 const X86Subtarget *getSubtargetImpl() const = delete;
70
71 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
72
73 // Set up the pass pipeline.
74 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
75
76 TargetLoweringObjectFile *getObjFileLowering() const override {
77 return TLOF.get();
78 }
79
80 MachineFunctionInfo *
81 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
82 const TargetSubtargetInfo *STI) const override;
83
84 yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
85 yaml::MachineFunctionInfo *
86 convertFuncInfoToYAML(const MachineFunction &MF) const override;
87 bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
88 PerFunctionMIParsingState &PFS,
89 SMDiagnostic &Error,
90 SMRange &SourceRange) const override;
91
92 void registerPassBuilderCallbacks(PassBuilder &PB) override;
93
94 Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM,
95 raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
96 CodeGenFileType FileType,
97 const CGPassBuilderOption &Opt, MCContext &Ctx,
98 PassInstrumentationCallbacks *PIC) override;
99
100 bool isJIT() const { return IsJIT; }
101
102 bool isNoopAddrSpaceCast(const DataLayout &DL, unsigned SrcAS,
103 unsigned DestAS) const override;
104 ScheduleDAGInstrs *
105 createMachineScheduler(MachineSchedContext *C) const override;
106 ScheduleDAGInstrs *
107 createPostMachineScheduler(MachineSchedContext *C) const override;
108
109 bool canLowerCondLoop() const override { return true; }
110};
111
112} // end namespace llvm
113
114#endif // LLVM_LIB_TARGET_X86_X86TARGETMACHINE_H
115