2009-01-02 07:01:27 +00:00
|
|
|
//===-- LLParser.cpp - Parser Class ---------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LLParser.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-01-02 07:01:27 +00:00
|
|
|
#include "llvm/AutoUpgrade.h"
|
|
|
|
#include "llvm/CallingConv.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/InlineAsm.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Module.h"
|
2009-07-20 21:19:07 +00:00
|
|
|
#include "llvm/Operator.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-01-02 07:01:27 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ValueSymbolTable.h"
|
2009-01-02 07:01:27 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
static std::string getTypeString(Type *T) {
|
2011-06-18 21:18:23 +00:00
|
|
|
std::string Result;
|
|
|
|
raw_string_ostream Tmp(Result);
|
|
|
|
Tmp << *T;
|
|
|
|
return Tmp.str();
|
|
|
|
}
|
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
/// Run: module ::= toplevelentity*
|
2009-01-04 20:44:11 +00:00
|
|
|
bool LLParser::Run() {
|
2009-01-02 08:05:26 +00:00
|
|
|
// Prime the lexer.
|
|
|
|
Lex.Lex();
|
|
|
|
|
2009-01-04 20:44:11 +00:00
|
|
|
return ParseTopLevelEntities() ||
|
|
|
|
ValidateEndOfModule();
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ValidateEndOfModule - Do final validity and sanity checks at the end of the
|
|
|
|
/// module.
|
|
|
|
bool LLParser::ValidateEndOfModule() {
|
2010-04-01 05:14:45 +00:00
|
|
|
// Handle any instruction metadata forward references.
|
|
|
|
if (!ForwardRefInstMetadata.empty()) {
|
|
|
|
for (DenseMap<Instruction*, std::vector<MDRef> >::iterator
|
|
|
|
I = ForwardRefInstMetadata.begin(), E = ForwardRefInstMetadata.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Instruction *Inst = I->first;
|
|
|
|
const std::vector<MDRef> &MDList = I->second;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2010-04-01 05:14:45 +00:00
|
|
|
for (unsigned i = 0, e = MDList.size(); i != e; ++i) {
|
|
|
|
unsigned SlotNo = MDList[i].MDSlot;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2010-04-01 05:14:45 +00:00
|
|
|
if (SlotNo >= NumberedMetadata.size() || NumberedMetadata[SlotNo] == 0)
|
|
|
|
return Error(MDList[i].Loc, "use of undefined metadata '!" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(SlotNo) + "'");
|
2010-04-01 05:14:45 +00:00
|
|
|
Inst->setMetadata(MDList[i].MDKind, NumberedMetadata[SlotNo]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ForwardRefInstMetadata.clear();
|
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
// If there are entries in ForwardRefBlockAddresses at this point, they are
|
|
|
|
// references after the function was defined. Resolve those now.
|
|
|
|
while (!ForwardRefBlockAddresses.empty()) {
|
|
|
|
// Okay, we are referencing an already-parsed function, resolve them now.
|
|
|
|
Function *TheFn = 0;
|
|
|
|
const ValID &Fn = ForwardRefBlockAddresses.begin()->first;
|
|
|
|
if (Fn.Kind == ValID::t_GlobalName)
|
|
|
|
TheFn = M->getFunction(Fn.StrVal);
|
|
|
|
else if (Fn.UIntVal < NumberedVals.size())
|
|
|
|
TheFn = dyn_cast<Function>(NumberedVals[Fn.UIntVal]);
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
if (TheFn == 0)
|
|
|
|
return Error(Fn.Loc, "unknown function referenced by blockaddress");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
// Resolve all these references.
|
2012-11-15 22:34:00 +00:00
|
|
|
if (ResolveForwardRefBlockAddresses(TheFn,
|
2009-10-28 03:39:23 +00:00
|
|
|
ForwardRefBlockAddresses.begin()->second,
|
|
|
|
0))
|
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
ForwardRefBlockAddresses.erase(ForwardRefBlockAddresses.begin());
|
|
|
|
}
|
2012-11-15 22:34:00 +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
|
|
|
for (unsigned i = 0, e = NumberedTypes.size(); i != e; ++i)
|
|
|
|
if (NumberedTypes[i].second.isValid())
|
|
|
|
return Error(NumberedTypes[i].second,
|
|
|
|
"use of undefined type '%" + Twine(i) + "'");
|
|
|
|
|
|
|
|
for (StringMap<std::pair<Type*, LocTy> >::iterator I =
|
|
|
|
NamedTypes.begin(), E = NamedTypes.end(); I != E; ++I)
|
|
|
|
if (I->second.second.isValid())
|
|
|
|
return Error(I->second.second,
|
|
|
|
"use of undefined type named '" + I->getKey() + "'");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!ForwardRefVals.empty())
|
|
|
|
return Error(ForwardRefVals.begin()->second.second,
|
|
|
|
"use of undefined value '@" + ForwardRefVals.begin()->first +
|
|
|
|
"'");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!ForwardRefValIDs.empty())
|
|
|
|
return Error(ForwardRefValIDs.begin()->second.second,
|
|
|
|
"use of undefined value '@" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(ForwardRefValIDs.begin()->first) + "'");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-07-08 19:23:54 +00:00
|
|
|
if (!ForwardRefMDNodes.empty())
|
|
|
|
return Error(ForwardRefMDNodes.begin()->second.second,
|
|
|
|
"use of undefined metadata '!" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(ForwardRefMDNodes.begin()->first) + "'");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-07-08 19:23:54 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Look for intrinsic functions and CallInst that need to be upgraded
|
|
|
|
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
|
|
|
|
UpgradeCallsToIntrinsic(FI++); // must be post-increment, as we remove
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-15 22:34:00 +00:00
|
|
|
bool LLParser::ResolveForwardRefBlockAddresses(Function *TheFn,
|
2009-10-28 03:39:23 +00:00
|
|
|
std::vector<std::pair<ValID, GlobalValue*> > &Refs,
|
|
|
|
PerFunctionState *PFS) {
|
|
|
|
// Loop over all the references, resolving them.
|
|
|
|
for (unsigned i = 0, e = Refs.size(); i != e; ++i) {
|
|
|
|
BasicBlock *Res;
|
2009-11-01 01:27:45 +00:00
|
|
|
if (PFS) {
|
2009-10-28 03:39:23 +00:00
|
|
|
if (Refs[i].first.Kind == ValID::t_LocalName)
|
|
|
|
Res = PFS->GetBB(Refs[i].first.StrVal, Refs[i].first.Loc);
|
2009-11-01 01:27:45 +00:00
|
|
|
else
|
2009-10-28 03:39:23 +00:00
|
|
|
Res = PFS->GetBB(Refs[i].first.UIntVal, Refs[i].first.Loc);
|
|
|
|
} else if (Refs[i].first.Kind == ValID::t_LocalID) {
|
|
|
|
return Error(Refs[i].first.Loc,
|
2009-11-02 18:28:45 +00:00
|
|
|
"cannot take address of numeric label after the function is defined");
|
2009-10-28 03:39:23 +00:00
|
|
|
} else {
|
|
|
|
Res = dyn_cast_or_null<BasicBlock>(
|
|
|
|
TheFn->getValueSymbolTable().lookup(Refs[i].first.StrVal));
|
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-11-01 01:27:45 +00:00
|
|
|
if (Res == 0)
|
2009-10-28 03:39:23 +00:00
|
|
|
return Error(Refs[i].first.Loc,
|
|
|
|
"referenced value is not a basic block");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
// Get the BlockAddress for this and update references to use it.
|
|
|
|
BlockAddress *BA = BlockAddress::get(TheFn, Res);
|
|
|
|
Refs[i].second->replaceAllUsesWith(BA);
|
|
|
|
Refs[i].second->eraseFromParent();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top-Level Entities
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool LLParser::ParseTopLevelEntities() {
|
|
|
|
while (1) {
|
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: return TokError("expected top-level entity");
|
|
|
|
case lltok::Eof: return false;
|
|
|
|
case lltok::kw_declare: if (ParseDeclare()) return true; break;
|
|
|
|
case lltok::kw_define: if (ParseDefine()) return true; break;
|
|
|
|
case lltok::kw_module: if (ParseModuleAsm()) return true; break;
|
|
|
|
case lltok::kw_target: if (ParseTargetDefinition()) return true; break;
|
2012-11-28 08:41:48 +00:00
|
|
|
case lltok::kw_deplibs: if (ParseDepLibs()) return true; break;
|
2009-08-12 23:32:33 +00:00
|
|
|
case lltok::LocalVarID: if (ParseUnnamedType()) return true; break;
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::LocalVar: if (ParseNamedType()) return true; break;
|
2009-08-12 23:32:33 +00:00
|
|
|
case lltok::GlobalID: if (ParseUnnamedGlobal()) return true; break;
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::GlobalVar: if (ParseNamedGlobal()) return true; break;
|
2009-12-30 04:56:59 +00:00
|
|
|
case lltok::exclaim: if (ParseStandaloneMetadata()) return true; break;
|
2009-12-30 05:02:06 +00:00
|
|
|
case lltok::MetadataVar: if (ParseNamedMetadata()) return true; break;
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
// The Global variable production with no name can have many different
|
|
|
|
// optional leading prefixes, the production is:
|
|
|
|
// GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
|
2011-01-08 16:42:36 +00:00
|
|
|
// OptionalAddrSpace OptionalUnNammedAddr
|
|
|
|
// ('constant'|'global') ...
|
2010-07-01 21:55:59 +00:00
|
|
|
case lltok::kw_private: // OptionalLinkage
|
|
|
|
case lltok::kw_linker_private: // OptionalLinkage
|
|
|
|
case lltok::kw_linker_private_weak: // OptionalLinkage
|
2012-08-17 18:33:14 +00:00
|
|
|
case lltok::kw_linker_private_weak_def_auto: // FIXME: backwards compat.
|
2010-07-01 21:55:59 +00:00
|
|
|
case lltok::kw_internal: // OptionalLinkage
|
|
|
|
case lltok::kw_weak: // OptionalLinkage
|
|
|
|
case lltok::kw_weak_odr: // OptionalLinkage
|
|
|
|
case lltok::kw_linkonce: // OptionalLinkage
|
|
|
|
case lltok::kw_linkonce_odr: // OptionalLinkage
|
2012-08-17 18:33:14 +00:00
|
|
|
case lltok::kw_linkonce_odr_auto_hide: // OptionalLinkage
|
2010-07-01 21:55:59 +00:00
|
|
|
case lltok::kw_appending: // OptionalLinkage
|
|
|
|
case lltok::kw_dllexport: // OptionalLinkage
|
|
|
|
case lltok::kw_common: // OptionalLinkage
|
|
|
|
case lltok::kw_dllimport: // OptionalLinkage
|
|
|
|
case lltok::kw_extern_weak: // OptionalLinkage
|
|
|
|
case lltok::kw_external: { // OptionalLinkage
|
2009-01-02 07:01:27 +00:00
|
|
|
unsigned Linkage, Visibility;
|
|
|
|
if (ParseOptionalLinkage(Linkage) ||
|
|
|
|
ParseOptionalVisibility(Visibility) ||
|
2009-07-02 23:08:13 +00:00
|
|
|
ParseGlobal("", SMLoc(), Linkage, true, Visibility))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case lltok::kw_default: // OptionalVisibility
|
|
|
|
case lltok::kw_hidden: // OptionalVisibility
|
|
|
|
case lltok::kw_protected: { // OptionalVisibility
|
|
|
|
unsigned Visibility;
|
|
|
|
if (ParseOptionalVisibility(Visibility) ||
|
2009-07-02 23:08:13 +00:00
|
|
|
ParseGlobal("", SMLoc(), 0, false, Visibility))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_thread_local: // OptionalThreadLocal
|
|
|
|
case lltok::kw_addrspace: // OptionalAddrSpace
|
|
|
|
case lltok::kw_constant: // GlobalType
|
|
|
|
case lltok::kw_global: // GlobalType
|
2009-07-02 23:08:13 +00:00
|
|
|
if (ParseGlobal("", SMLoc(), 0, false, 0)) return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// toplevelentity
|
|
|
|
/// ::= 'module' 'asm' STRINGCONSTANT
|
|
|
|
bool LLParser::ParseModuleAsm() {
|
|
|
|
assert(Lex.getKind() == lltok::kw_module);
|
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
|
|
|
std::string AsmStr;
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseToken(lltok::kw_asm, "expected 'module asm'") ||
|
|
|
|
ParseStringConstant(AsmStr)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-03-02 04:14:42 +00:00
|
|
|
M->appendModuleInlineAsm(AsmStr);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// toplevelentity
|
|
|
|
/// ::= 'target' 'triple' '=' STRINGCONSTANT
|
|
|
|
/// ::= 'target' 'datalayout' '=' STRINGCONSTANT
|
|
|
|
bool LLParser::ParseTargetDefinition() {
|
|
|
|
assert(Lex.getKind() == lltok::kw_target);
|
2009-01-02 08:05:26 +00:00
|
|
|
std::string Str;
|
2009-01-02 07:01:27 +00:00
|
|
|
switch (Lex.Lex()) {
|
|
|
|
default: return TokError("unknown target property");
|
|
|
|
case lltok::kw_triple:
|
|
|
|
Lex.Lex();
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseToken(lltok::equal, "expected '=' after target triple") ||
|
|
|
|
ParseStringConstant(Str))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-01-02 08:05:26 +00:00
|
|
|
M->setTargetTriple(Str);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
case lltok::kw_datalayout:
|
|
|
|
Lex.Lex();
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseToken(lltok::equal, "expected '=' after target datalayout") ||
|
|
|
|
ParseStringConstant(Str))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-01-02 08:05:26 +00:00
|
|
|
M->setDataLayout(Str);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 08:41:48 +00:00
|
|
|
/// toplevelentity
|
|
|
|
/// ::= 'deplibs' '=' '[' ']'
|
|
|
|
/// ::= 'deplibs' '=' '[' STRINGCONSTANT (',' STRINGCONSTANT)* ']'
|
|
|
|
/// FIXME: Remove in 4.0. Currently parse, but ignore.
|
|
|
|
bool LLParser::ParseDepLibs() {
|
|
|
|
assert(Lex.getKind() == lltok::kw_deplibs);
|
|
|
|
Lex.Lex();
|
|
|
|
if (ParseToken(lltok::equal, "expected '=' after deplibs") ||
|
|
|
|
ParseToken(lltok::lsquare, "expected '=' after deplibs"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (EatIfPresent(lltok::rsquare))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
do {
|
|
|
|
std::string Str;
|
|
|
|
if (ParseStringConstant(Str)) return true;
|
|
|
|
} while (EatIfPresent(lltok::comma));
|
|
|
|
|
|
|
|
return ParseToken(lltok::rsquare, "expected ']' at end of list");
|
|
|
|
}
|
|
|
|
|
2009-08-12 23:32:33 +00:00
|
|
|
/// ParseUnnamedType:
|
|
|
|
/// ::= LocalVarID '=' 'type' type
|
2009-01-02 07:01:27 +00:00
|
|
|
bool LLParser::ParseUnnamedType() {
|
2011-06-19 00:03:46 +00:00
|
|
|
LocTy TypeLoc = 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
|
|
|
unsigned TypeID = Lex.getUIntVal();
|
2011-06-19 00:03:46 +00:00
|
|
|
Lex.Lex(); // eat LocalVarID;
|
2009-08-12 23:32:33 +00:00
|
|
|
|
2011-06-19 00:03:46 +00:00
|
|
|
if (ParseToken(lltok::equal, "expected '=' after name") ||
|
|
|
|
ParseToken(lltok::kw_type, "expected 'type' after '='"))
|
|
|
|
return true;
|
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
|
|
|
if (TypeID >= NumberedTypes.size())
|
|
|
|
NumberedTypes.resize(TypeID+1);
|
2012-11-15 22:34:00 +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 *Result = 0;
|
|
|
|
if (ParseStructDefinition(TypeLoc, "",
|
|
|
|
NumberedTypes[TypeID], Result)) return true;
|
2012-11-15 22:34:00 +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
|
|
|
if (!isa<StructType>(Result)) {
|
|
|
|
std::pair<Type*, LocTy> &Entry = NumberedTypes[TypeID];
|
|
|
|
if (Entry.first)
|
|
|
|
return Error(TypeLoc, "non-struct types may not be recursive");
|
|
|
|
Entry.first = Result;
|
|
|
|
Entry.second = SMLoc();
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// toplevelentity
|
|
|
|
/// ::= LocalVar '=' 'type' type
|
|
|
|
bool LLParser::ParseNamedType() {
|
|
|
|
std::string Name = Lex.getStrVal();
|
|
|
|
LocTy NameLoc = Lex.getLoc();
|
2009-01-02 08:05:26 +00:00
|
|
|
Lex.Lex(); // eat LocalVar.
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseToken(lltok::equal, "expected '=' after 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
|
|
|
ParseToken(lltok::kw_type, "expected 'type' after name"))
|
2009-01-02 08:05:26 +00:00
|
|
|
return true;
|
2012-11-15 22:34:00 +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 *Result = 0;
|
|
|
|
if (ParseStructDefinition(NameLoc, Name,
|
|
|
|
NamedTypes[Name], Result)) return true;
|
2012-11-15 22:34:00 +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
|
|
|
if (!isa<StructType>(Result)) {
|
|
|
|
std::pair<Type*, LocTy> &Entry = NamedTypes[Name];
|
|
|
|
if (Entry.first)
|
|
|
|
return Error(NameLoc, "non-struct types may not be recursive");
|
|
|
|
Entry.first = Result;
|
|
|
|
Entry.second = SMLoc();
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2012-11-15 22:34:00 +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
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// toplevelentity
|
|
|
|
/// ::= 'declare' FunctionHeader
|
|
|
|
bool LLParser::ParseDeclare() {
|
|
|
|
assert(Lex.getKind() == lltok::kw_declare);
|
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Function *F;
|
|
|
|
return ParseFunctionHeader(F, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// toplevelentity
|
|
|
|
/// ::= 'define' FunctionHeader '{' ...
|
|
|
|
bool LLParser::ParseDefine() {
|
|
|
|
assert(Lex.getKind() == lltok::kw_define);
|
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Function *F;
|
2009-01-02 08:05:26 +00:00
|
|
|
return ParseFunctionHeader(F, true) ||
|
|
|
|
ParseFunctionBody(*F);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
/// ParseGlobalType
|
|
|
|
/// ::= 'constant'
|
|
|
|
/// ::= 'global'
|
2009-01-02 07:01:27 +00:00
|
|
|
bool LLParser::ParseGlobalType(bool &IsConstant) {
|
|
|
|
if (Lex.getKind() == lltok::kw_constant)
|
|
|
|
IsConstant = true;
|
|
|
|
else if (Lex.getKind() == lltok::kw_global)
|
|
|
|
IsConstant = false;
|
2009-02-10 16:24:55 +00:00
|
|
|
else {
|
|
|
|
IsConstant = false;
|
2009-01-02 07:01:27 +00:00
|
|
|
return TokError("expected 'global' or 'constant'");
|
2009-02-10 16:24:55 +00:00
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-12 23:32:33 +00:00
|
|
|
/// ParseUnnamedGlobal:
|
|
|
|
/// OptionalVisibility ALIAS ...
|
|
|
|
/// OptionalLinkage OptionalVisibility ... -> global variable
|
|
|
|
/// GlobalID '=' OptionalVisibility ALIAS ...
|
|
|
|
/// GlobalID '=' OptionalLinkage OptionalVisibility ... -> global variable
|
|
|
|
bool LLParser::ParseUnnamedGlobal() {
|
|
|
|
unsigned VarID = NumberedVals.size();
|
|
|
|
std::string Name;
|
|
|
|
LocTy NameLoc = Lex.getLoc();
|
|
|
|
|
|
|
|
// Handle the GlobalID form.
|
|
|
|
if (Lex.getKind() == lltok::GlobalID) {
|
|
|
|
if (Lex.getUIntVal() != VarID)
|
|
|
|
return Error(Lex.getLoc(), "variable expected to be numbered '%" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(VarID) + "'");
|
2009-08-12 23:32:33 +00:00
|
|
|
Lex.Lex(); // eat GlobalID;
|
|
|
|
|
|
|
|
if (ParseToken(lltok::equal, "expected '=' after name"))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasLinkage;
|
|
|
|
unsigned Linkage, Visibility;
|
|
|
|
if (ParseOptionalLinkage(Linkage, HasLinkage) ||
|
|
|
|
ParseOptionalVisibility(Visibility))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-08-12 23:32:33 +00:00
|
|
|
if (HasLinkage || Lex.getKind() != lltok::kw_alias)
|
|
|
|
return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
|
|
|
|
return ParseAlias(Name, NameLoc, Visibility);
|
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseNamedGlobal:
|
|
|
|
/// GlobalVar '=' OptionalVisibility ALIAS ...
|
|
|
|
/// GlobalVar '=' OptionalLinkage OptionalVisibility ... -> global variable
|
|
|
|
bool LLParser::ParseNamedGlobal() {
|
|
|
|
assert(Lex.getKind() == lltok::GlobalVar);
|
|
|
|
LocTy NameLoc = Lex.getLoc();
|
|
|
|
std::string Name = Lex.getStrVal();
|
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
bool HasLinkage;
|
|
|
|
unsigned Linkage, Visibility;
|
|
|
|
if (ParseToken(lltok::equal, "expected '=' in global variable") ||
|
|
|
|
ParseOptionalLinkage(Linkage, HasLinkage) ||
|
|
|
|
ParseOptionalVisibility(Visibility))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (HasLinkage || Lex.getKind() != lltok::kw_alias)
|
|
|
|
return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
|
|
|
|
return ParseAlias(Name, NameLoc, Visibility);
|
|
|
|
}
|
|
|
|
|
2009-07-20 19:00:08 +00:00
|
|
|
// MDString:
|
|
|
|
// ::= '!' STRINGCONSTANT
|
2009-12-29 21:53:55 +00:00
|
|
|
bool LLParser::ParseMDString(MDString *&Result) {
|
2009-07-20 19:00:08 +00:00
|
|
|
std::string Str;
|
|
|
|
if (ParseStringConstant(Str)) return true;
|
2009-12-29 21:53:55 +00:00
|
|
|
Result = MDString::get(Context, Str);
|
2009-07-20 19:00:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MDNode:
|
|
|
|
// ::= '!' MDNodeNumber
|
2010-04-01 05:14:45 +00:00
|
|
|
//
|
|
|
|
/// This version of ParseMDNodeID returns the slot number and null in the case
|
|
|
|
/// of a forward reference.
|
|
|
|
bool LLParser::ParseMDNodeID(MDNode *&Result, unsigned &SlotNo) {
|
|
|
|
// !{ ..., !42, ... }
|
|
|
|
if (ParseUInt32(SlotNo)) return true;
|
|
|
|
|
|
|
|
// Check existing MDNode.
|
|
|
|
if (SlotNo < NumberedMetadata.size() && NumberedMetadata[SlotNo] != 0)
|
|
|
|
Result = NumberedMetadata[SlotNo];
|
|
|
|
else
|
|
|
|
Result = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-30 04:15:23 +00:00
|
|
|
bool LLParser::ParseMDNodeID(MDNode *&Result) {
|
2009-07-20 19:00:08 +00:00
|
|
|
// !{ ..., !42, ... }
|
|
|
|
unsigned MID = 0;
|
2010-04-01 05:14:45 +00:00
|
|
|
if (ParseMDNodeID(Result, MID)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2010-04-01 05:14:45 +00:00
|
|
|
// If not a forward reference, just return it now.
|
|
|
|
if (Result) return false;
|
2009-07-20 19:00:08 +00:00
|
|
|
|
2010-04-01 05:14:45 +00:00
|
|
|
// Otherwise, create MDNode forward reference.
|
2011-04-21 19:59:31 +00:00
|
|
|
MDNode *FwdNode = MDNode::getTemporary(Context, ArrayRef<Value*>());
|
2009-07-20 19:00:08 +00:00
|
|
|
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-12-30 04:51:58 +00:00
|
|
|
if (NumberedMetadata.size() <= MID)
|
|
|
|
NumberedMetadata.resize(MID+1);
|
|
|
|
NumberedMetadata[MID] = FwdNode;
|
2009-12-29 21:53:55 +00:00
|
|
|
Result = FwdNode;
|
2009-07-20 19:00:08 +00:00
|
|
|
return false;
|
2009-09-20 02:20:51 +00:00
|
|
|
}
|
2009-07-20 19:00:08 +00:00
|
|
|
|
2009-12-29 22:35:39 +00:00
|
|
|
/// ParseNamedMetadata:
|
2009-07-29 00:34:02 +00:00
|
|
|
/// !foo = !{ !1, !2 }
|
|
|
|
bool LLParser::ParseNamedMetadata() {
|
2009-12-30 05:02:06 +00:00
|
|
|
assert(Lex.getKind() == lltok::MetadataVar);
|
2009-07-29 00:34:02 +00:00
|
|
|
std::string Name = Lex.getStrVal();
|
2009-12-30 05:02:06 +00:00
|
|
|
Lex.Lex();
|
2009-07-29 00:34:02 +00:00
|
|
|
|
2009-12-29 22:35:39 +00:00
|
|
|
if (ParseToken(lltok::equal, "expected '=' here") ||
|
2009-12-30 04:56:59 +00:00
|
|
|
ParseToken(lltok::exclaim, "Expected '!' here") ||
|
2009-12-29 22:35:39 +00:00
|
|
|
ParseToken(lltok::lbrace, "Expected '{' here"))
|
2009-07-29 00:34:02 +00:00
|
|
|
return true;
|
|
|
|
|
2010-07-21 23:38:33 +00:00
|
|
|
NamedMDNode *NMD = M->getOrInsertNamedMetadata(Name);
|
2010-07-13 19:42:44 +00:00
|
|
|
if (Lex.getKind() != lltok::rbrace)
|
|
|
|
do {
|
|
|
|
if (ParseToken(lltok::exclaim, "Expected '!' here"))
|
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2010-07-13 19:42:44 +00:00
|
|
|
MDNode *N = 0;
|
|
|
|
if (ParseMDNodeID(N)) return true;
|
2010-07-21 23:38:33 +00:00
|
|
|
NMD->addOperand(N);
|
2010-07-13 19:42:44 +00:00
|
|
|
} while (EatIfPresent(lltok::comma));
|
2009-07-29 00:34:02 +00:00
|
|
|
|
|
|
|
if (ParseToken(lltok::rbrace, "expected end of metadata node"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-01 19:21:12 +00:00
|
|
|
/// ParseStandaloneMetadata:
|
2009-09-20 02:20:51 +00:00
|
|
|
/// !42 = !{...}
|
2009-07-01 19:21:12 +00:00
|
|
|
bool LLParser::ParseStandaloneMetadata() {
|
2009-12-30 04:56:59 +00:00
|
|
|
assert(Lex.getKind() == lltok::exclaim);
|
2009-07-01 19:21:12 +00:00
|
|
|
Lex.Lex();
|
|
|
|
unsigned MetadataID = 0;
|
|
|
|
|
|
|
|
LocTy TyLoc;
|
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 = 0;
|
2009-07-23 01:07:34 +00:00
|
|
|
SmallVector<Value *, 16> Elts;
|
2009-12-29 22:40:21 +00:00
|
|
|
if (ParseUInt32(MetadataID) ||
|
|
|
|
ParseToken(lltok::equal, "expected '=' here") ||
|
|
|
|
ParseType(Ty, TyLoc) ||
|
2009-12-30 04:56:59 +00:00
|
|
|
ParseToken(lltok::exclaim, "Expected '!' here") ||
|
2009-12-29 22:40:21 +00:00
|
|
|
ParseToken(lltok::lbrace, "Expected '{' here") ||
|
2010-01-10 07:14:18 +00:00
|
|
|
ParseMDNodeVector(Elts, NULL) ||
|
2009-12-29 22:40:21 +00:00
|
|
|
ParseToken(lltok::rbrace, "expected end of metadata node"))
|
2009-07-23 01:07:34 +00:00
|
|
|
return true;
|
|
|
|
|
2011-04-21 19:59:31 +00:00
|
|
|
MDNode *Init = MDNode::get(Context, Elts);
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-12-30 04:51:58 +00:00
|
|
|
// See if this was forward referenced, if so, handle it.
|
2009-12-29 21:43:58 +00:00
|
|
|
std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> >::iterator
|
2009-07-08 19:23:54 +00:00
|
|
|
FI = ForwardRefMDNodes.find(MetadataID);
|
|
|
|
if (FI != ForwardRefMDNodes.end()) {
|
2010-08-20 22:02:26 +00:00
|
|
|
MDNode *Temp = FI->second.first;
|
|
|
|
Temp->replaceAllUsesWith(Init);
|
|
|
|
MDNode::deleteTemporary(Temp);
|
2009-07-08 19:23:54 +00:00
|
|
|
ForwardRefMDNodes.erase(FI);
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-12-30 04:51:58 +00:00
|
|
|
assert(NumberedMetadata[MetadataID] == Init && "Tracking VH didn't work");
|
|
|
|
} else {
|
|
|
|
if (MetadataID >= NumberedMetadata.size())
|
|
|
|
NumberedMetadata.resize(MetadataID+1);
|
|
|
|
|
|
|
|
if (NumberedMetadata[MetadataID] != 0)
|
|
|
|
return TokError("Metadata id is already used");
|
|
|
|
NumberedMetadata[MetadataID] = Init;
|
2009-07-08 19:23:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 19:21:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseAlias:
|
|
|
|
/// ::= GlobalVar '=' OptionalVisibility 'alias' OptionalLinkage Aliasee
|
|
|
|
/// Aliasee
|
2009-04-25 21:26:00 +00:00
|
|
|
/// ::= TypeAndValue
|
|
|
|
/// ::= 'bitcast' '(' TypeAndValue 'to' Type ')'
|
2009-07-27 21:53:46 +00:00
|
|
|
/// ::= 'getelementptr' 'inbounds'? '(' ... ')'
|
2009-01-02 07:01:27 +00:00
|
|
|
///
|
|
|
|
/// Everything through visibility has already been parsed.
|
|
|
|
///
|
|
|
|
bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
|
|
|
|
unsigned Visibility) {
|
|
|
|
assert(Lex.getKind() == lltok::kw_alias);
|
|
|
|
Lex.Lex();
|
|
|
|
unsigned Linkage;
|
|
|
|
LocTy LinkageLoc = Lex.getLoc();
|
|
|
|
if (ParseOptionalLinkage(Linkage))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Linkage != GlobalValue::ExternalLinkage &&
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
Linkage != GlobalValue::WeakAnyLinkage &&
|
|
|
|
Linkage != GlobalValue::WeakODRLinkage &&
|
2009-01-15 20:18:42 +00:00
|
|
|
Linkage != GlobalValue::InternalLinkage &&
|
2009-07-20 01:03:30 +00:00
|
|
|
Linkage != GlobalValue::PrivateLinkage &&
|
2010-07-01 21:55:59 +00:00
|
|
|
Linkage != GlobalValue::LinkerPrivateLinkage &&
|
2012-08-17 18:33:14 +00:00
|
|
|
Linkage != GlobalValue::LinkerPrivateWeakLinkage)
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(LinkageLoc, "invalid linkage type for alias");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Constant *Aliasee;
|
|
|
|
LocTy AliaseeLoc = Lex.getLoc();
|
2009-04-25 21:26:00 +00:00
|
|
|
if (Lex.getKind() != lltok::kw_bitcast &&
|
|
|
|
Lex.getKind() != lltok::kw_getelementptr) {
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseGlobalTypeAndValue(Aliasee)) return true;
|
|
|
|
} else {
|
|
|
|
// The bitcast dest type is not present, it is implied by the dest type.
|
|
|
|
ValID ID;
|
|
|
|
if (ParseValID(ID)) return true;
|
|
|
|
if (ID.Kind != ValID::t_Constant)
|
|
|
|
return Error(AliaseeLoc, "invalid aliasee");
|
|
|
|
Aliasee = ID.ConstantVal;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Aliasee->getType()->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(AliaseeLoc, "alias must have pointer type");
|
|
|
|
|
|
|
|
// Okay, create the alias but do not insert it into the module yet.
|
|
|
|
GlobalAlias* GA = new GlobalAlias(Aliasee->getType(),
|
|
|
|
(GlobalValue::LinkageTypes)Linkage, Name,
|
|
|
|
Aliasee);
|
|
|
|
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// See if this value already exists in the symbol table. If so, it is either
|
|
|
|
// a redefinition or a definition of a forward reference.
|
2009-10-25 23:22:50 +00:00
|
|
|
if (GlobalValue *Val = M->getNamedValue(Name)) {
|
2009-01-02 07:01:27 +00:00
|
|
|
// See if this was a redefinition. If so, there is no entry in
|
|
|
|
// ForwardRefVals.
|
|
|
|
std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
|
|
|
|
I = ForwardRefVals.find(Name);
|
|
|
|
if (I == ForwardRefVals.end())
|
|
|
|
return Error(NameLoc, "redefinition of global named '@" + Name + "'");
|
|
|
|
|
|
|
|
// Otherwise, this was a definition of forward ref. Verify that types
|
|
|
|
// agree.
|
|
|
|
if (Val->getType() != GA->getType())
|
|
|
|
return Error(NameLoc,
|
|
|
|
"forward reference and definition of alias have different types");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If they agree, just RAUW the old value with the alias and remove the
|
|
|
|
// forward ref info.
|
|
|
|
Val->replaceAllUsesWith(GA);
|
|
|
|
Val->eraseFromParent();
|
|
|
|
ForwardRefVals.erase(I);
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Insert into the module, we know its name won't collide now.
|
|
|
|
M->getAliasList().push_back(GA);
|
2010-10-16 11:28:23 +00:00
|
|
|
assert(GA->getName() == Name && "Should not be a name conflict!");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseGlobal
|
|
|
|
/// ::= GlobalVar '=' OptionalLinkage OptionalVisibility OptionalThreadLocal
|
2011-01-08 16:42:36 +00:00
|
|
|
/// OptionalAddrSpace OptionalUnNammedAddr GlobalType Type Const
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
|
2011-01-08 16:42:36 +00:00
|
|
|
/// OptionalAddrSpace OptionalUnNammedAddr GlobalType Type Const
|
2009-01-02 07:01:27 +00:00
|
|
|
///
|
|
|
|
/// Everything through visibility has been parsed already.
|
|
|
|
///
|
|
|
|
bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
|
|
|
|
unsigned Linkage, bool HasLinkage,
|
|
|
|
unsigned Visibility) {
|
|
|
|
unsigned AddrSpace;
|
2012-06-23 11:37:03 +00:00
|
|
|
bool IsConstant, UnnamedAddr;
|
|
|
|
GlobalVariable::ThreadLocalMode TLM;
|
2011-01-13 01:30:30 +00:00
|
|
|
LocTy UnnamedAddrLoc;
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy TyLoc;
|
2009-09-20 02:20:51 +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 *Ty = 0;
|
2012-06-23 11:37:03 +00:00
|
|
|
if (ParseOptionalThreadLocal(TLM) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseOptionalAddrSpace(AddrSpace) ||
|
2011-01-13 01:30:30 +00:00
|
|
|
ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
|
|
|
|
&UnnamedAddrLoc) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseGlobalType(IsConstant) ||
|
|
|
|
ParseType(Ty, TyLoc))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If the linkage is specified and is external, then no initializer is
|
|
|
|
// present.
|
|
|
|
Constant *Init = 0;
|
|
|
|
if (!HasLinkage || (Linkage != GlobalValue::DLLImportLinkage &&
|
2009-03-11 08:08:06 +00:00
|
|
|
Linkage != GlobalValue::ExternalWeakLinkage &&
|
2009-01-02 07:01:27 +00:00
|
|
|
Linkage != GlobalValue::ExternalLinkage)) {
|
|
|
|
if (ParseGlobalValue(Ty, Init))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-16 11:11:14 +00:00
|
|
|
if (Ty->isFunctionTy() || Ty->isLabelTy())
|
2009-02-08 20:00:15 +00:00
|
|
|
return Error(TyLoc, "invalid type for global variable");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
GlobalVariable *GV = 0;
|
|
|
|
|
|
|
|
// See if the global was forward referenced, if so, use the global.
|
2009-02-02 07:24:28 +00:00
|
|
|
if (!Name.empty()) {
|
2009-10-25 23:22:50 +00:00
|
|
|
if (GlobalValue *GVal = M->getNamedValue(Name)) {
|
|
|
|
if (!ForwardRefVals.erase(Name) || !isa<GlobalValue>(GVal))
|
|
|
|
return Error(NameLoc, "redefinition of global '@" + Name + "'");
|
|
|
|
GV = cast<GlobalVariable>(GVal);
|
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
} else {
|
|
|
|
std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
|
|
|
|
I = ForwardRefValIDs.find(NumberedVals.size());
|
|
|
|
if (I != ForwardRefValIDs.end()) {
|
|
|
|
GV = cast<GlobalVariable>(I->second.first);
|
|
|
|
ForwardRefValIDs.erase(I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GV == 0) {
|
2009-09-20 02:20:51 +00:00
|
|
|
GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, 0,
|
2012-06-23 11:37:03 +00:00
|
|
|
Name, 0, GlobalVariable::NotThreadLocal,
|
|
|
|
AddrSpace);
|
2009-01-02 07:01:27 +00:00
|
|
|
} else {
|
|
|
|
if (GV->getType()->getElementType() != Ty)
|
|
|
|
return Error(TyLoc,
|
|
|
|
"forward reference and definition of global have different types");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Move the forward-reference to the correct spot in the module.
|
|
|
|
M->getGlobalList().splice(M->global_end(), M->getGlobalList(), GV);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Name.empty())
|
|
|
|
NumberedVals.push_back(GV);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Set the parsed properties on the global.
|
|
|
|
if (Init)
|
|
|
|
GV->setInitializer(Init);
|
|
|
|
GV->setConstant(IsConstant);
|
|
|
|
GV->setLinkage((GlobalValue::LinkageTypes)Linkage);
|
|
|
|
GV->setVisibility((GlobalValue::VisibilityTypes)Visibility);
|
2012-06-23 11:37:03 +00:00
|
|
|
GV->setThreadLocalMode(TLM);
|
2011-01-08 16:42:36 +00:00
|
|
|
GV->setUnnamedAddr(UnnamedAddr);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Parse attributes on the global.
|
|
|
|
while (Lex.getKind() == lltok::comma) {
|
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Lex.getKind() == lltok::kw_section) {
|
|
|
|
Lex.Lex();
|
|
|
|
GV->setSection(Lex.getStrVal());
|
|
|
|
if (ParseToken(lltok::StringConstant, "expected global section string"))
|
|
|
|
return true;
|
|
|
|
} else if (Lex.getKind() == lltok::kw_align) {
|
|
|
|
unsigned Alignment;
|
|
|
|
if (ParseOptionalAlignment(Alignment)) return true;
|
|
|
|
GV->setAlignment(Alignment);
|
|
|
|
} else {
|
|
|
|
TokError("unknown global variable property!");
|
|
|
|
}
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// GlobalValue Reference/Resolution Routines.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// 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 *LLParser::GetGlobalVal(const std::string &Name, Type *Ty,
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy Loc) {
|
2011-07-18 04:54:35 +00:00
|
|
|
PointerType *PTy = dyn_cast<PointerType>(Ty);
|
2009-01-02 07:01:27 +00:00
|
|
|
if (PTy == 0) {
|
|
|
|
Error(Loc, "global variable reference must have pointer type");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Look this name up in the normal function symbol table.
|
|
|
|
GlobalValue *Val =
|
|
|
|
cast_or_null<GlobalValue>(M->getValueSymbolTable().lookup(Name));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If this is a forward reference for the value, see if we already created a
|
|
|
|
// forward ref record.
|
|
|
|
if (Val == 0) {
|
|
|
|
std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
|
|
|
|
I = ForwardRefVals.find(Name);
|
|
|
|
if (I != ForwardRefVals.end())
|
|
|
|
Val = I->second.first;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If we have the value in the symbol table or fwd-ref table, return it.
|
|
|
|
if (Val) {
|
|
|
|
if (Val->getType() == Ty) return Val;
|
|
|
|
Error(Loc, "'@" + Name + "' defined with type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(Val->getType()) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Otherwise, create a new forward reference for this value and remember it.
|
|
|
|
GlobalValue *FwdVal;
|
2011-07-18 04:54:35 +00:00
|
|
|
if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
|
2009-03-11 08:08:06 +00:00
|
|
|
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
|
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
|
|
|
else
|
2009-07-08 19:03:57 +00:00
|
|
|
FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
|
2012-11-16 21:03:47 +00:00
|
|
|
GlobalValue::ExternalWeakLinkage, 0, Name,
|
|
|
|
0, GlobalVariable::NotThreadLocal,
|
|
|
|
PTy->getAddressSpace());
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
|
|
|
|
return FwdVal;
|
|
|
|
}
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
GlobalValue *LLParser::GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc) {
|
|
|
|
PointerType *PTy = dyn_cast<PointerType>(Ty);
|
2009-01-02 07:01:27 +00:00
|
|
|
if (PTy == 0) {
|
|
|
|
Error(Loc, "global variable reference must have pointer type");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
GlobalValue *Val = ID < NumberedVals.size() ? NumberedVals[ID] : 0;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If this is a forward reference for the value, see if we already created a
|
|
|
|
// forward ref record.
|
|
|
|
if (Val == 0) {
|
|
|
|
std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
|
|
|
|
I = ForwardRefValIDs.find(ID);
|
|
|
|
if (I != ForwardRefValIDs.end())
|
|
|
|
Val = I->second.first;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If we have the value in the symbol table or fwd-ref table, return it.
|
|
|
|
if (Val) {
|
|
|
|
if (Val->getType() == Ty) return Val;
|
2010-09-27 17:42:11 +00:00
|
|
|
Error(Loc, "'@" + Twine(ID) + "' defined with type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(Val->getType()) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Otherwise, create a new forward reference for this value and remember it.
|
|
|
|
GlobalValue *FwdVal;
|
2011-07-18 04:54:35 +00:00
|
|
|
if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
|
2009-03-11 08:08:06 +00:00
|
|
|
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
|
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
|
|
|
else
|
2009-07-08 19:03:57 +00:00
|
|
|
FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
|
|
|
|
GlobalValue::ExternalWeakLinkage, 0, "");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
|
|
|
|
return FwdVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Helper Routines.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseToken - If the current token has the specified kind, eat it and return
|
|
|
|
/// success. Otherwise, emit the specified error and return failure.
|
|
|
|
bool LLParser::ParseToken(lltok::Kind T, const char *ErrMsg) {
|
|
|
|
if (Lex.getKind() != T)
|
|
|
|
return TokError(ErrMsg);
|
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
/// ParseStringConstant
|
|
|
|
/// ::= StringConstant
|
|
|
|
bool LLParser::ParseStringConstant(std::string &Result) {
|
|
|
|
if (Lex.getKind() != lltok::StringConstant)
|
|
|
|
return TokError("expected string constant");
|
|
|
|
Result = Lex.getStrVal();
|
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseUInt32
|
|
|
|
/// ::= uint32
|
|
|
|
bool LLParser::ParseUInt32(unsigned &Val) {
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
|
|
|
|
return TokError("expected integer");
|
|
|
|
uint64_t Val64 = Lex.getAPSIntVal().getLimitedValue(0xFFFFFFFFULL+1);
|
|
|
|
if (Val64 != unsigned(Val64))
|
|
|
|
return TokError("expected 32-bit integer (too large)");
|
|
|
|
Val = Val64;
|
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-23 11:37:03 +00:00
|
|
|
/// ParseTLSModel
|
|
|
|
/// := 'localdynamic'
|
|
|
|
/// := 'initialexec'
|
|
|
|
/// := 'localexec'
|
|
|
|
bool LLParser::ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM) {
|
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default:
|
|
|
|
return TokError("expected localdynamic, initialexec or localexec");
|
|
|
|
case lltok::kw_localdynamic:
|
|
|
|
TLM = GlobalVariable::LocalDynamicTLSModel;
|
|
|
|
break;
|
|
|
|
case lltok::kw_initialexec:
|
|
|
|
TLM = GlobalVariable::InitialExecTLSModel;
|
|
|
|
break;
|
|
|
|
case lltok::kw_localexec:
|
|
|
|
TLM = GlobalVariable::LocalExecTLSModel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseOptionalThreadLocal
|
|
|
|
/// := /*empty*/
|
|
|
|
/// := 'thread_local'
|
|
|
|
/// := 'thread_local' '(' tlsmodel ')'
|
|
|
|
bool LLParser::ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM) {
|
|
|
|
TLM = GlobalVariable::NotThreadLocal;
|
|
|
|
if (!EatIfPresent(lltok::kw_thread_local))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TLM = GlobalVariable::GeneralDynamicTLSModel;
|
|
|
|
if (Lex.getKind() == lltok::lparen) {
|
|
|
|
Lex.Lex();
|
|
|
|
return ParseTLSModel(TLM) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' after thread local model");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
/// ParseOptionalAddrSpace
|
|
|
|
/// := /*empty*/
|
|
|
|
/// := 'addrspace' '(' uint32 ')'
|
|
|
|
bool LLParser::ParseOptionalAddrSpace(unsigned &AddrSpace) {
|
|
|
|
AddrSpace = 0;
|
2009-01-02 08:05:26 +00:00
|
|
|
if (!EatIfPresent(lltok::kw_addrspace))
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
return ParseToken(lltok::lparen, "expected '(' in address space") ||
|
2009-01-02 08:05:26 +00:00
|
|
|
ParseUInt32(AddrSpace) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::rparen, "expected ')' in address space");
|
2009-09-20 02:20:51 +00:00
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2012-12-04 23:40:58 +00:00
|
|
|
/// ParseOptionalFuncAttrs - Parse a potentially empty list of function attributes.
|
|
|
|
bool LLParser::ParseOptionalFuncAttrs(AttrBuilder &B) {
|
2012-09-28 22:30:18 +00:00
|
|
|
bool HaveError = false;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-10-08 23:27:46 +00:00
|
|
|
B.clear();
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
while (1) {
|
2012-09-28 22:30:18 +00:00
|
|
|
lltok::Kind Token = Lex.getKind();
|
|
|
|
switch (Token) {
|
2009-01-02 07:01:27 +00:00
|
|
|
default: // End of attributes.
|
2012-09-28 22:30:18 +00:00
|
|
|
return HaveError;
|
2012-12-04 23:40:58 +00:00
|
|
|
case lltok::kw_alignstack: {
|
|
|
|
unsigned Alignment;
|
|
|
|
if (ParseOptionalStackAlignment(Alignment))
|
|
|
|
return true;
|
|
|
|
B.addStackAlignmentAttr(Alignment);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case lltok::kw_align: {
|
|
|
|
// As a hack, we allow "align 2" on functions as a synonym for "alignstack
|
|
|
|
// 2".
|
|
|
|
unsigned Alignment;
|
|
|
|
if (ParseOptionalAlignment(Alignment))
|
|
|
|
return true;
|
|
|
|
B.addAlignmentAttr(Alignment);
|
|
|
|
continue;
|
|
|
|
}
|
2012-12-19 07:18:57 +00:00
|
|
|
case lltok::kw_address_safety: B.addAttribute(Attribute::AddressSafety); break;
|
|
|
|
case lltok::kw_alwaysinline: B.addAttribute(Attribute::AlwaysInline); break;
|
|
|
|
case lltok::kw_inlinehint: B.addAttribute(Attribute::InlineHint); break;
|
|
|
|
case lltok::kw_minsize: B.addAttribute(Attribute::MinSize); break;
|
|
|
|
case lltok::kw_naked: B.addAttribute(Attribute::Naked); break;
|
|
|
|
case lltok::kw_noinline: B.addAttribute(Attribute::NoInline); break;
|
|
|
|
case lltok::kw_nonlazybind: B.addAttribute(Attribute::NonLazyBind); break;
|
|
|
|
case lltok::kw_noredzone: B.addAttribute(Attribute::NoRedZone); break;
|
|
|
|
case lltok::kw_noimplicitfloat: B.addAttribute(Attribute::NoImplicitFloat); break;
|
|
|
|
case lltok::kw_noreturn: B.addAttribute(Attribute::NoReturn); break;
|
|
|
|
case lltok::kw_nounwind: B.addAttribute(Attribute::NoUnwind); break;
|
|
|
|
case lltok::kw_optsize: B.addAttribute(Attribute::OptimizeForSize); break;
|
|
|
|
case lltok::kw_readnone: B.addAttribute(Attribute::ReadNone); break;
|
|
|
|
case lltok::kw_readonly: B.addAttribute(Attribute::ReadOnly); break;
|
|
|
|
case lltok::kw_returns_twice: B.addAttribute(Attribute::ReturnsTwice); break;
|
|
|
|
case lltok::kw_ssp: B.addAttribute(Attribute::StackProtect); break;
|
|
|
|
case lltok::kw_sspreq: B.addAttribute(Attribute::StackProtectReq); break;
|
|
|
|
case lltok::kw_uwtable: B.addAttribute(Attribute::UWTable); break;
|
2012-12-20 16:04:27 +00:00
|
|
|
case lltok::kw_noduplicate: B.addAttribute(Attribute::NoDuplicate); break;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-12-04 23:40:58 +00:00
|
|
|
// Error handling.
|
|
|
|
case lltok::kw_zeroext:
|
|
|
|
case lltok::kw_signext:
|
|
|
|
case lltok::kw_inreg:
|
|
|
|
HaveError |= Error(Lex.getLoc(), "invalid use of attribute on a function");
|
|
|
|
break;
|
|
|
|
case lltok::kw_sret: case lltok::kw_noalias:
|
|
|
|
case lltok::kw_nocapture: case lltok::kw_byval:
|
|
|
|
case lltok::kw_nest:
|
|
|
|
HaveError |=
|
|
|
|
Error(Lex.getLoc(), "invalid use of parameter-only attribute on a function");
|
|
|
|
break;
|
2010-02-12 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 23:40:58 +00:00
|
|
|
Lex.Lex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseOptionalParamAttrs - Parse a potentially empty list of parameter attributes.
|
|
|
|
bool LLParser::ParseOptionalParamAttrs(AttrBuilder &B) {
|
|
|
|
bool HaveError = false;
|
|
|
|
|
|
|
|
B.clear();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
lltok::Kind Token = Lex.getKind();
|
|
|
|
switch (Token) {
|
|
|
|
default: // End of attributes.
|
|
|
|
return HaveError;
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_align: {
|
|
|
|
unsigned Alignment;
|
|
|
|
if (ParseOptionalAlignment(Alignment))
|
|
|
|
return true;
|
2012-10-08 22:20:14 +00:00
|
|
|
B.addAlignmentAttr(Alignment);
|
2009-01-02 07:01:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-12-19 07:18:57 +00:00
|
|
|
case lltok::kw_byval: B.addAttribute(Attribute::ByVal); break;
|
|
|
|
case lltok::kw_inreg: B.addAttribute(Attribute::InReg); break;
|
|
|
|
case lltok::kw_nest: B.addAttribute(Attribute::Nest); break;
|
|
|
|
case lltok::kw_noalias: B.addAttribute(Attribute::NoAlias); break;
|
|
|
|
case lltok::kw_nocapture: B.addAttribute(Attribute::NoCapture); break;
|
|
|
|
case lltok::kw_signext: B.addAttribute(Attribute::SExt); break;
|
|
|
|
case lltok::kw_sret: B.addAttribute(Attribute::StructRet); break;
|
|
|
|
case lltok::kw_zeroext: B.addAttribute(Attribute::ZExt); break;
|
2010-02-12 00:31:15 +00:00
|
|
|
|
2012-12-04 23:40:58 +00:00
|
|
|
case lltok::kw_noreturn: case lltok::kw_nounwind:
|
|
|
|
case lltok::kw_uwtable: case lltok::kw_returns_twice:
|
|
|
|
case lltok::kw_noinline: case lltok::kw_readnone:
|
|
|
|
case lltok::kw_readonly: case lltok::kw_inlinehint:
|
|
|
|
case lltok::kw_alwaysinline: case lltok::kw_optsize:
|
|
|
|
case lltok::kw_ssp: case lltok::kw_sspreq:
|
|
|
|
case lltok::kw_noredzone: case lltok::kw_noimplicitfloat:
|
|
|
|
case lltok::kw_naked: case lltok::kw_nonlazybind:
|
|
|
|
case lltok::kw_address_safety: case lltok::kw_minsize:
|
|
|
|
case lltok::kw_alignstack:
|
|
|
|
HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
|
|
|
|
break;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2012-09-28 22:30:18 +00:00
|
|
|
|
2012-12-04 23:40:58 +00:00
|
|
|
Lex.Lex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseOptionalReturnAttrs - Parse a potentially empty list of return attributes.
|
|
|
|
bool LLParser::ParseOptionalReturnAttrs(AttrBuilder &B) {
|
|
|
|
bool HaveError = false;
|
|
|
|
|
|
|
|
B.clear();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
lltok::Kind Token = Lex.getKind();
|
2012-09-28 22:30:18 +00:00
|
|
|
switch (Token) {
|
2012-12-04 23:40:58 +00:00
|
|
|
default: // End of attributes.
|
|
|
|
return HaveError;
|
2012-12-19 07:18:57 +00:00
|
|
|
case lltok::kw_inreg: B.addAttribute(Attribute::InReg); break;
|
|
|
|
case lltok::kw_noalias: B.addAttribute(Attribute::NoAlias); break;
|
|
|
|
case lltok::kw_signext: B.addAttribute(Attribute::SExt); break;
|
|
|
|
case lltok::kw_zeroext: B.addAttribute(Attribute::ZExt); break;
|
2012-09-28 22:30:18 +00:00
|
|
|
|
2012-12-04 23:40:58 +00:00
|
|
|
// Error handling.
|
|
|
|
case lltok::kw_sret: case lltok::kw_nocapture:
|
|
|
|
case lltok::kw_byval: case lltok::kw_nest:
|
|
|
|
HaveError |= Error(Lex.getLoc(), "invalid use of parameter-only attribute");
|
2012-09-28 22:30:18 +00:00
|
|
|
break;
|
2012-12-20 16:04:27 +00:00
|
|
|
|
2012-12-04 23:40:58 +00:00
|
|
|
case lltok::kw_noreturn: case lltok::kw_nounwind:
|
|
|
|
case lltok::kw_uwtable: case lltok::kw_returns_twice:
|
|
|
|
case lltok::kw_noinline: case lltok::kw_readnone:
|
|
|
|
case lltok::kw_readonly: case lltok::kw_inlinehint:
|
|
|
|
case lltok::kw_alwaysinline: case lltok::kw_optsize:
|
|
|
|
case lltok::kw_ssp: case lltok::kw_sspreq:
|
|
|
|
case lltok::kw_noredzone: case lltok::kw_noimplicitfloat:
|
|
|
|
case lltok::kw_naked: case lltok::kw_nonlazybind:
|
|
|
|
case lltok::kw_address_safety: case lltok::kw_minsize:
|
|
|
|
case lltok::kw_alignstack: case lltok::kw_align:
|
2012-12-20 16:04:27 +00:00
|
|
|
case lltok::kw_noduplicate:
|
2012-12-04 23:40:58 +00:00
|
|
|
HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
|
2012-09-28 22:30:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseOptionalLinkage
|
|
|
|
/// ::= /*empty*/
|
2009-01-15 20:18:42 +00:00
|
|
|
/// ::= 'private'
|
2009-07-20 01:03:30 +00:00
|
|
|
/// ::= 'linker_private'
|
2010-07-01 21:55:59 +00:00
|
|
|
/// ::= 'linker_private_weak'
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= 'internal'
|
|
|
|
/// ::= 'weak'
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
/// ::= 'weak_odr'
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= 'linkonce'
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
/// ::= 'linkonce_odr'
|
2012-08-17 18:33:14 +00:00
|
|
|
/// ::= 'linkonce_odr_auto_hide'
|
2010-07-01 21:55:59 +00:00
|
|
|
/// ::= 'available_externally'
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= 'appending'
|
|
|
|
/// ::= 'dllexport'
|
|
|
|
/// ::= 'common'
|
|
|
|
/// ::= 'dllimport'
|
|
|
|
/// ::= 'extern_weak'
|
|
|
|
/// ::= 'external'
|
|
|
|
bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
|
|
|
|
HasLinkage = false;
|
|
|
|
switch (Lex.getKind()) {
|
2009-07-20 01:03:30 +00:00
|
|
|
default: Res=GlobalValue::ExternalLinkage; return false;
|
|
|
|
case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
|
|
|
|
case lltok::kw_linker_private: Res = GlobalValue::LinkerPrivateLinkage; break;
|
2010-07-01 21:55:59 +00:00
|
|
|
case lltok::kw_linker_private_weak:
|
|
|
|
Res = GlobalValue::LinkerPrivateWeakLinkage;
|
|
|
|
break;
|
2009-07-20 01:03:30 +00:00
|
|
|
case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
|
|
|
|
case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break;
|
|
|
|
case lltok::kw_weak_odr: Res = GlobalValue::WeakODRLinkage; break;
|
|
|
|
case lltok::kw_linkonce: Res = GlobalValue::LinkOnceAnyLinkage; break;
|
|
|
|
case lltok::kw_linkonce_odr: Res = GlobalValue::LinkOnceODRLinkage; break;
|
2012-08-17 18:33:14 +00:00
|
|
|
case lltok::kw_linkonce_odr_auto_hide:
|
|
|
|
case lltok::kw_linker_private_weak_def_auto: // FIXME: For backwards compat.
|
|
|
|
Res = GlobalValue::LinkOnceODRAutoHideLinkage;
|
|
|
|
break;
|
2009-04-13 05:44:34 +00:00
|
|
|
case lltok::kw_available_externally:
|
|
|
|
Res = GlobalValue::AvailableExternallyLinkage;
|
|
|
|
break;
|
2009-07-20 01:03:30 +00:00
|
|
|
case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break;
|
|
|
|
case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break;
|
|
|
|
case lltok::kw_common: Res = GlobalValue::CommonLinkage; break;
|
|
|
|
case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break;
|
|
|
|
case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break;
|
|
|
|
case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
Lex.Lex();
|
|
|
|
HasLinkage = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseOptionalVisibility
|
|
|
|
/// ::= /*empty*/
|
|
|
|
/// ::= 'default'
|
|
|
|
/// ::= 'hidden'
|
|
|
|
/// ::= 'protected'
|
2009-09-20 02:20:51 +00:00
|
|
|
///
|
2009-01-02 07:01:27 +00:00
|
|
|
bool LLParser::ParseOptionalVisibility(unsigned &Res) {
|
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: Res = GlobalValue::DefaultVisibility; return false;
|
|
|
|
case lltok::kw_default: Res = GlobalValue::DefaultVisibility; break;
|
|
|
|
case lltok::kw_hidden: Res = GlobalValue::HiddenVisibility; break;
|
|
|
|
case lltok::kw_protected: Res = GlobalValue::ProtectedVisibility; break;
|
|
|
|
}
|
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseOptionalCallingConv
|
|
|
|
/// ::= /*empty*/
|
|
|
|
/// ::= 'ccc'
|
|
|
|
/// ::= 'fastcc'
|
2012-10-24 14:46:16 +00:00
|
|
|
/// ::= 'kw_intel_ocl_bicc'
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= 'coldcc'
|
|
|
|
/// ::= 'x86_stdcallcc'
|
|
|
|
/// ::= 'x86_fastcallcc'
|
2010-05-16 09:08:45 +00:00
|
|
|
/// ::= 'x86_thiscallcc'
|
2009-06-16 18:50:49 +00:00
|
|
|
/// ::= 'arm_apcscc'
|
|
|
|
/// ::= 'arm_aapcscc'
|
|
|
|
/// ::= 'arm_aapcs_vfpcc'
|
2009-12-07 02:27:35 +00:00
|
|
|
/// ::= 'msp430_intrcc'
|
2010-09-25 07:46:17 +00:00
|
|
|
/// ::= 'ptx_kernel'
|
|
|
|
/// ::= 'ptx_device'
|
2012-10-01 17:01:31 +00:00
|
|
|
/// ::= 'spir_func'
|
|
|
|
/// ::= 'spir_kernel'
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= 'cc' UINT
|
2009-06-16 18:50:49 +00:00
|
|
|
///
|
2009-09-02 08:44:58 +00:00
|
|
|
bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) {
|
2009-01-02 07:01:27 +00:00
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: CC = CallingConv::C; return false;
|
|
|
|
case lltok::kw_ccc: CC = CallingConv::C; break;
|
|
|
|
case lltok::kw_fastcc: CC = CallingConv::Fast; break;
|
|
|
|
case lltok::kw_coldcc: CC = CallingConv::Cold; break;
|
|
|
|
case lltok::kw_x86_stdcallcc: CC = CallingConv::X86_StdCall; break;
|
|
|
|
case lltok::kw_x86_fastcallcc: CC = CallingConv::X86_FastCall; break;
|
2010-05-16 09:08:45 +00:00
|
|
|
case lltok::kw_x86_thiscallcc: CC = CallingConv::X86_ThisCall; break;
|
2009-06-16 18:50:49 +00:00
|
|
|
case lltok::kw_arm_apcscc: CC = CallingConv::ARM_APCS; break;
|
|
|
|
case lltok::kw_arm_aapcscc: CC = CallingConv::ARM_AAPCS; break;
|
|
|
|
case lltok::kw_arm_aapcs_vfpcc:CC = CallingConv::ARM_AAPCS_VFP; break;
|
2009-12-07 02:27:35 +00:00
|
|
|
case lltok::kw_msp430_intrcc: CC = CallingConv::MSP430_INTR; break;
|
2010-09-25 07:46:17 +00:00
|
|
|
case lltok::kw_ptx_kernel: CC = CallingConv::PTX_Kernel; break;
|
|
|
|
case lltok::kw_ptx_device: CC = CallingConv::PTX_Device; break;
|
2012-10-01 17:01:31 +00:00
|
|
|
case lltok::kw_spir_kernel: CC = CallingConv::SPIR_KERNEL; break;
|
|
|
|
case lltok::kw_spir_func: CC = CallingConv::SPIR_FUNC; break;
|
2012-10-24 14:46:16 +00:00
|
|
|
case lltok::kw_intel_ocl_bicc: CC = CallingConv::Intel_OCL_BI; break;
|
2009-09-02 08:44:58 +00:00
|
|
|
case lltok::kw_cc: {
|
|
|
|
unsigned ArbitraryCC;
|
|
|
|
Lex.Lex();
|
2012-01-20 21:51:11 +00:00
|
|
|
if (ParseUInt32(ArbitraryCC))
|
2009-09-02 08:44:58 +00:00
|
|
|
return true;
|
2012-01-20 21:51:11 +00:00
|
|
|
CC = static_cast<CallingConv::ID>(ArbitraryCC);
|
|
|
|
return false;
|
2009-09-02 08:44:58 +00:00
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-30 05:31:19 +00:00
|
|
|
/// ParseInstructionMetadata
|
2009-12-29 21:25:40 +00:00
|
|
|
/// ::= !dbg !42 (',' !dbg !57)*
|
2010-08-24 02:05:17 +00:00
|
|
|
bool LLParser::ParseInstructionMetadata(Instruction *Inst,
|
|
|
|
PerFunctionState *PFS) {
|
2009-12-30 05:31:19 +00:00
|
|
|
do {
|
|
|
|
if (Lex.getKind() != lltok::MetadataVar)
|
|
|
|
return TokError("expected metadata after comma");
|
2009-09-29 00:01:14 +00:00
|
|
|
|
2009-12-29 21:25:40 +00:00
|
|
|
std::string Name = Lex.getStrVal();
|
2011-12-06 11:50:26 +00:00
|
|
|
unsigned MDK = M->getMDKindID(Name);
|
2009-12-29 21:25:40 +00:00
|
|
|
Lex.Lex();
|
2009-10-19 05:31:10 +00:00
|
|
|
|
2009-12-29 21:53:55 +00:00
|
|
|
MDNode *Node;
|
2010-04-01 05:14:45 +00:00
|
|
|
SMLoc Loc = Lex.getLoc();
|
2010-08-24 02:24:03 +00:00
|
|
|
|
|
|
|
if (ParseToken(lltok::exclaim, "expected '!' here"))
|
2009-12-30 04:56:59 +00:00
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2010-08-24 14:35:45 +00:00
|
|
|
// This code is similar to that of ParseMetadataValue, however it needs to
|
|
|
|
// have special-case code for a forward reference; see the comments on
|
|
|
|
// ForwardRefInstMetadata for details. Also, MDStrings are not supported
|
|
|
|
// at the top level here.
|
2010-08-24 02:24:03 +00:00
|
|
|
if (Lex.getKind() == lltok::lbrace) {
|
|
|
|
ValID ID;
|
|
|
|
if (ParseMetadataListValue(ID, PFS))
|
|
|
|
return true;
|
|
|
|
assert(ID.Kind == ValID::t_MDNode);
|
|
|
|
Inst->setMetadata(MDK, ID.MDNodeVal);
|
2010-04-01 05:14:45 +00:00
|
|
|
} else {
|
2010-09-30 21:04:13 +00:00
|
|
|
unsigned NodeID = 0;
|
2010-08-24 02:24:03 +00:00
|
|
|
if (ParseMDNodeID(Node, NodeID))
|
|
|
|
return true;
|
|
|
|
if (Node) {
|
|
|
|
// If we got the node, add it to the instruction.
|
|
|
|
Inst->setMetadata(MDK, Node);
|
|
|
|
} else {
|
|
|
|
MDRef R = { Loc, MDK, NodeID };
|
|
|
|
// Otherwise, remember that this should be resolved later.
|
|
|
|
ForwardRefInstMetadata[Inst].push_back(R);
|
|
|
|
}
|
2010-04-01 05:14:45 +00:00
|
|
|
}
|
2009-12-29 21:25:40 +00:00
|
|
|
|
|
|
|
// If this is the end of the list, we're done.
|
2009-12-30 05:31:19 +00:00
|
|
|
} while (EatIfPresent(lltok::comma));
|
|
|
|
return false;
|
2009-09-17 23:04:48 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseOptionalAlignment
|
|
|
|
/// ::= /* empty */
|
|
|
|
/// ::= 'align' 4
|
|
|
|
bool LLParser::ParseOptionalAlignment(unsigned &Alignment) {
|
|
|
|
Alignment = 0;
|
2009-01-02 08:05:26 +00:00
|
|
|
if (!EatIfPresent(lltok::kw_align))
|
|
|
|
return false;
|
2009-01-05 07:46:05 +00:00
|
|
|
LocTy AlignLoc = Lex.getLoc();
|
|
|
|
if (ParseUInt32(Alignment)) return true;
|
|
|
|
if (!isPowerOf2_32(Alignment))
|
|
|
|
return Error(AlignLoc, "alignment is not a power of two");
|
2010-07-30 21:07:05 +00:00
|
|
|
if (Alignment > Value::MaximumAlignment)
|
2010-07-28 20:12:04 +00:00
|
|
|
return Error(AlignLoc, "huge alignments are not supported yet");
|
2009-01-05 07:46:05 +00:00
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-30 05:44:30 +00:00
|
|
|
/// ParseOptionalCommaAlign
|
2012-11-15 22:34:00 +00:00
|
|
|
/// ::=
|
2009-12-30 05:44:30 +00:00
|
|
|
/// ::= ',' align 4
|
|
|
|
///
|
|
|
|
/// This returns with AteExtraComma set to true if it ate an excess comma at the
|
|
|
|
/// end.
|
|
|
|
bool LLParser::ParseOptionalCommaAlign(unsigned &Alignment,
|
|
|
|
bool &AteExtraComma) {
|
|
|
|
AteExtraComma = false;
|
|
|
|
while (EatIfPresent(lltok::comma)) {
|
|
|
|
// Metadata at the end is an early exit.
|
2009-12-30 05:02:06 +00:00
|
|
|
if (Lex.getKind() == lltok::MetadataVar) {
|
2009-12-30 05:44:30 +00:00
|
|
|
AteExtraComma = true;
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2010-04-23 00:50:50 +00:00
|
|
|
if (Lex.getKind() != lltok::kw_align)
|
|
|
|
return Error(Lex.getLoc(), "expected metadata or 'align'");
|
2010-10-21 16:07:10 +00:00
|
|
|
|
2010-04-23 00:50:50 +00:00
|
|
|
if (ParseOptionalAlignment(Alignment)) return true;
|
2009-12-30 05:44:30 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-09-17 23:04:48 +00:00
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
2011-07-25 23:16:38 +00:00
|
|
|
/// ParseScopeAndOrdering
|
|
|
|
/// if isAtomic: ::= 'singlethread'? AtomicOrdering
|
|
|
|
/// else: ::=
|
|
|
|
///
|
|
|
|
/// This sets Scope and Ordering to the parsed values.
|
|
|
|
bool LLParser::ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,
|
|
|
|
AtomicOrdering &Ordering) {
|
|
|
|
if (!isAtomic)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Scope = CrossThread;
|
|
|
|
if (EatIfPresent(lltok::kw_singlethread))
|
|
|
|
Scope = SingleThread;
|
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: return TokError("Expected ordering on atomic instruction");
|
|
|
|
case lltok::kw_unordered: Ordering = Unordered; break;
|
|
|
|
case lltok::kw_monotonic: Ordering = Monotonic; break;
|
|
|
|
case lltok::kw_acquire: Ordering = Acquire; break;
|
|
|
|
case lltok::kw_release: Ordering = Release; break;
|
|
|
|
case lltok::kw_acq_rel: Ordering = AcquireRelease; break;
|
|
|
|
case lltok::kw_seq_cst: Ordering = SequentiallyConsistent; break;
|
|
|
|
}
|
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-12 00:31:15 +00:00
|
|
|
/// ParseOptionalStackAlignment
|
|
|
|
/// ::= /* empty */
|
|
|
|
/// ::= 'alignstack' '(' 4 ')'
|
|
|
|
bool LLParser::ParseOptionalStackAlignment(unsigned &Alignment) {
|
|
|
|
Alignment = 0;
|
|
|
|
if (!EatIfPresent(lltok::kw_alignstack))
|
|
|
|
return false;
|
|
|
|
LocTy ParenLoc = Lex.getLoc();
|
|
|
|
if (!EatIfPresent(lltok::lparen))
|
|
|
|
return Error(ParenLoc, "expected '('");
|
|
|
|
LocTy AlignLoc = Lex.getLoc();
|
|
|
|
if (ParseUInt32(Alignment)) return true;
|
|
|
|
ParenLoc = Lex.getLoc();
|
|
|
|
if (!EatIfPresent(lltok::rparen))
|
|
|
|
return Error(ParenLoc, "expected ')'");
|
|
|
|
if (!isPowerOf2_32(Alignment))
|
|
|
|
return Error(AlignLoc, "stack alignment is not a power of two");
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-17 23:04:48 +00:00
|
|
|
|
2009-12-30 05:14:00 +00:00
|
|
|
/// ParseIndexList - This parses the index list for an insert/extractvalue
|
|
|
|
/// instruction. This sets AteExtraComma in the case where we eat an extra
|
|
|
|
/// comma at the end of the line and find that it is followed by metadata.
|
|
|
|
/// Clients that don't allow metadata can call the version of this function that
|
|
|
|
/// only takes one argument.
|
|
|
|
///
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseIndexList
|
|
|
|
/// ::= (',' uint32)+
|
2009-12-30 05:14:00 +00:00
|
|
|
///
|
|
|
|
bool LLParser::ParseIndexList(SmallVectorImpl<unsigned> &Indices,
|
|
|
|
bool &AteExtraComma) {
|
|
|
|
AteExtraComma = false;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Lex.getKind() != lltok::comma)
|
|
|
|
return TokError("expected ',' as start of index list");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
while (EatIfPresent(lltok::comma)) {
|
2009-12-30 05:14:00 +00:00
|
|
|
if (Lex.getKind() == lltok::MetadataVar) {
|
|
|
|
AteExtraComma = true;
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-29 23:32:20 +00:00
|
|
|
unsigned Idx = 0;
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseUInt32(Idx)) return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
Indices.push_back(Idx);
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// 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
|
|
|
/// ParseType - Parse a type.
|
|
|
|
bool LLParser::ParseType(Type *&Result, bool AllowVoid) {
|
|
|
|
SMLoc TypeLoc = Lex.getLoc();
|
2009-01-02 07:01:27 +00:00
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default:
|
|
|
|
return TokError("expected type");
|
|
|
|
case lltok::Type:
|
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 ::= 'float' | 'void' (etc)
|
2009-01-02 07:01:27 +00:00
|
|
|
Result = Lex.getTyVal();
|
2009-09-20 02:20:51 +00:00
|
|
|
Lex.Lex();
|
2009-01-02 07:01:27 +00:00
|
|
|
break;
|
|
|
|
case lltok::lbrace:
|
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 ::= StructType
|
|
|
|
if (ParseAnonStructType(Result, false))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
case lltok::lsquare:
|
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 ::= '[' ... ']'
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex(); // eat the lsquare.
|
|
|
|
if (ParseArrayVectorType(Result, false))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
case lltok::less: // Either vector or packed struct.
|
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 ::= '<' ... '>'
|
2009-01-02 08:05:26 +00:00
|
|
|
Lex.Lex();
|
|
|
|
if (Lex.getKind() == lltok::lbrace) {
|
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
|
|
|
if (ParseAnonStructType(Result, true) ||
|
2009-01-02 08:05:26 +00:00
|
|
|
ParseToken(lltok::greater, "expected '>' at end of packed struct"))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
|
|
|
} else if (ParseArrayVectorType(Result, true))
|
|
|
|
return true;
|
|
|
|
break;
|
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
|
|
|
case lltok::LocalVar: {
|
|
|
|
// Type ::= %foo
|
|
|
|
std::pair<Type*, LocTy> &Entry = NamedTypes[Lex.getStrVal()];
|
2012-11-15 22:34:00 +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
|
|
|
// If the type hasn't been defined yet, create a forward definition and
|
|
|
|
// remember where that forward def'n was seen (in case it never is defined).
|
|
|
|
if (Entry.first == 0) {
|
2011-08-12 18:06:37 +00:00
|
|
|
Entry.first = StructType::create(Context, Lex.getStrVal());
|
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
|
|
|
Entry.second = Lex.getLoc();
|
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
|
|
|
Result = Entry.first;
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
break;
|
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
|
|
|
}
|
2009-09-20 02:20:51 +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
|
|
|
case lltok::LocalVarID: {
|
|
|
|
// Type ::= %4
|
|
|
|
if (Lex.getUIntVal() >= NumberedTypes.size())
|
|
|
|
NumberedTypes.resize(Lex.getUIntVal()+1);
|
|
|
|
std::pair<Type*, LocTy> &Entry = NumberedTypes[Lex.getUIntVal()];
|
2012-11-15 22:34:00 +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
|
|
|
// If the type hasn't been defined yet, create a forward definition and
|
|
|
|
// remember where that forward def'n was seen (in case it never is defined).
|
|
|
|
if (Entry.first == 0) {
|
2011-08-12 18:06:37 +00:00
|
|
|
Entry.first = StructType::create(Context);
|
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
|
|
|
Entry.second = Lex.getLoc();
|
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
|
|
|
Result = Entry.first;
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
|
|
|
// Parse the type suffixes.
|
2009-01-02 07:01:27 +00:00
|
|
|
while (1) {
|
|
|
|
switch (Lex.getKind()) {
|
|
|
|
// End of type.
|
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
|
|
|
default:
|
|
|
|
if (!AllowVoid && Result->isVoidTy())
|
|
|
|
return Error(TypeLoc, "void type only allowed for function results");
|
|
|
|
return false;
|
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
|
|
|
// Type ::= Type '*'
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::star:
|
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
|
|
|
if (Result->isLabelTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return TokError("basic block pointers are invalid");
|
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
|
|
|
if (Result->isVoidTy())
|
|
|
|
return TokError("pointers to void are invalid - use i8* instead");
|
|
|
|
if (!PointerType::isValidElementType(Result))
|
2009-06-07 07:26:46 +00:00
|
|
|
return TokError("pointer to this type is invalid");
|
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
|
|
|
Result = PointerType::getUnqual(Result);
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
break;
|
|
|
|
|
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 ::= Type 'addrspace' '(' uint32 ')' '*'
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_addrspace: {
|
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
|
|
|
if (Result->isLabelTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return TokError("basic block pointers are invalid");
|
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
|
|
|
if (Result->isVoidTy())
|
2009-02-09 17:41:21 +00:00
|
|
|
return TokError("pointers to void are invalid; use i8* instead");
|
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
|
|
|
if (!PointerType::isValidElementType(Result))
|
2009-06-07 07:26:46 +00:00
|
|
|
return TokError("pointer to this type is invalid");
|
2009-01-02 07:01:27 +00:00
|
|
|
unsigned AddrSpace;
|
|
|
|
if (ParseOptionalAddrSpace(AddrSpace) ||
|
|
|
|
ParseToken(lltok::star, "expected '*' in address space"))
|
|
|
|
return true;
|
|
|
|
|
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
|
|
|
Result = PointerType::get(Result, AddrSpace);
|
2009-01-02 07:01:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// Types '(' ArgTypeListI ')' OptFuncAttrs
|
|
|
|
case lltok::lparen:
|
|
|
|
if (ParseFunctionType(Result))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseParameterList
|
|
|
|
/// ::= '(' ')'
|
|
|
|
/// ::= '(' Arg (',' Arg)* ')'
|
|
|
|
/// Arg
|
|
|
|
/// ::= Type OptionalAttributes Value OptionalAttributes
|
|
|
|
bool LLParser::ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
|
|
|
|
PerFunctionState &PFS) {
|
|
|
|
if (ParseToken(lltok::lparen, "expected '(' in call"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
while (Lex.getKind() != lltok::rparen) {
|
|
|
|
// If this isn't the first argument, we need a comma.
|
|
|
|
if (!ArgList.empty() &&
|
|
|
|
ParseToken(lltok::comma, "expected ',' in argument list"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Parse the argument.
|
|
|
|
LocTy ArgLoc;
|
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 *ArgTy = 0;
|
2012-10-15 20:35:56 +00:00
|
|
|
AttrBuilder ArgAttrs;
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *V;
|
2009-12-03 23:40:58 +00:00
|
|
|
if (ParseType(ArgTy, ArgLoc))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-12-03 23:40:58 +00:00
|
|
|
|
2009-12-30 02:11:14 +00:00
|
|
|
// Otherwise, handle normal operands.
|
2012-12-04 23:40:58 +00:00
|
|
|
if (ParseOptionalParamAttrs(ArgAttrs) || ParseValue(ArgTy, V, PFS))
|
2009-12-30 02:11:14 +00:00
|
|
|
return true;
|
2012-12-19 07:18:57 +00:00
|
|
|
ArgList.push_back(ParamInfo(ArgLoc, V, Attribute::get(V->getContext(),
|
2012-10-15 04:46:55 +00:00
|
|
|
ArgAttrs)));
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Lex.Lex(); // Lex the ')'.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-05 18:34:07 +00:00
|
|
|
/// ParseArgumentList - Parse the argument list for a function type or function
|
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
|
|
|
/// prototype.
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= '(' ArgTypeListI ')'
|
|
|
|
/// ArgTypeListI
|
|
|
|
/// ::= /*empty*/
|
|
|
|
/// ::= '...'
|
|
|
|
/// ::= ArgTypeList ',' '...'
|
|
|
|
/// ::= ArgType (',' ArgType)*
|
2009-01-05 18:34:07 +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 LLParser::ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
|
|
|
|
bool &isVarArg){
|
2009-01-02 07:01:27 +00:00
|
|
|
isVarArg = false;
|
|
|
|
assert(Lex.getKind() == lltok::lparen);
|
|
|
|
Lex.Lex(); // eat the (.
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Lex.getKind() == lltok::rparen) {
|
|
|
|
// empty
|
|
|
|
} else if (Lex.getKind() == lltok::dotdotdot) {
|
|
|
|
isVarArg = true;
|
|
|
|
Lex.Lex();
|
|
|
|
} else {
|
|
|
|
LocTy TypeLoc = 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
|
|
|
Type *ArgTy = 0;
|
2012-10-15 20:35:56 +00:00
|
|
|
AttrBuilder Attrs;
|
2009-01-02 07:01:27 +00:00
|
|
|
std::string Name;
|
2009-09-20 02:20:51 +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
|
|
|
if (ParseType(ArgTy) ||
|
2012-12-04 23:40:58 +00:00
|
|
|
ParseOptionalParamAttrs(Attrs)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-10-05 05:54:46 +00:00
|
|
|
if (ArgTy->isVoidTy())
|
2009-03-09 04:49:14 +00:00
|
|
|
return Error(TypeLoc, "argument can not have void type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-06-17 06:36:20 +00:00
|
|
|
if (Lex.getKind() == lltok::LocalVar) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Name = Lex.getStrVal();
|
|
|
|
Lex.Lex();
|
|
|
|
}
|
2009-01-02 08:05:26 +00:00
|
|
|
|
2009-06-07 07:26:46 +00:00
|
|
|
if (!FunctionType::isValidArgumentType(ArgTy))
|
2009-01-02 08:05:26 +00:00
|
|
|
return Error(TypeLoc, "invalid type for function argument");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-10-15 04:46:55 +00:00
|
|
|
ArgList.push_back(ArgInfo(TypeLoc, ArgTy,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(ArgTy->getContext(),
|
2012-10-15 04:46:55 +00:00
|
|
|
Attrs), Name));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
while (EatIfPresent(lltok::comma)) {
|
2009-01-02 07:01:27 +00:00
|
|
|
// Handle ... at end of arg list.
|
2009-01-02 08:05:26 +00:00
|
|
|
if (EatIfPresent(lltok::dotdotdot)) {
|
2009-01-02 07:01:27 +00:00
|
|
|
isVarArg = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Otherwise must be an argument type.
|
|
|
|
TypeLoc = Lex.getLoc();
|
2012-12-04 23:40:58 +00:00
|
|
|
if (ParseType(ArgTy) || ParseOptionalParamAttrs(Attrs)) return true;
|
2009-01-02 08:05:26 +00:00
|
|
|
|
2009-10-05 05:54:46 +00:00
|
|
|
if (ArgTy->isVoidTy())
|
2009-03-09 04:49:14 +00:00
|
|
|
return Error(TypeLoc, "argument can not have void type");
|
|
|
|
|
2011-06-17 06:36:20 +00:00
|
|
|
if (Lex.getKind() == lltok::LocalVar) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Name = Lex.getStrVal();
|
|
|
|
Lex.Lex();
|
|
|
|
} else {
|
|
|
|
Name = "";
|
|
|
|
}
|
2009-01-02 08:05:26 +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
|
|
|
if (!ArgTy->isFirstClassType())
|
2009-01-02 08:05:26 +00:00
|
|
|
return Error(TypeLoc, "invalid type for function argument");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-10-15 04:46:55 +00:00
|
|
|
ArgList.push_back(ArgInfo(TypeLoc, ArgTy,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(ArgTy->getContext(), Attrs),
|
2012-10-15 04:46:55 +00:00
|
|
|
Name));
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
return ParseToken(lltok::rparen, "expected ')' at end of argument list");
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseFunctionType
|
|
|
|
/// ::= Type ArgumentList OptionalAttrs
|
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 LLParser::ParseFunctionType(Type *&Result) {
|
2009-01-02 07:01:27 +00:00
|
|
|
assert(Lex.getKind() == lltok::lparen);
|
|
|
|
|
2009-01-05 08:04:33 +00:00
|
|
|
if (!FunctionType::isValidReturnType(Result))
|
|
|
|
return TokError("invalid function return type");
|
2009-09-20 02:20:51 +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
|
|
|
SmallVector<ArgInfo, 8> ArgList;
|
2009-01-02 07:01:27 +00:00
|
|
|
bool isVarArg;
|
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
|
|
|
if (ParseArgumentList(ArgList, isVarArg))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Reject names on the arguments lists.
|
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
|
|
|
|
if (!ArgList[i].Name.empty())
|
|
|
|
return Error(ArgList[i].Loc, "argument name invalid in function type");
|
2012-10-14 08:54:26 +00:00
|
|
|
if (ArgList[i].Attrs.hasAttributes())
|
2011-06-17 17:37:13 +00:00
|
|
|
return Error(ArgList[i].Loc,
|
|
|
|
"argument attributes invalid in function type");
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-07-12 14:06:48 +00:00
|
|
|
SmallVector<Type*, 16> ArgListTy;
|
2009-01-02 07:01:27 +00:00
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
|
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
|
|
|
ArgListTy.push_back(ArgList[i].Ty);
|
|
|
|
|
|
|
|
Result = FunctionType::get(Result, ArgListTy, isVarArg);
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +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
|
|
|
/// ParseAnonStructType - Parse an anonymous struct type, which is inlined into
|
|
|
|
/// other structs.
|
|
|
|
bool LLParser::ParseAnonStructType(Type *&Result, bool Packed) {
|
|
|
|
SmallVector<Type*, 8> Elts;
|
|
|
|
if (ParseStructBody(Elts)) return true;
|
2012-11-15 22:34:00 +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
|
|
|
Result = StructType::get(Context, Elts, Packed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseStructDefinition - Parse a struct in a 'type' definition.
|
|
|
|
bool LLParser::ParseStructDefinition(SMLoc TypeLoc, StringRef Name,
|
|
|
|
std::pair<Type*, LocTy> &Entry,
|
|
|
|
Type *&ResultTy) {
|
|
|
|
// If the type was already defined, diagnose the redefinition.
|
|
|
|
if (Entry.first && !Entry.second.isValid())
|
|
|
|
return Error(TypeLoc, "redefinition of type");
|
2012-11-15 22:34:00 +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
|
|
|
// If we have opaque, just return without filling in the definition for the
|
|
|
|
// struct. This counts as a definition as far as the .ll file goes.
|
|
|
|
if (EatIfPresent(lltok::kw_opaque)) {
|
|
|
|
// This type is being defined, so clear the location to indicate this.
|
|
|
|
Entry.second = SMLoc();
|
2012-11-15 22:34:00 +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
|
|
|
// If this type number has never been uttered, create it.
|
|
|
|
if (Entry.first == 0)
|
2011-08-12 18:06:37 +00:00
|
|
|
Entry.first = StructType::create(Context, 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
|
|
|
ResultTy = Entry.first;
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-15 22:34:00 +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
|
|
|
// If the type starts with '<', then it is either a packed struct or a vector.
|
|
|
|
bool isPacked = EatIfPresent(lltok::less);
|
|
|
|
|
|
|
|
// If we don't have a struct, then we have a random type alias, which we
|
|
|
|
// accept for compatibility with old files. These types are not allowed to be
|
|
|
|
// forward referenced and not allowed to be recursive.
|
|
|
|
if (Lex.getKind() != lltok::lbrace) {
|
|
|
|
if (Entry.first)
|
|
|
|
return Error(TypeLoc, "forward references to non-struct type");
|
2012-11-15 22:34:00 +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
|
|
|
ResultTy = 0;
|
|
|
|
if (isPacked)
|
|
|
|
return ParseArrayVectorType(ResultTy, true);
|
|
|
|
return ParseType(ResultTy);
|
|
|
|
}
|
2012-11-15 22:34:00 +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
|
|
|
// This type is being defined, so clear the location to indicate this.
|
|
|
|
Entry.second = SMLoc();
|
2012-11-15 22:34:00 +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
|
|
|
// If this type number has never been uttered, create it.
|
|
|
|
if (Entry.first == 0)
|
2011-08-12 18:06:37 +00:00
|
|
|
Entry.first = StructType::create(Context, Name);
|
2012-11-15 22:34:00 +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
|
|
|
StructType *STy = cast<StructType>(Entry.first);
|
2012-11-15 22:34:00 +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
|
|
|
SmallVector<Type*, 8> Body;
|
|
|
|
if (ParseStructBody(Body) ||
|
|
|
|
(isPacked && ParseToken(lltok::greater, "expected '>' in packed struct")))
|
|
|
|
return true;
|
2012-11-15 22:34:00 +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
|
|
|
STy->setBody(Body, isPacked);
|
|
|
|
ResultTy = STy;
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseStructType: Handles packed and unpacked types. </> parsed elsewhere.
|
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
|
|
|
/// StructType
|
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
|
|
|
/// ::= '{' Type (',' Type)* '}'
|
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
|
|
|
/// ::= '<' '{' Type (',' Type)* '}' '>'
|
|
|
|
bool LLParser::ParseStructBody(SmallVectorImpl<Type*> &Body) {
|
2009-01-02 07:01:27 +00:00
|
|
|
assert(Lex.getKind() == lltok::lbrace);
|
|
|
|
Lex.Lex(); // Consume the '{'
|
2009-09-20 02:20:51 +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
|
|
|
// Handle the empty struct.
|
|
|
|
if (EatIfPresent(lltok::rbrace))
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
|
2009-03-09 04:49:14 +00:00
|
|
|
LocTy EltTyLoc = 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
|
|
|
Type *Ty = 0;
|
|
|
|
if (ParseType(Ty)) return true;
|
|
|
|
Body.push_back(Ty);
|
2009-09-20 02:20:51 +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
|
|
|
if (!StructType::isValidElementType(Ty))
|
2009-06-07 07:26:46 +00:00
|
|
|
return Error(EltTyLoc, "invalid element type for struct");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
while (EatIfPresent(lltok::comma)) {
|
2009-03-09 04:49:14 +00:00
|
|
|
EltTyLoc = 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
|
|
|
if (ParseType(Ty)) return true;
|
2009-09-20 02:20:51 +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
|
|
|
if (!StructType::isValidElementType(Ty))
|
2009-06-07 07:26:46 +00:00
|
|
|
return Error(EltTyLoc, "invalid element type for struct");
|
2009-09-20 02:20:51 +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
|
|
|
Body.push_back(Ty);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +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
|
|
|
return ParseToken(lltok::rbrace, "expected '}' at end of struct");
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseArrayVectorType - Parse an array or vector type, assuming the first
|
|
|
|
/// token has already been consumed.
|
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
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ::= '[' APSINTVAL 'x' Types ']'
|
|
|
|
/// ::= '<' APSINTVAL 'x' Types '>'
|
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 LLParser::ParseArrayVectorType(Type *&Result, bool isVector) {
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned() ||
|
|
|
|
Lex.getAPSIntVal().getBitWidth() > 64)
|
|
|
|
return TokError("expected number in address space");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy SizeLoc = Lex.getLoc();
|
|
|
|
uint64_t Size = Lex.getAPSIntVal().getZExtValue();
|
2009-01-02 08:05:26 +00:00
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseToken(lltok::kw_x, "expected 'x' after element count"))
|
|
|
|
return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
LocTy TypeLoc = 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
|
|
|
Type *EltTy = 0;
|
|
|
|
if (ParseType(EltTy)) return true;
|
2009-03-09 04:49:14 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseToken(isVector ? lltok::greater : lltok::rsquare,
|
|
|
|
"expected end of sequential type"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (isVector) {
|
2009-02-28 18:12:41 +00:00
|
|
|
if (Size == 0)
|
|
|
|
return Error(SizeLoc, "zero element vector is illegal");
|
2009-01-02 07:01:27 +00:00
|
|
|
if ((unsigned)Size != Size)
|
|
|
|
return Error(SizeLoc, "size too large for vector");
|
2009-06-07 07:26:46 +00:00
|
|
|
if (!VectorType::isValidElementType(EltTy))
|
2012-11-13 12:59:33 +00:00
|
|
|
return Error(TypeLoc, "invalid vector element type");
|
2009-07-29 22:17:13 +00:00
|
|
|
Result = VectorType::get(EltTy, unsigned(Size));
|
2009-01-02 07:01:27 +00:00
|
|
|
} else {
|
2009-06-07 07:26:46 +00:00
|
|
|
if (!ArrayType::isValidElementType(EltTy))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(TypeLoc, "invalid array element type");
|
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
|
|
|
Result = ArrayType::get(EltTy, Size);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Function Semantic Analysis.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
LLParser::PerFunctionState::PerFunctionState(LLParser &p, Function &f,
|
|
|
|
int functionNumber)
|
|
|
|
: P(p), F(f), FunctionNumber(functionNumber) {
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
// Insert unnamed arguments into the NumberedVals list.
|
|
|
|
for (Function::arg_iterator AI = F.arg_begin(), E = F.arg_end();
|
|
|
|
AI != E; ++AI)
|
|
|
|
if (!AI->hasName())
|
|
|
|
NumberedVals.push_back(AI);
|
|
|
|
}
|
|
|
|
|
|
|
|
LLParser::PerFunctionState::~PerFunctionState() {
|
|
|
|
// If there were any forward referenced non-basicblock values, delete them.
|
|
|
|
for (std::map<std::string, std::pair<Value*, LocTy> >::iterator
|
|
|
|
I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++I)
|
|
|
|
if (!isa<BasicBlock>(I->second.first)) {
|
2009-07-02 17:04:01 +00:00
|
|
|
I->second.first->replaceAllUsesWith(
|
2009-07-30 23:03:37 +00:00
|
|
|
UndefValue::get(I->second.first->getType()));
|
2009-01-02 07:01:27 +00:00
|
|
|
delete I->second.first;
|
|
|
|
I->second.first = 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
for (std::map<unsigned, std::pair<Value*, LocTy> >::iterator
|
|
|
|
I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++I)
|
|
|
|
if (!isa<BasicBlock>(I->second.first)) {
|
2009-07-02 17:04:01 +00:00
|
|
|
I->second.first->replaceAllUsesWith(
|
2009-07-30 23:03:37 +00:00
|
|
|
UndefValue::get(I->second.first->getType()));
|
2009-01-02 07:01:27 +00:00
|
|
|
delete I->second.first;
|
|
|
|
I->second.first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
bool LLParser::PerFunctionState::FinishFunction() {
|
|
|
|
// Check to see if someone took the address of labels in this block.
|
|
|
|
if (!P.ForwardRefBlockAddresses.empty()) {
|
|
|
|
ValID FunctionID;
|
|
|
|
if (!F.getName().empty()) {
|
|
|
|
FunctionID.Kind = ValID::t_GlobalName;
|
|
|
|
FunctionID.StrVal = F.getName();
|
|
|
|
} else {
|
|
|
|
FunctionID.Kind = ValID::t_GlobalID;
|
|
|
|
FunctionID.UIntVal = FunctionNumber;
|
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >::iterator
|
|
|
|
FRBAI = P.ForwardRefBlockAddresses.find(FunctionID);
|
|
|
|
if (FRBAI != P.ForwardRefBlockAddresses.end()) {
|
|
|
|
// Resolve all these references.
|
|
|
|
if (P.ResolveForwardRefBlockAddresses(&F, FRBAI->second, this))
|
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
P.ForwardRefBlockAddresses.erase(FRBAI);
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!ForwardRefVals.empty())
|
|
|
|
return P.Error(ForwardRefVals.begin()->second.second,
|
|
|
|
"use of undefined value '%" + ForwardRefVals.begin()->first +
|
|
|
|
"'");
|
|
|
|
if (!ForwardRefValIDs.empty())
|
|
|
|
return P.Error(ForwardRefValIDs.begin()->second.second,
|
|
|
|
"use of undefined value '%" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(ForwardRefValIDs.begin()->first) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
Value *LLParser::PerFunctionState::GetVal(const std::string &Name,
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *Ty, LocTy Loc) {
|
2009-01-02 07:01:27 +00:00
|
|
|
// Look this name up in the normal function symbol table.
|
|
|
|
Value *Val = F.getValueSymbolTable().lookup(Name);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If this is a forward reference for the value, see if we already created a
|
|
|
|
// forward ref record.
|
|
|
|
if (Val == 0) {
|
|
|
|
std::map<std::string, std::pair<Value*, LocTy> >::iterator
|
|
|
|
I = ForwardRefVals.find(Name);
|
|
|
|
if (I != ForwardRefVals.end())
|
|
|
|
Val = I->second.first;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If we have the value in the symbol table or fwd-ref table, return it.
|
|
|
|
if (Val) {
|
|
|
|
if (Val->getType() == Ty) return Val;
|
2009-10-05 05:54:46 +00:00
|
|
|
if (Ty->isLabelTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
P.Error(Loc, "'%" + Name + "' is not a basic block");
|
|
|
|
else
|
|
|
|
P.Error(Loc, "'%" + Name + "' defined with type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(Val->getType()) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Don't make placeholders with invalid type.
|
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
|
|
|
if (!Ty->isFirstClassType() && !Ty->isLabelTy()) {
|
2009-01-02 07:01:27 +00:00
|
|
|
P.Error(Loc, "invalid use of a non-first-class type");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Otherwise, create a new forward reference for this value and remember it.
|
|
|
|
Value *FwdVal;
|
2009-10-05 05:54:46 +00:00
|
|
|
if (Ty->isLabelTy())
|
2009-08-13 21:58:54 +00:00
|
|
|
FwdVal = BasicBlock::Create(F.getContext(), Name, &F);
|
2009-01-02 07:01:27 +00:00
|
|
|
else
|
|
|
|
FwdVal = new Argument(Ty, Name);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
|
|
|
|
return FwdVal;
|
|
|
|
}
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *LLParser::PerFunctionState::GetVal(unsigned ID, Type *Ty,
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy Loc) {
|
|
|
|
// Look this name up in the normal function symbol table.
|
|
|
|
Value *Val = ID < NumberedVals.size() ? NumberedVals[ID] : 0;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If this is a forward reference for the value, see if we already created a
|
|
|
|
// forward ref record.
|
|
|
|
if (Val == 0) {
|
|
|
|
std::map<unsigned, std::pair<Value*, LocTy> >::iterator
|
|
|
|
I = ForwardRefValIDs.find(ID);
|
|
|
|
if (I != ForwardRefValIDs.end())
|
|
|
|
Val = I->second.first;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If we have the value in the symbol table or fwd-ref table, return it.
|
|
|
|
if (Val) {
|
|
|
|
if (Val->getType() == Ty) return Val;
|
2009-10-05 05:54:46 +00:00
|
|
|
if (Ty->isLabelTy())
|
2010-09-27 17:42:11 +00:00
|
|
|
P.Error(Loc, "'%" + Twine(ID) + "' is not a basic block");
|
2009-01-02 07:01:27 +00:00
|
|
|
else
|
2010-09-27 17:42:11 +00:00
|
|
|
P.Error(Loc, "'%" + Twine(ID) + "' defined with type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(Val->getType()) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +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
|
|
|
if (!Ty->isFirstClassType() && !Ty->isLabelTy()) {
|
2009-01-02 07:01:27 +00:00
|
|
|
P.Error(Loc, "invalid use of a non-first-class type");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Otherwise, create a new forward reference for this value and remember it.
|
|
|
|
Value *FwdVal;
|
2009-10-05 05:54:46 +00:00
|
|
|
if (Ty->isLabelTy())
|
2009-08-13 21:58:54 +00:00
|
|
|
FwdVal = BasicBlock::Create(F.getContext(), "", &F);
|
2009-01-02 07:01:27 +00:00
|
|
|
else
|
|
|
|
FwdVal = new Argument(Ty);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
|
|
|
|
return FwdVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// SetInstName - After an instruction is parsed and inserted into its
|
|
|
|
/// basic block, this installs its name.
|
|
|
|
bool LLParser::PerFunctionState::SetInstName(int NameID,
|
|
|
|
const std::string &NameStr,
|
|
|
|
LocTy NameLoc, Instruction *Inst) {
|
|
|
|
// If this instruction has void type, it cannot have a name or ID specified.
|
2009-10-05 05:54:46 +00:00
|
|
|
if (Inst->getType()->isVoidTy()) {
|
2009-01-02 07:01:27 +00:00
|
|
|
if (NameID != -1 || !NameStr.empty())
|
|
|
|
return P.Error(NameLoc, "instructions returning void cannot have a name");
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If this was a numbered instruction, verify that the instruction is the
|
|
|
|
// expected value and resolve any forward references.
|
|
|
|
if (NameStr.empty()) {
|
|
|
|
// If neither a name nor an ID was specified, just use the next ID.
|
|
|
|
if (NameID == -1)
|
|
|
|
NameID = NumberedVals.size();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (unsigned(NameID) != NumberedVals.size())
|
|
|
|
return P.Error(NameLoc, "instruction expected to be numbered '%" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(NumberedVals.size()) + "'");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
std::map<unsigned, std::pair<Value*, LocTy> >::iterator FI =
|
|
|
|
ForwardRefValIDs.find(NameID);
|
|
|
|
if (FI != ForwardRefValIDs.end()) {
|
|
|
|
if (FI->second.first->getType() != Inst->getType())
|
2009-09-20 02:20:51 +00:00
|
|
|
return P.Error(NameLoc, "instruction forward referenced with type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(FI->second.first->getType()) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
FI->second.first->replaceAllUsesWith(Inst);
|
2009-09-02 15:02:57 +00:00
|
|
|
delete FI->second.first;
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefValIDs.erase(FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberedVals.push_back(Inst);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, the instruction had a name. Resolve forward refs and set it.
|
|
|
|
std::map<std::string, std::pair<Value*, LocTy> >::iterator
|
|
|
|
FI = ForwardRefVals.find(NameStr);
|
|
|
|
if (FI != ForwardRefVals.end()) {
|
|
|
|
if (FI->second.first->getType() != Inst->getType())
|
2009-09-20 02:20:51 +00:00
|
|
|
return P.Error(NameLoc, "instruction forward referenced with type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(FI->second.first->getType()) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
FI->second.first->replaceAllUsesWith(Inst);
|
2009-09-02 14:22:03 +00:00
|
|
|
delete FI->second.first;
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefVals.erase(FI);
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Set the name on the instruction.
|
|
|
|
Inst->setName(NameStr);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2010-10-16 11:28:23 +00:00
|
|
|
if (Inst->getName() != NameStr)
|
2009-09-20 02:20:51 +00:00
|
|
|
return P.Error(NameLoc, "multiple definition of local value named '" +
|
2009-01-02 07:01:27 +00:00
|
|
|
NameStr + "'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GetBB - Get a basic block with the specified name or ID, creating a
|
|
|
|
/// forward reference record if needed.
|
|
|
|
BasicBlock *LLParser::PerFunctionState::GetBB(const std::string &Name,
|
|
|
|
LocTy Loc) {
|
2009-08-13 21:58:54 +00:00
|
|
|
return cast_or_null<BasicBlock>(GetVal(Name,
|
|
|
|
Type::getLabelTy(F.getContext()), Loc));
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BasicBlock *LLParser::PerFunctionState::GetBB(unsigned ID, LocTy Loc) {
|
2009-08-13 21:58:54 +00:00
|
|
|
return cast_or_null<BasicBlock>(GetVal(ID,
|
|
|
|
Type::getLabelTy(F.getContext()), Loc));
|
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 *LLParser::PerFunctionState::DefineBB(const std::string &Name,
|
|
|
|
LocTy Loc) {
|
|
|
|
BasicBlock *BB;
|
|
|
|
if (Name.empty())
|
|
|
|
BB = GetBB(NumberedVals.size(), Loc);
|
|
|
|
else
|
|
|
|
BB = GetBB(Name, Loc);
|
|
|
|
if (BB == 0) return 0; // Already diagnosed error.
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Move the block to the end of the function. Forward ref'd blocks are
|
|
|
|
// inserted wherever they happen to be referenced.
|
|
|
|
F.getBasicBlockList().splice(F.end(), F.getBasicBlockList(), BB);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Remove the block from forward ref sets.
|
|
|
|
if (Name.empty()) {
|
|
|
|
ForwardRefValIDs.erase(NumberedVals.size());
|
|
|
|
NumberedVals.push_back(BB);
|
|
|
|
} else {
|
|
|
|
// BB forward references are already in the function symbol table.
|
|
|
|
ForwardRefVals.erase(Name);
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return BB;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Constants.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseValID - Parse an abstract value that doesn't necessarily have a
|
|
|
|
/// type implied. For example, if we parse "4" we don't know what integer type
|
|
|
|
/// it has. The value will later be combined with its type and checked for
|
2010-01-10 07:14:18 +00:00
|
|
|
/// sanity. PFS is used to convert function-local operands of metadata (since
|
|
|
|
/// metadata operands are not just parsed here but also converted to values).
|
|
|
|
/// PFS can be null when we are not parsing metadata values inside a function.
|
2010-01-05 22:22:14 +00:00
|
|
|
bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Loc = Lex.getLoc();
|
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: return TokError("expected value token");
|
|
|
|
case lltok::GlobalID: // @42
|
|
|
|
ID.UIntVal = Lex.getUIntVal();
|
|
|
|
ID.Kind = ValID::t_GlobalID;
|
|
|
|
break;
|
|
|
|
case lltok::GlobalVar: // @foo
|
|
|
|
ID.StrVal = Lex.getStrVal();
|
|
|
|
ID.Kind = ValID::t_GlobalName;
|
|
|
|
break;
|
|
|
|
case lltok::LocalVarID: // %42
|
|
|
|
ID.UIntVal = Lex.getUIntVal();
|
|
|
|
ID.Kind = ValID::t_LocalID;
|
|
|
|
break;
|
|
|
|
case lltok::LocalVar: // %foo
|
|
|
|
ID.StrVal = Lex.getStrVal();
|
|
|
|
ID.Kind = ValID::t_LocalName;
|
|
|
|
break;
|
2010-07-14 18:26:50 +00:00
|
|
|
case lltok::exclaim: // !42, !{...}, or !"foo"
|
|
|
|
return ParseMetadataValue(ID, PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::APSInt:
|
2009-09-20 02:20:51 +00:00
|
|
|
ID.APSIntVal = Lex.getAPSIntVal();
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_APSInt;
|
|
|
|
break;
|
|
|
|
case lltok::APFloat:
|
|
|
|
ID.APFloatVal = Lex.getAPFloatVal();
|
|
|
|
ID.Kind = ValID::t_APFloat;
|
|
|
|
break;
|
|
|
|
case lltok::kw_true:
|
2009-07-31 17:39:07 +00:00
|
|
|
ID.ConstantVal = ConstantInt::getTrue(Context);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
break;
|
|
|
|
case lltok::kw_false:
|
2009-07-31 17:39:07 +00:00
|
|
|
ID.ConstantVal = ConstantInt::getFalse(Context);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
break;
|
|
|
|
case lltok::kw_null: ID.Kind = ValID::t_Null; break;
|
|
|
|
case lltok::kw_undef: ID.Kind = ValID::t_Undef; break;
|
|
|
|
case lltok::kw_zeroinitializer: ID.Kind = ValID::t_Zero; break;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::lbrace: {
|
|
|
|
// ValID ::= '{' ConstVector '}'
|
|
|
|
Lex.Lex();
|
|
|
|
SmallVector<Constant*, 16> Elts;
|
|
|
|
if (ParseGlobalValueVector(Elts) ||
|
|
|
|
ParseToken(lltok::rbrace, "expected end of struct constant"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +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
|
|
|
ID.ConstantStructElts = new Constant*[Elts.size()];
|
|
|
|
ID.UIntVal = Elts.size();
|
|
|
|
memcpy(ID.ConstantStructElts, Elts.data(), Elts.size()*sizeof(Elts[0]));
|
|
|
|
ID.Kind = ValID::t_ConstantStruct;
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case lltok::less: {
|
|
|
|
// ValID ::= '<' ConstVector '>' --> Vector.
|
|
|
|
// ValID ::= '<' '{' ConstVector '}' '>' --> Packed Struct.
|
|
|
|
Lex.Lex();
|
2009-01-02 08:05:26 +00:00
|
|
|
bool isPackedStruct = EatIfPresent(lltok::lbrace);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<Constant*, 16> Elts;
|
|
|
|
LocTy FirstEltLoc = Lex.getLoc();
|
|
|
|
if (ParseGlobalValueVector(Elts) ||
|
|
|
|
(isPackedStruct &&
|
|
|
|
ParseToken(lltok::rbrace, "expected end of packed struct")) ||
|
|
|
|
ParseToken(lltok::greater, "expected end of constant"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (isPackedStruct) {
|
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
|
|
|
ID.ConstantStructElts = new Constant*[Elts.size()];
|
|
|
|
memcpy(ID.ConstantStructElts, Elts.data(), Elts.size()*sizeof(Elts[0]));
|
|
|
|
ID.UIntVal = Elts.size();
|
|
|
|
ID.Kind = ValID::t_PackedConstantStruct;
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Elts.empty())
|
|
|
|
return Error(ID.Loc, "constant vector must not be empty");
|
|
|
|
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!Elts[0]->getType()->isIntegerTy() &&
|
2011-12-05 06:29:09 +00:00
|
|
|
!Elts[0]->getType()->isFloatingPointTy() &&
|
|
|
|
!Elts[0]->getType()->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(FirstEltLoc,
|
2011-12-05 06:29:09 +00:00
|
|
|
"vector elements must have integer, pointer or floating point type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Verify that all the vector elements have the same type.
|
|
|
|
for (unsigned i = 1, e = Elts.size(); i != e; ++i)
|
|
|
|
if (Elts[i]->getType() != Elts[0]->getType())
|
|
|
|
return Error(FirstEltLoc,
|
2010-09-27 17:42:11 +00:00
|
|
|
"vector element #" + Twine(i) +
|
2011-06-18 21:18:23 +00:00
|
|
|
" is not of type '" + getTypeString(Elts[0]->getType()));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-02-15 00:14:00 +00:00
|
|
|
ID.ConstantVal = ConstantVector::get(Elts);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case lltok::lsquare: { // Array Constant
|
|
|
|
Lex.Lex();
|
|
|
|
SmallVector<Constant*, 16> Elts;
|
|
|
|
LocTy FirstEltLoc = Lex.getLoc();
|
|
|
|
if (ParseGlobalValueVector(Elts) ||
|
|
|
|
ParseToken(lltok::rsquare, "expected end of array constant"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Handle empty element.
|
|
|
|
if (Elts.empty()) {
|
|
|
|
// Use undef instead of an array because it's inconvenient to determine
|
|
|
|
// the element type at this point, there being no elements to examine.
|
2009-01-05 07:52:51 +00:00
|
|
|
ID.Kind = ValID::t_EmptyArray;
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!Elts[0]->getType()->isFirstClassType())
|
2009-09-20 02:20:51 +00:00
|
|
|
return Error(FirstEltLoc, "invalid array element type: " +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(Elts[0]->getType()));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-07-29 22:17:13 +00:00
|
|
|
ArrayType *ATy = ArrayType::get(Elts[0]->getType(), Elts.size());
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Verify all elements are correct type!
|
2009-01-02 08:49:06 +00:00
|
|
|
for (unsigned i = 0, e = Elts.size(); i != e; ++i) {
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Elts[i]->getType() != Elts[0]->getType())
|
|
|
|
return Error(FirstEltLoc,
|
2010-09-27 17:42:11 +00:00
|
|
|
"array element #" + Twine(i) +
|
2011-06-18 21:18:23 +00:00
|
|
|
" is not of type '" + getTypeString(Elts[0]->getType()));
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-06-22 09:24:39 +00:00
|
|
|
ID.ConstantVal = ConstantArray::get(ATy, Elts);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case lltok::kw_c: // c "foo"
|
|
|
|
Lex.Lex();
|
2012-02-05 02:29:43 +00:00
|
|
|
ID.ConstantVal = ConstantDataArray::getString(Context, Lex.getStrVal(),
|
|
|
|
false);
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseToken(lltok::StringConstant, "expected string")) return true;
|
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case lltok::kw_asm: {
|
2009-10-21 23:28:00 +00:00
|
|
|
// ValID ::= 'asm' SideEffect? AlignStack? STRINGCONSTANT ',' STRINGCONSTANT
|
2012-09-05 19:00:49 +00:00
|
|
|
bool HasSideEffect, AlignStack, AsmDialect;
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
if (ParseOptionalToken(lltok::kw_sideeffect, HasSideEffect) ||
|
2009-10-21 23:28:00 +00:00
|
|
|
ParseOptionalToken(lltok::kw_alignstack, AlignStack) ||
|
2012-09-05 19:00:49 +00:00
|
|
|
ParseOptionalToken(lltok::kw_inteldialect, AsmDialect) ||
|
2009-01-02 08:05:26 +00:00
|
|
|
ParseStringConstant(ID.StrVal) ||
|
|
|
|
ParseToken(lltok::comma, "expected comma in inline asm expression") ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::StringConstant, "expected constraint string"))
|
|
|
|
return true;
|
|
|
|
ID.StrVal2 = Lex.getStrVal();
|
2012-09-05 00:08:17 +00:00
|
|
|
ID.UIntVal = unsigned(HasSideEffect) | (unsigned(AlignStack)<<1) |
|
2012-09-05 19:00:49 +00:00
|
|
|
(unsigned(AsmDialect)<<2);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_InlineAsm;
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
case lltok::kw_blockaddress: {
|
|
|
|
// ValID ::= 'blockaddress' '(' @foo ',' %bar ')'
|
|
|
|
Lex.Lex();
|
|
|
|
|
|
|
|
ValID Fn, Label;
|
|
|
|
LocTy FnLoc, LabelLoc;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
if (ParseToken(lltok::lparen, "expected '(' in block address expression") ||
|
|
|
|
ParseValID(Fn) ||
|
|
|
|
ParseToken(lltok::comma, "expected comma in block address expression")||
|
|
|
|
ParseValID(Label) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' in block address expression"))
|
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
if (Fn.Kind != ValID::t_GlobalID && Fn.Kind != ValID::t_GlobalName)
|
|
|
|
return Error(Fn.Loc, "expected function name in blockaddress");
|
2009-11-01 01:27:45 +00:00
|
|
|
if (Label.Kind != ValID::t_LocalID && Label.Kind != ValID::t_LocalName)
|
2009-10-28 03:39:23 +00:00
|
|
|
return Error(Label.Loc, "expected basic block name in blockaddress");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
// Make a global variable as a placeholder for this reference.
|
|
|
|
GlobalVariable *FwdRef = new GlobalVariable(*M, Type::getInt8Ty(Context),
|
|
|
|
false, GlobalValue::InternalLinkage,
|
|
|
|
0, "");
|
|
|
|
ForwardRefBlockAddresses[Fn].push_back(std::make_pair(Label, FwdRef));
|
|
|
|
ID.ConstantVal = FwdRef;
|
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_trunc:
|
|
|
|
case lltok::kw_zext:
|
|
|
|
case lltok::kw_sext:
|
|
|
|
case lltok::kw_fptrunc:
|
|
|
|
case lltok::kw_fpext:
|
|
|
|
case lltok::kw_bitcast:
|
|
|
|
case lltok::kw_uitofp:
|
|
|
|
case lltok::kw_sitofp:
|
|
|
|
case lltok::kw_fptoui:
|
2009-09-20 02:20:51 +00:00
|
|
|
case lltok::kw_fptosi:
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_inttoptr:
|
2009-09-20 02:20:51 +00:00
|
|
|
case lltok::kw_ptrtoint: {
|
2009-01-02 07:01:27 +00:00
|
|
|
unsigned Opc = Lex.getUIntVal();
|
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 *DestTy = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
Constant *SrcVal;
|
|
|
|
Lex.Lex();
|
|
|
|
if (ParseToken(lltok::lparen, "expected '(' after constantexpr cast") ||
|
|
|
|
ParseGlobalTypeAndValue(SrcVal) ||
|
2009-06-15 21:52:11 +00:00
|
|
|
ParseToken(lltok::kw_to, "expected 'to' in constantexpr cast") ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseType(DestTy) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' at end of constantexpr cast"))
|
|
|
|
return true;
|
|
|
|
if (!CastInst::castIsValid((Instruction::CastOps)Opc, SrcVal, DestTy))
|
|
|
|
return Error(ID.Loc, "invalid cast opcode for cast from '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(SrcVal->getType()) + "' to '" +
|
|
|
|
getTypeString(DestTy) + "'");
|
2009-09-20 02:20:51 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getCast((Instruction::CastOps)Opc,
|
2009-07-01 23:57:11 +00:00
|
|
|
SrcVal, DestTy);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case lltok::kw_extractvalue: {
|
|
|
|
Lex.Lex();
|
|
|
|
Constant *Val;
|
|
|
|
SmallVector<unsigned, 4> Indices;
|
|
|
|
if (ParseToken(lltok::lparen, "expected '(' in extractvalue constantexpr")||
|
|
|
|
ParseGlobalTypeAndValue(Val) ||
|
|
|
|
ParseIndexList(Indices) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' in extractvalue constantexpr"))
|
|
|
|
return true;
|
2009-11-03 19:06:07 +00:00
|
|
|
|
2010-02-12 20:49:41 +00:00
|
|
|
if (!Val->getType()->isAggregateType())
|
|
|
|
return Error(ID.Loc, "extractvalue operand must be aggregate type");
|
2011-07-13 10:26:04 +00:00
|
|
|
if (!ExtractValueInst::getIndexedType(Val->getType(), Indices))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "invalid indices for extractvalue");
|
2011-07-13 10:26:04 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getExtractValue(Val, Indices);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case lltok::kw_insertvalue: {
|
|
|
|
Lex.Lex();
|
|
|
|
Constant *Val0, *Val1;
|
|
|
|
SmallVector<unsigned, 4> Indices;
|
|
|
|
if (ParseToken(lltok::lparen, "expected '(' in insertvalue constantexpr")||
|
|
|
|
ParseGlobalTypeAndValue(Val0) ||
|
|
|
|
ParseToken(lltok::comma, "expected comma in insertvalue constantexpr")||
|
|
|
|
ParseGlobalTypeAndValue(Val1) ||
|
|
|
|
ParseIndexList(Indices) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' in insertvalue constantexpr"))
|
|
|
|
return true;
|
2010-02-12 20:49:41 +00:00
|
|
|
if (!Val0->getType()->isAggregateType())
|
|
|
|
return Error(ID.Loc, "insertvalue operand must be aggregate type");
|
2011-07-13 10:26:04 +00:00
|
|
|
if (!ExtractValueInst::getIndexedType(Val0->getType(), Indices))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "invalid indices for insertvalue");
|
2011-07-13 10:26:04 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getInsertValue(Val0, Val1, Indices);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case lltok::kw_icmp:
|
2009-07-08 03:04:38 +00:00
|
|
|
case lltok::kw_fcmp: {
|
2009-01-02 07:01:27 +00:00
|
|
|
unsigned PredVal, Opc = Lex.getUIntVal();
|
|
|
|
Constant *Val0, *Val1;
|
|
|
|
Lex.Lex();
|
|
|
|
if (ParseCmpPredicate(PredVal, Opc) ||
|
|
|
|
ParseToken(lltok::lparen, "expected '(' in compare constantexpr") ||
|
|
|
|
ParseGlobalTypeAndValue(Val0) ||
|
|
|
|
ParseToken(lltok::comma, "expected comma in compare constantexpr") ||
|
|
|
|
ParseGlobalTypeAndValue(Val1) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' in compare constantexpr"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Val0->getType() != Val1->getType())
|
|
|
|
return Error(ID.Loc, "compare operands must have the same type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
CmpInst::Predicate Pred = (CmpInst::Predicate)PredVal;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Opc == Instruction::FCmp) {
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!Val0->getType()->isFPOrFPVectorTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "fcmp requires floating point operands");
|
2009-07-29 18:55:55 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getFCmp(Pred, Val0, Val1);
|
2009-07-08 03:04:38 +00:00
|
|
|
} else {
|
|
|
|
assert(Opc == Instruction::ICmp && "Unexpected opcode for CmpInst!");
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!Val0->getType()->isIntOrIntVectorTy() &&
|
2011-12-05 06:29:09 +00:00
|
|
|
!Val0->getType()->getScalarType()->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "icmp requires pointer or integer operands");
|
2009-07-29 18:55:55 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getICmp(Pred, Val0, Val1);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Binary Operators.
|
|
|
|
case lltok::kw_add:
|
2009-06-04 22:49:04 +00:00
|
|
|
case lltok::kw_fadd:
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_sub:
|
2009-06-04 22:49:04 +00:00
|
|
|
case lltok::kw_fsub:
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_mul:
|
2009-06-04 22:49:04 +00:00
|
|
|
case lltok::kw_fmul:
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_udiv:
|
|
|
|
case lltok::kw_sdiv:
|
|
|
|
case lltok::kw_fdiv:
|
|
|
|
case lltok::kw_urem:
|
|
|
|
case lltok::kw_srem:
|
2011-02-07 16:40:21 +00:00
|
|
|
case lltok::kw_frem:
|
|
|
|
case lltok::kw_shl:
|
|
|
|
case lltok::kw_lshr:
|
|
|
|
case lltok::kw_ashr: {
|
2009-07-27 16:11:46 +00:00
|
|
|
bool NUW = false;
|
|
|
|
bool NSW = false;
|
|
|
|
bool Exact = false;
|
2009-01-02 07:01:27 +00:00
|
|
|
unsigned Opc = Lex.getUIntVal();
|
|
|
|
Constant *Val0, *Val1;
|
|
|
|
Lex.Lex();
|
2009-07-27 16:11:46 +00:00
|
|
|
LocTy ModifierLoc = Lex.getLoc();
|
2011-02-07 16:40:21 +00:00
|
|
|
if (Opc == Instruction::Add || Opc == Instruction::Sub ||
|
|
|
|
Opc == Instruction::Mul || Opc == Instruction::Shl) {
|
2009-07-27 16:11:46 +00:00
|
|
|
if (EatIfPresent(lltok::kw_nuw))
|
|
|
|
NUW = true;
|
|
|
|
if (EatIfPresent(lltok::kw_nsw)) {
|
|
|
|
NSW = true;
|
|
|
|
if (EatIfPresent(lltok::kw_nuw))
|
|
|
|
NUW = true;
|
|
|
|
}
|
2011-02-07 16:40:21 +00:00
|
|
|
} else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv ||
|
|
|
|
Opc == Instruction::LShr || Opc == Instruction::AShr) {
|
2009-07-27 16:11:46 +00:00
|
|
|
if (EatIfPresent(lltok::kw_exact))
|
|
|
|
Exact = true;
|
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseToken(lltok::lparen, "expected '(' in binary constantexpr") ||
|
|
|
|
ParseGlobalTypeAndValue(Val0) ||
|
|
|
|
ParseToken(lltok::comma, "expected comma in binary constantexpr") ||
|
|
|
|
ParseGlobalTypeAndValue(Val1) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' in binary constantexpr"))
|
|
|
|
return true;
|
|
|
|
if (Val0->getType() != Val1->getType())
|
|
|
|
return Error(ID.Loc, "operands of constexpr must have same type");
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!Val0->getType()->isIntOrIntVectorTy()) {
|
2009-07-27 16:11:46 +00:00
|
|
|
if (NUW)
|
|
|
|
return Error(ModifierLoc, "nuw only applies to integer operations");
|
|
|
|
if (NSW)
|
|
|
|
return Error(ModifierLoc, "nsw only applies to integer operations");
|
|
|
|
}
|
2010-05-03 22:44:19 +00:00
|
|
|
// Check that the type is valid for the operator.
|
|
|
|
switch (Opc) {
|
|
|
|
case Instruction::Add:
|
|
|
|
case Instruction::Sub:
|
|
|
|
case Instruction::Mul:
|
|
|
|
case Instruction::UDiv:
|
|
|
|
case Instruction::SDiv:
|
|
|
|
case Instruction::URem:
|
|
|
|
case Instruction::SRem:
|
2011-02-07 16:40:21 +00:00
|
|
|
case Instruction::Shl:
|
|
|
|
case Instruction::AShr:
|
|
|
|
case Instruction::LShr:
|
2010-05-03 22:44:19 +00:00
|
|
|
if (!Val0->getType()->isIntOrIntVectorTy())
|
|
|
|
return Error(ID.Loc, "constexpr requires integer operands");
|
|
|
|
break;
|
|
|
|
case Instruction::FAdd:
|
|
|
|
case Instruction::FSub:
|
|
|
|
case Instruction::FMul:
|
|
|
|
case Instruction::FDiv:
|
|
|
|
case Instruction::FRem:
|
|
|
|
if (!Val0->getType()->isFPOrFPVectorTy())
|
|
|
|
return Error(ID.Loc, "constexpr requires fp operands");
|
|
|
|
break;
|
|
|
|
default: llvm_unreachable("Unknown binary operator!");
|
|
|
|
}
|
2009-09-07 23:54:19 +00:00
|
|
|
unsigned Flags = 0;
|
|
|
|
if (NUW) Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
|
|
|
|
if (NSW) Flags |= OverflowingBinaryOperator::NoSignedWrap;
|
2011-02-06 21:44:57 +00:00
|
|
|
if (Exact) Flags |= PossiblyExactOperator::IsExact;
|
2009-09-07 23:54:19 +00:00
|
|
|
Constant *C = ConstantExpr::get(Opc, Val0, Val1, Flags);
|
2009-07-27 16:11:46 +00:00
|
|
|
ID.ConstantVal = C;
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Logical Operations
|
|
|
|
case lltok::kw_and:
|
|
|
|
case lltok::kw_or:
|
|
|
|
case lltok::kw_xor: {
|
|
|
|
unsigned Opc = Lex.getUIntVal();
|
|
|
|
Constant *Val0, *Val1;
|
|
|
|
Lex.Lex();
|
|
|
|
if (ParseToken(lltok::lparen, "expected '(' in logical constantexpr") ||
|
|
|
|
ParseGlobalTypeAndValue(Val0) ||
|
|
|
|
ParseToken(lltok::comma, "expected comma in logical constantexpr") ||
|
|
|
|
ParseGlobalTypeAndValue(Val1) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' in logical constantexpr"))
|
|
|
|
return true;
|
|
|
|
if (Val0->getType() != Val1->getType())
|
|
|
|
return Error(ID.Loc, "operands of constexpr must have same type");
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!Val0->getType()->isIntOrIntVectorTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc,
|
|
|
|
"constexpr requires integer or integer vector operands");
|
2009-07-29 18:55:55 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1);
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
2009-09-20 02:20:51 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_getelementptr:
|
|
|
|
case lltok::kw_shufflevector:
|
|
|
|
case lltok::kw_insertelement:
|
|
|
|
case lltok::kw_extractelement:
|
|
|
|
case lltok::kw_select: {
|
|
|
|
unsigned Opc = Lex.getUIntVal();
|
|
|
|
SmallVector<Constant*, 16> Elts;
|
2009-07-27 21:53:46 +00:00
|
|
|
bool InBounds = false;
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
2009-07-27 21:53:46 +00:00
|
|
|
if (Opc == Instruction::GetElementPtr)
|
2009-07-29 15:58:36 +00:00
|
|
|
InBounds = EatIfPresent(lltok::kw_inbounds);
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseToken(lltok::lparen, "expected '(' in constantexpr") ||
|
|
|
|
ParseGlobalValueVector(Elts) ||
|
|
|
|
ParseToken(lltok::rparen, "expected ')' in constantexpr"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Opc == Instruction::GetElementPtr) {
|
2011-12-05 06:29:09 +00:00
|
|
|
if (Elts.size() == 0 ||
|
|
|
|
!Elts[0]->getType()->getScalarType()->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "getelementptr requires pointer operand");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-07-21 14:31:17 +00:00
|
|
|
ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end());
|
2011-07-25 09:48:08 +00:00
|
|
|
if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), Indices))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "invalid indices for getelementptr");
|
2011-07-21 15:15:37 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0], Indices,
|
|
|
|
InBounds);
|
2009-01-02 07:01:27 +00:00
|
|
|
} else if (Opc == Instruction::Select) {
|
|
|
|
if (Elts.size() != 3)
|
|
|
|
return Error(ID.Loc, "expected three operands to select");
|
|
|
|
if (const char *Reason = SelectInst::areInvalidOperands(Elts[0], Elts[1],
|
|
|
|
Elts[2]))
|
|
|
|
return Error(ID.Loc, Reason);
|
2009-07-29 18:55:55 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getSelect(Elts[0], Elts[1], Elts[2]);
|
2009-01-02 07:01:27 +00:00
|
|
|
} else if (Opc == Instruction::ShuffleVector) {
|
|
|
|
if (Elts.size() != 3)
|
|
|
|
return Error(ID.Loc, "expected three operands to shufflevector");
|
|
|
|
if (!ShuffleVectorInst::isValidOperands(Elts[0], Elts[1], Elts[2]))
|
|
|
|
return Error(ID.Loc, "invalid operands to shufflevector");
|
2009-07-01 23:57:11 +00:00
|
|
|
ID.ConstantVal =
|
2009-07-29 18:55:55 +00:00
|
|
|
ConstantExpr::getShuffleVector(Elts[0], Elts[1],Elts[2]);
|
2009-01-02 07:01:27 +00:00
|
|
|
} else if (Opc == Instruction::ExtractElement) {
|
|
|
|
if (Elts.size() != 2)
|
|
|
|
return Error(ID.Loc, "expected two operands to extractelement");
|
|
|
|
if (!ExtractElementInst::isValidOperands(Elts[0], Elts[1]))
|
|
|
|
return Error(ID.Loc, "invalid extractelement operands");
|
2009-07-29 18:55:55 +00:00
|
|
|
ID.ConstantVal = ConstantExpr::getExtractElement(Elts[0], Elts[1]);
|
2009-01-02 07:01:27 +00:00
|
|
|
} else {
|
|
|
|
assert(Opc == Instruction::InsertElement && "Unknown opcode");
|
|
|
|
if (Elts.size() != 3)
|
|
|
|
return Error(ID.Loc, "expected three operands to insertelement");
|
|
|
|
if (!InsertElementInst::isValidOperands(Elts[0], Elts[1], Elts[2]))
|
|
|
|
return Error(ID.Loc, "invalid insertelement operands");
|
2009-07-01 23:57:11 +00:00
|
|
|
ID.ConstantVal =
|
2009-07-29 18:55:55 +00:00
|
|
|
ConstantExpr::getInsertElement(Elts[0], Elts[1],Elts[2]);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
ID.Kind = ValID::t_Constant;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseGlobalValue - Parse a global value with the specified type.
|
2011-07-18 04:54:35 +00:00
|
|
|
bool LLParser::ParseGlobalValue(Type *Ty, Constant *&C) {
|
2010-01-11 22:31:58 +00:00
|
|
|
C = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
ValID ID;
|
2010-01-11 22:31:58 +00:00
|
|
|
Value *V = NULL;
|
|
|
|
bool Parsed = ParseValID(ID) ||
|
|
|
|
ConvertValIDToValue(Ty, ID, V, NULL);
|
|
|
|
if (V && !(C = dyn_cast<Constant>(V)))
|
|
|
|
return Error(ID.Loc, "global values must be constants");
|
|
|
|
return Parsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LLParser::ParseGlobalTypeAndValue(Constant *&V) {
|
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 = 0;
|
|
|
|
return ParseType(Ty) ||
|
|
|
|
ParseGlobalValue(Ty, V);
|
2010-01-11 22:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseGlobalValueVector
|
|
|
|
/// ::= /*empty*/
|
|
|
|
/// ::= TypeAndValue (',' TypeAndValue)*
|
|
|
|
bool LLParser::ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts) {
|
|
|
|
// Empty list.
|
|
|
|
if (Lex.getKind() == lltok::rbrace ||
|
|
|
|
Lex.getKind() == lltok::rsquare ||
|
|
|
|
Lex.getKind() == lltok::greater ||
|
|
|
|
Lex.getKind() == lltok::rparen)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Constant *C;
|
|
|
|
if (ParseGlobalTypeAndValue(C)) return true;
|
|
|
|
Elts.push_back(C);
|
|
|
|
|
|
|
|
while (EatIfPresent(lltok::comma)) {
|
|
|
|
if (ParseGlobalTypeAndValue(C)) return true;
|
|
|
|
Elts.push_back(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
2010-08-24 02:24:03 +00:00
|
|
|
bool LLParser::ParseMetadataListValue(ValID &ID, PerFunctionState *PFS) {
|
|
|
|
assert(Lex.getKind() == lltok::lbrace);
|
|
|
|
Lex.Lex();
|
|
|
|
|
|
|
|
SmallVector<Value*, 16> Elts;
|
|
|
|
if (ParseMDNodeVector(Elts, PFS) ||
|
|
|
|
ParseToken(lltok::rbrace, "expected end of metadata node"))
|
|
|
|
return true;
|
|
|
|
|
2011-04-21 19:59:31 +00:00
|
|
|
ID.MDNodeVal = MDNode::get(Context, Elts);
|
2010-08-24 02:24:03 +00:00
|
|
|
ID.Kind = ValID::t_MDNode;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-14 18:26:50 +00:00
|
|
|
/// ParseMetadataValue
|
|
|
|
/// ::= !42
|
|
|
|
/// ::= !{...}
|
|
|
|
/// ::= !"string"
|
|
|
|
bool LLParser::ParseMetadataValue(ValID &ID, PerFunctionState *PFS) {
|
|
|
|
assert(Lex.getKind() == lltok::exclaim);
|
|
|
|
Lex.Lex();
|
|
|
|
|
|
|
|
// MDNode:
|
|
|
|
// !{ ... }
|
2010-08-24 02:24:03 +00:00
|
|
|
if (Lex.getKind() == lltok::lbrace)
|
|
|
|
return ParseMetadataListValue(ID, PFS);
|
2010-07-14 18:26:50 +00:00
|
|
|
|
|
|
|
// Standalone metadata reference
|
|
|
|
// !42
|
|
|
|
if (Lex.getKind() == lltok::APSInt) {
|
|
|
|
if (ParseMDNodeID(ID.MDNodeVal)) return true;
|
|
|
|
ID.Kind = ValID::t_MDNode;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MDString:
|
|
|
|
// ::= '!' STRINGCONSTANT
|
|
|
|
if (ParseMDString(ID.MDStringVal)) return true;
|
|
|
|
ID.Kind = ValID::t_MDString;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-11 22:31:58 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Function Parsing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
bool LLParser::ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
|
2010-01-11 22:31:58 +00:00
|
|
|
PerFunctionState *PFS) {
|
2010-02-16 11:11:14 +00:00
|
|
|
if (Ty->isFunctionTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "functions are not values, refer to them as pointers");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
switch (ID.Kind) {
|
|
|
|
case ValID::t_LocalID:
|
2010-01-11 22:31:58 +00:00
|
|
|
if (!PFS) return Error(ID.Loc, "invalid use of function-local name");
|
|
|
|
V = PFS->GetVal(ID.UIntVal, Ty, ID.Loc);
|
|
|
|
return (V == 0);
|
2009-01-02 07:01:27 +00:00
|
|
|
case ValID::t_LocalName:
|
2010-01-11 22:31:58 +00:00
|
|
|
if (!PFS) return Error(ID.Loc, "invalid use of function-local name");
|
|
|
|
V = PFS->GetVal(ID.StrVal, Ty, ID.Loc);
|
|
|
|
return (V == 0);
|
|
|
|
case ValID::t_InlineAsm: {
|
2011-07-18 04:54:35 +00:00
|
|
|
PointerType *PTy = dyn_cast<PointerType>(Ty);
|
2012-11-15 22:34:00 +00:00
|
|
|
FunctionType *FTy =
|
2010-01-11 22:31:58 +00:00
|
|
|
PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
|
|
|
|
if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2))
|
|
|
|
return Error(ID.Loc, "invalid type for inline asm constraint string");
|
2012-09-05 00:08:17 +00:00
|
|
|
V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal&1,
|
2012-09-05 19:00:49 +00:00
|
|
|
(ID.UIntVal>>1)&1, (InlineAsm::AsmDialect(ID.UIntVal>>2)));
|
2010-01-11 22:31:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case ValID::t_MDNode:
|
|
|
|
if (!Ty->isMetadataTy())
|
|
|
|
return Error(ID.Loc, "metadata value must have metadata type");
|
|
|
|
V = ID.MDNodeVal;
|
|
|
|
return false;
|
|
|
|
case ValID::t_MDString:
|
|
|
|
if (!Ty->isMetadataTy())
|
|
|
|
return Error(ID.Loc, "metadata value must have metadata type");
|
|
|
|
V = ID.MDStringVal;
|
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
case ValID::t_GlobalName:
|
|
|
|
V = GetGlobalVal(ID.StrVal, Ty, ID.Loc);
|
|
|
|
return V == 0;
|
|
|
|
case ValID::t_GlobalID:
|
|
|
|
V = GetGlobalVal(ID.UIntVal, Ty, ID.Loc);
|
|
|
|
return V == 0;
|
|
|
|
case ValID::t_APSInt:
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Ty->isIntegerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "integer constant must have integer type");
|
2010-12-07 08:25:19 +00:00
|
|
|
ID.APSIntVal = ID.APSIntVal.extOrTrunc(Ty->getPrimitiveSizeInBits());
|
2009-07-24 23:12:02 +00:00
|
|
|
V = ConstantInt::get(Context, ID.APSIntVal);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
case ValID::t_APFloat:
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!Ty->isFloatingPointTy() ||
|
2009-01-02 07:01:27 +00:00
|
|
|
!ConstantFP::isValueValidForType(Ty, ID.APFloatVal))
|
|
|
|
return Error(ID.Loc, "floating point constant invalid for type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-12-17 00:04:22 +00:00
|
|
|
// The lexer has no type info, so builds all half, float, and double FP
|
|
|
|
// constants as double. Fix this here. Long double does not need this.
|
|
|
|
if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble) {
|
2009-01-02 07:01:27 +00:00
|
|
|
bool Ignored;
|
2011-12-17 00:04:22 +00:00
|
|
|
if (Ty->isHalfTy())
|
|
|
|
ID.APFloatVal.convert(APFloat::IEEEhalf, APFloat::rmNearestTiesToEven,
|
|
|
|
&Ignored);
|
|
|
|
else if (Ty->isFloatTy())
|
|
|
|
ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
|
|
|
|
&Ignored);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-07-27 20:59:43 +00:00
|
|
|
V = ConstantFP::get(Context, ID.APFloatVal);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-05 18:24:23 +00:00
|
|
|
if (V->getType() != Ty)
|
|
|
|
return Error(ID.Loc, "floating point constant does not have type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(Ty) + "'");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
case ValID::t_Null:
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Ty->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "null must be a pointer type");
|
2009-07-30 23:03:37 +00:00
|
|
|
V = ConstantPointerNull::get(cast<PointerType>(Ty));
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
case ValID::t_Undef:
|
2009-01-05 08:13:38 +00:00
|
|
|
// FIXME: LabelTy should not be a first-class type.
|
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
|
|
|
if (!Ty->isFirstClassType() || Ty->isLabelTy())
|
2009-01-05 08:13:38 +00:00
|
|
|
return Error(ID.Loc, "invalid type for undef constant");
|
2009-07-30 23:03:37 +00:00
|
|
|
V = UndefValue::get(Ty);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
2009-01-05 07:52:51 +00:00
|
|
|
case ValID::t_EmptyArray:
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Ty->isArrayTy() || cast<ArrayType>(Ty)->getNumElements() != 0)
|
2009-01-05 07:52:51 +00:00
|
|
|
return Error(ID.Loc, "invalid empty array initializer");
|
2009-07-30 23:03:37 +00:00
|
|
|
V = UndefValue::get(Ty);
|
2009-01-05 07:52:51 +00:00
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
case ValID::t_Zero:
|
2009-01-05 08:13:38 +00:00
|
|
|
// FIXME: LabelTy should not be a first-class type.
|
2009-10-05 05:54:46 +00:00
|
|
|
if (!Ty->isFirstClassType() || Ty->isLabelTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "invalid type for null constant");
|
2009-07-31 20:28:14 +00:00
|
|
|
V = Constant::getNullValue(Ty);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
case ValID::t_Constant:
|
2010-08-28 04:09:24 +00:00
|
|
|
if (ID.ConstantVal->getType() != Ty)
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ID.Loc, "constant expression type mismatch");
|
2010-02-12 20:49:41 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
V = ID.ConstantVal;
|
|
|
|
return false;
|
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
|
|
|
case ValID::t_ConstantStruct:
|
|
|
|
case ValID::t_PackedConstantStruct:
|
2011-07-18 04:54:35 +00:00
|
|
|
if (StructType *ST = dyn_cast<StructType>(Ty)) {
|
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
|
|
|
if (ST->getNumElements() != ID.UIntVal)
|
|
|
|
return Error(ID.Loc,
|
|
|
|
"initializer with struct type has wrong # elements");
|
|
|
|
if (ST->isPacked() != (ID.Kind == ValID::t_PackedConstantStruct))
|
|
|
|
return Error(ID.Loc, "packed'ness of initializer and type don't match");
|
2012-11-15 22:34:00 +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
|
|
|
// Verify that the elements are compatible with the structtype.
|
|
|
|
for (unsigned i = 0, e = ID.UIntVal; i != e; ++i)
|
|
|
|
if (ID.ConstantStructElts[i]->getType() != ST->getElementType(i))
|
|
|
|
return Error(ID.Loc, "element " + Twine(i) +
|
|
|
|
" of struct initializer doesn't match struct element type");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2011-07-18 12:00:32 +00:00
|
|
|
V = ConstantStruct::get(ST, makeArrayRef(ID.ConstantStructElts,
|
|
|
|
ID.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
|
|
|
} else
|
|
|
|
return Error(ID.Loc, "constant expression type mismatch");
|
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2012-01-10 18:08:01 +00:00
|
|
|
llvm_unreachable("Invalid ValID");
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
bool LLParser::ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
V = 0;
|
|
|
|
ValID ID;
|
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 ParseValID(ID, PFS) ||
|
|
|
|
ConvertValIDToValue(Ty, ID, V, PFS);
|
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 LLParser::ParseTypeAndValue(Value *&V, PerFunctionState *PFS) {
|
|
|
|
Type *Ty = 0;
|
|
|
|
return ParseType(Ty) ||
|
|
|
|
ParseValue(Ty, V, PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
bool LLParser::ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
|
|
|
|
PerFunctionState &PFS) {
|
|
|
|
Value *V;
|
|
|
|
Loc = Lex.getLoc();
|
|
|
|
if (ParseTypeAndValue(V, PFS)) return true;
|
|
|
|
if (!isa<BasicBlock>(V))
|
|
|
|
return Error(Loc, "expected a basic block");
|
|
|
|
BB = cast<BasicBlock>(V);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// FunctionHeader
|
|
|
|
/// ::= OptionalLinkage OptionalVisibility OptionalCallingConv OptRetAttrs
|
2011-01-08 16:42:36 +00:00
|
|
|
/// OptUnnamedAddr Type GlobalName '(' ArgList ')' OptFuncAttrs OptSection
|
2009-01-02 07:01:27 +00:00
|
|
|
/// OptionalAlign OptGC
|
|
|
|
bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
|
|
|
|
// Parse the linkage.
|
|
|
|
LocTy LinkageLoc = Lex.getLoc();
|
|
|
|
unsigned Linkage;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-01-20 17:56:17 +00:00
|
|
|
unsigned Visibility;
|
2012-10-15 20:35:56 +00:00
|
|
|
AttrBuilder RetAttrs;
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CC;
|
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 *RetType = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy RetTypeLoc = Lex.getLoc();
|
|
|
|
if (ParseOptionalLinkage(Linkage) ||
|
|
|
|
ParseOptionalVisibility(Visibility) ||
|
|
|
|
ParseOptionalCallingConv(CC) ||
|
2012-12-04 23:40:58 +00:00
|
|
|
ParseOptionalReturnAttrs(RetAttrs) ||
|
2009-03-09 04:49:14 +00:00
|
|
|
ParseType(RetType, RetTypeLoc, true /*void allowed*/))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Verify that the linkage is ok.
|
|
|
|
switch ((GlobalValue::LinkageTypes)Linkage) {
|
|
|
|
case GlobalValue::ExternalLinkage:
|
|
|
|
break; // always ok.
|
|
|
|
case GlobalValue::DLLImportLinkage:
|
2009-03-11 08:08:06 +00:00
|
|
|
case GlobalValue::ExternalWeakLinkage:
|
2009-01-02 07:01:27 +00:00
|
|
|
if (isDefine)
|
|
|
|
return Error(LinkageLoc, "invalid linkage for function definition");
|
|
|
|
break;
|
2009-01-15 20:18:42 +00:00
|
|
|
case GlobalValue::PrivateLinkage:
|
2009-07-20 01:03:30 +00:00
|
|
|
case GlobalValue::LinkerPrivateLinkage:
|
2010-07-01 21:55:59 +00:00
|
|
|
case GlobalValue::LinkerPrivateWeakLinkage:
|
2009-01-02 07:01:27 +00:00
|
|
|
case GlobalValue::InternalLinkage:
|
2009-04-13 07:02:02 +00:00
|
|
|
case GlobalValue::AvailableExternallyLinkage:
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
case GlobalValue::LinkOnceAnyLinkage:
|
|
|
|
case GlobalValue::LinkOnceODRLinkage:
|
2012-08-17 18:33:14 +00:00
|
|
|
case GlobalValue::LinkOnceODRAutoHideLinkage:
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
case GlobalValue::WeakAnyLinkage:
|
|
|
|
case GlobalValue::WeakODRLinkage:
|
2009-01-02 07:01:27 +00:00
|
|
|
case GlobalValue::DLLExportLinkage:
|
|
|
|
if (!isDefine)
|
|
|
|
return Error(LinkageLoc, "invalid linkage for function declaration");
|
|
|
|
break;
|
|
|
|
case GlobalValue::AppendingLinkage:
|
2009-03-11 20:14:15 +00:00
|
|
|
case GlobalValue::CommonLinkage:
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(LinkageLoc, "invalid function linkage type");
|
|
|
|
}
|
2009-09-20 02:20:51 +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
|
|
|
if (!FunctionType::isValidReturnType(RetType))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(RetTypeLoc, "invalid function return type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-02-18 21:48:13 +00:00
|
|
|
LocTy NameLoc = Lex.getLoc();
|
|
|
|
|
|
|
|
std::string FunctionName;
|
|
|
|
if (Lex.getKind() == lltok::GlobalVar) {
|
|
|
|
FunctionName = Lex.getStrVal();
|
|
|
|
} else if (Lex.getKind() == lltok::GlobalID) { // @42 is ok.
|
|
|
|
unsigned NameID = Lex.getUIntVal();
|
|
|
|
|
|
|
|
if (NameID != NumberedVals.size())
|
|
|
|
return TokError("function expected to be numbered '%" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(NumberedVals.size()) + "'");
|
2009-02-18 21:48:13 +00:00
|
|
|
} else {
|
2009-01-02 07:01:27 +00:00
|
|
|
return TokError("expected function name");
|
2009-02-18 21:48:13 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
if (Lex.getKind() != lltok::lparen)
|
2009-01-02 07:01:27 +00:00
|
|
|
return TokError("expected '(' in function argument list");
|
2009-09-20 02:20:51 +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
|
|
|
SmallVector<ArgInfo, 8> ArgList;
|
2009-01-02 07:01:27 +00:00
|
|
|
bool isVarArg;
|
2012-10-15 20:35:56 +00:00
|
|
|
AttrBuilder FuncAttrs;
|
2009-01-02 07:01:27 +00:00
|
|
|
std::string Section;
|
|
|
|
unsigned Alignment;
|
2009-01-02 08:05:26 +00:00
|
|
|
std::string GC;
|
2011-01-25 19:09:56 +00:00
|
|
|
bool UnnamedAddr;
|
|
|
|
LocTy UnnamedAddrLoc;
|
2009-01-02 08:05:26 +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
|
|
|
if (ParseArgumentList(ArgList, isVarArg) ||
|
2011-01-25 19:09:56 +00:00
|
|
|
ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
|
|
|
|
&UnnamedAddrLoc) ||
|
2012-12-04 23:40:58 +00:00
|
|
|
ParseOptionalFuncAttrs(FuncAttrs) ||
|
2009-01-02 08:05:26 +00:00
|
|
|
(EatIfPresent(lltok::kw_section) &&
|
|
|
|
ParseStringConstant(Section)) ||
|
|
|
|
ParseOptionalAlignment(Alignment) ||
|
|
|
|
(EatIfPresent(lltok::kw_gc) &&
|
|
|
|
ParseStringConstant(GC)))
|
|
|
|
return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
// If the alignment was parsed as an attribute, move to the alignment field.
|
2012-10-08 23:27:46 +00:00
|
|
|
if (FuncAttrs.hasAlignmentAttr()) {
|
2012-09-21 15:26:31 +00:00
|
|
|
Alignment = FuncAttrs.getAlignment();
|
2012-12-19 07:18:57 +00:00
|
|
|
FuncAttrs.removeAttribute(Attribute::Alignment);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Okay, if we got here, the function is syntactically valid. Convert types
|
|
|
|
// and do semantic checks.
|
2011-07-12 14:06:48 +00:00
|
|
|
std::vector<Type*> ParamTypeList;
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<AttributeWithIndex, 8> Attrs;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-09-19 23:54:18 +00:00
|
|
|
if (RetAttrs.hasAttributes())
|
2012-10-15 07:29:08 +00:00
|
|
|
Attrs.push_back(
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeWithIndex::get(AttributeSet::ReturnIndex,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(RetType->getContext(),
|
2012-10-15 07:29:08 +00:00
|
|
|
RetAttrs)));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
|
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
|
|
|
ParamTypeList.push_back(ArgList[i].Ty);
|
2012-09-19 23:54:18 +00:00
|
|
|
if (ArgList[i].Attrs.hasAttributes())
|
2009-01-02 07:01:27 +00:00
|
|
|
Attrs.push_back(AttributeWithIndex::get(i+1, ArgList[i].Attrs));
|
|
|
|
}
|
|
|
|
|
2012-09-19 23:54:18 +00:00
|
|
|
if (FuncAttrs.hasAttributes())
|
2012-10-15 07:29:08 +00:00
|
|
|
Attrs.push_back(
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeWithIndex::get(AttributeSet::FunctionIndex,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(RetType->getContext(),
|
2012-10-15 07:29:08 +00:00
|
|
|
FuncAttrs)));
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet PAL = AttributeSet::get(Context, Attrs);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-12-19 07:18:57 +00:00
|
|
|
if (PAL.getParamAttributes(1).hasAttribute(Attribute::StructRet) &&
|
2012-10-09 07:45:08 +00:00
|
|
|
!RetType->isVoidTy())
|
2009-09-20 02:20:51 +00:00
|
|
|
return Error(RetTypeLoc, "functions with 'sret' argument must return void");
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
FunctionType *FT =
|
2009-07-29 22:17:13 +00:00
|
|
|
FunctionType::get(RetType, ParamTypeList, isVarArg);
|
2011-07-18 04:54:35 +00:00
|
|
|
PointerType *PFT = PointerType::getUnqual(FT);
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
Fn = 0;
|
|
|
|
if (!FunctionName.empty()) {
|
|
|
|
// If this was a definition of a forward reference, remove the definition
|
|
|
|
// from the forward reference table and fill in the forward ref.
|
|
|
|
std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator FRVI =
|
|
|
|
ForwardRefVals.find(FunctionName);
|
|
|
|
if (FRVI != ForwardRefVals.end()) {
|
|
|
|
Fn = M->getFunction(FunctionName);
|
2012-10-11 00:38:25 +00:00
|
|
|
if (!Fn)
|
|
|
|
return Error(FRVI->second.second, "invalid forward reference to "
|
|
|
|
"function as global value!");
|
2010-04-20 04:49:11 +00:00
|
|
|
if (Fn->getType() != PFT)
|
|
|
|
return Error(FRVI->second.second, "invalid forward reference to "
|
|
|
|
"function '" + FunctionName + "' with wrong type!");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefVals.erase(FRVI);
|
|
|
|
} else if ((Fn = M->getFunction(FunctionName))) {
|
2011-06-17 07:06:44 +00:00
|
|
|
// Reject redefinitions.
|
|
|
|
return Error(NameLoc, "invalid redefinition of function '" +
|
|
|
|
FunctionName + "'");
|
2009-10-25 23:22:50 +00:00
|
|
|
} else if (M->getNamedValue(FunctionName)) {
|
|
|
|
return Error(NameLoc, "redefinition of function '@" + FunctionName + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-08-29 23:37:49 +00:00
|
|
|
} else {
|
2009-01-02 07:01:27 +00:00
|
|
|
// If this is a definition of a forward referenced function, make sure the
|
|
|
|
// types agree.
|
|
|
|
std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator I
|
|
|
|
= ForwardRefValIDs.find(NumberedVals.size());
|
|
|
|
if (I != ForwardRefValIDs.end()) {
|
|
|
|
Fn = cast<Function>(I->second.first);
|
|
|
|
if (Fn->getType() != PFT)
|
|
|
|
return Error(NameLoc, "type of definition and forward reference of '@" +
|
2010-09-27 17:42:11 +00:00
|
|
|
Twine(NumberedVals.size()) + "' disagree");
|
2009-01-02 07:01:27 +00:00
|
|
|
ForwardRefValIDs.erase(I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Fn == 0)
|
|
|
|
Fn = Function::Create(FT, GlobalValue::ExternalLinkage, FunctionName, M);
|
|
|
|
else // Move the forward-reference to the correct spot in the module.
|
|
|
|
M->getFunctionList().splice(M->end(), M->getFunctionList(), Fn);
|
|
|
|
|
|
|
|
if (FunctionName.empty())
|
|
|
|
NumberedVals.push_back(Fn);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Fn->setLinkage((GlobalValue::LinkageTypes)Linkage);
|
|
|
|
Fn->setVisibility((GlobalValue::VisibilityTypes)Visibility);
|
|
|
|
Fn->setCallingConv(CC);
|
|
|
|
Fn->setAttributes(PAL);
|
2011-01-08 16:42:36 +00:00
|
|
|
Fn->setUnnamedAddr(UnnamedAddr);
|
2009-01-02 07:01:27 +00:00
|
|
|
Fn->setAlignment(Alignment);
|
|
|
|
Fn->setSection(Section);
|
|
|
|
if (!GC.empty()) Fn->setGC(GC.c_str());
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Add all of the arguments we parsed to the function.
|
|
|
|
Function::arg_iterator ArgIt = Fn->arg_begin();
|
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i, ++ArgIt) {
|
|
|
|
// If the argument has a name, insert it into the argument symbol table.
|
|
|
|
if (ArgList[i].Name.empty()) continue;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Set the name, if it conflicted, it will be auto-renamed.
|
|
|
|
ArgIt->setName(ArgList[i].Name);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2010-10-16 11:28:23 +00:00
|
|
|
if (ArgIt->getName() != ArgList[i].Name)
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(ArgList[i].Loc, "redefinition of argument '%" +
|
|
|
|
ArgList[i].Name + "'");
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ParseFunctionBody
|
|
|
|
/// ::= '{' BasicBlock+ '}'
|
|
|
|
///
|
|
|
|
bool LLParser::ParseFunctionBody(Function &Fn) {
|
2011-06-17 06:42:57 +00:00
|
|
|
if (Lex.getKind() != lltok::lbrace)
|
2009-01-02 07:01:27 +00:00
|
|
|
return TokError("expected '{' in function body");
|
|
|
|
Lex.Lex(); // eat the {.
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
int FunctionNumber = -1;
|
|
|
|
if (!Fn.hasName()) FunctionNumber = NumberedVals.size()-1;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-28 03:39:23 +00:00
|
|
|
PerFunctionState PFS(*this, Fn, FunctionNumber);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2010-01-09 19:20:07 +00:00
|
|
|
// We need at least one basic block.
|
2011-06-17 06:42:57 +00:00
|
|
|
if (Lex.getKind() == lltok::rbrace)
|
2010-01-09 19:20:07 +00:00
|
|
|
return TokError("function body requires at least one basic block");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2011-06-17 06:42:57 +00:00
|
|
|
while (Lex.getKind() != lltok::rbrace)
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseBasicBlock(PFS)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Eat the }.
|
|
|
|
Lex.Lex();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Verify function is ok.
|
2009-10-28 03:39:23 +00:00
|
|
|
return PFS.FinishFunction();
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseBasicBlock
|
|
|
|
/// ::= LabelStr? Instruction*
|
|
|
|
bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
|
|
|
|
// If this basic block starts out with a name, remember it.
|
|
|
|
std::string Name;
|
|
|
|
LocTy NameLoc = Lex.getLoc();
|
|
|
|
if (Lex.getKind() == lltok::LabelStr) {
|
|
|
|
Name = Lex.getStrVal();
|
|
|
|
Lex.Lex();
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
BasicBlock *BB = PFS.DefineBB(Name, NameLoc);
|
|
|
|
if (BB == 0) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
std::string NameStr;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Parse the instructions in this block until we get a terminator.
|
|
|
|
Instruction *Inst;
|
2009-12-30 05:48:36 +00:00
|
|
|
SmallVector<std::pair<unsigned, MDNode *>, 4> MetadataOnInst;
|
2009-01-02 07:01:27 +00:00
|
|
|
do {
|
|
|
|
// This instruction may have three possibilities for a name: a) none
|
|
|
|
// specified, b) name specified "%foo =", c) number specified: "%4 =".
|
|
|
|
LocTy NameLoc = Lex.getLoc();
|
|
|
|
int NameID = -1;
|
|
|
|
NameStr = "";
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Lex.getKind() == lltok::LocalVarID) {
|
|
|
|
NameID = Lex.getUIntVal();
|
|
|
|
Lex.Lex();
|
|
|
|
if (ParseToken(lltok::equal, "expected '=' after instruction id"))
|
|
|
|
return true;
|
2011-06-17 06:36:20 +00:00
|
|
|
} else if (Lex.getKind() == lltok::LocalVar) {
|
2009-01-02 07:01:27 +00:00
|
|
|
NameStr = Lex.getStrVal();
|
|
|
|
Lex.Lex();
|
|
|
|
if (ParseToken(lltok::equal, "expected '=' after instruction name"))
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-17 23:04:48 +00:00
|
|
|
|
2009-12-30 05:23:43 +00:00
|
|
|
switch (ParseInstruction(Inst, BB, PFS)) {
|
2012-02-07 05:05:23 +00:00
|
|
|
default: llvm_unreachable("Unknown ParseInstruction result!");
|
2009-12-30 05:23:43 +00:00
|
|
|
case InstError: return true;
|
|
|
|
case InstNormal:
|
2010-04-07 04:08:57 +00:00
|
|
|
BB->getInstList().push_back(Inst);
|
|
|
|
|
2009-12-30 05:23:43 +00:00
|
|
|
// With a normal result, we check to see if the instruction is followed by
|
|
|
|
// a comma and metadata.
|
|
|
|
if (EatIfPresent(lltok::comma))
|
2010-08-24 02:05:17 +00:00
|
|
|
if (ParseInstructionMetadata(Inst, &PFS))
|
2009-12-30 05:23:43 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
case InstExtraComma:
|
2010-04-07 04:08:57 +00:00
|
|
|
BB->getInstList().push_back(Inst);
|
|
|
|
|
2009-12-30 05:23:43 +00:00
|
|
|
// If the instruction parser ate an extra comma at the end of it, it
|
|
|
|
// *must* be followed by metadata.
|
2010-08-24 02:05:17 +00:00
|
|
|
if (ParseInstructionMetadata(Inst, &PFS))
|
2009-12-30 05:23:43 +00:00
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
break;
|
2009-12-30 05:23:43 +00:00
|
|
|
}
|
2009-09-17 23:04:48 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Set the name on the instruction.
|
|
|
|
if (PFS.SetInstName(NameID, NameStr, NameLoc, Inst)) return true;
|
|
|
|
} while (!isa<TerminatorInst>(Inst));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction Parsing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseInstruction - Parse one of the many different instructions.
|
|
|
|
///
|
2009-12-30 05:23:43 +00:00
|
|
|
int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
|
|
|
|
PerFunctionState &PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
lltok::Kind Token = Lex.getKind();
|
|
|
|
if (Token == lltok::Eof)
|
|
|
|
return TokError("found end of file when expecting more instructions");
|
|
|
|
LocTy Loc = Lex.getLoc();
|
2009-03-01 00:53:13 +00:00
|
|
|
unsigned KeywordVal = Lex.getUIntVal();
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex(); // Eat the keyword.
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
switch (Token) {
|
|
|
|
default: return Error(Loc, "expected instruction opcode");
|
|
|
|
// Terminator Instructions.
|
2009-08-13 21:58:54 +00:00
|
|
|
case lltok::kw_unreachable: Inst = new UnreachableInst(Context); return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_ret: return ParseRet(Inst, BB, PFS);
|
|
|
|
case lltok::kw_br: return ParseBr(Inst, PFS);
|
|
|
|
case lltok::kw_switch: return ParseSwitch(Inst, PFS);
|
2009-10-28 00:19:10 +00:00
|
|
|
case lltok::kw_indirectbr: return ParseIndirectBr(Inst, PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_invoke: return ParseInvoke(Inst, PFS);
|
2011-07-31 06:30:59 +00:00
|
|
|
case lltok::kw_resume: return ParseResume(Inst, PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
// Binary Operators.
|
|
|
|
case lltok::kw_add:
|
|
|
|
case lltok::kw_sub:
|
2011-02-07 16:40:21 +00:00
|
|
|
case lltok::kw_mul:
|
|
|
|
case lltok::kw_shl: {
|
|
|
|
bool NUW = EatIfPresent(lltok::kw_nuw);
|
|
|
|
bool NSW = EatIfPresent(lltok::kw_nsw);
|
|
|
|
if (!NUW) NUW = EatIfPresent(lltok::kw_nuw);
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2011-02-07 16:40:21 +00:00
|
|
|
if (ParseArithmetic(Inst, PFS, KeywordVal, 1)) return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2011-02-07 16:40:21 +00:00
|
|
|
if (NUW) cast<BinaryOperator>(Inst)->setHasNoUnsignedWrap(true);
|
|
|
|
if (NSW) cast<BinaryOperator>(Inst)->setHasNoSignedWrap(true);
|
|
|
|
return false;
|
2009-07-27 16:11:46 +00:00
|
|
|
}
|
2009-06-04 22:49:04 +00:00
|
|
|
case lltok::kw_fadd:
|
|
|
|
case lltok::kw_fsub:
|
2012-11-27 00:42:44 +00:00
|
|
|
case lltok::kw_fmul:
|
|
|
|
case lltok::kw_fdiv:
|
|
|
|
case lltok::kw_frem: {
|
|
|
|
FastMathFlags FMF = EatFastMathFlagsIfPresent();
|
|
|
|
int Res = ParseArithmetic(Inst, PFS, KeywordVal, 2);
|
|
|
|
if (Res != 0)
|
|
|
|
return Res;
|
|
|
|
if (FMF.any())
|
|
|
|
Inst->setFastMathFlags(FMF);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-04 22:49:04 +00:00
|
|
|
|
2011-02-06 21:44:57 +00:00
|
|
|
case lltok::kw_sdiv:
|
2011-02-07 16:40:21 +00:00
|
|
|
case lltok::kw_udiv:
|
|
|
|
case lltok::kw_lshr:
|
|
|
|
case lltok::kw_ashr: {
|
|
|
|
bool Exact = EatIfPresent(lltok::kw_exact);
|
|
|
|
|
|
|
|
if (ParseArithmetic(Inst, PFS, KeywordVal, 1)) return true;
|
|
|
|
if (Exact) cast<BinaryOperator>(Inst)->setIsExact(true);
|
|
|
|
return false;
|
2009-07-27 16:11:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_urem:
|
2009-03-01 00:53:13 +00:00
|
|
|
case lltok::kw_srem: return ParseArithmetic(Inst, PFS, KeywordVal, 1);
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_and:
|
|
|
|
case lltok::kw_or:
|
2009-03-01 00:53:13 +00:00
|
|
|
case lltok::kw_xor: return ParseLogical(Inst, PFS, KeywordVal);
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_icmp:
|
2009-07-08 03:04:38 +00:00
|
|
|
case lltok::kw_fcmp: return ParseCompare(Inst, PFS, KeywordVal);
|
2009-01-02 07:01:27 +00:00
|
|
|
// Casts.
|
|
|
|
case lltok::kw_trunc:
|
|
|
|
case lltok::kw_zext:
|
|
|
|
case lltok::kw_sext:
|
|
|
|
case lltok::kw_fptrunc:
|
|
|
|
case lltok::kw_fpext:
|
|
|
|
case lltok::kw_bitcast:
|
|
|
|
case lltok::kw_uitofp:
|
|
|
|
case lltok::kw_sitofp:
|
|
|
|
case lltok::kw_fptoui:
|
2009-09-20 02:20:51 +00:00
|
|
|
case lltok::kw_fptosi:
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_inttoptr:
|
2009-03-01 00:53:13 +00:00
|
|
|
case lltok::kw_ptrtoint: return ParseCast(Inst, PFS, KeywordVal);
|
2009-01-02 07:01:27 +00:00
|
|
|
// Other.
|
|
|
|
case lltok::kw_select: return ParseSelect(Inst, PFS);
|
2009-01-05 08:18:44 +00:00
|
|
|
case lltok::kw_va_arg: return ParseVA_Arg(Inst, PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_extractelement: return ParseExtractElement(Inst, PFS);
|
|
|
|
case lltok::kw_insertelement: return ParseInsertElement(Inst, PFS);
|
|
|
|
case lltok::kw_shufflevector: return ParseShuffleVector(Inst, PFS);
|
|
|
|
case lltok::kw_phi: return ParsePHI(Inst, PFS);
|
2011-08-12 20:24:12 +00:00
|
|
|
case lltok::kw_landingpad: return ParseLandingPad(Inst, PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_call: return ParseCall(Inst, PFS, false);
|
|
|
|
case lltok::kw_tail: return ParseCall(Inst, PFS, true);
|
|
|
|
// Memory.
|
2009-10-17 00:00:19 +00:00
|
|
|
case lltok::kw_alloca: return ParseAlloc(Inst, PFS);
|
2011-11-27 06:56:53 +00:00
|
|
|
case lltok::kw_load: return ParseLoad(Inst, PFS);
|
|
|
|
case lltok::kw_store: return ParseStore(Inst, PFS);
|
2011-08-12 22:50:01 +00:00
|
|
|
case lltok::kw_cmpxchg: return ParseCmpXchg(Inst, PFS);
|
|
|
|
case lltok::kw_atomicrmw: return ParseAtomicRMW(Inst, PFS);
|
2011-07-25 23:16:38 +00:00
|
|
|
case lltok::kw_fence: return ParseFence(Inst, PFS);
|
2009-01-02 07:01:27 +00:00
|
|
|
case lltok::kw_getelementptr: return ParseGetElementPtr(Inst, PFS);
|
|
|
|
case lltok::kw_extractvalue: return ParseExtractValue(Inst, PFS);
|
|
|
|
case lltok::kw_insertvalue: return ParseInsertValue(Inst, PFS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseCmpPredicate - Parse an integer or fp predicate, based on Kind.
|
|
|
|
bool LLParser::ParseCmpPredicate(unsigned &P, unsigned Opc) {
|
2009-07-08 03:04:38 +00:00
|
|
|
if (Opc == Instruction::FCmp) {
|
2009-01-02 07:01:27 +00:00
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: TokError("expected fcmp predicate (e.g. 'oeq')");
|
|
|
|
case lltok::kw_oeq: P = CmpInst::FCMP_OEQ; break;
|
|
|
|
case lltok::kw_one: P = CmpInst::FCMP_ONE; break;
|
|
|
|
case lltok::kw_olt: P = CmpInst::FCMP_OLT; break;
|
|
|
|
case lltok::kw_ogt: P = CmpInst::FCMP_OGT; break;
|
|
|
|
case lltok::kw_ole: P = CmpInst::FCMP_OLE; break;
|
|
|
|
case lltok::kw_oge: P = CmpInst::FCMP_OGE; break;
|
|
|
|
case lltok::kw_ord: P = CmpInst::FCMP_ORD; break;
|
|
|
|
case lltok::kw_uno: P = CmpInst::FCMP_UNO; break;
|
|
|
|
case lltok::kw_ueq: P = CmpInst::FCMP_UEQ; break;
|
|
|
|
case lltok::kw_une: P = CmpInst::FCMP_UNE; break;
|
|
|
|
case lltok::kw_ult: P = CmpInst::FCMP_ULT; break;
|
|
|
|
case lltok::kw_ugt: P = CmpInst::FCMP_UGT; break;
|
|
|
|
case lltok::kw_ule: P = CmpInst::FCMP_ULE; break;
|
|
|
|
case lltok::kw_uge: P = CmpInst::FCMP_UGE; break;
|
|
|
|
case lltok::kw_true: P = CmpInst::FCMP_TRUE; break;
|
|
|
|
case lltok::kw_false: P = CmpInst::FCMP_FALSE; break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: TokError("expected icmp predicate (e.g. 'eq')");
|
|
|
|
case lltok::kw_eq: P = CmpInst::ICMP_EQ; break;
|
|
|
|
case lltok::kw_ne: P = CmpInst::ICMP_NE; break;
|
|
|
|
case lltok::kw_slt: P = CmpInst::ICMP_SLT; break;
|
|
|
|
case lltok::kw_sgt: P = CmpInst::ICMP_SGT; break;
|
|
|
|
case lltok::kw_sle: P = CmpInst::ICMP_SLE; break;
|
|
|
|
case lltok::kw_sge: P = CmpInst::ICMP_SGE; break;
|
|
|
|
case lltok::kw_ult: P = CmpInst::ICMP_ULT; break;
|
|
|
|
case lltok::kw_ugt: P = CmpInst::ICMP_UGT; break;
|
|
|
|
case lltok::kw_ule: P = CmpInst::ICMP_ULE; break;
|
|
|
|
case lltok::kw_uge: P = CmpInst::ICMP_UGE; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Lex.Lex();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Terminator Instructions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseRet - Parse a return instruction.
|
2009-12-29 21:25:40 +00:00
|
|
|
/// ::= 'ret' void (',' !dbg, !1)*
|
|
|
|
/// ::= 'ret' TypeAndValue (',' !dbg, !1)*
|
2011-06-17 06:49:41 +00:00
|
|
|
bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
|
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
|
|
|
PerFunctionState &PFS) {
|
|
|
|
SMLoc TypeLoc = Lex.getLoc();
|
|
|
|
Type *Ty = 0;
|
2009-03-09 04:49:14 +00:00
|
|
|
if (ParseType(Ty, true /*void allowed*/)) return true;
|
2009-09-20 02:20:51 +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 *ResType = PFS.getFunction().getReturnType();
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-05 05:54:46 +00:00
|
|
|
if (Ty->isVoidTy()) {
|
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
|
|
|
if (!ResType->isVoidTy())
|
|
|
|
return Error(TypeLoc, "value doesn't match function result type '" +
|
|
|
|
getTypeString(ResType) + "'");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-08-13 21:58:54 +00:00
|
|
|
Inst = ReturnInst::Create(Context);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *RV;
|
|
|
|
if (ParseValue(Ty, RV, PFS)) return true;
|
|
|
|
|
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
|
|
|
if (ResType != RV->getType())
|
|
|
|
return Error(TypeLoc, "value doesn't match function result type '" +
|
|
|
|
getTypeString(ResType) + "'");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-08-13 21:58:54 +00:00
|
|
|
Inst = ReturnInst::Create(Context, RV);
|
2011-06-17 06:49:41 +00:00
|
|
|
return false;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ParseBr
|
|
|
|
/// ::= 'br' TypeAndValue
|
|
|
|
/// ::= 'br' TypeAndValue ',' TypeAndValue ',' TypeAndValue
|
|
|
|
bool LLParser::ParseBr(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
LocTy Loc, Loc2;
|
2009-10-27 19:13:16 +00:00
|
|
|
Value *Op0;
|
|
|
|
BasicBlock *Op1, *Op2;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Op0, Loc, PFS)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (BasicBlock *BB = dyn_cast<BasicBlock>(Op0)) {
|
|
|
|
Inst = BranchInst::Create(BB);
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-08-13 21:58:54 +00:00
|
|
|
if (Op0->getType() != Type::getInt1Ty(Context))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc, "branch condition must have 'i1' type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseToken(lltok::comma, "expected ',' after branch condition") ||
|
2009-10-27 19:13:16 +00:00
|
|
|
ParseTypeAndBasicBlock(Op1, Loc, PFS) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::comma, "expected ',' after true destination") ||
|
2009-10-27 19:13:16 +00:00
|
|
|
ParseTypeAndBasicBlock(Op2, Loc2, PFS))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
Inst = BranchInst::Create(Op1, Op2, Op0);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseSwitch
|
|
|
|
/// Instruction
|
|
|
|
/// ::= 'switch' TypeAndValue ',' TypeAndValue '[' JumpTable ']'
|
|
|
|
/// JumpTable
|
|
|
|
/// ::= (TypeAndValue ',' TypeAndValue)*
|
|
|
|
bool LLParser::ParseSwitch(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
LocTy CondLoc, BBLoc;
|
2009-10-27 19:13:16 +00:00
|
|
|
Value *Cond;
|
|
|
|
BasicBlock *DefaultBB;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Cond, CondLoc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after switch condition") ||
|
2009-10-27 19:13:16 +00:00
|
|
|
ParseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::lsquare, "expected '[' with switch table"))
|
|
|
|
return true;
|
|
|
|
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Cond->getType()->isIntegerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(CondLoc, "switch condition must have integer type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Parse the jump table pairs.
|
|
|
|
SmallPtrSet<Value*, 32> SeenCases;
|
|
|
|
SmallVector<std::pair<ConstantInt*, BasicBlock*>, 32> Table;
|
|
|
|
while (Lex.getKind() != lltok::rsquare) {
|
2009-10-27 19:13:16 +00:00
|
|
|
Value *Constant;
|
|
|
|
BasicBlock *DestBB;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Constant, CondLoc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after case value") ||
|
2009-10-27 19:13:16 +00:00
|
|
|
ParseTypeAndBasicBlock(DestBB, PFS))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!SeenCases.insert(Constant))
|
|
|
|
return Error(CondLoc, "duplicate case value in switch");
|
|
|
|
if (!isa<ConstantInt>(Constant))
|
|
|
|
return Error(CondLoc, "case value is not a constant integer");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
Table.push_back(std::make_pair(cast<ConstantInt>(Constant), DestBB));
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Lex.Lex(); // Eat the ']'.
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
SwitchInst *SI = SwitchInst::Create(Cond, DefaultBB, Table.size());
|
2009-01-02 07:01:27 +00:00
|
|
|
for (unsigned i = 0, e = Table.size(); i != e; ++i)
|
|
|
|
SI->addCase(Table[i].first, Table[i].second);
|
|
|
|
Inst = SI;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
/// ParseIndirectBr
|
2009-10-27 19:13:16 +00:00
|
|
|
/// Instruction
|
2009-10-28 00:19:10 +00:00
|
|
|
/// ::= 'indirectbr' TypeAndValue ',' '[' LabelList ']'
|
|
|
|
bool LLParser::ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) {
|
2009-10-27 19:13:16 +00:00
|
|
|
LocTy AddrLoc;
|
|
|
|
Value *Address;
|
|
|
|
if (ParseTypeAndValue(Address, AddrLoc, PFS) ||
|
2009-10-28 00:19:10 +00:00
|
|
|
ParseToken(lltok::comma, "expected ',' after indirectbr address") ||
|
|
|
|
ParseToken(lltok::lsquare, "expected '[' with indirectbr"))
|
2009-10-27 19:13:16 +00:00
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Address->getType()->isPointerTy())
|
2009-10-28 00:19:10 +00:00
|
|
|
return Error(AddrLoc, "indirectbr address must have pointer type");
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
// Parse the destination list.
|
|
|
|
SmallVector<BasicBlock*, 16> DestList;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
if (Lex.getKind() != lltok::rsquare) {
|
|
|
|
BasicBlock *DestBB;
|
|
|
|
if (ParseTypeAndBasicBlock(DestBB, PFS))
|
|
|
|
return true;
|
|
|
|
DestList.push_back(DestBB);
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
while (EatIfPresent(lltok::comma)) {
|
|
|
|
if (ParseTypeAndBasicBlock(DestBB, PFS))
|
|
|
|
return true;
|
|
|
|
DestList.push_back(DestBB);
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
if (ParseToken(lltok::rsquare, "expected ']' at end of block list"))
|
|
|
|
return true;
|
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
IndirectBrInst *IBI = IndirectBrInst::Create(Address, DestList.size());
|
2009-10-27 19:13:16 +00:00
|
|
|
for (unsigned i = 0, e = DestList.size(); i != e; ++i)
|
|
|
|
IBI->addDestination(DestList[i]);
|
|
|
|
Inst = IBI;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseInvoke
|
|
|
|
/// ::= 'invoke' OptionalCallingConv OptionalAttrs Type Value ParamList
|
|
|
|
/// OptionalAttrs 'to' TypeAndValue 'unwind' TypeAndValue
|
|
|
|
bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
LocTy CallLoc = Lex.getLoc();
|
2012-10-15 20:35:56 +00:00
|
|
|
AttrBuilder RetAttrs, FnAttrs;
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CC;
|
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 *RetType = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy RetTypeLoc;
|
|
|
|
ValID CalleeID;
|
|
|
|
SmallVector<ParamInfo, 16> ArgList;
|
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
BasicBlock *NormalBB, *UnwindBB;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseOptionalCallingConv(CC) ||
|
2012-12-04 23:40:58 +00:00
|
|
|
ParseOptionalReturnAttrs(RetAttrs) ||
|
2009-03-09 04:49:14 +00:00
|
|
|
ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseValID(CalleeID) ||
|
|
|
|
ParseParameterList(ArgList, PFS) ||
|
2012-12-04 23:40:58 +00:00
|
|
|
ParseOptionalFuncAttrs(FnAttrs) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::kw_to, "expected 'to' in invoke") ||
|
2009-10-27 19:13:16 +00:00
|
|
|
ParseTypeAndBasicBlock(NormalBB, PFS) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::kw_unwind, "expected 'unwind' in invoke") ||
|
2009-10-27 19:13:16 +00:00
|
|
|
ParseTypeAndBasicBlock(UnwindBB, PFS))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If RetType is a non-function pointer type, then this is the short syntax
|
|
|
|
// for the call, which means that RetType is just the return type. Infer the
|
|
|
|
// rest of the function argument types from the arguments that are present.
|
2011-07-18 04:54:35 +00:00
|
|
|
PointerType *PFTy = 0;
|
|
|
|
FunctionType *Ty = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!(PFTy = dyn_cast<PointerType>(RetType)) ||
|
|
|
|
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
|
|
|
|
// Pull out the types of all of the arguments...
|
2011-07-12 14:06:48 +00:00
|
|
|
std::vector<Type*> ParamTypes;
|
2009-01-02 07:01:27 +00:00
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
|
|
|
|
ParamTypes.push_back(ArgList[i].V->getType());
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!FunctionType::isValidReturnType(RetType))
|
|
|
|
return Error(RetTypeLoc, "Invalid result type for LLVM function");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-07-29 22:17:13 +00:00
|
|
|
Ty = FunctionType::get(RetType, ParamTypes, false);
|
|
|
|
PFTy = PointerType::getUnqual(Ty);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Look up the callee.
|
|
|
|
Value *Callee;
|
2010-01-11 22:31:58 +00:00
|
|
|
if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-12-19 07:18:57 +00:00
|
|
|
// Set up the Attribute for the function.
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<AttributeWithIndex, 8> Attrs;
|
2012-09-19 23:54:18 +00:00
|
|
|
if (RetAttrs.hasAttributes())
|
2012-10-15 07:29:08 +00:00
|
|
|
Attrs.push_back(
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeWithIndex::get(AttributeSet::ReturnIndex,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(Callee->getContext(),
|
2012-10-15 07:29:08 +00:00
|
|
|
RetAttrs)));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<Value*, 8> Args;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Loop through FunctionType's arguments and ensure they are specified
|
|
|
|
// correctly. Also, gather any parameter attributes.
|
|
|
|
FunctionType::param_iterator I = Ty->param_begin();
|
|
|
|
FunctionType::param_iterator E = Ty->param_end();
|
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *ExpectedTy = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (I != E) {
|
|
|
|
ExpectedTy = *I++;
|
|
|
|
} else if (!Ty->isVarArg()) {
|
|
|
|
return Error(ArgList[i].Loc, "too many arguments specified");
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ExpectedTy && ExpectedTy != ArgList[i].V->getType())
|
|
|
|
return Error(ArgList[i].Loc, "argument is not of expected type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(ExpectedTy) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
Args.push_back(ArgList[i].V);
|
2012-09-19 23:54:18 +00:00
|
|
|
if (ArgList[i].Attrs.hasAttributes())
|
2009-01-02 07:01:27 +00:00
|
|
|
Attrs.push_back(AttributeWithIndex::get(i+1, ArgList[i].Attrs));
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (I != E)
|
|
|
|
return Error(CallLoc, "not enough parameters specified for call");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-09-19 23:54:18 +00:00
|
|
|
if (FnAttrs.hasAttributes())
|
2012-10-15 07:29:08 +00:00
|
|
|
Attrs.push_back(
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeWithIndex::get(AttributeSet::FunctionIndex,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(Callee->getContext(),
|
2012-10-15 07:29:08 +00:00
|
|
|
FnAttrs)));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-12-19 07:18:57 +00:00
|
|
|
// Finish off the Attribute and check them
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet PAL = AttributeSet::get(Context, Attrs);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-07-15 08:37:34 +00:00
|
|
|
InvokeInst *II = InvokeInst::Create(Callee, NormalBB, UnwindBB, Args);
|
2009-01-02 07:01:27 +00:00
|
|
|
II->setCallingConv(CC);
|
|
|
|
II->setAttributes(PAL);
|
|
|
|
Inst = II;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-31 06:30:59 +00:00
|
|
|
/// ParseResume
|
|
|
|
/// ::= 'resume' TypeAndValue
|
|
|
|
bool LLParser::ParseResume(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
Value *Exn; LocTy ExnLoc;
|
|
|
|
if (ParseTypeAndValue(Exn, ExnLoc, PFS))
|
|
|
|
return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2011-07-31 06:30:59 +00:00
|
|
|
ResumeInst *RI = ResumeInst::Create(Exn);
|
|
|
|
Inst = RI;
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Binary Operators.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseArithmetic
|
2009-01-05 08:24:46 +00:00
|
|
|
/// ::= ArithmeticOps TypeAndValue ',' Value
|
|
|
|
///
|
|
|
|
/// If OperandType is 0, then any FP or integer operand is allowed. If it is 1,
|
|
|
|
/// then any integer operand is allowed, if it is 2, any fp operand is allowed.
|
2009-01-02 07:01:27 +00:00
|
|
|
bool LLParser::ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS,
|
2009-01-05 08:24:46 +00:00
|
|
|
unsigned Opc, unsigned OperandType) {
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy Loc; Value *LHS, *RHS;
|
|
|
|
if (ParseTypeAndValue(LHS, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' in arithmetic operation") ||
|
|
|
|
ParseValue(LHS->getType(), RHS, PFS))
|
|
|
|
return true;
|
|
|
|
|
2009-01-05 08:24:46 +00:00
|
|
|
bool Valid;
|
|
|
|
switch (OperandType) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Unknown operand type!");
|
2009-01-05 08:24:46 +00:00
|
|
|
case 0: // int or FP.
|
2010-02-15 16:12:20 +00:00
|
|
|
Valid = LHS->getType()->isIntOrIntVectorTy() ||
|
|
|
|
LHS->getType()->isFPOrFPVectorTy();
|
2009-01-05 08:24:46 +00:00
|
|
|
break;
|
2010-02-15 16:12:20 +00:00
|
|
|
case 1: Valid = LHS->getType()->isIntOrIntVectorTy(); break;
|
|
|
|
case 2: Valid = LHS->getType()->isFPOrFPVectorTy(); break;
|
2009-01-05 08:24:46 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-05 08:24:46 +00:00
|
|
|
if (!Valid)
|
|
|
|
return Error(Loc, "invalid operand type for instruction");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Inst = BinaryOperator::Create((Instruction::BinaryOps)Opc, LHS, RHS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseLogical
|
|
|
|
/// ::= ArithmeticOps TypeAndValue ',' Value {
|
|
|
|
bool LLParser::ParseLogical(Instruction *&Inst, PerFunctionState &PFS,
|
|
|
|
unsigned Opc) {
|
|
|
|
LocTy Loc; Value *LHS, *RHS;
|
|
|
|
if (ParseTypeAndValue(LHS, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' in logical operation") ||
|
|
|
|
ParseValue(LHS->getType(), RHS, PFS))
|
|
|
|
return true;
|
|
|
|
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!LHS->getType()->isIntOrIntVectorTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc,"instruction requires integer or integer vector operands");
|
|
|
|
|
|
|
|
Inst = BinaryOperator::Create((Instruction::BinaryOps)Opc, LHS, RHS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ParseCompare
|
|
|
|
/// ::= 'icmp' IPredicates TypeAndValue ',' Value
|
|
|
|
/// ::= 'fcmp' FPredicates TypeAndValue ',' Value
|
|
|
|
bool LLParser::ParseCompare(Instruction *&Inst, PerFunctionState &PFS,
|
|
|
|
unsigned Opc) {
|
|
|
|
// Parse the integer/fp comparison predicate.
|
|
|
|
LocTy Loc;
|
|
|
|
unsigned Pred;
|
|
|
|
Value *LHS, *RHS;
|
|
|
|
if (ParseCmpPredicate(Pred, Opc) ||
|
|
|
|
ParseTypeAndValue(LHS, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after compare value") ||
|
|
|
|
ParseValue(LHS->getType(), RHS, PFS))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (Opc == Instruction::FCmp) {
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!LHS->getType()->isFPOrFPVectorTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc, "fcmp requires floating point operands");
|
2009-08-25 23:17:54 +00:00
|
|
|
Inst = new FCmpInst(CmpInst::Predicate(Pred), LHS, RHS);
|
2009-07-08 03:04:38 +00:00
|
|
|
} else {
|
|
|
|
assert(Opc == Instruction::ICmp && "Unknown opcode for CmpInst!");
|
2010-02-15 16:12:20 +00:00
|
|
|
if (!LHS->getType()->isIntOrIntVectorTy() &&
|
2011-12-05 06:29:09 +00:00
|
|
|
!LHS->getType()->getScalarType()->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc, "icmp requires integer operands");
|
2009-08-25 23:17:54 +00:00
|
|
|
Inst = new ICmpInst(CmpInst::Predicate(Pred), LHS, RHS);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Other Instructions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
|
/// ParseCast
|
|
|
|
/// ::= CastOpc TypeAndValue 'to' Type
|
|
|
|
bool LLParser::ParseCast(Instruction *&Inst, PerFunctionState &PFS,
|
|
|
|
unsigned Opc) {
|
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
|
|
|
LocTy Loc;
|
|
|
|
Value *Op;
|
|
|
|
Type *DestTy = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Op, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::kw_to, "expected 'to' after cast value") ||
|
|
|
|
ParseType(DestTy))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-03-01 00:53:13 +00:00
|
|
|
if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy)) {
|
|
|
|
CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy);
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc, "invalid cast opcode for cast from '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(Op->getType()) + "' to '" +
|
|
|
|
getTypeString(DestTy) + "'");
|
2009-03-01 00:53:13 +00:00
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
Inst = CastInst::Create((Instruction::CastOps)Opc, Op, DestTy);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseSelect
|
|
|
|
/// ::= 'select' TypeAndValue ',' TypeAndValue ',' TypeAndValue
|
|
|
|
bool LLParser::ParseSelect(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
LocTy Loc;
|
|
|
|
Value *Op0, *Op1, *Op2;
|
|
|
|
if (ParseTypeAndValue(Op0, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after select condition") ||
|
|
|
|
ParseTypeAndValue(Op1, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after select value") ||
|
|
|
|
ParseTypeAndValue(Op2, PFS))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (const char *Reason = SelectInst::areInvalidOperands(Op0, Op1, Op2))
|
|
|
|
return Error(Loc, Reason);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Inst = SelectInst::Create(Op0, Op1, Op2);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-05 08:18:44 +00:00
|
|
|
/// ParseVA_Arg
|
|
|
|
/// ::= 'va_arg' TypeAndValue ',' Type
|
|
|
|
bool LLParser::ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *Op;
|
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 *EltTy = 0;
|
2009-01-05 08:18:44 +00:00
|
|
|
LocTy TypeLoc;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Op, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after vaarg operand") ||
|
2009-01-05 08:18:44 +00:00
|
|
|
ParseType(EltTy, TypeLoc))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-05 08:18:44 +00:00
|
|
|
if (!EltTy->isFirstClassType())
|
|
|
|
return Error(TypeLoc, "va_arg requires operand with first class type");
|
2009-01-02 07:01:27 +00:00
|
|
|
|
|
|
|
Inst = new VAArgInst(Op, EltTy);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseExtractElement
|
|
|
|
/// ::= 'extractelement' TypeAndValue ',' TypeAndValue
|
|
|
|
bool LLParser::ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
LocTy Loc;
|
|
|
|
Value *Op0, *Op1;
|
|
|
|
if (ParseTypeAndValue(Op0, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after extract value") ||
|
|
|
|
ParseTypeAndValue(Op1, PFS))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!ExtractElementInst::isValidOperands(Op0, Op1))
|
|
|
|
return Error(Loc, "invalid extractelement operands");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-07-25 02:28:41 +00:00
|
|
|
Inst = ExtractElementInst::Create(Op0, Op1);
|
2009-01-02 07:01:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseInsertElement
|
|
|
|
/// ::= 'insertelement' TypeAndValue ',' TypeAndValue ',' TypeAndValue
|
|
|
|
bool LLParser::ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
LocTy Loc;
|
|
|
|
Value *Op0, *Op1, *Op2;
|
|
|
|
if (ParseTypeAndValue(Op0, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after insertelement value") ||
|
|
|
|
ParseTypeAndValue(Op1, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after insertelement value") ||
|
|
|
|
ParseTypeAndValue(Op2, PFS))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!InsertElementInst::isValidOperands(Op0, Op1, Op2))
|
2009-07-23 01:01:32 +00:00
|
|
|
return Error(Loc, "invalid insertelement operands");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Inst = InsertElementInst::Create(Op0, Op1, Op2);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseShuffleVector
|
|
|
|
/// ::= 'shufflevector' TypeAndValue ',' TypeAndValue ',' TypeAndValue
|
|
|
|
bool LLParser::ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
LocTy Loc;
|
|
|
|
Value *Op0, *Op1, *Op2;
|
|
|
|
if (ParseTypeAndValue(Op0, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after shuffle mask") ||
|
|
|
|
ParseTypeAndValue(Op1, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after shuffle value") ||
|
|
|
|
ParseTypeAndValue(Op2, PFS))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!ShuffleVectorInst::isValidOperands(Op0, Op1, Op2))
|
2012-02-01 23:43:12 +00:00
|
|
|
return Error(Loc, "invalid shufflevector operands");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
Inst = new ShuffleVectorInst(Op0, Op1, Op2);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParsePHI
|
2009-10-18 05:27:44 +00:00
|
|
|
/// ::= 'phi' Type '[' Value ',' Value ']' (',' '[' Value ',' Value ']')*
|
2009-12-30 05:27:33 +00:00
|
|
|
int LLParser::ParsePHI(Instruction *&Inst, 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
|
|
|
Type *Ty = 0; LocTy TypeLoc;
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *Op0, *Op1;
|
2009-09-20 02:20:51 +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
|
|
|
if (ParseType(Ty, TypeLoc) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::lsquare, "expected '[' in phi value list") ||
|
|
|
|
ParseValue(Ty, Op0, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after insertelement value") ||
|
2009-08-13 21:58:54 +00:00
|
|
|
ParseValue(Type::getLabelTy(Context), Op1, PFS) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::rsquare, "expected ']' in phi value list"))
|
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-12-30 05:27:33 +00:00
|
|
|
bool AteExtraComma = false;
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<std::pair<Value*, BasicBlock*>, 16> PHIVals;
|
|
|
|
while (1) {
|
|
|
|
PHIVals.push_back(std::make_pair(Op0, cast<BasicBlock>(Op1)));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
if (!EatIfPresent(lltok::comma))
|
2009-01-02 07:01:27 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-30 05:27:33 +00:00
|
|
|
if (Lex.getKind() == lltok::MetadataVar) {
|
|
|
|
AteExtraComma = true;
|
2009-10-16 18:45:49 +00:00
|
|
|
break;
|
2009-12-30 05:27:33 +00:00
|
|
|
}
|
2009-10-16 18:45:49 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseToken(lltok::lsquare, "expected '[' in phi value list") ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseValue(Ty, Op0, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after insertelement value") ||
|
2009-08-13 21:58:54 +00:00
|
|
|
ParseValue(Type::getLabelTy(Context), Op1, PFS) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseToken(lltok::rsquare, "expected ']' in phi value list"))
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!Ty->isFirstClassType())
|
|
|
|
return Error(TypeLoc, "phi node must have first class type");
|
|
|
|
|
2011-03-30 11:28:46 +00:00
|
|
|
PHINode *PN = PHINode::Create(Ty, PHIVals.size());
|
2009-01-02 07:01:27 +00:00
|
|
|
for (unsigned i = 0, e = PHIVals.size(); i != e; ++i)
|
|
|
|
PN->addIncoming(PHIVals[i].first, PHIVals[i].second);
|
|
|
|
Inst = PN;
|
2009-12-30 05:27:33 +00:00
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 20:24:12 +00:00
|
|
|
/// ParseLandingPad
|
|
|
|
/// ::= 'landingpad' Type 'personality' TypeAndValue 'cleanup'? Clause+
|
|
|
|
/// Clause
|
|
|
|
/// ::= 'catch' TypeAndValue
|
|
|
|
/// ::= 'filter'
|
|
|
|
/// ::= 'filter' TypeAndValue ( ',' TypeAndValue )*
|
|
|
|
bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
Type *Ty = 0; LocTy TyLoc;
|
|
|
|
Value *PersFn; LocTy PersFnLoc;
|
|
|
|
|
|
|
|
if (ParseType(Ty, TyLoc) ||
|
|
|
|
ParseToken(lltok::kw_personality, "expected 'personality'") ||
|
|
|
|
ParseTypeAndValue(PersFn, PersFnLoc, PFS))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, 0);
|
|
|
|
LP->setCleanup(EatIfPresent(lltok::kw_cleanup));
|
|
|
|
|
|
|
|
while (Lex.getKind() == lltok::kw_catch || Lex.getKind() == lltok::kw_filter){
|
|
|
|
LandingPadInst::ClauseType CT;
|
|
|
|
if (EatIfPresent(lltok::kw_catch))
|
|
|
|
CT = LandingPadInst::Catch;
|
|
|
|
else if (EatIfPresent(lltok::kw_filter))
|
|
|
|
CT = LandingPadInst::Filter;
|
|
|
|
else
|
|
|
|
return TokError("expected 'catch' or 'filter' clause type");
|
|
|
|
|
|
|
|
Value *V; LocTy VLoc;
|
|
|
|
if (ParseTypeAndValue(V, VLoc, PFS)) {
|
|
|
|
delete LP;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-12 20:52:25 +00:00
|
|
|
// A 'catch' type expects a non-array constant. A filter clause expects an
|
|
|
|
// array constant.
|
|
|
|
if (CT == LandingPadInst::Catch) {
|
|
|
|
if (isa<ArrayType>(V->getType()))
|
|
|
|
Error(VLoc, "'catch' clause has an invalid type");
|
|
|
|
} else {
|
|
|
|
if (!isa<ArrayType>(V->getType()))
|
|
|
|
Error(VLoc, "'filter' clause has an invalid type");
|
|
|
|
}
|
|
|
|
|
2011-08-12 20:24:12 +00:00
|
|
|
LP->addClause(V);
|
|
|
|
}
|
|
|
|
|
|
|
|
Inst = LP;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseCall
|
|
|
|
/// ::= 'tail'? 'call' OptionalCallingConv OptionalAttrs Type Value
|
|
|
|
/// ParameterList OptionalAttrs
|
|
|
|
bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
|
|
|
|
bool isTail) {
|
2012-10-15 20:35:56 +00:00
|
|
|
AttrBuilder RetAttrs, FnAttrs;
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CC;
|
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 *RetType = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
LocTy RetTypeLoc;
|
|
|
|
ValID CalleeID;
|
|
|
|
SmallVector<ParamInfo, 16> ArgList;
|
|
|
|
LocTy CallLoc = Lex.getLoc();
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if ((isTail && ParseToken(lltok::kw_call, "expected 'tail call'")) ||
|
|
|
|
ParseOptionalCallingConv(CC) ||
|
2012-12-04 23:40:58 +00:00
|
|
|
ParseOptionalReturnAttrs(RetAttrs) ||
|
2009-03-09 04:49:14 +00:00
|
|
|
ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
|
2009-01-02 07:01:27 +00:00
|
|
|
ParseValID(CalleeID) ||
|
|
|
|
ParseParameterList(ArgList, PFS) ||
|
2012-12-04 23:40:58 +00:00
|
|
|
ParseOptionalFuncAttrs(FnAttrs))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// If RetType is a non-function pointer type, then this is the short syntax
|
|
|
|
// for the call, which means that RetType is just the return type. Infer the
|
|
|
|
// rest of the function argument types from the arguments that are present.
|
2011-07-18 04:54:35 +00:00
|
|
|
PointerType *PFTy = 0;
|
|
|
|
FunctionType *Ty = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!(PFTy = dyn_cast<PointerType>(RetType)) ||
|
|
|
|
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
|
|
|
|
// Pull out the types of all of the arguments...
|
2011-07-12 14:06:48 +00:00
|
|
|
std::vector<Type*> ParamTypes;
|
2010-07-24 23:06:59 +00:00
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
|
|
|
|
ParamTypes.push_back(ArgList[i].V->getType());
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (!FunctionType::isValidReturnType(RetType))
|
|
|
|
return Error(RetTypeLoc, "Invalid result type for LLVM function");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-07-29 22:17:13 +00:00
|
|
|
Ty = FunctionType::get(RetType, ParamTypes, false);
|
|
|
|
PFTy = PointerType::getUnqual(Ty);
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Look up the callee.
|
|
|
|
Value *Callee;
|
2010-01-11 22:31:58 +00:00
|
|
|
if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2012-12-19 07:18:57 +00:00
|
|
|
// Set up the Attribute for the function.
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<AttributeWithIndex, 8> Attrs;
|
2012-09-19 23:54:18 +00:00
|
|
|
if (RetAttrs.hasAttributes())
|
2012-10-15 07:29:08 +00:00
|
|
|
Attrs.push_back(
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeWithIndex::get(AttributeSet::ReturnIndex,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(Callee->getContext(),
|
2012-10-15 07:29:08 +00:00
|
|
|
RetAttrs)));
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<Value*, 8> Args;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
// Loop through FunctionType's arguments and ensure they are specified
|
|
|
|
// correctly. Also, gather any parameter attributes.
|
|
|
|
FunctionType::param_iterator I = Ty->param_begin();
|
|
|
|
FunctionType::param_iterator E = Ty->param_end();
|
|
|
|
for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *ExpectedTy = 0;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (I != E) {
|
|
|
|
ExpectedTy = *I++;
|
|
|
|
} else if (!Ty->isVarArg()) {
|
|
|
|
return Error(ArgList[i].Loc, "too many arguments specified");
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ExpectedTy && ExpectedTy != ArgList[i].V->getType())
|
|
|
|
return Error(ArgList[i].Loc, "argument is not of expected type '" +
|
2011-06-18 21:18:23 +00:00
|
|
|
getTypeString(ExpectedTy) + "'");
|
2009-01-02 07:01:27 +00:00
|
|
|
Args.push_back(ArgList[i].V);
|
2012-09-19 23:54:18 +00:00
|
|
|
if (ArgList[i].Attrs.hasAttributes())
|
2009-01-02 07:01:27 +00:00
|
|
|
Attrs.push_back(AttributeWithIndex::get(i+1, ArgList[i].Attrs));
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (I != E)
|
|
|
|
return Error(CallLoc, "not enough parameters specified for call");
|
|
|
|
|
2012-09-19 23:54:18 +00:00
|
|
|
if (FnAttrs.hasAttributes())
|
2012-10-15 07:29:08 +00:00
|
|
|
Attrs.push_back(
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeWithIndex::get(AttributeSet::FunctionIndex,
|
2012-12-19 07:18:57 +00:00
|
|
|
Attribute::get(Callee->getContext(),
|
2012-10-15 07:29:08 +00:00
|
|
|
FnAttrs)));
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2012-12-19 07:18:57 +00:00
|
|
|
// Finish off the Attribute and check them
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet PAL = AttributeSet::get(Context, Attrs);
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-07-15 08:37:34 +00:00
|
|
|
CallInst *CI = CallInst::Create(Callee, Args);
|
2009-01-02 07:01:27 +00:00
|
|
|
CI->setTailCall(isTail);
|
|
|
|
CI->setCallingConv(CC);
|
|
|
|
CI->setAttributes(PAL);
|
|
|
|
Inst = CI;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Memory Instructions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseAlloc
|
2009-09-17 23:04:48 +00:00
|
|
|
/// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalInfo)?
|
2011-06-17 03:16:47 +00:00
|
|
|
int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *Size = 0;
|
2009-07-02 23:08:13 +00:00
|
|
|
LocTy SizeLoc;
|
2009-01-02 07:01:27 +00:00
|
|
|
unsigned Alignment = 0;
|
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 = 0;
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseType(Ty)) return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2009-12-30 05:44:30 +00:00
|
|
|
bool AteExtraComma = false;
|
2009-01-02 08:05:26 +00:00
|
|
|
if (EatIfPresent(lltok::comma)) {
|
2009-12-30 05:44:30 +00:00
|
|
|
if (Lex.getKind() == lltok::kw_align) {
|
|
|
|
if (ParseOptionalAlignment(Alignment)) return true;
|
|
|
|
} else if (Lex.getKind() == lltok::MetadataVar) {
|
|
|
|
AteExtraComma = true;
|
2009-09-17 23:04:48 +00:00
|
|
|
} else {
|
2009-12-30 05:44:30 +00:00
|
|
|
if (ParseTypeAndValue(Size, SizeLoc, PFS) ||
|
|
|
|
ParseOptionalCommaAlign(Alignment, AteExtraComma))
|
|
|
|
return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 01:14:11 +00:00
|
|
|
if (Size && !Size->getType()->isIntegerTy())
|
|
|
|
return Error(SizeLoc, "element count must have integer type");
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2011-06-17 03:16:47 +00:00
|
|
|
Inst = new AllocaInst(Ty, Size, Alignment);
|
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseLoad
|
2011-08-12 22:50:01 +00:00
|
|
|
/// ::= 'load' 'volatile'? TypeAndValue (',' 'align' i32)?
|
2012-11-15 22:34:00 +00:00
|
|
|
/// ::= 'load' 'atomic' 'volatile'? TypeAndValue
|
2011-08-12 22:50:01 +00:00
|
|
|
/// 'singlethread'? AtomicOrdering (',' 'align' i32)?
|
2011-11-27 06:56:53 +00:00
|
|
|
int LLParser::ParseLoad(Instruction *&Inst, PerFunctionState &PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *Val; LocTy Loc;
|
2009-09-17 23:04:48 +00:00
|
|
|
unsigned Alignment = 0;
|
2009-12-30 05:44:30 +00:00
|
|
|
bool AteExtraComma = false;
|
2011-08-12 22:50:01 +00:00
|
|
|
bool isAtomic = false;
|
2011-08-09 23:02:53 +00:00
|
|
|
AtomicOrdering Ordering = NotAtomic;
|
|
|
|
SynchronizationScope Scope = CrossThread;
|
2011-08-12 22:50:01 +00:00
|
|
|
|
|
|
|
if (Lex.getKind() == lltok::kw_atomic) {
|
|
|
|
isAtomic = true;
|
|
|
|
Lex.Lex();
|
|
|
|
}
|
|
|
|
|
2011-11-27 06:56:53 +00:00
|
|
|
bool isVolatile = false;
|
2011-08-12 22:50:01 +00:00
|
|
|
if (Lex.getKind() == lltok::kw_volatile) {
|
|
|
|
isVolatile = true;
|
|
|
|
Lex.Lex();
|
|
|
|
}
|
|
|
|
|
2009-12-30 05:44:30 +00:00
|
|
|
if (ParseTypeAndValue(Val, Loc, PFS) ||
|
2011-08-09 23:02:53 +00:00
|
|
|
ParseScopeAndOrdering(isAtomic, Scope, Ordering) ||
|
2009-12-30 05:44:30 +00:00
|
|
|
ParseOptionalCommaAlign(Alignment, AteExtraComma))
|
|
|
|
return true;
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Val->getType()->isPointerTy() ||
|
2009-01-02 07:01:27 +00:00
|
|
|
!cast<PointerType>(Val->getType())->getElementType()->isFirstClassType())
|
|
|
|
return Error(Loc, "load operand must be a pointer to a first class type");
|
2011-08-09 23:02:53 +00:00
|
|
|
if (isAtomic && !Alignment)
|
|
|
|
return Error(Loc, "atomic load must have explicit non-zero alignment");
|
|
|
|
if (Ordering == Release || Ordering == AcquireRelease)
|
|
|
|
return Error(Loc, "atomic load cannot use Release ordering");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-08-09 23:02:53 +00:00
|
|
|
Inst = new LoadInst(Val, "", isVolatile, Alignment, Ordering, Scope);
|
2009-12-30 05:44:30 +00:00
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseStore
|
2011-08-12 22:50:01 +00:00
|
|
|
|
|
|
|
/// ::= 'store' 'volatile'? TypeAndValue ',' TypeAndValue (',' 'align' i32)?
|
|
|
|
/// ::= 'store' 'atomic' 'volatile'? TypeAndValue ',' TypeAndValue
|
2011-08-09 23:02:53 +00:00
|
|
|
/// 'singlethread'? AtomicOrdering (',' 'align' i32)?
|
2011-11-27 06:56:53 +00:00
|
|
|
int LLParser::ParseStore(Instruction *&Inst, PerFunctionState &PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *Val, *Ptr; LocTy Loc, PtrLoc;
|
2009-09-17 23:04:48 +00:00
|
|
|
unsigned Alignment = 0;
|
2009-12-30 05:44:30 +00:00
|
|
|
bool AteExtraComma = false;
|
2011-08-12 22:50:01 +00:00
|
|
|
bool isAtomic = false;
|
2011-08-09 23:02:53 +00:00
|
|
|
AtomicOrdering Ordering = NotAtomic;
|
|
|
|
SynchronizationScope Scope = CrossThread;
|
2011-08-12 22:50:01 +00:00
|
|
|
|
|
|
|
if (Lex.getKind() == lltok::kw_atomic) {
|
|
|
|
isAtomic = true;
|
|
|
|
Lex.Lex();
|
|
|
|
}
|
|
|
|
|
2011-11-27 06:56:53 +00:00
|
|
|
bool isVolatile = false;
|
2011-08-12 22:50:01 +00:00
|
|
|
if (Lex.getKind() == lltok::kw_volatile) {
|
|
|
|
isVolatile = true;
|
|
|
|
Lex.Lex();
|
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Val, Loc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after store operand") ||
|
2009-12-30 05:44:30 +00:00
|
|
|
ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
|
2011-08-09 23:02:53 +00:00
|
|
|
ParseScopeAndOrdering(isAtomic, Scope, Ordering) ||
|
2009-12-30 05:44:30 +00:00
|
|
|
ParseOptionalCommaAlign(Alignment, AteExtraComma))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2009-09-17 23:04:48 +00:00
|
|
|
|
2010-02-16 11:11:14 +00:00
|
|
|
if (!Ptr->getType()->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(PtrLoc, "store operand must be a pointer");
|
|
|
|
if (!Val->getType()->isFirstClassType())
|
|
|
|
return Error(Loc, "store operand must be a first class value");
|
|
|
|
if (cast<PointerType>(Ptr->getType())->getElementType() != Val->getType())
|
|
|
|
return Error(Loc, "stored value and pointer type do not match");
|
2011-08-09 23:02:53 +00:00
|
|
|
if (isAtomic && !Alignment)
|
|
|
|
return Error(Loc, "atomic store must have explicit non-zero alignment");
|
|
|
|
if (Ordering == Acquire || Ordering == AcquireRelease)
|
|
|
|
return Error(Loc, "atomic store cannot use Acquire ordering");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-08-09 23:02:53 +00:00
|
|
|
Inst = new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, Scope);
|
2009-12-30 05:44:30 +00:00
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
/// ParseCmpXchg
|
2011-08-12 22:50:01 +00:00
|
|
|
/// ::= 'cmpxchg' 'volatile'? TypeAndValue ',' TypeAndValue ',' TypeAndValue
|
|
|
|
/// 'singlethread'? AtomicOrdering
|
|
|
|
int LLParser::ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) {
|
2011-07-28 21:48:00 +00:00
|
|
|
Value *Ptr, *Cmp, *New; LocTy PtrLoc, CmpLoc, NewLoc;
|
|
|
|
bool AteExtraComma = false;
|
|
|
|
AtomicOrdering Ordering = NotAtomic;
|
|
|
|
SynchronizationScope Scope = CrossThread;
|
2011-08-12 22:50:01 +00:00
|
|
|
bool isVolatile = false;
|
|
|
|
|
|
|
|
if (EatIfPresent(lltok::kw_volatile))
|
|
|
|
isVolatile = true;
|
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after cmpxchg address") ||
|
|
|
|
ParseTypeAndValue(Cmp, CmpLoc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after cmpxchg cmp operand") ||
|
|
|
|
ParseTypeAndValue(New, NewLoc, PFS) ||
|
|
|
|
ParseScopeAndOrdering(true /*Always atomic*/, Scope, Ordering))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ordering == Unordered)
|
|
|
|
return TokError("cmpxchg cannot be unordered");
|
|
|
|
if (!Ptr->getType()->isPointerTy())
|
|
|
|
return Error(PtrLoc, "cmpxchg operand must be a pointer");
|
|
|
|
if (cast<PointerType>(Ptr->getType())->getElementType() != Cmp->getType())
|
|
|
|
return Error(CmpLoc, "compare value and pointer type do not match");
|
|
|
|
if (cast<PointerType>(Ptr->getType())->getElementType() != New->getType())
|
|
|
|
return Error(NewLoc, "new value and pointer type do not match");
|
|
|
|
if (!New->getType()->isIntegerTy())
|
|
|
|
return Error(NewLoc, "cmpxchg operand must be an integer");
|
|
|
|
unsigned Size = New->getType()->getPrimitiveSizeInBits();
|
|
|
|
if (Size < 8 || (Size & (Size - 1)))
|
|
|
|
return Error(NewLoc, "cmpxchg operand must be power-of-two byte-sized"
|
|
|
|
" integer");
|
|
|
|
|
|
|
|
AtomicCmpXchgInst *CXI =
|
|
|
|
new AtomicCmpXchgInst(Ptr, Cmp, New, Ordering, Scope);
|
|
|
|
CXI->setVolatile(isVolatile);
|
|
|
|
Inst = CXI;
|
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseAtomicRMW
|
2011-08-12 22:50:01 +00:00
|
|
|
/// ::= 'atomicrmw' 'volatile'? BinOp TypeAndValue ',' TypeAndValue
|
|
|
|
/// 'singlethread'? AtomicOrdering
|
|
|
|
int LLParser::ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
|
2011-07-28 21:48:00 +00:00
|
|
|
Value *Ptr, *Val; LocTy PtrLoc, ValLoc;
|
|
|
|
bool AteExtraComma = false;
|
|
|
|
AtomicOrdering Ordering = NotAtomic;
|
|
|
|
SynchronizationScope Scope = CrossThread;
|
2011-08-12 22:50:01 +00:00
|
|
|
bool isVolatile = false;
|
2011-07-28 21:48:00 +00:00
|
|
|
AtomicRMWInst::BinOp Operation;
|
2011-08-12 22:50:01 +00:00
|
|
|
|
|
|
|
if (EatIfPresent(lltok::kw_volatile))
|
|
|
|
isVolatile = true;
|
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
switch (Lex.getKind()) {
|
|
|
|
default: return TokError("expected binary operation in atomicrmw");
|
|
|
|
case lltok::kw_xchg: Operation = AtomicRMWInst::Xchg; break;
|
|
|
|
case lltok::kw_add: Operation = AtomicRMWInst::Add; break;
|
|
|
|
case lltok::kw_sub: Operation = AtomicRMWInst::Sub; break;
|
|
|
|
case lltok::kw_and: Operation = AtomicRMWInst::And; break;
|
|
|
|
case lltok::kw_nand: Operation = AtomicRMWInst::Nand; break;
|
|
|
|
case lltok::kw_or: Operation = AtomicRMWInst::Or; break;
|
|
|
|
case lltok::kw_xor: Operation = AtomicRMWInst::Xor; break;
|
|
|
|
case lltok::kw_max: Operation = AtomicRMWInst::Max; break;
|
|
|
|
case lltok::kw_min: Operation = AtomicRMWInst::Min; break;
|
|
|
|
case lltok::kw_umax: Operation = AtomicRMWInst::UMax; break;
|
|
|
|
case lltok::kw_umin: Operation = AtomicRMWInst::UMin; break;
|
|
|
|
}
|
|
|
|
Lex.Lex(); // Eat the operation.
|
|
|
|
|
|
|
|
if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected ',' after atomicrmw address") ||
|
|
|
|
ParseTypeAndValue(Val, ValLoc, PFS) ||
|
|
|
|
ParseScopeAndOrdering(true /*Always atomic*/, Scope, Ordering))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ordering == Unordered)
|
|
|
|
return TokError("atomicrmw cannot be unordered");
|
|
|
|
if (!Ptr->getType()->isPointerTy())
|
|
|
|
return Error(PtrLoc, "atomicrmw operand must be a pointer");
|
|
|
|
if (cast<PointerType>(Ptr->getType())->getElementType() != Val->getType())
|
|
|
|
return Error(ValLoc, "atomicrmw value and pointer type do not match");
|
|
|
|
if (!Val->getType()->isIntegerTy())
|
|
|
|
return Error(ValLoc, "atomicrmw operand must be an integer");
|
|
|
|
unsigned Size = Val->getType()->getPrimitiveSizeInBits();
|
|
|
|
if (Size < 8 || (Size & (Size - 1)))
|
|
|
|
return Error(ValLoc, "atomicrmw operand must be power-of-two byte-sized"
|
|
|
|
" integer");
|
|
|
|
|
|
|
|
AtomicRMWInst *RMWI =
|
|
|
|
new AtomicRMWInst(Operation, Ptr, Val, Ordering, Scope);
|
|
|
|
RMWI->setVolatile(isVolatile);
|
|
|
|
Inst = RMWI;
|
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
|
|
|
}
|
|
|
|
|
2011-07-25 23:16:38 +00:00
|
|
|
/// ParseFence
|
|
|
|
/// ::= 'fence' 'singlethread'? AtomicOrdering
|
|
|
|
int LLParser::ParseFence(Instruction *&Inst, PerFunctionState &PFS) {
|
|
|
|
AtomicOrdering Ordering = NotAtomic;
|
|
|
|
SynchronizationScope Scope = CrossThread;
|
|
|
|
if (ParseScopeAndOrdering(true /*Always atomic*/, Scope, Ordering))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ordering == Unordered)
|
|
|
|
return TokError("fence cannot be unordered");
|
|
|
|
if (Ordering == Monotonic)
|
|
|
|
return TokError("fence cannot be monotonic");
|
|
|
|
|
|
|
|
Inst = new FenceInst(Context, Ordering, Scope);
|
|
|
|
return InstNormal;
|
|
|
|
}
|
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
/// ParseGetElementPtr
|
2009-07-27 21:53:46 +00:00
|
|
|
/// ::= 'getelementptr' 'inbounds'? TypeAndValue (',' TypeAndValue)*
|
2009-12-30 05:27:33 +00:00
|
|
|
int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
|
2011-12-05 06:29:09 +00:00
|
|
|
Value *Ptr = 0;
|
|
|
|
Value *Val = 0;
|
|
|
|
LocTy Loc, EltLoc;
|
2009-07-27 21:53:46 +00:00
|
|
|
|
2009-07-29 15:58:36 +00:00
|
|
|
bool InBounds = EatIfPresent(lltok::kw_inbounds);
|
2009-07-27 21:53:46 +00:00
|
|
|
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseTypeAndValue(Ptr, Loc, PFS)) return true;
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-12-05 06:29:09 +00:00
|
|
|
if (!Ptr->getType()->getScalarType()->isPointerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc, "base of getelementptr must be a pointer");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2009-01-02 07:01:27 +00:00
|
|
|
SmallVector<Value*, 16> Indices;
|
2009-12-30 05:27:33 +00:00
|
|
|
bool AteExtraComma = false;
|
2009-01-02 08:05:26 +00:00
|
|
|
while (EatIfPresent(lltok::comma)) {
|
2009-12-30 05:27:33 +00:00
|
|
|
if (Lex.getKind() == lltok::MetadataVar) {
|
|
|
|
AteExtraComma = true;
|
2009-10-13 18:49:55 +00:00
|
|
|
break;
|
2009-12-30 05:27:33 +00:00
|
|
|
}
|
2009-01-02 08:05:26 +00:00
|
|
|
if (ParseTypeAndValue(Val, EltLoc, PFS)) return true;
|
2011-12-05 06:29:09 +00:00
|
|
|
if (!Val->getType()->getScalarType()->isIntegerTy())
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(EltLoc, "getelementptr index must be an integer");
|
2011-12-05 06:29:09 +00:00
|
|
|
if (Val->getType()->isVectorTy() != Ptr->getType()->isVectorTy())
|
|
|
|
return Error(EltLoc, "getelementptr index type missmatch");
|
|
|
|
if (Val->getType()->isVectorTy()) {
|
|
|
|
unsigned ValNumEl = cast<VectorType>(Val->getType())->getNumElements();
|
|
|
|
unsigned PtrNumEl = cast<VectorType>(Ptr->getType())->getNumElements();
|
|
|
|
if (ValNumEl != PtrNumEl)
|
|
|
|
return Error(EltLoc,
|
|
|
|
"getelementptr vector index has a wrong number of elements");
|
|
|
|
}
|
2009-01-02 07:01:27 +00:00
|
|
|
Indices.push_back(Val);
|
|
|
|
}
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-07-25 09:48:08 +00:00
|
|
|
if (!GetElementPtrInst::getIndexedType(Ptr->getType(), Indices))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc, "invalid getelementptr indices");
|
2011-07-25 09:48:08 +00:00
|
|
|
Inst = GetElementPtrInst::Create(Ptr, Indices);
|
2009-07-27 21:53:46 +00:00
|
|
|
if (InBounds)
|
2009-09-07 23:54:19 +00:00
|
|
|
cast<GetElementPtrInst>(Inst)->setIsInBounds(true);
|
2009-12-30 05:27:33 +00:00
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseExtractValue
|
|
|
|
/// ::= 'extractvalue' TypeAndValue (',' uint32)+
|
2009-12-30 05:27:33 +00:00
|
|
|
int LLParser::ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *Val; LocTy Loc;
|
|
|
|
SmallVector<unsigned, 4> Indices;
|
2009-12-30 05:27:33 +00:00
|
|
|
bool AteExtraComma;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Val, Loc, PFS) ||
|
2009-12-30 05:27:33 +00:00
|
|
|
ParseIndexList(Indices, AteExtraComma))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
|
|
|
|
2010-02-12 20:49:41 +00:00
|
|
|
if (!Val->getType()->isAggregateType())
|
|
|
|
return Error(Loc, "extractvalue operand must be aggregate type");
|
2009-01-02 07:01:27 +00:00
|
|
|
|
2011-07-13 10:26:04 +00:00
|
|
|
if (!ExtractValueInst::getIndexedType(Val->getType(), Indices))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc, "invalid indices for extractvalue");
|
2011-07-13 10:26:04 +00:00
|
|
|
Inst = ExtractValueInst::Create(Val, Indices);
|
2009-12-30 05:27:33 +00:00
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseInsertValue
|
|
|
|
/// ::= 'insertvalue' TypeAndValue ',' TypeAndValue (',' uint32)+
|
2009-12-30 05:27:33 +00:00
|
|
|
int LLParser::ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS) {
|
2009-01-02 07:01:27 +00:00
|
|
|
Value *Val0, *Val1; LocTy Loc0, Loc1;
|
|
|
|
SmallVector<unsigned, 4> Indices;
|
2009-12-30 05:27:33 +00:00
|
|
|
bool AteExtraComma;
|
2009-01-02 07:01:27 +00:00
|
|
|
if (ParseTypeAndValue(Val0, Loc0, PFS) ||
|
|
|
|
ParseToken(lltok::comma, "expected comma after insertvalue operand") ||
|
|
|
|
ParseTypeAndValue(Val1, Loc1, PFS) ||
|
2009-12-30 05:27:33 +00:00
|
|
|
ParseIndexList(Indices, AteExtraComma))
|
2009-01-02 07:01:27 +00:00
|
|
|
return true;
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2010-02-12 20:49:41 +00:00
|
|
|
if (!Val0->getType()->isAggregateType())
|
|
|
|
return Error(Loc0, "insertvalue operand must be aggregate type");
|
2009-09-20 02:20:51 +00:00
|
|
|
|
2011-07-13 10:26:04 +00:00
|
|
|
if (!ExtractValueInst::getIndexedType(Val0->getType(), Indices))
|
2009-01-02 07:01:27 +00:00
|
|
|
return Error(Loc0, "invalid indices for insertvalue");
|
2011-07-13 10:26:04 +00:00
|
|
|
Inst = InsertValueInst::Create(Val0, Val1, Indices);
|
2009-12-30 05:27:33 +00:00
|
|
|
return AteExtraComma ? InstExtraComma : InstNormal;
|
2009-01-02 07:01:27 +00:00
|
|
|
}
|
2009-04-04 07:22:01 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Embedded metadata.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ParseMDNodeVector
|
2009-05-10 20:57:05 +00:00
|
|
|
/// ::= Element (',' Element)*
|
|
|
|
/// Element
|
|
|
|
/// ::= 'null' | TypeAndValue
|
2010-01-05 22:22:14 +00:00
|
|
|
bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts,
|
2010-01-10 07:14:18 +00:00
|
|
|
PerFunctionState *PFS) {
|
2010-07-13 19:33:27 +00:00
|
|
|
// Check for an empty list.
|
|
|
|
if (Lex.getKind() == lltok::rbrace)
|
|
|
|
return false;
|
|
|
|
|
2009-04-04 07:22:01 +00:00
|
|
|
do {
|
2009-12-30 04:42:57 +00:00
|
|
|
// Null is a special case since it is typeless.
|
|
|
|
if (EatIfPresent(lltok::kw_null)) {
|
|
|
|
Elts.push_back(0);
|
|
|
|
continue;
|
2009-05-10 20:57:05 +00:00
|
|
|
}
|
2012-11-15 22:34:00 +00:00
|
|
|
|
2009-12-30 04:42:57 +00:00
|
|
|
Value *V = 0;
|
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
|
|
|
if (ParseTypeAndValue(V, PFS)) return true;
|
2009-05-10 20:57:05 +00:00
|
|
|
Elts.push_back(V);
|
2009-04-04 07:22:01 +00:00
|
|
|
} while (EatIfPresent(lltok::comma));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|