@@ -139,8 +139,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
139139 // not.
140140 // (It may be safe to add the nocapture parameter to the context
141141 // 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 )
144143 }
145144 }
146145
@@ -153,7 +152,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
153152 // Mark it as noreturn so LLVM can optimize away code.
154153 llvmFn .AddFunctionAttr (c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("noreturn" ), 0 ))
155154 case "internal/abi.NoEscape" :
156- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
155+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
157156 case "runtime.alloc" :
158157 // Tell the optimizer that runtime.alloc is an allocator, meaning that it
159158 // 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)
175174 case "runtime.sliceAppend" :
176175 // Appending a slice will only read the to-be-appended slice, it won't
177176 // be modified.
178- llvmFn .AddAttributeAtIndex (2 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
177+ llvmFn .AddAttributeAtIndex (2 , c .nocaptureAttr )
179178 llvmFn .AddAttributeAtIndex (2 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
180179 case "runtime.sliceCopy" :
181180 // Copying a slice won't capture any of the parameters.
182181 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 )
184183 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 )
186185 case "runtime.stringFromBytes" :
187- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
186+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
188187 llvmFn .AddAttributeAtIndex (1 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
189188 case "runtime.stringFromRunes" :
190- llvmFn .AddAttributeAtIndex (1 , c .ctx . CreateEnumAttribute ( llvm . AttributeKindID ( "nocapture" ), 0 ) )
189+ llvmFn .AddAttributeAtIndex (1 , c .nocaptureAttr )
191190 llvmFn .AddAttributeAtIndex (1 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
192191 case "runtime.trackPointer" :
193192 // This function is necessary for tracking pointers on the stack in a
194193 // portable way (see gc_stack_portable.go). Indicate to the optimizer
195194 // 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 )
197196 llvmFn .AddAttributeAtIndex (1 , c .ctx .CreateEnumAttribute (llvm .AttributeKindID ("readonly" ), 0 ))
198197 case "__mulsi3" , "__divmodsi4" , "__udivmodsi4" :
199198 if strings .Split (c .Triple , "-" )[0 ] == "avr" {
@@ -228,11 +227,9 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
228227
229228 llvmFn .AddFunctionAttr (c .ctx .CreateStringAttribute ("wasm-import-name" , info .wasmName ))
230229 }
231- nocaptureKind := llvm .AttributeKindID ("nocapture" )
232- nocapture := c .ctx .CreateEnumAttribute (nocaptureKind , 0 )
233230 for i , typ := range paramTypes {
234231 if typ .TypeKind () == llvm .PointerTypeKind {
235- llvmFn .AddAttributeAtIndex (i + 1 , nocapture )
232+ llvmFn .AddAttributeAtIndex (i + 1 , c . nocaptureAttr )
236233 }
237234 }
238235 }
0 commit comments