xref: /freebsd/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCTargetMachine.h (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
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/IR/DataLayout.h"
19 #include "llvm/Target/TargetMachine.h"
20 
21 namespace llvm {
22 
23 /// Common code between 32-bit and 64-bit PowerPC targets.
24 ///
25 class PPCTargetMachine final : public LLVMTargetMachine {
26 public:
27   enum PPCABI { PPC_ABI_UNKNOWN, PPC_ABI_ELFv1, PPC_ABI_ELFv2 };
28   enum Endian { NOT_DETECTED, LITTLE, BIG };
29 
30 private:
31   std::unique_ptr<TargetLoweringObjectFile> TLOF;
32   PPCABI TargetABI;
33   Endian Endianness = Endian::NOT_DETECTED;
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                    Optional<Reloc::Model> RM, Optional<CodeModel::Model> CM,
41                    CodeGenOpt::Level OL, bool JIT);
42 
43   ~PPCTargetMachine() override;
44 
45   const PPCSubtarget *getSubtargetImpl(const Function &F) const override;
46   // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
47   // subtargets are per-function entities based on the target-specific
48   // attributes of each function.
49   const PPCSubtarget *getSubtargetImpl() const = delete;
50 
51   // Pass Pipeline Configuration
52   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
53 
54   TargetTransformInfo getTargetTransformInfo(const Function &F) override;
55 
56   TargetLoweringObjectFile *getObjFileLowering() const override {
57     return TLOF.get();
58   }
59   bool isELFv2ABI() const { return TargetABI == PPC_ABI_ELFv2; }
60   bool isPPC64() const {
61     const Triple &TT = getTargetTriple();
62     return (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le);
63   };
64 
65   bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
66     // Addrspacecasts are always noops.
67     return true;
68   }
69 
70   bool isLittleEndian() const;
71 
72   int unqualifiedInlineAsmVariant() const override { return 1; }
73 };
74 } // end namespace llvm
75 
76 #endif
77