Home | History | Annotate | Download | only in src
      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 //===----------------------------------------------------------------------===//
      9 ///
     10 /// \file
     11 /// \brief Declares the general driver class for translating ICE to machine
     12 /// code.
     13 ///
     14 //===----------------------------------------------------------------------===//
     15 
     16 #ifndef SUBZERO_SRC_ICETRANSLATOR_H
     17 #define SUBZERO_SRC_ICETRANSLATOR_H
     18 
     19 #include "IceDefs.h"
     20 #include "IceGlobalContext.h"
     21 
     22 #include <memory>
     23 
     24 namespace llvm {
     25 class Module;
     26 } // end of namespace llvm
     27 
     28 namespace Ice {
     29 
     30 class ClFlags;
     31 class Cfg;
     32 class VariableDeclaration;
     33 class GlobalContext;
     34 
     35 /// Base class for translating ICE to machine code. Derived classes convert
     36 /// other intermediate representations down to ICE, and then call the
     37 /// appropriate (inherited) methods to convert ICE into machine instructions.
     38 class Translator {
     39   Translator() = delete;
     40   Translator(const Translator &) = delete;
     41   Translator &operator=(const Translator &) = delete;
     42 
     43 public:
     44   explicit Translator(GlobalContext *Ctx);
     45 
     46   virtual ~Translator() = default;
     47   const ErrorCode &getErrorStatus() const { return ErrorStatus; }
     48 
     49   GlobalContext *getContext() const { return Ctx; }
     50 
     51   /// Translates the constructed ICE function Func to machine code.
     52   void translateFcn(std::unique_ptr<Cfg> Func);
     53 
     54   /// Lowers the given list of global addresses to target. Generates list of
     55   /// corresponding variable declarations.
     56   void
     57   lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations);
     58 
     59   /// Creates a name using the given prefix and corresponding index.
     60   std::string createUnnamedName(const std::string &Prefix, SizeT Index);
     61 
     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.
     65   bool checkIfUnnamedNameSafe(const std::string &Name, const char *Kind,
     66                               const std::string &Prefix);
     67 
     68   uint32_t getNextSequenceNumber() { return NextSequenceNumber++; }
     69 
     70 protected:
     71   GlobalContext *Ctx;
     72   uint32_t NextSequenceNumber;
     73   /// ErrorCode of the translation.
     74   ErrorCode ErrorStatus;
     75 };
     76 
     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 
     91 } // end of namespace Ice
     92 
     93 #endif // SUBZERO_SRC_ICETRANSLATOR_H
     94