llvm.org GIT mirror llvm / d49e18d
Implement part of review feedback for address spaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44933 91177308-0d34-0410-b5e6-96231b3b80d8 Christopher Lamb 12 years ago
5 changed file(s) with 25 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
670670

A global variable may be declared to reside in a target-specifc numbered

671671 address space. For targets that support them, address spaces may affect how
672672 optimizations are performed and/or what target instructions are used to access
673 the variable. The default address space is zero.

673 the variable. The default address space is zero. The address space qualifier
674 must precede any other attributes.

674675
675676

LLVM allows an explicit section to be specified for globals. If the target

676677 supports it, it will emit globals to the section specified.

193193 FUNC_CODE_INST_FREE = 18, // FREE: [opty, op]
194194 FUNC_CODE_INST_ALLOCA = 19, // ALLOCA: [instty, op, align]
195195 FUNC_CODE_INST_LOAD = 20, // LOAD: [opty, op, align, vol]
196 // FIXME: Remove STORE in favor of STORE2 in LLVM 3.0
196197 FUNC_CODE_INST_STORE = 21, // STORE: [valty,val,ptr, align, vol]
197198 FUNC_CODE_INST_CALL = 22, // CALL: [attr, fnty, fnid, args...]
198199 FUNC_CODE_INST_VAARG = 23, // VAARG: [valistty, valist, instty]
10491049 %type GlobalName OptGlobalAssign GlobalAssign
10501050 %type OptSection SectionString OptGC
10511051
1052 %type OptAlign OptCAlign
1052 %type OptAlign OptCAlign OptAddrSpace
10531053
10541054 %token ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK
10551055 %token DECLARE DEFINE GLOBAL CONSTANT SECTION ALIAS VOLATILE THREAD_LOCAL
11351135
11361136 LocalName : LOCALVAR | STRINGCONSTANT | PCTSTRINGCONSTANT ;
11371137 OptLocalName : LocalName | /*empty*/ { $$ = 0; };
1138
1139 OptAddrSpace : ADDRSPACE '(' EUINT64VAL ')' { $$=$3; }
1140 | /*empty*/ { $$=0; };
11381141
11391142 /// OptLocalAssign - Value producing statements have an optional assignment
11401143 /// component.
13151318 $$ = new PATypeHolder($1);
13161319 CHECK_FOR_ERROR
13171320 }
1318 | Types '*' { // Pointer type?
1321 | Types OptAddrSpace '*' { // Pointer type?
13191322 if (*$1 == Type::LabelTy)
13201323 GEN_ERROR("Cannot form a pointer to a basic block");
1321 $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1)));
1322 delete $1;
1323 CHECK_FOR_ERROR
1324 }
1325 | Types ADDRSPACE '(' EUINT64VAL ')' '*' { // Pointer type?
1326 if (*$1 == Type::LabelTy)
1327 GEN_ERROR("Cannot form a pointer to a basic block");
1328 $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1, $4)));
1324 $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1, $2)));
13291325 delete $1;
13301326 CHECK_FOR_ERROR
13311327 }
20722068 }
20732069 CHECK_FOR_ERROR
20742070 }
2075 | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal {
2071 | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal
2072 OptAddrSpace {
20762073 /* "Externally Visible" Linkage */
20772074 if ($5 == 0)
20782075 GEN_ERROR("Global value initializer is not a constant");
20792076 CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
2080 $2, $4, $5->getType(), $5, $3);
2077 $2, $4, $5->getType(), $5, $3, $6);
20812078 CHECK_FOR_ERROR
20822079 } GlobalVarAttributes {
20832080 CurGV = 0;
20842081 }
2085 | OptGlobalAssign GVVisibilityStyle ThreadLocal GlobalType ConstVal
2086 ADDRSPACE '(' EUINT64VAL ')' {
2087 /* "Externally Visible" Linkage with address space qualifier */
2088 if ($5 == 0)
2082 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal GlobalType
2083 ConstVal OptAddrSpace {
2084 if ($6 == 0)
20892085 GEN_ERROR("Global value initializer is not a constant");
2090 CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
2091 $2, $4, $5->getType(), $5, $3, $8);
2086 CurGV = ParseGlobalVariable($1, $2, $3, $5, $6->getType(), $6, $4, $7);
20922087 CHECK_FOR_ERROR
20932088 } GlobalVarAttributes {
20942089 CurGV = 0;
20952090 }
2096 | OptGlobalAssign GVInternalLinkage GVVisibilityStyle ThreadLocal GlobalType
2097 ConstVal {
2098 if ($6 == 0)
2099 GEN_ERROR("Global value initializer is not a constant");
2100 CurGV = ParseGlobalVariable($1, $2, $3, $5, $6->getType(), $6, $4);
2101 CHECK_FOR_ERROR
2102 } GlobalVarAttributes {
2103 CurGV = 0;
2104 }
21052091 | OptGlobalAssign GVExternalLinkage GVVisibilityStyle ThreadLocal GlobalType
2106 Types {
2092 Types OptAddrSpace {
21072093 if (!UpRefs.empty())
21082094 GEN_ERROR("Invalid upreference in type: " + (*$6)->getDescription());
2109 CurGV = ParseGlobalVariable($1, $2, $3, $5, *$6, 0, $4);
2095 CurGV = ParseGlobalVariable($1, $2, $3, $5, *$6, 0, $4, $7);
21102096 CHECK_FOR_ERROR
21112097 delete $6;
21122098 } GlobalVarAttributes {
140140 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_POINTER));
141141 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
142142 Log2_32_Ceil(VE.getTypes().size()+1)));
143 Abbv->Add(BitCodeAbbrevOp(0)); // Addrspace = 0
143144 unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv);
144145
145146 // Abbrev for TYPE_CODE_FUNCTION.
197198 break;
198199 case Type::PointerTyID: {
199200 const PointerType *PTy = cast(T);
200 // POINTER: [pointee type] or [pointee type, address space]
201 // POINTER: [pointee type, address space]
201202 Code = bitc::TYPE_CODE_POINTER;
202203 TypeVals.push_back(VE.getTypeID(PTy->getElementType()));
203 if (unsigned AddressSpace = PTy->getAddressSpace())
204 TypeVals.push_back(AddressSpace);
205 else
206 AbbrevToUse = PtrAbbrev;
204 unsigned AddressSpace = PTy->getAddressSpace();
205 TypeVals.push_back(AddressSpace);
206 if (AddressSpace == 0) AbbrevToUse = PtrAbbrev;
207207 break;
208208 }
209
210209 case Type::FunctionTyID: {
211210 const FunctionType *FT = cast(T);
212211 // FUNCTION: [isvararg, attrid, retty, paramty x N]
44 ; RUN: llvm-as < %s | llvm-dis |& grep {addrspace(22)} | count 5
55
66 %struct.mystruct = type { i32, i32 addrspace(33)*, i32, i32 addrspace(33)* }
7 @input = global %struct.mystruct zeroinitializer addrspace(42) ; <%struct.mystruct addrspace(42)*> [#uses=1]
7 @input = weak global %struct.mystruct zeroinitializer addrspace(42) ; <%struct.mystruct addrspace(42)*> [#uses=1]
88 @output = global %struct.mystruct zeroinitializer addrspace(66) ; <%struct.mystruct addrspace(66)*> [#uses=1]
9 @y = global i32 addrspace(11)* addrspace(22)* null addrspace(33) ; [#uses=1]
9 @y = external global i32 addrspace(11)* addrspace(22)* addrspace(33) ; [#uses=1]
1010
1111 define void @foo() {
1212 entry: