[PATCH] D18433: [IFUNC] Introduce GlobalIndirectSymbol as a base class for aliases and ifuncs

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 10:33:01 PDT 2016


> On 2016-Mar-30, at 01:13, Dmitry Polukhin <dmitry.polukhin at gmail.com> wrote:
> 
> DmitryPolukhin added a comment.
> 
> Friendly ping, please take a look! This patch is relatively short and has no functional changes, just class hierarchy preparation.
> 
> 
> http://reviews.llvm.org/D18433

LGTM, with a question.

> Index: include/llvm/IR/GlobalIndirectSymbol.h
> ===================================================================
> --- /dev/null
> +++ include/llvm/IR/GlobalIndirectSymbol.h
> @@ -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);
> +  }

Should setIndirectSymbol() be protected?  I feel like the IFunc
version might want to add some extra checks about the type of
symbol passed in, or constrain the type somehow.

Although maybe those checks would fit better in the verifier?

> +  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



More information about the llvm-commits mailing list