diff options
author | Christopher Lamb <christopher.lamb@gmail.com> | 2007-12-11 08:59:05 +0000 |
---|---|---|
committer | Christopher Lamb <christopher.lamb@gmail.com> | 2007-12-11 08:59:05 +0000 |
commit | fe63fb986dc9510c5d68f2442edab9574e9e50d0 (patch) | |
tree | 6a39f01b605f8fe68fa2e0c69f4e4c903c558967 /lib/AsmParser | |
parent | 7431c2ba79cbf7019aafac2ebafa259621726be2 (diff) |
Implement address space attribute for LLVM pointer types. Address spaces are
regions of memory that have a target specific relationship, as described in the
Embedded C Technical Report.
This also implements the 2007-12-11-AddressSpaces test,
which demonstrates how address space attributes can be used in LLVM IR.
In addition, this patch changes the bitcode signature for stores (in a backwards
compatible manner), such that the pointer type, rather than the pointee type, is
encoded. This permits type information in the pointer (e.g. address space) to be
preserved for stores.
LangRef updates are forthcoming.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44858 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r-- | lib/AsmParser/LLLexer.cpp | 1 | ||||
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 31 |
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index ef8d27c8a3..750529451a 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -463,6 +463,7 @@ int LLLexer::LexIdentifier() { KEYWORD("datalayout", DATALAYOUT); KEYWORD("volatile", VOLATILE); KEYWORD("align", ALIGN); + KEYWORD("addrspace", ADDRSPACE); KEYWORD("section", SECTION); KEYWORD("alias", ALIAS); KEYWORD("module", MODULE); diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 57b6f81d8f..cd3a7edb50 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -491,7 +491,8 @@ static Value *getVal(const Type *Ty, const ValID &ID) { if (const FunctionType *FTy = dyn_cast<FunctionType>(ElTy)) V = new Function(FTy, GlobalValue::ExternalLinkage); else - V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage); + V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage, 0, "", + (Module*)0, false, PTy->getAddressSpace()); break; } default: @@ -722,13 +723,14 @@ ParseGlobalVariable(std::string *NameStr, GlobalValue::LinkageTypes Linkage, GlobalValue::VisibilityTypes Visibility, bool isConstantGlobal, const Type *Ty, - Constant *Initializer, bool IsThreadLocal) { + Constant *Initializer, bool IsThreadLocal, + unsigned AddressSpace = 0) { if (isa<FunctionType>(Ty)) { GenerateError("Cannot declare global vars of function type"); return 0; } - const PointerType *PTy = PointerType::get(Ty); + const PointerType *PTy = PointerType::get(Ty, AddressSpace); std::string Name; if (NameStr) { @@ -780,7 +782,7 @@ ParseGlobalVariable(std::string *NameStr, // Otherwise there is no existing GV to use, create one now. GlobalVariable *GV = new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name, - CurModule.CurrentModule, IsThreadLocal); + CurModule.CurrentModule, IsThreadLocal, AddressSpace); GV->setVisibility(Visibility); InsertValue(GV, CurModule.Values); return GV; @@ -1054,7 +1056,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) { %token DECLARE DEFINE GLOBAL CONSTANT SECTION ALIAS VOLATILE THREAD_LOCAL %token TO DOTDOTDOT NULL_TOK UNDEF INTERNAL LINKONCE WEAK APPENDING %token DLLIMPORT DLLEXPORT EXTERN_WEAK -%token OPAQUE EXTERNAL TARGET TRIPLE ALIGN +%token OPAQUE EXTERNAL TARGET TRIPLE ALIGN ADDRSPACE %token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT %token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK %token DATALAYOUT @@ -1268,6 +1270,7 @@ OptCAlign : /*empty*/ { $$ = 0; } | }; + SectionString : SECTION STRINGCONSTANT { for (unsigned i = 0, e = $2->length(); i != e; ++i) if ((*$2)[i] == '"' || (*$2)[i] == '\\') @@ -1320,6 +1323,13 @@ Types delete $1; CHECK_FOR_ERROR } + | Types ADDRSPACE '(' EUINT64VAL ')' '*' { // Pointer type? + if (*$1 == Type::LabelTy) + GEN_ERROR("Cannot form a pointer to a basic block"); + $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1, $4))); + delete $1; + CHECK_FOR_ERROR + } | SymbolicValueRef { // Named types are also simple types... const Type* tmp = getTypeVal($1); CHECK_FOR_ERROR @@ -2073,6 +2083,17 @@ Definition } GlobalVarAttributes { CurGV = 0; } + | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal + ADDRSPACE '(' EUINT64VAL ')' { + /* "Externally Visible" Linkage with address space qualifier */ + if ($5 == 0) + GEN_ERROR("Global value initializer is not a constant"); + CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, + $2, $4, $5->getType(), $5, $3, $8); + CHECK_FOR_ERROR + } GlobalVarAttributes { + CurGV = 0; + } | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal GlobalType ConstVal { if ($6 == 0) |