CodeGenTBAA.h revision b22c7dc707cf3770ff3b5e5f11f11fd0aaa06d9b
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/MDBuilder.h" 20#include "llvm/ADT/DenseMap.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 const CodeGenOptions &CodeGenOpts; 43 const LangOptions &Features; 44 MangleContext &MContext; 45 46 // MDHelper - Helper for creating metadata. 47 llvm::MDBuilder MDHelper; 48 49 /// MetadataCache - This maps clang::Types to llvm::MDNodes describing them. 50 llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache; 51 52 /// StructMetadataCache - This maps clang::Types to llvm::MDNodes describing 53 /// them for struct assignments. 54 llvm::DenseMap<const Type *, llvm::MDNode *> StructMetadataCache; 55 56 llvm::MDNode *Root; 57 llvm::MDNode *Char; 58 59 /// getRoot - This is the mdnode for the root of the metadata type graph 60 /// for this translation unit. 61 llvm::MDNode *getRoot(); 62 63 /// getChar - This is the mdnode for "char", which is special, and any types 64 /// considered to be equivalent to it. 65 llvm::MDNode *getChar(); 66 67 /// CollectFields - Collect information about the fields of a type for 68 /// !tbaa.struct metadata formation. Return false for an unsupported type. 69 bool CollectFields(uint64_t BaseOffset, 70 QualType Ty, 71 SmallVectorImpl<llvm::MDBuilder::TBAAStructField> &Fields, 72 bool MayAlias); 73 74public: 75 CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext, 76 const CodeGenOptions &CGO, 77 const LangOptions &Features, 78 MangleContext &MContext); 79 ~CodeGenTBAA(); 80 81 /// getTBAAInfo - Get the TBAA MDNode to be used for a dereference 82 /// of the given type. 83 llvm::MDNode *getTBAAInfo(QualType QTy); 84 85 /// getTBAAInfoForVTablePtr - Get the TBAA MDNode to be used for a 86 /// dereference of a vtable pointer. 87 llvm::MDNode *getTBAAInfoForVTablePtr(); 88 89 /// getTBAAStructInfo - Get the TBAAStruct MDNode to be used for a memcpy of 90 /// the given type. 91 llvm::MDNode *getTBAAStructInfo(QualType QTy); 92}; 93 94} // end namespace CodeGen 95} // end namespace clang 96 97#endif 98