CodeGenTBAA.h revision c9fe6056e4ce8ffad1ef439fca3318a5faf1c075
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#include "llvm/Support/MDBuilder.h"
21
22namespace llvm {
23  class LLVMContext;
24  class MDNode;
25}
26
27namespace clang {
28  class ASTContext;
29  class CodeGenOptions;
30  class LangOptions;
31  class MangleContext;
32  class QualType;
33  class Type;
34
35namespace CodeGen {
36  class CGRecordLayout;
37
38/// CodeGenTBAA - This class organizes the cross-module state that is used
39/// while lowering AST types to LLVM types.
40class CodeGenTBAA {
41  ASTContext &Context;
42  llvm::LLVMContext& VMContext;
43  const CodeGenOptions &CodeGenOpts;
44  const LangOptions &Features;
45  MangleContext &MContext;
46
47  // MDHelper - Helper for creating metadata.
48  llvm::MDBuilder MDHelper;
49
50  /// MetadataCache - This maps clang::Types to llvm::MDNodes describing them.
51  llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache;
52
53  llvm::MDNode *Root;
54  llvm::MDNode *Char;
55
56  /// getRoot - This is the mdnode for the root of the metadata type graph
57  /// for this translation unit.
58  llvm::MDNode *getRoot();
59
60  /// getChar - This is the mdnode for "char", which is special, and any types
61  /// considered to be equivalent to it.
62  llvm::MDNode *getChar();
63
64public:
65  CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext,
66              const CodeGenOptions &CGO,
67              const LangOptions &Features,
68              MangleContext &MContext);
69  ~CodeGenTBAA();
70
71  /// getTBAAInfo - Get the TBAA MDNode to be used for a dereference
72  /// of the given type.
73  llvm::MDNode *getTBAAInfo(QualType QTy);
74
75  /// getTBAAInfoForVTablePtr - Get the TBAA MDNode to be used for a
76  /// dereference of a vtable pointer.
77  llvm::MDNode *getTBAAInfoForVTablePtr();
78};
79
80}  // end namespace CodeGen
81}  // end namespace clang
82
83#endif
84