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 22 namespace llvm { 23 class LLVMContext; 24 class MDNode; 25 } 26 27 namespace clang { 28 class ASTContext; 29 class LangOptions; 30 class MangleContext; 31 class QualType; 32 class Type; 33 34 namespace CodeGen { 35 class CGRecordLayout; 36 37 /// CodeGenTBAA - This class organizes the cross-module state that is used 38 /// while lowering AST types to LLVM types. 39 class CodeGenTBAA { 40 ASTContext &Context; 41 llvm::LLVMContext& VMContext; 42 const LangOptions &Features; 43 MangleContext &MContext; 44 45 // MDHelper - Helper for creating metadata. 46 llvm::MDBuilder MDHelper; 47 48 /// MetadataCache - This maps clang::Types to llvm::MDNodes describing them. 49 llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache; 50 51 llvm::MDNode *Root; 52 llvm::MDNode *Char; 53 54 /// getRoot - This is the mdnode for the root of the metadata type graph 55 /// for this translation unit. 56 llvm::MDNode *getRoot(); 57 58 /// getChar - This is the mdnode for "char", which is special, and any types 59 /// considered to be equivalent to it. 60 llvm::MDNode *getChar(); 61 62 public: 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