Home | History | Annotate | Download | only in src
      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 /// \file
     11 /// \brief Declares the LLVM to ICE converter.
     12 ///
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef SUBZERO_SRC_ICECONVERTER_H
     16 #define SUBZERO_SRC_ICECONVERTER_H
     17 
     18 #include "IceDefs.h"
     19 #include "IceTranslator.h"
     20 
     21 namespace llvm {
     22 class GlobalValue;
     23 class Module;
     24 }
     25 
     26 namespace Ice {
     27 
     28 class Converter : public Translator {
     29   Converter() = delete;
     30   Converter(const Converter &) = delete;
     31   Converter &operator=(const Converter &) = delete;
     32 
     33 public:
     34   Converter(llvm::Module *Mod, GlobalContext *Ctx)
     35       : Translator(Ctx), Mod(Mod),
     36         GlobalDeclarationsPool(new VariableDeclarationList()) {}
     37 
     38   ~Converter() override = default;
     39 
     40   /// Converts the LLVM Module to ICE. Sets exit status to false if successful,
     41   /// true otherwise.
     42   void convertToIce();
     43 
     44   llvm::Module *getModule() const { return Mod; }
     45 
     46   /// Returns the global declaration associated with the corresponding global
     47   /// value V. If no such global address, generates fatal error.
     48   GlobalDeclaration *getGlobalDeclaration(const llvm::GlobalValue *V);
     49 
     50 private:
     51   llvm::Module *Mod;
     52   using GlobalDeclarationMapType =
     53       std::map<const llvm::GlobalValue *, GlobalDeclaration *>;
     54   GlobalDeclarationMapType GlobalDeclarationMap;
     55 
     56   std::unique_ptr<VariableDeclarationList> GlobalDeclarationsPool;
     57 
     58   /// Walks module and generates names for unnamed globals using prefix
     59   /// getFlags().DefaultGlobalPrefix, if the prefix is non-empty.
     60   void nameUnnamedGlobalVariables(llvm::Module *Mod);
     61 
     62   /// Walks module and generates names for unnamed functions using prefix
     63   /// getFlags().DefaultFunctionPrefix, if the prefix is non-empty.
     64   void nameUnnamedFunctions(llvm::Module *Mod);
     65 
     66   /// Converts functions to ICE, and then machine code.
     67   void convertFunctions();
     68 
     69   /// Converts globals to ICE, and then machine code.
     70   void convertGlobals(llvm::Module *Mod);
     71 
     72   /// Installs global declarations into GlobalDeclarationMap.
     73   void installGlobalDeclarations(llvm::Module *Mod);
     74 };
     75 
     76 } // end of namespace ICE.
     77 
     78 #endif // SUBZERO_SRC_ICECONVERTER_H
     79