CodeGenTBAA.h revision 8cb4a070d491ddd671b049110cc8d0accb08b905
1//===--- CodeGenTBAA.h - TBAA information for LLVM CodeGen ------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
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 is the code that manages TBAA information and defines the TBAA policy
11// for the optimizer to use.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef CLANG_CODEGEN_CODEGENTBAA_H
16#define CLANG_CODEGEN_CODEGENTBAA_H
17
18#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/DenseMap.h"
20
21namespace llvm {
22  class LLVMContext;
23  class MDNode;
24}
25
26namespace clang {
27  class ASTContext;
28  class LangOptions;
29  class MangleContext;
30  class QualType;
31  class Type;
32
33namespace CodeGen {
34  class CGRecordLayout;
35
36/// CodeGenTBAA - This class organizes the cross-module state that is used
37/// while lowering AST types to LLVM types.
38class CodeGenTBAA {
39  ASTContext &Context;
40  llvm::LLVMContext& VMContext;
41  const LangOptions &Features;
42  MangleContext &MContext;
43
44  /// MetadataCache - This maps clang::Types to llvm::MDNodes describing them.
45  llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache;
46
47  llvm::MDNode *Root;
48  llvm::MDNode *Char;
49
50  /// getRoot - This is the mdnode for the root of the metadata type graph
51  /// for this translation unit.
52  llvm::MDNode *getRoot();
53
54  /// getChar - This is the mdnode for "char", which is special, and any types
55  /// considered to be equivalent to it.
56  llvm::MDNode *getChar();
57
58  llvm::MDNode *getTBAAInfoForNamedType(StringRef NameStr,
59                                        llvm::MDNode *Parent,
60                                        bool Readonly = false);
61
62public:
63  CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext,
64              const LangOptions &Features,
65              MangleContext &MContext);
66  ~CodeGenTBAA();
67
68  /// getTBAAInfo - Get the TBAA MDNode to be used for a dereference
69  /// of the given type.
70  llvm::MDNode *getTBAAInfo(QualType QTy);
71
72  /// getTBAAInfoForVTablePtr - Get the TBAA MDNode to be used for a
73  /// dereference of a vtable pointer.
74  llvm::MDNode *getTBAAInfoForVTablePtr();
75};
76
77}  // end namespace CodeGen
78}  // end namespace clang
79
80#endif
81