llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
target.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <llvm/ADT/Triple.h>
8 
9 #include "core/type.h"
10 
11 
12 
14 class X86Target;
15 class PPCTarget;
16 class AArch64Target;
17 class RISCVTarget;
18 
19 
20 
24 class Target {
25 public:
27  enum class Kind {
28  X86,
29  PPC,
30  AARCH64,
31  RISCV
32  };
33 
34 public:
35  Target(
36  Kind kind,
37  const llvm::Triple &triple,
38  const std::string &cpu,
39  const std::string &tuneCPU,
40  const std::string &fs,
41  const std::string &abi,
42  bool shared)
43  : kind_(kind)
44  , triple_(triple)
45  , cpu_(cpu)
46  , tuneCPU_(tuneCPU)
47  , fs_(fs)
48  , abi_(abi)
49  , shared_(shared)
50  {
51  }
52 
54  template<typename T>
55  T *As()
56  {
57  return T::kKind == kind_ ? static_cast<T *>(this) : nullptr;
58  }
59 
61  template<typename T>
62  const T *As() const
63  {
64  return T::kKind == kind_ ? static_cast<const T *>(this) : nullptr;
65  }
66 
68  bool IsShared() const { return shared_; }
70  const llvm::Triple &GetTriple() const { return triple_; }
72  llvm::StringRef getCPU() const { return cpu_; }
74  llvm::StringRef getTuneCPU() const { return tuneCPU_; }
76  llvm::StringRef getFS() const { return fs_; }
78  llvm::StringRef getABI() const { return abi_; }
79 
81  Type GetPointerType() const;
82 
84  Kind GetKind() const { return kind_; }
85 
87  virtual bool IsLittleEndian() const { return true; }
89  virtual bool AllowsUnalignedStores() const { return false; }
90 
91 protected:
95  llvm::Triple triple_;
97  std::string cpu_;
99  std::string tuneCPU_;
101  std::string fs_;
103  std::string abi_;
105  bool shared_;
106 };
Target::As
T * As()
Convert the target to a specific target.
Definition: target.h:55
Target::getABI
llvm::StringRef getABI() const
Return the feature strings of the target.
Definition: target.h:78
Target::triple_
llvm::Triple triple_
Target triple.
Definition: target.h:95
AArch64Target
Definition: aarch64.h:16
Target::AllowsUnalignedStores
virtual bool AllowsUnalignedStores() const
Check whether the target allows unaligned stores.
Definition: target.h:89
Target::cpu_
std::string cpu_
Target CPU.
Definition: target.h:97
Target
Definition: target.h:24
X86Target
Definition: x86.h:20
Target::shared_
bool shared_
Flag indicating whether the target is a shared library.
Definition: target.h:105
Target::tuneCPU_
std::string tuneCPU_
Target CPU to tune fore.
Definition: target.h:99
Target::abi_
std::string abi_
Target ABI descriptor.
Definition: target.h:103
Target::fs_
std::string fs_
Target feature string.
Definition: target.h:101
Target::GetPointerType
Type GetPointerType() const
Return the target pointer type.
Definition: target.cpp:10
PPCTarget
Definition: ppc.h:16
Target::Kind
Kind
Enumeration of supported targets.
Definition: target.h:27
Target::getCPU
llvm::StringRef getCPU() const
Returns the CPU to target.
Definition: target.h:72
Target::getTuneCPU
llvm::StringRef getTuneCPU() const
Returns the CPU to target.
Definition: target.h:74
RISCVTarget
Definition: riscv.h:16
Target::kind_
Kind kind_
Target kind.
Definition: target.h:93
Target::As
const T * As() const
Convert the target to a specific target.
Definition: target.h:62
Target::getFS
llvm::StringRef getFS() const
Return the feature strings of the target.
Definition: target.h:76
Target::GetKind
Kind GetKind() const
Return the target kind.
Definition: target.h:84
Target::IsShared
bool IsShared() const
Checks whether the target is a shared library.
Definition: target.h:68
Target::GetTriple
const llvm::Triple & GetTriple() const
Returns the target triple.
Definition: target.h:70
Target::IsLittleEndian
virtual bool IsLittleEndian() const
Check whether the target is little endian.
Definition: target.h:87