1//=-- HexagonTargetMachine.h - Define TargetMachine for Hexagon ---*- 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 Hexagon specific subclass of TargetMachine.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETMACHINE_H
14#define LLVM_LIB_TARGET_HEXAGON_HEXAGONTARGETMACHINE_H
15
16#include "HexagonInstrInfo.h"
17#include "HexagonSubtarget.h"
18#include "HexagonTargetObjectFile.h"
19#include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
20#include "llvm/Target/LastSubtargetCache.h"
21#include <optional>
22
23namespace llvm {
24
25enum class QFloatMode { StrictIEEE, IEEE, Lossy, Legacy };
26
27class HexagonTargetMachine : public CodeGenTargetMachineImpl {
28 std::unique_ptr<TargetLoweringObjectFile> TLOF;
29 HexagonSubtarget Subtarget;
30 mutable StringMap<std::unique_ptr<HexagonSubtarget>> SubtargetMap;
31
32 /// The attributes that select a subtarget.
33 struct SubtargetAttrs {
34 Attribute CPU, FS;
35
36 bool operator==(const SubtargetAttrs &RHS) const {
37 return CPU == RHS.CPU && FS == RHS.FS;
38 }
39
40 bool operator!=(const SubtargetAttrs &RHS) const { return !(*this == RHS); }
41 };
42 mutable LastSubtargetCache<HexagonSubtarget, SubtargetAttrs> LastSubtarget;
43
44public:
45 HexagonTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
46 StringRef FS, const TargetOptions &Options,
47 std::optional<Reloc::Model> RM,
48 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
49 bool JIT);
50 ~HexagonTargetMachine() override;
51 const HexagonSubtarget *getHexagonSubtarget() const { return &Subtarget; }
52 const HexagonSubtarget *getSubtargetImpl(const Function &F) const override;
53
54 void registerPassBuilderCallbacks(PassBuilder &PB) override;
55 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
56 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
57
58 HexagonTargetObjectFile *getObjFileLowering() const override {
59 return static_cast<HexagonTargetObjectFile*>(TLOF.get());
60 }
61
62 MachineFunctionInfo *
63 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
64 const TargetSubtargetInfo *STI) const override;
65
66 yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
67 yaml::MachineFunctionInfo *
68 convertFuncInfoToYAML(const MachineFunction &MF) const override;
69 bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
70 PerFunctionMIParsingState &PFS,
71 SMDiagnostic &Error,
72 SMRange &SourceRange) const override;
73
74 bool isNoopAddrSpaceCast(const DataLayout &, unsigned SrcAS,
75 unsigned DestAS) const override {
76 return true;
77 }
78 ScheduleDAGInstrs *
79 createMachineScheduler(MachineSchedContext *C) const override;
80};
81
82} // end namespace llvm
83
84#endif
85