mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
For PR1256:
Make Signedness information pervasive throughout all types and values. There is no easy way to get around this. Because the GEP instruction can index through an arbitrarily complex value structure, it is necessary to keep track of signedness information throughout that structure. This change makes Signedness a full class, capable of representing Signedness in arbitrarily shaped types. The class is then used throughout llvm-upgrade to track signedness and differentiate between globals, locals, and functions based on their signedness. For PR1243: This patch also removes bogus warnings about renaming internal globals. It now only emits such warnings when renaming non-internal globals because they may affect linkage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35234 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
82d4264c1f
commit
3e5affd263
@ -21,6 +21,7 @@
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// Global variables exported from the lexer.
|
||||
@ -32,12 +33,10 @@ extern int Upgradelineno;
|
||||
|
||||
namespace llvm {
|
||||
|
||||
|
||||
class Module;
|
||||
Module* UpgradeAssembly(const std::string &infile, std::istream& in,
|
||||
bool debug, bool addAttrs);
|
||||
|
||||
|
||||
extern std::istream* LexInput;
|
||||
|
||||
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
|
||||
@ -59,6 +58,88 @@ struct InlineAsmDescriptor {
|
||||
: AsmString(as), Constraints(c), HasSideEffects(HSE) {}
|
||||
};
|
||||
|
||||
/// This class keeps track of the signedness of a type or value. It allows the
|
||||
/// signedness of a composite type to be captured in a relatively simple form.
|
||||
/// This is needed in order to retain the signedness of pre LLVM 2.0 types so
|
||||
/// they can be upgraded properly. Signedness of composite types must be
|
||||
/// captured in order to accurately get the signedness of a value through a
|
||||
/// GEP instruction.
|
||||
/// @brief Class to track signedness of types and values.
|
||||
struct Signedness {
|
||||
/// The basic kinds of signedness values.
|
||||
enum Kind {
|
||||
Signless, ///< The type doesn't have any sign.
|
||||
Unsigned, ///< The type is an unsigned integer.
|
||||
Signed, ///< The type is a signed integer.
|
||||
Named, ///< The type is a named type (probably forward ref or up ref).
|
||||
Composite ///< The type is composite (struct, array, pointer).
|
||||
};
|
||||
|
||||
private:
|
||||
/// @brief Keeps track of Signedness for composite types
|
||||
typedef std::vector<Signedness> SignVector;
|
||||
Kind kind; ///< The kind of signedness node
|
||||
union {
|
||||
SignVector *sv; ///< The vector of Signedness for composite types
|
||||
std::string *name; ///< The name of the type for named types.
|
||||
};
|
||||
public:
|
||||
/// The Signedness class is used as a member of a union so it cannot have
|
||||
/// a constructor or assignment operator. This function suffices.
|
||||
/// @brief Copy one signedness value to another
|
||||
void copy(const Signedness &that);
|
||||
/// The Signedness class is used as a member of a union so it cannot have
|
||||
/// a destructor.
|
||||
/// @brief Release memory, if any allocated.
|
||||
void destroy();
|
||||
|
||||
/// @brief Make a Signless node.
|
||||
void makeSignless() { kind = Signless; sv = 0; }
|
||||
/// @brief Make a Signed node.
|
||||
void makeSigned() { kind = Signed; sv = 0; }
|
||||
/// @brief Make an Unsigned node.
|
||||
void makeUnsigned() { kind = Unsigned; sv = 0; }
|
||||
/// @brief Make a Named node.
|
||||
void makeNamed(const std::string& nm){
|
||||
kind = Named; name = new std::string(nm);
|
||||
}
|
||||
/// @brief Make an empty Composite node.
|
||||
void makeComposite() { kind = Composite; sv = new SignVector(); }
|
||||
/// @brief Make an Composite node, with the first element given.
|
||||
void makeComposite(const Signedness &S) {
|
||||
kind = Composite;
|
||||
sv = new SignVector();
|
||||
sv->push_back(S);
|
||||
}
|
||||
/// @brief Add an element to a Composite node.
|
||||
void add(const Signedness &S) {
|
||||
assert(isComposite() && "Must be composite to use add");
|
||||
sv->push_back(S);
|
||||
}
|
||||
bool operator<(const Signedness &that) const;
|
||||
bool operator==(const Signedness &that) const;
|
||||
bool isSigned() const { return kind == Signed; }
|
||||
bool isUnsigned() const { return kind == Unsigned; }
|
||||
bool isSignless() const { return kind == Signless; }
|
||||
bool isNamed() const { return kind == Named; }
|
||||
bool isComposite() const { return kind == Composite; }
|
||||
/// This is used by GetElementPtr to extract the sign of an element.
|
||||
/// @brief Get a specific element from a Composite node.
|
||||
Signedness get(uint64_t idx) const {
|
||||
assert(isComposite() && "Invalid Signedness type for get()");
|
||||
assert(sv && idx < sv->size() && "Invalid index");
|
||||
return (*sv)[idx];
|
||||
}
|
||||
/// @brief Get the name from a Named node.
|
||||
const std::string& getName() const {
|
||||
assert(isNamed() && "Can't get name from non-name Sign");
|
||||
return *name;
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
void dump() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
// ValID - Represents a reference of a definition of some sort. This may either
|
||||
// be a numeric reference or a symbolic (%var) reference. This is just a
|
||||
@ -82,41 +163,58 @@ struct ValID {
|
||||
Constant *ConstantValue; // Fully resolved constant for ConstantVal case.
|
||||
InlineAsmDescriptor *IAD;
|
||||
};
|
||||
Signedness S;
|
||||
|
||||
static ValID create(int Num) {
|
||||
ValID D; D.Type = NumberVal; D.Num = Num; return D;
|
||||
ValID D; D.Type = NumberVal; D.Num = Num; D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID create(char *Name) {
|
||||
ValID D; D.Type = NameVal; D.Name = Name; return D;
|
||||
ValID D; D.Type = NameVal; D.Name = Name; D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID create(int64_t Val) {
|
||||
ValID D; D.Type = ConstSIntVal; D.ConstPool64 = Val; return D;
|
||||
ValID D; D.Type = ConstSIntVal; D.ConstPool64 = Val;
|
||||
D.S.makeSigned();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID create(uint64_t Val) {
|
||||
ValID D; D.Type = ConstUIntVal; D.UConstPool64 = Val; return D;
|
||||
ValID D; D.Type = ConstUIntVal; D.UConstPool64 = Val;
|
||||
D.S.makeUnsigned();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID create(double Val) {
|
||||
ValID D; D.Type = ConstFPVal; D.ConstPoolFP = Val; return D;
|
||||
ValID D; D.Type = ConstFPVal; D.ConstPoolFP = Val;
|
||||
D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID createNull() {
|
||||
ValID D; D.Type = ConstNullVal; return D;
|
||||
ValID D; D.Type = ConstNullVal;
|
||||
D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID createUndef() {
|
||||
ValID D; D.Type = ConstUndefVal; return D;
|
||||
ValID D; D.Type = ConstUndefVal;
|
||||
D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID createZeroInit() {
|
||||
ValID D; D.Type = ConstZeroVal; return D;
|
||||
ValID D; D.Type = ConstZeroVal;
|
||||
D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID create(Constant *Val) {
|
||||
ValID D; D.Type = ConstantVal; D.ConstantValue = Val; return D;
|
||||
ValID D; D.Type = ConstantVal; D.ConstantValue = Val;
|
||||
D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
static ValID createInlineAsm(const std::string &AsmString,
|
||||
@ -125,6 +223,7 @@ struct ValID {
|
||||
ValID D;
|
||||
D.Type = InlineAsmVal;
|
||||
D.IAD = new InlineAsmDescriptor(AsmString, Constraints, HasSideEffects);
|
||||
D.S.makeSignless();
|
||||
return D;
|
||||
}
|
||||
|
||||
@ -221,10 +320,6 @@ namespace OldCallingConv {
|
||||
};
|
||||
}
|
||||
|
||||
/// An enumeration for defining the Signedness of a type or value. Signless
|
||||
/// means the signedness is not relevant to the type or value.
|
||||
enum Signedness { Signless, Unsigned, Signed };
|
||||
|
||||
/// These structures are used as the semantic values returned from various
|
||||
/// productions in the grammar. They simply bundle an LLVM IR object with
|
||||
/// its Signedness value. These help track signedness through the various
|
||||
@ -232,31 +327,67 @@ enum Signedness { Signless, Unsigned, Signed };
|
||||
struct TypeInfo {
|
||||
const llvm::Type *T;
|
||||
Signedness S;
|
||||
bool operator<(const TypeInfo& that) const {
|
||||
if (this == &that)
|
||||
return false;
|
||||
if (T < that.T)
|
||||
return true;
|
||||
if (T == that.T) {
|
||||
bool result = S < that.S;
|
||||
//#define TYPEINFO_DEBUG
|
||||
#ifdef TYPEINFO_DEBUG
|
||||
std::cerr << (result?"true ":"false ") << T->getDescription() << " (";
|
||||
S.dump();
|
||||
std::cerr << ") < " << that.T->getDescription() << " (";
|
||||
that.S.dump();
|
||||
std::cerr << ")\n";
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool operator==(const TypeInfo& that) const {
|
||||
if (this == &that)
|
||||
return true;
|
||||
return T == that.T && S == that.S;
|
||||
}
|
||||
void destroy() { S.destroy(); }
|
||||
};
|
||||
|
||||
struct PATypeInfo {
|
||||
llvm::PATypeHolder* PAT;
|
||||
Signedness S;
|
||||
void destroy() { S.destroy(); delete PAT; }
|
||||
};
|
||||
|
||||
struct ConstInfo {
|
||||
llvm::Constant* C;
|
||||
Signedness S;
|
||||
void destroy() { S.destroy(); }
|
||||
};
|
||||
|
||||
struct ValueInfo {
|
||||
llvm::Value* V;
|
||||
Signedness S;
|
||||
void destroy() { S.destroy(); }
|
||||
};
|
||||
|
||||
struct InstrInfo {
|
||||
llvm::Instruction *I;
|
||||
Signedness S;
|
||||
void destroy() { S.destroy(); }
|
||||
};
|
||||
|
||||
struct TermInstInfo {
|
||||
llvm::TerminatorInst *TI;
|
||||
Signedness S;
|
||||
void destroy() { S.destroy(); }
|
||||
};
|
||||
|
||||
struct PHIListInfo {
|
||||
std::list<std::pair<llvm::Value*, llvm::BasicBlock*> > *P;
|
||||
Signedness S;
|
||||
void destroy() { S.destroy(); delete P; }
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
@ -51,7 +51,12 @@
|
||||
|
||||
#define RET_TY(sym,NewTY,sign) \
|
||||
Upgradelval.PrimType.T = NewTY; \
|
||||
Upgradelval.PrimType.S = sign; \
|
||||
switch (sign) { \
|
||||
case 0: Upgradelval.PrimType.S.makeSignless(); break; \
|
||||
case 1: Upgradelval.PrimType.S.makeUnsigned(); break; \
|
||||
case 2: Upgradelval.PrimType.S.makeSigned(); break; \
|
||||
default: assert(0 && "Invalid sign kind"); break; \
|
||||
}\
|
||||
return sym
|
||||
|
||||
namespace llvm {
|
||||
@ -238,24 +243,24 @@ coldcc { return COLDCC_TOK; }
|
||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
|
||||
|
||||
sbyte { RET_TY(SBYTE, Type::Int8Ty, Signed); }
|
||||
ubyte { RET_TY(UBYTE, Type::Int8Ty, Unsigned); }
|
||||
i8 { RET_TY(UBYTE, Type::Int8Ty, Unsigned); }
|
||||
short { RET_TY(SHORT, Type::Int16Ty, Signed); }
|
||||
ushort { RET_TY(USHORT, Type::Int16Ty, Unsigned); }
|
||||
i16 { RET_TY(USHORT, Type::Int16Ty, Unsigned); }
|
||||
int { RET_TY(INT, Type::Int32Ty, Signed); }
|
||||
uint { RET_TY(UINT, Type::Int32Ty, Unsigned); }
|
||||
i32 { RET_TY(UINT, Type::Int32Ty, Unsigned); }
|
||||
long { RET_TY(LONG, Type::Int64Ty, Signed); }
|
||||
ulong { RET_TY(ULONG, Type::Int64Ty, Unsigned); }
|
||||
i64 { RET_TY(ULONG, Type::Int64Ty, Unsigned); }
|
||||
void { RET_TY(VOID, Type::VoidTy, Signless ); }
|
||||
bool { RET_TY(BOOL, Type::Int1Ty, Unsigned ); }
|
||||
i1 { RET_TY(BOOL, Type::Int1Ty, Unsigned ); }
|
||||
float { RET_TY(FLOAT, Type::FloatTy, Signless ); }
|
||||
double { RET_TY(DOUBLE, Type::DoubleTy,Signless); }
|
||||
label { RET_TY(LABEL, Type::LabelTy, Signless ); }
|
||||
sbyte { RET_TY(SBYTE, Type::Int8Ty, 2); }
|
||||
ubyte { RET_TY(UBYTE, Type::Int8Ty, 1); }
|
||||
i8 { RET_TY(UBYTE, Type::Int8Ty, 1); }
|
||||
short { RET_TY(SHORT, Type::Int16Ty, 2); }
|
||||
ushort { RET_TY(USHORT, Type::Int16Ty, 1); }
|
||||
i16 { RET_TY(USHORT, Type::Int16Ty, 1); }
|
||||
int { RET_TY(INT, Type::Int32Ty, 2); }
|
||||
uint { RET_TY(UINT, Type::Int32Ty, 1); }
|
||||
i32 { RET_TY(UINT, Type::Int32Ty, 1); }
|
||||
long { RET_TY(LONG, Type::Int64Ty, 2); }
|
||||
ulong { RET_TY(ULONG, Type::Int64Ty, 1); }
|
||||
i64 { RET_TY(ULONG, Type::Int64Ty, 1); }
|
||||
void { RET_TY(VOID, Type::VoidTy, 0); }
|
||||
bool { RET_TY(BOOL, Type::Int1Ty, 1); }
|
||||
i1 { RET_TY(BOOL, Type::Int1Ty, 1); }
|
||||
float { RET_TY(FLOAT, Type::FloatTy, 0); }
|
||||
double { RET_TY(DOUBLE, Type::DoubleTy,0); }
|
||||
label { RET_TY(LABEL, Type::LabelTy, 0); }
|
||||
type { return TYPE; }
|
||||
opaque { return OPAQUE; }
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user