1//===-- SparcTargetMachine.h - Define TargetMachine for Sparc ---*- 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 Sparc specific subclass of TargetMachine.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_SPARC_SPARCTARGETMACHINE_H
14#define LLVM_LIB_TARGET_SPARC_SPARCTARGETMACHINE_H
15
16#include "SparcInstrInfo.h"
17#include "SparcSubtarget.h"
18#include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
19#include "llvm/Target/LastSubtargetCache.h"
20#include "llvm/Target/TargetMachine.h"
21#include <optional>
22
23namespace llvm {
24
25class SparcTargetMachine : public CodeGenTargetMachineImpl {
26 const SparcOptions &CLOpts;
27 std::unique_ptr<TargetLoweringObjectFile> TLOF;
28 mutable StringMap<std::unique_ptr<SparcSubtarget>> SubtargetMap;
29
30 /// The attributes that select a subtarget.
31 struct SubtargetAttrs {
32 Attribute CPU, TuneCPU, FS, SoftFloat;
33
34 bool operator==(const SubtargetAttrs &RHS) const {
35 return CPU == RHS.CPU && TuneCPU == RHS.TuneCPU && FS == RHS.FS &&
36 SoftFloat == RHS.SoftFloat;
37 }
38
39 bool operator!=(const SubtargetAttrs &RHS) const { return !(*this == RHS); }
40 };
41 mutable LastSubtargetCache<SparcSubtarget, SubtargetAttrs> LastSubtarget;
42
43public:
44 SparcTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
45 StringRef FS, const TargetOptions &Options,
46 std::optional<Reloc::Model> RM,
47 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
48 bool JIT);
49 ~SparcTargetMachine() override;
50
51 const SparcOptions &getCLOpts() const { return CLOpts; }
52
53 const SparcSubtarget *getSubtargetImpl(const Function &F) const override;
54
55 // Pass Pipeline Configuration
56 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
57 TargetLoweringObjectFile *getObjFileLowering() const override {
58 return TLOF.get();
59 }
60 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
61
62 MachineFunctionInfo *
63 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
64 const TargetSubtargetInfo *STI) const override;
65
66 void registerPassBuilderCallbacks(PassBuilder &PB) override;
67
68 Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM,
69 raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
70 CodeGenFileType FileType,
71 const CGPassBuilderOption &Opt, MCContext &Ctx,
72 PassInstrumentationCallbacks *PIC) override;
73};
74
75/// Sparc 32-bit target machine
76///
77class SparcV8TargetMachine : public SparcTargetMachine {
78 virtual void anchor();
79
80public:
81 SparcV8TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
82 StringRef FS, const TargetOptions &Options,
83 std::optional<Reloc::Model> RM,
84 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
85 bool JIT);
86};
87
88/// Sparc 64-bit target machine
89///
90class SparcV9TargetMachine : public SparcTargetMachine {
91 virtual void anchor();
92
93public:
94 SparcV9TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
95 StringRef FS, const TargetOptions &Options,
96 std::optional<Reloc::Model> RM,
97 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
98 bool JIT);
99};
100
101class SparcelTargetMachine : public SparcTargetMachine {
102 virtual void anchor();
103
104public:
105 SparcelTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
106 StringRef FS, const TargetOptions &Options,
107 std::optional<Reloc::Model> RM,
108 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
109 bool JIT);
110};
111
112} // end namespace llvm
113
114#endif
115