]> granicus.if.org Git - clang/commitdiff
Add infrastructure for emitting TBAA metadata with the "constant" flag.
authorDan Gohman <gohman@apple.com>
Mon, 25 Oct 2010 23:51:23 +0000 (23:51 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 25 Oct 2010 23:51:23 +0000 (23:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117328 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenTBAA.cpp
lib/CodeGen/CodeGenTBAA.h

index d8618f0d3ad0082ba538bbc0e30f3ba26faa5311..d4d71a755745cdb718199515e253ca331efb0ec3 100644 (file)
@@ -20,6 +20,8 @@
 #include "clang/AST/ASTContext.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Metadata.h"
+#include "llvm/Constants.h"
+#include "llvm/Type.h"
 using namespace clang;
 using namespace CodeGen;
 
@@ -57,13 +59,22 @@ llvm::MDNode *CodeGenTBAA::getChar() {
 /// 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,
-                                                   llvm::MDNode *Parent) {
+                                                   llvm::MDNode *Parent,
+                                                   bool Readonly) {
+  // Currently there is only one flag defined - the readonly flag.
+  llvm::Value *Flags = 0;
+  if (Readonly)
+    Flags = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), true);
+
+  // Set up the mdnode operand list.
   llvm::Value *Ops[] = {
     llvm::MDString::get(VMContext, NameStr),
-    Parent
+    Parent,
+    Flags
   };
 
-  return llvm::MDNode::get(VMContext, Ops, llvm::array_lengthof(Ops));
+  // Create the mdnode.
+  return llvm::MDNode::get(VMContext, Ops, llvm::array_lengthof(Ops) - !Flags);
 }
 
 llvm::MDNode *
index 5a56079fc9586b7fe0fb08e965150f993f7faa02..29f7f544d31196b94c9cfd55e7a20d44fbabed2b 100644 (file)
@@ -56,7 +56,8 @@ class CodeGenTBAA {
   llvm::MDNode *getChar();
 
   llvm::MDNode *getTBAAInfoForNamedType(llvm::StringRef NameStr,
-                                        llvm::MDNode *Parent);
+                                        llvm::MDNode *Parent,
+                                        bool Readonly = false);
 
 public:
   CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext &VMContext,