llvm.org GIT mirror llvm / a80e118
Implement review feedback. Aliasees can be either GlobalValue's or bitcasts of them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36537 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 12 years ago
20 changed file(s) with 391 addition(s) and 273 deletion(s). Raw diff Collapse all Expand all
12111211 linkage, 2 - Weak linkage.
12121212
12131213
1214 bit(2-31)
1214 bit(2)
1215 0 - Aliasee is global value. 1 - Aliasee is constant
1216 expression (bitcast of global value)
1217
1218
1219 bit(3-31)
12151220 Type slot number of type for the alias itself.
12161221
12171222
12181223
12191224 1220

The next two uint32_vbr's describes the 1221 aliasee.

1225

The next uint32_vbr describes the aliasee.

12221226 12231227
12241228
12251229
12261230 Type
12271231 Description
1228
1229
1230 uint32_vbr
1231 Type slot number of type for the aliasee.
12321232
12331233
12341234 uint32_vbr
2323
  • Calling Conventions
  • 2424
  • Global Variables
  • 2525
  • Functions
  • 26
  • Aliases
  • 2627
  • Parameter Attributes
  • 2728
  • Module-Level Inline Assembly
  • 2829
  • Data Layout
  • 704705
    705706
    706707

    Aliases act as "second name" for the aliasee value (which can be either

    707 function or global variable). Aliases may have an
    708 function or global variable or bitcast of global value). Aliases may have an
    708709 optional linkage type, and an
    709710 optional visibility style.

    710711
    115115 bool isThreadLocal ///< Whether the GV is thread local or not
    116116 ) {}
    117117
    118 virtual void handleGlobalAlias(
    119 const Type* ElemType,
    120 GlobalValue::LinkageTypes Linkage,
    121 unsigned TypeSlotNum,
    122 unsigned AliaseeSlot) { }
    123
    118124 /// This method is called when a type list is recognized. It simply
    119125 /// provides the number of types that the list contains. The handler
    120126 /// should expect that number of calls to handleType.
    8080 void setNext(Function *N) { Next = N; }
    8181 void setPrev(Function *N) { Prev = N; }
    8282
    83 public:
    84 /// Function ctor - If the (optional) Module argument is specified, the
    85 /// function is automatically inserted into the end of the function list for
    86 /// the module.
    87 ///
    88 Function(const FunctionType *Ty, LinkageTypes Linkage,
    89 const std::string &N = "", Module *M = 0);
    90 ~Function();
    91
    92 const Type *getReturnType() const; // Return the type of the ret val
    93 const FunctionType *getFunctionType() const; // Return the FunctionType for me
    94
    95 /// isVarArg - Return true if this function takes a variable number of
    96 /// arguments.
    97 bool isVarArg() const;
    98
    99 /// isDeclaration - Is the body of this function unknown? (The basic block
    100 /// list is empty if so.) This is true for function declarations, but not
    101 /// true for function definitions.
    102 ///
    103 virtual bool isDeclaration() const { return BasicBlocks.empty(); }
    104
    105 /// getIntrinsicID - This method returns the ID number of the specified
    106 /// function, or Intrinsic::not_intrinsic if the function is not an
    107 /// instrinsic, or if the pointer is null. This value is always defined to be
    108 /// zero to allow easy checking for whether a function is intrinsic or not.
    109 /// The particular intrinsic functions which correspond to this value are
    110 /// defined in llvm/Intrinsics.h.
    111 ///
    112 unsigned getIntrinsicID(bool noAssert = false) const;
    113 bool isIntrinsic() const { return getIntrinsicID() != 0; }
    114
    115 /// getCallingConv()/setCallingConv(uint) - These method get and set the
    116 /// calling convention of this function. The enum values for the known
    117 /// calling conventions are defined in CallingConv.h.
    118 unsigned getCallingConv() const { return SubclassData; }
    119 void setCallingConv(unsigned CC) { SubclassData = CC; }
    120
    121 /// Obtains a constant pointer to the ParamAttrsList object which holds the
    122 /// parameter attributes information, if any.
    123 /// @returns 0 if no parameter attributes have been set.
    124 /// @brief Get the parameter attributes.
    125 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
    126
    127 /// Sets the parameter attributes for this Function. To construct a
    128 /// ParamAttrsList, see ParameterAttributes.h
    129 /// @brief Set the parameter attributes.
    130 void setParamAttrs(ParamAttrsList *attrs);
    131
    132 /// deleteBody - This method deletes the body of the function, and converts
    133 /// the linkage to external.
    134 ///
    135 void deleteBody() {
    136 dropAllReferences();
    137 setLinkage(ExternalLinkage);
    138 }
    139
    140 /// removeFromParent - This method unlinks 'this' from the containing module,
    141 /// but does not delete it.
    142 ///
    143 virtual void removeFromParent();
    144
    145 /// eraseFromParent - This method unlinks 'this' from the containing module
    146 /// and deletes it.
    147 ///
    148 virtual void eraseFromParent();
    149
    150
    151 /// Get the underlying elements of the Function... the basic block list is
    152 /// empty for external functions.
    153 ///
    154 const ArgumentListType &getArgumentList() const { return ArgumentList; }
    155 ArgumentListType &getArgumentList() { return ArgumentList; }
    156
    157 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
    158 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
    159
    160 const BasicBlock &getEntryBlock() const { return front(); }
    161 BasicBlock &getEntryBlock() { return front(); }
    162
    163 //===--------------------------------------------------------------------===//
    164 // Symbol Table Accessing functions...
    165
    166 /// getSymbolTable() - Return the symbol table...
    167 ///
    168 inline ValueSymbolTable &getValueSymbolTable() { return *SymTab; }
    169 inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; }
    170
    171
    172 //===--------------------------------------------------------------------===//
    173 // BasicBlock iterator forwarding functions
    174 //
    175 iterator begin() { return BasicBlocks.begin(); }
    176 const_iterator begin() const { return BasicBlocks.begin(); }
    177 iterator end () { return BasicBlocks.end(); }
    178 const_iterator end () const { return BasicBlocks.end(); }
    179
    180 size_t size() const { return BasicBlocks.size(); }
    181 bool empty() const { return BasicBlocks.empty(); }
    182 const BasicBlock &front() const { return BasicBlocks.front(); }
    183 BasicBlock &front() { return BasicBlocks.front(); }
    184 const BasicBlock &back() const { return BasicBlocks.back(); }
    185 BasicBlock &back() { return BasicBlocks.back(); }
    186
    187 //===--------------------------------------------------------------------===//
    188 // Argument iterator forwarding functions
    189 //
    190 arg_iterator arg_begin() { return ArgumentList.begin(); }
    191 const_arg_iterator arg_begin() const { return ArgumentList.begin(); }
    192 arg_iterator arg_end () { return ArgumentList.end(); }
    193 const_arg_iterator arg_end () const { return ArgumentList.end(); }
    194
    195 size_t arg_size () const { return ArgumentList.size(); }
    196 bool arg_empty() const { return ArgumentList.empty(); }
    197
    198 virtual void print(std::ostream &OS) const { print(OS, 0); }
    199 void print(std::ostream *OS) const { if (OS) print(*OS); }
    200 void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
    201
    202 /// viewCFG - This function is meant for use from the debugger. You can just
    203 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
    204 /// program, displaying the CFG of the current function with the code for each
    205 /// basic block inside. This depends on there being a 'dot' and 'gv' program
    206 /// in your path.
    207 ///
    208 void viewCFG() const;
    209
    210 /// viewCFGOnly - This function is meant for use from the debugger. It works
    211 /// just like viewCFG, but it does not include the contents of basic blocks
    212 /// into the nodes, just the label. If you are only interested in the CFG
    213 /// this can make the graph smaller.
    214 ///
    215 void viewCFGOnly() const;
    216
    217 /// Methods for support type inquiry through isa, cast, and dyn_cast:
    218 static inline bool classof(const Function *) { return true; }
    219 static inline bool classof(const Value *V) {
    220 return V->getValueID() == Value::FunctionVal;
    221 }
    222
    223 /// dropAllReferences() - This method causes all the subinstructions to "let
    224 /// go" of all references that they are maintaining. This allows one to
    225 /// 'delete' a whole module at a time, even though there may be circular
    226 /// references... first all references are dropped, and all use counts go to
    227 /// zero. Then everything is deleted for real. Note that no operations are
    228 /// valid on an object that has "dropped all references", except operator
    229 /// delete.
    230 ///
    231 /// Since no other object in the module can have references into the body of a
    232 /// function, dropping all references deletes the entire body of the function,
    233 /// including any contained basic blocks.
    234 ///
    235 void dropAllReferences();
    236
    237 static unsigned getBasicBlockListOffset() {
    238 Function *Obj = 0;
    239 return unsigned(reinterpret_cast(&Obj->BasicBlocks));
    240 }
    241 static unsigned getArgumentListOffset() {
    242 Function *Obj = 0;
    243 return unsigned(reinterpret_cast(&Obj->ArgumentList));
    244 }
    245 private:
    24683 // getNext/Prev - Return the next or previous function in the list. These
    24784 // methods should never be used directly, and are only used to implement the
    24885 // function list as part of the module.
    25188 const Function *getNext() const { return Next; }
    25289 Function *getPrev() { return Prev; }
    25390 const Function *getPrev() const { return Prev; }
    91
    92 public:
    93 /// Function ctor - If the (optional) Module argument is specified, the
    94 /// function is automatically inserted into the end of the function list for
    95 /// the module.
    96 ///
    97 Function(const FunctionType *Ty, LinkageTypes Linkage,
    98 const std::string &N = "", Module *M = 0);
    99 ~Function();
    100
    101 const Type *getReturnType() const; // Return the type of the ret val
    102 const FunctionType *getFunctionType() const; // Return the FunctionType for me
    103
    104 /// isVarArg - Return true if this function takes a variable number of
    105 /// arguments.
    106 bool isVarArg() const;
    107
    108 /// isDeclaration - Is the body of this function unknown? (The basic block
    109 /// list is empty if so.) This is true for function declarations, but not
    110 /// true for function definitions.
    111 ///
    112 virtual bool isDeclaration() const { return BasicBlocks.empty(); }
    113
    114 /// getIntrinsicID - This method returns the ID number of the specified
    115 /// function, or Intrinsic::not_intrinsic if the function is not an
    116 /// instrinsic, or if the pointer is null. This value is always defined to be
    117 /// zero to allow easy checking for whether a function is intrinsic or not.
    118 /// The particular intrinsic functions which correspond to this value are
    119 /// defined in llvm/Intrinsics.h.
    120 ///
    121 unsigned getIntrinsicID(bool noAssert = false) const;
    122 bool isIntrinsic() const { return getIntrinsicID() != 0; }
    123
    124 /// getCallingConv()/setCallingConv(uint) - These method get and set the
    125 /// calling convention of this function. The enum values for the known
    126 /// calling conventions are defined in CallingConv.h.
    127 unsigned getCallingConv() const { return SubclassData; }
    128 void setCallingConv(unsigned CC) { SubclassData = CC; }
    129
    130 /// Obtains a constant pointer to the ParamAttrsList object which holds the
    131 /// parameter attributes information, if any.
    132 /// @returns 0 if no parameter attributes have been set.
    133 /// @brief Get the parameter attributes.
    134 const ParamAttrsList *getParamAttrs() const { return ParamAttrs; }
    135
    136 /// Sets the parameter attributes for this Function. To construct a
    137 /// ParamAttrsList, see ParameterAttributes.h
    138 /// @brief Set the parameter attributes.
    139 void setParamAttrs(ParamAttrsList *attrs);
    140
    141 /// deleteBody - This method deletes the body of the function, and converts
    142 /// the linkage to external.
    143 ///
    144 void deleteBody() {
    145 dropAllReferences();
    146 setLinkage(ExternalLinkage);
    147 }
    148
    149 /// removeFromParent - This method unlinks 'this' from the containing module,
    150 /// but does not delete it.
    151 ///
    152 virtual void removeFromParent();
    153
    154 /// eraseFromParent - This method unlinks 'this' from the containing module
    155 /// and deletes it.
    156 ///
    157 virtual void eraseFromParent();
    158
    159
    160 /// Get the underlying elements of the Function... the basic block list is
    161 /// empty for external functions.
    162 ///
    163 const ArgumentListType &getArgumentList() const { return ArgumentList; }
    164 ArgumentListType &getArgumentList() { return ArgumentList; }
    165
    166 const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
    167 BasicBlockListType &getBasicBlockList() { return BasicBlocks; }
    168
    169 const BasicBlock &getEntryBlock() const { return front(); }
    170 BasicBlock &getEntryBlock() { return front(); }
    171
    172 //===--------------------------------------------------------------------===//
    173 // Symbol Table Accessing functions...
    174
    175 /// getSymbolTable() - Return the symbol table...
    176 ///
    177 inline ValueSymbolTable &getValueSymbolTable() { return *SymTab; }
    178 inline const ValueSymbolTable &getValueSymbolTable() const { return *SymTab; }
    179
    180
    181 //===--------------------------------------------------------------------===//
    182 // BasicBlock iterator forwarding functions
    183 //
    184 iterator begin() { return BasicBlocks.begin(); }
    185 const_iterator begin() const { return BasicBlocks.begin(); }
    186 iterator end () { return BasicBlocks.end(); }
    187 const_iterator end () const { return BasicBlocks.end(); }
    188
    189 size_t size() const { return BasicBlocks.size(); }
    190 bool empty() const { return BasicBlocks.empty(); }
    191 const BasicBlock &front() const { return BasicBlocks.front(); }
    192 BasicBlock &front() { return BasicBlocks.front(); }
    193 const BasicBlock &back() const { return BasicBlocks.back(); }
    194 BasicBlock &back() { return BasicBlocks.back(); }
    195
    196 //===--------------------------------------------------------------------===//
    197 // Argument iterator forwarding functions
    198 //
    199 arg_iterator arg_begin() { return ArgumentList.begin(); }
    200 const_arg_iterator arg_begin() const { return ArgumentList.begin(); }
    201 arg_iterator arg_end () { return ArgumentList.end(); }
    202 const_arg_iterator arg_end () const { return ArgumentList.end(); }
    203
    204 size_t arg_size () const { return ArgumentList.size(); }
    205 bool arg_empty() const { return ArgumentList.empty(); }
    206
    207 virtual void print(std::ostream &OS) const { print(OS, 0); }
    208 void print(std::ostream *OS) const { if (OS) print(*OS); }
    209 void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const;
    210
    211 /// viewCFG - This function is meant for use from the debugger. You can just
    212 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
    213 /// program, displaying the CFG of the current function with the code for each
    214 /// basic block inside. This depends on there being a 'dot' and 'gv' program
    215 /// in your path.
    216 ///
    217 void viewCFG() const;
    218
    219 /// viewCFGOnly - This function is meant for use from the debugger. It works
    220 /// just like viewCFG, but it does not include the contents of basic blocks
    221 /// into the nodes, just the label. If you are only interested in the CFG
    222 /// this can make the graph smaller.
    223 ///
    224 void viewCFGOnly() const;
    225
    226 /// Methods for support type inquiry through isa, cast, and dyn_cast:
    227 static inline bool classof(const Function *) { return true; }
    228 static inline bool classof(const Value *V) {
    229 return V->getValueID() == Value::FunctionVal;
    230 }
    231
    232 /// dropAllReferences() - This method causes all the subinstructions to "let
    233 /// go" of all references that they are maintaining. This allows one to
    234 /// 'delete' a whole module at a time, even though there may be circular
    235 /// references... first all references are dropped, and all use counts go to
    236 /// zero. Then everything is deleted for real. Note that no operations are
    237 /// valid on an object that has "dropped all references", except operator
    238 /// delete.
    239 ///
    240 /// Since no other object in the module can have references into the body of a
    241 /// function, dropping all references deletes the entire body of the function,
    242 /// including any contained basic blocks.
    243 ///
    244 void dropAllReferences();
    245
    246 static unsigned getBasicBlockListOffset() {
    247 Function *Obj = 0;
    248 return unsigned(reinterpret_cast(&Obj->BasicBlocks));
    249 }
    250 static unsigned getArgumentListOffset() {
    251 Function *Obj = 0;
    252 return unsigned(reinterpret_cast(&Obj->ArgumentList));
    253 }
    254254 };
    255255
    256256 inline ValueSymbolTable *
    None //===______-- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
    0 //===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
    11 //
    22 // The LLVM Compiler Infrastructure
    33 //
    77 //===----------------------------------------------------------------------===//
    88 //
    99 // This file contains the declaration of the GlobalAlias class, which
    10 // represents a single function or variable alias in the VM.
    10 // represents a single function or variable alias in the IR.
    1111 //
    1212 //===----------------------------------------------------------------------===//
    1313
    3535 void setNext(GlobalAlias *N) { Next = N; }
    3636 void setPrev(GlobalAlias *N) { Prev = N; }
    3737
    38 const GlobalValue* Aliasee;
    39 std::string Target;
    38 // getNext/Prev - Return the next or previous alias in the list.
    39 GlobalAlias *getNext() { return Next; }
    40 const GlobalAlias *getNext() const { return Next; }
    41 GlobalAlias *getPrev() { return Prev; }
    42 const GlobalAlias *getPrev() const { return Prev; }
    43
    44 Use Aliasee;
    4045 public:
    4146 /// GlobalAlias ctor - If a parent module is specified, the alias is
    42 /// automatically inserted into the end of the specified modules alias list.
    47 /// automatically inserted into the end of the specified module's alias list.
    4348 GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "",
    44 const GlobalValue* Aliasee = 0, Module *Parent = 0);
    49 Constant* Aliasee = 0, Module *Parent = 0);
    4550
    4651 /// isDeclaration - Is this global variable lacking an initializer? If so,
    4752 /// the global variable is defined in some other translation unit, and is thus
    5156 /// removeFromParent - This method unlinks 'this' from the containing module,
    5257 /// but does not delete it.
    5358 ///
    54 virtual void removeFromParent();
    59 void removeFromParent();
    5560
    5661 /// eraseFromParent - This method unlinks 'this' from the containing module
    5762 /// and deletes it.
    5863 ///
    59 virtual void eraseFromParent();
    64 void eraseFromParent();
    6065
    6166 virtual void print(std::ostream &OS) const;
    6267 void print(std::ostream *OS) const { if (OS) print(*OS); }
    6368
    64 void setAliasee(const GlobalValue* GV);
    65 const GlobalValue* getAliasee() const { return Aliasee; }
    69 /// set/getAliasee - These methods retrive and set alias target.
    70 void setAliasee(Constant* GV);
    71 const Constant* getAliasee() const {
    72 return cast_or_null(getOperand(0));
    73 }
    74 Constant* getAliasee() {
    75 return cast_or_null(getOperand(0));
    76 }
    6677
    6778 // Methods for support type inquiry through isa, cast, and dyn_cast:
    6879 static inline bool classof(const GlobalAlias *) { return true; }
    6980 static inline bool classof(const Value *V) {
    7081 return V->getValueID() == Value::GlobalAliasVal;
    7182 }
    72 private:
    73 // getNext/Prev - Return the next or previous alias in the list.
    74 GlobalAlias *getNext() { return Next; }
    75 const GlobalAlias *getNext() const { return Next; }
    76 GlobalAlias *getPrev() { return Prev; }
    77 const GlobalAlias *getPrev() const { return Prev; }
    7883 };
    7984
    8085 } // End llvm namespace
    120120 /// value is outside of the current translation unit...
    121121 virtual bool isDeclaration() const = 0;
    122122
    123 /// removeFromParent - This method unlinks 'this' from the containing module,
    124 /// but does not delete it.
    125 ///
    126 virtual void removeFromParent() = 0;
    127
    128 /// eraseFromParent - This method unlinks 'this' from the containing module
    129 /// and deletes it.
    130 ///
    131 virtual void eraseFromParent() = 0;
    132
    133123 /// getParent - Get the module that this global value is contained inside
    134124 /// of...
    135125 inline Module *getParent() { return Parent; }
    106106 /// removeFromParent - This method unlinks 'this' from the containing module,
    107107 /// but does not delete it.
    108108 ///
    109 virtual void removeFromParent();
    109 void removeFromParent();
    110110
    111111 /// eraseFromParent - This method unlinks 'this' from the containing module
    112112 /// and deletes it.
    113113 ///
    114 virtual void eraseFromParent();
    114 void eraseFromParent();
    115115
    116116 /// Override Constant's implementation of this method so we can
    117117 /// replace constant initializers.
    479479 // or an id number that hasn't been read yet. We may be referencing something
    480480 // forward, so just create an entry to be resolved later and get to it...
    481481 //
    482 V = new Argument(Ty);
    483
    482 switch (ID.Type) {
    483 case ValID::GlobalName:
    484 case ValID::GlobalID:
    485 const PointerType *PTy = dyn_cast(Ty);
    486 if (!PTy) {
    487 GenerateError("Invalid type for reference to global" );
    488 return 0;
    489 }
    490 const Type* ElTy = PTy->getElementType();
    491 if (const FunctionType *FTy = dyn_cast(ElTy))
    492 V = new Function(FTy, GlobalValue::ExternalLinkage);
    493 else
    494 V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage);
    495 break;
    496 default:
    497 V = new Argument(Ty);
    498 }
    499
    484500 // Remember where this forward reference came from. FIXME, shouldn't we try
    485501 // to recycle these things??
    486502 CurModule.PlaceHolderInfo.insert(std::make_pair(V, std::make_pair(ID,
    9861002 %type BasicBlock InstructionList
    9871003 %type BBTerminatorInst
    9881004 %type Inst InstVal MemoryInst
    989 %type ConstVal ConstExpr
    1005 %type ConstVal ConstExpr AliaseeRef
    9901006 %type ConstVector
    9911007 %type ArgList ArgListH
    9921008 %type PHIList
    19421958 // ThreadLocal
    19431959 ThreadLocal : THREAD_LOCAL { $$ = true; } | { $$ = false; };
    19441960
    1961 // AliaseeRef - Match either GlobalValue or bitcast to GlobalValue.
    1962 AliaseeRef : ResultTypes SymbolicValueRef {
    1963 const Type* VTy = $1->get();
    1964 Value *V = getVal(VTy, $2);
    1965 GlobalValue* Aliasee = dyn_cast(V);
    1966 if (!Aliasee)
    1967 GEN_ERROR("Aliases can be created only to global values");
    1968
    1969 $$ = Aliasee;
    1970 CHECK_FOR_ERROR
    1971 delete $1;
    1972 }
    1973 | BITCAST '(' AliaseeRef TO Types ')' {
    1974 Constant *Val = $3;
    1975 const Type *DestTy = $5->get();
    1976 if (!CastInst::castIsValid($1, $3, DestTy))
    1977 GEN_ERROR("invalid cast opcode for cast from '" +
    1978 Val->getType()->getDescription() + "' to '" +
    1979 DestTy->getDescription() + "'");
    1980
    1981 $$ = ConstantExpr::getCast($1, $3, DestTy);
    1982 CHECK_FOR_ERROR
    1983 delete $5;
    1984 };
    19451985
    19461986 //===----------------------------------------------------------------------===//
    19471987 // Rules to match Modules
    20442084 CurGV = 0;
    20452085 CHECK_FOR_ERROR
    20462086 }
    2047 | OptGlobalAssign GVVisibilityStyle ALIAS AliasLinkage ResultTypes
    2048 SymbolicValueRef {
    2087 | OptGlobalAssign GVVisibilityStyle ALIAS AliasLinkage AliaseeRef {
    20492088 std::string Name($1);
    20502089 if (Name.empty())
    2051 GEN_ERROR("Alias name cannot be empty")
    2052 const PointerType *PFTy = 0;
    2053 const FunctionType *Ty = 0;
    2054 Value* V = 0;
    2055 const Type* VTy = 0;
    2056 if (!(PFTy = dyn_cast($5->get())) ||
    2057 !(Ty = dyn_cast(PFTy->getElementType()))) {
    2058 VTy = $5->get();
    2059 V = getExistingVal(VTy, $6);
    2060 } else {
    2061 VTy = PFTy;
    2062 V = getExistingVal(PFTy, $6);
    2063 }
    2064 if (V == 0)
    2090 GEN_ERROR("Alias name cannot be empty");
    2091
    2092 Constant* Aliasee = $5;
    2093 if (Aliasee == 0)
    20652094 GEN_ERROR(std::string("Invalid aliasee for alias: ") + $1);
    2066 if (GlobalValue* Aliasee = dyn_cast(V)) {
    2067 GlobalAlias* GA = new GlobalAlias(VTy, $4, Name, Aliasee,
    2068 CurModule.CurrentModule);
    2069 GA->setVisibility($2);
    2070 InsertValue(GA, CurModule.Values);
    2071 } else
    2072 GEN_ERROR("Aliases can be created only to global values");
    2073 CHECK_FOR_ERROR
    2074 delete $5;
    2095
    2096 GlobalAlias* GA = new GlobalAlias(Aliasee->getType(), $4, Name, Aliasee,
    2097 CurModule.CurrentModule);
    2098 GA->setVisibility($2);
    2099 InsertValue(GA, CurModule.Values);
    2100 CHECK_FOR_ERROR
    20752101 }
    20762102 | TARGET TargetDefinition {
    20772103 CHECK_FOR_ERROR
    178178
    179179 }
    180180
    181 virtual void handleGlobalAlias(
    182 const Type* ElemType,
    183 GlobalValue::LinkageTypes Linkage,
    184 unsigned TypeSlotNum,
    185 unsigned AliaseeSlot) {
    186 if (os) {
    187 *os << " GA: "
    188 << " Linkage=" << Linkage
    189 << " Type=";
    190 //WriteTypeSymbolic(*os, ElemType, M);
    191 *os << " Slot=" << TypeSlotNum << " AliaseeSlot=" << AliaseeSlot
    192 << "\n";
    193 }
    194
    195 bca.numValues++;
    196 if (TypeSlotNum > bca.maxValueSlot)
    197 bca.maxValueSlot = TypeSlotNum;
    198 if (AliaseeSlot > bca.maxValueSlot)
    199 bca.maxValueSlot = AliaseeSlot;
    200 }
    201
    181202 virtual void handleTypeList(unsigned numEntries) {
    182203 bca.maxTypeSlot = numEntries - 1;
    183204 }
    19221922 // Read aliases...
    19231923 unsigned VarType = read_vbr_uint();
    19241924 while (VarType != Type::VoidTyID) { // List is terminated by Void
    1925 unsigned TypeSlotNo = VarType >> 2;
    1925 unsigned TypeSlotNo = VarType >> 3;
    19261926 unsigned EncodedLinkage = VarType & 3;
    1927 unsigned AliaseeTypeSlotNo, AliaseeSlotNo;
    1928
    1929 AliaseeTypeSlotNo = read_vbr_uint();
    1930 AliaseeSlotNo = read_vbr_uint();
    1927 bool isConstantAliasee = (VarType >> 2) & 1;
    1928 unsigned AliaseeSlotNo = read_vbr_uint();
    19311929
    19321930 const Type *Ty = getType(TypeSlotNo);
    19331931 if (!Ty)
    19361934 if (!isa(Ty))
    19371935 error("Alias not a pointer type! Ty= " + Ty->getDescription());
    19381936
    1939 Value* V = getValue(AliaseeTypeSlotNo, AliaseeSlotNo, false);
    1940 if (!V)
    1941 error("Invalid aliasee! TypeSlotNo=" + utostr(AliaseeTypeSlotNo) +
    1937 Value* V = getValue(TypeSlotNo, AliaseeSlotNo, false);
    1938 if (!V && !isConstantAliasee)
    1939 error("Invalid aliasee! TypeSlotNo=" + utostr(TypeSlotNo) +
    19421940 " SlotNo=" + utostr(AliaseeSlotNo));
    1943 if (!isa(V))
    1941 if (!isConstantAliasee && !isa(V))
    19441942 error("Aliasee is not global value! SlotNo=" + utostr(AliaseeSlotNo));
    19451943
    19461944 GlobalValue::LinkageTypes Linkage;
    19591957 }
    19601958
    19611959 GlobalAlias *GA = new GlobalAlias(Ty, Linkage, "",
    1962 dyn_cast(V), TheModule);
    1960 dyn_cast_or_null(V),
    1961 TheModule);
    19631962 insertValue(GA, TypeSlotNo, ModuleValues);
    1963 if (!V && isConstantAliasee)
    1964 Aliasees.push_back(std::make_pair(GA, AliaseeSlotNo));
    1965
    1966 if (Handler) Handler->handleGlobalAlias(Ty, Linkage,
    1967 TypeSlotNo, AliaseeSlotNo);
    19641968 VarType = read_vbr_uint();
    19651969 }
    19661970 }
    20652069 GV->setInitializer(CV);
    20662070 } else
    20672071 error("Cannot find initializer value.");
    2072 }
    2073
    2074 // And aliasees
    2075 while (!Aliasees.empty()) {
    2076 GlobalAlias *GA = Aliasees.back().first;
    2077 unsigned Slot = Aliasees.back().second;
    2078 Aliasees.pop_back();
    2079
    2080 // Look up the aliasee value...
    2081 const llvm::PointerType* GAType = GA->getType();
    2082 unsigned TypeSlot = getTypeSlot(GAType);
    2083 if (Constant *CV = getConstantValue(TypeSlot, Slot)) {
    2084 if (GA->getAliasee())
    2085 error("Aliasee was *already* set?!");
    2086 GA->setAliasee(CV);
    2087 } else
    2088 error("Cannot find aliasee value.");
    20682089 }
    20692090
    20702091 if (!ConstantFwdRefs.empty())
    128128 /// them.
    129129 typedef std::vector > GlobalInitsList;
    130130
    131 /// @brief A list of global aliases and the slot number for constant aliasees
    132 typedef std::vector > AliaseeList;
    133
    131134 /// This type maps a typeslot/valueslot pair to the corresponding Value*.
    132135 /// It is used for dealing with forward references as values are read in.
    133136 /// @brief A map for dealing with forward references of values.
    337340 /// of what we must do.
    338341 GlobalInitsList GlobalInits;
    339342
    343 /// Constant values are read in after global aliases. Because of this, we must
    344 /// defer setting the constant aliasees until after module level constants
    345 /// have been read. In the mean time, this list keeps track of what we must
    346 /// do.
    347 AliaseeList Aliasees;
    348
    340349 // For lazy reading-in of functions, we need to save away several pieces of
    341350 // information about each function: its begin and end pointer in the buffer
    342351 // and its FunctionSlot.
    8888 I != E; ++I)
    8989 CreateSlotIfNeeded(I);
    9090
    91 // Add all of the global aliases to the value table...
    92 //
    93 for (Module::const_alias_iterator I = TheModule->alias_begin(),
    94 E = TheModule->alias_end(); I != E; ++I)
    95 CreateSlotIfNeeded(I);
    96
    9197 // Add all of the module level constants used as initializers
    9298 //
    9399 for (Module::const_global_iterator I = TheModule->global_begin(),
    94100 E = TheModule->global_end(); I != E; ++I)
    95101 if (I->hasInitializer())
    96102 CreateSlotIfNeeded(I->getInitializer());
    103
    104 // Add all of the module level constants used as aliasees
    105 //
    106 for (Module::const_alias_iterator I = TheModule->alias_begin(),
    107 E = TheModule->alias_end(); I != E; ++I)
    108 if (I->getAliasee())
    109 CreateSlotIfNeeded(I->getAliasee());
    97110
    98111 // Now that all global constants have been added, rearrange constant planes
    99112 // that contain constant strings so that the strings occur at the start of the
    10941094 // Output aliases
    10951095 for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
    10961096 I != E; ++I) {
    1097 unsigned Slot = Table.getTypeSlot(I->getType());
    1098 assert(((Slot << 2) >> 2) == Slot && "Slot # too big!");
    1097 unsigned TypeSlotNo = Table.getTypeSlot(I->getType());
    1098 unsigned AliaseeSlotNo = Table.getSlot(I->getAliasee());
    1099 assert(((TypeSlotNo << 3) >> 3) == TypeSlotNo && "Slot # too big!");
    10991100 unsigned aliasLinkage = 0;
    1101 unsigned isConstantAliasee = ((!isa(I->getAliasee())) << 2);
    11001102 switch (I->getLinkage()) {
    11011103 case GlobalValue::ExternalLinkage:
    11021104 aliasLinkage = 0;
    11101112 default:
    11111113 assert(0 && "Invalid alias linkage");
    11121114 }
    1113 output_vbr((Slot << 2) | aliasLinkage);
    1114 output_vbr(Table.getTypeSlot(I->getAliasee()->getType()));
    1115 output_vbr(Table.getSlot(I->getAliasee()));
    1115 output_vbr((TypeSlotNo << 3) | isConstantAliasee | aliasLinkage);
    1116 output_vbr(AliaseeSlotNo);
    11161117 }
    11171118 output_typeid(Table.getTypeSlot(Type::VoidTy));
    11181119 }
    122122 }
    123123
    124124 if (TAI->getSetDirective()) {
    125 if (M.alias_size())
    125 if (!M.alias_empty())
    126126 SwitchToTextSection(TAI->getTextSection());
    127127
    128128 O << "\n";
    129129 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
    130130 I!=E; ++I) {
    131 const GlobalValue *Aliasee = I->getAliasee();
    132 assert(Aliasee && "Aliasee cannot be null!");
    133 std::string Target = Mang->getValueName(Aliasee);
    134 std::string Name = Mang->getValueName(I);
    135
    136 // Aliases with external weak linkage was emitted already
    131 const Constant *Aliasee = dyn_cast_or_null(I->getAliasee());
    132 assert(Aliasee && "Aliasee cannot be null");
    133
    134 std::string Name = Mang->getValueName(I);
    135 std::string Target;
    136
    137 if (const GlobalValue *GV = dyn_cast(Aliasee))
    138 Target = Mang->getValueName(GV);
    139 else {
    140 const ConstantExpr *CE = 0;
    141 if ((CE = dyn_cast(Aliasee)) &&
    142 (CE->getOpcode() == Instruction::BitCast))
    143 Target = Mang->getValueName(CE->getOperand(0));
    144 else
    145 assert(0 && "Unsupported aliasee");
    146 }
    147
    137148 if (I->hasExternalLinkage())
    138149 O << "\t.globl\t" << Name << "\n";
    139150 else if (I->hasWeakLinkage())
    7474
    7575 for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
    7676 I != E; ++I) {
    77 Changed |= RemoveUnusedGlobalValue(*I);
    7877 // Aliases are always needed even if they are not used.
    79 GlobalIsNeeded(I);
    78 MarkUsedGlobalsAsNeeded(cast(I->getAliasee()));
    8079 }
    8180
    8281 // Now that all globals which are needed are in the AliveGlobals set, we loop
    142141 // referenced by the initializer to the alive set.
    143142 if (GV->hasInitializer())
    144143 MarkUsedGlobalsAsNeeded(GV->getInitializer());
    145 } else if (GlobalAlias *GA = dyn_cast(G)) {
    146 // If this is a global alias we also need it's aliasee
    147 GlobalIsNeeded(const_cast(GA->getAliasee()));
    148 } else {
    144 } else if (!isa(G)) {
    149145 // Otherwise this must be a function object. We have to scan the body of
    150146 // the function looking for constants and global values which are used as
    151147 // operands. Any operands of these types must be processed to ensure that
    925925 assert(0 && "Invalid alias linkage");
    926926 }
    927927
    928 const GlobalValue *Aliasee = GA->getAliasee();
    928 const Constant *Aliasee = dyn_cast_or_null(GA->getAliasee());
    929929 assert(Aliasee && "Aliasee cannot be null");
    930930
    931931 if (const GlobalVariable *GV = dyn_cast(Aliasee)) {
    939939 Out << getLLVMName(F->getName(), GlobalPrefix);
    940940 else
    941941 Out << "@\"\"";
    942 } else
    943 assert(0 && "Unsupported aliasee");
    944
    942 } else {
    943 const ConstantExpr *CE = 0;
    944 if ((CE = dyn_cast(Aliasee)) &&
    945 (CE->getOpcode() == Instruction::BitCast)) {
    946 writeOperand(CE, false);
    947 } else
    948 assert(0 && "Unsupported aliasee");
    949 }
    950
    945951 printInfoComment(*GA);
    946952 Out << "\n";
    947953 }
    162162 //===----------------------------------------------------------------------===//
    163163
    164164 GlobalAlias::GlobalAlias(const Type *Ty, LinkageTypes Link,
    165 const std::string &Name, const GlobalValue* aliasee,
    165 const std::string &Name, Constant* aliasee,
    166166 Module *ParentModule)
    167 : GlobalValue(Ty, Value::GlobalAliasVal, 0, 0,
    168 Link, Name), Aliasee(aliasee) {
    167 : GlobalValue(Ty, Value::GlobalAliasVal, &Aliasee, 1, Link, Name) {
    169168 LeakDetector::addGarbageObject(this);
    169
    170 if (aliasee)
    171 assert(aliasee->getType() == Ty && "Alias and aliasee types should match!");
    172 Aliasee.init(aliasee, this);
    170173
    171174 if (ParentModule)
    172175 ParentModule->getAliasList().push_back(this);
    189192 }
    190193
    191194 bool GlobalAlias::isDeclaration() const {
    192 return (Aliasee && Aliasee->isDeclaration());
    193 }
    194
    195 void GlobalAlias::setAliasee(const GlobalValue *GV)
    195 const GlobalValue* AV = dyn_cast_or_null(getAliasee());
    196 return (AV && AV->isDeclaration());
    197 }
    198
    199 void GlobalAlias::setAliasee(Constant *Aliasee)
    196200 {
    197 // FIXME: Some checks?
    198 Aliasee = GV;
    199 }
    200
    201 if (Aliasee) {
    202 assert(Aliasee->getType() == getType() &&
    203 "Alias and aliasee types should match!");
    204 setOperand(0, Aliasee);
    205 }
    206 }
    207
    297297
    298298 for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I)
    299299 I->dropAllReferences();
    300
    301 for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I)
    302 I->dropAllReferences();
    300303 }
    301304
    302305 void Module::addLibrary(const std::string& Lib) {
    315315 Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() ||
    316316 GA.hasWeakLinkage(),
    317317 "Alias should have external or external weak linkage!", &GA);
    318
    318 Assert1(GA.getType() == GA.getAliasee()->getType(),
    319 "Alias and aliasee types should match!", &GA);
    320
    319321 visitGlobalValue(GA);
    320322 }
    321323
    0 ; RUN: llvm-as < %s | llvm-dis > %t1.ll
    11 ; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
    22 ; RUN: diff %t1.ll %t2.ll
    3
    4 ; XFAIL: *
    53
    64 @bar = external global i32
    75 @foo1 = alias i32* @bar
    1311 @bar_f = alias weak %FunTy* @foo_f
    1412
    1513 @bar_i = alias internal i32* @bar
    14
    15 @A = alias bitcast (i32* @bar to i64*)
    1616
    1717 define i32 @test() {
    1818 entry: