Skip to content

Commit

Permalink
recursive conversion to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Mar 14, 2019
1 parent 4e2c90c commit bdc0f6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
25 changes: 25 additions & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,31 @@ static Value *stringConstPtr(IRBuilder<> &irbuilder, const std::string &txt)
}
}

// --- MDNode ---
Metadata *to_md_tree(jl_value_t *val) {
if (val == jl_nothing)
return NULL;
Metadata *MD;
if (jl_is_symbol(val)) {
MD = MDString::get(jl_LLVMContext, jl_symbol_name((jl_sym_t*)val));
} else if jl_is_bool(val) {
MD = ConstantAsMetadata::get(ConstantInt::get(T_int1, jl_unbox_bool(val)));
} else if jl_is_long(val) {
MD = ConstantAsMetadata::get(ConstantInt::get(T_int64, jl_unbox_long(val)));
} else if jl_is_tuple(val) {
SmallVector<Metadata *, 8> MDs;
for (int f = 0, nf = jl_nfields(val); f < nf; ++f) {
MD = to_md_tree(jl_fieldref(val, f));
if (MD)
MDs.push_back(MD);
}
MD = MDNode::get(jl_LLVMContext, MDs);
} else {
jl_error("LLVM metadata needs to Symbol/Bool/Int or Tuple thereof");
}
return MD;
}

// --- Debug info ---

static DIType *julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed = false)
Expand Down
27 changes: 1 addition & 26 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4100,34 +4100,9 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval)
// parse Expr(:loopinfo, "julia.simdloop", ("llvm.loop.vectorize.width", 4))
SmallVector<Metadata *, 8> MDs;
for (int i = 0, ie = jl_expr_nargs(ex); i < ie; ++i) {
jl_value_t *arg = args[i];
Metadata *MD;
if (arg == jl_nothing)
continue;
if (jl_is_symbol(arg)) {
MD = MDString::get(jl_LLVMContext, jl_symbol_name((jl_sym_t*)arg));
} else if (jl_is_tuple(arg)) {
// TODO: are there loopinfo with more than one field?
if (jl_nfields(arg) != 2)
jl_error("loopinfo: only accept 2-arg tuple");
jl_value_t* name = jl_fieldref(arg, 0);
jl_value_t* value = jl_fieldref(arg, 1);
if (!jl_is_symbol(name))
jl_error("loopinfo: name needs to be a symbol");
Metadata *MDVal;
if(jl_is_bool(value))
MDVal = ConstantAsMetadata::get(ConstantInt::get(T_int1, jl_unbox_bool(value)));
if(jl_is_long(value))
MDVal = ConstantAsMetadata::get(ConstantInt::get(T_int64, jl_unbox_long(value)));
if(!MDVal)
jl_error("loopinfo: value can only be a bool or a long");
MD = MDNode::get(jl_LLVMContext,
{ MDString::get(jl_LLVMContext, jl_symbol_name((jl_sym_t*)name)), MDVal });
}
Metadata *MD = to_md_tree(args[i]);
if (MD)
MDs.push_back(MD);
else
jl_error("loopinfo: argument needs to be either a symbol or a tuple of type (Symbol, Union{Int, Bool}");
}

MDNode* MD = MDNode::get(jl_LLVMContext, MDs);
Expand Down

0 comments on commit bdc0f6b

Please sign in to comment.