Re: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Globals.cpp Module.cpp Verifier.cpp
Hello, Chris. > Ok, but the call can be used to dig the global out from under the > constantexprs etc. Yes. Commited. > I must be missing something: isn't it *always* safe to RAUW uses of > an alias with uses of its aliasee? No, that's me missing some bits :) It's always safe to do RAUW of an alias. But even no used alias should be alive. -- With best regards, Anton Korobeynikov. Faculty of Mathematics & Mechanics, Saint Petersburg State University. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Globals.cpp Module.cpp Verifier.cpp
On Apr 29, 2007, at 3:38 AM, Anton Korobeynikov wrote: > Chris, > >> This can use the new getAliaseeGlobal() method. > Not here. We should distinguish, whether we have variable, function ot > bitcast here and print them differently. Ok, but the call can be used to dig the global out from under the constantexprs etc. >> What does it mean for an alias to be a declaration? I'd be fine with >> them always returning true or false. What code calls >> GlobalValue::isDeclaration? > I thought to use it inside linker. Call Alias->isDeclaration() and if > not => do RAUW. I think it's ok to delegate isDeclaration() to > aliasee. I must be missing something: isn't it *always* safe to RAUW uses of an alias with uses of its aliasee? -Chris ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Globals.cpp Module.cpp Verifier.cpp
Chris, > This can use the new getAliaseeGlobal() method. Not here. We should distinguish, whether we have variable, function ot bitcast here and print them differently. > What does it mean for an alias to be a declaration? I'd be fine with > them always returning true or false. What code calls > GlobalValue::isDeclaration? I thought to use it inside linker. Call Alias->isDeclaration() and if not => do RAUW. I think it's ok to delegate isDeclaration() to aliasee. -- With best regards, Anton Korobeynikov. Faculty of Mathematics & Mechanics, Saint Petersburg State University. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Globals.cpp Module.cpp Verifier.cpp
> +++ llvm/lib/VMCore/AsmWriter.cpp Sat Apr 28 08:44:59 2007 > @@ -926,7 +926,7 @@ > assert(0 && "Invalid alias linkage"); >} > > - const GlobalValue *Aliasee = GA->getAliasee(); > + const Constant *Aliasee = dyn_cast_or_null(GA- > >getAliasee()); >assert(Aliasee && "Aliasee cannot be null"); You can drop the dyn_cast_or_null > >if (const GlobalVariable *GV = dyn_cast(Aliasee)) { > @@ -940,9 +940,15 @@ >Out << getLLVMName(F->getName(), GlobalPrefix); > else >Out << "@\"\""; > - } else > -assert(0 && "Unsupported aliasee"); > - > + } else { > +const ConstantExpr *CE = 0; > +if ((CE = dyn_cast(Aliasee)) && > +(CE->getOpcode() == Instruction::BitCast)) { > + writeOperand(CE, false); > +} else > + assert(0 && "Unsupported aliasee"); > + } This can use the new getAliaseeGlobal() method. > bool GlobalAlias::isDeclaration() const { > - return (Aliasee && Aliasee->isDeclaration()); > + const GlobalValue* AV = dyn_cast_or_null > (getAliasee()); > + return (AV && AV->isDeclaration()); > } What does it mean for an alias to be a declaration? I'd be fine with them always returning true or false. What code calls GlobalValue::isDeclaration? > +void GlobalAlias::setAliasee(Constant *Aliasee) > { > - // FIXME: Some checks? > - Aliasee = GV; > + if (Aliasee) { > +assert(Aliasee->getType() == getType() && > + "Alias and aliasee types should match!"); > +setOperand(0, Aliasee); > + } > } With this code, setAliasee(0) is a noop - that is a bug. -Chris ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Globals.cpp Module.cpp Verifier.cpp
Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.276 -> 1.277 Globals.cpp updated: 1.20 -> 1.21 Module.cpp updated: 1.81 -> 1.82 Verifier.cpp updated: 1.206 -> 1.207 --- Log message: Implement review feedback. Aliasees can be either GlobalValue's or bitcasts of them. --- Diffs of the changes: (+30 -12) AsmWriter.cpp | 14 ++ Globals.cpp | 21 ++--- Module.cpp|3 +++ Verifier.cpp |4 +++- 4 files changed, 30 insertions(+), 12 deletions(-) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.276 llvm/lib/VMCore/AsmWriter.cpp:1.277 --- llvm/lib/VMCore/AsmWriter.cpp:1.276 Wed Apr 25 21:24:10 2007 +++ llvm/lib/VMCore/AsmWriter.cpp Sat Apr 28 08:44:59 2007 @@ -926,7 +926,7 @@ assert(0 && "Invalid alias linkage"); } - const GlobalValue *Aliasee = GA->getAliasee(); + const Constant *Aliasee = dyn_cast_or_null(GA->getAliasee()); assert(Aliasee && "Aliasee cannot be null"); if (const GlobalVariable *GV = dyn_cast(Aliasee)) { @@ -940,9 +940,15 @@ Out << getLLVMName(F->getName(), GlobalPrefix); else Out << "@\"\""; - } else -assert(0 && "Unsupported aliasee"); - + } else { +const ConstantExpr *CE = 0; +if ((CE = dyn_cast(Aliasee)) && +(CE->getOpcode() == Instruction::BitCast)) { + writeOperand(CE, false); +} else + assert(0 && "Unsupported aliasee"); + } + printInfoComment(*GA); Out << "\n"; } Index: llvm/lib/VMCore/Globals.cpp diff -u llvm/lib/VMCore/Globals.cpp:1.20 llvm/lib/VMCore/Globals.cpp:1.21 --- llvm/lib/VMCore/Globals.cpp:1.20Wed Apr 25 09:27:10 2007 +++ llvm/lib/VMCore/Globals.cpp Sat Apr 28 08:44:59 2007 @@ -163,12 +163,15 @@ //===--===// GlobalAlias::GlobalAlias(const Type *Ty, LinkageTypes Link, - const std::string &Name, const GlobalValue* aliasee, + const std::string &Name, Constant* aliasee, Module *ParentModule) - : GlobalValue(Ty, Value::GlobalAliasVal, 0, 0, -Link, Name), Aliasee(aliasee) { + : GlobalValue(Ty, Value::GlobalAliasVal, &Aliasee, 1, Link, Name) { LeakDetector::addGarbageObject(this); + if (aliasee) +assert(aliasee->getType() == Ty && "Alias and aliasee types should match!"); + Aliasee.init(aliasee, this); + if (ParentModule) ParentModule->getAliasList().push_back(this); } @@ -190,12 +193,16 @@ } bool GlobalAlias::isDeclaration() const { - return (Aliasee && Aliasee->isDeclaration()); + const GlobalValue* AV = dyn_cast_or_null(getAliasee()); + return (AV && AV->isDeclaration()); } -void GlobalAlias::setAliasee(const GlobalValue *GV) +void GlobalAlias::setAliasee(Constant *Aliasee) { - // FIXME: Some checks? - Aliasee = GV; + if (Aliasee) { +assert(Aliasee->getType() == getType() && + "Alias and aliasee types should match!"); +setOperand(0, Aliasee); + } } Index: llvm/lib/VMCore/Module.cpp diff -u llvm/lib/VMCore/Module.cpp:1.81 llvm/lib/VMCore/Module.cpp:1.82 --- llvm/lib/VMCore/Module.cpp:1.81 Wed Apr 25 09:27:10 2007 +++ llvm/lib/VMCore/Module.cpp Sat Apr 28 08:45:00 2007 @@ -298,6 +298,9 @@ for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I) I->dropAllReferences(); + + for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I) +I->dropAllReferences(); } void Module::addLibrary(const std::string& Lib) { Index: llvm/lib/VMCore/Verifier.cpp diff -u llvm/lib/VMCore/Verifier.cpp:1.206 llvm/lib/VMCore/Verifier.cpp:1.207 --- llvm/lib/VMCore/Verifier.cpp:1.206 Wed Apr 25 09:27:10 2007 +++ llvm/lib/VMCore/Verifier.cppSat Apr 28 08:45:00 2007 @@ -316,7 +316,9 @@ Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() || GA.hasWeakLinkage(), "Alias should have external or external weak linkage!", &GA); - + Assert1(GA.getType() == GA.getAliasee()->getType(), + "Alias and aliasee types should match!", &GA); + visitGlobalValue(GA); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Globals.cpp Module.cpp Verifier.cpp
On Apr 25, 2007, at 7:28 AM, Anton Korobeynikov wrote: > +void GlobalAlias::setAliasee(const GlobalValue *GV) > +{ > + // FIXME: Some checks? > + Aliasee = GV; > +} > + This should assert that GV type matches the alias type. > @@ -277,7 +282,9 @@ >Assert1(!GV.isDeclaration() || >GV.hasExternalLinkage() || >GV.hasDLLImportLinkage() || > - GV.hasExternalWeakLinkage(), > + GV.hasExternalWeakLinkage() || > + (isa(GV) && > + (GV.hasInternalLinkage() || GV.hasWeakLinkage())), >"Global is external, but doesn't have external or dllimport or > weak linkage!", >&GV); Hopefully we can eliminate internal aliases... > > @@ -303,6 +310,16 @@ >visitGlobalValue(GV); > } > > +void Verifier::visitGlobalAlias(GlobalAlias &GA) { > + Assert1(!GA.getName().empty(), > + "Alias name cannot be empty!", &GA); > + Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() || > + GA.hasWeakLinkage(), > + "Alias should have external or external weak linkage!", > &GA); This should check that the alias and aliasee have the same type. -Chris ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Globals.cpp Module.cpp Verifier.cpp
Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.274 -> 1.275 Globals.cpp updated: 1.19 -> 1.20 Module.cpp updated: 1.80 -> 1.81 Verifier.cpp updated: 1.205 -> 1.206 --- Log message: Implement aliases. This fixes PR1017: http://llvm.org/PR1017 and it's dependent bugs. CFE part will follow. --- Diffs of the changes: (+150 -11) AsmWriter.cpp | 74 ++ Globals.cpp | 45 ++- Module.cpp| 23 ++ Verifier.cpp | 19 ++ 4 files changed, 150 insertions(+), 11 deletions(-) Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.274 llvm/lib/VMCore/AsmWriter.cpp:1.275 --- llvm/lib/VMCore/AsmWriter.cpp:1.274 Sun Apr 22 14:24:39 2007 +++ llvm/lib/VMCore/AsmWriter.cpp Wed Apr 25 09:27:10 2007 @@ -166,6 +166,8 @@ return new SlotMachine(BB->getParent()); } else if (const GlobalVariable *GV = dyn_cast(V)){ return new SlotMachine(GV->getParent()); + } else if (const GlobalAlias *GA = dyn_cast(V)){ +return new SlotMachine(GA->getParent()); } else if (const Function *Func = dyn_cast(V)) { return new SlotMachine(Func); } @@ -683,12 +685,13 @@ fillTypeNameTable(M, TypeNames); } - inline void write(const Module *M) { printModule(M); } - inline void write(const GlobalVariable *G) { printGlobal(G); } - inline void write(const Function *F) { printFunction(F);} - inline void write(const BasicBlock *BB){ printBasicBlock(BB); } + inline void write(const Module *M) { printModule(M); } + inline void write(const GlobalVariable *G) { printGlobal(G); } + inline void write(const GlobalAlias *G){ printAlias(G);} + inline void write(const Function *F) { printFunction(F); } + inline void write(const BasicBlock *BB){ printBasicBlock(BB); } inline void write(const Instruction *I){ printInstruction(*I); } - inline void write(const Type *Ty) { printType(Ty); } + inline void write(const Type *Ty) { printType(Ty);} void writeOperand(const Value *Op, bool PrintType); @@ -698,6 +701,7 @@ void printModule(const Module *M); void printTypeSymbolTable(const TypeSymbolTable &ST); void printGlobal(const GlobalVariable *GV); + void printAlias(const GlobalAlias *GV); void printFunction(const Function *F); void printArgument(const Argument *FA, uint16_t ParamAttrs); void printBasicBlock(const BasicBlock *BB); @@ -848,6 +852,11 @@ // Output all of the functions. for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) printFunction(I); + + // Output all aliases + for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); + I != E; ++I) +printAlias(I); } void AssemblyWriter::printGlobal(const GlobalVariable *GV) { @@ -888,16 +897,55 @@ assert(C && "GlobalVar initializer isn't constant?"); writeOperand(GV->getInitializer(), false); } - + if (GV->hasSection()) Out << ", section \"" << GV->getSection() << '"'; if (GV->getAlignment()) Out << ", align " << GV->getAlignment(); - + printInfoComment(*GV); Out << "\n"; } +void AssemblyWriter::printAlias(const GlobalAlias *GA) { + Out << getLLVMName(GA->getName(), GlobalPrefix) << " = "; + switch (GA->getVisibility()) { + default: assert(0 && "Invalid visibility style!"); + case GlobalValue::DefaultVisibility: break; + case GlobalValue::HiddenVisibility: Out << "hidden "; break; + } + + Out << "alias "; + + switch (GA->getLinkage()) { + case GlobalValue::WeakLinkage: Out << "weak "; break; + case GlobalValue::InternalLinkage: Out << "internal "; break; + case GlobalValue::ExternalLinkage: break; + default: + assert(0 && "Invalid alias linkage"); + } + + const GlobalValue *Aliasee = GA->getAliasee(); + assert(Aliasee && "Aliasee cannot be null"); + + if (const GlobalVariable *GV = dyn_cast(Aliasee)) { +printType(GV->getType()); +Out << " " << getLLVMName(GV->getName(), GlobalPrefix); + } else if (const Function *F = dyn_cast(Aliasee)) { +printType(F->getFunctionType()); +Out << "* "; + +if (!F->getName().empty()) + Out << getLLVMName(F->getName(), GlobalPrefix); +else + Out << "@\"\""; + } else +assert(0 && "Unsupported aliasee"); + + printInfoComment(*GA); + Out << "\n"; +} + void AssemblyWriter::printTypeSymbolTable(const TypeSymbolTable &ST) { // Print the types. for (TypeSymbolTable::const_iterator TI = ST.begin(), TE = ST.end(); @@ -1336,6 +1384,12 @@ W.write(this); } +void GlobalAlias::print(std::ostream &o) const { + SlotMachine SlotTable(getParent()); + AssemblyWriter W(o, SlotTable, getParent(), 0); + W.write(this); +} + void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { SlotMachine SlotTable(getParent()); AssemblyWriter W(o, S