Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceConverter.h - Converts LLVM to ICE --------*- 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 LLVM to ICE converter. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 12 | /// |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef SUBZERO_SRC_ICECONVERTER_H |
| 16 | #define SUBZERO_SRC_ICECONVERTER_H |
| 17 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 18 | #include "IceDefs.h" |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 19 | #include "IceTranslator.h" |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 22 | class GlobalValue; |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 23 | class Module; |
Antonio Maiorano | debdfa2 | 2020-11-10 16:28:34 -0500 | [diff] [blame] | 24 | } // namespace llvm |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 25 | |
| 26 | namespace Ice { |
| 27 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 28 | class Converter : public Translator { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 29 | Converter() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 30 | Converter(const Converter &) = delete; |
| 31 | Converter &operator=(const Converter &) = delete; |
| 32 | |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 33 | public: |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 34 | Converter(llvm::Module *Mod, GlobalContext *Ctx) |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 35 | : Translator(Ctx), Mod(Mod), |
| 36 | GlobalDeclarationsPool(new VariableDeclarationList()) {} |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 37 | |
Jim Stichnoth | f4fbf7f | 2015-08-08 08:37:02 -0700 | [diff] [blame] | 38 | ~Converter() override = default; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 39 | |
Karl Schimpf | b164d20 | 2014-07-11 10:26:34 -0700 | [diff] [blame] | 40 | /// Converts the LLVM Module to ICE. Sets exit status to false if successful, |
| 41 | /// true otherwise. |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 42 | void convertToIce(); |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 43 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 44 | llvm::Module *getModule() const { return Mod; } |
| 45 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 46 | /// Returns the global declaration associated with the corresponding global |
| 47 | /// value V. If no such global address, generates fatal error. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 48 | GlobalDeclaration *getGlobalDeclaration(const llvm::GlobalValue *V); |
| 49 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 50 | private: |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 51 | llvm::Module *Mod; |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 52 | using GlobalDeclarationMapType = |
| 53 | std::map<const llvm::GlobalValue *, GlobalDeclaration *>; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 54 | GlobalDeclarationMapType GlobalDeclarationMap; |
| 55 | |
John Porto | a78e4ba | 2016-03-15 09:28:04 -0700 | [diff] [blame] | 56 | std::unique_ptr<VariableDeclarationList> GlobalDeclarationsPool; |
| 57 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 58 | /// Walks module and generates names for unnamed globals using prefix |
| 59 | /// getFlags().DefaultGlobalPrefix, if the prefix is non-empty. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 60 | void nameUnnamedGlobalVariables(llvm::Module *Mod); |
| 61 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 62 | /// Walks module and generates names for unnamed functions using prefix |
| 63 | /// getFlags().DefaultFunctionPrefix, if the prefix is non-empty. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 64 | void nameUnnamedFunctions(llvm::Module *Mod); |
| 65 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 66 | /// Converts functions to ICE, and then machine code. |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 67 | void convertFunctions(); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 68 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 69 | /// Converts globals to ICE, and then machine code. |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 70 | void convertGlobals(llvm::Module *Mod); |
| 71 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 72 | /// Installs global declarations into GlobalDeclarationMap. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 73 | void installGlobalDeclarations(llvm::Module *Mod); |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 74 | }; |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 75 | |
Antonio Maiorano | debdfa2 | 2020-11-10 16:28:34 -0500 | [diff] [blame] | 76 | } // namespace Ice |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 77 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 78 | #endif // SUBZERO_SRC_ICECONVERTER_H |