blob: 623a4f047a0d47020960a246517672b2a91f7f5b [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//===----------------------------------------------------------------------===//
9//
10// This file declares the LLVM to ICE converter.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef SUBZERO_SRC_ICECONVERTER_H
15#define SUBZERO_SRC_ICECONVERTER_H
16
Karl Schimpf9d98d792014-10-13 15:01:08 -070017#include "IceDefs.h"
Karl Schimpf8d7abae2014-07-07 14:50:30 -070018#include "IceTranslator.h"
Karl Schimpfe1e013c2014-06-27 09:15:29 -070019
20namespace llvm {
Karl Schimpf9d98d792014-10-13 15:01:08 -070021class GlobalValue;
Karl Schimpfe1e013c2014-06-27 09:15:29 -070022class Module;
23}
24
25namespace Ice {
26
Karl Schimpf8d7abae2014-07-07 14:50:30 -070027class Converter : public Translator {
Jim Stichnoth7b451a92014-10-15 14:39:23 -070028 Converter(const Converter &) = delete;
29 Converter &operator=(const Converter &) = delete;
30
Karl Schimpfe1e013c2014-06-27 09:15:29 -070031public:
Karl Schimpfd6064a12014-08-27 15:34:58 -070032 Converter(llvm::Module *Mod, GlobalContext *Ctx, const Ice::ClFlags &Flags)
33 : Translator(Ctx, Flags), Mod(Mod) {}
Karl Schimpfe3f64d02014-10-07 10:38:22 -070034
Karl Schimpf9d98d792014-10-13 15:01:08 -070035 ~Converter() {}
36
Karl Schimpfb164d202014-07-11 10:26:34 -070037 /// Converts the LLVM Module to ICE. Sets exit status to false if successful,
38 /// true otherwise.
Karl Schimpfd6064a12014-08-27 15:34:58 -070039 void convertToIce();
Karl Schimpfe1e013c2014-06-27 09:15:29 -070040
Karl Schimpf9d98d792014-10-13 15:01:08 -070041 llvm::Module *getModule() const { return Mod; }
42
43 // Returns the global declaration associated with the corresponding
44 // global value V. If no such global address, generates fatal error.
45 GlobalDeclaration *getGlobalDeclaration(const llvm::GlobalValue *V);
46
Karl Schimpf8d7abae2014-07-07 14:50:30 -070047private:
Karl Schimpfd6064a12014-08-27 15:34:58 -070048 llvm::Module *Mod;
Karl Schimpf9d98d792014-10-13 15:01:08 -070049 typedef std::map<const llvm::GlobalValue *, GlobalDeclaration *>
50 GlobalDeclarationMapType;
51 GlobalDeclarationMapType GlobalDeclarationMap;
52
53 // Walks module and generates names for unnamed globals using prefix
54 // getFlags().DefaultGlobalPrefix, if the prefix is non-empty.
55 void nameUnnamedGlobalVariables(llvm::Module *Mod);
56
57 // Walks module and generates names for unnamed functions using
58 // prefix getFlags().DefaultFunctionPrefix, if the prefix is
59 // non-empty.
60 void nameUnnamedFunctions(llvm::Module *Mod);
61
Karl Schimpfb164d202014-07-11 10:26:34 -070062 // Converts functions to ICE, and then machine code.
Karl Schimpfd6064a12014-08-27 15:34:58 -070063 void convertFunctions();
Karl Schimpfe3f64d02014-10-07 10:38:22 -070064
65 // Converts globals to ICE, and then machine code.
66 void convertGlobals(llvm::Module *Mod);
67
Karl Schimpf9d98d792014-10-13 15:01:08 -070068 // Installs global declarations into GlobalDeclarationMap.
69 void installGlobalDeclarations(llvm::Module *Mod);
Karl Schimpf8d7abae2014-07-07 14:50:30 -070070};
Karl Schimpfe3f64d02014-10-07 10:38:22 -070071
72} // end of namespace ICE.
Karl Schimpfe1e013c2014-06-27 09:15:29 -070073
Karl Schimpf8d7abae2014-07-07 14:50:30 -070074#endif // SUBZERO_SRC_ICECONVERTER_H