1 //===- DerivedUser.h - Base for non-IR Users --------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_IR_DERIVEDUSER_H 11 #define LLVM_IR_DERIVEDUSER_H 12 13 #include "llvm/IR/User.h" 14 15 namespace llvm { 16 17 class Type; 18 class Use; 19 20 /// Extension point for the Value hierarchy. All classes outside of lib/IR 21 /// that wish to inherit from User should instead inherit from DerivedUser 22 /// instead. Inheriting from this class is discouraged. 23 /// 24 /// Generally speaking, Value is the base of a closed class hierarchy 25 /// that can't be extended by code outside of lib/IR. This class creates a 26 /// loophole that allows classes outside of lib/IR to extend User to leverage 27 /// its use/def list machinery. 28 class DerivedUser : public User { 29 protected: 30 using DeleteValueTy = void (*)(DerivedUser *); 31 32 private: 33 friend class Value; 34 35 DeleteValueTy DeleteValue; 36 37 public: DerivedUser(Type * Ty,unsigned VK,Use * U,unsigned NumOps,DeleteValueTy DeleteValue)38 DerivedUser(Type *Ty, unsigned VK, Use *U, unsigned NumOps, 39 DeleteValueTy DeleteValue) 40 : User(Ty, VK, U, NumOps), DeleteValue(DeleteValue) {} 41 }; 42 43 } // end namespace llvm 44 45 #endif // LLVM_IR_DERIVEDUSER_H 46