Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceTranslator.h - ICE to machine code --------*- 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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Declares the general driver class for translating ICE to machine |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 12 | /// code. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 13 | /// |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICETRANSLATOR_H |
| 17 | #define SUBZERO_SRC_ICETRANSLATOR_H |
| 18 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 19 | #include "IceDefs.h" |
| 20 | #include "IceGlobalContext.h" |
| 21 | |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 22 | #include <memory> |
| 23 | |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 24 | namespace llvm { |
| 25 | class Module; |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 26 | } // end of namespace llvm |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 27 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 28 | namespace Ice { |
| 29 | |
| 30 | class ClFlags; |
| 31 | class Cfg; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 32 | class VariableDeclaration; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 33 | class GlobalContext; |
| 34 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 35 | /// Base class for translating ICE to machine code. Derived classes convert |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 36 | /// other intermediate representations down to ICE, and then call the |
| 37 | /// appropriate (inherited) methods to convert ICE into machine instructions. |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 38 | class Translator { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 39 | Translator() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 40 | Translator(const Translator &) = delete; |
| 41 | Translator &operator=(const Translator &) = delete; |
| 42 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 43 | public: |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 44 | explicit Translator(GlobalContext *Ctx); |
Jan Voung | 72984d8 | 2015-01-29 14:42:38 -0800 | [diff] [blame] | 45 | |
Jim Stichnoth | f4fbf7f | 2015-08-08 08:37:02 -0700 | [diff] [blame] | 46 | virtual ~Translator() = default; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 47 | const ErrorCode &getErrorStatus() const { return ErrorStatus; } |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 48 | |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 49 | GlobalContext *getContext() const { return Ctx; } |
| 50 | |
John Porto | bd2e231 | 2016-03-15 11:06:25 -0700 | [diff] [blame] | 51 | /// Translates the constructed ICE function Func to machine code. |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 52 | void translateFcn(std::unique_ptr<Cfg> Func); |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 53 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 54 | /// Lowers the given list of global addresses to target. Generates list of |
| 55 | /// corresponding variable declarations. |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 56 | void |
| 57 | lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 58 | |
| 59 | /// Creates a name using the given prefix and corresponding index. |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 60 | std::string createUnnamedName(const std::string &Prefix, SizeT Index); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 61 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 62 | /// Reports if there is a (potential) conflict between Name, and using Prefix |
| 63 | /// to name unnamed names. Errors are put on Ostream. Returns true if there |
| 64 | /// isn't a potential conflict. |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 65 | bool checkIfUnnamedNameSafe(const std::string &Name, const char *Kind, |
| 66 | const std::string &Prefix); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 67 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 68 | uint32_t getNextSequenceNumber() { return NextSequenceNumber++; } |
| 69 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 70 | protected: |
| 71 | GlobalContext *Ctx; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 72 | uint32_t NextSequenceNumber; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 73 | /// ErrorCode of the translation. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 74 | ErrorCode ErrorStatus; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 75 | }; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 76 | |
Eric Holk | 16f8061 | 2016-04-04 17:07:42 -0700 | [diff] [blame] | 77 | class CfgOptWorkItem final : public OptWorkItem { |
| 78 | CfgOptWorkItem() = delete; |
| 79 | CfgOptWorkItem(const CfgOptWorkItem &) = delete; |
| 80 | CfgOptWorkItem &operator=(const CfgOptWorkItem &) = delete; |
| 81 | |
| 82 | public: |
| 83 | CfgOptWorkItem(std::unique_ptr<Cfg> Func) : Func(std::move(Func)) {} |
| 84 | std::unique_ptr<Cfg> getParsedCfg() override { return std::move(Func); } |
| 85 | ~CfgOptWorkItem() override = default; |
| 86 | |
| 87 | private: |
| 88 | std::unique_ptr<Ice::Cfg> Func; |
| 89 | }; |
| 90 | |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 91 | } // end of namespace Ice |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 92 | |
| 93 | #endif // SUBZERO_SRC_ICETRANSLATOR_H |