| 1 | //===-- PPCTargetMachine.h - Define TargetMachine for PowerPC ---*- 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 PowerPC specific subclass of TargetMachine. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_TARGET_POWERPC_PPCTARGETMACHINE_H |
| 14 | #define LLVM_LIB_TARGET_POWERPC_PPCTARGETMACHINE_H |
| 15 | |
| 16 | #include "PPCInstrInfo.h" |
| 17 | #include "PPCSubtarget.h" |
| 18 | #include "llvm/CodeGen/CodeGenTargetMachineImpl.h" |
| 19 | #include "llvm/IR/DataLayout.h" |
| 20 | #include <optional> |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | /// Common code between 32-bit and 64-bit PowerPC targets. |
| 25 | /// |
| 26 | class PPCTargetMachine final : public CodeGenTargetMachineImpl { |
| 27 | public: |
| 28 | enum Endian { NOT_DETECTED, LITTLE, BIG }; |
| 29 | |
| 30 | private: |
| 31 | std::unique_ptr<TargetLoweringObjectFile> TLOF; |
| 32 | Endian Endianness = Endian::NOT_DETECTED; |
| 33 | mutable bool HasGlibcHWCAPAccess = false; |
| 34 | |
| 35 | mutable StringMap<std::unique_ptr<PPCSubtarget>> SubtargetMap; |
| 36 | |
| 37 | public: |
| 38 | PPCTargetMachine(const Target &T, const Triple &TT, StringRef CPU, |
| 39 | StringRef FS, const TargetOptions &Options, |
| 40 | std::optional<Reloc::Model> RM, |
| 41 | std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, |
| 42 | bool JIT); |
| 43 | |
| 44 | ~PPCTargetMachine() override; |
| 45 | |
| 46 | const PPCSubtarget *getSubtargetImpl(const Function &F) const override; |
| 47 | // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget, |
| 48 | // subtargets are per-function entities based on the target-specific |
| 49 | // attributes of each function. |
| 50 | const PPCSubtarget *getSubtargetImpl() const = delete; |
| 51 | |
| 52 | // Pass Pipeline Configuration |
| 53 | TargetPassConfig *createPassConfig(PassManagerBase &PM) override; |
| 54 | |
| 55 | TargetTransformInfo getTargetTransformInfo(const Function &F) const override; |
| 56 | |
| 57 | TargetLoweringObjectFile *getObjFileLowering() const override { |
| 58 | return TLOF.get(); |
| 59 | } |
| 60 | |
| 61 | MachineFunctionInfo * |
| 62 | createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, |
| 63 | const TargetSubtargetInfo *STI) const override; |
| 64 | ScheduleDAGInstrs * |
| 65 | createMachineScheduler(MachineSchedContext *C) const override; |
| 66 | ScheduleDAGInstrs * |
| 67 | createPostMachineScheduler(MachineSchedContext *C) const override; |
| 68 | |
| 69 | /// Compute the ABI variant for \p TT and \p ABIName (the "target-abi" module |
| 70 | /// flag), falling back to the triple default. |
| 71 | static PPCABI computeABI(const Triple &TT, StringRef ABIName); |
| 72 | |
| 73 | bool hasGlibcHWCAPAccess() const { return HasGlibcHWCAPAccess; } |
| 74 | void setGlibcHWCAPAccess(bool Val = true) const { HasGlibcHWCAPAccess = Val; } |
| 75 | bool isPPC64() const { |
| 76 | const Triple &TT = getTargetTriple(); |
| 77 | return (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le); |
| 78 | }; |
| 79 | |
| 80 | bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override { |
| 81 | // Addrspacecasts are always noops. |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | bool isLittleEndian() const; |
| 86 | |
| 87 | int unqualifiedInlineAsmVariant() const override { return 1; } |
| 88 | }; |
| 89 | } // end namespace llvm |
| 90 | |
| 91 | #endif |
| 92 | |