@@ -139,8 +139,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
139
139
// not.
140
140
// (It may be safe to add the nocapture parameter to the context
141
141
// parameter, but I'd like to stay on the safe side here).
142
- nocapture := c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("nocapture" ), 0 )
143
- llvmFn .AddAttributeAtIndex (i + 1 , nocapture )
142
+ llvmFn .AddAttributeAtIndex (i + 1 , c .nocaptureAttr )
144
143
}
145
144
}
146
145
@@ -153,7 +152,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
153
152
// Mark it as noreturn so LLVM can optimize away code.
154
153
llvmFn .AddFunctionAttr (c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("noreturn" ), 0 ))
155
154
case "internal/abi.NoEscape" :
156
- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
155
+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
157
156
case "runtime.alloc" :
158
157
// Tell the optimizer that runtime.alloc is an allocator, meaning that it
159
158
// returns values that are never null and never alias to an existing value.
@@ -175,25 +174,25 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
175
174
case "runtime.sliceAppend" :
176
175
// Appending a slice will only read the to-be-appended slice, it won't
177
176
// be modified.
178
- llvmFn .AddAttributeAtIndex (2 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
177
+ llvmFn .AddAttributeAtIndex (2 , c .nocaptureAttr )
179
178
llvmFn .AddAttributeAtIndex (2 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
180
179
case "runtime.sliceCopy" :
181
180
// Copying a slice won't capture any of the parameters.
182
181
llvmFn .AddAttributeAtIndex (1 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("writeonly" ), 0 ))
183
- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
182
+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
184
183
llvmFn .AddAttributeAtIndex (2 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
185
- llvmFn .AddAttributeAtIndex (2 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
184
+ llvmFn .AddAttributeAtIndex (2 , c .nocaptureAttr )
186
185
case "runtime.stringFromBytes" :
187
- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
186
+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
188
187
llvmFn .AddAttributeAtIndex (1 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
189
188
case "runtime.stringFromRunes" :
190
- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
189
+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
191
190
llvmFn .AddAttributeAtIndex (1 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
192
191
case "runtime.trackPointer" :
193
192
// This function is necessary for tracking pointers on the stack in a
194
193
// portable way (see gc_stack_portable.go). Indicate to the optimizer
195
194
// that the only thing we'll do is read the pointer.
196
- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
195
+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
197
196
llvmFn .AddAttributeAtIndex (1 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
198
197
case "__mulsi3" , "__divmodsi4" , "__udivmodsi4" :
199
198
if strings .Split (c .Triple , "-" )[0 ] == "avr" {
@@ -228,11 +227,9 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
228
227
229
228
llvmFn .AddFunctionAttr (c .ctx .CreateStringAttribute ("wasm-import-name" , info .wasmName ))
230
229
}
231
- nocaptureKind := llvm .AttributeKindID ("nocapture" )
232
- nocapture := c .ctx .CreateEnumAttribute (nocaptureKind , 0 )
233
230
for i , typ := range paramTypes {
234
231
if typ .TypeKind () == llvm .PointerTypeKind {
235
- llvmFn .AddAttributeAtIndex (i + 1 , nocapture )
232
+ llvmFn .AddAttributeAtIndex (i + 1 , c . nocaptureAttr )
236
233
}
237
234
}
238
235
}
0 commit comments