65084842bc846c8876093c083dd15fc50d9c3f07
[oota-llvm.git] / lib / Target / PowerPC / PPCTargetMachine.h
1 //===-- PPCTargetMachine.h - Define TargetMachine for PowerPC ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the PowerPC specific subclass of TargetMachine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_TARGET_POWERPC_PPCTARGETMACHINE_H
15 #define LLVM_LIB_TARGET_POWERPC_PPCTARGETMACHINE_H
16
17 #include "PPCInstrInfo.h"
18 #include "PPCSubtarget.h"
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/Target/TargetMachine.h"
21
22 namespace llvm {
23
24 /// PPCTargetMachine - Common code between 32-bit and 64-bit PowerPC targets.
25 ///
26 class PPCTargetMachine : public LLVMTargetMachine {
27 public:
28   enum PPCABI { PPC_ABI_UNKNOWN, PPC_ABI_ELFv1, PPC_ABI_ELFv2 };
29 private:
30   std::unique_ptr<TargetLoweringObjectFile> TLOF;
31   PPCABI TargetABI;
32   // Calculates type size & alignment
33   const DataLayout DL;
34   PPCSubtarget Subtarget;
35
36   mutable StringMap<std::unique_ptr<PPCSubtarget>> SubtargetMap;
37
38 public:
39   PPCTargetMachine(const Target &T, StringRef TT, StringRef CPU, StringRef FS,
40                    const TargetOptions &Options, Reloc::Model RM,
41                    CodeModel::Model CM, CodeGenOpt::Level OL);
42
43   ~PPCTargetMachine() override;
44
45   const DataLayout *getDataLayout() const override { return &DL; }
46   const PPCSubtarget *getSubtargetImpl() const override { return &Subtarget; }
47   const PPCSubtarget *getSubtargetImpl(const Function &F) const override;
48
49   // Pass Pipeline Configuration
50   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
51
52   TargetIRAnalysis getTargetIRAnalysis() override;
53
54   TargetLoweringObjectFile *getObjFileLowering() const override {
55     return TLOF.get();
56   }
57   bool isELFv2ABI() const { return TargetABI == PPC_ABI_ELFv2; }
58   bool isPPC64() const {
59     Triple TT(getTargetTriple());
60     return (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le);
61   };
62 };
63
64 /// PPC32TargetMachine - PowerPC 32-bit target machine.
65 ///
66 class PPC32TargetMachine : public PPCTargetMachine {
67   virtual void anchor();
68 public:
69   PPC32TargetMachine(const Target &T, StringRef TT,
70                      StringRef CPU, StringRef FS, const TargetOptions &Options,
71                      Reloc::Model RM, CodeModel::Model CM,
72                      CodeGenOpt::Level OL);
73 };
74
75 /// PPC64TargetMachine - PowerPC 64-bit target machine.
76 ///
77 class PPC64TargetMachine : public PPCTargetMachine {
78   virtual void anchor();
79 public:
80   PPC64TargetMachine(const Target &T, StringRef TT,
81                      StringRef CPU, StringRef FS, const TargetOptions &Options,
82                      Reloc::Model RM, CodeModel::Model CM,
83                      CodeGenOpt::Level OL);
84 };
85
86 } // end namespace llvm
87
88 #endif