[llvm] r265016 - [IFUNC] Introduce GlobalIndirectSymbol as a base class for alias and ifunc

Dmitry Polukhin via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 07:16:21 PDT 2016


Author: dpolukhin
Date: Thu Mar 31 09:16:21 2016
New Revision: 265016

URL: http://llvm.org/viewvc/llvm-project?rev=265016&view=rev
Log:
[IFUNC] Introduce GlobalIndirectSymbol as a base class for alias and ifunc

This patch is a part of http://reviews.llvm.org/D15525

GlobalIndirectSymbol class contains common implementation for both
aliases and ifuncs. This patch should be NFC change that just prepare
common code for ifunc support.

Differential Revision: http://reviews.llvm.org/D18433

Added:
    llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h   (with props)
Modified:
    llvm/trunk/include/llvm/IR/GlobalAlias.h
    llvm/trunk/include/llvm/IR/Value.h
    llvm/trunk/lib/IR/Globals.cpp

Modified: llvm/trunk/include/llvm/IR/GlobalAlias.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalAlias.h?rev=265016&r1=265015&r2=265016&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalAlias.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalAlias.h Thu Mar 31 09:16:21 2016
@@ -17,15 +17,15 @@
 
 #include "llvm/ADT/Twine.h"
 #include "llvm/ADT/ilist_node.h"
-#include "llvm/IR/GlobalValue.h"
-#include "llvm/IR/OperandTraits.h"
+#include "llvm/IR/GlobalIndirectSymbol.h"
 
 namespace llvm {
 
 class Module;
 template <typename ValueSubClass> class SymbolTableListTraits;
 
-class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
+class GlobalAlias : public GlobalIndirectSymbol,
+                    public ilist_node<GlobalAlias> {
   friend class SymbolTableListTraits<GlobalAlias>;
   void operator=(const GlobalAlias &) = delete;
   GlobalAlias(const GlobalAlias &) = delete;
@@ -36,11 +36,6 @@ class GlobalAlias : public GlobalValue,
               const Twine &Name, Constant *Aliasee, Module *Parent);
 
 public:
-  // allocate space for exactly one operand
-  void *operator new(size_t s) {
-    return User::operator new(s, 1);
-  }
-
   /// If a parent module is specified, the alias is automatically inserted into
   /// the end of the specified module's alias list.
   static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
@@ -64,9 +59,6 @@ public:
   // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
   static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
 
-  /// Provide fast operand accessors
-  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
-
   /// removeFromParent - This method unlinks 'this' from the containing module,
   /// but does not delete it.
   ///
@@ -77,13 +69,13 @@ public:
   ///
   void eraseFromParent() override;
 
-  /// These methods retrive and set alias target.
+  /// These methods retrieve and set alias target.
   void setAliasee(Constant *Aliasee);
   const Constant *getAliasee() const {
-    return const_cast<GlobalAlias *>(this)->getAliasee();
+    return getIndirectSymbol();
   }
   Constant *getAliasee() {
-    return getOperand(0);
+    return getIndirectSymbol();
   }
 
   const GlobalObject *getBaseObject() const {
@@ -112,13 +104,6 @@ public:
   }
 };
 
-template <>
-struct OperandTraits<GlobalAlias> :
-  public FixedNumOperandTraits<GlobalAlias, 1> {
-};
-
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
-
 } // End llvm namespace
 
 #endif

Added: llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h?rev=265016&view=auto
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h (added)
+++ llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h Thu Mar 31 09:16:21 2016
@@ -0,0 +1,67 @@
+//===- llvm/GlobalIndirectSymbol.h - GlobalIndirectSymbol class -*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the declaration of the GlobalIndirectSymbol class, which
+// is a base class for GlobalAlias and GlobalIFunc. It contains all common code
+// for aliases and ifuncs.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_GLOBALINDIRECTSYMBOL_H
+#define LLVM_IR_GLOBALINDIRECTSYMBOL_H
+
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/OperandTraits.h"
+
+namespace llvm {
+
+class GlobalIndirectSymbol : public GlobalValue {
+  void operator=(const GlobalIndirectSymbol &) = delete;
+  GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete;
+
+protected:
+  GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace,
+      LinkageTypes Linkage, const Twine &Name, Constant *Symbol);
+
+public:
+  // allocate space for exactly one operand
+  void *operator new(size_t s) {
+    return User::operator new(s, 1);
+  }
+
+  /// Provide fast operand accessors
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+
+  /// These methods set and retrieve indirect symbol.
+  void setIndirectSymbol(Constant *Symbol) {
+    setOperand(0, Symbol);
+  }
+  const Constant *getIndirectSymbol() const {
+    return const_cast<GlobalIndirectSymbol *>(this)->getIndirectSymbol();
+  }
+  Constant *getIndirectSymbol() {
+    return getOperand(0);
+  }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const Value *V) {
+    return V->getValueID() == Value::GlobalAliasVal;
+  }
+};
+
+template <>
+struct OperandTraits<GlobalIndirectSymbol> :
+  public FixedNumOperandTraits<GlobalIndirectSymbol, 1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
+
+} // End llvm namespace
+
+#endif

Propchange: llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Rev URL"

Propchange: llvm/trunk/include/llvm/IR/GlobalIndirectSymbol.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: llvm/trunk/include/llvm/IR/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Value.h?rev=265016&r1=265015&r2=265016&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Value.h (original)
+++ llvm/trunk/include/llvm/IR/Value.h Thu Mar 31 09:16:21 2016
@@ -31,6 +31,7 @@ class ConstantData;
 class DataLayout;
 class Function;
 class GlobalAlias;
+class GlobalIndirectSymbol;
 class GlobalObject;
 class GlobalValue;
 class GlobalVariable;
@@ -742,9 +743,15 @@ template <> struct isa_impl<GlobalAlias,
   }
 };
 
+template <> struct isa_impl<GlobalIndirectSymbol, Value> {
+  static inline bool doit(const Value &Val) {
+    return isa<GlobalAlias>(Val);
+  }
+};
+
 template <> struct isa_impl<GlobalValue, Value> {
   static inline bool doit(const Value &Val) {
-    return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
+    return isa<GlobalObject>(Val) || isa<GlobalIndirectSymbol>(Val);
   }
 };
 

Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=265016&r1=265015&r2=265016&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Thu Mar 31 09:16:21 2016
@@ -294,16 +294,26 @@ void GlobalVariable::copyAttributesFrom(
 
 
 //===----------------------------------------------------------------------===//
+// GlobalIndirectSymbol Implementation
+//===----------------------------------------------------------------------===//
+
+GlobalIndirectSymbol::GlobalIndirectSymbol(Type *Ty, ValueTy VTy,
+    unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name,
+    Constant *Symbol)
+    : GlobalValue(Ty, VTy, &Op<0>(), 1, Linkage, Name, AddressSpace) {
+    Op<0>() = Symbol;
+}
+
+
+//===----------------------------------------------------------------------===//
 // GlobalAlias Implementation
 //===----------------------------------------------------------------------===//
 
 GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
                          const Twine &Name, Constant *Aliasee,
                          Module *ParentModule)
-    : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name,
-                  AddressSpace) {
-  Op<0>() = Aliasee;
-
+    : GlobalIndirectSymbol(Ty, Value::GlobalAliasVal, AddressSpace, Link, Name,
+                           Aliasee) {
   if (ParentModule)
     ParentModule->getAliasList().push_back(this);
 }
@@ -352,5 +362,5 @@ void GlobalAlias::eraseFromParent() {
 void GlobalAlias::setAliasee(Constant *Aliasee) {
   assert((!Aliasee || Aliasee->getType() == getType()) &&
          "Alias and aliasee types should match!");
-  setOperand(0, Aliasee);
+  setIndirectSymbol(Aliasee);
 }




More information about the llvm-commits mailing list