CodeGenTBAA::~CodeGenTBAA() {
}
+llvm::MDNode *CodeGenTBAA::getRoot() {
+ // Define the root of the tree. This identifies the tree, so that
+ // if our LLVM IR is linked with LLVM IR from a different front-end
+ // (or a different version of this front-end), their TBAA trees will
+ // remain distinct, and the optimizer will treat them conservatively.
+ if (!Root)
+ Root = getTBAAInfoForNamedType("Simple C/C++ TBAA", 0);
+
+ return Root;
+}
+
+llvm::MDNode *CodeGenTBAA::getChar() {
+ // Define the root of the tree for user-accessible memory. C and C++
+ // give special powers to char and certain similar types. However,
+ // these special powers only cover user-accessible memory, and doesn't
+ // include things like vtables.
+ if (!Char)
+ Char = getTBAAInfoForNamedType("omnipotent char", getRoot());
+
+ return Char;
+}
+
/// getTBAAInfoForNamedType - Create a TBAA tree node with the given string
/// as its identifier, and the given Parent node as its tree parent.
llvm::MDNode *CodeGenTBAA::getTBAAInfoForNamedType(llvm::StringRef NameStr,
if (llvm::MDNode *N = MetadataCache[Ty])
return N;
- // If this is our first node, create the initial tree.
- if (!Root) {
- // Define the root of the tree. This identifies the tree, so that
- // if our LLVM IR is linked with LLVM IR from a different front-end
- // (or a different version of this front-end), their TBAA trees will
- // remain distinct, and the optimizer will treat them conservatively.
- Root = getTBAAInfoForNamedType("Simple C/C++ TBAA", 0);
-
- // Define the root of the tree for user-accessible memory. C and C++
- // give special powers to char and certain similar types. However,
- // these special powers only cover user-accessible memory, and doesn't
- // include things like vtables.
- Char = getTBAAInfoForNamedType("omnipotent char", Root);
- }
-
// Handle builtin types.
if (const BuiltinType *BTy = dyn_cast<BuiltinType>(Ty)) {
switch (BTy->getKind()) {
case BuiltinType::Char_S:
case BuiltinType::UChar:
case BuiltinType::SChar:
- return Char;
+ return getChar();
// Unsigned types can alias their corresponding signed types.
case BuiltinType::UShort:
// "underlying types".
default:
return MetadataCache[Ty] =
- getTBAAInfoForNamedType(BTy->getName(Features), Char);
+ getTBAAInfoForNamedType(BTy->getName(Features), getChar());
}
}
// TODO: Implement C++'s type "similarity" and consider dis-"similar"
// pointers distinct.
if (Ty->isPointerType())
- return MetadataCache[Ty] = getTBAAInfoForNamedType("any pointer", Char);
+ return MetadataCache[Ty] = getTBAAInfoForNamedType("any pointer",
+ getChar());
// Enum types are distinct types. In C++ they have "underlying types",
// however they aren't related for TBAA.
// members into a single identifying MDNode.
if (!Features.CPlusPlus &&
ETy->getDecl()->getTypedefForAnonDecl())
- return MetadataCache[Ty] = Char;
+ return MetadataCache[Ty] = getChar();
// In C++ mode, types have linkage, so we can rely on the ODR and
// on their mangled names, if they're external.
// decl with local linkage or no linkage?
if (Features.CPlusPlus &&
ETy->getDecl()->getLinkage() != ExternalLinkage)
- return MetadataCache[Ty] = Char;
+ return MetadataCache[Ty] = getChar();
// TODO: This is using the RTTI name. Is there a better way to get
// a unique string for a type?
llvm::SmallString<256> OutName;
MContext.mangleCXXRTTIName(QualType(ETy, 0), OutName);
- return MetadataCache[Ty] = getTBAAInfoForNamedType(OutName, Char);
+ return MetadataCache[Ty] = getTBAAInfoForNamedType(OutName, getChar());
}
// For now, handle any other kind of type conservatively.
- return MetadataCache[Ty] = Char;
+ return MetadataCache[Ty] = getChar();
}
/// MetadataCache - This maps clang::Types to llvm::MDNodes describing them.
llvm::DenseMap<const Type *, llvm::MDNode *> MetadataCache;
- /// Root - This is the mdnode for the root of the metadata type graph
- /// for this translation unit.
llvm::MDNode *Root;
+ llvm::MDNode *Char;
- /// Char - This is the mdnode for "char", which is special, and any types
+ /// getRoot - This is the mdnode for the root of the metadata type graph
+ /// for this translation unit.
+ llvm::MDNode *getRoot();
+
+ /// getChar - This is the mdnode for "char", which is special, and any types
/// considered to be equivalent to it.
- llvm::MDNode *Char;
+ llvm::MDNode *getChar();
llvm::MDNode *getTBAAInfoForNamedType(llvm::StringRef NameStr,
llvm::MDNode *Parent);