PPCTargetMachine.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef LLVM_LIB_TARGET_POWERPC_PPCTARGETMACHINE_H
  13. #define LLVM_LIB_TARGET_POWERPC_PPCTARGETMACHINE_H
  14. #include "PPCInstrInfo.h"
  15. #include "PPCSubtarget.h"
  16. #include "llvm/IR/DataLayout.h"
  17. #include "llvm/Target/TargetMachine.h"
  18. #include <optional>
  19. namespace llvm {
  20. /// Common code between 32-bit and 64-bit PowerPC targets.
  21. ///
  22. class PPCTargetMachine final : public LLVMTargetMachine {
  23. public:
  24. enum PPCABI { PPC_ABI_UNKNOWN, PPC_ABI_ELFv1, PPC_ABI_ELFv2 };
  25. enum Endian { NOT_DETECTED, LITTLE, BIG };
  26. private:
  27. std::unique_ptr<TargetLoweringObjectFile> TLOF;
  28. PPCABI TargetABI;
  29. Endian Endianness = Endian::NOT_DETECTED;
  30. mutable StringMap<std::unique_ptr<PPCSubtarget>> SubtargetMap;
  31. public:
  32. PPCTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
  33. StringRef FS, const TargetOptions &Options,
  34. std::optional<Reloc::Model> RM,
  35. std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
  36. bool JIT);
  37. ~PPCTargetMachine() override;
  38. const PPCSubtarget *getSubtargetImpl(const Function &F) const override;
  39. // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
  40. // subtargets are per-function entities based on the target-specific
  41. // attributes of each function.
  42. const PPCSubtarget *getSubtargetImpl() const = delete;
  43. // Pass Pipeline Configuration
  44. TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
  45. TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
  46. TargetLoweringObjectFile *getObjFileLowering() const override {
  47. return TLOF.get();
  48. }
  49. MachineFunctionInfo *
  50. createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
  51. const TargetSubtargetInfo *STI) const override;
  52. bool isELFv2ABI() const { return TargetABI == PPC_ABI_ELFv2; }
  53. bool isPPC64() const {
  54. const Triple &TT = getTargetTriple();
  55. return (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le);
  56. };
  57. bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
  58. // Addrspacecasts are always noops.
  59. return true;
  60. }
  61. bool isLittleEndian() const;
  62. int unqualifiedInlineAsmVariant() const override { return 1; }
  63. };
  64. } // end namespace llvm
  65. #endif