diff options
author | Dan Gohman <gohman@apple.com> | 2010-10-14 23:06:10 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-10-14 23:06:10 +0000 |
commit | 3d5aff5d3036b0ff09d114857cd2276134b3d8c9 (patch) | |
tree | 63d582147e979c75e55602858d0bcae7fff6b422 /lib/CodeGen/CodeGenTBAA.cpp | |
parent | 5bc794ff3034bad2b231b0841ea6d0a711c4af59 (diff) |
Experimental TBAA support.
This enables metadata generation by default, however the TBAA pass
in the optimizer is still disabled for now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116536 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenTBAA.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenTBAA.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGenTBAA.cpp b/lib/CodeGen/CodeGenTBAA.cpp new file mode 100644 index 0000000000..0039db81b4 --- /dev/null +++ b/lib/CodeGen/CodeGenTBAA.cpp @@ -0,0 +1,68 @@ +//===--- CodeGenTypes.cpp - TBAA information for LLVM CodeGen -------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This is the code that manages TBAA information. +// +//===----------------------------------------------------------------------===// + +#include "CodeGenTBAA.h" +#include "clang/AST/ASTContext.h" +#include "llvm/LLVMContext.h" +#include "llvm/Metadata.h" +using namespace clang; +using namespace CodeGen; + +CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext& VMContext, + const LangOptions &Features) + : Context(Ctx), VMContext(VMContext), Features(Features), Root(0), Char(0) { +} + +CodeGenTBAA::~CodeGenTBAA() { +} + +llvm::MDNode *CodeGenTBAA::getTBAAInfoForNamedType(const char *NameStr, + llvm::MDNode *Parent) { + llvm::Value *Ops[] = { + llvm::MDString::get(VMContext, NameStr), + Parent + }; + + return llvm::MDNode::get(VMContext, Ops, llvm::array_lengthof(Ops)); +} + +llvm::MDNode * +CodeGenTBAA::getTBAAInfo(QualType QTy) { + Type *Ty = Context.getCanonicalType(QTy).getTypePtr(); + + if (llvm::MDNode *N = MetadataCache[Ty]) + return N; + + if (!Root) { + Root = getTBAAInfoForNamedType("Experimental TBAA", 0); + Char = getTBAAInfoForNamedType("omnipotent char", Root); + } + + // For now, just emit a very minimal tree. + const Type *CanonicalTy = Context.getCanonicalType(Ty); + if (const BuiltinType *BTy = dyn_cast<BuiltinType>(CanonicalTy)) { + switch (BTy->getKind()) { + case BuiltinType::Char_U: + case BuiltinType::Char_S: + case BuiltinType::UChar: + case BuiltinType::SChar: + // Charactar types are special. + return Char; + default: + return MetadataCache[Ty] = + getTBAAInfoForNamedType(BTy->getName(Features), Char); + } + } + + return MetadataCache[Ty] = getTBAAInfoForNamedType("TBAA.other", Char); +} |