diff options
Diffstat (limited to 'tools/llvm-upgrade/UpgradeParser.cpp.cvs')
-rw-r--r-- | tools/llvm-upgrade/UpgradeParser.cpp.cvs | 1282 |
1 files changed, 802 insertions, 480 deletions
diff --git a/tools/llvm-upgrade/UpgradeParser.cpp.cvs b/tools/llvm-upgrade/UpgradeParser.cpp.cvs index a04facb614..bf15425196 100644 --- a/tools/llvm-upgrade/UpgradeParser.cpp.cvs +++ b/tools/llvm-upgrade/UpgradeParser.cpp.cvs @@ -427,7 +427,7 @@ static GlobalVariable *CurGV; // typedef std::vector<Value *> ValueList; // Numbered defs -typedef std::pair<std::string,const Type*> RenameMapKey; +typedef std::pair<std::string,TypeInfo> RenameMapKey; typedef std::map<RenameMapKey,std::string> RenameMapType; static void @@ -438,7 +438,10 @@ static struct PerModuleInfo { Module *CurrentModule; std::map<const Type *, ValueList> Values; // Module level numbered definitions std::map<const Type *,ValueList> LateResolveValues; - std::vector<PATypeHolder> Types; + std::vector<PATypeHolder> Types; + std::vector<Signedness> TypeSigns; + std::map<std::string,Signedness> NamedTypeSigns; + std::map<std::string,Signedness> NamedValueSigns; std::map<ValID, PATypeHolder> LateResolveTypes; static Module::Endianness Endian; static Module::PointerSize PointerSize; @@ -495,6 +498,9 @@ static struct PerModuleInfo { Values.clear(); // Clear out function local definitions Types.clear(); + TypeSigns.clear(); + NamedTypeSigns.clear(); + NamedValueSigns.clear(); CurrentModule = 0; } @@ -568,6 +574,24 @@ static struct PerFunctionInfo { static bool inFunctionScope() { return CurFun.CurrentFunction != 0; } +/// This function is just a utility to make a Key value for the rename map. +/// The Key is a combination of the name, type, Signedness of the original +/// value (global/function). This just constructs the key and ensures that +/// named Signedness values are resolved to the actual Signedness. +/// @brief Make a key for the RenameMaps +static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty, + const Signedness &Sign) { + TypeInfo TI; + TI.T = Ty; + if (Sign.isNamed()) + // Don't allow Named Signedness nodes because they won't match. The actual + // Signedness must be looked up in the NamedTypeSigns map. + TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]); + else + TI.S.copy(Sign); + return std::make_pair(Name, TI); +} + //===----------------------------------------------------------------------===// // Code to handle definitions of all the types @@ -593,7 +617,6 @@ static const Type *getType(const ValID &D, bool DoNotImprovise = false) { break; case ValID::NameVal: // Is it a named definition? if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) { - D.destroy(); // Free old strdup'd memory... return N; } break; @@ -608,7 +631,6 @@ static const Type *getType(const ValID &D, bool DoNotImprovise = false) { // if (DoNotImprovise) return 0; // Do we just want a null to be returned? - if (inFunctionScope()) { if (D.Type == ValID::NameVal) { error("Reference to an undefined type: '" + D.getName() + "'"); @@ -626,13 +648,94 @@ static const Type *getType(const ValID &D, bool DoNotImprovise = false) { Type *Typ = OpaqueType::get(); CurModule.LateResolveTypes.insert(std::make_pair(D, Typ)); return Typ; - } +} + +/// This is like the getType method except that instead of looking up the type +/// for a given ID, it looks up that type's sign. +/// @brief Get the signedness of a referenced type +static Signedness getTypeSign(const ValID &D) { + switch (D.Type) { + case ValID::NumberVal: // Is it a numbered definition? + // Module constants occupy the lowest numbered slots... + if ((unsigned)D.Num < CurModule.TypeSigns.size()) { + return CurModule.TypeSigns[(unsigned)D.Num]; + } + break; + case ValID::NameVal: { // Is it a named definition? + std::map<std::string,Signedness>::const_iterator I = + CurModule.NamedTypeSigns.find(D.Name); + if (I != CurModule.NamedTypeSigns.end()) + return I->second; + // Perhaps its a named forward .. just cache the name + Signedness S; + S.makeNamed(D.Name); + return S; + } + default: + break; + } + // If we don't find it, its signless + Signedness S; + S.makeSignless(); + return S; +} + +/// This function is analagous to getElementType in LLVM. It provides the same +/// function except that it looks up the Signedness instead of the type. This is +/// used when processing GEP instructions that need to extract the type of an +/// indexed struct/array/ptr member. +/// @brief Look up an element's sign. +static Signedness getElementSign(const ValueInfo& VI, + const std::vector<Value*> &Indices) { + const Type *Ptr = VI.V->getType(); + assert(isa<PointerType>(Ptr) && "Need pointer type"); + + unsigned CurIdx = 0; + Signedness S(VI.S); + while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) { + if (CurIdx == Indices.size()) + break; + + Value *Index = Indices[CurIdx++]; + assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type"); + Ptr = CT->getTypeAtIndex(Index); + if (const Type* Ty = Ptr->getForwardedType()) + Ptr = Ty; + assert(S.isComposite() && "Bad Signedness type"); + if (isa<StructType>(CT)) { + S = S.get(cast<ConstantInt>(Index)->getZExtValue()); + } else { + S = S.get(0UL); + } + if (S.isNamed()) + S = CurModule.NamedTypeSigns[S.getName()]; + } + Signedness Result; + Result.makeComposite(S); + return Result; +} + +/// This function just translates a ConstantInfo into a ValueInfo and calls +/// getElementSign(ValueInfo,...). Its just a convenience. +/// @brief ConstantInfo version of getElementSign. +static Signedness getElementSign(const ConstInfo& CI, + const std::vector<Constant*> &Indices) { + ValueInfo VI; + VI.V = CI.C; + VI.S.copy(CI.S); + std::vector<Value*> Idx; + for (unsigned i = 0; i < Indices.size(); ++i) + Idx.push_back(Indices[i]); + Signedness result = getElementSign(VI, Idx); + VI.destroy(); + return result; +} /// This function determines if two function types differ only in their use of /// the sret parameter attribute in the first argument. If they are identical /// in all other respects, it returns true. Otherwise, it returns false. -bool FuncTysDifferOnlyBySRet(const FunctionType *F1, - const FunctionType *F2) { +static bool FuncTysDifferOnlyBySRet(const FunctionType *F1, + const FunctionType *F2) { if (F1->getReturnType() != F2->getReturnType() || F1->getNumParams() != F2->getNumParams() || F1->getParamAttrs(0) != F2->getParamAttrs(0)) @@ -647,10 +750,27 @@ bool FuncTysDifferOnlyBySRet(const FunctionType *F1, return true; } +/// This function determines if the type of V and Ty differ only by the SRet +/// parameter attribute. This is a more generalized case of +/// FuncTysDIfferOnlyBySRet since it doesn't require FunctionType arguments. +static bool TypesDifferOnlyBySRet(Value *V, const Type* Ty) { + if (V->getType() == Ty) + return true; + const PointerType *PF1 = dyn_cast<PointerType>(Ty); + const PointerType *PF2 = dyn_cast<PointerType>(V->getType()); + if (PF1 && PF2) { + const FunctionType* FT1 = dyn_cast<FunctionType>(PF1->getElementType()); + const FunctionType* FT2 = dyn_cast<FunctionType>(PF2->getElementType()); + if (FT1 && FT2) + return FuncTysDifferOnlyBySRet(FT1, FT2); + } + return false; +} + // The upgrade of csretcc to sret param attribute may have caused a function // to not be found because the param attribute changed the type of the called // function. This helper function, used in getExistingValue, detects that -// situation and returns V if it occurs and 0 otherwise. +// situation and bitcasts the function to the correct type. static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) { // Handle degenerate cases if (!V) @@ -658,23 +778,21 @@ static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) { if (V->getType() == Ty) return V; - Value* Result = 0; const PointerType *PF1 = dyn_cast<PointerType>(Ty); const PointerType *PF2 = dyn_cast<PointerType>(V->getType()); if (PF1 && PF2) { - const FunctionType *FT1 = - dyn_cast<FunctionType>(PF1->getElementType()); - const FunctionType *FT2 = - dyn_cast<FunctionType>(PF2->getElementType()); + const FunctionType *FT1 = dyn_cast<FunctionType>(PF1->getElementType()); + const FunctionType *FT2 = dyn_cast<FunctionType>(PF2->getElementType()); if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2)) if (FT2->paramHasAttr(1, FunctionType::StructRetAttribute)) - Result = V; + return V; else if (Constant *C = dyn_cast<Constant>(V)) - Result = ConstantExpr::getBitCast(C, PF1); + return ConstantExpr::getBitCast(C, PF1); else - Result = new BitCastInst(V, PF1, "upgrd.cast", CurBB); + return new BitCastInst(V, PF1, "upgrd.cast", CurBB); + } - return Result; + return 0; } // getExistingValue - Look up the value specified by the provided type and @@ -710,9 +828,8 @@ static Value *getExistingValue(const Type *Ty, const ValID &D) { case ValID::NameVal: { // Is it a named definition? // Get the name out of the ID - std::string Name(D.Name); - Value* V = 0; - RenameMapKey Key = std::make_pair(Name, Ty); + RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S); + Value *V = 0; if (inFunctionScope()) { // See if the name was renamed RenameMapType::const_iterator I = CurFun.RenameMap.find(Key); @@ -720,10 +837,12 @@ static Value *getExistingValue(const Type *Ty, const ValID &D) { if (I != CurFun.RenameMap.end()) LookupName = I->second; else - LookupName = Name; + LookupName = D.Name; ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable(); V = SymTab.lookup(LookupName); - V = handleSRetFuncTypeMerge(V, Ty); + if (V && V->getType() != Ty) + V = handleSRetFuncTypeMerge(V, Ty); + assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type"); } if (!V) { RenameMapType::const_iterator I = CurModule.RenameMap.find(Key); @@ -731,9 +850,11 @@ static Value *getExistingValue(const Type *Ty, const ValID &D) { if (I != CurModule.RenameMap.end()) LookupName = I->second; else - LookupName = Name; + LookupName = D.Name; V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName); - V = handleSRetFuncTypeMerge(V, Ty); + if (V && V->getType() != Ty) + V = handleSRetFuncTypeMerge(V, Ty); + assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type"); } if (!V) return 0; @@ -866,14 +987,13 @@ static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) { break; case ValID::NameVal: // Is it a named definition? Name = ID.Name; - if (Value *N = CurFun.CurrentFunction-> - getValueSymbolTable().lookup(Name)) { + if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) { if (N->getType() != Type::LabelTy) { // Register names didn't use to conflict with basic block names // because of type planes. Now they all have to be unique. So, we just // rename the register and treat this name as if no basic block // had been found. - RenameMapKey Key = std::make_pair(N->getName(),N->getType()); + RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S); N->setName(makeNameUnique(N->getName())); CurModule.RenameMap[Key] = N->getName(); BB = 0; @@ -984,19 +1104,33 @@ ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers, LateResolvers.clear(); } -// ResolveTypeTo - A brand new type was just declared. This means that (if -// name is not null) things referencing Name can be resolved. Otherwise, things -// refering to the number can be resolved. Do this now. -// -static void ResolveTypeTo(char *Name, const Type *ToTy) { +/// This function is used for type resolution and upref handling. When a type +/// becomes concrete, this function is called to adjust the signedness for the +/// concrete type. +static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) { + std::string TyName = CurModule.CurrentModule->getTypeName(oldTy); + if (!TyName.empty()) + CurModule.NamedTypeSigns[TyName] = Sign; +} + +/// ResolveTypeTo - A brand new type was just declared. This means that (if +/// name is not null) things referencing Name can be resolved. Otherwise, +/// things refering to the number can be resolved. Do this now. +static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){ ValID D; - if (Name) D = ValID::create(Name); - else D = ValID::create((int)CurModule.Types.size()); + if (Name) + D = ValID::create(Name); + else + D = ValID::create((int)CurModule.Types.size()); + D.S.copy(Sign); + + CurModule.NamedTypeSigns[Name] = Sign; std::map<ValID, PATypeHolder>::iterator I = CurModule.LateResolveTypes.find(D); if (I != CurModule.LateResolveTypes.end()) { - ((DerivedType*)I->second.get())->refineAbstractTypeTo(ToTy); + const Type *OldTy = I->second.get(); + ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy); CurModule.LateResolveTypes.erase(I); } } @@ -1056,12 +1190,12 @@ static inline bool TypeHasInteger(const Type *Ty) { // null potentially, in which case this is a noop. The string passed in is // assumed to be a malloc'd string buffer, and is free'd by this function. // -static void setValueName(Value *V, char *NameStr) { +static void setValueName(const ValueInfo &V, char *NameStr) { if (NameStr) { std::string Name(NameStr); // Copy string free(NameStr); // Free old string - if (V->getType() == Type::VoidTy) { + if (V.V->getType() == Type::VoidTy) { error("Can't assign name '" + Name + "' to value with void type"); return; } @@ -1074,13 +1208,13 @@ static void setValueName(Value *V, char *NameStr) { if (Existing) { // An existing value of the same name was found. This might have happened // because of the integer type planes collapsing in LLVM 2.0. - if (Existing->getType() == V->getType() && + if (Existing->getType() == V.V->getType() && !TypeHasInteger(Existing->getType())) { // If the type does not contain any integers in them then this can't be // a type plane collapsing issue. It truly is a redefinition and we // should error out as the assembly is invalid. error("Redefinition of value named '" + Name + "' of type '" + - V->getType()->getDescription() + "'"); + V.V->getType()->getDescription() + "'"); return; } // In LLVM 2.0 we don't allow names to be re-used for any values in a @@ -1094,13 +1228,13 @@ static void setValueName(Value *V, char *NameStr) { // We're changing the name but it will probably be used by other // instructions as operands later on. Consequently we have to retain // a mapping of the renaming that we're doing. - RenameMapKey Key = std::make_pair(Name,V->getType()); + RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S); CurFun.RenameMap[Key] = NewName; Name = NewName; } // Set the name. - V->setName(Name); + V.V->setName(Name); } } @@ -1109,7 +1243,8 @@ static void setValueName(Value *V, char *NameStr) { static GlobalVariable * ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, bool isConstantGlobal, const Type *Ty, - Constant *Initializer) { + Constant *Initializer, + const Signedness &Sign) { if (isa<FunctionType>(Ty)) error("Cannot declare global vars of function type"); @@ -1129,6 +1264,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, } else { ID = ValID::create((int)CurModule.Values[PTy].size()); } + ID.S.makeComposite(Sign); if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) { // Move the global to the end of the list, from whereever it was @@ -1154,13 +1290,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, // There is alread a global of the same name which means there is a // conflict. Let's see what we can do about it. std::string NewName(makeNameUnique(Name)); - if (Linkage == GlobalValue::InternalLinkage) { - // The linkage type is internal so just warn about the rename without - // invoking "scarey language" about linkage failures. GVars with - // InternalLinkage can be renamed at will. - warning("Global variable '" + Name + "' was renamed to '"+ - NewName + "'"); - } else { + if (Linkage != GlobalValue::InternalLinkage) { // The linkage of this gval is external so we can't reliably rename // it because it could potentially create a linking problem. // However, we can't leave the name conflict in the output either or @@ -1171,7 +1301,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, } // Put the renaming in the global rename map - RenameMapKey Key = std::make_pair(Name,PointerType::get(Ty)); + RenameMapKey Key = makeRenameMapKey(Name, PointerType::get(Ty), ID.S); CurModule.RenameMap[Key] = NewName; // Rename it @@ -1184,6 +1314,8 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name, CurModule.CurrentModule); InsertValue(GV, CurModule.Values); + // Remember the sign of this global. + CurModule.NamedValueSigns[Name] = ID.S; return GV; } @@ -1194,21 +1326,26 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage, // This function returns true if the type has already been defined, but is // allowed to be redefined in the specified context. If the name is a new name // for the type plane, it is inserted and false is returned. -static bool setTypeName(const Type *T, char *NameStr) { +static bool setTypeName(const PATypeInfo& TI, char *NameStr) { assert(!inFunctionScope() && "Can't give types function-local names"); if (NameStr == 0) return false; std::string Name(NameStr); // Copy string free(NameStr); // Free old string + const Type* Ty = TI.PAT->get(); + // We don't allow assigning names to void type - if (T == Type::VoidTy) { + if (Ty == Type::VoidTy) { error("Can't assign name '" + Name + "' to the void type"); return false; } // Set the type name, checking for conflicts as we do so. - bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, T); + bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty); + + // Save the sign information for later use + CurModule.NamedTypeSigns[Name] = TI.S; if (AlreadyExists) { // Inserting a name that is already defined??? const Type *Existing = CurModule.CurrentModule->getTypeByName(Name); @@ -1218,7 +1355,7 @@ static bool setTypeName(const Type *T, char *NameStr) { // opaque type. In this case, Existing will be an opaque type. if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) { // We ARE replacing an opaque type! - const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(T); + const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty); return true; } @@ -1226,11 +1363,11 @@ static bool setTypeName(const Type *T, char *NameStr) { // the redefinition is identical to the original. This will be so if // Existing and T point to the same Type object. In this one case we // allow the equivalent redefinition. - if (Existing == T) return true; // Yes, it's equal. + if (Existing == Ty) return true; // Yes, it's equal. // Any other kind of (non-equivalent) redefinition is an error. error("Redefinition of type named '" + Name + "' in the '" + - T->getDescription() + "' type plane"); + Ty->getDescription() + "' type plane"); } return false; @@ -1262,7 +1399,7 @@ namespace { OpaqueType *UpRefTy; UpRefRecord(unsigned NL, OpaqueType *URTy) - : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) {} + : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { } }; } @@ -1276,7 +1413,7 @@ static std::vector<UpRefRecord> UpRefs; /// count reaches zero, the upreferenced type is the type that is passed in: /// thus we can complete the cycle. /// -static PATypeHolder HandleUpRefs(const Type *ty) { +static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) { // If Ty isn't abstract, or if there are no up-references in it, then there is // nothing to resolve here. if (!ty->isAbstract() || UpRefs.empty()) return ty; @@ -1292,10 +1429,11 @@ static PATypeHolder HandleUpRefs(const Type *ty) { // this variable. OpaqueType *TypeToResolve = 0; - for (unsigned i = 0; i != UpRefs.size(); ++i) { + unsigned i = 0; + for (; i != UpRefs.size(); ++i) { UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", " - << UpRefs[i].second->getDescription() << ") = " - << (TypeContains(Ty, UpRefs[i].second) ? "true" : "false") << "\n"); + << UpRefs[i].UpRefTy->getDescription() << ") = " + << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n"); if (TypeContains(Ty, UpRefs[i].LastContainedTy)) { // Decrement level of upreference unsigned Level = --UpRefs[i].NestingLevel; @@ -1306,8 +1444,9 @@ static PATypeHolder HandleUpRefs(const Type *ty) { TypeToResolve = UpRefs[i].UpRefTy; } else { UR_OUT(" * Resolving upreference for " - << UpRefs[i].second->getDescription() << "\n"; - std::string OldName = UpRefs[i].UpRefTy->getDescription()); + << UpRefs[i].UpRefTy->getDescription() << "\n"; + std::string OldName = UpRefs[i].UpRefTy->getDescription()); + ResolveTypeSign(UpRefs[i].UpRefTy, Sign); UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve); UR_OUT(" * Type '" << OldName << "' refined upreference to: " << (const void*)Ty << ", " << Ty->getDescription() << "\n"); @@ -1320,14 +1459,113 @@ static PATypeHolder HandleUpRefs(const Type *ty) { if (TypeToResolve) { UR_OUT(" * Resolving upreference for " - << UpRefs[i].second->getDescription() << "\n"; + << UpRefs[i].UpRefTy->getDescription() << "\n"; std::string OldName = TypeToResolve->getDescription()); + ResolveTypeSign(TypeToResolve, Sign); TypeToResolve->refineAbstractTypeTo(Ty); } return Ty; } +bool Signedness::operator<(const Signedness &that) const { + if (isNamed()) { + if (that.isNamed()) + return *(this->name) < *(that.name); + else + return CurModule.NamedTypeSigns[*name] < that; + } else if (that.isNamed()) { + return *this < CurModule.NamedTypeSigns[*that.name]; + } + + if (isComposite() && that.isComposite()) { + if (sv->size() == that.sv->size()) { + SignVector::const_iterator thisI = sv->begin(), thisE = sv->end(); + SignVector::const_iterator thatI = that.sv->begin(), + thatE = that.sv->end(); + for (; thisI != thisE; ++thisI, ++thatI) { + if (*thisI < *thatI) + return true; + else if (!(*thisI == *thatI)) + return false; + } + return false; + } + return sv->size() < that.sv->size(); + } + return kind < that.kind; +} + +bool Signedness::operator==(const Signedness &that) const { + if (isNamed()) + if (that.isNamed()) + return *(this->name) == *(that.name); + else + return CurModule.NamedTypeSigns[*(this->name)] == that; + else if (that.isNamed()) + return *this == CurModule.NamedTypeSigns[*(that.name)]; + if (isComposite() && that.isComposite()) { + if (sv->size() == that.sv->size()) { + SignVector::const_iterator thisI = sv->begin(), thisE = sv->end(); + SignVector::const_iterator thatI = that.sv->begin(), + thatE = that.sv->end(); + for (; thisI != thisE; ++thisI, ++thatI) { + if (!(*thisI == *thatI)) + return false; + } + return true; + } + return false; + } + return kind == that.kind; +} + +void Signedness::copy(const Signedness &that) { + if (that.isNamed()) { + kind = Named; + name = new std::string(*that.name); + } else if (that.isComposite()) { + kind = Composite; + sv = new SignVector(); + *sv = *that.sv; + } else { + kind = that.kind; + sv = 0; + } +} + +void Signedness::destroy() { + if (isNamed()) { + delete name; + } else if (isComposite()) { + delete sv; + } +} + +void Signedness::dump() const { + if (isComposite()) { + if (sv->size() == 1) { + (*sv)[0].dump(); + std::cerr << "*"; + } else { + std::cerr << "{ " ; + for (unsigned i = 0; i < sv->size(); ++i) { + if (i != 0) + std::cerr << ", "; + (*sv)[i].dump(); + } + std::cerr << "} " ; + } + } else if (isNamed()) { + std::cerr << *name; + } else if (isSigned()) { + std::cerr << "S"; + } else if (isUnsigned()) { + std::cerr << "U"; + } else + std::cerr << "."; +} + static inline Instruction::TermOps getTermOp(TermOps op) { switch (op) { @@ -1342,7 +1580,7 @@ getTermOp(TermOps op) { } static inline Instruction::BinaryOps -getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) { +getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) { switch (op) { default : assert(0 && "Invalid OldBinaryOps"); case SetEQ : @@ -1363,7 +1601,7 @@ getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) { isFP = PTy->getElementType()->isFloatingPoint(); if (isFP) return Instruction::FDiv; - else if (Sign == Signed) + else if (Sign.isSigned()) return Instruction::SDiv; return Instruction::UDiv; } @@ -1380,7 +1618,7 @@ getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) { // Select correct opcode if (isFP) return Instruction::FRem; - else if (Sign == Signed) + else if (Sign.isSigned()) return Instruction::SRem; return Instruction::URem; } @@ -1391,7 +1629,7 @@ getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) { case AShrOp : return Instruction::AShr; case ShlOp : return Instruction::Shl; case ShrOp : - if (Sign == Signed) + if (Sign.isSigned()) return Instruction::AShr; return Instruction::LShr; case AndOp : return Instruction::And; @@ -1402,8 +1640,8 @@ getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) { static inline Instruction::OtherOps getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty, - Signedness Sign) { - bool isSigned = Sign == Signed; + const Signedness &Sign) { + bool isSigned = Sign.isSigned(); bool isFP = Ty->isFloatingPoint(); switch (op) { default : assert(0 && "Invalid OldSetCC"); @@ -1483,7 +1721,7 @@ static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) { } static inline Instruction::OtherOps -getOtherOp(OtherOps op, Signedness Sign) { +getOtherOp(OtherOps op, const Signedness &Sign) { switch (op) { default : assert(0 && "Invalid OldOtherOps"); case PHIOp : return Instruction::PHI; @@ -1501,8 +1739,8 @@ getOtherOp(OtherOps op, Signedness Sign) { } static inline Value* -getCast(CastOps op, Value *Src, Signedness SrcSign, const Type *DstTy, - Signedness DstSign, bool ForceInstruction = false) { +getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy, + const Signedness &DstSign, bool ForceInstruction = false) { Instruction::CastOps Opcode; const Type* SrcTy = Src->getType(); if (op == CastOp) { @@ -1539,7 +1777,8 @@ getCast(CastOps op, Value *Src, Signedness SrcSign, const Type *DstTy, } // Determine the opcode to use by calling CastInst::getCastOpcode Opcode = - CastInst::getCastOpcode(Src, SrcSign == Signed, DstTy, DstSign == Signed); + CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy, + DstSign.isSigned()); } else switch (op) { default: assert(0 && "Invalid cast token"); @@ -1631,7 +1870,7 @@ const Type* upgradeGEPIndices(const Type* PTy, // all indices for SequentialType elements. We must retain the same // semantic (zext) for unsigned types. if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) - if (Ity->getBitWidth() < 64 && (*Indices)[i].S == Unsigned) { + if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) { if (CIndices) Index = ConstantExpr::getCast(Instruction::ZExt, cast<Constant>(Index), Type::Int64Ty); @@ -1830,13 +2069,13 @@ using namespace llvm; #endif #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 1454 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1693 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" typedef union YYSTYPE { llvm::Module *ModuleVal; llvm::Function *FunctionVal; std::pair<llvm::PATypeInfo, char*> *ArgVal; llvm::BasicBlock *BasicBlockVal; - llvm::TerminatorInst *TermInstVal; + llvm::TermInstInfo TermInstVal; llvm::InstrInfo InstVal; llvm::ConstInfo ConstVal; llvm::ValueInfo ValueVal; @@ -1873,7 +2112,7 @@ typedef union YYSTYPE { llvm::Module::Endianness Endianness; } YYSTYPE; /* Line 196 of yacc.c. */ -#line 1877 "UpgradeParser.tab.c" +#line 2116 "UpgradeParser.tab.c" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 @@ -1885,7 +2124,7 @@ typedef union YYSTYPE { /* Line 219 of yacc.c. */ -#line 1889 "UpgradeParser.tab.c" +#line 2128 "UpgradeParser.tab.c" #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ @@ -2244,37 +2483,37 @@ static const short int yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned short int yyrline[] = { - 0, 1594, 1594, 1595, 1603, 1604, 1614, 1614, 1614, 1614, - 1614, 1614, 1614, 1614, 1614, 1614, 1614, 1618, 1618, 1618, - 1622, 1622, 1622, 1622, 1622, 1622, 1626, 1626, 1627, 1627, - 1628, 1628, 1629, 1629, 1630, 1630, 1634, 1634, 1635, 1635, - 1636, 1636, 1637, 1637, 1638, 1638, 1639, 1639, 1640, 1640, - 1641, 1642, 1645, 1645, 1645, 1645, 1649, 1649, 1649, 1649, - 1649, 1649, 1649, 1650, 1650, 1650, 1650, 1650, 1650, 1656, - 1656, 1656, 1656, 1660, 1660, 1660, 1660, 1664, 1664, 1668, - 1668, 1673, 1676, 1681, 1682, 1683, 1684, 1685, 1686, 1687, - 1688, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1709, - 1710, 1718, 1719, 1727, 1736, 1737, 1744, 1745, 1749, 1753, - 1769, 1770, 1777, 1778, 1785, 1793, 1793, 1793, 1793, 1793, - 1793, 1793, 1794, 1794, 1794, 1794, 1794, 1799, 1803, 1807, - 1812, 1821, 1838, 1844, 1857, 1866, 1870, 1881, 1885, 1898, - 1902, 1909, 1910, 1916, 1923, 1935, 1965, 1978, 2001, 2029, - 2051, 2062, 2084, 2095, 2104, 2109, 2167, 2174, 2182, 2189, - 2196, 2200, 2204, 2213, 2228, 2241, 2250, 2278, 2291, 2300, - 2306, 2312, 2323, 2329, 2335, 2346, 2347, 2356, 2357, 2369, - 2378, 2379, 2380, 2381, 2382, 2398, 2418, 2420, 2422, 2422, - 2429, 2429, 2436, 2436, 2443, 2443, 2451, 2453, 2455, 2460, - 2474, 2475, 2479, 2482, 2490, 2494, 2501, 2505, 2509, 2513, - 2521, 2521, 2525, 2526, 2530, 2538, 2543, 2551, 2552, 2559, - 2566, 2570, 2746, 2746, 2750, 2760, 2760, 2764, 2769, 2770, - 2771, 2775, 2776, 2775, 2788, 2789, 2794, 2795, 2796, 2797, - 2798, 2799, 2800, 2801, 2802, 2823, 2826, 2841, 2842, 2847, - 2847, 2855, 2864, 2867, 2876, 2886, 2891, 2900, 2911, 2911, - 2914, 2917, 2920, 2924, 2930, 2945, 2951, 3007, 3010, 3016, - 3026, 3039, 3068, 3076, 3084, 3088, 3095, 3096, 3100, 3103, - 3109, 3126, 3142, 3156, 3168, 3180, 3191, 3209, 3218, 3227, - 3234, 3255, 3279, 3285, 3291, 3297, 3313, 3391, 3399, 3400, - 3404, 3405, 3409, 3415, 3421, 3427, 3433, 3440, 3452, 3477 + 0, 1833, 1833, 1834, 1842, 1843, 1853, 1853, 1853, 1853, + 1853, 1853, 1853, 1853, 1853, 1853, 1853, 1857, 1857, 1857, + 1861, 1861, 1861, 1861, 1861, 1861, 1865, 1865, 1866, 1866, + 1867, 1867, 1868, 1868, 1869, 1869, 1873, 1873, 1874, 1874, + 1875, 1875, 1876, 1876, 1877, 1877, 1878, 1878, 1879, 1879, + 1880, 1881, 1884, 1884, 1884, 1884, 1888, 1888, 1888, 1888, + 1888, 1888, 1888, 1889, 1889, 1889, 1889, 1889, 1889, 1895, + 1895, 1895, 1895, 1899, 1899, 1899, 1899, 1903, 1903, 1907, + 1907, 1912, 1915, 1920, 1921, 1922, 1923, 1924, 1925, 1926, + 1927, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1948, + 1949, 1957, 1958, 1966, 1975, 1976, 1983, 1984, 1988, 1992, + 2008, 2009, 2016, 2017, 2024, 2032, 2032, 2032, 2032, 2032, + 2032, 2032, 2033, 2033, 2033, 2033, 2033, 2038, 2042, 2046, + 2051, 2060, 2078, 2084, 2097, 2108, 2112, 2125, 2129, 2143, + 2147, 2154, 2155, 2161, 2168, 2180, 2210, 2223, 2246, 2274, + 2296, 2307, 2329, 2340, 2349, 2354, 2413, 2420, 2428, 2435, + 2442, 2446, 2450, 2459, 2474, 2487, 2496, 2524, 2537, 2546, + 2552, 2558, 2569, 2575, 2581, 2592, 2593, 2602, 2603, 2615, + 2624, 2625, 2626, 2627, 2628, 2644, 2664, 2666, 2668, 2668, + 2675, 2675, 2683, 2683, 2691, 2691, 2700, 2702, 2704, 2709, + 2723, 2724, 2728, 2731, 2739, 2743, 2750, 2754, 2758, 2762, + 2770, 2770, 2774, 2775, 2779, 2787, 2792, 2800, 2801, 2808, + 2815, 2819, 3004, 3004, 3008, 3018, 3018, 3022, 3027, 3028, + 3029, 3033, 3034, 3033, 3046, 3047, 3052, 3053, 3054, 3055, + 3059, 3063, 3064, 3065, 3066, 3087, 3091, 3105, 3106, 3111, + 3111, 3119, 3129, 3132, 3141, 3152, 3157, 3166, 3177, 3177, + 3180, 3184, 3188, 3193, 3203, 3221, 3230, 3295, 3299, 3306, + 3318, 3333, 3363, 3373, 3383, 3387, 3394, 3395, 3399, 3402, + 3408, 3427, 3445, 3461, 3475, 3489, 3500, 3518, 3527, 3536, + 3543, 3564, 3588, 3594, 3600, 3606, 3622, 3706, 3714, 3715, + 3719, 3720, 3724, 3730, 3737, 3743, 3750, 3757, 3770, 3796 }; #endif @@ -3686,7 +3925,7 @@ yyreduce: switch (yyn) { case 3: -#line 1595 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1834 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { if ((yyvsp[0].UIntVal) > (uint32_t)INT32_MAX) // Outside of my range! error("Value too large for type"); @@ -3695,7 +3934,7 @@ yyreduce: break; case 5: -#line 1604 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1843 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { if ((yyvsp[0].UInt64Val) > (uint64_t)INT64_MAX) // Outside of my range! error("Value too large for type"); @@ -3704,226 +3943,226 @@ yyreduce: break; case 26: -#line 1626 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1865 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { (yyval.IPred) = ICmpInst::ICMP_EQ; ;} break; case 27: -#line 1626 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1865 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { (yyval.IPred) = ICmpInst::ICMP_NE; ;} break; case 28: -#line 1627 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1866 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { (yyval.IPred) = ICmpInst::ICMP_SLT; ;} break; case 29: -#line 1627 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1866 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { (yyval.IPred) = ICmpInst::ICMP_SGT; ;} break; case 30: -#line 1628 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1867 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { (yyval.IPred) = ICmpInst::ICMP_SLE; ;} break; case 31: -#line 1628 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" +#line 1867 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y" { (yyval.IPred) = I |