blob: 1ecd998ca0403be3644467039b2fd2e6bae3b572 [file] [log] [blame]
Karl Schimpf8d7abae2014-07-07 14:50:30 -07001//===- 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//===----------------------------------------------------------------------===//
Andrew Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Declares the general driver class for translating ICE to machine
Andrew Scull57e12682015-09-16 11:30:19 -070012/// code.
Andrew Scull9612d322015-07-06 14:53:25 -070013///
Karl Schimpf8d7abae2014-07-07 14:50:30 -070014//===----------------------------------------------------------------------===//
15
16#ifndef SUBZERO_SRC_ICETRANSLATOR_H
17#define SUBZERO_SRC_ICETRANSLATOR_H
18
John Porto67f8de92015-06-25 10:14:17 -070019#include "IceDefs.h"
20#include "IceGlobalContext.h"
21
Karl Schimpf5ee234a2014-09-12 10:41:40 -070022namespace llvm {
23class Module;
John Porto67f8de92015-06-25 10:14:17 -070024} // end of namespace llvm
Karl Schimpf5ee234a2014-09-12 10:41:40 -070025
Karl Schimpf8d7abae2014-07-07 14:50:30 -070026namespace Ice {
27
28class ClFlags;
29class Cfg;
Karl Schimpf9d98d792014-10-13 15:01:08 -070030class VariableDeclaration;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070031class GlobalContext;
32
Andrew Scull57e12682015-09-16 11:30:19 -070033/// Base class for translating ICE to machine code. Derived classes convert
Andrew Scull9612d322015-07-06 14:53:25 -070034/// other intermediate representations down to ICE, and then call the
35/// appropriate (inherited) methods to convert ICE into machine instructions.
Karl Schimpf8d7abae2014-07-07 14:50:30 -070036class Translator {
Jim Stichnothc6ead202015-02-24 09:30:30 -080037 Translator() = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -070038 Translator(const Translator &) = delete;
39 Translator &operator=(const Translator &) = delete;
40
Karl Schimpf8d7abae2014-07-07 14:50:30 -070041public:
Jim Stichnothc6ead202015-02-24 09:30:30 -080042 explicit Translator(GlobalContext *Ctx);
Jan Voung72984d82015-01-29 14:42:38 -080043
Jim Stichnothf4fbf7f2015-08-08 08:37:02 -070044 virtual ~Translator() = default;
Jim Stichnothfa4efea2015-01-27 05:06:03 -080045 const ErrorCode &getErrorStatus() const { return ErrorStatus; }
Karl Schimpf8d7abae2014-07-07 14:50:30 -070046
Karl Schimpfd6064a12014-08-27 15:34:58 -070047 GlobalContext *getContext() const { return Ctx; }
48
Jim Stichnothbbca7542015-02-11 16:08:31 -080049 const ClFlags &getFlags() const { return Ctx->getFlags(); }
Karl Schimpfd6064a12014-08-27 15:34:58 -070050
Andrew Scull57e12682015-09-16 11:30:19 -070051 /// Translates the constructed ICE function Fcn to machine code. Takes
52 /// ownership of Func.
Jim Stichnoth8e928382015-02-02 17:03:08 -080053 void translateFcn(std::unique_ptr<Cfg> Func);
Karl Schimpfd6064a12014-08-27 15:34:58 -070054
Andrew Scull57e12682015-09-16 11:30:19 -070055 /// Lowers the given list of global addresses to target. Generates list of
56 /// corresponding variable declarations.
Jim Stichnothbbca7542015-02-11 16:08:31 -080057 void
58 lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070059
60 /// Creates a name using the given prefix and corresponding index.
61 std::string createUnnamedName(const IceString &Prefix, SizeT Index);
62
Andrew Scull57e12682015-09-16 11:30:19 -070063 /// Reports if there is a (potential) conflict between Name, and using Prefix
64 /// to name unnamed names. Errors are put on Ostream. Returns true if there
65 /// isn't a potential conflict.
Karl Schimpfe3f64d02014-10-07 10:38:22 -070066 bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind,
Jim Stichnothe4a8f402015-01-20 12:52:51 -080067 const IceString &Prefix);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070068
Jim Stichnothbbca7542015-02-11 16:08:31 -080069 uint32_t getNextSequenceNumber() { return NextSequenceNumber++; }
70
Karl Schimpf8d7abae2014-07-07 14:50:30 -070071protected:
72 GlobalContext *Ctx;
Jim Stichnothbbca7542015-02-11 16:08:31 -080073 uint32_t NextSequenceNumber;
Andrew Scull9612d322015-07-06 14:53:25 -070074 /// ErrorCode of the translation.
Jim Stichnothfa4efea2015-01-27 05:06:03 -080075 ErrorCode ErrorStatus;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070076};
Jim Stichnoth7b451a92014-10-15 14:39:23 -070077
78} // end of namespace Ice
Karl Schimpf8d7abae2014-07-07 14:50:30 -070079
80#endif // SUBZERO_SRC_ICETRANSLATOR_H