blob: beb5bc077e1de921623e0fc0b0a1dcc359b02f21 [file] [log] [blame]
Jim Stichnothf7c9a142014-04-29 10:52:43 -07001//===- subzero/src/IceGlobalContext.h - Global context defs -----*- 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 aspects of the compilation that persist across
11// multiple functions.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef SUBZERO_SRC_ICEGLOBALCONTEXT_H
16#define SUBZERO_SRC_ICEGLOBALCONTEXT_H
17
18#include "llvm/ADT/OwningPtr.h"
19#include "llvm/Support/Allocator.h"
20#include "llvm/Support/raw_ostream.h"
21
22#include "IceDefs.h"
23#include "IceTypes.h"
24
25namespace Ice {
26
27// TODO: Accesses to all non-const fields of GlobalContext need to
28// be synchronized, especially the constant pool, the allocator, and
29// the output streams.
30class GlobalContext {
31public:
32 GlobalContext(llvm::raw_ostream *OsDump, llvm::raw_ostream *OsEmit,
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070033 VerboseMask Mask, TargetArch Arch, OptLevel Opt,
34 IceString TestPrefix);
Jim Stichnothf7c9a142014-04-29 10:52:43 -070035 ~GlobalContext();
36
37 // Returns true if any of the specified options in the verbose mask
38 // are set. If the argument is omitted, it checks if any verbose
39 // options at all are set. IceV_Timing is treated specially, so
40 // that running with just IceV_Timing verbosity doesn't trigger an
41 // avalanche of extra output.
42 bool isVerbose(VerboseMask Mask = (IceV_All & ~IceV_Timing)) const {
43 return VMask & Mask;
44 }
45 void setVerbose(VerboseMask Mask) { VMask = Mask; }
46 void addVerbose(VerboseMask Mask) { VMask |= Mask; }
47 void subVerbose(VerboseMask Mask) { VMask &= ~Mask; }
48
49 Ostream &getStrDump() { return StrDump; }
50 Ostream &getStrEmit() { return StrEmit; }
51
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070052 TargetArch getTargetArch() const { return Arch; }
53 OptLevel getOptLevel() const { return Opt; }
54
Jim Stichnothf7c9a142014-04-29 10:52:43 -070055 // When emitting assembly, we allow a string to be prepended to
56 // names of translated functions. This makes it easier to create an
57 // execution test against a reference translator like llc, with both
58 // translators using the same bitcode as input.
59 IceString getTestPrefix() const { return TestPrefix; }
60 IceString mangleName(const IceString &Name) const;
61
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070062 // The purpose of HasEmitted is to add a header comment at the
63 // beginning of assembly code emission, doing it once per file
64 // rather than once per function.
65 bool testAndSetHasEmittedFirstMethod() {
66 bool HasEmitted = HasEmittedFirstMethod;
67 HasEmittedFirstMethod = true;
68 return HasEmitted;
69 }
70
Jim Stichnothf7c9a142014-04-29 10:52:43 -070071 // Manage Constants.
72 // getConstant*() functions are not const because they might add
73 // something to the constant pool.
74 Constant *getConstantInt(Type Ty, uint64_t ConstantInt64);
75 Constant *getConstantFloat(float Value);
76 Constant *getConstantDouble(double Value);
77 // Returns a symbolic constant.
78 Constant *getConstantSym(Type Ty, int64_t Offset, const IceString &Name = "",
79 bool SuppressMangling = false);
Jim Stichnothf61d5b22014-05-23 13:31:24 -070080 // getConstantPool() returns a copy of the constant pool for
81 // constants of a given type.
82 ConstantList getConstantPool(Type Ty) const;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070083
84 // Allocate data of type T using the global allocator.
85 template <typename T> T *allocate() { return Allocator.Allocate<T>(); }
86
87private:
88 Ostream StrDump; // Stream for dumping / diagnostics
89 Ostream StrEmit; // Stream for code emission
90
91 llvm::BumpPtrAllocator Allocator;
92 VerboseMask VMask;
93 llvm::OwningPtr<class ConstantPool> ConstPool;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070094 const TargetArch Arch;
95 const OptLevel Opt;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070096 const IceString TestPrefix;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070097 bool HasEmittedFirstMethod;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070098 GlobalContext(const GlobalContext &) LLVM_DELETED_FUNCTION;
99 GlobalContext &operator=(const GlobalContext &) LLVM_DELETED_FUNCTION;
100};
101
102} // end of namespace Ice
103
104#endif // SUBZERO_SRC_ICEGLOBALCONTEXT_H