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