blob: 05601b260d1d247fbcd42d855ada258d1f443503 [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
John Portobd2e2312016-03-15 11:06:25 -070022#include <memory>
23
Karl Schimpf5ee234a2014-09-12 10:41:40 -070024namespace llvm {
25class Module;
John Porto67f8de92015-06-25 10:14:17 -070026} // end of namespace llvm
Karl Schimpf5ee234a2014-09-12 10:41:40 -070027
Karl Schimpf8d7abae2014-07-07 14:50:30 -070028namespace Ice {
29
30class ClFlags;
31class Cfg;
Karl Schimpf9d98d792014-10-13 15:01:08 -070032class VariableDeclaration;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070033class GlobalContext;
34
Andrew Scull57e12682015-09-16 11:30:19 -070035/// Base class for translating ICE to machine code. Derived classes convert
Andrew Scull9612d322015-07-06 14:53:25 -070036/// other intermediate representations down to ICE, and then call the
37/// appropriate (inherited) methods to convert ICE into machine instructions.
Karl Schimpf8d7abae2014-07-07 14:50:30 -070038class Translator {
Jim Stichnothc6ead202015-02-24 09:30:30 -080039 Translator() = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -070040 Translator(const Translator &) = delete;
41 Translator &operator=(const Translator &) = delete;
42
Karl Schimpf8d7abae2014-07-07 14:50:30 -070043public:
Jim Stichnothc6ead202015-02-24 09:30:30 -080044 explicit Translator(GlobalContext *Ctx);
Jan Voung72984d82015-01-29 14:42:38 -080045
Jim Stichnothf4fbf7f2015-08-08 08:37:02 -070046 virtual ~Translator() = default;
Jim Stichnothfa4efea2015-01-27 05:06:03 -080047 const ErrorCode &getErrorStatus() const { return ErrorStatus; }
Karl Schimpf8d7abae2014-07-07 14:50:30 -070048
Karl Schimpfd6064a12014-08-27 15:34:58 -070049 GlobalContext *getContext() const { return Ctx; }
50
John Portobd2e2312016-03-15 11:06:25 -070051 /// Translates the constructed ICE function Func to machine code.
Jim Stichnoth8e928382015-02-02 17:03:08 -080052 void translateFcn(std::unique_ptr<Cfg> Func);
Karl Schimpfd6064a12014-08-27 15:34:58 -070053
Andrew Scull57e12682015-09-16 11:30:19 -070054 /// Lowers the given list of global addresses to target. Generates list of
55 /// corresponding variable declarations.
Jim Stichnothbbca7542015-02-11 16:08:31 -080056 void
57 lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070058
59 /// Creates a name using the given prefix and corresponding index.
Jim Stichnoth467ffe52016-03-29 15:01:06 -070060 std::string createUnnamedName(const std::string &Prefix, SizeT Index);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070061
Andrew Scull57e12682015-09-16 11:30:19 -070062 /// 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.
Jim Stichnoth467ffe52016-03-29 15:01:06 -070065 bool checkIfUnnamedNameSafe(const std::string &Name, const char *Kind,
66 const std::string &Prefix);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070067
Jim Stichnothbbca7542015-02-11 16:08:31 -080068 uint32_t getNextSequenceNumber() { return NextSequenceNumber++; }
69
Karl Schimpf8d7abae2014-07-07 14:50:30 -070070protected:
71 GlobalContext *Ctx;
Jim Stichnothbbca7542015-02-11 16:08:31 -080072 uint32_t NextSequenceNumber;
Andrew Scull9612d322015-07-06 14:53:25 -070073 /// ErrorCode of the translation.
Jim Stichnothfa4efea2015-01-27 05:06:03 -080074 ErrorCode ErrorStatus;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070075};
Jim Stichnoth7b451a92014-10-15 14:39:23 -070076
Eric Holk16f80612016-04-04 17:07:42 -070077class CfgOptWorkItem final : public OptWorkItem {
78 CfgOptWorkItem() = delete;
79 CfgOptWorkItem(const CfgOptWorkItem &) = delete;
80 CfgOptWorkItem &operator=(const CfgOptWorkItem &) = delete;
81
82public:
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
87private:
88 std::unique_ptr<Ice::Cfg> Func;
89};
90
Jim Stichnoth7b451a92014-10-15 14:39:23 -070091} // end of namespace Ice
Karl Schimpf8d7abae2014-07-07 14:50:30 -070092
93#endif // SUBZERO_SRC_ICETRANSLATOR_H