//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ParameterAttributes.h"
+#include "llvm/ValueSymbolTable.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/MathExtras.h"
#include <algorithm>
#include <iostream>
+#include <map>
#include <list>
#include <utility>
namespace llvm {
-
-SignedType *SignedType::SByteTy = 0;
-SignedType *SignedType::SShortTy = 0;
-SignedType *SignedType::SIntTy = 0;
-SignedType *SignedType::SLongTy = 0;
-
-inline bool SignedType::classof(const Type *T) {
- if (T->getTypeID() != IntegerTyID)
- return false;
- return (T == SByteTy || T == SShortTy || T == SIntTy || T == SLongTy );
-}
-
-SignedType::SignedType(const IntegerType* ITy)
- : IntegerType(ITy->getBitWidth()), base_type(ITy)
-{
-}
-
-const SignedType *SignedType::get(const IntegerType* ITy) {
- if (ITy == Type::Int8Ty) {
- if (!SByteTy)
- SByteTy = new SignedType(IntegerType::get(8));
- return SByteTy;
- } else if (ITy == Type::Int16Ty) {
- if (!SShortTy)
- SShortTy = new SignedType(IntegerType::get(16));
- return SShortTy;
- } else if (ITy == Type::Int32Ty) {
- if (!SIntTy)
- SIntTy = new SignedType(IntegerType::get(32));
- return SIntTy;
- } else if (ITy == Type::Int64Ty) {
- if (!SLongTy)
- SLongTy = new SignedType(IntegerType::get(64));
- return SLongTy;
- } else
- assert(0 && "Invalid integer type for SignedType::get");
-}
-
-static inline Signedness getSign(const Type *&Ty) {
- if (const SignedType *STy = dyn_cast<SignedType>(Ty)) {
- Ty = STy->getBaseType();
- return Signed;
- } else if (isa<IntegerType>(Ty))
- return Unsigned;
- return Signless;
-}
-
-static const Type*
-resolveTypeImpl(const Type* Ty, std::vector<const Type*>& TyStack)
-{
- // Nothing to resolve if it isn't a derived type
- if (!Ty->isDerivedType())
- return Ty;
-
- // Prevent infinite recursion for recursive types
- for (std::vector<const Type*>::const_iterator I = TyStack.begin(),
- E = TyStack.end(); I != E; ++I)
- if (Ty == *I)
- return Ty;
-
- // Okay, haven't seen this derived type yet, push it on the stack.
- const Type* Result = Ty;
- TyStack.push_back(Ty);
-
- // Process the type
- switch (Ty->getTypeID()) {
- default: assert(0 && "Invalid derived type");
- case Type::IntegerTyID:
- break;
- case Type::FunctionTyID: {
- const FunctionType* FTy = cast<FunctionType>(Ty);
- const Type* RetTy = resolveTypeImpl(FTy->getReturnType(), TyStack);
- std::vector<const Type*> Types;
- FunctionType::ParamAttrsList Attrs;
- Attrs.push_back(FTy->getParamAttrs(0));
- for (unsigned i = 0; i < FTy->getNumParams(); ++i) {
- Types.push_back(resolveTypeImpl(FTy->getParamType(i), TyStack));
- Attrs.push_back(FTy->getParamAttrs(i+1));
- }
- Result = FunctionType::get(RetTy, Types, FTy->isVarArg(), Attrs);
- break;
- }
- case Type::StructTyID:
- case Type::PackedStructTyID: {
- const StructType *STy = cast<StructType>(Ty);
- std::vector<const Type*> FieldTypes;
- for (unsigned i = 0; i < STy->getNumElements(); ++i)
- FieldTypes.push_back(resolveTypeImpl(STy->getElementType(i), TyStack));
- Result = StructType::get(FieldTypes, STy->isPacked());
- break;
- }
- case Type::ArrayTyID: {
- const ArrayType *ATy = cast<ArrayType>(Ty);
- uint64_t NElems = ATy->getNumElements();
- const Type *ElemTy = resolveTypeImpl(ATy->getElementType(), TyStack);
- Result = ArrayType::get(ElemTy, NElems);
- break;
- }
- case Type::PointerTyID: {
- const PointerType *PTy = cast<PointerType>(Ty);
- const Type *ElemTy = resolveTypeImpl(PTy->getElementType(), TyStack);
- Result = PointerType::get(ElemTy);
- break;
- }
- case Type::PackedTyID: {
- const PackedType *PTy = cast<PackedType>(Ty);
- unsigned NElems = PTy->getNumElements();
- const Type *ElemTy = resolveTypeImpl(PTy->getElementType(), TyStack);
- Result = PackedType::get(ElemTy, NElems);
- break;
- }
- }
- // Done with it, pop it off.
- TyStack.pop_back();
- return Result;
-}
-
-static inline const Type* resolveType(const Type* Ty) {
- if (!Ty)
- return 0;
- if (const SignedType* STy = dyn_cast<SignedType>(Ty))
- return STy->getBaseType();
- std::vector<const Type*> TyStack;
- return resolveTypeImpl(Ty, TyStack);
-}
-
std::istream* LexInput;
static std::string CurFilename;
static bool NewVarArgs;
static BasicBlock *CurBB;
static GlobalVariable *CurGV;
-
-
+static unsigned lastCallingConv;
// This contains info used when building the body of a function. It is
// destroyed when the function is completed.
//
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
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;
Values.clear(); // Clear out function local definitions
Types.clear();
+ TypeSigns.clear();
+ NamedTypeSigns.clear();
+ NamedValueSigns.clear();
CurrentModule = 0;
}
std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
std::vector<BasicBlock*> NumberedBlocks;
RenameMapType RenameMap;
- std::set<Value*> SignedValues;
unsigned NextBBNum;
inline PerFunctionInfo() {
Values.clear(); // Clear out function local definitions
RenameMap.clear();
- SignedValues.clear();
CurrentFunction = 0;
isDeclare = false;
Linkage = GlobalValue::ExternalLinkage;
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
return List.size()-1;
}
-static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
+static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
switch (D.Type) {
case ValID::NumberVal: // Is it a numbered definition?
// Module constants occupy the lowest numbered slots...
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;
//
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() + "'");
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;
+}
// getExistingValue - Look up the value specified by the provided type and
// the provided ValID. If the value exists and has already been defined, return
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);
if (I != CurFun.RenameMap.end())
LookupName = I->second;
else
- LookupName = Name;
- SymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
- V = SymTab.lookup(Ty, LookupName);
+ LookupName = D.Name;
+ ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
+ V = SymTab.lookup(LookupName);
+ if (V && V->getType() != Ty)
+ V = 0;
}
if (!V) {
RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
if (I != CurModule.RenameMap.end())
LookupName = I->second;
else
- LookupName = Name;
- V = CurModule.CurrentModule->getValueSymbolTable().lookup(Ty, LookupName);
+ LookupName = D.Name;
+ V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
+ if (V && V->getType() != Ty)
+ V = 0;
}
- if (V == 0)
+ if (!V)
return 0;
D.destroy(); // Free old strdup'd memory...
return ConstantInt::get(Ty, D.UConstPool64);
case ValID::ConstFPVal: // Is it a floating point const pool reference?
- if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
+ if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
error("FP constant invalid for type");
- return ConstantFP::get(Ty, D.ConstPoolFP);
+ // Lexer has no type info, so builds all FP constants as double.
+ // Fix this here.
+ if (Ty==Type::FloatTy)
+ D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+ return ConstantFP::get(Ty, *D.ConstPoolFP);
case ValID::ConstNullVal: // Is it a null value?
if (!isa<PointerType>(Ty))
// If we reached here, we referenced either a symbol that we don't know about
// or an id number that hasn't been read yet. We may be referencing something
// forward, so just create an entry to be resolved later and get to it...
- assert(!isa<SignedType>(Ty) && "Can't create value with SignedType");
V = new Argument(Ty);
// Remember where this forward reference came from. FIXME, shouldn't we try
// to recycle these things??
CurModule.PlaceHolderInfo.insert(
- std::make_pair(V, std::make_pair(ID, Upgradelineno-1)));
+ std::make_pair(V, std::make_pair(ID, Upgradelineno)));
if (inFunctionScope())
InsertValue(V, CurFun.LateResolveValues);
return V;
}
+/// @brief This just makes any name given to it unique, up to MAX_UINT times.
+static std::string makeNameUnique(const std::string& Name) {
+ static unsigned UniqueNameCounter = 1;
+ std::string Result(Name);
+ Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
+ return Result;
+}
+
/// getBBVal - This is used for two purposes:
/// * If isDefinition is true, a new basic block with the specified ID is being
/// defined.
break;
case ValID::NameVal: // Is it a named definition?
Name = ID.Name;
- if (Value *N = CurFun.CurrentFunction->
- getValueSymbolTable().lookup(Type::LabelTy, Name)) {
- if (N->getType() != Type::LabelTy)
- error("Name '" + Name + "' does not refer to a BasicBlock");
- BB = cast<BasicBlock>(N);
+ 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 = makeRenameMapKey(ID.Name, N->getType(), ID.S);
+ N->setName(makeNameUnique(N->getName()));
+ CurModule.RenameMap[Key] = N->getName();
+ BB = 0;
+ } else {
+ BB = cast<BasicBlock>(N);
+ }
}
break;
}
static void
ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
std::map<const Type*,ValueList> *FutureLateResolvers) {
+
// Loop over LateResolveDefs fixing up stuff that couldn't be resolved
for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
E = LateResolvers.end(); LRI != E; ++LRI) {
+ const Type* Ty = LRI->first;
ValueList &List = LRI->second;
while (!List.empty()) {
Value *V = List.back();
ValID &DID = PHI->second.first;
- Value *TheRealValue = getExistingValue(LRI->first, DID);
+ Value *TheRealValue = getExistingValue(Ty, DID);
if (TheRealValue) {
V->replaceAllUsesWith(TheRealValue);
delete V;
InsertValue(V, *FutureLateResolvers);
} else {
if (DID.Type == ValID::NameVal) {
- error("Reference to an invalid definition: '" +DID.getName()+
+ error("Reference to an invalid definition: '" + DID.getName() +
"' of type '" + V->getType()->getDescription() + "'",
PHI->second.second);
- return;
+ return;
} else {
error("Reference to an invalid definition: #" +
itostr(DID.Num) + " of type '" +
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);
+
+ if (Name)
+ 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);
}
}
-static std::string makeNameUnique(const std::string& Name) {
- static unsigned UniqueNameCounter = 1;
- std::string Result(Name);
- Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
- return Result;
+/// This is the implementation portion of TypeHasInteger. It traverses the
+/// type given, avoiding recursive types, and returns true as soon as it finds
+/// an integer type. If no integer type is found, it returns false.
+static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
+ // Handle some easy cases
+ if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
+ return false;
+ if (Ty->isInteger())
+ return true;
+ if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
+ return STy->getElementType()->isInteger();
+
+ // Avoid type structure recursion
+ for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
+ I != E; ++I)
+ if (Ty == *I)
+ return false;
+
+ // Push us on the type stack
+ Stack.push_back(Ty);
+
+ if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
+ if (TypeHasIntegerI(FTy->getReturnType(), Stack))
+ return true;
+ FunctionType::param_iterator I = FTy->param_begin();
+ FunctionType::param_iterator E = FTy->param_end();
+ for (; I != E; ++I)
+ if (TypeHasIntegerI(*I, Stack))
+ return true;
+ return false;
+ } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
+ StructType::element_iterator I = STy->element_begin();
+ StructType::element_iterator E = STy->element_end();
+ for (; I != E; ++I) {
+ if (TypeHasIntegerI(*I, Stack))
+ return true;
+ }
+ return false;
+ }
+ // There shouldn't be anything else, but its definitely not integer
+ assert(0 && "What type is this?");
+ return false;
+}
+
+/// This is the interface to TypeHasIntegerI. It just provides the type stack,
+/// to avoid recursion, and then calls TypeHasIntegerI.
+static inline bool TypeHasInteger(const Type *Ty) {
+ std::vector<const Type*> TyStack;
+ return TypeHasIntegerI(Ty, TyStack);
}
// setValueName - Set the specified value to the name given. The name may be
// 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;
}
- assert(!isa<SignedType>(V->getType()) && "Shouldn't have SignedType Value");
assert(inFunctionScope() && "Must be in function scope");
// Search the function's symbol table for an existing value of this name
- Value* Existing = 0;
- SymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
- SymbolTable::plane_const_iterator PI = ST.plane_begin(), PE =ST.plane_end();
- for ( ; PI != PE; ++PI) {
- SymbolTable::value_const_iterator VI = PI->second.find(Name);
- if (VI != PI->second.end()) {
- Existing = VI->second;
- break;
- }
- }
+ ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
+ Value* Existing = ST.lookup(Name);
if (Existing) {
- if (Existing->getType() == V->getType()) {
- // The type of the Existing value and the new one are the same. This
- // is probably a type plane collapsing error. If the types involved
- // are both integer, just rename it. Otherwise it
- // is a redefinition error.
- if (!Existing->getType()->isInteger()) {
- error("Redefinition of value named '" + Name + "' in the '" +
- V->getType()->getDescription() + "' type plane");
- return;
- }
+ // 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.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.V->getType()->getDescription() + "'");
+ return;
}
// In LLVM 2.0 we don't allow names to be re-used for any values in a
// function, regardless of Type. Previously re-use of names was okay as
// 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);
}
}
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");
- const PointerType *PTy = PointerType::get(Ty);
+ const PointerType *PTy = PointerType::getUnqual(Ty);
std::string Name;
if (NameStr) {
} 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
// of this global in the module and emit warnings if there are conflicts.
if (!Name.empty()) {
// The global has a name. See if there's an existing one of the same name.
- if (CurModule.CurrentModule->getNamedGlobal(Name)) {
- // We found an existing global ov the same name. This isn't allowed
+ if (CurModule.CurrentModule->getNamedGlobal(Name) ||
+ CurModule.CurrentModule->getFunction(Name)) {
+ // We found an existing global of the same name. This isn't allowed
// in LLVM 2.0. Consequently, we must alter the name of the global so it
// can at least compile. This can happen because of type planes
// 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
}
// Put the renaming in the global rename map
- RenameMapKey Key = std::make_pair(Name,PointerType::get(Ty));
+ RenameMapKey Key =
+ makeRenameMapKey(Name, PointerType::getUnqual(Ty), ID.S);
CurModule.RenameMap[Key] = NewName;
// Rename it
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;
}
// 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);
// 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;
}
// 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;
OpaqueType *UpRefTy;
UpRefRecord(unsigned NL, OpaqueType *URTy)
- : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) {}
+ : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
};
}
/// 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;
// 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;
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");
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;
+ }
+}
+
+#ifndef NDEBUG
+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 << ".";
+}
+#endif
+
static inline Instruction::TermOps
getTermOp(TermOps op) {
switch (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 :
// This is an obsolete instruction so we must upgrade it based on the
// types of its operands.
bool isFP = Ty->isFloatingPoint();
- if (const PackedType* PTy = dyn_cast<PackedType>(Ty))
- // If its a packed type we want to use the element type
+ if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
+ // If its a vector type we want to use the element type
isFP = PTy->getElementType()->isFloatingPoint();
if (isFP)
return Instruction::FDiv;
- else if (Sign == Signed)
+ else if (Sign.isSigned())
return Instruction::SDiv;
return Instruction::UDiv;
}
// This is an obsolete instruction so we must upgrade it based on the
// types of its operands.
bool isFP = Ty->isFloatingPoint();
- if (const PackedType* PTy = dyn_cast<PackedType>(Ty))
- // If its a packed type we want to use the element type
+ if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
+ // If its a vector type we want to use the element type
isFP = PTy->getElementType()->isFloatingPoint();
// Select correct opcode
if (isFP)
return Instruction::FRem;
- else if (Sign == Signed)
+ else if (Sign.isSigned())
return Instruction::SRem;
return Instruction::URem;
}
case URemOp : return Instruction::URem;
case SRemOp : return Instruction::SRem;
case FRemOp : return Instruction::FRem;
+ case LShrOp : return Instruction::LShr;
+ case AShrOp : return Instruction::AShr;
+ case ShlOp : return Instruction::Shl;
+ case ShrOp :
+ if (Sign.isSigned())
+ return Instruction::AShr;
+ return Instruction::LShr;
case AndOp : return Instruction::And;
case OrOp : return Instruction::Or;
case XorOp : return Instruction::Xor;
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");
}
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;
case CallOp : return Instruction::Call;
- case ShlOp : return Instruction::Shl;
- case ShrOp :
- if (Sign == Signed)
- return Instruction::AShr;
- return Instruction::LShr;
case SelectOp : return Instruction::Select;
case UserOp1 : return Instruction::UserOp1;
case UserOp2 : return Instruction::UserOp2;
case ShuffleVectorOp : return Instruction::ShuffleVector;
case ICmpOp : return Instruction::ICmp;
case FCmpOp : return Instruction::FCmp;
- case LShrOp : return Instruction::LShr;
- case AShrOp : return Instruction::AShr;
};
}
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) {
}
// 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");
std::vector<Value*>& Args) {
std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
- if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
- if (Args.size() != 2)
- error("Invalid prototype for " + Name + " prototype");
- return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
- } else {
- static unsigned upgradeCount = 1;
- const Type* PtrTy = PointerType::get(Type::Int8Ty);
- std::vector<const Type*> Params;
- if (Name == "llvm.va_start" || Name == "llvm.va_end") {
- if (Args.size() != 1)
- error("Invalid prototype for " + Name + " prototype");
- Params.push_back(PtrTy);
- const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
- const PointerType *PFTy = PointerType::get(FTy);
- Value* Func = getVal(PFTy, ID);
- std::string InstName("va_upgrade");
- InstName += llvm::utostr(upgradeCount++);
- Args[0] = new BitCastInst(Args[0], PtrTy, InstName, CurBB);
- return new CallInst(Func, Args);
- } else if (Name == "llvm.va_copy") {
- if (Args.size() != 2)
- error("Invalid prototype for " + Name + " prototype");
- Params.push_back(PtrTy);
- Params.push_back(PtrTy);
- const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
- const PointerType *PFTy = PointerType::get(FTy);
- Value* Func = getVal(PFTy, ID);
- std::string InstName0("va_upgrade");
- InstName0 += llvm::utostr(upgradeCount++);
- std::string InstName1("va_upgrade");
- InstName1 += llvm::utostr(upgradeCount++);
- Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
- Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
- return new CallInst(Func, Args);
+ if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' ||
+ Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
+ return 0;
+
+ switch (Name[5]) {
+ case 'i':
+ if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
+ if (Args.size() != 2)
+ error("Invalid prototype for " + Name);
+ return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
+ }
+ break;
+
+ case 'v' : {
+ const Type* PtrTy = PointerType::getUnqual(Type::Int8Ty);
+ std::vector<const Type*> Params;
+ if (Name == "llvm.va_start" || Name == "llvm.va_end") {
+ if (Args.size() != 1)
+ error("Invalid prototype for " + Name + " prototype");
+ Params.push_back(PtrTy);
+ const FunctionType *FTy =
+ FunctionType::get(Type::VoidTy, Params, false);
+ const PointerType *PFTy = PointerType::getUnqual(FTy);
+ Value* Func = getVal(PFTy, ID);
+ Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
+ return new CallInst(Func, Args.begin(), Args.end());
+ } else if (Name == "llvm.va_copy") {
+ if (Args.size() != 2)
+ error("Invalid prototype for " + Name + " prototype");
+ Params.push_back(PtrTy);
+ Params.push_back(PtrTy);
+ const FunctionType *FTy =
+ FunctionType::get(Type::VoidTy, Params, false);
+ const PointerType *PFTy = PointerType::getUnqual(FTy);
+ Value* Func = getVal(PFTy, ID);
+ std::string InstName0(makeNameUnique("va0"));
+ std::string InstName1(makeNameUnique("va1"));
+ Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
+ Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
+ return new CallInst(Func, Args.begin(), Args.end());
+ }
}
}
return 0;
}
-const Type* upgradeGEPIndices(const Type* PTy,
- std::vector<ValueInfo> *Indices,
- std::vector<Value*> &VIndices,
- std::vector<Constant*> *CIndices = 0) {
- // Traverse the indices with a gep_type_iterator so we can build the list
- // of constant and value indices for use later. Also perform upgrades
- VIndices.clear();
- if (CIndices) CIndices->clear();
- for (unsigned i = 0, e = Indices->size(); i != e; ++i)
- VIndices.push_back((*Indices)[i].V);
- generic_gep_type_iterator<std::vector<Value*>::iterator>
- GTI = gep_type_begin(PTy, VIndices.begin(), VIndices.end()),
- GTE = gep_type_end(PTy, VIndices.begin(), VIndices.end());
- for (unsigned i = 0, e = Indices->size(); i != e && GTI != GTE; ++i, ++GTI) {
- Value *Index = VIndices[i];
- if (CIndices && !isa<Constant>(Index))
- error("Indices to constant getelementptr must be constants");
- // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
- // struct indices to i32 struct indices with ZExt for compatibility.
- else if (isa<StructType>(*GTI)) { // Only change struct indices
- if (ConstantInt *CUI = dyn_cast<ConstantInt>(Index))
- if (CUI->getType()->getBitWidth() == 8)
- Index =
- ConstantExpr::getCast(Instruction::ZExt, CUI, Type::Int32Ty);
+const Type* upgradeGEPCEIndices(const Type* PTy,
+ std::vector<ValueInfo> *Indices,
+ std::vector<Constant*> &Result) {
+ const Type *Ty = PTy;
+ Result.clear();
+ for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
+ Constant *Index = cast<Constant>((*Indices)[i].V);
+
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
+ // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
+ // struct indices to i32 struct indices with ZExt for compatibility.
+ if (CI->getBitWidth() < 32)
+ Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
+ }
+
+ if (isa<SequentialType>(Ty)) {
+ // Make sure that unsigned SequentialType indices are zext'd to
+ // 64-bits if they were smaller than that because LLVM 2.0 will sext
+ // 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.isUnsigned()) {
+ Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
+ }
+ }
+ }
+ Result.push_back(Index);
+ Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
+ Result.end(),true);
+ if (!Ty)
+ error("Index list invalid for constant getelementptr");
+ }
+ return Ty;
+}
+
+const Type* upgradeGEPInstIndices(const Type* PTy,
+ std::vector<ValueInfo> *Indices,
+ std::vector<Value*> &Result) {
+ const Type *Ty = PTy;
+ Result.clear();
+ for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
+ Value *Index = (*Indices)[i].V;
+
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
+ // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
+ // struct indices to i32 struct indices with ZExt for compatibility.
+ if (CI->getBitWidth() < 32)
+ Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
+ }
+
+
+ if (isa<StructType>(Ty)) { // Only change struct indices
+ if (!isa<Constant>(Index)) {
+ error("Invalid non-constant structure index");
+ return 0;
+ }
} else {
// Make sure that unsigned SequentialType indices are zext'd to
// 64-bits if they were smaller than that because LLVM 2.0 will sext
// 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 (CIndices)
+ if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
+ if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
+ if (isa<Constant>(Index))
Index = ConstantExpr::getCast(Instruction::ZExt,
cast<Constant>(Index), Type::Int64Ty);
else
Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
- "gep_upgrade", CurBB);
+ makeNameUnique("gep"), CurBB);
+ }
+ }
}
- // Add to the CIndices list, if requested.
- if (CIndices)
- CIndices->push_back(cast<Constant>(Index));
+ Result.push_back(Index);
+ Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
+ Result.end(),true);
+ if (!Ty)
+ error("Index list invalid for constant getelementptr");
}
+ return Ty;
+}
- const Type *IdxTy =
- GetElementPtrInst::getIndexedType(PTy, VIndices, true);
- if (!IdxTy)
- error("Index list invalid for constant getelementptr");
- return IdxTy;
+unsigned upgradeCallingConv(unsigned CC) {
+ switch (CC) {
+ case OldCallingConv::C : return CallingConv::C;
+ case OldCallingConv::CSRet : return CallingConv::C;
+ case OldCallingConv::Fast : return CallingConv::Fast;
+ case OldCallingConv::Cold : return CallingConv::Cold;
+ case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
+ case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
+ default:
+ return CC;
+ }
}
Module* UpgradeAssembly(const std::string &infile, std::istream& in,
//Not all functions use vaarg, so make a second check for ObsoleteVarArgs
{
Function* F;
- if ((F = Result->getNamedFunction("llvm.va_start"))
+ if ((F = Result->getFunction("llvm.va_start"))
&& F->getFunctionType()->getNumParams() == 0)
ObsoleteVarArgs = true;
- if((F = Result->getNamedFunction("llvm.va_copy"))
+ if((F = Result->getFunction("llvm.va_copy"))
&& F->getFunctionType()->getNumParams() == 1)
ObsoleteVarArgs = true;
}
}
if(ObsoleteVarArgs) {
- if(Function* F = Result->getNamedFunction("llvm.va_start")) {
+ if(Function* F = Result->getFunction("llvm.va_start")) {
if (F->arg_size() != 0) {
error("Obsolete va_start takes 0 argument");
return 0;
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getReturnType();
- const Type* ArgTyPtr = PointerType::get(ArgTy);
+ const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Function* NF = cast<Function>(Result->getOrInsertFunction(
"llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_end")) {
+ if(Function* F = Result->getFunction("llvm.va_end")) {
if(F->arg_size() != 1) {
error("Obsolete va_end takes 1 argument");
return 0;
//vaend bar
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getParamType(0);
- const Type* ArgTyPtr = PointerType::get(ArgTy);
+ const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Function* NF = cast<Function>(Result->getOrInsertFunction(
"llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
+ if(Function* F = Result->getFunction("llvm.va_copy")) {
if(F->arg_size() != 1) {
error("Obsolete va_copy takes 1 argument");
return 0;
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getReturnType();
- const Type* ArgTyPtr = PointerType::get(ArgTy);
+ const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Function* NF = cast<Function>(Result->getOrInsertFunction(
"llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
while (!F->use_empty()) {
CallInst* CI = cast<CallInst>(F->use_back());
- AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
- AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
- new StoreInst(CI->getOperand(1), b, CI);
- new CallInst(NF, a, b, "", CI);
- Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
+ Value *Args[2] = {
+ new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI),
+ new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI)
+ };
+ new StoreInst(CI->getOperand(1), Args[1], CI);
+ new CallInst(NF, Args, Args + 2, "", CI);
+ Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
CI->replaceAllUsesWith(foo);
CI->getParent()->getInstList().erase(CI);
}
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;
uint64_t UInt64Val;
int SIntVal;
unsigned UIntVal;
- double FPVal;
+ llvm::APFloat *FPVal;
bool BoolVal;
char *StrVal; // This memory is strdup'd!
%type <BoolVal> OptVolatile // 'volatile' or not
%type <BoolVal> OptTailCall // TAIL CALL or plain CALL.
%type <BoolVal> OptSideEffect // 'sideeffect' or not.
-%type <Linkage> OptLinkage
+%type <Linkage> OptLinkage FnDeclareLinkage
%type <Endianness> BigOrLittle
// ValueRef - Unresolved reference to a definition or BB
%type <ValIDVal> ValueRef ConstValueRef SymbolicValueRef
%type <ValueVal> ResolvedVal // <type> <valref> pair
+
// Tokens and types for handling constant integer values
//
// ESINT64VAL - A negative number within long long range
// Binary Operators
%type <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories
+%type <BinaryOpVal> ShiftOps
%token <BinaryOpVal> ADD SUB MUL DIV UDIV SDIV FDIV REM UREM SREM FREM
-%token <BinaryOpVal> AND OR XOR
+%token <BinaryOpVal> AND OR XOR SHL SHR ASHR LSHR
%token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
%token <OtherOpVal> ICMP FCMP
%token <MemOpVal> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
// Other Operators
-%type <OtherOpVal> ShiftOps
-%token <OtherOpVal> PHI_TOK SELECT SHL SHR ASHR LSHR VAARG
+%token <OtherOpVal> PHI_TOK SELECT VAARG
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
%token VAARG_old VANEXT_old //OBSOLETE
+// Support for ICmp/FCmp Predicates, which is 1.9++ but not 2.0
%type <IPred> IPredicates
%type <FPred> FPredicates
%token EQ NE SLT SGT SLE SGE ULT UGT ULE UGE
// Handle constant integer size restriction and conversion...
//
INTVAL
- : SINTVAL;
+ : SINTVAL
| UINTVAL {
if ($1 > (uint32_t)INT32_MAX) // Outside of my range!
error("Value too large for type");
;
EINT64VAL
- : ESINT64VAL; // These have same type and can't cause problems...
+ : ESINT64VAL // These have same type and can't cause problems...
| EUINT64VAL {
if ($1 > (uint64_t)INT64_MAX) // Outside of my range!
error("Value too large for type");
};
OptLinkage
- : INTERNAL { $$ = GlobalValue::InternalLinkage; }
+ : INTERNAL { $$ = GlobalValue::InternalLinkage; }
| LINKONCE { $$ = GlobalValue::LinkOnceLinkage; }
| WEAK { $$ = GlobalValue::WeakLinkage; }
| APPENDING { $$ = GlobalValue::AppendingLinkage; }
| DLLIMPORT { $$ = GlobalValue::DLLImportLinkage; }
| DLLEXPORT { $$ = GlobalValue::DLLExportLinkage; }
- | EXTERN_WEAK { $$ = GlobalValue::ExternalWeakLinkage; }
+ | EXTERN_WEAK { $$ = GlobalValue::ExternalWeakLinkage; }
| /*empty*/ { $$ = GlobalValue::ExternalLinkage; }
;
OptCallingConv
- : /*empty*/ { $$ = CallingConv::C; }
- | CCC_TOK { $$ = CallingConv::C; }
- | CSRETCC_TOK { $$ = CallingConv::CSRet; }
- | FASTCC_TOK { $$ = CallingConv::Fast; }
- | COLDCC_TOK { $$ = CallingConv::Cold; }
- | X86_STDCALLCC_TOK { $$ = CallingConv::X86_StdCall; }
- | X86_FASTCALLCC_TOK { $$ = CallingConv::X86_FastCall; }
+ : /*empty*/ { $$ = lastCallingConv = OldCallingConv::C; }
+ | CCC_TOK { $$ = lastCallingConv = OldCallingConv::C; }
+ | CSRETCC_TOK { $$ = lastCallingConv = OldCallingConv::CSRet; }
+ | FASTCC_TOK { $$ = lastCallingConv = OldCallingConv::Fast; }
+ | COLDCC_TOK { $$ = lastCallingConv = OldCallingConv::Cold; }
+ | X86_STDCALLCC_TOK { $$ = lastCallingConv = OldCallingConv::X86_StdCall; }
+ | X86_FASTCALLCC_TOK { $$ = lastCallingConv = OldCallingConv::X86_FastCall; }
| CC_TOK EUINT64VAL {
if ((unsigned)$2 != $2)
error("Calling conv too large");
- $$ = $2;
+ $$ = lastCallingConv = $2;
}
;
TypesV
: Types
| VOID {
- $$.T = new PATypeHolder($1.T);
- $$.S = Signless;
+ $$.PAT = new PATypeHolder($1.T);
+ $$.S.makeSignless();
}
;
UpRTypesV
: UpRTypes
| VOID {
- $$.T = new PATypeHolder($1.T);
- $$.S = Signless;
+ $$.PAT = new PATypeHolder($1.T);
+ $$.S.makeSignless();
}
;
Types
: UpRTypes {
if (!UpRefs.empty())
- error("Invalid upreference in type: " + (*$1.T)->getDescription());
+ error("Invalid upreference in type: " + (*$1.PAT)->getDescription());
$$ = $1;
}
;
// Derived types are added later...
UpRTypes
: PrimType {
- $$.T = new PATypeHolder($1.T);
- $$.S = $1.S;
+ $$.PAT = new PATypeHolder($1.T);
+ $$.S.copy($1.S);
}
| OPAQUE {
- $$.T = new PATypeHolder(OpaqueType::get());
- $$.S = Signless;
+ $$.PAT = new PATypeHolder(OpaqueType::get());
+ $$.S.makeSignless();
}
| SymbolicValueRef { // Named types are also simple types...
- const Type* tmp = getTypeVal($1);
- $$.T = new PATypeHolder(tmp);
- $$.S = Signless; // FIXME: what if its signed?
+ $$.S.copy(getTypeSign($1));
+ const Type* tmp = getType($1);
+ $$.PAT = new PATypeHolder(tmp);
}
| '\\' EUINT64VAL { // Type UpReference
if ($2 > (uint64_t)~0U)
error("Value out of range");
OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
UpRefs.push_back(UpRefRecord((unsigned)$2, OT)); // Add to vector...
- $$.T = new PATypeHolder(OT);
- $$.S = Signless;
+ $$.PAT = new PATypeHolder(OT);
+ $$.S.makeSignless();
UR_OUT("New Upreference!\n");
}
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
+ $$.S.makeComposite($1.S);
std::vector<const Type*> Params;
for (std::list<llvm::PATypeInfo>::iterator I = $3->begin(),
E = $3->end(); I != E; ++I) {
- Params.push_back(I->T->get());
- delete I->T;
+ Params.push_back(I->PAT->get());
+ $$.S.add(I->S);
}
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
if (isVarArg) Params.pop_back();
- $$.T = new PATypeHolder(HandleUpRefs(
- FunctionType::get($1.T->get(),Params,isVarArg)));
- $$.S = $1.S;
- delete $1.T; // Delete the return type handle
+ const ParamAttrsList *PAL = 0;
+ if (lastCallingConv == OldCallingConv::CSRet) {
+ ParamAttrsVector Attrs;
+ ParamAttrsWithIndex PAWI;
+ PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
+ Attrs.push_back(PAWI);
+ PAL = ParamAttrsList::get(Attrs);
+ }
+
+ const FunctionType *FTy =
+ FunctionType::get($1.PAT->get(), Params, isVarArg);
+
+ $$.PAT = new PATypeHolder( HandleUpRefs(FTy, $$.S) );
+ delete $1.PAT; // Delete the return type handle
delete $3; // Delete the argument list
}
| '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
- $$.T = new PATypeHolder(HandleUpRefs(ArrayType::get($4.T->get(),
- (unsigned)$2)));
- $$.S = $4.S;
- delete $4.T;
- }
- | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
- const llvm::Type* ElemTy = $4.T->get();
- if ((unsigned)$2 != $2)
- error("Unsigned result not equal to signed result");
- if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
- error("Elements of a PackedType must be integer or floating point");
- if (!isPowerOf2_32($2))
- error("PackedType length should be a power of 2");
- $$.T = new PATypeHolder(HandleUpRefs(PackedType::get(ElemTy,
- (unsigned)$2)));
- $$.S = $4.S;
- delete $4.T;
+ $$.S.makeComposite($4.S);
+ $$.PAT = new PATypeHolder(HandleUpRefs(ArrayType::get($4.PAT->get(),
+ (unsigned)$2), $$.S));
+ delete $4.PAT;
+ }
+ | '<' EUINT64VAL 'x' UpRTypes '>' { // Vector type?
+ const llvm::Type* ElemTy = $4.PAT->get();
+ if ((unsigned)$2 != $2)
+ error("Unsigned result not equal to signed result");
+ if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
+ error("Elements of a VectorType must be integer or floating point");
+ if (!isPowerOf2_32($2))
+ error("VectorType length should be a power of 2");
+ $$.S.makeComposite($4.S);
+ $$.PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
+ (unsigned)$2), $$.S));
+ delete $4.PAT;
}
| '{' TypeListI '}' { // Structure type?
std::vector<const Type*> Elements;
+ $$.S.makeComposite();
for (std::list<llvm::PATypeInfo>::iterator I = $2->begin(),
- E = $2->end(); I != E; ++I)
- Elements.push_back(I->T->get());
- $$.T = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
- $$.S = Signless;
+ E = $2->end(); I != E; ++I) {
+ Elements.push_back(I->PAT->get());
+ $$.S.add(I->S);
+ }
+ $$.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), $$.S));
delete $2;
}
| '{' '}' { // Empty structure type?
- $$.T = new PATypeHolder(StructType::get(std::vector<const Type*>()));
- $$.S = Signless;
+ $$.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
+ $$.S.makeComposite();
}
| '<' '{' TypeListI '}' '>' { // Packed Structure type?
+ $$.S.makeComposite();
std::vector<const Type*> Elements;
for (std::list<llvm::PATypeInfo>::iterator I = $3->begin(),
E = $3->end(); I != E; ++I) {
- Elements.push_back(I->T->get());
- delete I->T;
+ Elements.push_back(I->PAT->get());
+ $$.S.add(I->S);
+ delete I->PAT;
}
- $$.T = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true)));
- $$.S = Signless;
+ $$.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
+ $$.S));
delete $3;
}
| '<' '{' '}' '>' { // Empty packed structure type?
- $$.T = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
- $$.S = Signless;
+ $$.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
+ $$.S.makeComposite();
}
| UpRTypes '*' { // Pointer type?
- if ($1.T->get() == Type::LabelTy)
+ if ($1.PAT->get() == Type::LabelTy)
error("Cannot form a pointer to a basic block");
- $$.T = new PATypeHolder(HandleUpRefs(PointerType::get($1.T->get())));
- $$.S = $1.S;
- delete $1.T;
+ $$.S.makeComposite($1.S);
+ $$.PAT = new
+ PATypeHolder(HandleUpRefs(PointerType::getUnqual($1.PAT->get()),
+ $$.S));
+ delete $1.PAT;
}
;
: TypeListI
| TypeListI ',' DOTDOTDOT {
PATypeInfo VoidTI;
- VoidTI.T = new PATypeHolder(Type::VoidTy);
- VoidTI.S = Signless;
+ VoidTI.PAT = new PATypeHolder(Type::VoidTy);
+ VoidTI.S.makeSignless();
($$=$1)->push_back(VoidTI);
}
| DOTDOTDOT {
$$ = new std::list<PATypeInfo>();
PATypeInfo VoidTI;
- VoidTI.T = new PATypeHolder(Type::VoidTy);
- VoidTI.S = Signless;
+ VoidTI.PAT = new PATypeHolder(Type::VoidTy);
+ VoidTI.S.makeSignless();
$$->push_back(VoidTI);
}
| /*empty*/ {
//
ConstVal
: Types '[' ConstVector ']' { // Nonempty unsized arr
- const ArrayType *ATy = dyn_cast<ArrayType>($1.T->get());
+ const ArrayType *ATy = dyn_cast<ArrayType>($1.PAT->get());
if (ATy == 0)
error("Cannot make array constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
const Type *ETy = ATy->getElementType();
int NumElements = ATy->getNumElements();
Elems.push_back(C);
}
$$.C = ConstantArray::get(ATy, Elems);
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
delete $3;
}
| Types '[' ']' {
- const ArrayType *ATy = dyn_cast<ArrayType>($1.T->get());
+ const ArrayType *ATy = dyn_cast<ArrayType>($1.PAT->get());
if (ATy == 0)
error("Cannot make array constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
int NumElements = ATy->getNumElements();
if (NumElements != -1 && NumElements != 0)
error("Type mismatch: constant sized array initialized with 0"
" arguments, but has size of " + itostr(NumElements) +"");
$$.C = ConstantArray::get(ATy, std::vector<Constant*>());
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| Types 'c' STRINGCONSTANT {
- const ArrayType *ATy = dyn_cast<ArrayType>($1.T->get());
+ const ArrayType *ATy = dyn_cast<ArrayType>($1.PAT->get());
if (ATy == 0)
error("Cannot make array constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
int NumElements = ATy->getNumElements();
const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
Vals.push_back(ConstantInt::get(ETy, *C));
free($3);
$$.C = ConstantArray::get(ATy, Vals);
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| Types '<' ConstVector '>' { // Nonempty unsized arr
- const PackedType *PTy = dyn_cast<PackedType>($1.T->get());
+ const VectorType *PTy = dyn_cast<VectorType>($1.PAT->get());
if (PTy == 0)
error("Cannot make packed constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
const Type *ETy = PTy->getElementType();
int NumElements = PTy->getNumElements();
// Verify that we have the correct size...
ValTy->getDescription() + "'");
Elems.push_back(C);
}
- $$.C = ConstantPacked::get(PTy, Elems);
- $$.S = $1.S;
- delete $1.T;
+ $$.C = ConstantVector::get(PTy, Elems);
+ $$.S.copy($1.S);
+ delete $1.PAT;
delete $3;
}
| Types '{' ConstVector '}' {
- const StructType *STy = dyn_cast<StructType>($1.T->get());
+ const StructType *STy = dyn_cast<StructType>($1.PAT->get());
if (STy == 0)
error("Cannot make struct constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
if ($3->size() != STy->getNumContainedTypes())
error("Illegal number of initializers for structure type");
Fields.push_back(C);
}
$$.C = ConstantStruct::get(STy, Fields);
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
delete $3;
}
| Types '{' '}' {
- const StructType *STy = dyn_cast<StructType>($1.T->get());
+ const StructType *STy = dyn_cast<StructType>($1.PAT->get());
if (STy == 0)
error("Cannot make struct constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
if (STy->getNumContainedTypes() != 0)
error("Illegal number of initializers for structure type");
$$.C = ConstantStruct::get(STy, std::vector<Constant*>());
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| Types '<' '{' ConstVector '}' '>' {
- const StructType *STy = dyn_cast<StructType>($1.T->get());
+ const StructType *STy = dyn_cast<StructType>($1.PAT->get());
if (STy == 0)
error("Cannot make packed struct constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
if ($4->size() != STy->getNumContainedTypes())
error("Illegal number of initializers for packed structure type");
Fields.push_back(C);
}
$$.C = ConstantStruct::get(STy, Fields);
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
delete $4;
}
| Types '<' '{' '}' '>' {
- const StructType *STy = dyn_cast<StructType>($1.T->get());
+ const StructType *STy = dyn_cast<StructType>($1.PAT->get());
if (STy == 0)
error("Cannot make packed struct constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
if (STy->getNumContainedTypes() != 0)
error("Illegal number of initializers for packed structure type");
$$.C = ConstantStruct::get(STy, std::vector<Constant*>());
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| Types NULL_TOK {
- const PointerType *PTy = dyn_cast<PointerType>($1.T->get());
+ const PointerType *PTy = dyn_cast<PointerType>($1.PAT->get());
if (PTy == 0)
error("Cannot make null pointer constant with type: '" +
- $1.T->get()->getDescription() + "'");
+ $1.PAT->get()->getDescription() + "'");
$$.C = ConstantPointerNull::get(PTy);
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| Types UNDEF {
- $$.C = UndefValue::get($1.T->get());
- $$.S = $1.S;
- delete $1.T;
+ $$.C = UndefValue::get($1.PAT->get());
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| Types SymbolicValueRef {
- const PointerType *Ty = dyn_cast<PointerType>($1.T->get());
+ const PointerType *Ty = dyn_cast<PointerType>($1.PAT->get());
if (Ty == 0)
error("Global const reference must be a pointer type, not" +
- $1.T->get()->getDescription());
+ $1.PAT->get()->getDescription());
// ConstExprs can exist in the body of a function, thus creating
// GlobalValues whenever they refer to a variable. Because we are in
//
Function *SavedCurFn = CurFun.CurrentFunction;
CurFun.CurrentFunction = 0;
+ $2.S.copy($1.S);
Value *V = getExistingValue(Ty, $2);
CurFun.CurrentFunction = SavedCurFn;
}
}
$$.C = cast<GlobalValue>(V);
- $$.S = $1.S;
- delete $1.T; // Free the type handle
+ $$.S.copy($1.S);
+ delete $1.PAT; // Free the type handle
}
| Types ConstExpr {
- if ($1.T->get() != $2.C->getType())
+ if ($1.PAT->get() != $2.C->getType())
error("Mismatched types for constant expression");
$$ = $2;
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| Types ZEROINITIALIZER {
- const Type *Ty = $1.T->get();
+ const Type *Ty = $1.PAT->get();
if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
error("Cannot create a null initialized value of this type");
$$.C = Constant::getNullValue(Ty);
- $$.S = $1.S;
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
| SIntType EINT64VAL { // integral constants
const Type *Ty = $1.T;
if (!ConstantInt::isValueValidForType(Ty, $2))
error("Constant value doesn't fit in type");
$$.C = ConstantInt::get(Ty, $2);
- $$.S = Signed;
+ $$.S.makeSigned();
}
| UIntType EUINT64VAL { // integral constants
const Type *Ty = $1.T;
if (!ConstantInt::isValueValidForType(Ty, $2))
error("Constant value doesn't fit in type");
$$.C = ConstantInt::get(Ty, $2);
- $$.S = Unsigned;
+ $$.S.makeUnsigned();
}
| BOOL TRUETOK { // Boolean constants
$$.C = ConstantInt::get(Type::Int1Ty, true);
- $$.S = Unsigned;
+ $$.S.makeUnsigned();
}
| BOOL FALSETOK { // Boolean constants
$$.C = ConstantInt::get(Type::Int1Ty, false);
- $$.S = Unsigned;
+ $$.S.makeUnsigned();
}
| FPType FPVAL { // Float & Double constants
- if (!ConstantFP::isValueValidForType($1.T, $2))
+ if (!ConstantFP::isValueValidForType($1.T, *$2))
error("Floating point constant invalid for type");
- $$.C = ConstantFP::get($1.T, $2);
- $$.S = Signless;
+ // Lexer has no type info, so builds all FP constants as double.
+ // Fix this here.
+ if ($1.T==Type::FloatTy)
+ $2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+ $$.C = ConstantFP::get($1.T, *$2);
+ delete $2;
+ $$.S.makeSignless();
}
;
ConstExpr
: CastOps '(' ConstVal TO Types ')' {
const Type* SrcTy = $3.C->getType();
- const Type* DstTy = $5.T->get();
- Signedness SrcSign = $3.S;
- Signedness DstSign = $5.S;
+ const Type* DstTy = $5.PAT->get();
+ Signedness SrcSign($3.S);
+ Signedness DstSign($5.S);
if (!SrcTy->isFirstClassType())
error("cast constant expression from a non-primitive type: '" +
SrcTy->getDescription() + "'");
error("cast constant expression to a non-primitive type: '" +
DstTy->getDescription() + "'");
$$.C = cast<Constant>(getCast($1, $3.C, SrcSign, DstTy, DstSign));
- $$.S = DstSign;
- delete $5.T;
+ $$.S.copy(DstSign);
+ delete $5.PAT;
}
| GETELEMENTPTR '(' ConstVal IndexList ')' {
const Type *Ty = $3.C->getType();
if (!isa<PointerType>(Ty))
error("GetElementPtr requires a pointer operand");
- std::vector<Value*> VIndices;
std::vector<Constant*> CIndices;
- upgradeGEPIndices($3.C->getType(), $4, VIndices, &CIndices);
+ upgradeGEPCEIndices($3.C->getType(), $4, CIndices);
delete $4;
- $$.C = ConstantExpr::getGetElementPtr($3.C, CIndices);
- $$.S = Signless;
+ $$.C = ConstantExpr::getGetElementPtr($3.C, &CIndices[0], CIndices.size());
+ $$.S.copy(getElementSign($3, CIndices));
}
| SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
if (!$3.C->getType()->isInteger() ||
if ($5.C->getType() != $7.C->getType())
error("Select operand types must match");
$$.C = ConstantExpr::getSelect($3.C, $5.C, $7.C);
- $$.S = Unsigned;
+ $$.S.copy($5.S);
}
| ArithmeticOps '(' ConstVal ',' ConstVal ')' {
const Type *Ty = $3.C->getType();
ConstantExpr::getCast(Instruction::PtrToInt, $5.C, IntPtrTy));
$$.C = ConstantExpr::getCast(Instruction::IntToPtr, $$.C, Ty);
}
- $$.S = $3.S;
+ $$.S.copy($3.S);
}
| LogicalOps '(' ConstVal ',' ConstVal ')' {
const Type* Ty = $3.C->getType();
if (Ty != $5.C->getType())
error("Logical operator types must match");
if (!Ty->isInteger()) {
- if (!isa<PackedType>(Ty) ||
- !cast<PackedType>(Ty)->getElementType()->isInteger())
+ if (!isa<VectorType>(Ty) ||
+ !cast<VectorType>(Ty)->getElementType()->isInteger())
error("Logical operator requires integer operands");
}
Instruction::BinaryOps Opcode = getBinaryOp($1, Ty, $3.S);
$$.C = ConstantExpr::get(Opcode, $3.C, $5.C);
- $$.S = $3.S;
+ $$.S.copy($3.S);
}
| SetCondOps '(' ConstVal ',' ConstVal ')' {
const Type* Ty = $3.C->getType();
unsigned short pred;
Instruction::OtherOps Opcode = getCompareOp($1, pred, Ty, $3.S);
$$.C = ConstantExpr::getCompare(Opcode, $3.C, $5.C);
- $$.S = Unsigned;
+ $$.S.makeUnsigned();
}
| ICMP IPredicates '(' ConstVal ',' ConstVal ')' {
if ($4.C->getType() != $6.C->getType())
error("icmp operand types must match");
$$.C = ConstantExpr::getCompare($2, $4.C, $6.C);
- $$.S = Unsigned;
+ $$.S.makeUnsigned();
}
| FCMP FPredicates '(' ConstVal ',' ConstVal ')' {
if ($4.C->getType() != $6.C->getType())
error("fcmp operand types must match");
$$.C = ConstantExpr::getCompare($2, $4.C, $6.C);
- $$.S = Unsigned;
+ $$.S.makeUnsigned();
}
| ShiftOps '(' ConstVal ',' ConstVal ')' {
if (!$5.C->getType()->isInteger() ||
cast<IntegerType>($5.C->getType())->getBitWidth() != 8)
error("Shift count for shift constant must be unsigned byte");
+ const Type* Ty = $3.C->getType();
if (!$3.C->getType()->isInteger())
error("Shift constant expression requires integer operand");
- $$.C = ConstantExpr::get(getOtherOp($1, $3.S), $3.C, $5.C);
- $$.S = $3.S;
+ Constant *ShiftAmt = ConstantExpr::getZExt($5.C, Ty);
+ $$.C = ConstantExpr::get(getBinaryOp($1, Ty, $3.S), $3.C, ShiftAmt);
+ $$.S.copy($3.S);
}
| EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
if (!ExtractElementInst::isValidOperands($3.C, $5.C))
error("Invalid extractelement operands");
$$.C = ConstantExpr::getExtractElement($3.C, $5.C);
- $$.S = $3.S;
+ $$.S.copy($3.S.get(0));
}
| INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
if (!InsertElementInst::isValidOperands($3.C, $5.C, $7.C))
error("Invalid insertelement operands");
$$.C = ConstantExpr::getInsertElement($3.C, $5.C, $7.C);
- $$.S = $3.S;
+ $$.S.copy($3.S);
}
| SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
if (!ShuffleVectorInst::isValidOperands($3.C, $5.C, $7.C))
error("Invalid shufflevector operands");
$$.C = ConstantExpr::getShuffleVector($3.C, $5.C, $7.C);
- $$.S = $3.S;
+ $$.S.copy($3.S);
}
;
// If types are not resolved eagerly, then the two types will not be
// determined to be the same type!
//
- const Type* Ty = $4.T->get();
- ResolveTypeTo($2, Ty);
+ ResolveTypeTo($2, $4.PAT->get(), $4.S);
- if (!setTypeName(Ty, $2) && !$2) {
- // If this is a named type that is not a redefinition, add it to the slot
- // table.
- CurModule.Types.push_back(Ty);
+ if (!setTypeName($4, $2) && !$2) {
+ // If this is a numbered type that is not a redefinition, add it to the
+ // slot table.
+ CurModule.Types.push_back($4.PAT->get());
+ CurModule.TypeSigns.push_back($4.S);
}
- delete $4.T;
+ delete $4.PAT;
}
| ConstPool FunctionProto { // Function prototypes can be in const pool
}
| ConstPool OptAssign OptLinkage GlobalType ConstVal {
if ($5.C == 0)
error("Global value initializer is not a constant");
- CurGV = ParseGlobalVariable($2, $3, $4, $5.C->getType(), $5.C);
+ CurGV = ParseGlobalVariable($2, $3, $4, $5.C->getType(), $5.C, $5.S);
} GlobalVarAttributes {
CurGV = 0;
}
| ConstPool OptAssign EXTERNAL GlobalType Types {
- const Type *Ty = $5.T->get();
- CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, Ty, 0);
- delete $5.T;
+ const Type *Ty = $5.PAT->get();
+ CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, Ty, 0,
+ $5.S);
+ delete $5.PAT;
} GlobalVarAttributes {
CurGV = 0;
}
| ConstPool OptAssign DLLIMPORT GlobalType Types {
- const Type *Ty = $5.T->get();
- CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4, Ty, 0);
- delete $5.T;
+ const Type *Ty = $5.PAT->get();
+ CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4, Ty, 0,
+ $5.S);
+ delete $5.PAT;
} GlobalVarAttributes {
CurGV = 0;
}
| ConstPool OptAssign EXTERN_WEAK GlobalType Types {
- const Type *Ty = $5.T->get();
+ const Type *Ty = $5.PAT->get();
CurGV =
- ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4, Ty, 0);
- delete $5.T;
+ ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4, Ty, 0,
+ $5.S);
+ delete $5.PAT;
} GlobalVarAttributes {
CurGV = 0;
}
;
BigOrLittle
- : BIG { $$ = Module::BigEndian; };
+ : BIG { $$ = Module::BigEndian; }
| LITTLE { $$ = Module::LittleEndian; }
;
ArgVal
: Types OptName {
- if ($1.T->get() == Type::VoidTy)
+ if ($1.PAT->get() == Type::VoidTy)
error("void typed arguments are invalid");
$$ = new std::pair<PATypeInfo, char*>($1, $2);
}
| ArgListH ',' DOTDOTDOT {
$$ = $1;
PATypeInfo VoidTI;
- VoidTI.T = new PATypeHolder(Type::VoidTy);
- VoidTI.S = Signless;
+ VoidTI.PAT = new PATypeHolder(Type::VoidTy);
+ VoidTI.S.makeSignless();
$$->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
}
| DOTDOTDOT {
$$ = new std::vector<std::pair<PATypeInfo,char*> >();
PATypeInfo VoidTI;
- VoidTI.T = new PATypeHolder(Type::VoidTy);
- VoidTI.S = Signless;
+ VoidTI.PAT = new PATypeHolder(Type::VoidTy);
+ VoidTI.S.makeSignless();
$$->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
}
| /* empty */ { $$ = 0; }
std::string FunctionName($3);
free($3); // Free strdup'd memory!
- const Type* RetTy = $2.T->get();
+ const Type* RetTy = $2.PAT->get();
if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
error("LLVM functions cannot return aggregate types");
- std::vector<const Type*> ParamTypeList;
+ Signedness FTySign;
+ FTySign.makeComposite($2.S);
+ std::vector<const Type*> ParamTyList;
// In LLVM 2.0 the signatures of three varargs intrinsics changed to take
// i8*. We check here for those names and override the parameter list
// types to ensure the prototype is correct.
if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
- ParamTypeList.push_back(PointerType::get(Type::Int8Ty));
+ ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
} else if (FunctionName == "llvm.va_copy") {
- ParamTypeList.push_back(PointerType::get(Type::Int8Ty));
- ParamTypeList.push_back(PointerType::get(Type::Int8Ty));
+ ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
+ ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
} else if ($5) { // If there are arguments...
for (std::vector<std::pair<PATypeInfo,char*> >::iterator
I = $5->begin(), E = $5->end(); I != E; ++I) {
- const Type *Ty = I->first.T->get();
- ParamTypeList.push_back(Ty);
+ const Type *Ty = I->first.PAT->get();
+ ParamTyList.push_back(Ty);
+ FTySign.add(I->first.S);
}
}
- bool isVarArg =
- ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
- if (isVarArg) ParamTypeList.pop_back();
+ bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
+ if (isVarArg)
+ ParamTyList.pop_back();
- const FunctionType *FT = FunctionType::get(RetTy, ParamTypeList, isVarArg);
- const PointerType *PFT = PointerType::get(FT);
- delete $2.T;
+ const FunctionType *FT = FunctionType::get(RetTy, ParamTyList, isVarArg);
+ const PointerType *PFT = PointerType::getUnqual(FT);
+ delete $2.PAT;
ValID ID;
if (!FunctionName.empty()) {
} else {
ID = ValID::create((int)CurModule.Values[PFT].size());
}
+ ID.S.makeComposite(FTySign);
Function *Fn = 0;
+ Module* M = CurModule.CurrentModule;
+
// See if this function was forward referenced. If so, recycle the object.
if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
// Move the function to the end of the list, from whereever it was
// previously inserted.
Fn = cast<Function>(FWRef);
- CurModule.CurrentModule->getFunctionList().remove(Fn);
- CurModule.CurrentModule->getFunctionList().push_back(Fn);
- } else if (!FunctionName.empty() && // Merge with an earlier prototype?
- (Fn = CurModule.CurrentModule->getFunction(FunctionName, FT))) {
- // If this is the case, either we need to be a forward decl, or it needs
- // to be.
- if (!CurFun.isDeclare && !Fn->isExternal())
- error("Redefinition of function '" + FunctionName + "'");
-
- // Make sure to strip off any argument names so we can't get conflicts.
- if (Fn->isExternal())
- for (Function::arg_iterator AI = Fn->arg_begin(), AE = Fn->arg_end();
- AI != AE; ++AI)
- AI->setName("");
- } else { // Not already defined?
- Fn = new Function(FT, GlobalValue::ExternalLinkage, FunctionName,
- CurModule.CurrentModule);
-
+ M->getFunctionList().remove(Fn);
+ M->getFunctionList().push_back(Fn);
+ } else if (!FunctionName.empty()) {
+ GlobalValue *Conflict = M->getFunction(FunctionName);
+ if (!Conflict)
+ Conflict = M->getNamedGlobal(FunctionName);
+ if (Conflict && PFT == Conflict->getType()) {
+ if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
+ // We have two function definitions that conflict, same type, same
+ // name. We should really check to make sure that this is the result
+ // of integer type planes collapsing and generate an error if it is
+ // not, but we'll just rename on the assumption that it is. However,
+ // let's do it intelligently and rename the internal linkage one
+ // if there is one.
+ std::string NewName(makeNameUnique(FunctionName));
+ if (Conflict->hasInternalLinkage()) {
+ Conflict->setName(NewName);
+ RenameMapKey Key =
+ makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
+ CurModule.RenameMap[Key] = NewName;
+ Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
+ InsertValue(Fn, CurModule.Values);
+ } else {
+ Fn = new Function(FT, CurFun.Linkage, NewName, M);
+ InsertValue(Fn, CurModule.Values);
+ RenameMapKey Key =
+ makeRenameMapKey(FunctionName, PFT, ID.S);
+ CurModule.RenameMap[Key] = NewName;
+ }
+ } else {
+ // If they are not both definitions, then just use the function we
+ // found since the types are the same.
+ Fn = cast<Function>(Conflict);
+
+ // Make sure to strip off any argument names so we can't get
+ // conflicts.
+ if (Fn->isDeclaration())
+ for (Function::arg_iterator AI = Fn->arg_begin(),
+ AE = Fn->arg_end(); AI != AE; ++AI)
+ AI->setName("");
+ }
+ } else if (Conflict) {
+ // We have two globals with the same name and different types.
+ // Previously, this was permitted because the symbol table had
+ // "type planes" and names only needed to be distinct within a
+ // type plane. After PR411 was fixed, this is no loner the case.
+ // To resolve this we must rename one of the two.
+ if (Conflict->hasInternalLinkage()) {
+ // We can safely rename the Conflict.
+ RenameMapKey Key =
+ makeRenameMapKey(Conflict->getName(), Conflict->getType(),
+ CurModule.NamedValueSigns[Conflict->getName()]);
+ Conflict->setName(makeNameUnique(Conflict->getName()));
+ CurModule.RenameMap[Key] = Conflict->getName();
+ Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
+ InsertValue(Fn, CurModule.Values);
+ } else {
+ // We can't quietly rename either of these things, but we must
+ // rename one of them. Only if the function's linkage is internal can
+ // we forgo a warning message about the renamed function.
+ std::string NewName = makeNameUnique(FunctionName);
+ if (CurFun.Linkage != GlobalValue::InternalLinkage) {
+ warning("Renaming function '" + FunctionName + "' as '" + NewName +
+ "' may cause linkage errors");
+ }
+ // Elect to rename the thing we're now defining.
+ Fn = new Function(FT, CurFun.Linkage, NewName, M);
+ InsertValue(Fn, CurModule.Values);
+ RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
+ CurModule.RenameMap[Key] = NewName;
+ }
+ } else {
+ // There's no conflict, just define the function
+ Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
+ InsertValue(Fn, CurModule.Values);
+ }
+ } else {
+ // There's no conflict, just define the function
+ Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
InsertValue(Fn, CurModule.Values);
}
+
CurFun.FunctionStart(Fn);
if (CurFun.isDeclare) {
// argument to another function.
Fn->setLinkage(CurFun.Linkage);
}
- Fn->setCallingConv($1);
+ Fn->setCallingConv(upgradeCallingConv($1));
Fn->setAlignment($8);
if ($7) {
Fn->setSection($7);
free($7);
}
+ // Convert the CSRet calling convention into the corresponding parameter
+ // attribute.
+ if ($1 == OldCallingConv::CSRet) {
+ ParamAttrsVector Attrs;
+ ParamAttrsWithIndex PAWI;
+ PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
+ Attrs.push_back(PAWI);
+ Fn->setParamAttrs(ParamAttrsList::get(Attrs));
+ }
+
// Add all of the arguments we parsed to the function...
if ($5) { // Is null if empty...
if (isVarArg) { // Nuke the last entry
- assert($5->back().first.T->get() == Type::VoidTy &&
+ assert($5->back().first.PAT->get() == Type::VoidTy &&
$5->back().second == 0 && "Not a varargs marker");
- delete $5->back().first.T;
+ delete $5->back().first.PAT;
$5->pop_back(); // Delete the last entry
}
Function::arg_iterator ArgIt = Fn->arg_begin();
- for (std::vector<std::pair<PATypeInfo,char*> >::iterator
- I = $5->begin(), E = $5->end(); I != E; ++I, ++ArgIt) {
- delete I->first.T; // Delete the typeholder...
- setValueName(ArgIt, I->second); // Insert arg into symtab...
+ Function::arg_iterator ArgEnd = Fn->arg_end();
+ std::vector<std::pair<PATypeInfo,char*> >::iterator I = $5->begin();
+ std::vector<std::pair<PATypeInfo,char*> >::iterator E = $5->end();
+ for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
+ delete I->first.PAT; // Delete the typeholder...
+ ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
+ setValueName(VI, I->second); // Insert arg into symtab...
InsertValue(ArgIt);
}
delete $5; // We're now done with the argument list
}
+ lastCallingConv = OldCallingConv::C;
}
;
;
FunctionHeader
- : OptLinkage FunctionHeaderH BEGIN {
+ : OptLinkage { CurFun.Linkage = $1; } FunctionHeaderH BEGIN {
$$ = CurFun.CurrentFunction;
// Make sure that we keep track of the linkage type even if there was a
};
FnDeclareLinkage
- : /*default*/
- | DLLIMPORT { CurFun.Linkage = GlobalValue::DLLImportLinkage; }
- | EXTERN_WEAK { CurFun.Linkage = GlobalValue::ExternalWeakLinkage; }
+ : /*default*/ { $$ = GlobalValue::ExternalLinkage; }
+ | DLLIMPORT { $$ = GlobalValue::DLLImportLinkage; }
+ | EXTERN_WEAK { $$ = GlobalValue::ExternalWeakLinkage; }
;
FunctionProto
- : DECLARE { CurFun.isDeclare = true; } FnDeclareLinkage FunctionHeaderH {
+ : DECLARE { CurFun.isDeclare = true; }
+ FnDeclareLinkage { CurFun.Linkage = $3; } FunctionHeaderH {
$$ = CurFun.CurrentFunction;
CurFun.FunctionDone();
ConstValueRef
// A reference to a direct constant
- : ESINT64VAL { $$ = ValID::create($1); }
+ : ESINT64VAL { $$ = ValID::create($1); }
| EUINT64VAL { $$ = ValID::create($1); }
| FPVAL { $$ = ValID::create($1); }
- | TRUETOK { $$ = ValID::create(ConstantInt::get(Type::Int1Ty, true)); }
- | FALSETOK { $$ = ValID::create(ConstantInt::get(Type::Int1Ty, false)); }
+ | TRUETOK {
+ $$ = ValID::create(ConstantInt::get(Type::Int1Ty, true));
+ $$.S.makeUnsigned();
+ }
+ | FALSETOK {
+ $$ = ValID::create(ConstantInt::get(Type::Int1Ty, false));
+ $$.S.makeUnsigned();
+ }
| NULL_TOK { $$ = ValID::createNull(); }
| UNDEF { $$ = ValID::createUndef(); }
| ZEROINITIALIZER { $$ = ValID::createZeroInit(); }
| '<' ConstVector '>' { // Nonempty unsized packed vector
const Type *ETy = (*$2)[0].C->getType();
int NumElements = $2->size();
- PackedType* pt = PackedType::get(ETy, NumElements);
- PATypeHolder* PTy = new PATypeHolder(
- HandleUpRefs(PackedType::get(ETy, NumElements)));
+ VectorType* pt = VectorType::get(ETy, NumElements);
+ $$.S.makeComposite((*$2)[0].S);
+ PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, $$.S));
// Verify all elements are correct type!
std::vector<Constant*> Elems;
CTy->getDescription() + "'");
Elems.push_back(C);
}
- $$ = ValID::create(ConstantPacked::get(pt, Elems));
+ $$ = ValID::create(ConstantVector::get(pt, Elems));
delete PTy; delete $2;
}
| ConstExpr {
$$ = ValID::create($1.C);
+ $$.S.copy($1.S);
}
| ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
char *End = UnEscapeLexed($3, true);
}
;
-// SymbolicValueRef - Reference to one of two ways of symbolically refering to
+// SymbolicValueRef - Reference to one of two ways of symbolically refering to
// another value.
//
SymbolicValueRef
- : INTVAL { $$ = ValID::create($1); }
- | Name { $$ = ValID::create($1); }
+ : INTVAL { $$ = ValID::create($1); $$.S.makeSignless(); }
+ | Name { $$ = ValID::create($1); $$.S.makeSignless(); }
;
// ValueRef - A reference to a definition... either constant or symbolic
// pool references (for things like: 'ret [2 x int] [ int 12, int 42]')
ResolvedVal
: Types ValueRef {
- const Type *Ty = $1.T->get();
- $$.S = $1.S;
+ const Type *Ty = $1.PAT->get();
+ $2.S.copy($1.S);
$$.V = getVal(Ty, $2);
- delete $1.T;
+ $$.S.copy($1.S);
+ delete $1.PAT;
}
;
//
BasicBlock
: InstructionList OptAssign BBTerminatorInst {
- setValueName($3, $2);
- InsertValue($3);
- $1->getInstList().push_back($3);
+ ValueInfo VI; VI.V = $3.TI; VI.S.copy($3.S);
+ setValueName(VI, $2);
+ InsertValue($3.TI);
+ $1->getInstList().push_back($3.TI);
InsertValue($1);
$$ = $1;
}
$$ = $1;
}
| /* empty */ {
- $$ = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
+ $$ = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
// Make sure to move the basic block to the correct location in the
// function, instead of leaving it inserted wherever it was first
// referenced.
BBTerminatorInst
: RET ResolvedVal { // Return with a result...
- $$ = new ReturnInst($2.V);
+ $$.TI = new ReturnInst($2.V);
+ $$.S.makeSignless();
}
| RET VOID { // Return with no result...
- $$ = new ReturnInst();
+ $$.TI = new ReturnInst();
+ $$.S.makeSignless();
}
| BR LABEL ValueRef { // Unconditional Branch...
BasicBlock* tmpBB = getBBVal($3);
- $$ = new BranchInst(tmpBB);
+ $$.TI = new BranchInst(tmpBB);
+ $$.S.makeSignless();
} // Conditional Branch...
| BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
+ $6.S.makeSignless();
+ $9.S.makeSignless();
BasicBlock* tmpBBA = getBBVal($6);
BasicBlock* tmpBBB = getBBVal($9);
+ $3.S.makeUnsigned();
Value* tmpVal = getVal(Type::Int1Ty, $3);
- $$ = new BranchInst(tmpBBA, tmpBBB, tmpVal);
+ $$.TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
+ $$.S.makeSignless();
}
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
+ $3.S.copy($2.S);
Value* tmpVal = getVal($2.T, $3);
+ $6.S.makeSignless();
BasicBlock* tmpBB = getBBVal($6);
SwitchInst *S = new SwitchInst(tmpVal, tmpBB, $8->size());
- $$ = S;
+ $$.TI = S;
+ $$.S.makeSignless();
std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = $8->begin(),
E = $8->end();
for (; I != E; ++I) {
delete $8;
}
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
+ $3.S.copy($2.S);
Value* tmpVal = getVal($2.T, $3);
+ $6.S.makeSignless();
BasicBlock* tmpBB = getBBVal($6);
SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
- $$ = S;
+ $$.TI = S;
+ $$.S.makeSignless();
}
| INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
TO LABEL ValueRef Unwind LABEL ValueRef {
const PointerType *PFTy;
const FunctionType *Ty;
+ Signedness FTySign;
- if (!(PFTy = dyn_cast<PointerType>($3.T->get())) ||
+ if (!(PFTy = dyn_cast<PointerType>($3.PAT->get())) ||
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
// Pull out the types of all of the arguments...
std::vector<const Type*> ParamTypes;
+ FTySign.makeComposite($3.S);
if ($6) {
for (std::vector<ValueInfo>::iterator I = $6->begin(), E = $6->end();
- I != E; ++I)
+ I != E; ++I) {
ParamTypes.push_back((*I).V->getType());
+ FTySign.add(I->S);
+ }
}
bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
if (isVarArg) ParamTypes.pop_back();
- Ty = FunctionType::get($3.T->get(), ParamTypes, isVarArg);
- PFTy = PointerType::get(Ty);
+ Ty = FunctionType::get($3.PAT->get(), ParamTypes, isVarArg);
+ PFTy = PointerType::getUnqual(Ty);
+ $$.S.copy($3.S);
+ } else {
+ FTySign = $3.S;
+ // Get the signedness of the result type. $3 is the pointer to the
+ // function type so we get the 0th element to extract the function type,
+ // and then the 0th element again to get the result type.
+ $$.S.copy($3.S.get(0).get(0));
}
+
+ $4.S.makeComposite(FTySign);
Value *V = getVal(PFTy, $4); // Get the function we're calling...
BasicBlock *Normal = getBBVal($10);
BasicBlock *Except = getBBVal($13);
// Create the call node...
if (!$6) { // Has no arguments?
- $$ = new InvokeInst(V, Normal, Except, std::vector<Value*>());
+ std::vector<Value*> Args;
+ $$.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
} else { // Has arguments?
// Loop through FunctionType's arguments and ensure they are specified
// correctly!
if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
error("Invalid number of parameters detected");
- $$ = new InvokeInst(V, Normal, Except, Args);
+ $$.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
+ }
+ cast<InvokeInst>($$.TI)->setCallingConv(upgradeCallingConv($2));
+ if ($2 == OldCallingConv::CSRet) {
+ ParamAttrsVector Attrs;
+ ParamAttrsWithIndex PAWI;
+ PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
+ Attrs.push_back(PAWI);
+ cast<InvokeInst>($$.TI)->setParamAttrs(ParamAttrsList::get(Attrs));
}
- cast<InvokeInst>($$)->setCallingConv($2);
- delete $3.T;
+ delete $3.PAT;
delete $6;
+ lastCallingConv = OldCallingConv::C;
}
| Unwind {
- $$ = new UnwindInst();
+ $$.TI = new UnwindInst();
+ $$.S.makeSignless();
}
| UNREACHABLE {
- $$ = new UnreachableInst();
+ $$.TI = new UnreachableInst();
+ $$.S.makeSignless();
}
;
JumpTable
: JumpTable IntType ConstValueRef ',' LABEL ValueRef {
$$ = $1;
+ $3.S.copy($2.S);
Constant *V = cast<Constant>(getExistingValue($2.T, $3));
if (V == 0)
error("May only switch on a constant pool value");
+ $6.S.makeSignless();
BasicBlock* tmpBB = getBBVal($6);
$$->push_back(std::make_pair(V, tmpBB));
}
| IntType ConstValueRef ',' LABEL ValueRef {
$$ = new std::vector<std::pair<Constant*, BasicBlock*> >();
+ $2.S.copy($1.S);
Constant *V = cast<Constant>(getExistingValue($1.T, $2));
if (V == 0)
error("May only switch on a constant pool value");
+ $5.S.makeSignless();
BasicBlock* tmpBB = getBBVal($5);
$$->push_back(std::make_pair(V, tmpBB));
}
omit = true;
if (omit) {
$$.I = 0;
- $$.S = Signless;
+ $$.S.makeSignless();
} else {
- setValueName($2.I, $1);
+ ValueInfo VI; VI.V = $2.I; VI.S.copy($2.S);
+ setValueName(VI, $1);
InsertValue($2.I);
$$ = $2;
}
PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
$$.P = new std::list<std::pair<Value*, BasicBlock*> >();
- $$.S = $1.S;
- Value* tmpVal = getVal($1.T->get(), $3);
+ $$.S.copy($1.S);
+ $3.S.copy($1.S);
+ Value* tmpVal = getVal($1.PAT->get(), $3);
+ $5.S.makeSignless();
BasicBlock* tmpBB = getBBVal($5);
$$.P->push_back(std::make_pair(tmpVal, tmpBB));
- delete $1.T;
+ delete $1.PAT;
}
| PHIList ',' '[' ValueRef ',' ValueRef ']' {
$$ = $1;
+ $4.S.copy($1.S);
Value* tmpVal = getVal($1.P->front().first->getType(), $4);
+ $6.S.makeSignless();
BasicBlock* tmpBB = getBBVal($6);
$1.P->push_back(std::make_pair(tmpVal, tmpBB));
}
InstVal
: ArithmeticOps Types ValueRef ',' ValueRef {
- const Type* Ty = $2.T->get();
- if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<PackedType>(Ty))
+ $3.S.copy($2.S);
+ $5.S.copy($2.S);
+ const Type* Ty = $2.PAT->get();
+ if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
error("Arithmetic operator requires integer, FP, or packed operands");
- if (isa<PackedType>(Ty) &&
+ if (isa<VectorType>(Ty) &&
($1 == URemOp || $1 == SRemOp || $1 == FRemOp || $1 == RemOp))
- error("Remainder not supported on packed types");
+ error("Remainder not supported on vector types");
// Upgrade the opcode from obsolete versions before we do anything with it.
Instruction::BinaryOps Opcode = getBinaryOp($1, Ty, $2.S);
Value* val1 = getVal(Ty, $3);
$$.I = BinaryOperator::create(Opcode, val1, val2);
if ($$.I == 0)
error("binary operator returned null");
- $$.S = $2.S;
- delete $2.T;
+ $$.S.copy($2.S);
+ delete $2.PAT;
}
| LogicalOps Types ValueRef ',' ValueRef {
- const Type *Ty = $2.T->get();
+ $3.S.copy($2.S);
+ $5.S.copy($2.S);
+ const Type *Ty = $2.PAT->get();
if (!Ty->isInteger()) {
- if (!isa<PackedType>(Ty) ||
- !cast<PackedType>(Ty)->getElementType()->isInteger())
+ if (!isa<VectorType>(Ty) ||
+ !cast<VectorType>(Ty)->getElementType()->isInteger())
error("Logical operator requires integral operands");
}
Instruction::BinaryOps Opcode = getBinaryOp($1, Ty, $2.S);
$$.I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
if ($$.I == 0)
error("binary operator returned null");
- $$.S = $2.S;
- delete $2.T;
+ $$.S.copy($2.S);
+ delete $2.PAT;
}
| SetCondOps Types ValueRef ',' ValueRef {
- const Type* Ty = $2.T->get();
- if(isa<PackedType>(Ty))
- error("PackedTypes currently not supported in setcc instructions");
+ $3.S.copy($2.S);
+ $5.S.copy($2.S);
+ const Type* Ty = $2.PAT->get();
+ if(isa<VectorType>(Ty))
+ error("VectorTypes currently not supported in setcc instructions");
unsigned short pred;
Instruction::OtherOps Opcode = getCompareOp($1, pred, Ty, $2.S);
Value* tmpVal1 = getVal(Ty, $3);
$$.I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
if ($$.I == 0)
error("binary operator returned null");
- $$.S = Unsigned;
- delete $2.T;
+ $$.S.makeUnsigned();
+ delete $2.PAT;
}
| ICMP IPredicates Types ValueRef ',' ValueRef {
- const Type *Ty = $3.T->get();
- if (isa<PackedType>(Ty))
- error("PackedTypes currently not supported in icmp instructions");
+ $4.S.copy($3.S);
+ $6.S.copy($3.S);
+ const Type *Ty = $3.PAT->get();
+ if (isa<VectorType>(Ty))
+ error("VectorTypes currently not supported in icmp instructions");
else if (!Ty->isInteger() && !isa<PointerType>(Ty))
error("icmp requires integer or pointer typed operands");
Value* tmpVal1 = getVal(Ty, $4);
Value* tmpVal2 = getVal(Ty, $6);
$$.I = new ICmpInst($2, tmpVal1, tmpVal2);
- $$.S = Unsigned;
- delete $3.T;
+ $$.S.makeUnsigned();
+ delete $3.PAT;
}
| FCMP FPredicates Types ValueRef ',' ValueRef {
- const Type *Ty = $3.T->get();
- if (isa<PackedType>(Ty))
- error("PackedTypes currently not supported in fcmp instructions");
+ $4.S.copy($3.S);
+ $6.S.copy($3.S);
+ const Type *Ty = $3.PAT->get();
+ if (isa<VectorType>(Ty))
+ error("VectorTypes currently not supported in fcmp instructions");
else if (!Ty->isFloatingPoint())
error("fcmp instruction requires floating point operands");
Value* tmpVal1 = getVal(Ty, $4);
Value* tmpVal2 = getVal(Ty, $6);
$$.I = new FCmpInst($2, tmpVal1, tmpVal2);
- $$.S = Unsigned;
- delete $3.T;
+ $$.S.makeUnsigned();
+ delete $3.PAT;
}
| NOT ResolvedVal {
warning("Use of obsolete 'not' instruction: Replacing with 'xor");
$$.I = BinaryOperator::create(Instruction::Xor, $2.V, Ones);
if ($$.I == 0)
error("Could not create a xor instruction");
- $$.S = $2.S
+ $$.S.copy($2.S);
}
| ShiftOps ResolvedVal ',' ResolvedVal {
if (!$4.V->getType()->isInteger() ||
cast<IntegerType>($4.V->getType())->getBitWidth() != 8)
error("Shift amount must be int8");
- if (!$2.V->getType()->isInteger())
+ const Type* Ty = $2.V->getType();
+ if (!Ty->isInteger())
error("Shift constant expression requires integer operand");
- $$.I = new ShiftInst(getOtherOp($1, $2.S), $2.V, $4.V);
- $$.S = $2.S;
+ Value* ShiftAmt = 0;
+ if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
+ if (Constant *C = dyn_cast<Constant>($4.V))
+ ShiftAmt = ConstantExpr::getZExt(C, Ty);
+ else
+ ShiftAmt = new ZExtInst($4.V, Ty, makeNameUnique("shift"), CurBB);
+ else
+ ShiftAmt = $4.V;
+ $$.I = BinaryOperator::create(getBinaryOp($1, Ty, $2.S), $2.V, ShiftAmt);
+ $$.S.copy($2.S);
}
| CastOps ResolvedVal TO Types {
- const Type *DstTy = $4.T->get();
+ const Type *DstTy = $4.PAT->get();
if (!DstTy->isFirstClassType())
error("cast instruction to a non-primitive type: '" +
DstTy->getDescription() + "'");
$$.I = cast<Instruction>(getCast($1, $2.V, $2.S, DstTy, $4.S, true));
- $$.S = $4.S;
- delete $4.T;
+ $$.S.copy($4.S);
+ delete $4.PAT;
}
| SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
if (!$2.V->getType()->isInteger() ||
if ($4.V->getType() != $6.V->getType())
error("select value types should match");
$$.I = new SelectInst($2.V, $4.V, $6.V);
- $$.S = $2.S;
+ $$.S.copy($4.S);
}
| VAARG ResolvedVal ',' Types {
- const Type *Ty = $4.T->get();
+ const Type *Ty = $4.PAT->get();
NewVarArgs = true;
$$.I = new VAArgInst($2.V, Ty);
- $$.S = $4.S;
- delete $4.T;
+ $$.S.copy($4.S);
+ delete $4.PAT;
}
| VAARG_old ResolvedVal ',' Types {
const Type* ArgTy = $2.V->getType();
- const Type* DstTy = $4.T->get();
+ const Type* DstTy = $4.PAT->get();
ObsoleteVarArgs = true;
Function* NF = cast<Function>(CurModule.CurrentModule->
getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
CurBB->getInstList().push_back(bar);
CurBB->getInstList().push_back(new StoreInst(bar, foo));
$$.I = new VAArgInst(foo, DstTy);
- $$.S = $4.S;
- delete $4.T;
+ $$.S.copy($4.S);
+ delete $4.PAT;
}
| VANEXT_old ResolvedVal ',' Types {
const Type* ArgTy = $2.V->getType();
- const Type* DstTy = $4.T->get();
+ const Type* DstTy = $4.PAT->get();
ObsoleteVarArgs = true;
Function* NF = cast<Function>(CurModule.CurrentModule->
getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
Instruction* tmp = new VAArgInst(foo, DstTy);
CurBB->getInstList().push_back(tmp);
$$.I = new LoadInst(foo);
- $$.S = $4.S;
- delete $4.T;
+ $$.S.copy($4.S);
+ delete $4.PAT;
}
| EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
if (!ExtractElementInst::isValidOperands($2.V, $4.V))
error("Invalid extractelement operands");
$$.I = new ExtractElementInst($2.V, $4.V);
- $$.S = $2.S;
+ $$.S.copy($2.S.get(0));
}
| INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
if (!InsertElementInst::isValidOperands($2.V, $4.V, $6.V))
error("Invalid insertelement operands");
$$.I = new InsertElementInst($2.V, $4.V, $6.V);
- $$.S = $2.S;
+ $$.S.copy($2.S);
}
| SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
if (!ShuffleVectorInst::isValidOperands($2.V, $4.V, $6.V))
error("Invalid shufflevector operands");
$$.I = new ShuffleVectorInst($2.V, $4.V, $6.V);
- $$.S = $2.S;
+ $$.S.copy($2.S);
}
| PHI_TOK PHIList {
const Type *Ty = $2.P->front().first->getType();
$2.P->pop_front();
}
$$.I = PHI;
- $$.S = $2.S;
+ $$.S.copy($2.S);
delete $2.P; // Free the list...
}
- | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
-
+ | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
// Handle the short call syntax
const PointerType *PFTy;
const FunctionType *FTy;
- if (!(PFTy = dyn_cast<PointerType>($3.T->get())) ||
+ Signedness FTySign;
+ if (!(PFTy = dyn_cast<PointerType>($3.PAT->get())) ||
!(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
// Pull out the types of all of the arguments...
std::vector<const Type*> ParamTypes;
+ FTySign.makeComposite($3.S);
if ($6) {
for (std::vector<ValueInfo>::iterator I = $6->begin(), E = $6->end();
- I != E; ++I)
+ I != E; ++I) {
ParamTypes.push_back((*I).V->getType());
+ FTySign.add(I->S);
+ }
}
bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
if (isVarArg) ParamTypes.pop_back();
- const Type *RetTy = $3.T->get();
+ const Type *RetTy = $3.PAT->get();
if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
error("Functions cannot return aggregate types");
FTy = FunctionType::get(RetTy, ParamTypes, isVarArg);
- PFTy = PointerType::get(FTy);
+ PFTy = PointerType::getUnqual(FTy);
+ $$.S.copy($3.S);
+ } else {
+ FTySign = $3.S;
+ // Get the signedness of the result type. $3 is the pointer to the
+ // function type so we get the 0th element to extract the function type,
+ // and then the 0th element again to get the result type.
+ $$.S.copy($3.S.get(0).get(0));
}
+ $4.S.makeComposite(FTySign);
// First upgrade any intrinsic calls.
std::vector<Value*> Args;
if ($6)
for (unsigned i = 0, e = $6->size(); i < e; ++i)
Args.push_back((*$6)[i].V);
- Instruction *Inst = upgradeIntrinsicCall(FTy, $4, Args);
+ Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), $4, Args);
// If we got an upgraded intrinsic
if (Inst) {
$$.I = Inst;
- $$.S = Signless;
} else {
// Get the function we're calling
Value *V = getVal(PFTy, $4);
}
// Create the call instruction
- CallInst *CI = new CallInst(V, Args);
+ CallInst *CI = new CallInst(V, Args.begin(), Args.end());
CI->setTailCall($1);
- CI->setCallingConv($2);
+ CI->setCallingConv(upgradeCallingConv($2));
+
$$.I = CI;
- $$.S = $3.S;
}
- delete $3.T;
+ // Deal with CSRetCC
+ if ($2 == OldCallingConv::CSRet) {
+ ParamAttrsVector Attrs;
+ ParamAttrsWithIndex PAWI;
+ PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
+ Attrs.push_back(PAWI);
+ cast<CallInst>($$.I)->setParamAttrs(ParamAttrsList::get(Attrs));
+ }
+ delete $3.PAT;
delete $6;
+ lastCallingConv = OldCallingConv::C;
}
| MemoryInst {
$$ = $1;
MemoryInst
: MALLOC Types OptCAlign {
- const Type *Ty = $2.T->get();
- $$.S = $2.S;
+ const Type *Ty = $2.PAT->get();
+ $$.S.makeComposite($2.S);
$$.I = new MallocInst(Ty, 0, $3);
- delete $2.T;
+ delete $2.PAT;
}
| MALLOC Types ',' UINT ValueRef OptCAlign {
- const Type *Ty = $2.T->get();
- $$.S = $2.S;
+ const Type *Ty = $2.PAT->get();
+ $5.S.makeUnsigned();
+ $$.S.makeComposite($2.S);
$$.I = new MallocInst(Ty, getVal($4.T, $5), $6);
- delete $2.T;
+ delete $2.PAT;
}
| ALLOCA Types OptCAlign {
- const Type *Ty = $2.T->get();
- $$.S = $2.S;
+ const Type *Ty = $2.PAT->get();
+ $$.S.makeComposite($2.S);
$$.I = new AllocaInst(Ty, 0, $3);
- delete $2.T;
+ delete $2.PAT;
}
| ALLOCA Types ',' UINT ValueRef OptCAlign {
- const Type *Ty = $2.T->get();
- $$.S = $2.S;
+ const Type *Ty = $2.PAT->get();
+ $5.S.makeUnsigned();
+ $$.S.makeComposite($4.S);
$$.I = new AllocaInst(Ty, getVal($4.T, $5), $6);
- delete $2.T;
+ delete $2.PAT;
}
| FREE ResolvedVal {
const Type *PTy = $2.V->getType();
if (!isa<PointerType>(PTy))
error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
$$.I = new FreeInst($2.V);
- $$.S = Signless;
+ $$.S.makeSignless();
}
| OptVolatile LOAD Types ValueRef {
- const Type* Ty = $3.T->get();
- $$.S = $3.S;
+ const Type* Ty = $3.PAT->get();
+ $4.S.copy($3.S);
if (!isa<PointerType>(Ty))
error("Can't load from nonpointer type: " + Ty->getDescription());
if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
Ty->getDescription());
Value* tmpVal = getVal(Ty, $4);
$$.I = new LoadInst(tmpVal, "", $1);
- delete $3.T;
+ $$.S.copy($3.S.get(0));
+ delete $3.PAT;
}
| OptVolatile STORE ResolvedVal ',' Types ValueRef {
- const PointerType *PTy = dyn_cast<PointerType>($5.T->get());
+ $6.S.copy($5.S);
+ const PointerType *PTy = dyn_cast<PointerType>($5.PAT->get());
if (!PTy)
error("Can't store to a nonpointer type: " +
- $5.T->get()->getDescription());
+ $5.PAT->get()->getDescription());
const Type *ElTy = PTy->getElementType();
- if (ElTy != $3.V->getType())
- error("Can't store '" + $3.V->getType()->getDescription() +
- "' into space of type '" + ElTy->getDescription() + "'");
+ Value *StoreVal = $3.V;
Value* tmpVal = getVal(PTy, $6);
- $$.I = new StoreInst($3.V, tmpVal, $1);
- $$.S = Signless;
- delete $5.T;
+ if (ElTy != $3.V->getType()) {
+ PTy = PointerType::getUnqual(StoreVal->getType());
+ if (Constant *C = dyn_cast<Constant>(tmpVal))
+ tmpVal = ConstantExpr::getBitCast(C, PTy);
+ else
+ tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
+ }
+ $$.I = new StoreInst(StoreVal, tmpVal, $1);
+ $$.S.makeSignless();
+ delete $5.PAT;
}
| GETELEMENTPTR Types ValueRef IndexList {
- const Type* Ty = $2.T->get();
+ $3.S.copy($2.S);
+ const Type* Ty = $2.PAT->get();
if (!isa<PointerType>(Ty))
error("getelementptr insn requires pointer operand");
std::vector<Value*> VIndices;
- upgradeGEPIndices(Ty, $4, VIndices);
+ upgradeGEPInstIndices(Ty, $4, VIndices);
Value* tmpVal = getVal(Ty, $3);
- $$.I = new GetElementPtrInst(tmpVal, VIndices);
- $$.S = Signless;
- delete $2.T;
+ $$.I = new GetElementPtrInst(tmpVal, VIndices.begin(), VIndices.end());
+ ValueInfo VI; VI.V = tmpVal; VI.S.copy($2.S);
+ $$.S.copy(getElementSign(VI, VIndices));
+ delete $2.PAT;
delete $4;
};
int yyerror(const char *ErrorMsg) {
std::string where
= std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
- + ":" + llvm::utostr((unsigned) Upgradelineno-1) + ": ";
+ + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
std::string errMsg = where + "error: " + std::string(ErrorMsg);
if (yychar != YYEMPTY && yychar != 0)
errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
void warning(const std::string& ErrorMsg) {
std::string where
= std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
- + ":" + llvm::utostr((unsigned) Upgradelineno-1) + ": ";
+ + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
std::string errMsg = where + "warning: " + std::string(ErrorMsg);
if (yychar != YYEMPTY && yychar != 0)
errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +