2009-01-02 07:01:27 +00:00
|
|
|
//===-- LLParser.h - Parser Class -------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the parser class for .ll files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ASMPARSER_LLPARSER_H
|
|
|
|
#define LLVM_ASMPARSER_LLPARSER_H
|
|
|
|
|
|
|
|
#include "LLLexer.h"
|
2011-07-25 23:16:38 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2009-07-01 23:57:11 +00:00
|
|
|
#include "llvm/Module.h"
|
2009-01-02 07:01:27 +00:00
|
|
|
#include "llvm/Type.h"
|
2010-04-01 05:20:21 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2009-12-28 08:20:46 +00:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2009-12-29 21:43:58 +00:00
|
|
|
#include <map>
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Module;
|
|
|
|
class OpaqueType;
|
|
|
|
class Function;
|
|
|
|
class Value;
|
|
|
|
class BasicBlock;
|
|
|
|
class Instruction;
|
|
|
|
class Constant;
|
|
|
|
class GlobalValue;
|
2009-04-04 07:22:01 +00:00
|
|
|
class MDString;
|
|
|
|
class MDNode;
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
class StructType;
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
/// ValID - Represents a reference of a definition of some sort with no type.
|
|
|
|
/// There are several cases where we have to parse the value but where the
|
|
|
|
/// type can depend on later context. This may either be a numeric reference
|
|
|
|
/// or a symbolic (%var) reference. This is just a discriminated union.
|
|
|
|
struct ValID {
|
|
|
|
enum {
|
|
|
|
t_LocalID, t_GlobalID, // ID in UIntVal.
|
|
|
|
t_LocalName, t_GlobalName, // Name in StrVal.
|
|
|
|
t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal.
|
|
|
|
t_Null, t_Undef, t_Zero, // No value.
|
|
|
|
t_EmptyArray, // No value: []
|
|
|
|
t_Constant, // Value in ConstantVal.
|
|
|
|
t_InlineAsm, // Value in StrVal/StrVal2/UIntVal.
|
2009-12-30 02:11:14 +00:00
|
|
|
t_MDNode, // Value in MDNodeVal.
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
t_MDString, // Value in MDStringVal.
|
|
|
|
t_ConstantStruct, // Value in ConstantStructElts.
|
|
|
|
t_PackedConstantStruct // Value in ConstantStructElts.
|
2009-10-28 03:39:23 +00:00
|
|
|
} Kind;
|
|
|
|
|
|
|
|
LLLexer::LocTy Loc;
|
|
|
|
unsigned UIntVal;
|
|
|
|
std::string StrVal, StrVal2;
|
|
|
|
APSInt APSIntVal;
|
|
|
|
APFloat APFloatVal;
|
|
|
|
Constant *ConstantVal;
|
2009-12-30 02:11:14 +00:00
|
|
|
MDNode *MDNodeVal;
|
|
|
|
MDString *MDStringVal;
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
Constant **ConstantStructElts;
|
|
|
|
|
|
|
|
ValID() : Kind(t_LocalID), APFloatVal(0.0) {}
|
|
|
|
~ValID() {
|
|
|
|
if (Kind == t_ConstantStruct || Kind == t_PackedConstantStruct)
|
|
|
|
delete [] ConstantStructElts;
|
|
|
|
}
|
2009-10-28 03:39:23 +00:00
|
|
|
|
|
|
|
bool operator<(const ValID &RHS) const {
|
|
|
|
if (Kind == t_LocalID || Kind == t_GlobalID)
|
|
|
|
return UIntVal < RHS.UIntVal;
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
assert((Kind == t_LocalName || Kind == t_GlobalName ||
|
|
|
|
Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) &&
|
2009-10-28 03:39:23 +00:00
|
|
|
"Ordering not defined for this ValID kind yet");
|
|
|
|
return StrVal < RHS.StrVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
class LLParser {
|
|
|
|
public:
|
|
|
|
typedef LLLexer::LocTy LocTy;
|
|
|
|
private:
|
2010-04-07 04:08:57 +00:00
|
|
|
LLVMContext &Context;
|
2009-01-02 07:01:27 +00:00
|
|
|
LLLexer Lex;
|
|
|
|
Module *M;
|
2010-04-01 05:14:45 +00:00
|
|
|
|
|
|
|
// Instruction metadata resolution. Each instruction can have a list of
|
|
|
|
// MDRef info associated with them.
|
2010-08-24 14:31:06 +00:00
|
|
|
//
|
|
|
|
// The simpler approach of just creating temporary MDNodes and then calling
|
|
|
|
// RAUW on them when the definition is processed doesn't work because some
|
|
|
|
// instruction metadata kinds, such as dbg, get stored in the IR in an
|
|
|
|
// "optimized" format which doesn't participate in the normal value use
|
|
|
|
// lists. This means that RAUW doesn't work, even on temporary MDNodes
|
|
|
|
// which otherwise support RAUW. Instead, we defer resolving MDNode
|
|
|
|
// references until the definitions have been processed.
|
2010-04-01 05:14:45 +00:00
|
|
|
struct MDRef {
|
|
|
|
SMLoc Loc;
|
|
|
|
unsigned MDKind, MDSlot;
|
|
|
|
};
|
|
|
|
DenseMap<Instruction*, std::vector<MDRef> > ForwardRefInstMetadata;
|
2009-01-02 22:46:48 +00:00
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
// Type resolution handling data structures. The location is set when we
|
|
|
|
// have processed a use of the type but not a definition yet.
|
|
|
|
StringMap<std::pair<Type*, LocTy> > NamedTypes;
|
|
|
|
std::vector<std::pair<Type*, LocTy> > NumberedTypes;
|
|
|
|
|
2009-12-30 04:51:58 +00:00
|
|
|
std::vector<TrackingVH<MDNode> > NumberedMetadata;
|
2009-12-29 21:43:58 +00:00
|
|
|
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes;
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
// Global Value reference information.
|
|
|
|
std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
|
|
|
|
std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
|
|
|
|
std::vector<GlobalValue*> NumberedVals;
|
2009-10-28 03:39:23 +00:00
|
|
|
|
|
|
|
// References to blockaddress. The key is the function ValID, the value is
|
|
|
|
// a list of references to blocks in that function.
|
|
|
|
std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >
|
|
|
|
ForwardRefBlockAddresses;
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
public:
|
2009-07-02 23:08:13 +00:00
|
|
|
LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) :
|
2009-10-17 00:00:19 +00:00
|
|
|
Context(m->getContext()), Lex(F, SM, Err, m->getContext()),
|
2011-06-17 03:16:47 +00:00
|
|
|
M(m) {}
|
2009-01-04 20:44:11 +00:00
|
|
|
bool Run();
|
2009-01-02 22:46:48 +00:00
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
LLVMContext &getContext() { return Context; }
|
2009-07-02 17:04:01 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
private:
|
|
|
|
|
2010-09-27 17:42:11 +00:00
|
|
|
bool Error(LocTy L, const Twine &Msg) const {
|
2009-01-02 07:01:27 +00:00
|
|
|
return Lex.Error(L, Msg);
|
|
|
|
}
|
2010-09-27 17:42:11 +00:00
|
|
|
bool TokError(const Twine &Msg) const {
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Lex.getLoc(), Msg);
|
|
|
|
}
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// GetGlobalVal - Get a value with the specified name or ID, creating a
|
|
|
|
/// forward reference record if needed. This can return null if the value
|
|
|
|
/// exists but does not have the right type.
|
2011-07-18 04:54:35 +00:00
|
|
|
GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc);
|
|
|
|
GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Helper Routines.
|
|
|
|
bool ParseToken(lltok::Kind T, const char *ErrMsg);
|
2009-01-02 08:05:26 +00:00
|
|
|
bool EatIfPresent(lltok::Kind T) {
|
|
|
|
if (Lex.getKind() != T) return false;
|
|
|
|
Lex.Lex();
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-13 01:30:30 +00:00
|
|
|
bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) {
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Lex.getKind() != T) {
|
|
|
|
Present = false;
|
|
|
|
} else {
|
2011-01-13 01:30:30 +00:00
|
|
|
if (Loc)
|
|
|
|
*Loc = Lex.getLoc();
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
Present = true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-02 08:05:26 +00:00
|
|
|
bool ParseStringConstant(std::string &Result);
|
|
|
|
bool ParseUInt32(unsigned &Val);
|
|
|
|
bool ParseUInt32(unsigned &Val, LocTy &Loc) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Loc = Lex.getLoc();
|
2009-01-02 08:05:26 +00:00
|
|
|
return ParseUInt32(Val);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
bool ParseOptionalAddrSpace(unsigned &AddrSpace);
|
|
|
|
bool ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind);
|
|
|
|
bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage);
|
|
|
|
bool ParseOptionalLinkage(unsigned &Linkage) {
|
|
|
|
bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
|
|
|
|
}
|
|
|
|
bool ParseOptionalVisibility(unsigned &Visibility);
|
2009-09-02 08:44:58 +00:00
|
|
|
bool ParseOptionalCallingConv(CallingConv::ID &CC);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseOptionalAlignment(unsigned &Alignment);
|
2011-07-25 23:16:38 +00:00
|
|
|
bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,
|
|
|
|
AtomicOrdering &Ordering);
|
2010-02-12 00:31:15 +00:00
|
|
|
bool ParseOptionalStackAlignment(unsigned &Alignment);
|
2009-12-30 05:44:30 +00:00
|
|
|
bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma);
|
2009-12-30 05:14:00 +00:00
|
|
|
bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,bool &AteExtraComma);
|
|
|
|
bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
|
|
|
|
bool AteExtraComma;
|
|
|
|
if (ParseIndexList(Indices, AteExtraComma)) return true;
|
|
|
|
if (AteExtraComma)
|
|
|
|
return TokError("expected index");
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Top-Level Entities
|
|
|
|
bool ParseTopLevelEntities();
|
|
|
|
bool ValidateEndOfModule();
|
|
|
|
bool ParseTargetDefinition();
|
|
|
|
bool ParseDepLibs();
|
|
|
|
bool ParseModuleAsm();
|
|
|
|
bool ParseUnnamedType();
|
|
|
|
bool ParseNamedType();
|
|
|
|
bool ParseDeclare();
|
|
|
|
bool ParseDefine();
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseGlobalType(bool &IsConstant);
|
2009-08-12 23:32:33 +00:00
|
|
|
bool ParseUnnamedGlobal();
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseNamedGlobal();
|
|
|
|
bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage,
|
|
|
|
bool HasLinkage, unsigned Visibility);
|
|
|
|
bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
|
2009-07-01 19:21:12 +00:00
|
|
|
bool ParseStandaloneMetadata();
|
2009-07-29 00:34:02 +00:00
|
|
|
bool ParseNamedMetadata();
|
2009-12-29 21:53:55 +00:00
|
|
|
bool ParseMDString(MDString *&Result);
|
2009-12-30 04:15:23 +00:00
|
|
|
bool ParseMDNodeID(MDNode *&Result);
|
2010-04-01 05:14:45 +00:00
|
|
|
bool ParseMDNodeID(MDNode *&Result, unsigned &SlotNo);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Type Parsing.
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
bool ParseType(Type *&Result, bool AllowVoid = false);
|
|
|
|
bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Loc = Lex.getLoc();
|
2009-03-09 04:49:14 +00:00
|
|
|
return ParseType(Result, AllowVoid);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
bool ParseAnonStructType(Type *&Result, bool Packed);
|
|
|
|
bool ParseStructBody(SmallVectorImpl<Type*> &Body);
|
|
|
|
bool ParseStructDefinition(SMLoc TypeLoc, StringRef Name,
|
|
|
|
std::pair<Type*, LocTy> &Entry,
|
|
|
|
Type *&ResultTy);
|
|
|
|
|
|
|
|
bool ParseArrayVectorType(Type *&Result, bool isVector);
|
|
|
|
bool ParseFunctionType(Type *&Result);
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
// Function Semantic Analysis.
|
|
|
|
class PerFunctionState {
|
|
|
|
LLParser &P;
|
|
|
|
Function &F;
|
|
|
|
std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
|
|
|
|
std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
|
|
|
|
std::vector<Value*> NumberedVals;
|
2009-10-28 03:39:23 +00:00
|
|
|
|
|
|
|
/// FunctionNumber - If this is an unnamed function, this is the slot
|
|
|
|
/// number of it, otherwise it is -1.
|
|
|
|
int FunctionNumber;
|
2009-01-02 07:01:27 +00:00
|
|
|
public:
|
2009-10-28 03:39:23 +00:00
|
|
|
PerFunctionState(LLParser &p, Function &f, int FunctionNumber);
|
2009-01-02 07:01:27 +00:00
|
|
|
~PerFunctionState();
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Function &getFunction() const { return F; }
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
bool FinishFunction();
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// GetVal - Get a value with the specified name or ID, creating a
|
|
|
|
/// forward reference record if needed. This can return null if the value
|
|
|
|
/// exists but does not have the right type.
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc);
|
|
|
|
Value *GetVal(unsigned ID, Type *Ty, LocTy Loc);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// SetInstName - After an instruction is parsed and inserted into its
|
|
|
|
/// basic block, this installs its name.
|
|
|
|
bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
|
|
|
|
Instruction *Inst);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// GetBB - Get a basic block with the specified name or ID, creating a
|
|
|
|
/// forward reference record if needed. This can return null if the value
|
|
|
|
/// is not a BasicBlock.
|
|
|
|
BasicBlock *GetBB(const std::string &Name, LocTy Loc);
|
|
|
|
BasicBlock *GetBB(unsigned ID, LocTy Loc);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// DefineBB - Define the specified basic block, which is either named or
|
|
|
|
/// unnamed. If there is an error, this returns null otherwise it returns
|
|
|
|
/// the block being defined.
|
|
|
|
BasicBlock *DefineBB(const std::string &Name, LocTy Loc);
|
|
|
|
};
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
|
2010-01-11 22:31:58 +00:00
|
|
|
PerFunctionState *PFS);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
|
|
|
|
bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
return ParseValue(Ty, V, &PFS);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
bool ParseValue(Type *Ty, Value *&V, LocTy &Loc,
|
2009-01-02 07:01:27 +00:00
|
|
|
PerFunctionState &PFS) {
|
|
|
|
Loc = Lex.getLoc();
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
return ParseValue(Ty, V, &PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-01-02 22:46:48 +00:00
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS);
|
|
|
|
bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
|
|
|
|
return ParseTypeAndValue(V, &PFS);
|
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
|
|
|
|
Loc = Lex.getLoc();
|
|
|
|
return ParseTypeAndValue(V, PFS);
|
|
|
|
}
|
2009-10-27 19:13:16 +00:00
|
|
|
bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
|
|
|
|
PerFunctionState &PFS);
|
|
|
|
bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
|
|
|
|
LocTy Loc;
|
|
|
|
return ParseTypeAndBasicBlock(BB, Loc, PFS);
|
|
|
|
}
|
2009-12-03 23:40:58 +00:00
|
|
|
|
2010-02-12 20:49:41 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
struct ParamInfo {
|
|
|
|
LocTy Loc;
|
|
|
|
Value *V;
|
|
|
|
unsigned Attrs;
|
2009-01-02 22:46:48 +00:00
|
|
|
ParamInfo(LocTy loc, Value *v, unsigned attrs)
|
2009-01-02 07:01:27 +00:00
|
|
|
: Loc(loc), V(v), Attrs(attrs) {}
|
|
|
|
};
|
|
|
|
bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
|
|
|
|
PerFunctionState &PFS);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2010-01-05 22:22:14 +00:00
|
|
|
// Constant Parsing.
|
|
|
|
bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL);
|
2011-07-18 04:54:35 +00:00
|
|
|
bool ParseGlobalValue(Type *Ty, Constant *&V);
|
2010-01-05 22:22:14 +00:00
|
|
|
bool ParseGlobalTypeAndValue(Constant *&V);
|
|
|
|
bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts);
|
2010-08-24 02:24:03 +00:00
|
|
|
bool ParseMetadataListValue(ValID &ID, PerFunctionState *PFS);
|
2010-07-14 18:26:50 +00:00
|
|
|
bool ParseMetadataValue(ValID &ID, PerFunctionState *PFS);
|
2010-01-10 07:14:18 +00:00
|
|
|
bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS);
|
2010-08-24 02:05:17 +00:00
|
|
|
bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);
|
2010-01-05 22:22:14 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Function Parsing.
|
|
|
|
struct ArgInfo {
|
|
|
|
LocTy Loc;
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
Type *Ty;
|
2009-01-02 07:01:27 +00:00
|
|
|
unsigned Attrs;
|
|
|
|
std::string Name;
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
ArgInfo(LocTy L, Type *ty, unsigned Attr, const std::string &N)
|
|
|
|
: Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
|
2009-01-02 07:01:27 +00:00
|
|
|
};
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseFunctionHeader(Function *&Fn, bool isDefine);
|
|
|
|
bool ParseFunctionBody(Function &Fn);
|
|
|
|
bool ParseBasicBlock(PerFunctionState &PFS);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-12-30 05:23:43 +00:00
|
|
|
// Instruction Parsing. Each instruction parsing routine can return with a
|
|
|
|
// normal result, an error result, or return having eaten an extra comma.
|
|
|
|
enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
|
|
|
|
int ParseInstruction(Instruction *&Inst, BasicBlock *BB,
|
|
|
|
PerFunctionState &PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseCmpPredicate(unsigned &Pred, unsigned Opc);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2011-06-17 06:49:41 +00:00
|
|
|
bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
|
|
|
|
bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
|
2009-10-28 00:19:10 +00:00
|
|
|
bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
|
2011-07-31 06:30:59 +00:00
|
|
|
bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
|
2009-01-02 22:46:48 +00:00
|
|
|
|
2009-01-05 08:24:46 +00:00
|
|
|
bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
|
|
|
|
unsigned OperandType);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
|
|
|
|
bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
|
|
|
|
bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
|
|
|
|
bool ParseSelect(Instruction *&I, PerFunctionState &PFS);
|
2009-01-05 08:18:44 +00:00
|
|
|
bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS);
|
|
|
|
bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS);
|
|
|
|
bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS);
|
2009-12-30 05:27:33 +00:00
|
|
|
int ParsePHI(Instruction *&I, PerFunctionState &PFS);
|
2011-08-12 20:24:12 +00:00
|
|
|
bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail);
|
2011-06-17 03:16:47 +00:00
|
|
|
int ParseAlloc(Instruction *&I, PerFunctionState &PFS);
|
2011-08-12 22:50:01 +00:00
|
|
|
int ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile);
|
|
|
|
int ParseStore(Instruction *&I, PerFunctionState &PFS, bool isVolatile);
|
|
|
|
int ParseCmpXchg(Instruction *&I, PerFunctionState &PFS);
|
|
|
|
int ParseAtomicRMW(Instruction *&I, PerFunctionState &PFS);
|
2011-07-25 23:16:38 +00:00
|
|
|
int ParseFence(Instruction *&I, PerFunctionState &PFS);
|
2009-12-30 05:27:33 +00:00
|
|
|
int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS);
|
|
|
|
int ParseExtractValue(Instruction *&I, PerFunctionState &PFS);
|
|
|
|
int ParseInsertValue(Instruction *&I, PerFunctionState &PFS);
|
2009-10-28 03:39:23 +00:00
|
|
|
|
|
|
|
bool ResolveForwardRefBlockAddresses(Function *TheFn,
|
|
|
|
std::vector<std::pair<ValID, GlobalValue*> > &Refs,
|
|
|
|
PerFunctionState *PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
};
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|