1//=- SystemZTargetMachine.h - Define TargetMachine for SystemZ ----*- 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 SystemZ specific subclass of TargetMachine.
10//
11//===----------------------------------------------------------------------===//
12
13
14#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETMACHINE_H
15#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETMACHINE_H
16
17#include "SystemZSubtarget.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Analysis/TargetTransformInfo.h"
20#include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
21#include "llvm/Support/CodeGen.h"
22#include "llvm/Target/LastSubtargetCache.h"
23#include "llvm/Target/TargetMachine.h"
24#include <memory>
25#include <optional>
26
27namespace llvm {
28
29class SystemZTargetMachine : public CodeGenTargetMachineImpl {
30 std::unique_ptr<TargetLoweringObjectFile> TLOF;
31
32 mutable StringMap<std::unique_ptr<SystemZSubtarget>> SubtargetMap;
33
34 /// The attributes that select a subtarget.
35 struct SubtargetAttrs {
36 Attribute CPU, TuneCPU, FS, SoftFloat, BackChain;
37
38 bool operator==(const SubtargetAttrs &RHS) const {
39 return CPU == RHS.CPU && TuneCPU == RHS.TuneCPU && FS == RHS.FS &&
40 SoftFloat == RHS.SoftFloat && BackChain == RHS.BackChain;
41 }
42
43 bool operator!=(const SubtargetAttrs &RHS) const { return !(*this == RHS); }
44 };
45 mutable LastSubtargetCache<SystemZSubtarget, SubtargetAttrs> LastSubtarget;
46
47public:
48 SystemZTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
49 StringRef FS, const TargetOptions &Options,
50 std::optional<Reloc::Model> RM,
51 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
52 bool JIT);
53 ~SystemZTargetMachine() override;
54
55 const SystemZSubtarget *getSubtargetImpl(const Function &) const override;
56 // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
57 // subtargets are per-function entities based on the target-specific
58 // attributes of each function.
59 const SystemZSubtarget *getSubtargetImpl() const = delete;
60
61 // Override CodeGenTargetMachineImpl
62 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
63 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
64
65 TargetLoweringObjectFile *getObjFileLowering() const override {
66 return TLOF.get();
67 }
68
69 MachineFunctionInfo *
70 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
71 const TargetSubtargetInfo *STI) const override;
72
73 ScheduleDAGInstrs *
74 createMachineScheduler(MachineSchedContext *C) const override;
75
76 ScheduleDAGInstrs *
77 createPostMachineScheduler(MachineSchedContext *C) const override;
78
79 bool targetSchedulesPostRAScheduling() const override { return true; };
80
81 void registerPassBuilderCallbacks(PassBuilder &PB) override;
82
83 Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM,
84 raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
85 CodeGenFileType FileType,
86 const CGPassBuilderOption &Opt, MCContext &Ctx,
87 PassInstrumentationCallbacks *PIC) override;
88};
89
90} // end namespace llvm
91
92#endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZTARGETMACHINE_H
93