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; |
| 24 | } |
| 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) |
| 35 | : Translator(Ctx), Mod(Mod) {} |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 36 | |
Jim Stichnoth | f4fbf7f | 2015-08-08 08:37:02 -0700 | [diff] [blame] | 37 | ~Converter() override = default; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 38 | |
Karl Schimpf | b164d20 | 2014-07-11 10:26:34 -0700 | [diff] [blame] | 39 | /// Converts the LLVM Module to ICE. Sets exit status to false if successful, |
| 40 | /// true otherwise. |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 41 | void convertToIce(); |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 42 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 43 | llvm::Module *getModule() const { return Mod; } |
| 44 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 45 | /// Returns the global declaration associated with the corresponding global |
| 46 | /// value V. If no such global address, generates fatal error. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 47 | GlobalDeclaration *getGlobalDeclaration(const llvm::GlobalValue *V); |
| 48 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 49 | private: |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 50 | llvm::Module *Mod; |
Andrew Scull | 8072bae | 2015-09-14 16:01:26 -0700 | [diff] [blame] | 51 | using GlobalDeclarationMapType = |
| 52 | std::map<const llvm::GlobalValue *, GlobalDeclaration *>; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 53 | GlobalDeclarationMapType GlobalDeclarationMap; |
| 54 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 55 | /// Walks module and generates names for unnamed globals using prefix |
| 56 | /// getFlags().DefaultGlobalPrefix, if the prefix is non-empty. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 57 | void nameUnnamedGlobalVariables(llvm::Module *Mod); |
| 58 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 59 | /// Walks module and generates names for unnamed functions using prefix |
| 60 | /// getFlags().DefaultFunctionPrefix, if the prefix is non-empty. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 61 | void nameUnnamedFunctions(llvm::Module *Mod); |
| 62 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 63 | /// Converts functions to ICE, and then machine code. |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 64 | void convertFunctions(); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 65 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 66 | /// Converts globals to ICE, and then machine code. |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 67 | void convertGlobals(llvm::Module *Mod); |
| 68 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 69 | /// Installs global declarations into GlobalDeclarationMap. |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 70 | void installGlobalDeclarations(llvm::Module *Mod); |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 71 | }; |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 72 | |
| 73 | } // end of namespace ICE. |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 74 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 75 | #endif // SUBZERO_SRC_ICECONVERTER_H |