bool has_offset;
};
+enum ac_func_attr {
+ AC_FUNC_ATTR_ALWAYSINLINE = (1 << 0),
+ AC_FUNC_ATTR_BYVAL = (1 << 1),
+ AC_FUNC_ATTR_INREG = (1 << 2),
+ AC_FUNC_ATTR_NOALIAS = (1 << 3),
+ AC_FUNC_ATTR_NOUNWIND = (1 << 4),
+ AC_FUNC_ATTR_READNONE = (1 << 5),
+ AC_FUNC_ATTR_READONLY = (1 << 6),
+ AC_FUNC_ATTR_LAST = (1 << 7)
+};
+
+#if HAVE_LLVM < 0x0400
+static LLVMAttribute ac_attr_to_llvm_attr(enum ac_func_attr attr)
+{
+ switch (attr) {
+ case AC_FUNC_ATTR_ALWAYSINLINE: return LLVMAlwaysInlineAttribute;
+ case AC_FUNC_ATTR_BYVAL: return LLVMByValAttribute;
+ case AC_FUNC_ATTR_INREG: return LLVMInRegAttribute;
+ case AC_FUNC_ATTR_NOALIAS: return LLVMNoAliasAttribute;
+ case AC_FUNC_ATTR_NOUNWIND: return LLVMNoUnwindAttribute;
+ case AC_FUNC_ATTR_READNONE: return LLVMReadNoneAttribute;
+ case AC_FUNC_ATTR_READONLY: return LLVMReadOnlyAttribute;
+ default:
+ fprintf(stderr, "Unhandled function attribute: %x\n", attr);
+ return 0;
+ }
+}
+
+#else
+
+static const char *attr_to_str(enum ac_func_attr attr)
+{
+ switch (attr) {
+ case AC_FUNC_ATTR_ALWAYSINLINE: return "alwaysinline";
+ case AC_FUNC_ATTR_BYVAL: return "byval";
+ case AC_FUNC_ATTR_INREG: return "inreg";
+ case AC_FUNC_ATTR_NOALIAS: return "noalias";
+ case AC_FUNC_ATTR_NOUNWIND: return "nounwind";
+ case AC_FUNC_ATTR_READNONE: return "readnone";
+ case AC_FUNC_ATTR_READONLY: return "readonly";
+ default:
+ fprintf(stderr, "Unhandled function attribute: %x\n", attr);
+ return 0;
+ }
+}
+
+#endif
+
+static void
+ac_add_function_attr(LLVMValueRef function,
+ int attr_idx,
+ enum ac_func_attr attr)
+{
+
+#if HAVE_LLVM < 0x0400
+ LLVMAttribute llvm_attr = ac_attr_to_llvm_attr(attr);
+ if (attr_idx == -1) {
+ LLVMAddFunctionAttr(function, llvm_attr);
+ } else {
+ LLVMAddAttribute(LLVMGetParam(function, attr_idx - 1), llvm_attr);
+ }
+#else
+ LLVMContextRef context = LLVMGetModuleContext(LLVMGetGlobalParent(function));
+ const char *attr_name = attr_to_str(attr);
+ unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name,
+ strlen(attr_name));
+ LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(context, kind_id, 0);
+ LLVMAddAttributeAtIndex(function, attr_idx, llvm_attr);
+#endif
+}
+
static LLVMValueRef
emit_llvm_intrinsic(struct nir_to_llvm_context *ctx, const char *name,
LLVMTypeRef return_type, LLVMValueRef *params,
- unsigned param_count, LLVMAttribute attribs);
+ unsigned param_count, unsigned attr_mask);
static LLVMValueRef get_sampler_desc(struct nir_to_llvm_context *ctx,
nir_deref_var *deref,
enum desc_type desc_type);
LLVMValueRef P = LLVMGetParam(main_function, i);
if (i < array_params) {
- LLVMAddAttribute(P, LLVMByValAttribute);
+ ac_add_function_attr(P, i + 1, AC_FUNC_ATTR_BYVAL);
ac_add_attr_dereferenceable(P, UINT64_MAX);
}
- else
- LLVMAddAttribute(P, LLVMInRegAttribute);
+ else {
+ ac_add_function_attr(P, i + 1, AC_FUNC_ATTR_INREG);
+ }
}
if (unsafe_math) {
LLVMValueRef params[] = {
to_float(ctx, src0),
};
- return emit_llvm_intrinsic(ctx, intrin, ctx->f32, params, 1, LLVMReadNoneAttribute);
+ return emit_llvm_intrinsic(ctx, intrin, ctx->f32, params, 1, AC_FUNC_ATTR_READNONE);
}
static LLVMValueRef emit_intrin_2f_param(struct nir_to_llvm_context *ctx,
to_float(ctx, src0),
to_float(ctx, src1),
};
- return emit_llvm_intrinsic(ctx, intrin, ctx->f32, params, 2, LLVMReadNoneAttribute);
+ return emit_llvm_intrinsic(ctx, intrin, ctx->f32, params, 2, AC_FUNC_ATTR_READNONE);
}
static LLVMValueRef emit_intrin_3f_param(struct nir_to_llvm_context *ctx,
to_float(ctx, src1),
to_float(ctx, src2),
};
- return emit_llvm_intrinsic(ctx, intrin, ctx->f32, params, 3, LLVMReadNoneAttribute);
+ return emit_llvm_intrinsic(ctx, intrin, ctx->f32, params, 3, AC_FUNC_ATTR_READNONE);
}
static LLVMValueRef emit_bcsel(struct nir_to_llvm_context *ctx,
*/
LLVMConstInt(ctx->i32, 1, false),
};
- return emit_llvm_intrinsic(ctx, "llvm.cttz.i32", ctx->i32, params, 2, LLVMReadNoneAttribute);
+ return emit_llvm_intrinsic(ctx, "llvm.cttz.i32", ctx->i32, params, 2, AC_FUNC_ATTR_READNONE);
}
static LLVMValueRef emit_ifind_msb(struct nir_to_llvm_context *ctx,
{
LLVMValueRef msb = emit_llvm_intrinsic(ctx, "llvm.AMDGPU.flbit.i32",
ctx->i32, &src0, 1,
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
/* The HW returns the last bit index from MSB, but NIR wants
* the index from LSB. Invert it by doing "31 - msb". */
};
LLVMValueRef msb = emit_llvm_intrinsic(ctx, "llvm.ctlz.i32",
ctx->i32, args, ARRAY_SIZE(args),
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
/* The HW returns the last bit index from MSB, but NIR wants
* the index from LSB. Invert it by doing "31 - msb". */
};
LLVMValueRef floor = emit_llvm_intrinsic(ctx, intr,
ctx->f32, params, 1,
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
return LLVMBuildFSub(ctx->builder, fsrc0, floor, "");
}
2, true);
res = emit_llvm_intrinsic(ctx, intrin, ret_type,
- params, 2, LLVMReadNoneAttribute);
+ params, 2, AC_FUNC_ATTR_READNONE);
res = LLVMBuildExtractValue(ctx->builder, res, 1, "");
res = LLVMBuildZExt(ctx->builder, res, ctx->i32, "");
{
LLVMValueRef result;
LLVMValueRef icond = LLVMBuildICmp(ctx->builder, LLVMIntEQ, srcs[2], LLVMConstInt(ctx->i32, 32, false), "");
- result = emit_llvm_intrinsic(ctx, intrin, ctx->i32, srcs, 3, LLVMReadNoneAttribute);
+ result = emit_llvm_intrinsic(ctx, intrin, ctx->i32, srcs, 3, AC_FUNC_ATTR_READNONE);
result = LLVMBuildSelect(ctx->builder, icond, srcs[0], result, "");
return result;
tid_args[1] = ctx->i32zero;
tid_args[1] = emit_llvm_intrinsic(ctx,
"llvm.amdgcn.mbcnt.lo", ctx->i32,
- tid_args, 2, LLVMReadNoneAttribute);
+ tid_args, 2, AC_FUNC_ATTR_READNONE);
tid = emit_llvm_intrinsic(ctx,
"llvm.amdgcn.mbcnt.hi", ctx->i32,
- tid_args, 2, LLVMReadNoneAttribute);
+ tid_args, 2, AC_FUNC_ATTR_READNONE);
set_range_metadata(ctx, tid, 0, 64);
return tid;
}
args[1] = src0;
tl = emit_llvm_intrinsic(ctx, "llvm.amdgcn.ds.bpermute",
ctx->i32, args, 2,
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
args[0] = LLVMBuildMul(ctx->builder, trbl_tid,
LLVMConstInt(ctx->i32, 4, false), "");
trbl = emit_llvm_intrinsic(ctx, "llvm.amdgcn.ds.bpermute",
ctx->i32, args, 2,
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
} else {
LLVMBuildStore(ctx->builder, src0, store_ptr);
result = emit_bitfield_insert(ctx, src[0], src[1], src[2], src[3]);
break;
case nir_op_bitfield_reverse:
- result = emit_llvm_intrinsic(ctx, "llvm.bitreverse.i32", ctx->i32, src, 1, LLVMReadNoneAttribute);
+ result = emit_llvm_intrinsic(ctx, "llvm.bitreverse.i32", ctx->i32, src, 1, AC_FUNC_ATTR_READNONE);
break;
case nir_op_bit_count:
- result = emit_llvm_intrinsic(ctx, "llvm.ctpop.i32", ctx->i32, src, 1, LLVMReadNoneAttribute);
+ result = emit_llvm_intrinsic(ctx, "llvm.ctpop.i32", ctx->i32, src, 1, AC_FUNC_ATTR_READNONE);
break;
case nir_op_vec2:
case nir_op_vec3:
static LLVMValueRef
emit_llvm_intrinsic(struct nir_to_llvm_context *ctx, const char *name,
LLVMTypeRef return_type, LLVMValueRef *params,
- unsigned param_count, LLVMAttribute attribs)
+ unsigned param_count, unsigned attrib_mask)
{
LLVMValueRef function;
LLVMSetFunctionCallConv(function, LLVMCCallConv);
LLVMSetLinkage(function, LLVMExternalLinkage);
- LLVMAddFunctionAttr(function, attribs | LLVMNoUnwindAttribute);
+ ac_add_function_attr(function, 0, attrib_mask | AC_FUNC_ATTR_NOUNWIND);
}
return LLVMBuildCall(ctx->builder, function, params, param_count, "");
}
txq_args[txq_arg_count++] = LLVMConstInt(ctx->i32, 0, 0); /* lwe */
size = emit_llvm_intrinsic(ctx, "llvm.SI.getresinfo.i32", ctx->v4i32,
txq_args, txq_arg_count,
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
for (c = 0; c < 2; c++) {
half_texel[c] = LLVMBuildExtractElement(ctx->builder, size,
tinfo->args[0] = coord;
return emit_llvm_intrinsic(ctx, intr_name, tinfo->dst_type, tinfo->args, tinfo->arg_count,
- LLVMReadNoneAttribute | LLVMNoUnwindAttribute);
+ AC_FUNC_ATTR_READNONE | AC_FUNC_ATTR_NOUNWIND);
}
}
}
return emit_llvm_intrinsic(ctx, intr_name, tinfo->dst_type, tinfo->args, tinfo->arg_count,
- LLVMReadNoneAttribute | LLVMNoUnwindAttribute);
+ AC_FUNC_ATTR_READNONE | AC_FUNC_ATTR_NOUNWIND);
}
intrinsic_name, sizeof(intrinsic_name));
res = emit_llvm_intrinsic(ctx, intrinsic_name, ctx->v4f32,
- params, 7, LLVMReadOnlyAttribute);
+ params, 7, AC_FUNC_ATTR_READONLY);
}
return to_integer(ctx, res);
}
params[9] = ctx->i32zero;
res = emit_llvm_intrinsic(ctx, "llvm.SI.getresinfo.i32", ctx->v4i32,
- params, 10, LLVMReadNoneAttribute);
+ params, 10, AC_FUNC_ATTR_READNONE);
if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_CUBE &&
glsl_sampler_type_is_array(type)) {
args[3] = interp_param;
result[chan] = emit_llvm_intrinsic(ctx, intr_name,
ctx->f32, args, args[3] ? 4 : 3,
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
}
return build_gather_values(ctx, result, 2);
}
LLVMValueRef out[4];
out[0] = emit_llvm_intrinsic(ctx, "llvm.amdgcn.cubetc",
- f32, in, 3, LLVMReadNoneAttribute);
+ f32, in, 3, AC_FUNC_ATTR_READNONE);
out[1] = emit_llvm_intrinsic(ctx, "llvm.amdgcn.cubesc",
- f32, in, 3, LLVMReadNoneAttribute);
+ f32, in, 3, AC_FUNC_ATTR_READNONE);
out[2] = emit_llvm_intrinsic(ctx, "llvm.amdgcn.cubema",
- f32, in, 3, LLVMReadNoneAttribute);
+ f32, in, 3, AC_FUNC_ATTR_READNONE);
out[3] = emit_llvm_intrinsic(ctx, "llvm.amdgcn.cubeid",
- f32, in, 3, LLVMReadNoneAttribute);
+ f32, in, 3, AC_FUNC_ATTR_READNONE);
return build_gather_values(ctx, out, 4);
} else {
c[3] = LLVMGetUndef(LLVMTypeOf(in[0]));
cube_vec = build_gather_values(ctx, c, 4);
v = emit_llvm_intrinsic(ctx, "llvm.AMDGPU.cube", LLVMTypeOf(cube_vec),
- &cube_vec, 1, LLVMReadNoneAttribute);
+ &cube_vec, 1, AC_FUNC_ATTR_READNONE);
}
return v;
}
LLVMConstInt(ctx->i32, i, false), "");
coords[2] = emit_llvm_intrinsic(ctx, "llvm.fabs.f32", ctx->f32,
- &coords[2], 1, LLVMReadNoneAttribute);
+ &coords[2], 1, AC_FUNC_ATTR_READNONE);
coords[2] = emit_fdiv(ctx, ctx->f32one, coords[2]);
mad_args[1] = coords[2];
args[2] = buffer_index;
input = emit_llvm_intrinsic(ctx,
"llvm.SI.vs.load.input", ctx->v4f32, args, 3,
- LLVMReadNoneAttribute | LLVMNoUnwindAttribute);
+ AC_FUNC_ATTR_READNONE | AC_FUNC_ATTR_NOUNWIND);
for (unsigned chan = 0; chan < 4; chan++) {
LLVMValueRef llvm_chan = LLVMConstInt(ctx->i32, chan, false);
args[3] = interp_param;
result[chan] = emit_llvm_intrinsic(ctx, intr_name,
ctx->f32, args, args[3] ? 4 : 3,
- LLVMReadNoneAttribute | LLVMNoUnwindAttribute);
+ AC_FUNC_ATTR_READNONE | AC_FUNC_ATTR_NOUNWIND);
}
}
packed = emit_llvm_intrinsic(ctx, "llvm.SI.packf16",
ctx->i32, pack_args, 2,
- LLVMReadNoneAttribute);
+ AC_FUNC_ATTR_READNONE);
args[chan + 5] = packed;
}
break;