llvm.org GIT mirror llvm / 1afcace
Land the long talked about "type system rewrite" patch. This patch brings numerous advantages to LLVM. One way to look at it is through diffstat: 109 files changed, 3005 insertions(+), 5906 deletions(-) Removing almost 3K lines of code is a good thing. Other advantages include: 1. Value::getType() is a simple load that can be CSE'd, not a mutating union-find operation. 2. Types a uniqued and never move once created, defining away PATypeHolder. 3. Structs can be "named" now, and their name is part of the identity that uniques them. This means that the compiler doesn't merge them structurally which makes the IR much less confusing. 4. Now that there is no way to get a cycle in a type graph without a named struct type, "upreferences" go away. 5. Type refinement is completely gone, which should make LTO much MUCH faster in some common cases with C++ code. 6. Types are now generally immutable, so we can use "Type *" instead "const Type *" everywhere. Downsides of this patch are that it removes some functions from the C API, so people using those will have to upgrade to (not yet added) new API. "LLVM 3.0" is the right time to do this. There are still some cleanups pending after this, this patch is large enough as-is. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
109 changed file(s) with 3271 addition(s) and 6172 deletion(s). Raw diff Collapse all Expand all
7373
7474
  • Array Type
  • 7575
  • Structure Type
  • 76
  • Packed Structure Type
  • 76
  • Opaque Type
  • 7777
  • Vector Type
  • 7878
    7979
    8080
  • Function Type
  • 8181
  • Pointer Type
  • 82
  • Opaque Type
  • 8382
    8483
    85
  • Type Up-references
  • 8684
    8785
    8886
  • Constants
  • 15341532 function,
    15351533 pointer,
    15361534 structure,
    1537 packed structure,
    15381535 vector,
    15391536 opaque.
    15401537
    17021699 possible to have a two dimensional array, using an array as the element type
    17031700 of another array.

    17041701
    1705
    1702
    1703
    1704
    17061705
    17071706

    17081707 Aggregate Types
    18411840
    18421841
    Overview:
    18431842

    The structure type is used to represent a collection of data members together

    1844 in memory. The packing of the field types is defined to match the ABI of the
    1845 underlying processor. The elements of a structure may be any type that has a
    1846 size.

    1843 in memory. The elements of a structure may be any type that has a size.

    18471844
    18481845

    Structures in memory are accessed using 'load'

    18491846 and 'store' by getting a pointer to a field
    18511848 Structures in registers are accessed using the
    18521849 'extractvalue' and
    18531850 'insertvalue' instructions.

    1854
    Syntax:
    1855
    
                      
                    
    1856 { <type list> }
    1857
    1858
    1851
    1852

    Structures may optionally be "packed" structures, which indicate that the

    1853 alignment of the struct is one byte, and that there is no padding between
    1854 the elements. In non-packed structs, padding between field types is defined
    1855 by the target data string to match the underlying processor.

    1856
    1857

    Structures can either be "anonymous" or "named". An anonymous structure is

    1858 defined inline with other types (e.g. {i32, i32}*) and a named types
    1859 are always defined at the top level with a name. Anonmyous types are uniqued
    1860 by their contents and can never be recursive since there is no way to write
    1861 one. Named types can be recursive.
    1862

    1863
    1864
    Syntax:
    1865
    
                      
                    
    1866 %T1 = type { <type list> } ; Named normal struct type
    1867 %T2 = type <{ <type list> }> ; Named packed struct type
    1868
    1869
    18591870
    Examples:
    18601871
    18611872
    18621873 { i32, i32, i32 }
    18631874 A triple of three i32 values
    1864
    1875
    1876
    18651877 { float, i32 (i32) * }
    18661878 A pair, where the first element is a float and the
    18671879 second element is a pointer to a
    18681880 function that takes an i32, returning
    18691881 an i32.
    18701882
    1883
    1884 <{ i8, i32 }>
    1885 A packed struct known to be 5 bytes in size.
    1886
    18711887
    18721888
    18731889
    1874
    1875
    1876

    1877 Packed Structure Type
    1878
    1879
    1880
    1881
    1882
    Overview:
    1883

    The packed structure type is used to represent a collection of data members

    1884 together in memory. There is no padding between fields. Further, the
    1885 alignment of a packed structure is 1 byte. The elements of a packed
    1886 structure may be any type that has a size.

    1887
    1888

    Structures are accessed using 'load and

    1889 'store' by getting a pointer to a field with
    1890 the 'getelementptr' instruction.

    1891
    1892
    Syntax:
    1893
    
                      
                    
    1894 < { <type list> } >
    1890
    1891
    1892

    1893 Opaque Type
    1894
    1895
    1896
    1897
    1898
    Overview:
    1899

    Opaque types are used to represent named structure types that do not have a

    1900 body specified. This corresponds (for example) to the C notion of a forward
    1901 declared structure.

    1902
    1903
    Syntax:
    1904
    
                      
                    
    1905 %X = type opaque
    1906 %52 = type opaque
    18951907
    18961908
    18971909
    Examples:
    18981910
    18991911
    1900 < { i32, i32, i32 } >
    1901 A triple of three i32 values
    1902
    1903
    1904 < { float, i32 (i32)* } >
    1905 A pair, where the first element is a float and the
    1906 second element is a pointer to a
    1907 function that takes an i32, returning
    1908 an i32.
    1912 opaque
    1913 An opaque type.
    19091914
    19101915
    19111916
    19121917
    1918
    1919
    19131920
    19141921
    19151922

    19952002 Vector of 2 64-bit integer values.
    19962003
    19972004
    1998 1999
    2000 2001 2002

    2003 Opaque Type 2004

    2005 2006
    2007 2008
    Overview:
    2009

    Opaque types are used to represent unknown types in the system. This 2010 corresponds (for example) to the C notion of a forward declared structure 2011 type. In LLVM, opaque types can eventually be resolved to any type (not just 2012 a structure type).

    2013 2014
    Syntax:
    2015
    
                      
                    
    
                  2016
                        opaque
    
                      
                    
    
                  2017
                      
    2018 2019
    Examples:
    2020
    2021
    2022 opaque
    2023 An opaque type.
    2024
    2025
    2026 2027
    2028 2029
    2030 2031 2032

    2033 Type Up-references 2034

    2035 2036
    2037 2038
    Overview:
    2039

    An "up reference" allows you to refer to a lexically enclosing type without 2040 requiring it to have a name. For instance, a structure declaration may 2041 contain a pointer to any of the types it is lexically a member of. Example 2042 of up references (with their equivalent as named type declarations) 2043 include:

    2044 2045
    
                      
                    
    
                  2046
                         { \2 * }                %x = type { %x* }
    
                      
                    
    
                  2047
                         { \2 }*                 %y = type { %y }*
    
                      
                    
    
                  2048
                         \1*                     %z = type %z*
    
                      
                    
    
                  2049
                      
    2050 2051

    An up reference is needed by the asmprinter for printing out cyclic types 2052 when there is no declared name for a type in the cycle. Because the 2053 asmprinter does not want to print out an infinite type string, it needs a 2054 syntax to handle recursive types that have no names (all names are optional 2055 in llvm IR).

    2056 2057
    Syntax:
    2058
    
                      
                    
    
                  2059
                         \<level>
    
                      
                    
    
                  2060
                      
    2061 2062

    The level is the count of the lexical type that is being referred to.

    2063 2064
    Examples:
    2065
    2066
    2067 \1*
    2068 Self-referential pointer.
    2069
    2070
    2071 { { \3*, i8 }, i32 }
    2072 Recursive structure where the upref refers to the out-most
    2073 structure.
    2074
    2075
    2076 2077
    20782005 20792006
    20802007
    +7
    -191
    docs/ProgrammersManual.html less more
    159159
    160160
  • Advanced Topics
  • 161161
    162
  • LLVM Type Resolution
  • 163
    164
  • Basic Recursive Type Construction
  • 165
  • The refineAbstractTypeTo method
  • 166
  • The PATypeHolder Class
  • 167
  • The AbstractTypeUser Class
  • 168
    169
    170
  • The ValueSymbolTable and TypeSymbolTable classes
  • 162
    163
  • The ValueSymbolTable class
  • 171164
  • The User and owned Use classes' memory layout
  • 172165
    173166
    26442637 LLVM system, and only need to be accessed in unusual circumstances.
    26452638

    26462639
    2640
    26472641
    26482642

    2649 LLVM Type Resolution
    2650
    2651
    2652
    2653
    2654

    2655 The LLVM type system has a very simple goal: allow clients to compare types for
    2656 structural equality with a simple pointer comparison (aka a shallow compare).
    2657 This goal makes clients much simpler and faster, and is used throughout the LLVM
    2658 system.
    2659

    2660
    2661

    2662 Unfortunately achieving this goal is not a simple matter. In particular,
    2663 recursive types and late resolution of opaque types makes the situation very
    2664 difficult to handle. Fortunately, for the most part, our implementation makes
    2665 most clients able to be completely unaware of the nasty internal details. The
    2666 primary case where clients are exposed to the inner workings of it are when
    2667 building a recursive type. In addition to this case, the LLVM bitcode reader,
    2668 assembly parser, and linker also have to be aware of the inner workings of this
    2669 system.
    2670

    2671
    2672

    2673 For our purposes below, we need three concepts. First, an "Opaque Type" is
    2674 exactly as defined in the language
    2675 reference. Second an "Abstract Type" is any type which includes an
    2676 opaque type as part of its type graph (for example "{ opaque, i32 }").
    2677 Third, a concrete type is a type that is not an abstract type (e.g. "{ i32,
    2678 float }").
    2679

    2680
    2681
    2682

    2683 Basic Recursive Type Construction
    2684
    2685
    2686
    2687
    2688

    2689 Because the most common question is "how do I build a recursive type with LLVM",
    2690 we answer it now and explain it as we go. Here we include enough to cause this
    2691 to be emitted to an output .ll file:
    2692

    2693
    2694
    2695
    
                      
                    
    2696 %mylist = type { %mylist*, i32 }
    2697
    2698
    2699
    2700

    2701 To build this, use the following LLVM APIs:
    2702

    2703
    2704
    2705
    
                      
                    
    2706 // Create the initial outer struct
    2707 PATypeHolder StructTy = OpaqueType::get();
    2708 std::vector<const Type*> Elts;
    2709 Elts.push_back(PointerType::getUnqual(StructTy));
    2710 Elts.push_back(Type::Int32Ty);
    2711 StructType *NewSTy = StructType::get(Elts);
    2712
    2713 // At this point, NewSTy = "{ opaque*, i32 }". Tell VMCore that
    2714 // the struct and the opaque type are actually the same.
    2715 cast<OpaqueType>(StructTy.get())->refineAbstractTypeTo(NewSTy);
    2716
    2717 // NewSTy is potentially invalidated, but StructTy (a PATypeHolder) is
    2718 // kept up-to-date
    2719 NewSTy = cast<StructType>(StructTy.get());
    2720
    2721 // Add a name for the type to the module symbol table (optional)
    2722 MyModule->addTypeName("mylist", NewSTy);
    2723
    2724
    2725
    2726

    2727 This code shows the basic approach used to build recursive types: build a
    2728 non-recursive type using 'opaque', then use type unification to close the cycle.
    2729 The type unification step is performed by the
    2730 href="#refineAbstractTypeTo">refineAbstractTypeTo method, which is
    2731 described next. After that, we describe the
    2732 href="#PATypeHolder">PATypeHolder class.
    2733

    2734
    2735
    2736
    2737
    2738

    2739 The refineAbstractTypeTo method
    2740
    2741
    2742
    2743

    2744 The refineAbstractTypeTo method starts the type unification process.
    2745 While this method is actually a member of the DerivedType class, it is most
    2746 often used on OpaqueType instances. Type unification is actually a recursive
    2747 process. After unification, types can become structurally isomorphic to
    2748 existing types, and all duplicates are deleted (to preserve pointer equality).
    2749

    2750
    2751

    2752 In the example above, the OpaqueType object is definitely deleted.
    2753 Additionally, if there is an "{ \2*, i32}" type already created in the system,
    2754 the pointer and struct type created are also deleted. Obviously whenever
    2755 a type is deleted, any "Type*" pointers in the program are invalidated. As
    2756 such, it is safest to avoid having any "Type*" pointers to abstract types
    2757 live across a call to refineAbstractTypeTo (note that non-abstract
    2758 types can never move or be deleted). To deal with this, the
    2759 href="#PATypeHolder">PATypeHolder class is used to maintain a stable
    2760 reference to a possibly refined type, and the
    2761 href="#AbstractTypeUser">AbstractTypeUser class is used to update more
    2762 complex datastructures.
    2763

    2764
    2765
    2766
    2767
    2768

    2769 The PATypeHolder Class
    2770
    2771
    2772
    2773

    2774 PATypeHolder is a form of a "smart pointer" for Type objects. When VMCore
    2775 happily goes about nuking types that become isomorphic to existing types, it
    2776 automatically updates all PATypeHolder objects to point to the new type. In the
    2777 example above, this allows the code to maintain a pointer to the resultant
    2778 resolved recursive type, even though the Type*'s are potentially invalidated.
    2779

    2780
    2781

    2782 PATypeHolder is an extremely light-weight object that uses a lazy union-find
    2783 implementation to update pointers. For example the pointer from a Value to its
    2784 Type is maintained by PATypeHolder objects.
    2785

    2786
    2787
    2788
    2789
    2790

    2791 The AbstractTypeUser Class
    2792
    2793
    2794
    2795
    2796

    2797 Some data structures need more to perform more complex updates when types get
    2798 resolved. To support this, a class can derive from the AbstractTypeUser class.
    2799 This class
    2800 allows it to get callbacks when certain types are resolved. To register to get
    2801 callbacks for a particular type, the DerivedType::{add/remove}AbstractTypeUser
    2802 methods can be called on a type. Note that these methods only work for
    2803 abstract types. Concrete types (those that do not include any opaque
    2804 objects) can never be refined.
    2805

    2806
    2807
    2808
    2809
    2810
    2811

    2812 The ValueSymbolTable and
    2813 TypeSymbolTable classes
    2643 The ValueSymbolTable class
    28142644
    28152645
    28162646
    28192649 href="#Function">Function and
    28202650 Module classes use for naming value definitions. The symbol table
    28212651 can provide a name for any Value.
    2822 The
    2823 TypeSymbolTable class is used by the Module class to store
    2824 names for types.

    2652

    28252653
    28262654

    Note that the SymbolTable class should not be directly accessed

    28272655 by most clients. It should only be used when iteration over the symbol table
    28312659 an empty name) do not exist in the symbol table.
    28322660

    28332661
    2834

    These symbol tables support iteration over the values/types in the symbol

    2662

    Symbol tables support iteration over the values in the symbol

    28352663 table with begin/end/iterator and supports querying to see if a
    28362664 specific name is in the symbol table (with lookup). The
    28372665 ValueSymbolTable class exposes no public mutator methods, instead,
    28382666 simply call setName on a value, which will autoinsert it into the
    2839 appropriate symbol table. For types, use the Module::addTypeName method to
    2840 insert entries into the symbol table.

    2667 appropriate symbol table.

    28412668
    28422669
    28432670
    31262953
    31272954
  • bool isFloatingPointTy(): Return true if this is one of the five
  • 31282955 floating point types.
    3129
    3130
  • bool isAbstract(): Return true if the type is abstract (contains
  • 3131 an OpaqueType anywhere in its definition).
    31322956
    31332957
  • bool isSized(): Return true if the type has known size. Things
  • 31342958 that don't have a size are abstract types, labels and void.
    31913015 number of formal parameters.
    31923016
    31933017
    3194
    OpaqueType
    3195
    Sublcass of DerivedType for abstract types. This class
    3196 defines no content and is used as a placeholder for some other type. Note
    3197 that OpaqueType is used (temporarily) during type resolution for forward
    3198 references of types. Once the referenced type is resolved, the OpaqueType
    3199 is replaced with the actual type. OpaqueType can also be used for data
    3200 abstraction. At link time opaque types can be resolved to actual types
    3201 of the same name.
    32023018
    32033019
    32043020
    +0
    -205
    include/llvm/AbstractTypeUser.h less more
    None //===-- llvm/AbstractTypeUser.h - AbstractTypeUser Interface ----*- C++ -*-===//
    1 //
    2 // The LLVM Compiler Infrastructure
    3 //
    4 // This file is distributed under the University of Illinois Open Source
    5 // License. See LICENSE.TXT for details.
    6 //
    7 //===----------------------------------------------------------------------===//
    8 //
    9 // This file declares the AbstractTypeUser class.
    10 //
    11 //===----------------------------------------------------------------------===//
    12
    13 #ifndef LLVM_ABSTRACT_TYPE_USER_H
    14 #define LLVM_ABSTRACT_TYPE_USER_H
    15
    16 #if !defined(LLVM_TYPE_H) && !defined(LLVM_VALUE_H)
    17 #error Do not include this file directly. Include Type.h instead.
    18 #error Some versions of GCC (e.g. 3.4 and 4.1) can not handle the inlined method
    19 #error PATypeHolder::dropRef() correctly otherwise.
    20 #endif
    21
    22 // This is the "master" include for Whether this file needs it or not,
    23 // it must always include for the files which include
    24 // llvm/AbstractTypeUser.h
    25 //
    26 // In this way, most every LLVM source file will have access to the assert()
    27 // macro without having to #include directly.
    28 //
    29 #include
    30
    31 namespace llvm {
    32
    33 class Value;
    34 class Type;
    35 class DerivedType;
    36 template struct simplify_type;
    37
    38 /// The AbstractTypeUser class is an interface to be implemented by classes who
    39 /// could possibly use an abstract type. Abstract types are denoted by the
    40 /// isAbstract flag set to true in the Type class. These are classes that
    41 /// contain an Opaque type in their structure somewhere.
    42 ///
    43 /// Classes must implement this interface so that they may be notified when an
    44 /// abstract type is resolved. Abstract types may be resolved into more
    45 /// concrete types through: linking, parsing, and bitcode reading. When this
    46 /// happens, all of the users of the type must be updated to reference the new,
    47 /// more concrete type. They are notified through the AbstractTypeUser
    48 /// interface.
    49 ///
    50 /// In addition to this, AbstractTypeUsers must keep the use list of the
    51 /// potentially abstract type that they reference up-to-date. To do this in a
    52 /// nice, transparent way, the PATypeHandle class is used to hold "Potentially
    53 /// Abstract Types", and keep the use list of the abstract types up-to-date.
    54 /// @brief LLVM Abstract Type User Representation
    55 class AbstractTypeUser {
    56 protected:
    57 virtual ~AbstractTypeUser(); // Derive from me
    58
    59 /// setType - It's normally not possible to change a Value's type in place,
    60 /// but an AbstractTypeUser subclass that knows what its doing can be
    61 /// permitted to do so with care.
    62 void setType(Value *V, const Type *NewTy);
    63
    64 public:
    65
    66 /// refineAbstractType - The callback method invoked when an abstract type is
    67 /// resolved to another type. An object must override this method to update
    68 /// its internal state to reference NewType instead of OldType.
    69 ///
    70 virtual void refineAbstractType(const DerivedType *OldTy,
    71 const Type *NewTy) = 0;
    72
    73 /// The other case which AbstractTypeUsers must be aware of is when a type
    74 /// makes the transition from being abstract (where it has clients on its
    75 /// AbstractTypeUsers list) to concrete (where it does not). This method
    76 /// notifies ATU's when this occurs for a type.
    77 ///
    78 virtual void typeBecameConcrete(const DerivedType *AbsTy) = 0;
    79
    80 // for debugging...
    81 virtual void dump() const = 0;
    82 };
    83
    84
    85 /// PATypeHandle - Handle to a Type subclass. This class is used to keep the
    86 /// use list of abstract types up-to-date.
    87 ///
    88 class PATypeHandle {
    89 const Type *Ty;
    90 AbstractTypeUser * const User;
    91
    92 // These functions are defined at the bottom of Type.h. See the comment there
    93 // for justification.
    94 void addUser();
    95 void removeUser();
    96 public:
    97 // ctor - Add use to type if abstract. Note that Ty must not be null
    98 inline PATypeHandle(const Type *ty, AbstractTypeUser *user)
    99 : Ty(ty), User(user) {
    100 addUser();
    101 }
    102
    103 // ctor - Add use to type if abstract.
    104 inline PATypeHandle(const PATypeHandle &T) : Ty(T.Ty), User(T.User) {
    105 addUser();
    106 }
    107
    108 // dtor - Remove reference to type...
    109 inline ~PATypeHandle() { removeUser(); }
    110
    111 // Automatic casting operator so that the handle may be used naturally
    112 inline operator Type *() const { return const_cast(Ty); }
    113 inline Type *get() const { return const_cast(Ty); }
    114
    115 // operator= - Allow assignment to handle
    116 inline Type *operator=(const Type *ty) {
    117 if (Ty != ty) { // Ensure we don't accidentally drop last ref to Ty
    118 removeUser();
    119 Ty = ty;
    120 addUser();
    121 }
    122 return get();
    123 }
    124
    125 // operator= - Allow assignment to handle
    126 inline const Type *operator=(const PATypeHandle &T) {
    127 return operator=(T.Ty);
    128 }
    129
    130 inline bool operator==(const Type *ty) {
    131 return Ty == ty;
    132 }
    133
    134 // operator-> - Allow user to dereference handle naturally...
    135 inline const Type *operator->() const { return Ty; }
    136 };
    137
    138
    139 /// PATypeHolder - Holder class for a potentially abstract type. This uses
    140 /// efficient union-find techniques to handle dynamic type resolution. Unless
    141 /// you need to do custom processing when types are resolved, you should always
    142 /// use PATypeHolders in preference to PATypeHandles.
    143 ///
    144 class PATypeHolder {
    145 mutable const Type *Ty;
    146 void destroy();
    147 public:
    148 PATypeHolder() : Ty(0) {}
    149 PATypeHolder(const Type *ty) : Ty(ty) {
    150 addRef();
    151 }
    152 PATypeHolder(const PATypeHolder &T) : Ty(T.Ty) {
    153 addRef();
    154 }
    155
    156 ~PATypeHolder() { dropRef(); }
    157
    158 operator Type *() const { return get(); }
    159 Type *get() const;
    160
    161 // operator-> - Allow user to dereference handle naturally...
    162 Type *operator->() const { return get(); }
    163
    164 // operator= - Allow assignment to handle
    165 Type *operator=(const Type *ty) {
    166 if (Ty != ty) { // Don't accidentally drop last ref to Ty.
    167 dropRef();
    168 Ty = ty;
    169 addRef();
    170 }
    171 return get();
    172 }
    173 Type *operator=(const PATypeHolder &H) {
    174 return operator=(H.Ty);
    175 }
    176
    177 /// getRawType - This should only be used to implement the vmcore library.
    178 ///
    179 const Type *getRawType() const { return Ty; }
    180
    181 private:
    182 void addRef();
    183 void dropRef();
    184 friend class TypeMapBase;
    185 };
    186
    187 // simplify_type - Allow clients to treat uses just like values when using
    188 // casting operators.
    189 template<> struct simplify_type {
    190 typedef const Type* SimpleType;
    191 static SimpleType getSimplifiedValue(const PATypeHolder &Val) {
    192 return static_cast(Val.get());
    193 }
    194 };
    195 template<> struct simplify_type {
    196 typedef const Type* SimpleType;
    197 static SimpleType getSimplifiedValue(const PATypeHolder &Val) {
    198 return static_cast(Val.get());
    199 }
    200 };
    201
    202 } // End llvm namespace
    203
    204 #endif
    +39
    -22
    include/llvm/Bitcode/LLVMBitCodes.h less more
    2828
    2929 // Module sub-block id's.
    3030 PARAMATTR_BLOCK_ID,
    31 TYPE_BLOCK_ID,
    31
    32 /// TYPE_BLOCK_ID_OLD - This is the type descriptor block in LLVM 2.9 and
    33 /// earlier, replaced with TYPE_BLOCK_ID2. FIXME: Remove in LLVM 3.1.
    34 TYPE_BLOCK_ID_OLD,
    35
    3236 CONSTANTS_BLOCK_ID,
    3337 FUNCTION_BLOCK_ID,
    34 TYPE_SYMTAB_BLOCK_ID,
    38
    39 /// TYPE_SYMTAB_BLOCK_ID_OLD - This type descriptor is from LLVM 2.9 and
    40 /// earlier bitcode files. FIXME: Remove in LLVM 3.1
    41 TYPE_SYMTAB_BLOCK_ID_OLD,
    42
    3543 VALUE_SYMTAB_BLOCK_ID,
    3644 METADATA_BLOCK_ID,
    37 METADATA_ATTACHMENT_ID
    45 METADATA_ATTACHMENT_ID,
    46
    47 TYPE_BLOCK_ID_NEW
    3848 };
    3949
    4050
    7181
    7282 /// TYPE blocks have codes for each type primitive they use.
    7383 enum TypeCodes {
    74 TYPE_CODE_NUMENTRY = 1, // NUMENTRY: [numentries]
    84 TYPE_CODE_NUMENTRY = 1, // NUMENTRY: [numentries]
    7585
    7686 // Type Codes
    77 TYPE_CODE_VOID = 2, // VOID
    78 TYPE_CODE_FLOAT = 3, // FLOAT
    79 TYPE_CODE_DOUBLE = 4, // DOUBLE
    80 TYPE_CODE_LABEL = 5, // LABEL
    81 TYPE_CODE_OPAQUE = 6, // OPAQUE
    82 TYPE_CODE_INTEGER = 7, // INTEGER: [width]
    83 TYPE_CODE_POINTER = 8, // POINTER: [pointee type]
    84 TYPE_CODE_FUNCTION = 9, // FUNCTION: [vararg, retty, paramty x N]
    85 TYPE_CODE_STRUCT = 10, // STRUCT: [ispacked, eltty x N]
    86 TYPE_CODE_ARRAY = 11, // ARRAY: [numelts, eltty]
    87 TYPE_CODE_VECTOR = 12, // VECTOR: [numelts, eltty]
    87 TYPE_CODE_VOID = 2, // VOID
    88 TYPE_CODE_FLOAT = 3, // FLOAT
    89 TYPE_CODE_DOUBLE = 4, // DOUBLE
    90 TYPE_CODE_LABEL = 5, // LABEL
    91 TYPE_CODE_OPAQUE = 6, // OPAQUE
    92 TYPE_CODE_INTEGER = 7, // INTEGER: [width]
    93 TYPE_CODE_POINTER = 8, // POINTER: [pointee type]
    94 TYPE_CODE_FUNCTION = 9, // FUNCTION: [vararg, retty, paramty x N]
    95
    96 // FIXME: This is the encoding used for structs in LLVM 2.9 and earlier.
    97 // REMOVE this in LLVM 3.1
    98 TYPE_CODE_STRUCT_OLD = 10, // STRUCT: [ispacked, eltty x N]
    99 TYPE_CODE_ARRAY = 11, // ARRAY: [numelts, eltty]
    100 TYPE_CODE_VECTOR = 12, // VECTOR: [numelts, eltty]
    88101
    89102 // These are not with the other floating point types because they're
    90103 // a late addition, and putting them in the right place breaks
    91104 // binary compatibility.
    92 TYPE_CODE_X86_FP80 = 13, // X86 LONG DOUBLE
    93 TYPE_CODE_FP128 = 14, // LONG DOUBLE (112 bit mantissa)
    94 TYPE_CODE_PPC_FP128= 15, // PPC LONG DOUBLE (2 doubles)
    95
    96 TYPE_CODE_METADATA = 16, // METADATA
    97
    98 TYPE_CODE_X86_MMX = 17 // X86 MMX
    105 TYPE_CODE_X86_FP80 = 13, // X86 LONG DOUBLE
    106 TYPE_CODE_FP128 = 14, // LONG DOUBLE (112 bit mantissa)
    107 TYPE_CODE_PPC_FP128= 15, // PPC LONG DOUBLE (2 doubles)
    108
    109 TYPE_CODE_METADATA = 16, // METADATA
    110
    111 TYPE_CODE_X86_MMX = 17, // X86 MMX
    112
    113 TYPE_CODE_STRUCT_ANON = 18, // STRUCT_ANON: [ispacked, eltty x N]
    114 TYPE_CODE_STRUCT_NAME = 19, // STRUCT_NAME: [strchr x N]
    115 TYPE_CODE_STRUCT_NAMED = 20 // STRUCT_NAMED: [ispacked, eltty x N]
    99116 };
    100117
    101118 // The type symbol table only has one code (TST_ENTRY_CODE).
    +12
    -4
    include/llvm/Constants.h less more
    911911 Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
    912912
    913913 /// getWithOperands - This returns the current constant expression with the
    914 /// operands replaced with the specified values. The specified operands must
    915 /// match count and type with the existing ones.
    916 Constant *getWithOperands(ArrayRef Ops) const;
    917
    914 /// operands replaced with the specified values. The specified array must
    915 /// have the same number of operands as our current one.
    916 Constant *getWithOperands(ArrayRef Ops) const {
    917 return getWithOperands(Ops, getType());
    918 }
    919
    920 /// getWithOperands - This returns the current constant expression with the
    921 /// operands replaced with the specified values and with the specified result
    922 /// type. The specified array must have the same number of operands as our
    923 /// current one.
    924 Constant *getWithOperands(ArrayRef Ops, const Type *Ty) const;
    925
    918926 virtual void destroyConstant();
    919927 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
    920928
    +0
    -1
    include/llvm/DefaultPasses.h less more
    2828 extern unsigned char CorrelatedValuePropagationID;
    2929 extern unsigned char DeadArgEliminationID;
    3030 extern unsigned char DeadStoreEliminationID;
    31 extern unsigned char DeadTypeEliminationID;
    3231 extern unsigned char EarlyCSEID;
    3332 extern unsigned char FunctionAttrsID;
    3433 extern unsigned char FunctionInliningID;
    +84
    -112
    include/llvm/DerivedTypes.h less more
    2323 namespace llvm {
    2424
    2525 class Value;
    26 template class TypeMap;
    27 class FunctionValType;
    28 class ArrayValType;
    29 class StructValType;
    30 class PointerValType;
    31 class VectorValType;
    32 class IntegerValType;
    3326 class APInt;
    3427 class LLVMContext;
    3528 template class ArrayRef;
    29 class StringRef;
    3630
    3731 class DerivedType : public Type {
    38 friend class Type;
    39
    4032 protected:
    4133 explicit DerivedType(LLVMContext &C, TypeID id) : Type(C, id) {}
    42
    43 /// notifyUsesThatTypeBecameConcrete - Notify AbstractTypeUsers of this type
    44 /// that the current type has transitioned from being abstract to being
    45 /// concrete.
    46 ///
    47 void notifyUsesThatTypeBecameConcrete();
    48
    49 /// dropAllTypeUses - When this (abstract) type is resolved to be equal to
    50 /// another (more concrete) type, we must eliminate all references to other
    51 /// types, to avoid some circular reference problems.
    52 ///
    53 void dropAllTypeUses();
    54
    55 public:
    56
    57 //===--------------------------------------------------------------------===//
    58 // Abstract Type handling methods - These types have special lifetimes, which
    59 // are managed by (add|remove)AbstractTypeUser. See comments in
    60 // AbstractTypeUser.h for more information.
    61
    62 /// refineAbstractTypeTo - This function is used to when it is discovered that
    63 /// the 'this' abstract type is actually equivalent to the NewType specified.
    64 /// This causes all users of 'this' to switch to reference the more concrete
    65 /// type NewType and for 'this' to be deleted.
    66 ///
    67 void refineAbstractTypeTo(const Type *NewType);
    68
    69 void dump() const { Type::dump(); }
    34 public:
    7035
    7136 // Methods for support type inquiry through isa, cast, and dyn_cast.
    7237 static inline bool classof(const DerivedType *) { return true; }
    8752 DerivedType(C, IntegerTyID) {
    8853 setSubclassData(NumBits);
    8954 }
    90 friend class TypeMap;
    9155 public:
    9256 /// This enum is just used to hold constants we need for IntegerType.
    9357 enum {
    10266 /// that instance will be returned. Otherwise a new one will be created. Only
    10367 /// one instance with a given NumBits value is ever created.
    10468 /// @brief Get or create an IntegerType instance.
    105 static const IntegerType *get(LLVMContext &C, unsigned NumBits);
    69 static IntegerType *get(LLVMContext &C, unsigned NumBits);
    10670
    10771 /// @brief Get the number of bits in this IntegerType
    10872 unsigned getBitWidth() const { return getSubclassData(); }
    142106 /// FunctionType - Class to represent function types
    143107 ///
    144108 class FunctionType : public DerivedType {
    145 friend class TypeMap;
    146109 FunctionType(const FunctionType &); // Do not implement
    147110 const FunctionType &operator=(const FunctionType &); // Do not implement
    148 FunctionType(const Type *Result, ArrayRef Params,
    149 bool IsVarArgs);
    111 FunctionType(const Type *Result, ArrayRef Params, bool IsVarArgs);
    150112
    151113 public:
    152114 /// FunctionType::get - This static method is the primary way of constructing
    154116 ///
    155117 static FunctionType *get(const Type *Result,
    156118 ArrayRef Params, bool isVarArg);
    119 static FunctionType *get(const Type *Result,
    120 ArrayRef Params, bool isVarArg);
    157121
    158122 /// FunctionType::get - Create a FunctionType taking no parameters.
    159123 ///
    168132 static bool isValidArgumentType(const Type *ArgTy);
    169133
    170134 bool isVarArg() const { return getSubclassData(); }
    171 const Type *getReturnType() const { return ContainedTys[0]; }
    135 Type *getReturnType() const { return ContainedTys[0]; }
    172136
    173137 typedef Type::subtype_iterator param_iterator;
    174138 param_iterator param_begin() const { return ContainedTys + 1; }
    175139 param_iterator param_end() const { return &ContainedTys[NumContainedTys]; }
    176140
    177141 // Parameter type accessors.
    178 const Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
    142 Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
    179143
    180144 /// getNumParams - Return the number of fixed parameters this function type
    181145 /// requires. This does not consider varargs.
    182146 ///
    183147 unsigned getNumParams() const { return NumContainedTys - 1; }
    184
    185 // Implement the AbstractTypeUser interface.
    186 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
    187 virtual void typeBecameConcrete(const DerivedType *AbsTy);
    188148
    189149 // Methods for support type inquiry through isa, cast, and dyn_cast.
    190150 static inline bool classof(const FunctionType *) { return true; }
    204164 /// getTypeAtIndex - Given an index value into the type, return the type of
    205165 /// the element.
    206166 ///
    207 const Type *getTypeAtIndex(const Value *V) const;
    208 const Type *getTypeAtIndex(unsigned Idx) const;
    167 Type *getTypeAtIndex(const Value *V) const;
    168 Type *getTypeAtIndex(unsigned Idx) const;
    209169 bool indexValid(const Value *V) const;
    210170 bool indexValid(unsigned Idx) const;
    211171
    221181
    222182
    223183 /// StructType - Class to represent struct types, both normal and packed.
    184 /// Besides being optionally packed, structs can be either "anonymous" or may
    185 /// have an identity. Anonymous structs are uniqued by structural equivalence,
    186 /// but types are each unique when created, and optionally have a name.
    224187 ///
    225188 class StructType : public CompositeType {
    226 friend class TypeMap;
    227189 StructType(const StructType &); // Do not implement
    228190 const StructType &operator=(const StructType &); // Do not implement
    229 StructType(LLVMContext &C, ArrayRef Types, bool isPacked);
    230 public:
    191 StructType(LLVMContext &C)
    192 : CompositeType(C, StructTyID), SymbolTableEntry(0) {}
    193 enum {
    194 // This is the contents of the SubClassData field.
    195 SCDB_HasBody = 1,
    196 SCDB_Packed = 2,
    197 SCDB_IsAnonymous = 4
    198 };
    199
    200 /// SymbolTableEntry - For a named struct that actually has a name, this is a
    201 /// pointer to the symbol table entry (maintained by LLVMContext) for the
    202 /// struct. This is null if the type is an anonymous struct or if it is
    203 ///
    204 void *SymbolTableEntry;
    205 public:
    206 /// StructType::createNamed - This creates a named struct with no body
    207 /// specified. If the name is empty, it creates an unnamed struct, which has
    208 /// a unique identity but no actual name.
    209 static StructType *createNamed(LLVMContext &Context, StringRef Name);
    210
    211 static StructType *createNamed(StringRef Name, ArrayRef Elements,
    212 bool isPacked = false);
    213 static StructType *createNamed(LLVMContext &Context, StringRef Name,
    214 ArrayRef Elements,
    215 bool isPacked = false);
    216 static StructType *createNamed(StringRef Name, Type *elt1, ...) END_WITH_NULL;
    217
    231218 /// StructType::get - This static method is the primary way to create a
    232219 /// StructType.
    233220 ///
    221 /// FIXME: Remove the 'const Type*' version of this when types are pervasively
    222 /// de-constified.
    234223 static StructType *get(LLVMContext &Context, ArrayRef Elements,
    224 bool isPacked = false);
    225 static StructType *get(LLVMContext &Context, ArrayRef Elements,
    235226 bool isPacked = false);
    236227
    237228 /// StructType::get - Create an empty structure type.
    244235 /// element type.
    245236 static StructType *get(const Type *elt1, ...) END_WITH_NULL;
    246237
    238 bool isPacked() const { return (getSubclassData() & SCDB_Packed) != 0; }
    239
    240 /// isAnonymous - Return true if this type is uniqued by structural
    241 /// equivalence, false if it has an identity.
    242 bool isAnonymous() const {return (getSubclassData() & SCDB_IsAnonymous) != 0;}
    243
    244 /// isOpaque - Return true if this is a type with an identity that has no body
    245 /// specified yet. These prints as 'opaque' in .ll files.
    246 bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; }
    247
    248 /// hasName - Return true if this is a named struct that has a non-empty name.
    249 bool hasName() const { return SymbolTableEntry != 0; }
    250
    251 /// getName - Return the name for this struct type if it has an identity.
    252 /// This may return an empty string for an unnamed struct type. Do not call
    253 /// this on an anonymous type.
    254 StringRef getName() const;
    255
    256 /// setName - Change the name of this type to the specified name, or to a name
    257 /// with a suffix if there is a collision. Do not call this on an anonymous
    258 /// type.
    259 void setName(StringRef Name);
    260
    261 /// setBody - Specify a body for an opaque type.
    262 void setBody(ArrayRef Elements, bool isPacked = false);
    263 void setBody(Type *elt1, ...) END_WITH_NULL;
    264
    247265 /// isValidElementType - Return true if the specified type is valid as a
    248266 /// element type.
    249267 static bool isValidElementType(const Type *ElemTy);
    250
    251 bool isPacked() const { return getSubclassData() != 0 ? true : false; }
    268
    252269
    253270 // Iterator access to the elements.
    254271 typedef Type::subtype_iterator element_iterator;
    257274
    258275 /// isLayoutIdentical - Return true if this is layout identical to the
    259276 /// specified struct.
    260 bool isLayoutIdentical(const StructType *Other) const {
    261 return this == Other;
    262 }
    263
    277 bool isLayoutIdentical(const StructType *Other) const;
    264278
    265279 // Random access to the elements
    266280 unsigned getNumElements() const { return NumContainedTys; }
    267 const Type *getElementType(unsigned N) const {
    281 Type *getElementType(unsigned N) const {
    268282 assert(N < NumContainedTys && "Element number out of range!");
    269283 return ContainedTys[N];
    270284 }
    271
    272 // Implement the AbstractTypeUser interface.
    273 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
    274 virtual void typeBecameConcrete(const DerivedType *AbsTy);
    275285
    276286 // Methods for support type inquiry through isa, cast, and dyn_cast.
    277287 static inline bool classof(const StructType *) { return true; }
    289299 /// components out in memory identically.
    290300 ///
    291301 class SequentialType : public CompositeType {
    292 PATypeHandle ContainedType; ///< Storage for the single contained type.
    302 Type *ContainedType; ///< Storage for the single contained type.
    293303 SequentialType(const SequentialType &); // Do not implement!
    294304 const SequentialType &operator=(const SequentialType &); // Do not implement!
    295305
    296 // avoiding warning: 'this' : used in base member initializer list
    297 SequentialType *this_() { return this; }
    298306 protected:
    299 SequentialType(TypeID TID, const Type *ElType)
    300 : CompositeType(ElType->getContext(), TID), ContainedType(ElType, this_()) {
    307 SequentialType(TypeID TID, Type *ElType)
    308 : CompositeType(ElType->getContext(), TID), ContainedType(ElType) {
    301309 ContainedTys = &ContainedType;
    302310 NumContainedTys = 1;
    303311 }
    304312
    305313 public:
    306 const Type *getElementType() const { return ContainedTys[0]; }
    314 Type *getElementType() const { return ContainedTys[0]; }
    307315
    308316 // Methods for support type inquiry through isa, cast, and dyn_cast.
    309317 static inline bool classof(const SequentialType *) { return true; }
    318326 /// ArrayType - Class to represent array types.
    319327 ///
    320328 class ArrayType : public SequentialType {
    321 friend class TypeMap;
    322329 uint64_t NumElements;
    323330
    324331 ArrayType(const ArrayType &); // Do not implement
    325332 const ArrayType &operator=(const ArrayType &); // Do not implement
    326 ArrayType(const Type *ElType, uint64_t NumEl);
    333 ArrayType(Type *ElType, uint64_t NumEl);
    327334 public:
    328335 /// ArrayType::get - This static method is the primary way to construct an
    329336 /// ArrayType
    336343
    337344 uint64_t getNumElements() const { return NumElements; }
    338345
    339 // Implement the AbstractTypeUser interface.
    340 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
    341 virtual void typeBecameConcrete(const DerivedType *AbsTy);
    342
    343346 // Methods for support type inquiry through isa, cast, and dyn_cast.
    344347 static inline bool classof(const ArrayType *) { return true; }
    345348 static inline bool classof(const Type *T) {
    350353 /// VectorType - Class to represent vector types.
    351354 ///
    352355 class VectorType : public SequentialType {
    353 friend class TypeMap;
    354356 unsigned NumElements;
    355357
    356358 VectorType(const VectorType &); // Do not implement
    357359 const VectorType &operator=(const VectorType &); // Do not implement
    358 VectorType(const Type *ElType, unsigned NumEl);
    360 VectorType(Type *ElType, unsigned NumEl);
    359361 public:
    360362 /// VectorType::get - This static method is the primary way to construct an
    361363 /// VectorType.
    368370 ///
    369371 static VectorType *getInteger(const VectorType *VTy) {
    370372 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
    371 const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
    373 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
    372374 return VectorType::get(EltTy, VTy->getNumElements());
    373375 }
    374376
    378380 ///
    379381 static VectorType *getExtendedElementVectorType(const VectorType *VTy) {
    380382 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
    381 const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2);
    383 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2);
    382384 return VectorType::get(EltTy, VTy->getNumElements());
    383385 }
    384386
    390392 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
    391393 assert((EltBits & 1) == 0 &&
    392394 "Cannot truncate vector element with odd bit-width");
    393 const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);
    395 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);
    394396 return VectorType::get(EltTy, VTy->getNumElements());
    395397 }
    396398
    406408 return NumElements * getElementType()->getPrimitiveSizeInBits();
    407409 }
    408410
    409 // Implement the AbstractTypeUser interface.
    410 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
    411 virtual void typeBecameConcrete(const DerivedType *AbsTy);
    412
    413411 // Methods for support type inquiry through isa, cast, and dyn_cast.
    414412 static inline bool classof(const VectorType *) { return true; }
    415413 static inline bool classof(const Type *T) {
    421419 /// PointerType - Class to represent pointers.
    422420 ///
    423421 class PointerType : public SequentialType {
    424 friend class TypeMap;
    425
    426422 PointerType(const PointerType &); // Do not implement
    427423 const PointerType &operator=(const PointerType &); // Do not implement
    428 explicit PointerType(const Type *ElType, unsigned AddrSpace);
    424 explicit PointerType(Type *ElType, unsigned AddrSpace);
    429425 public:
    430426 /// PointerType::get - This constructs a pointer to an object of the specified
    431427 /// type in a numbered address space.
    444440 /// @brief Return the address space of the Pointer type.
    445441 inline unsigned getAddressSpace() const { return getSubclassData(); }
    446442
    447 // Implement the AbstractTypeUser interface.
    448 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
    449 virtual void typeBecameConcrete(const DerivedType *AbsTy);
    450
    451443 // Implement support type inquiry through isa, cast, and dyn_cast.
    452444 static inline bool classof(const PointerType *) { return true; }
    453445 static inline bool classof(const Type *T) {
    455447 }
    456448 };
    457449
    458
    459 /// OpaqueType - Class to represent opaque types.
    460 ///
    461 class OpaqueType : public DerivedType {
    462 friend class LLVMContextImpl;
    463 OpaqueType(const OpaqueType &); // DO NOT IMPLEMENT
    464 const OpaqueType &operator=(const OpaqueType &); // DO NOT IMPLEMENT
    465 OpaqueType(LLVMContext &C);
    466 public:
    467 /// OpaqueType::get - Static factory method for the OpaqueType class.
    468 ///
    469 static OpaqueType *get(LLVMContext &C);
    470
    471 // Implement support for type inquiry through isa, cast, and dyn_cast.
    472 static inline bool classof(const OpaqueType *) { return true; }
    473 static inline bool classof(const Type *T) {
    474 return T->getTypeID() == OpaqueTyID;
    475 }
    476 };
    477
    478450 } // End llvm namespace
    479451
    480452 #endif
    +2
    -2
    include/llvm/Function.h less more
    127127
    128128 ~Function();
    129129
    130 const Type *getReturnType() const; // Return the type of the ret val
    131 const FunctionType *getFunctionType() const; // Return the FunctionType for me
    130 Type *getReturnType() const; // Return the type of the ret val
    131 FunctionType *getFunctionType() const; // Return the FunctionType for me
    132132
    133133 /// getContext - Return a pointer to the LLVMContext associated with this
    134134 /// function, or NULL if this function is not bound to a context yet.
    +5
    -5
    include/llvm/GlobalAlias.h less more
    6262 virtual void eraseFromParent();
    6363
    6464 /// set/getAliasee - These methods retrive and set alias target.
    65 void setAliasee(Constant* GV);
    66 const Constant* getAliasee() const {
    65 void setAliasee(Constant *GV);
    66 const Constant *getAliasee() const {
    6767 return cast_or_null(getOperand(0));
    6868 }
    69 Constant* getAliasee() {
    69 Constant *getAliasee() {
    7070 return cast_or_null(getOperand(0));
    7171 }
    7272 /// getAliasedGlobal() - Aliasee can be either global or bitcast of
    7373 /// global. This method retrives the global for both aliasee flavours.
    74 const GlobalValue* getAliasedGlobal() const;
    74 const GlobalValue *getAliasedGlobal() const;
    7575
    7676 /// resolveAliasedGlobal() - This method tries to ultimately resolve the alias
    7777 /// by going through the aliasing chain and trying to find the very last
    7878 /// global. Returns NULL if a cycle was found. If stopOnWeak is false, then
    7979 /// the whole chain aliasing chain is traversed, otherwise - only strong
    8080 /// aliases.
    81 const GlobalValue* resolveAliasedGlobal(bool stopOnWeak = true) const;
    81 const GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true) const;
    8282
    8383 // Methods for support type inquiry through isa, cast, and dyn_cast:
    8484 static inline bool classof(const GlobalAlias *) { return true; }
    +2
    -2
    include/llvm/GlobalValue.h less more
    105105 bool use_empty_except_constants();
    106106
    107107 /// getType - Global values are always pointers.
    108 inline const PointerType *getType() const {
    109 return reinterpret_cast(User::getType());
    108 inline PointerType *getType() const {
    109 return reinterpret_cast(User::getType());
    110110 }
    111111
    112112 static LinkageTypes getLinkOnceLinkage(bool ODR) {
    +0
    -1
    include/llvm/InitializePasses.h less more
    8383 void initializeDAHPass(PassRegistry&);
    8484 void initializeDCEPass(PassRegistry&);
    8585 void initializeDSEPass(PassRegistry&);
    86 void initializeDTEPass(PassRegistry&);
    8786 void initializeDeadInstEliminationPass(PassRegistry&);
    8887 void initializeDeadMachineInstructionElimPass(PassRegistry&);
    8988 void initializeDomOnlyPrinterPass(PassRegistry&);
    +42
    -42
    include/llvm/Instructions.h less more
    7575 /// getAllocatedType - Return the type that is being allocated by the
    7676 /// instruction.
    7777 ///
    78 const Type *getAllocatedType() const;
    78 Type *getAllocatedType() const;
    7979
    8080 /// getAlignment - Return the alignment of the memory that is being allocated
    8181 /// by the instruction.
    270270 // GetElementPtrInst Class
    271271 //===----------------------------------------------------------------------===//
    272272
    273 // checkType - Simple wrapper function to give a better assertion failure
    273 // checkGEPType - Simple wrapper function to give a better assertion failure
    274274 // message on bad indexes for a gep instruction.
    275275 //
    276 static inline const Type *checkType(const Type *Ty) {
    276 static inline const Type *checkGEPType(const Type *Ty) {
    277277 assert(Ty && "Invalid GetElementPtrInst indices for type!");
    278278 return Ty;
    279279 }
    314314 /// pointer type.
    315315 ///
    316316 template
    317 static const Type *getIndexedType(const Type *Ptr,
    318 RandomAccessIterator IdxBegin,
    319 RandomAccessIterator IdxEnd,
    320 // This argument ensures that we
    321 // have an iterator we can do
    322 // arithmetic on in constant time
    323 std::random_access_iterator_tag) {
    317 static Type *getIndexedType(const Type *Ptr,
    318 RandomAccessIterator IdxBegin,
    319 RandomAccessIterator IdxEnd,
    320 // This argument ensures that we
    321 // have an iterator we can do
    322 // arithmetic on in constant time
    323 std::random_access_iterator_tag) {
    324324 unsigned NumIdx = static_cast(std::distance(IdxBegin, IdxEnd));
    325325
    326326 if (NumIdx > 0)
    445445 /// pointer type.
    446446 ///
    447447 template
    448 static const Type *getIndexedType(const Type *Ptr,
    449 RandomAccessIterator IdxBegin,
    450 RandomAccessIterator IdxEnd) {
    448 static Type *getIndexedType(const Type *Ptr, RandomAccessIterator IdxBegin,
    449 RandomAccessIterator IdxEnd) {
    451450 return getIndexedType(Ptr, IdxBegin, IdxEnd,
    452451 typename std::iterator_traits::
    453452 iterator_category());
    454453 }
    455454
    456 static const Type *getIndexedType(const Type *Ptr,
    457 Value* const *Idx, unsigned NumIdx);
    458
    459 static const Type *getIndexedType(const Type *Ptr,
    460 Constant* const *Idx, unsigned NumIdx);
    461
    462 static const Type *getIndexedType(const Type *Ptr,
    463 uint64_t const *Idx, unsigned NumIdx);
    464
    465 static const Type *getIndexedType(const Type *Ptr, Value *Idx);
    455 // FIXME: Use ArrayRef
    456 static Type *getIndexedType(const Type *Ptr,
    457 Value* const *Idx, unsigned NumIdx);
    458 static Type *getIndexedType(const Type *Ptr,
    459 Constant* const *Idx, unsigned NumIdx);
    460
    461 static Type *getIndexedType(const Type *Ptr,
    462 uint64_t const *Idx, unsigned NumIdx);
    463 static Type *getIndexedType(const Type *Ptr, Value *Idx);
    466464
    467465 inline op_iterator idx_begin() { return op_begin()+1; }
    468466 inline const_op_iterator idx_begin() const { return op_begin()+1; }
    537535 unsigned Values,
    538536 const Twine &NameStr,
    539537 Instruction *InsertBefore)
    540 : Instruction(PointerType::get(checkType(
    538 : Instruction(PointerType::get(checkGEPType(
    541539 getIndexedType(Ptr->getType(),
    542540 IdxBegin, IdxEnd)),
    543541 cast(Ptr->getType())
    556554 unsigned Values,
    557555 const Twine &NameStr,
    558556 BasicBlock *InsertAtEnd)
    559 : Instruction(PointerType::get(checkType(
    557 : Instruction(PointerType::get(checkGEPType(
    560558 getIndexedType(Ptr->getType(),
    561559 IdxBegin, IdxEnd)),
    562560 cast(Ptr->getType())
    14581456 ///
    14591457 /// Null is returned if the indices are invalid for the specified type.
    14601458 ///
    1461 static const Type *getIndexedType(const Type *Agg,
    1462 const unsigned *Idx, unsigned NumIdx);
    1459 /// FIXME: Use ArrayRef
    1460 static Type *getIndexedType(const Type *Agg,
    1461 const unsigned *Idx, unsigned NumIdx);
    14631462
    14641463 template
    1465 static const Type *getIndexedType(const Type *Ptr,
    1466 RandomAccessIterator IdxBegin,
    1467 RandomAccessIterator IdxEnd,
    1468 // This argument ensures that we
    1469 // have an iterator we can do
    1470 // arithmetic on in constant time
    1471 std::random_access_iterator_tag) {
    1464 static Type *getIndexedType(const Type *Ptr,
    1465 RandomAccessIterator IdxBegin,
    1466 RandomAccessIterator IdxEnd,
    1467 // This argument ensures that we
    1468 // have an iterator we can do
    1469 // arithmetic on in constant time
    1470 std::random_access_iterator_tag) {
    14721471 unsigned NumIdx = static_cast(std::distance(IdxBegin, IdxEnd));
    14731472
    14741473 if (NumIdx > 0)
    15411540 ///
    15421541 /// Null is returned if the indices are invalid for the specified type.
    15431542 ///
    1543 /// FIXME: Remove the templates and just use ArrayRef.
    15441544 template
    1545 static const Type *getIndexedType(const Type *Ptr,
    1546 RandomAccessIterator IdxBegin,
    1547 RandomAccessIterator IdxEnd) {
    1545 static Type *getIndexedType(const Type *Ptr,
    1546 RandomAccessIterator IdxBegin,
    1547 RandomAccessIterator IdxEnd) {
    15481548 return getIndexedType(Ptr, IdxBegin, IdxEnd,
    15491549 typename std::iterator_traits::
    15501550 iterator_category());
    15511551 }
    1552 static const Type *getIndexedType(const Type *Ptr, unsigned Idx);
    1552 static Type *getIndexedType(const Type *Ptr, unsigned Idx);
    15531553
    15541554 typedef const unsigned* idx_iterator;
    15551555 inline idx_iterator idx_begin() const { return Indices.begin(); }
    15891589 RandomAccessIterator IdxEnd,
    15901590 const Twine &NameStr,
    15911591 Instruction *InsertBefore)
    1592 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
    1593 IdxBegin, IdxEnd)),
    1592 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(),
    1593 IdxBegin, IdxEnd)),
    15941594 ExtractValue, Agg, InsertBefore) {
    15951595 init(IdxBegin, IdxEnd, NameStr,
    15961596 typename std::iterator_traits
    16021602 RandomAccessIterator IdxEnd,
    16031603 const Twine &NameStr,
    16041604 BasicBlock *InsertAtEnd)
    1605 : UnaryInstruction(checkType(getIndexedType(Agg->getType(),
    1606 IdxBegin, IdxEnd)),
    1605 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(),
    1606 IdxBegin, IdxEnd)),
    16071607 ExtractValue, Agg, InsertAtEnd) {
    16081608 init(IdxBegin, IdxEnd, NameStr,
    16091609 typename std::iterator_traits
    +0
    -1
    include/llvm/LinkAllPasses.h less more
    6161 (void) llvm::createDeadCodeEliminationPass();
    6262 (void) llvm::createDeadInstEliminationPass();
    6363 (void) llvm::createDeadStoreEliminationPass();
    64 (void) llvm::createDeadTypeEliminationPass();
    6564 (void) llvm::createDomOnlyPrinterPass();
    6665 (void) llvm::createDomPrinterPass();
    6766 (void) llvm::createDomOnlyViewerPass();
    +24
    -52
    include/llvm/Module.h less more
    2727 class FunctionType;
    2828 class GVMaterializer;
    2929 class LLVMContext;
    30 class StructType;
    31 template struct DenseMapInfo;
    32 template
    33 typename KeyInfoT, typename ValueInfoT> class DenseMap;
    3034
    3135 template<> struct ilist_traits
    3236 : public SymbolTableListTraits {
    144148 NamedMDListType NamedMDList; ///< The named metadata in the module
    145149 std::string GlobalScopeAsm; ///< Inline Asm at global scope.
    146150 ValueSymbolTable *ValSymTab; ///< Symbol table for values
    147 TypeSymbolTable *TypeSymTab; ///< Symbol table for types
    148151 OwningPtr Materializer; ///< Used to materialize GlobalValues
    149152 std::string ModuleID; ///< Human readable identifier for the module
    150153 std::string TargetTriple; ///< Platform target triple Module compiled on
    230233 /// @name Generic Value Accessors
    231234 /// @{
    232235
    233 /// getNamedValue - Return the first global value in the module with
    236 /// getNamedValue - Return the global value in the module with
    234237 /// the specified name, of arbitrary type. This method returns null
    235238 /// if a global with the specified name is not found.
    236239 GlobalValue *getNamedValue(StringRef Name) const;
    242245 /// getMDKindNames - Populate client supplied SmallVector with the name for
    243246 /// custom metadata IDs registered in this LLVMContext.
    244247 void getMDKindNames(SmallVectorImpl &Result) const;
    248
    249
    250 typedef DenseMap,
    251 DenseMapInfo > NumeredTypesMapTy;
    252
    253 /// findUsedStructTypes - Walk the entire module and find all of the
    254 /// struct types that are in use, returning them in a vector.
    255 void findUsedStructTypes(std::vector &StructTypes) const;
    256
    257 /// getTypeByName - Return the type with the specified name, or null if there
    258 /// is none by that name.
    259 StructType *getTypeByName(StringRef Name) const;
    245260
    246261 /// @}
    247262 /// @name Function Accessors
    295310 GlobalVariable *getGlobalVariable(StringRef Name,
    296311 bool AllowInternal = false) const;
    297312
    298 /// getNamedGlobal - Return the first global variable in the module with the
    313 /// getNamedGlobal - Return the global variable in the module with the
    299314 /// specified name, of arbitrary type. This method returns null if a global
    300315 /// with the specified name is not found.
    301316 GlobalVariable *getNamedGlobal(StringRef Name) const {
    315330 /// @name Global Alias Accessors
    316331 /// @{
    317332
    318 /// getNamedAlias - Return the first global alias in the module with the
    333 /// getNamedAlias - Return the global alias in the module with the
    319334 /// specified name, of arbitrary type. This method returns null if a global
    320335 /// with the specified name is not found.
    321336 GlobalAlias *getNamedAlias(StringRef Name) const;
    324339 /// @name Named Metadata Accessors
    325340 /// @{
    326341
    327 /// getNamedMetadata - Return the first NamedMDNode in the module with the
    342 /// getNamedMetadata - Return the NamedMDNode in the module with the
    328343 /// specified name. This method returns null if a NamedMDNode with the
    329344 /// specified name is not found.
    330345 NamedMDNode *getNamedMetadata(const Twine &Name) const;
    331346
    332 /// getOrInsertNamedMetadata - Return the first named MDNode in the module
    347 /// getOrInsertNamedMetadata - Return the named MDNode in the module
    333348 /// with the specified name. This method returns a new NamedMDNode if a
    334349 /// NamedMDNode with the specified name is not found.
    335350 NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
    337352 /// eraseNamedMetadata - Remove the given NamedMDNode from this module
    338353 /// and delete it.
    339354 void eraseNamedMetadata(NamedMDNode *NMD);
    340
    341 /// @}
    342 /// @name Type Accessors
    343 /// @{
    344
    345 /// addTypeName - Insert an entry in the symbol table mapping Str to Type. If
    346 /// there is already an entry for this name, true is returned and the symbol
    347 /// table is not modified.
    348 bool addTypeName(StringRef Name, const Type *Ty);
    349
    350 /// getTypeName - If there is at least one entry in the symbol table for the
    351 /// specified type, return it.
    352 std::string getTypeName(const Type *Ty) const;
    353
    354 /// getTypeByName - Return the type with the specified name in this module, or
    355 /// null if there is none by that name.
    356 const Type *getTypeByName(StringRef Name) const;
    357355
    358356 /// @}
    359357 /// @name Materialization
    428426 const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
    429427 /// Get the Module's symbol table of global variable and function identifiers.
    430428 ValueSymbolTable &getValueSymbolTable() { return *ValSymTab; }
    431 /// Get the symbol table of types
    432 const TypeSymbolTable &getTypeSymbolTable() const { return *TypeSymTab; }
    433 /// Get the Module's symbol table of types
    434 TypeSymbolTable &getTypeSymbolTable() { return *TypeSymTab; }
    435429
    436430 /// @}
    437431 /// @name Global Variable Iteration
    438432 /// @{
    439433
    440 /// Get an iterator to the first global variable
    441434 global_iterator global_begin() { return GlobalList.begin(); }
    442 /// Get a constant iterator to the first global variable
    443435 const_global_iterator global_begin() const { return GlobalList.begin(); }
    444 /// Get an iterator to the last global variable
    445436 global_iterator global_end () { return GlobalList.end(); }
    446 /// Get a constant iterator to the last global variable
    447437 const_global_iterator global_end () const { return GlobalList.end(); }
    448 /// Determine if the list of globals is empty.
    449438 bool global_empty() const { return GlobalList.empty(); }
    450439
    451440 /// @}
    452441 /// @name Function Iteration
    453442 /// @{
    454443
    455 /// Get an iterator to the first function.
    456444 iterator begin() { return FunctionList.begin(); }
    457 /// Get a constant iterator to the first function.
    458445 const_iterator begin() const { return FunctionList.begin(); }
    459 /// Get an iterator to the last function.
    460446 iterator end () { return FunctionList.end(); }
    461 /// Get a constant iterator to the last function.
    462447 const_iterator end () const { return FunctionList.end(); }
    463 /// Determine how many functions are in the Module's list of functions.
    464448 size_t size() const { return FunctionList.size(); }
    465 /// Determine if the list of functions is empty.
    466449 bool empty() const { return FunctionList.empty(); }
    467450
    468451 /// @}
    486469 /// @name Alias Iteration
    487470 /// @{
    488471
    489 /// Get an iterator to the first alias.
    490472 alias_iterator alias_begin() { return AliasList.begin(); }
    491 /// Get a constant iterator to the first alias.
    492473 const_alias_iterator alias_begin() const { return AliasList.begin(); }
    493 /// Get an iterator to the last alias.
    494474 alias_iterator alias_end () { return AliasList.end(); }
    495 /// Get a constant iterator to the last alias.
    496475 const_alias_iterator alias_end () const { return AliasList.end(); }
    497 /// Determine how many aliases are in the Module's list of aliases.
    498476 size_t alias_size () const { return AliasList.size(); }
    499 /// Determine if the list of aliases is empty.
    500477 bool alias_empty() const { return AliasList.empty(); }
    501478
    502479
    504481 /// @name Named Metadata Iteration
    505482 /// @{
    506483
    507 /// Get an iterator to the first named metadata.
    508484 named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
    509 /// Get a constant iterator to the first named metadata.
    510485 const_named_metadata_iterator named_metadata_begin() const {
    511486 return NamedMDList.begin();
    512487 }
    513488
    514 /// Get an iterator to the last named metadata.
    515489 named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
    516 /// Get a constant iterator to the last named metadata.
    517490 const_named_metadata_iterator named_metadata_end() const {
    518491 return NamedMDList.end();
    519492 }
    520493
    521 /// Determine how many NamedMDNodes are in the Module's list of named
    522 /// metadata.
    523494 size_t named_metadata_size() const { return NamedMDList.size(); }
    524 /// Determine if the list of named metadata is empty.
    525495 bool named_metadata_empty() const { return NamedMDList.empty(); }
    526496
    527497
    529499 /// @name Utility functions for printing and dumping Module objects
    530500 /// @{
    531501
    532 /// Print the module to an output stream with AssemblyAnnotationWriter.
    502 /// Print the module to an output stream with an optional
    503 /// AssemblyAnnotationWriter.
    533504 void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
    534505
    535506 /// Dump the module to stderr (for debugging).
    536507 void dump() const;
    508
    537509 /// This function causes all the subinstructions to "let go" of all references
    538510 /// that they are maintaining. This allows one to 'delete' a whole class at
    539511 /// a time, even though there may be circular references... first all
    +1
    -1
    include/llvm/Support/PassManagerBuilder.h less more
    236236 MPM.add(createInstructionCombiningPass()); // Clean up after everything.
    237237
    238238 if (!DisableUnitAtATime) {
    239 // FIXME: We shouldn't bother with this anymore.
    239240 MPM.add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
    240 MPM.add(createDeadTypeEliminationPass()); // Eliminate dead types
    241241
    242242 // GlobalOpt already deletes dead functions and globals, at -O3 try a
    243243 // late pass of GlobalDCE. It is capable of deleting dead cycles.
    +0
    -7
    include/llvm/Transforms/IPO.h less more
    7070 /// non-address taken internal globals.
    7171 ///
    7272 ModulePass *createGlobalOptimizerPass();
    73
    74
    75 //===----------------------------------------------------------------------===//
    76 /// createDeadTypeEliminationPass - Return a new pass that eliminates symbol
    77 /// table entries for types that are never used.
    78 ///
    79 ModulePass *createDeadTypeEliminationPass();
    8073
    8174
    8275 //===----------------------------------------------------------------------===//
    +32
    -2
    include/llvm/Transforms/Utils/ValueMapper.h less more
    2121 class Instruction;
    2222 typedef ValueMap > ValueToValueMapTy;
    2323
    24 /// ValueMapTypeRemapper - This is a class that can be implemented by clients
    25 /// to remap types when cloning constants and instructions.
    26 class ValueMapTypeRemapper {
    27 virtual void Anchor(); // Out of line method.
    28 public:
    29 ~ValueMapTypeRemapper() {}
    30
    31 /// remapType - The client should implement this method if they want to
    32 /// remap types while mapping values.
    33 virtual Type *remapType(Type *SrcTy) = 0;
    34 };
    35
    2436 /// RemapFlags - These are flags that the value mapping APIs allow.
    2537 enum RemapFlags {
    2638 RF_None = 0,
    4153 }
    4254
    4355 Value *MapValue(const Value *V, ValueToValueMapTy &VM,
    44 RemapFlags Flags = RF_None);
    56 RemapFlags Flags = RF_None,
    57 ValueMapTypeRemapper *TypeMapper = 0);
    58
    4559 void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
    46 RemapFlags Flags = RF_None);
    60 RemapFlags Flags = RF_None,
    61 ValueMapTypeRemapper *TypeMapper = 0);
    62
    63 /// MapValue - provide versions that preserve type safety for MDNode and
    64 /// Constants.
    65 inline MDNode *MapValue(const MDNode *V, ValueToValueMapTy &VM,
    66 RemapFlags Flags = RF_None,
    67 ValueMapTypeRemapper *TypeMapper = 0) {
    68 return (MDNode*)MapValue((const Value*)V, VM, Flags, TypeMapper);
    69 }
    70 inline Constant *MapValue(const Constant *V, ValueToValueMapTy &VM,
    71 RemapFlags Flags = RF_None,
    72 ValueMapTypeRemapper *TypeMapper = 0) {
    73 return (Constant*)MapValue((const Value*)V, VM, Flags, TypeMapper);
    74 }
    75
    76
    4777 } // End llvm namespace
    4878
    4979 #endif
    +96
    -252
    include/llvm/Type.h less more
    1414 #ifndef LLVM_TYPE_H
    1515 #define LLVM_TYPE_H
    1616
    17 #include "llvm/AbstractTypeUser.h"
    1817 #include "llvm/Support/Casting.h"
    19 #include
    2018
    2119 namespace llvm {
    2220
    2321 class DerivedType;
    2422 class PointerType;
    2523 class IntegerType;
    26 class TypeMapBase;
    2724 class raw_ostream;
    2825 class Module;
    2926 class LLVMContext;
    27 class LLVMContextImpl;
    3028 template struct GraphTraits;
    3129
    3230 /// The instances of the Type class are immutable: once they are created,
    3432 /// type is ever created. Thus seeing if two types are equal is a matter of
    3533 /// doing a trivial pointer comparison. To enforce that no two equal instances
    3634 /// are created, Type instances can only be created via static factory methods
    37 /// in class Type and in derived classes.
    35 /// in class Type and in derived classes. Once allocated, Types are never
    36 /// free'd.
    3837 ///
    39 /// Once allocated, Types are never free'd, unless they are an abstract type
    40 /// that is resolved to a more concrete type.
    41 ///
    42 /// Types themself don't have a name, and can be named either by:
    43 /// - using SymbolTable instance, typically from some Module,
    44 /// - using convenience methods in the Module class (which uses module's
    45 /// SymbolTable too).
    46 ///
    47 /// Opaque types are simple derived types with no state. There may be many
    48 /// different Opaque type objects floating around, but two are only considered
    49 /// identical if they are pointer equals of each other. This allows us to have
    50 /// two opaque types that end up resolving to different concrete types later.
    51 ///
    52 /// Opaque types are also kinda weird and scary and different because they have
    53 /// to keep a list of uses of the type. When, through linking, parsing, or
    54 /// bitcode reading, they become resolved, they need to find and update all
    55 /// users of the unknown type, causing them to reference a new, more concrete
    56 /// type. Opaque types are deleted when their use list dwindles to zero users.
    57 ///
    58 /// @brief Root of type hierarchy
    59 class Type : public AbstractTypeUser {
    38 class Type {
    6039 public:
    6140 //===--------------------------------------------------------------------===//
    6241 /// Definitions of all of the base types for the Type system. Based on this
    8463 StructTyID, ///< 11: Structures
    8564 ArrayTyID, ///< 12: Arrays
    8665 PointerTyID, ///< 13: Pointers
    87 OpaqueTyID, ///< 14: Opaque: type with unknown structure
    88 VectorTyID, ///< 15: SIMD 'packed' format, or other vector type
    66 VectorTyID, ///< 14: SIMD 'packed' format, or other vector type
    8967
    9068 NumTypeIDs, // Must remain as last defined ID
    9169 LastPrimitiveTyID = X86_MMXTyID,
    9371 };
    9472
    9573 private:
    96 TypeID ID : 8; // The current base type of this type.
    97 bool Abstract : 1; // True if type contains an OpaqueType
    98 unsigned SubclassData : 23; //Space for subclasses to store data
    99
    100 /// RefCount - This counts the number of PATypeHolders that are pointing to
    101 /// this type. When this number falls to zero, if the type is abstract and
    102 /// has no AbstractTypeUsers, the type is deleted. This is only sensical for
    103 /// derived types.
    104 ///
    105 mutable unsigned RefCount;
    106
    10774 /// Context - This refers to the LLVMContext in which this type was uniqued.
    10875 LLVMContext &Context;
    76
    77 TypeID ID : 8; // The current base type of this type.
    78 unsigned SubclassData : 24; // Space for subclasses to store data
    79
    80 protected:
    10981 friend class LLVMContextImpl;
    110
    111 const Type *getForwardedTypeInternal() const;
    112
    113 // When the last reference to a forwarded type is removed, it is destroyed.
    114 void destroy() const;
    115
    116 protected:
    117 explicit Type(LLVMContext &C, TypeID id) :
    118 ID(id), Abstract(false), SubclassData(0),
    119 RefCount(0), Context(C),
    120 ForwardType(0), NumContainedTys(0),
    121 ContainedTys(0) {}
    122 virtual ~Type() {
    123 assert(AbstractTypeUsers.empty() && "Abstract types remain");
    124 }
    125
    126 /// Types can become nonabstract later, if they are refined.
    127 ///
    128 inline void setAbstract(bool Val) { Abstract = Val; }
    129
    130 unsigned getRefCount() const { return RefCount; }
    82 explicit Type(LLVMContext &C, TypeID tid)
    83 : Context(C), ID(tid), SubclassData(0),
    84 NumContainedTys(0), ContainedTys(0) {}
    85 ~Type() {}
    13186
    13287 unsigned getSubclassData() const { return SubclassData; }
    133 void setSubclassData(unsigned val) { SubclassData = val; }
    134
    135 /// ForwardType - This field is used to implement the union find scheme for
    136 /// abstract types. When types are refined to other types, this field is set
    137 /// to the more refined type. Only abstract types can be forwarded.
    138 mutable const Type *ForwardType;
    139
    140
    141 /// AbstractTypeUsers - Implement a list of the users that need to be notified
    142 /// if I am a type, and I get resolved into a more concrete type.
    143 ///
    144 mutable std::vector AbstractTypeUsers;
    145
    146 /// NumContainedTys - Keeps track of how many PATypeHandle instances there
    147 /// are at the end of this type instance for the list of contained types. It
    148 /// is the subclasses responsibility to set this up. Set to 0 if there are no
    149 /// contained types in this type.
    88 void setSubclassData(unsigned val) {
    89 SubclassData = val;
    90 // Ensure we don't have any accidental truncation.
    91 assert(SubclassData == val && "Subclass data too large for field");
    92 }
    93
    94 /// NumContainedTys - Keeps track of how many Type*'s there are in the
    95 /// ContainedTys list.
    15096 unsigned NumContainedTys;
    15197
    152 /// ContainedTys - A pointer to the array of Types (PATypeHandle) contained
    153 /// by this Type. For example, this includes the arguments of a function
    154 /// type, the elements of a structure, the pointee of a pointer, the element
    155 /// type of an array, etc. This pointer may be 0 for types that don't
    156 /// contain other types (Integer, Double, Float). In general, the subclass
    157 /// should arrange for space for the PATypeHandles to be included in the
    158 /// allocation of the type object and set this pointer to the address of the
    159 /// first element. This allows the Type class to manipulate the ContainedTys
    160 /// without understanding the subclass's placement for this array. keeping
    161 /// it here also allows the subtype_* members to be implemented MUCH more
    162 /// efficiently, and dynamically very few types do not contain any elements.
    163 PATypeHandle *ContainedTys;
    98 /// ContainedTys - A pointer to the array of Types contained by this Type.
    99 /// For example, this includes the arguments of a function type, the elements
    100 /// of a structure, the pointee of a pointer, the element type of an array,
    101 /// etc. This pointer may be 0 for types that don't contain other types
    102 /// (Integer, Double, Float).
    103 Type * const *ContainedTys;
    164104
    165105 public:
    166106 void print(raw_ostream &O) const;
    167
    168 /// @brief Debugging support: print to stderr
    169107 void dump() const;
    170108
    171 /// @brief Debugging support: print to stderr (use type names from context
    172 /// module).
    173 void dump(const Module *Context) const;
    174
    175 /// getContext - Fetch the LLVMContext in which this type was uniqued.
    109 /// getContext - Return the LLVMContext in which this type was uniqued.
    176110 LLVMContext &getContext() const { return Context; }
    177111
    178112 //===--------------------------------------------------------------------===//
    204138
    205139 /// isFloatingPointTy - Return true if this is one of the five floating point
    206140 /// types
    207 bool isFloatingPointTy() const { return ID == FloatTyID || ID == DoubleTyID ||
    208 ID == X86_FP80TyID || ID == FP128TyID || ID == PPC_FP128TyID; }
    141 bool isFloatingPointTy() const {
    142 return ID == FloatTyID || ID == DoubleTyID ||
    143 ID == X86_FP80TyID || ID == FP128TyID || ID == PPC_FP128TyID;
    144 }
    209145
    210146 /// isX86_MMXTy - Return true if this is X86 MMX.
    211147 bool isX86_MMXTy() const { return ID == X86_MMXTyID; }
    248184 ///
    249185 bool isPointerTy() const { return ID == PointerTyID; }
    250186
    251 /// isOpaqueTy - True if this is an instance of OpaqueType.
    252 ///
    253 bool isOpaqueTy() const { return ID == OpaqueTyID; }
    254
    255187 /// isVectorTy - True if this is an instance of VectorType.
    256188 ///
    257189 bool isVectorTy() const { return ID == VectorTyID; }
    258
    259 /// isAbstract - True if the type is either an Opaque type, or is a derived
    260 /// type that includes an opaque type somewhere in it.
    261 ///
    262 inline bool isAbstract() const { return Abstract; }
    263190
    264191 /// canLosslesslyBitCastTo - Return true if this type could be converted
    265192 /// with a lossless BitCast to type 'Ty'. For example, i8* to i32*. BitCasts
    275202 /// Here are some useful little methods to query what type derived types are
    276203 /// Note that all other types can just compare to see if this == Type::xxxTy;
    277204 ///
    278 inline bool isPrimitiveType() const { return ID <= LastPrimitiveTyID; }
    279 inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
    205 bool isPrimitiveType() const { return ID <= LastPrimitiveTyID; }
    206 bool isDerivedType() const { return ID >= FirstDerivedTyID; }
    280207
    281208 /// isFirstClassType - Return true if the type is "first class", meaning it
    282209 /// is a valid type for a Value.
    283210 ///
    284 inline bool isFirstClassType() const {
    285 // There are more first-class kinds than non-first-class kinds, so a
    286 // negative test is simpler than a positive one.
    287 return ID != FunctionTyID && ID != VoidTyID && ID != OpaqueTyID;
    211 bool isFirstClassType() const {
    212 return ID != FunctionTyID && ID != VoidTyID;
    288213 }
    289214
    290215 /// isSingleValueType - Return true if the type is a valid type for a
    291 /// virtual register in codegen. This includes all first-class types
    292 /// except struct and array types.
    293 ///
    294 inline bool isSingleValueType() const {
    295 return (ID != VoidTyID && ID <= LastPrimitiveTyID) ||
    216 /// register in codegen. This includes all first-class types except struct
    217 /// and array types.
    218 ///
    219 bool isSingleValueType() const {
    220 return (ID != VoidTyID && isPrimitiveType()) ||
    296221 ID == IntegerTyID || ID == PointerTyID || ID == VectorTyID;
    297222 }
    298223
    301226 /// extractvalue instruction. This includes struct and array types, but
    302227 /// does not include vector types.
    303228 ///
    304 inline bool isAggregateType() const {
    229 bool isAggregateType() const {
    305230 return ID == StructTyID || ID == ArrayTyID;
    306231 }
    307232
    318243 // it doesn't have a size.
    319244 if (ID != StructTyID && ID != ArrayTyID && ID != VectorTyID)
    320245 return false;
    321 // If it is something that can have a size and it's concrete, it definitely
    322 // has a size, otherwise we have to try harder to decide.
    323 return !isAbstract() || isSizedDerivedType();
    246 // Otherwise we have to try harder to decide.
    247 return isSizedDerivedType();
    324248 }
    325249
    326250 /// getPrimitiveSizeInBits - Return the basic size of this type if it is a
    345269 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
    346270 int getFPMantissaWidth() const;
    347271
    348 /// getForwardedType - Return the type that this type has been resolved to if
    349 /// it has been resolved to anything. This is used to implement the
    350 /// union-find algorithm for type resolution, and shouldn't be used by general
    351 /// purpose clients.
    352 const Type *getForwardedType() const {
    353 if (!ForwardType) return 0;
    354 return getForwardedTypeInternal();
    355 }
    356
    357272 /// getScalarType - If this is a vector type, return the element type,
    358 /// otherwise return this.
    273 /// otherwise return 'this'.
    359274 const Type *getScalarType() const;
    360275
    361276 //===--------------------------------------------------------------------===//
    362 // Type Iteration support
    277 // Type Iteration support.
    363278 //
    364 typedef PATypeHandle *subtype_iterator;
    279 typedef Type * const *subtype_iterator;
    365280 subtype_iterator subtype_begin() const { return ContainedTys; }
    366281 subtype_iterator subtype_end() const { return &ContainedTys[NumContainedTys];}
    367282
    369284 /// (defined a the end of the file). For derived types, this returns the
    370285 /// types 'contained' in the derived type.
    371286 ///
    372 const Type *getContainedType(unsigned i) const {
    287 Type *getContainedType(unsigned i) const {
    373288 assert(i < NumContainedTys && "Index out of range!");
    374 return ContainedTys[i].get();
    289 return ContainedTys[i];
    375290 }
    376291
    377292 /// getNumContainedTypes - Return the number of types in the derived type.
    384299 //
    385300
    386301 /// getPrimitiveType - Return a type based on an identifier.
    387 static const Type *getPrimitiveType(LLVMContext &C, TypeID IDNumber);
    388
    389 //===--------------------------------------------------------------------===//
    390 // These are the builtin types that are always available...
    302 static Type *getPrimitiveType(LLVMContext &C, TypeID IDNumber);
    303
    304 //===--------------------------------------------------------------------===//
    305 // These are the builtin types that are always available.
    391306 //
    392 static const Type *getVoidTy(LLVMContext &C);
    393 static const Type *getLabelTy(LLVMContext &C);
    394 static const Type *getFloatTy(LLVMContext &C);
    395 static const Type *getDoubleTy(LLVMContext &C);
    396 static const Type *getMetadataTy(LLVMContext &C);
    397 static const Type *getX86_FP80Ty(LLVMContext &C);
    398 static const Type *getFP128Ty(LLVMContext &C);
    399 static const Type *getPPC_FP128Ty(LLVMContext &C);
    400 static const Type *getX86_MMXTy(LLVMContext &C);
    401 static const IntegerType *getIntNTy(LLVMContext &C, unsigned N);
    402 static const IntegerType *getInt1Ty(LLVMContext &C);
    403 static const IntegerType *getInt8Ty(LLVMContext &C);
    404 static const IntegerType *getInt16Ty(LLVMContext &C);
    405 static const IntegerType *getInt32Ty(LLVMContext &C);
    406 static const IntegerType *getInt64Ty(LLVMContext &C);
    307 static Type *getVoidTy(LLVMContext &C);
    308 static Type *getLabelTy(LLVMContext &C);
    309 static Type *getFloatTy(LLVMContext &C);
    310 static Type *getDoubleTy(LLVMContext &C);
    311 static Type *getMetadataTy(LLVMContext &C);
    312 static Type *getX86_FP80Ty(LLVMContext &C);
    313 static Type *getFP128Ty(LLVMContext &C);
    314 static Type *getPPC_FP128Ty(LLVMContext &C);
    315 static Type *getX86_MMXTy(LLVMContext &C);
    316 static IntegerType *getIntNTy(LLVMContext &C, unsigned N);
    317 static IntegerType *getInt1Ty(LLVMContext &C);
    318 static IntegerType *getInt8Ty(LLVMContext &C);
    319 static IntegerType *getInt16Ty(LLVMContext &C);
    320 static IntegerType *getInt32Ty(LLVMContext &C);
    321 static IntegerType *getInt64Ty(LLVMContext &C);
    407322
    408323 //===--------------------------------------------------------------------===//
    409324 // Convenience methods for getting pointer types with one of the above builtin
    410325 // types as pointee.
    411326 //
    412 static const PointerType *getFloatPtrTy(LLVMContext &C, unsigned AS = 0);
    413 static const PointerType *getDoublePtrTy(LLVMContext &C, unsigned AS = 0);
    414 static const PointerType *getX86_FP80PtrTy(LLVMContext &C, unsigned AS = 0);
    415 static const PointerType *getFP128PtrTy(LLVMContext &C, unsigned AS = 0);
    416 static const PointerType *getPPC_FP128PtrTy(LLVMContext &C, unsigned AS = 0);
    417 static const PointerType *getX86_MMXPtrTy(LLVMContext &C, unsigned AS = 0);
    418 static const PointerType *getIntNPtrTy(LLVMContext &C, unsigned N,
    419 unsigned AS = 0);
    420 static const PointerType *getInt1PtrTy(LLVMContext &C, unsigned AS = 0);
    421 static const PointerType *getInt8PtrTy(LLVMContext &C, unsigned AS = 0);
    422 static const PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
    423 static const PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
    424 static const PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
    327 static PointerType *getFloatPtrTy(LLVMContext &C, unsigned AS = 0);
    328 static PointerType *getDoublePtrTy(LLVMContext &C, unsigned AS = 0);
    329 static PointerType *getX86_FP80PtrTy(LLVMContext &C, unsigned AS = 0);
    330 static PointerType *getFP128PtrTy(LLVMContext &C, unsigned AS = 0);
    331 static PointerType *getPPC_FP128PtrTy(LLVMContext &C, unsigned AS = 0);
    332 static PointerType *getX86_MMXPtrTy(LLVMContext &C, unsigned AS = 0);
    333 static PointerType *getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS = 0);
    334 static PointerType *getInt1PtrTy(LLVMContext &C, unsigned AS = 0);
    335 static PointerType *getInt8PtrTy(LLVMContext &C, unsigned AS = 0);
    336 static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
    337 static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
    338 static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
    425339
    426340 /// Methods for support type inquiry through isa, cast, and dyn_cast:
    427341 static inline bool classof(const Type *) { return true; }
    428342
    429 void addRef() const {
    430 assert(isAbstract() && "Cannot add a reference to a non-abstract type!");
    431 ++RefCount;
    432 }
    433
    434 void dropRef() const {
    435 assert(isAbstract() && "Cannot drop a reference to a non-abstract type!");
    436 assert(RefCount && "No objects are currently referencing this object!");
    437
    438 // If this is the last PATypeHolder using this object, and there are no
    439 // PATypeHandles using it, the type is dead, delete it now.
    440 if (--RefCount == 0 && AbstractTypeUsers.empty())
    441 this->destroy();
    442 }
    443
    444 /// addAbstractTypeUser - Notify an abstract type that there is a new user of
    445 /// it. This function is called primarily by the PATypeHandle class.
    446 ///
    447 void addAbstractTypeUser(AbstractTypeUser *U) const;
    448
    449 /// removeAbstractTypeUser - Notify an abstract type that a user of the class
    450 /// no longer has a handle to the type. This function is called primarily by
    451 /// the PATypeHandle class. When there are no users of the abstract type, it
    452 /// is annihilated, because there is no way to get a reference to it ever
    453 /// again.
    454 ///
    455 void removeAbstractTypeUser(AbstractTypeUser *U) const;
    456
    457343 /// getPointerTo - Return a pointer to the current type. This is equivalent
    458344 /// to PointerType::get(Foo, AddrSpace).
    459 const PointerType *getPointerTo(unsigned AddrSpace = 0) const;
    345 PointerType *getPointerTo(unsigned AddrSpace = 0) const;
    460346
    461347 private:
    462348 /// isSizedDerivedType - Derived types like structures and arrays are sized
    463349 /// iff all of the members of the type are sized as well. Since asking for
    464350 /// their size is relatively uncommon, move this operation out of line.
    465351 bool isSizedDerivedType() const;
    466
    467 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
    468 virtual void typeBecameConcrete(const DerivedType *AbsTy);
    469
    470 protected:
    471 // PromoteAbstractToConcrete - This is an internal method used to calculate
    472 // change "Abstract" from true to false when types are refined.
    473 void PromoteAbstractToConcrete();
    474 friend class TypeMapBase;
    475352 };
    476353
    477 //===----------------------------------------------------------------------===//
    478 // Define some inline methods for the AbstractTypeUser.h:PATypeHandle class.
    479 // These are defined here because they MUST be inlined, yet are dependent on
    480 // the definition of the Type class.
    481 //
    482 inline void PATypeHandle::addUser() {
    483 assert(Ty && "Type Handle has a null type!");
    484 if (Ty->isAbstract())
    485 Ty->addAbstractTypeUser(User);
    354 // Printing of types.
    355 static inline raw_ostream &operator<<(raw_ostream &OS, const Type &T) {
    356 T.print(OS);
    357 return OS;
    486358 }
    487 inline void PATypeHandle::removeUser() {
    488 if (Ty->isAbstract())
    489 Ty->removeAbstractTypeUser(User);
    490 }
    491
    492 // Define inline methods for PATypeHolder.
    493
    494 /// get - This implements the forwarding part of the union-find algorithm for
    495 /// abstract types. Before every access to the Type*, we check to see if the
    496 /// type we are pointing to is forwarding to a new type. If so, we drop our
    497 /// reference to the type.
    498 ///
    499 inline Type *PATypeHolder::get() const {
    500 if (Ty == 0) return 0;
    501 const Type *NewTy = Ty->getForwardedType();
    502 if (!NewTy) return const_cast(Ty);
    503 return *const_cast(this) = NewTy;
    504 }
    505
    506 inline void PATypeHolder::addRef() {
    507 if (Ty && Ty->isAbstract())
    508 Ty->addRef();
    509 }
    510
    511 inline void PATypeHolder::dropRef() {
    512 if (Ty && Ty->isAbstract())
    513 Ty->dropRef();
    514 }
    515
    516
    359
    360 // allow isa(x) to work without DerivedTypes.h included.
    361 template <> struct isa_impl {
    362 static inline bool doit(const Type &Ty) {
    363 return Ty.getTypeID() == Type::PointerTyID;
    364 }
    365 };
    366
    367
    517368 //===----------------------------------------------------------------------===//
    518369 // Provide specializations of GraphTraits to be able to treat a type as a
    519370 // graph of sub types.
    520371
    372
    521373 template <> struct GraphTraits {
    522374 typedef Type NodeType;
    523375 typedef Type::subtype_iterator ChildIteratorType;
    544396 }
    545397 };
    546398
    547 template <> struct isa_impl {
    548 static inline bool doit(const Type &Ty) {
    549 return Ty.getTypeID() == Type::PointerTyID;
    550 }
    551 };
    552
    553 raw_ostream &operator<<(raw_ostream &OS, const Type &T);
    554
    555399 } // End llvm namespace
    556400
    557401 #endif
    +0
    -152
    include/llvm/TypeSymbolTable.h less more
    None //===-- llvm/TypeSymbolTable.h - Implement a Type Symtab --------*- C++ -*-===//
    1 //
    2 // The LLVM Compiler Infrastructure
    3 //
    4 // This file is distributed under the University of Illinois Open Source
    5 // License. See LICENSE.TXT for details.
    6 //
    7 //===----------------------------------------------------------------------===//
    8 //
    9 // This file implements the name/type symbol table for LLVM.
    10 //
    11 //===----------------------------------------------------------------------===//
    12
    13 #ifndef LLVM_TYPE_SYMBOL_TABLE_H
    14 #define LLVM_TYPE_SYMBOL_TABLE_H
    15
    16 #include "llvm/Type.h"
    17 #include "llvm/ADT/StringRef.h"
    18 #include "llvm/Support/DataTypes.h"
    19 #include
    20
    21 namespace llvm {
    22
    23 /// This class provides a symbol table of name/type pairs with operations to
    24 /// support constructing, searching and iterating over the symbol table. The
    25 /// class derives from AbstractTypeUser so that the contents of the symbol
    26 /// table can be updated when abstract types become concrete.
    27 class TypeSymbolTable : public AbstractTypeUser {
    28
    29 /// @name Types
    30 /// @{
    31 public:
    32
    33 /// @brief A mapping of names to types.
    34 typedef std::map TypeMap;
    35
    36 /// @brief An iterator over the TypeMap.
    37 typedef TypeMap::iterator iterator;
    38
    39 /// @brief A const_iterator over the TypeMap.
    40 typedef TypeMap::const_iterator const_iterator;
    41
    42 /// @}
    43 /// @name Constructors
    44 /// @{
    45 public:
    46
    47 TypeSymbolTable():LastUnique(0) {}
    48 ~TypeSymbolTable();
    49
    50 /// @}
    51 /// @name Accessors
    52 /// @{
    53 public:
    54
    55 /// Generates a unique name for a type based on the \p BaseName by
    56 /// incrementing an integer and appending it to the name, if necessary
    57 /// @returns the unique name
    58 /// @brief Get a unique name for a type
    59 std::string getUniqueName(StringRef BaseName) const;
    60
    61 /// This method finds the type with the given \p name in the type map
    62 /// and returns it.
    63 /// @returns null if the name is not found, otherwise the Type
    64 /// associated with the \p name.
    65 /// @brief Lookup a type by name.
    66 Type *lookup(StringRef name) const;
    67
    68 /// Lookup the type associated with name.
    69 /// @returns end() if the name is not found, or an iterator at the entry for
    70 /// Type.
    71 iterator find(StringRef Name) {
    72 return tmap.find(Name);
    73 }
    74
    75 /// Lookup the type associated with name.
    76 /// @returns end() if the name is not found, or an iterator at the entry for
    77 /// Type.
    78 const_iterator find(StringRef Name) const {
    79 return tmap.find(Name);
    80 }
    81
    82 /// @returns true iff the symbol table is empty.
    83 /// @brief Determine if the symbol table is empty
    84 inline bool empty() const { return tmap.empty(); }
    85
    86 /// @returns the size of the symbol table
    87 /// @brief The number of name/type pairs is returned.
    88 inline unsigned size() const { return unsigned(tmap.size()); }
    89
    90 /// This function can be used from the debugger to display the
    91 /// content of the symbol table while debugging.
    92 /// @brief Print out symbol table on stderr
    93 void dump() const;
    94
    95 /// @}
    96 /// @name Iteration
    97 /// @{
    98 public:
    99 /// Get an iterator to the start of the symbol table
    100 inline iterator begin() { return tmap.begin(); }
    101
    102 /// @brief Get a const_iterator to the start of the symbol table
    103 inline const_iterator begin() const { return tmap.begin(); }
    104
    105 /// Get an iterator to the end of the symbol table.
    106 inline iterator end() { return tmap.end(); }
    107
    108 /// Get a const_iterator to the end of the symbol table.
    109 inline const_iterator end() const { return tmap.end(); }
    110
    111 /// @}
    112 /// @name Mutators
    113 /// @{
    114 public:
    115
    116 /// Inserts a type into the symbol table with the specified name. There can be
    117 /// a many-to-one mapping between names and types. This method allows a type
    118 /// with an existing entry in the symbol table to get a new name.
    119 /// @brief Insert a type under a new name.
    120 void insert(StringRef Name, const Type *Typ);
    121
    122 /// Remove a type at the specified position in the symbol table.
    123 /// @returns the removed Type.
    124 /// @returns the Type that was erased from the symbol table.
    125 Type* remove(iterator TI);
    126
    127 /// @}
    128 /// @name AbstractTypeUser Methods
    129 /// @{
    130 private:
    131 /// This function is called when one of the types in the type plane
    132 /// is refined.
    133 virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
    134
    135 /// This function marks a type as being concrete (defined).
    136 virtual void typeBecameConcrete(const DerivedType *AbsTy);
    137
    138 /// @}
    139 /// @name Internal Data
    140 /// @{
    141 private:
    142 TypeMap tmap; ///< This is the mapping of names to types.
    143 mutable uint32_t LastUnique; ///< Counter for tracking unique names
    144
    145 /// @}
    146
    147 };
    148
    149 } // End llvm namespace
    150
    151 #endif
    +13
    -10
    include/llvm/Value.h less more
    1313 #ifndef LLVM_VALUE_H
    1414 #define LLVM_VALUE_H
    1515
    16 #include "llvm/AbstractTypeUser.h"
    1716 #include "llvm/Use.h"
    1817 #include "llvm/ADT/StringRef.h"
    1918 #include "llvm/Support/Casting.h"
    3130 class GlobalAlias;
    3231 class InlineAsm;
    3332 class ValueSymbolTable;
    34 class TypeSymbolTable;
    3533 template class StringMapEntry;
    3634 template
    3735 class AssertingVH;
    4240 class LLVMContext;
    4341 class Twine;
    4442 class MDNode;
    43 class Type;
    4544
    4645 //===----------------------------------------------------------------------===//
    4746 // Value Class
    7675 /// This field is initialized to zero by the ctor.
    7776 unsigned short SubclassData;
    7877
    79 PATypeHolder VTy;
    78 Type *VTy;
    8079 Use *UseList;
    8180
    8281 friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
    8382 friend class ValueHandleBase;
    84 friend class AbstractTypeUser;
    8583 ValueName *Name;
    8684
    8785 void operator=(const Value &); // Do not implement
    106104
    107105 /// All values are typed, get the type of this value.
    108106 ///
    109 inline const Type *getType() const { return VTy; }
    107 Type *getType() const { return VTy; }
    110108
    111109 /// All values hold a context through their type.
    112110 LLVMContext &getContext() const;
    113111
    114112 // All values can potentially be named...
    115 inline bool hasName() const { return Name != 0; }
    113 bool hasName() const { return Name != 0; }
    116114 ValueName *getValueName() const { return Name; }
    117115
    118116 /// getName() - Return a constant reference to the value's name. This is cheap
    278276 return true; // Values are always values.
    279277 }
    280278
    281 /// getRawType - This should only be used to implement the vmcore library.
    282 ///
    283 const Type *getRawType() const { return VTy.getRawType(); }
    284
    285279 /// stripPointerCasts - This method strips off any unneeded pointer
    286280 /// casts from the specified value, returning the original uncasted value.
    287281 /// Note that the returned value has pointer type if the specified value does.
    308302 /// MaximumAlignment - This is the greatest alignment value supported by
    309303 /// load, store, and alloca instructions, and global values.
    310304 static const unsigned MaximumAlignment = 1u << 29;
    305
    306 /// mutateType - Mutate the type of this Value to be of the specified type.
    307 /// Note that this is an extremely dangerous operation which can create
    308 /// completely invalid IR very easily. It is strongly recommended that you
    309 /// recreate IR objects with the right types instead of mutating them in
    310 /// place.
    311 void mutateType(Type *Ty) {
    312 VTy = Ty;
    313 }
    311314
    312315 protected:
    313316 unsigned short getSubclassDataFromValue() const { return SubclassData; }
    +0
    -23
    include/llvm-c/Core.h less more
    6767 */
    6868 typedef struct LLVMOpaqueType *LLVMTypeRef;
    6969
    70 /**
    71 * When building recursive types using LLVMRefineType, LLVMTypeRef values may
    72 * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
    73 * llvm::AbstractTypeHolder class.
    74 */
    75 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
    76
    7770 typedef struct LLVMOpaqueValue *LLVMValueRef;
    7871 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
    7972 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
    205198 LLVMStructTypeKind, /**< Structures */
    206199 LLVMArrayTypeKind, /**< Arrays */
    207200 LLVMPointerTypeKind, /**< Pointers */
    208 LLVMOpaqueTypeKind, /**< Opaque: type with unknown structure */
    209201 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
    210202 LLVMMetadataTypeKind, /**< Metadata */
    211203 LLVMX86_MMXTypeKind /**< X86 MMX */
    319311 const char *LLVMGetTarget(LLVMModuleRef M);
    320312 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
    321313
    322 /** See Module::addTypeName. */
    323 LLVMBool LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
    324 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
    325 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
    326 const char *LLVMGetTypeName(LLVMModuleRef M, LLVMTypeRef Ty);
    327
    328314 /** See Module::dump. */
    329315 void LLVMDumpModule(LLVMModuleRef M);
    330316
    417403 /* Operations on other types */
    418404 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
    419405 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
    420 LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
    421406 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
    422407
    423408 LLVMTypeRef LLVMVoidType(void);
    424409 LLVMTypeRef LLVMLabelType(void);
    425410 LLVMTypeRef LLVMOpaqueType(void);
    426411 LLVMTypeRef LLVMX86MMXType(void);
    427
    428 /* Operations on type handles */
    429 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
    430 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
    431 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
    432 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
    433
    434412
    435413 /*===-- Values ------------------------------------------------------------===*/
    436414
    11161094 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef )
    11171095 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef )
    11181096 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef )
    1119 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder, LLVMTypeHandleRef )
    11201097 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef )
    11211098 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef )
    11221099 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef )
    +0
    -3
    include/llvm-c/Transforms/IPO.h less more
    2828
    2929 /** See llvm::createDeadArgEliminationPass function. */
    3030 void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM);
    31
    32 /** See llvm::createDeadTypeEliminationPass function. */
    33 void LLVMAddDeadTypeEliminationPass(LLVMPassManagerRef PM);
    3431
    3532 /** See llvm::createFunctionAttrsPass function. */
    3633 void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM);
    +2
    -2
    lib/AsmParser/LLLexer.h less more
    3737 lltok::Kind CurKind;
    3838 std::string StrVal;
    3939 unsigned UIntVal;
    40 const Type *TyVal;
    40 Type *TyVal;
    4141 APFloat APFloatVal;
    4242 APSInt APSIntVal;
    4343
    5555 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
    5656 lltok::Kind getKind() const { return CurKind; }
    5757 const std::string &getStrVal() const { return StrVal; }
    58 const Type *getTyVal() const { return TyVal; }
    58 Type *getTyVal() const { return TyVal; }
    5959 unsigned getUIntVal() const { return UIntVal; }
    6060 const APSInt &getAPSIntVal() const { return APSIntVal; }
    6161 const APFloat &getAPFloatVal() const { return APFloatVal; }
    +286
    -337
    lib/AsmParser/LLParser.cpp less more
    8888 ForwardRefBlockAddresses.erase(ForwardRefBlockAddresses.begin());
    8989 }
    9090
    91
    92 if (!ForwardRefTypes.empty())
    93 return Error(ForwardRefTypes.begin()->second.second,
    94 "use of undefined type named '" +
    95 ForwardRefTypes.begin()->first + "'");
    96 if (!ForwardRefTypeIDs.empty())
    97 return Error(ForwardRefTypeIDs.begin()->second.second,
    98 "use of undefined type '%" +
    99 Twine(ForwardRefTypeIDs.begin()->first) + "'");
    91 for (unsigned i = 0, e = NumberedTypes.size(); i != e; ++i)
    92 if (NumberedTypes[i].second.isValid())
    93 return Error(NumberedTypes[i].second,
    94 "use of undefined type '%" + Twine(i) + "'");
    95
    96 for (StringMap >::iterator I =
    97 NamedTypes.begin(), E = NamedTypes.end(); I != E; ++I)
    98 if (I->second.second.isValid())
    99 return Error(I->second.second,
    100 "use of undefined type named '" + I->getKey() + "'");
    100101
    101102 if (!ForwardRefVals.empty())
    102103 return Error(ForwardRefVals.begin()->second.second,
    292293 /// ::= LocalVarID '=' 'type' type
    293294 bool LLParser::ParseUnnamedType() {
    294295 LocTy TypeLoc = Lex.getLoc();
    295 unsigned TypeID = NumberedTypes.size();
    296 if (Lex.getUIntVal() != TypeID)
    297 return Error(Lex.getLoc(), "type expected to be numbered '%" +
    298 Twine(TypeID) + "'");
    296 unsigned TypeID = Lex.getUIntVal();
    299297 Lex.Lex(); // eat LocalVarID;
    300298
    301299 if (ParseToken(lltok::equal, "expected '=' after name") ||
    302300 ParseToken(lltok::kw_type, "expected 'type' after '='"))
    303301 return true;
    304302
    305 PATypeHolder Ty(Type::getVoidTy(Context));
    306 if (ParseType(Ty)) return true;
    307
    308 // See if this type was previously referenced.
    309 std::map >::iterator
    310 FI = ForwardRefTypeIDs.find(TypeID);
    311 if (FI != ForwardRefTypeIDs.end()) {
    312 if (FI->second.first.get() == Ty)
    313 return Error(TypeLoc, "self referential type is invalid");
    314
    315 cast(FI->second.first.get())->refineAbstractTypeTo(Ty);
    316 Ty = FI->second.first.get();
    317 ForwardRefTypeIDs.erase(FI);
    318 }
    319
    320 NumberedTypes.push_back(Ty);
    321
    322 return false;
    323 }
    303 if (TypeID >= NumberedTypes.size())
    304 NumberedTypes.resize(TypeID+1);
    305
    306 Type *Result = 0;
    307 if (ParseStructDefinition(TypeLoc, "",
    308 NumberedTypes[TypeID], Result)) return true;
    309
    310 if (!isa(Result)) {
    311 std::pair &Entry = NumberedTypes[TypeID];
    312 if (Entry.first)
    313 return Error(TypeLoc, "non-struct types may not be recursive");
    314 Entry.first = Result;
    315 Entry.second = SMLoc();
    316 }
    317
    318 return false;
    319 }
    320
    324321
    325322 /// toplevelentity
    326323 /// ::= LocalVar '=' 'type' type
    329326 LocTy NameLoc = Lex.getLoc();
    330327 Lex.Lex(); // eat LocalVar.
    331328
    332 PATypeHolder Ty(Type::getVoidTy(Context));
    333
    334329 if (ParseToken(lltok::equal, "expected '=' after name") ||
    335 ParseToken(lltok::kw_type, "expected 'type' after name") ||
    336 ParseType(Ty))
    330 ParseToken(lltok::kw_type, "expected 'type' after name"))
    337331 return true;
    338
    339 // Set the type name, checking for conflicts as we do so.
    340 bool AlreadyExists = M->addTypeName(Name, Ty);
    341 if (!AlreadyExists) return false;
    342
    343 // See if this type is a forward reference. We need to eagerly resolve
    344 // types to allow recursive type redefinitions below.
    345 std::map >::iterator
    346 FI = ForwardRefTypes.find(Name);
    347 if (FI != ForwardRefTypes.end()) {
    348 if (FI->second.first.get() == Ty)
    349 return Error(NameLoc, "self referential type is invalid");
    350
    351 cast(FI->second.first.get())->refineAbstractTypeTo(Ty);
    352 Ty = FI->second.first.get();
    353 ForwardRefTypes.erase(FI);
    354 return false;
    355 }
    356
    357 // Inserting a name that is already defined, get the existing name.
    358 assert(M->getTypeByName(Name) && "Conflict but no matching type?!");
    359
    360 // Otherwise, this is an attempt to redefine a type, report the error.
    361 return Error(NameLoc, "redefinition of type named '" + Name + "' of type '" +
    362 getTypeString(Ty) + "'");
    332
    333 Type *Result = 0;
    334 if (ParseStructDefinition(NameLoc, Name,
    335 NamedTypes[Name], Result)) return true;
    336
    337 if (!isa(Result)) {
    338 std::pair &Entry = NamedTypes[Name];
    339 if (Entry.first)
    340 return Error(NameLoc, "non-struct types may not be recursive");
    341 Entry.first = Result;
    342 Entry.second = SMLoc();
    343 }
    344
    345 return false;
    363346 }
    364347
    365348
    535518 unsigned MetadataID = 0;
    536519
    537520 LocTy TyLoc;
    538 PATypeHolder Ty(Type::getVoidTy(Context));
    521 Type *Ty = 0;
    539522 SmallVector Elts;
    540523 if (ParseUInt32(MetadataID) ||
    541524 ParseToken(lltok::equal, "expected '=' here") ||
    667650 LocTy UnnamedAddrLoc;
    668651 LocTy TyLoc;
    669652
    670 PATypeHolder Ty(Type::getVoidTy(Context));
    653 Type *Ty = 0;
    671654 if (ParseOptionalToken(lltok::kw_thread_local, ThreadLocal) ||
    672655 ParseOptionalAddrSpace(AddrSpace) ||
    673656 ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
    791774
    792775 // Otherwise, create a new forward reference for this value and remember it.
    793776 GlobalValue *FwdVal;
    794 if (const FunctionType *FT = dyn_cast(PTy->getElementType())) {
    795 // Function types can return opaque but functions can't.
    796 if (FT->getReturnType()->isOpaqueTy()) {
    797 Error(Loc, "function may not return opaque type");
    798 return 0;
    799 }
    800
    777 if (const FunctionType *FT = dyn_cast(PTy->getElementType()))
    801778 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
    802 } else {
    779 else
    803780 FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
    804781 GlobalValue::ExternalWeakLinkage, 0, Name);
    805 }
    806782
    807783 ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
    808784 return FwdVal;
    836812
    837813 // Otherwise, create a new forward reference for this value and remember it.
    838814 GlobalValue *FwdVal;
    839 if (const FunctionType *FT = dyn_cast(PTy->getElementType())) {
    840 // Function types can return opaque but functions can't.
    841 if (FT->getReturnType()->isOpaqueTy()) {
    842 Error(Loc, "function may not return opaque type");
    843 return 0;
    844 }
    815 if (const FunctionType *FT = dyn_cast(PTy->getElementType()))
    845816 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
    846 } else {
    817 else
    847818 FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
    848819 GlobalValue::ExternalWeakLinkage, 0, "");
    849 }
    850820
    851821 ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
    852822 return FwdVal;
    12271197 // Type Parsing.
    12281198 //===----------------------------------------------------------------------===//
    12291199
    1230 /// ParseType - Parse and resolve a full type.
    1231 bool LLParser::ParseType(PATypeHolder &Result, bool AllowVoid) {
    1232 LocTy TypeLoc = Lex.getLoc();
    1233 if (ParseTypeRec(Result)) return true;
    1234
    1235 // Verify no unresolved uprefs.
    1236 if (!UpRefs.empty())
    1237 return Error(UpRefs.back().Loc, "invalid unresolved type up reference");
    1238
    1239 if (!AllowVoid && Result.get()->isVoidTy())
    1240 return Error(TypeLoc, "void type only allowed for function results");
    1241
    1242 return false;
    1243 }
    1244
    1245 /// HandleUpRefs - Every time we finish a new layer of types, this function is
    1246 /// called. It loops through the UpRefs vector, which is a list of the
    1247 /// currently active types. For each type, if the up-reference is contained in
    1248 /// the newly completed type, we decrement the level count. When the level
    1249 /// count reaches zero, the up-referenced type is the type that is passed in:
    1250 /// thus we can complete the cycle.
    1251 ///
    1252 PATypeHolder LLParser::HandleUpRefs(const Type *ty) {
    1253 // If Ty isn't abstract, or if there are no up-references in it, then there is
    1254 // nothing to resolve here.
    1255 if (!ty->isAbstract() || UpRefs.empty()) return ty;
    1256
    1257 PATypeHolder Ty(ty);
    1258 #if 0
    1259 dbgs() << "Type '" << *Ty
    1260 << "' newly formed. Resolving upreferences.\n"
    1261 << UpRefs.size() << " upreferences active!\n";
    1262 #endif
    1263
    1264 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
    1265 // to zero), we resolve them all together before we resolve them to Ty. At
    1266 // the end of the loop, if there is anything to resolve to Ty, it will be in
    1267 // this variable.
    1268 OpaqueType *TypeToResolve = 0;
    1269
    1270 for (unsigned i = 0; i != UpRefs.size(); ++i) {
    1271 // Determine if 'Ty' directly contains this up-references 'LastContainedTy'.
    1272 bool ContainsType =
    1273 std::find(Ty->subtype_begin(), Ty->subtype_end(),
    1274 UpRefs[i].LastContainedTy) != Ty->subtype_end();
    1275
    1276 #if 0
    1277 dbgs() << " UR#" << i << " - TypeContains(" << *Ty << ", "
    1278 << *UpRefs[i].LastContainedTy << ") = "
    1279 << (ContainsType ? "true" : "false")
    1280 << " level=" << UpRefs[i].NestingLevel << "\n";
    1281 #endif
    1282 if (!ContainsType)
    1283 continue;
    1284
    1285 // Decrement level of upreference
    1286 unsigned Level = --UpRefs[i].NestingLevel;
    1287 UpRefs[i].LastContainedTy = Ty;
    1288
    1289 // If the Up-reference has a non-zero level, it shouldn't be resolved yet.
    1290 if (Level != 0)
    1291 continue;
    1292
    1293 #if 0
    1294 dbgs() << " * Resolving upreference for " << UpRefs[i].UpRefTy << "\n";
    1295 #endif
    1296 if (!TypeToResolve)
    1297 TypeToResolve = UpRefs[i].UpRefTy;
    1298 else
    1299 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
    1300 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list.
    1301 --i; // Do not skip the next element.
    1302 }
    1303
    1304 if (TypeToResolve)
    1305 TypeToResolve->refineAbstractTypeTo(Ty);
    1306
    1307 return Ty;
    1308 }
    1309
    1310
    1311 /// ParseTypeRec - The recursive function used to process the internal
    1312 /// implementation details of types.
    1313 bool LLParser::ParseTypeRec(PATypeHolder &Result) {
    1200 /// ParseType - Parse a type.
    1201 bool LLParser::ParseType(Type *&Result, bool AllowVoid) {
    1202 SMLoc TypeLoc = Lex.getLoc();
    13141203 switch (Lex.getKind()) {
    13151204 default:
    13161205 return TokError("expected type");
    13171206 case lltok::Type:
    1318 // TypeRec ::= 'float' | 'void' (etc)
    1207 // Type ::= 'float' | 'void' (etc)
    13191208 Result = Lex.getTyVal();
    13201209 Lex.Lex();
    13211210 break;
    1322 case lltok::kw_opaque:
    1323 // TypeRec ::= 'opaque'
    1324 Result = OpaqueType::get(Context);
    1325 Lex.Lex();
    1326 break;
    13271211 case lltok::lbrace:
    1328 // TypeRec ::= '{' ... '}'
    1329 if (ParseStructType(Result, false))
    1212 // Type ::= StructType
    1213 if (ParseAnonStructType(Result, false))
    13301214 return true;
    13311215 break;
    13321216 case lltok::lsquare:
    1333 // TypeRec ::= '[' ... ']'
    1217 // Type ::= '[' ... ']'
    13341218 Lex.Lex(); // eat the lsquare.
    13351219 if (ParseArrayVectorType(Result, false))
    13361220 return true;
    13371221 break;
    13381222 case lltok::less: // Either vector or packed struct.
    1339 // TypeRec ::= '<' ... '>'
    1223 // Type ::= '<' ... '>'
    13401224 Lex.Lex();
    13411225 if (Lex.getKind() == lltok::lbrace) {
    1342 if (ParseStructType(Result, true) ||
    1226 if (ParseAnonStructType(Result, true) ||
    13431227 ParseToken(lltok::greater, "expected '>' at end of packed struct"))
    13441228 return true;
    13451229 } else if (ParseArrayVectorType(Result, true))
    13461230 return true;
    13471231 break;
    1348 case lltok::LocalVar:
    1349 // TypeRec ::= %foo
    1350 if (const Type *T = M->getTypeByName(Lex.getStrVal())) {
    1351 Result = T;
    1352 } else {
    1353 Result = OpaqueType::get(Context);
    1354 ForwardRefTypes.insert(std::make_pair(Lex.getStrVal(),
    1355 std::make_pair(Result,
    1356 Lex.getLoc())));
    1357 M->addTypeName(Lex.getStrVal(), Result.get());
    1358 }
    1232 case lltok::LocalVar: {
    1233 // Type ::= %foo
    1234 std::pair &Entry = NamedTypes[Lex.getStrVal()];
    1235
    1236 // If the type hasn't been defined yet, create a forward definition and
    1237 // remember where that forward def'n was seen (in case it never is defined).
    1238 if (Entry.first == 0) {
    1239 Entry.first = StructType::createNamed(Context, Lex.getStrVal());
    1240 Entry.second = Lex.getLoc();
    1241 }
    1242 Result = Entry.first;
    13591243 Lex.Lex();
    13601244 break;
    1361
    1362 case lltok::LocalVarID:
    1363 // TypeRec ::= %4
    1364 if (Lex.getUIntVal() < NumberedTypes.size())
    1365 Result = NumberedTypes[Lex.getUIntVal()];
    1366 else {
    1367 std::map >::iterator
    1368 I = ForwardRefTypeIDs.find(Lex.getUIntVal());
    1369 if (I != ForwardRefTypeIDs.end())
    1370 Result = I->second.first;
    1371 else {
    1372 Result = OpaqueType::get(Context);
    1373 ForwardRefTypeIDs.insert(std::make_pair(Lex.getUIntVal(),
    1374 std::make_pair(Result,
    1375 Lex.getLoc())));
    1376 }
    1377 }
    1245 }
    1246
    1247 case lltok::LocalVarID: {
    1248 // Type ::= %4
    1249 if (Lex.getUIntVal() >= NumberedTypes.size())
    1250 NumberedTypes.resize(Lex.getUIntVal()+1);
    1251 std::pair &Entry = NumberedTypes[Lex.getUIntVal()];
    1252
    1253 // If the type hasn't been defined yet, create a forward definition and
    1254 // remember where that forward def'n was seen (in case it never is defined).
    1255 if (Entry.first == 0) {
    1256 Entry.first = StructType::createNamed(Context, "");
    1257 Entry.second = Lex.getLoc();
    1258 }
    1259 Result = Entry.first;
    13781260 Lex.Lex();
    1379 break;
    1380 case lltok::backslash: {
    1381 // TypeRec ::= '\' 4
    1382 Lex.Lex();
    1383 unsigned Val;
    1384 if (ParseUInt32(Val)) return true;
    1385 OpaqueType *OT = OpaqueType::get(Context); //Use temporary placeholder.
    1386 UpRefs.push_back(UpRefRecord(Lex.getLoc(), Val, OT));
    1387 Result = OT;
    13881261 break;
    13891262 }
    13901263 }
    13931266 while (1) {
    13941267 switch (Lex.getKind()) {
    13951268 // End of type.
    1396 default: return false;
    1397
    1398 // TypeRec ::= TypeRec '*'
    1269 default:
    1270 if (!AllowVoid && Result->isVoidTy())
    1271 return Error(TypeLoc, "void type only allowed for function results");
    1272 return false;
    1273
    1274 // Type ::= Type '*'
    13991275 case lltok::star:
    1400 if (Result.get()->isLabelTy())
    1276 if (Result->isLabelTy())
    14011277 return TokError("basic block pointers are invalid");
    1402 if (Result.get()->isVoidTy())
    1403 return TokError("pointers to void are invalid; use i8* instead");
    1404 if (!PointerType::isValidElementType(Result.get()))
    1278 if (Result->isVoidTy())
    1279 return TokError("pointers to void are invalid - use i8* instead");
    1280 if (!PointerType::isValidElementType(Result))
    14051281 return TokError("pointer to this type is invalid");
    1406 Result = HandleUpRefs(PointerType::getUnqual(Result.get()));
    1282 Result = PointerType::getUnqual(Result);
    14071283 Lex.Lex();
    14081284 break;
    14091285
    1410 // TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*'
    1286 // Type ::= Type 'addrspace' '(' uint32 ')' '*'
    14111287 case lltok::kw_addrspace: {
    1412 if (Result.get()->isLabelTy())
    1288 if (Result->isLabelTy())
    14131289 return TokError("basic block pointers are invalid");
    1414 if (Result.get()->isVoidTy())
    1290 if (Result->isVoidTy())
    14151291 return TokError("pointers to void are invalid; use i8* instead");
    1416 if (!PointerType::isValidElementType(Result.get()))
    1292 if (!PointerType::isValidElementType(Result))
    14171293 return TokError("pointer to this type is invalid");
    14181294 unsigned AddrSpace;
    14191295 if (ParseOptionalAddrSpace(AddrSpace) ||
    14201296 ParseToken(lltok::star, "expected '*' in address space"))
    14211297 return true;
    14221298
    1423 Result = HandleUpRefs(PointerType::get(Result.get(), AddrSpace));
    1299 Result = PointerType::get(Result, AddrSpace);
    14241300 break;
    14251301 }
    14261302
    14511327
    14521328 // Parse the argument.
    14531329 LocTy ArgLoc;
    1454 PATypeHolder ArgTy(Type::getVoidTy(Context));
    1330 Type *ArgTy = 0;
    14551331 unsigned ArgAttrs1 = Attribute::None;
    14561332 unsigned ArgAttrs2 = Attribute::None;
    14571333 Value *V;
    14711347
    14721348
    14731349 /// ParseArgumentList - Parse the argument list for a function type or function
    1474 /// prototype. If 'inType' is true then we are parsing a FunctionType.
    1350 /// prototype.
    14751351 /// ::= '(' ArgTypeListI ')'
    14761352 /// ArgTypeListI
    14771353 /// ::= /*empty*/
    14791355 /// ::= ArgTypeList ',' '...'
    14801356 /// ::= ArgType (',' ArgType)*
    14811357 ///
    1482 bool LLParser::ParseArgumentList(std::vector &ArgList,
    1483 bool &isVarArg, bool inType) {
    1358 bool LLParser::ParseArgumentList(SmallVectorImpl &ArgList,
    1359 bool &isVarArg){
    14841360 isVarArg = false;
    14851361 assert(Lex.getKind() == lltok::lparen);
    14861362 Lex.Lex(); // eat the (.
    14921368 Lex.Lex();
    14931369 } else {
    14941370 LocTy TypeLoc = Lex.getLoc();
    1495 PATypeHolder ArgTy(Type::getVoidTy(Context));
    1371 Type *ArgTy = 0;
    14961372 unsigned Attrs;
    14971373 std::string Name;
    14981374
    1499 // If we're parsing a type, use ParseTypeRec, because we allow recursive
    1500 // types (such as a function returning a pointer to itself). If parsing a
    1501 // function prototype, we require fully resolved types.
    1502 if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
    1375 if (ParseType(ArgTy) ||
    15031376 ParseOptionalAttrs(Attrs, 0)) return true;
    15041377
    15051378 if (ArgTy->isVoidTy())
    15241397
    15251398 // Otherwise must be an argument type.
    15261399 TypeLoc = Lex.getLoc();
    1527 if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
    1528 ParseOptionalAttrs(Attrs, 0)) return true;
    1400 if (ParseType(ArgTy) || ParseOptionalAttrs(Attrs, 0)) return true;
    15291401
    15301402 if (ArgTy->isVoidTy())
    15311403 return Error(TypeLoc, "argument can not have void type");
    15371409 Name = "";
    15381410 }
    15391411
    1540 if (!ArgTy->isFirstClassType() && !ArgTy->isOpaqueTy())
    1412 if (!ArgTy->isFirstClassType())
    15411413 return Error(TypeLoc, "invalid type for function argument");
    15421414
    15431415 ArgList.push_back(ArgInfo(TypeLoc, ArgTy, Attrs, Name));
    15491421
    15501422 /// ParseFunctionType
    15511423 /// ::= Type ArgumentList OptionalAttrs
    1552 bool LLParser::ParseFunctionType(PATypeHolder &Result) {
    1424 bool LLParser::ParseFunctionType(Type *&Result) {
    15531425 assert(Lex.getKind() == lltok::lparen);
    15541426
    15551427 if (!FunctionType::isValidReturnType(Result))
    15561428 return TokError("invalid function return type");
    15571429
    1558 std::vector> ArgList;
    1430 SmallVector> ArgList;
    15591431 bool isVarArg;
    1560 if (ParseArgumentList(ArgList, isVarArg, true))
    1432 if (ParseArgumentList(ArgList, isVarArg))
    15611433 return true;
    15621434
    15631435 // Reject names on the arguments lists.
    15691441 "argument attributes invalid in function type");
    15701442 }
    15711443
    1572 std::vector> ArgListTy;
    1444 SmallVector> ArgListTy;
    15731445 for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
    1574 ArgListTy.push_back(ArgList[i].Type);
    1575
    1576 Result = HandleUpRefs(FunctionType::get(Result.get(),
    1577 ArgListTy, isVarArg));
    1578 return false;
    1579 }
    1446 ArgListTy.push_back(ArgList[i].Ty);
    1447
    1448 Result = FunctionType::get(Result, ArgListTy, isVarArg);
    1449 return false;
    1450 }
    1451
    1452 /// ParseAnonStructType - Parse an anonymous struct type, which is inlined into
    1453 /// other structs.
    1454 bool LLParser::ParseAnonStructType(Type *&Result, bool Packed) {
    1455 SmallVector Elts;
    1456 if (ParseStructBody(Elts)) return true;
    1457
    1458 Result = StructType::get(Context, Elts, Packed);
    1459 return false;
    1460 }
    1461
    1462 /// ParseStructDefinition - Parse a struct in a 'type' definition.
    1463 bool LLParser::ParseStructDefinition(SMLoc TypeLoc, StringRef Name,
    1464 std::pair &Entry,
    1465 Type *&ResultTy) {
    1466 // If the type was already defined, diagnose the redefinition.
    1467 if (Entry.first && !Entry.second.isValid())
    1468 return Error(TypeLoc, "redefinition of type");
    1469
    1470 // If we have opaque, just return without filling in the definition for the
    1471 // struct. This counts as a definition as far as the .ll file goes.
    1472 if (EatIfPresent(lltok::kw_opaque)) {
    1473 // This type is being defined, so clear the location to indicate this.
    1474 Entry.second = SMLoc();
    1475
    1476 // If this type number has never been uttered, create it.
    1477 if (Entry.first == 0)
    1478 Entry.first = StructType::createNamed(Context, Name);
    1479 ResultTy = Entry.first;
    1480 return false;
    1481 }
    1482
    1483 // If the type starts with '<', then it is either a packed struct or a vector.
    1484 bool isPacked = EatIfPresent(lltok::less);
    1485
    1486 // If we don't have a struct, then we have a random type alias, which we
    1487 // accept for compatibility with old files. These types are not allowed to be
    1488 // forward referenced and not allowed to be recursive.
    1489 if (Lex.getKind() != lltok::lbrace) {
    1490 if (Entry.first)
    1491 return Error(TypeLoc, "forward references to non-struct type");
    1492
    1493 ResultTy = 0;
    1494 if (isPacked)
    1495 return ParseArrayVectorType(ResultTy, true);
    1496 return ParseType(ResultTy);
    1497 }
    1498
    1499 // This type is being defined, so clear the location to indicate this.
    1500 Entry.second = SMLoc();
    1501
    1502 // If this type number has never been uttered, create it.
    1503 if (Entry.first == 0)
    1504 Entry.first = StructType::createNamed(Context, Name);
    1505
    1506 StructType *STy = cast(Entry.first);
    1507
    1508 SmallVector Body;
    1509 if (ParseStructBody(Body) ||
    1510 (isPacked && ParseToken(lltok::greater, "expected '>' in packed struct")))
    1511 return true;
    1512
    1513 STy->setBody(Body, isPacked);
    1514 ResultTy = STy;
    1515 return false;
    1516 }
    1517
    15801518
    15811519 /// ParseStructType: Handles packed and unpacked types. parsed elsewhere.
    1582 /// TypeRec
    1520 /// StructType
    15831521 /// ::= '{' '}'
    1584 /// ::= '{' TypeRec (',' TypeRec)* '}'
    1522 /// ::= '{' Type (',' Type)* '}'
    15851523 /// ::= '<' '{' '}' '>'
    1586 /// ::= '<' '{' TypeRec (',' TypeRec)* '}' '>'
    1587 bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) {
    1524 /// ::= '<' '{' Type (',' Type)* '}' '>'
    1525 bool LLParser::ParseStructBody(SmallVectorImpl &Body) {
    15881526 assert(Lex.getKind() == lltok::lbrace);
    15891527 Lex.Lex(); // Consume the '{'
    15901528
    1591 if (EatIfPresent(lltok::rbrace)) {
    1592 Result = StructType::get(Context, Packed);
    1593 return false;
    1594 }
    1595
    1596 std::vector ParamsList;
    1529 // Handle the empty struct.
    1530 if (EatIfPresent(lltok::rbrace))
    1531 return false;
    1532
    15971533 LocTy EltTyLoc = Lex.getLoc();
    1598 if (ParseTypeRec(Result)) return true;
    1599 ParamsList.push_back(Result);
    1600
    1601 if (Result->isVoidTy())
    1602 return Error(EltTyLoc, "struct element can not have void type");
    1603 if (!StructType::isValidElementType(Result))
    1534 Type *Ty = 0;
    1535 if (ParseType(Ty)) return true;
    1536 Body.push_back(Ty);
    1537
    1538 if (!StructType::isValidElementType(Ty))
    16041539 return Error(EltTyLoc, "invalid element type for struct");
    16051540
    16061541 while (EatIfPresent(lltok::comma)) {
    16071542 EltTyLoc = Lex.getLoc();
    1608 if (ParseTypeRec(Result)) return true;
    1609
    1610 if (Result->isVoidTy())
    1611 return Error(EltTyLoc, "struct element can not have void type");
    1612 if (!StructType::isValidElementType(Result))
    1543 if (ParseType(Ty)) return true;
    1544
    1545 if (!StructType::isValidElementType(Ty))
    16131546 return Error(EltTyLoc, "invalid element type for struct");
    16141547
    1615 ParamsList.push_back(Result);
    1616 }
    1617
    1618 if (ParseToken(lltok::rbrace, "expected '}' at end of struct"))
    1619 return true;
    1620
    1621 std::vector ParamsListTy;
    1622 for (unsigned i = 0, e = ParamsList.size(); i != e; ++i)
    1623 ParamsListTy.push_back(ParamsList[i].get());
    1624 Result = HandleUpRefs(StructType::get(Context, ParamsListTy, Packed));
    1625 return false;
    1548 Body.push_back(Ty);
    1549 }
    1550
    1551 return ParseToken(lltok::rbrace, "expected '}' at end of struct");
    16261552 }
    16271553
    16281554 /// ParseArrayVectorType - Parse an array or vector type, assuming the first
    16291555 /// token has already been consumed.
    1630 /// TypeRec
    1556 /// Type
    16311557 /// ::= '[' APSINTVAL 'x' Types ']'
    16321558 /// ::= '<' APSINTVAL 'x' Types '>'
    1633 bool LLParser::ParseArrayVectorType(PATypeHolder &Result, bool isVector) {
    1559 bool LLParser::ParseArrayVectorType(Type *&Result, bool isVector) {
    16341560 if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned() ||
    16351561 Lex.getAPSIntVal().getBitWidth() > 64)
    16361562 return TokError("expected number in address space");
    16431569 return true;
    16441570
    16451571 LocTy TypeLoc = Lex.getLoc();
    1646 PATypeHolder EltTy(Type::getVoidTy(Context));
    1647 if (ParseTypeRec(EltTy)) return true;
    1648
    1649 if (EltTy->isVoidTy())
    1650 return Error(TypeLoc, "array and vector element type cannot be void");
    1572 Type *EltTy = 0;
    1573 if (ParseType(EltTy)) return true;
    16511574
    16521575 if (ParseToken(isVector ? lltok::greater : lltok::rsquare,
    16531576 "expected end of sequential type"))
    16641587 } else {
    16651588 if (!ArrayType::isValidElementType(EltTy))
    16661589 return Error(TypeLoc, "invalid array element type");
    1667 Result = HandleUpRefs(ArrayType::get(EltTy, Size));
    1590 Result = ArrayType::get(EltTy, Size);
    16681591 }
    16691592 return false;
    16701593 }
    17691692 }
    17701693
    17711694 // Don't make placeholders with invalid type.
    1772 if (!Ty->isFirstClassType() && !Ty->isOpaqueTy() && !Ty->isLabelTy()) {
    1695 if (!Ty->isFirstClassType() && !Ty->isLabelTy()) {
    17731696 P.Error(Loc, "invalid use of a non-first-class type");
    17741697 return 0;
    17751698 }
    18101733 return 0;
    18111734 }
    18121735
    1813 if (!Ty->isFirstClassType() && !Ty->isOpaqueTy() && !Ty->isLabelTy()) {
    1736 if (!Ty->isFirstClassType() && !Ty->isLabelTy()) {
    18141737 P.Error(Loc, "invalid use of a non-first-class type");
    18151738 return 0;
    18161739 }
    19861909 ParseToken(lltok::rbrace, "expected end of struct constant"))
    19871910 return true;
    19881911
    1989 // FIXME: Get this type from context instead of reconstructing it!
    1990 ID.ConstantVal = ConstantStruct::getAnon(Context, Elts);
    1991 ID.Kind = ValID::t_Constant;
    1912 ID.ConstantStructElts = new Constant*[Elts.size()];
    1913 ID.UIntVal = Elts.size();
    1914 memcpy(ID.ConstantStructElts, Elts.data(), Elts.size()*sizeof(Elts[0]));
    1915 ID.Kind = ValID::t_ConstantStruct;
    19921916 return false;
    19931917 }
    19941918 case lltok::less: {
    20061930 return true;
    20071931
    20081932 if (isPackedStruct) {
    2009 // FIXME: Get this type from context instead of reconstructing it!
    2010 ID.ConstantVal = ConstantStruct::getAnon(Context, Elts, true);
    2011 ID.Kind = ValID::t_Constant;
    1933 ID.ConstantStructElts = new Constant*[Elts.size()];
    1934 memcpy(ID.ConstantStructElts, Elts.data(), Elts.size()*sizeof(Elts[0]));
    1935 ID.UIntVal = Elts.size();
    1936 ID.Kind = ValID::t_PackedConstantStruct;
    20121937 return false;
    20131938 }
    20141939
    21302055 case lltok::kw_inttoptr:
    21312056 case lltok::kw_ptrtoint: {
    21322057 unsigned Opc = Lex.getUIntVal();
    2133 PATypeHolder DestTy(Type::getVoidTy(Context));
    2058 Type *DestTy = 0;
    21342059 Constant *SrcVal;
    21352060 Lex.Lex();
    21362061 if (ParseToken(lltok::lparen, "expected '(' after constantexpr cast") ||
    24132338 }
    24142339
    24152340 bool LLParser::ParseGlobalTypeAndValue(Constant *&V) {
    2416 PATypeHolder Type(Type::getVoidTy(Context));
    2417 return ParseType(Type) ||
    2418 ParseGlobalValue(Type, V);
    2341 Type *Ty = 0;
    2342 return ParseType(Ty) ||
    2343 ParseGlobalValue(Ty, V);
    24192344 }
    24202345
    24212346 /// ParseGlobalValueVector
    25612486 return false;
    25622487 case ValID::t_Undef:
    25632488 // FIXME: LabelTy should not be a first-class type.
    2564 if ((!Ty->isFirstClassType() || Ty->isLabelTy()) &&
    2565 !Ty->isOpaqueTy())
    2489 if (!Ty->isFirstClassType() || Ty->isLabelTy())
    25662490 return Error(ID.Loc, "invalid type for undef constant");
    25672491 V = UndefValue::get(Ty);
    25682492 return false;
    25832507
    25842508 V = ID.ConstantVal;
    25852509 return false;
    2586 }
    2587 }
    2588
    2589 bool LLParser::ParseValue(const Type *Ty, Value *&V, PerFunctionState &PFS) {
    2510 case ValID::t_ConstantStruct:
    2511 case ValID::t_PackedConstantStruct:
    2512 if (const StructType *ST = dyn_cast(Ty)) {
    2513 if (ST->getNumElements() != ID.UIntVal)
    2514 return Error(ID.Loc,
    2515 "initializer with struct type has wrong # elements");
    2516 if (ST->isPacked() != (ID.Kind == ValID::t_PackedConstantStruct))
    2517 return Error(ID.Loc, "packed'ness of initializer and type don't match");
    2518
    2519 // Verify that the elements are compatible with the structtype.
    2520 for (unsigned i = 0, e = ID.UIntVal; i != e; ++i)
    2521 if (ID.ConstantStructElts[i]->getType() != ST->getElementType(i))
    2522 return Error(ID.Loc, "element " + Twine(i) +
    2523 " of struct initializer doesn't match struct element type");
    2524
    2525 V = ConstantStruct::get(ST, ArrayRef(ID.ConstantStructElts,
    2526 ID.UIntVal));
    2527 } else
    2528 return Error(ID.Loc, "constant expression type mismatch");
    2529 return false;
    2530 }
    2531 }
    2532
    2533 bool LLParser::ParseValue(const Type *Ty, Value *&V, PerFunctionState *PFS) {
    25902534 V = 0;
    25912535 ValID ID;
    2592 return ParseValID(ID, &PFS) ||
    2593 ConvertValIDToValue(Ty, ID, V, &PFS);
    2594 }
    2595
    2596 bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
    2597 PATypeHolder T(Type::getVoidTy(Context));
    2598 return ParseType(T) ||
    2599 ParseValue(T, V, PFS);
    2536 return ParseValID(ID, PFS) ||
    2537 ConvertValIDToValue(Ty, ID, V, PFS);
    2538 }
    2539
    2540 bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState *PFS) {
    2541 Type *Ty = 0;
    2542 return ParseType(Ty) ||
    2543 ParseValue(Ty, V, PFS);
    26002544 }
    26012545
    26022546 bool LLParser::ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
    26222566
    26232567 unsigned Visibility, RetAttrs;
    26242568 CallingConv::ID CC;
    2625 PATypeHolder RetType(Type::getVoidTy(Context));
    2569 Type *RetType = 0;
    26262570 LocTy RetTypeLoc = Lex.getLoc();
    26272571 if (ParseOptionalLinkage(Linkage) ||
    26282572 ParseOptionalVisibility(Visibility) ||
    26592603 return Error(LinkageLoc, "invalid function linkage type");
    26602604 }
    26612605
    2662 if (!FunctionType::isValidReturnType(RetType) ||
    2663 RetType->isOpaqueTy())