blob: 22288af503c0a846cf3c7f6762752689ad5a14fb [file] [log] [blame]
Karl Schimpfe1e013c2014-06-27 09:15:29 -07001//===- 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//===----------------------------------------------------------------------===//
Andrew Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
Jim Stichnoth92a6e5b2015-12-02 16:52:44 -080011/// \brief Declares the LLVM to ICE converter.
Andrew Scull9612d322015-07-06 14:53:25 -070012///
Karl Schimpfe1e013c2014-06-27 09:15:29 -070013//===----------------------------------------------------------------------===//
14
15#ifndef SUBZERO_SRC_ICECONVERTER_H
16#define SUBZERO_SRC_ICECONVERTER_H
17
Karl Schimpf9d98d792014-10-13 15:01:08 -070018#include "IceDefs.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070019#include "IceTranslator.h"
Karl Schimpfe1e013c2014-06-27 09:15:29 -070020
21namespace llvm {
Karl Schimpf9d98d792014-10-13 15:01:08 -070022class GlobalValue;
Karl Schimpfe1e013c2014-06-27 09:15:29 -070023class Module;
24}
25
26namespace Ice {
27
Karl Schimpf8d7abae2014-07-07 14:50:30 -070028class Converter : public Translator {
Jim Stichnothc6ead202015-02-24 09:30:30 -080029 Converter() = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -070030 Converter(const Converter &) = delete;
31 Converter &operator=(const Converter &) = delete;
32
Karl Schimpfe1e013c2014-06-27 09:15:29 -070033public:
Jim Stichnothbbca7542015-02-11 16:08:31 -080034 Converter(llvm::Module *Mod, GlobalContext *Ctx)
35 : Translator(Ctx), Mod(Mod) {}
Karl Schimpfe3f64d02014-10-07 10:38:22 -070036
Jim Stichnothf4fbf7f2015-08-08 08:37:02 -070037 ~Converter() override = default;
Karl Schimpf9d98d792014-10-13 15:01:08 -070038
Karl Schimpfb164d202014-07-11 10:26:34 -070039 /// Converts the LLVM Module to ICE. Sets exit status to false if successful,
40 /// true otherwise.
Karl Schimpfd6064a12014-08-27 15:34:58 -070041 void convertToIce();
Karl Schimpfe1e013c2014-06-27 09:15:29 -070042
Karl Schimpf9d98d792014-10-13 15:01:08 -070043 llvm::Module *getModule() const { return Mod; }
44
Andrew Scull57e12682015-09-16 11:30:19 -070045 /// Returns the global declaration associated with the corresponding global
46 /// value V. If no such global address, generates fatal error.
Karl Schimpf9d98d792014-10-13 15:01:08 -070047 GlobalDeclaration *getGlobalDeclaration(const llvm::GlobalValue *V);
48
Karl Schimpf8d7abae2014-07-07 14:50:30 -070049private:
Karl Schimpfd6064a12014-08-27 15:34:58 -070050 llvm::Module *Mod;
Andrew Scull8072bae2015-09-14 16:01:26 -070051 using GlobalDeclarationMapType =
52 std::map<const llvm::GlobalValue *, GlobalDeclaration *>;
Karl Schimpf9d98d792014-10-13 15:01:08 -070053 GlobalDeclarationMapType GlobalDeclarationMap;
54
Andrew Scull9612d322015-07-06 14:53:25 -070055 /// Walks module and generates names for unnamed globals using prefix
56 /// getFlags().DefaultGlobalPrefix, if the prefix is non-empty.
Karl Schimpf9d98d792014-10-13 15:01:08 -070057 void nameUnnamedGlobalVariables(llvm::Module *Mod);
58
Andrew Scull57e12682015-09-16 11:30:19 -070059 /// Walks module and generates names for unnamed functions using prefix
60 /// getFlags().DefaultFunctionPrefix, if the prefix is non-empty.
Karl Schimpf9d98d792014-10-13 15:01:08 -070061 void nameUnnamedFunctions(llvm::Module *Mod);
62
Andrew Scull9612d322015-07-06 14:53:25 -070063 /// Converts functions to ICE, and then machine code.
Karl Schimpfd6064a12014-08-27 15:34:58 -070064 void convertFunctions();
Karl Schimpfe3f64d02014-10-07 10:38:22 -070065
Andrew Scull9612d322015-07-06 14:53:25 -070066 /// Converts globals to ICE, and then machine code.
Karl Schimpfe3f64d02014-10-07 10:38:22 -070067 void convertGlobals(llvm::Module *Mod);
68
Andrew Scull9612d322015-07-06 14:53:25 -070069 /// Installs global declarations into GlobalDeclarationMap.
Karl Schimpf9d98d792014-10-13 15:01:08 -070070 void installGlobalDeclarations(llvm::Module *Mod);
Karl Schimpf8d7abae2014-07-07 14:50:30 -070071};
Karl Schimpfe3f64d02014-10-07 10:38:22 -070072
73} // end of namespace ICE.
Karl Schimpfe1e013c2014-06-27 09:15:29 -070074
Karl Schimpf8d7abae2014-07-07 14:50:30 -070075#endif // SUBZERO_SRC_ICECONVERTER_H