xref: /aosp_15_r20/external/swiftshader/third_party/subzero/src/IceTargetLoweringX86.h (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1 //===---- subzero/src/IceTargetLoweringX86.h - x86 lowering -*- C++ -*---===//
2 //
3 //                        The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Declares common functionlity for lowering to the X86 architecture
12 /// (32-bit and 64-bit).
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef SUBZERO_SRC_ICETARGETLOWERINGX86_H
17 #define SUBZERO_SRC_ICETARGETLOWERINGX86_H
18 
19 #include "IceCfg.h"
20 #include "IceTargetLowering.h"
21 
22 #include <inttypes.h>
23 
24 namespace Ice {
25 namespace X86 {
26 
27 enum InstructionSetX86 {
28   Begin,
29   // SSE2 is the baseline instruction set.
30   SSE2 = Begin,
31   SSE4_1,
32   End
33 };
34 
35 class TargetX86 : public ::Ice::TargetLowering {
36   TargetX86() = delete;
37   TargetX86(const TargetX86 &) = delete;
38   TargetX86 &operator=(const TargetX86 &) = delete;
39 
40 public:
41   ~TargetX86() override = default;
42 
getInstructionSet()43   InstructionSetX86 getInstructionSet() const { return InstructionSet; }
44 
45 protected:
TargetX86(Cfg * Func)46   explicit TargetX86(Cfg *Func) : TargetLowering(Func) {
47     static_assert((InstructionSetX86::End - InstructionSetX86::Begin) ==
48                       (TargetInstructionSet::X86InstructionSet_End -
49                        TargetInstructionSet::X86InstructionSet_Begin),
50                   "InstructionSet range different from TargetInstructionSet");
51     if (getFlags().getTargetInstructionSet() !=
52         TargetInstructionSet::BaseInstructionSet) {
53       InstructionSet = static_cast<InstructionSetX86>(
54           (getFlags().getTargetInstructionSet() -
55            TargetInstructionSet::X86InstructionSet_Begin) +
56           InstructionSetX86::Begin);
57     }
58   }
59 
60   InstructionSetX86 InstructionSet = InstructionSetX86::Begin;
61 
62 private:
63   ENABLE_MAKE_UNIQUE;
64 };
65 
getInstructionSet(const Cfg * Func)66 inline InstructionSetX86 getInstructionSet(const Cfg *Func) {
67   return reinterpret_cast<TargetX86 *>(Func->getTarget())->getInstructionSet();
68 }
69 
70 template <typename T> struct PoolTypeConverter {};
71 
72 template <> struct PoolTypeConverter<float> {
73   using PrimitiveIntType = uint32_t;
74   using IceType = ConstantFloat;
75   static constexpr Type Ty = IceType_f32;
76   static constexpr const char *TypeName = "float";
77   static constexpr const char *AsmTag = ".long";
78   static constexpr const char *PrintfString = "0x%x";
79 };
80 
81 template <> struct PoolTypeConverter<double> {
82   using PrimitiveIntType = uint64_t;
83   using IceType = ConstantDouble;
84   static constexpr Type Ty = IceType_f64;
85   static constexpr const char *TypeName = "double";
86   static constexpr const char *AsmTag = ".quad";
87   static constexpr const char *PrintfString = "%" PRIu64;
88 };
89 
90 // Add converter for int type constant pooling
91 template <> struct PoolTypeConverter<uint32_t> {
92   using PrimitiveIntType = uint32_t;
93   using IceType = ConstantInteger32;
94   static constexpr Type Ty = IceType_i32;
95   static constexpr const char *TypeName = "i32";
96   static constexpr const char *AsmTag = ".long";
97   static constexpr const char *PrintfString = "0x%x";
98 };
99 
100 // Add converter for int type constant pooling
101 template <> struct PoolTypeConverter<uint16_t> {
102   using PrimitiveIntType = uint32_t;
103   using IceType = ConstantInteger32;
104   static constexpr Type Ty = IceType_i16;
105   static constexpr const char *TypeName = "i16";
106   static constexpr const char *AsmTag = ".short";
107   static constexpr const char *PrintfString = "0x%x";
108 };
109 
110 // Add converter for int type constant pooling
111 template <> struct PoolTypeConverter<uint8_t> {
112   using PrimitiveIntType = uint32_t;
113   using IceType = ConstantInteger32;
114   static constexpr Type Ty = IceType_i8;
115   static constexpr const char *TypeName = "i8";
116   static constexpr const char *AsmTag = ".byte";
117   static constexpr const char *PrintfString = "0x%x";
118 };
119 
120 } // end of namespace X86
121 } // end of namespace Ice
122 
123 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H
124