Skip to content

Commit f7b60c1

Browse files
committed
Metadata changes to support LLVM 7.0
1 parent 4abf6bf commit f7b60c1

File tree

5 files changed

+73
-13
lines changed

5 files changed

+73
-13
lines changed

tools/flang2/flang2exe/ll_structure.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,15 @@ compute_ir_feature_vector(LLVMModuleRef module, enum LL_IRVersion vers)
399399
module->ir.is_spir = 1;
400400

401401
module->ir.version = vers;
402+
InitializeDIFlags(&module->ir);
402403
if (XBIT(120, 0x200)) {
403404
module->ir.dwarf_version = LL_DWARF_Version_2;
404405
} else if (XBIT(120, 0x4000)) {
405406
module->ir.dwarf_version = LL_DWARF_Version_3;
406-
} else {
407+
} else if (true) { // FIXME - need a new bit
407408
module->ir.dwarf_version = LL_DWARF_Version_4;
409+
} else {
410+
module->ir.dwarf_version = LL_DWARF_Version_5;
408411
}
409412

410413
if (ll_feature_versioned_dw_tag(&module->ir)) {

tools/flang2/flang2exe/ll_structure.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ typedef enum LL_IRVersion {
142142
LL_Version_4_0 = 40,
143143
LL_Version_5_0 = 50,
144144
LL_Version_6_0 = 60,
145+
LL_Version_7_0 = 70,
145146
LL_Version_trunk = 1023
146147
} LL_IRVersion;
147148

@@ -150,7 +151,8 @@ LL_IRVersion get_llvm_version(void);
150151
typedef enum LL_DWARFVersion {
151152
LL_DWARF_Version_2,
152153
LL_DWARF_Version_3,
153-
LL_DWARF_Version_4
154+
LL_DWARF_Version_4,
155+
LL_DWARF_Version_5
154156
} LL_DWARFVersion;
155157

156158
/* If flang is built with LLVM from github:flang-compiler/llvm, then one can
@@ -353,6 +355,15 @@ ll_feature_debug_info_ver38(const LL_IRFeatures *feature)
353355
return feature->version >= LL_Version_3_8;
354356
}
355357

358+
/**
359+
\brief Version 7.0 debug metadata
360+
*/
361+
INLINE static bool
362+
ll_feature_debug_info_ver70(const LL_IRFeatures *feature)
363+
{
364+
return feature->version >= LL_Version_7_0;
365+
}
366+
356367
INLINE static bool
357368
ll_feature_use_distinct_metadata(const LL_IRFeatures *feature)
358369
{
@@ -439,6 +450,7 @@ ll_feature_no_file_in_namespace(const LL_IRFeatures *feature)
439450
#define ll_feature_debug_info_subrange_needs_count(f) \
440451
((f)->version >= LL_Version_3_7)
441452
#define ll_feature_debug_info_ver38(f) ((f)->version >= LL_Version_3_8)
453+
#define ll_feature_debug_info_ver70(f) ((f)->version >= LL_Version_7_0)
442454
#define ll_feature_use_distinct_metadata(f) ((f)->version >= LL_Version_3_8)
443455
#define ll_feature_subprogram_not_in_cu(f) ((f)->version >= LL_Version_3_9)
444456
#define ll_feature_from_global_to_md(f) ((f)->version >= LL_Version_4_0)

tools/flang2/flang2exe/ll_write.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,28 @@ static const MDTemplate Tmpl_DISubprogram[] = {
918918
{"variables", NodeField},
919919
{"scopeLine", UnsignedField}};
920920

921+
static const MDTemplate Tmpl_DISubprogram_70[] = {
922+
{"DISubprogram", TF, 19},
923+
{"tag", DWTagField, FlgHidden},
924+
{"file", NodeField},
925+
{"scope", NodeField},
926+
{"name", StringField},
927+
{"displayName", StringField, FlgHidden},
928+
{"linkageName", StringField},
929+
{"line", UnsignedField},
930+
{"type", NodeField},
931+
{"isLocal", BoolField},
932+
{"isDefinition", BoolField},
933+
{"virtuality", DWVirtualityField},
934+
{"virtualIndex", UnsignedField},
935+
{"containingType", NodeField},
936+
{"flags", UnsignedField}, /* TBD: DIFlag... */
937+
{"isOptimized", BoolField},
938+
{"function", ValueField},
939+
{"templateParams", NodeField},
940+
{"declaration", NodeField},
941+
{"scopeLine", UnsignedField}};
942+
921943
static const MDTemplate Tmpl_DISubprogram_38[] = {
922944
{"DISubprogram", TF, 20},
923945
{"tag", DWTagField, FlgHidden},
@@ -1766,6 +1788,11 @@ emitDISubprogram(FILE *out, LLVMModuleRef mod, const LL_MDNode *mdnode,
17661788
emitTmpl(out, mod, mdnode, mdi, Tmpl_DISubprogram_38);
17671789
return;
17681790
}
1791+
if (ll_feature_debug_info_ver70(&mod->ir)) {
1792+
// 7.0, 'variables:' was removed
1793+
emitTmpl(out, mod, mdnode, mdi, Tmpl_DISubprogram_70);
1794+
return;
1795+
}
17691796
emitTmpl(out, mod, mdnode, mdi, Tmpl_DISubprogram);
17701797
return;
17711798
}

tools/flang2/flang2exe/lldebug.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@
6565

6666
const int DIFLAG_ARTIFICIAL = 1 << 6;
6767
const int DIFLAG_ISMAINPGM = 1 << 21;
68-
#if defined(FLANG_LLVM_EXTENSIONS)
69-
const int DIFLAG_PURE = 1 << 22;
70-
const int DIFLAG_ELEMENTAL = 1 << 23;
71-
const int DIFLAG_RECUSIVE = 1 << 24;
72-
#else
73-
const int DIFLAG_PURE = 0;
74-
const int DIFLAG_ELEMENTAL = 0;
75-
const int DIFLAG_RECUSIVE = 0;
76-
#endif
68+
static int DIFLAG_PURE;
69+
static int DIFLAG_ELEMENTAL;
70+
static int DIFLAG_RECUSIVE;
7771

7872
typedef struct {
7973
LL_MDRef mdnode; /**< mdnode for block */
@@ -154,6 +148,24 @@ static LL_MDRef lldbg_emit_type(
154148

155149
/* ---------------------------------------------------------------------- */
156150

151+
void
152+
InitializeDIFlags(const LL_IRFeatures* feature)
153+
{
154+
#ifdef FLANG_LLVM_EXTENSIONS
155+
if (ll_feature_debug_info_ver70(feature)) {
156+
DIFLAG_PURE = 1 << 27;
157+
DIFLAG_ELEMENTAL = 1 << 28;
158+
DIFLAG_RECUSIVE = 1 << 29;
159+
} else {
160+
DIFLAG_PURE = 1 << 22;
161+
DIFLAG_ELEMENTAL = 1 << 23;
162+
DIFLAG_RECUSIVE = 1 << 24;
163+
}
164+
#else
165+
// do nothing
166+
#endif
167+
}
168+
157169
char *
158170
lldbg_alloc(INT size)
159171
{
@@ -424,7 +436,9 @@ lldbg_create_subprogram_mdnode(
424436
llmd_add_md(mdb, db->comp_unit_mdnode);
425437

426438
/* Add extra layer of indirection before 3.4. */
427-
if (ll_feature_debug_info_pre34(&db->module->ir)) {
439+
if (ll_feature_debug_info_ver70(&db->module->ir)) {
440+
llmd_add_null(mdb);
441+
} else if (ll_feature_debug_info_pre34(&db->module->ir)) {
428442
llmd_add_md(mdb,
429443
ll_get_md_node(db->module, LL_PlainMDNode, &lv_list_mdnode, 1));
430444
} else {
@@ -2735,7 +2749,7 @@ lldbg_emit_local_variable(LL_DebugInfo *db, SPTR sptr, int findex,
27352749
} else
27362750
#endif
27372751
{
2738-
symname = (char *)lldbg_alloc(sizeof(char) * (strlen(SYMNAME(sptr)) + 1));
2752+
symname = (char *)lldbg_alloc(strlen(SYMNAME(sptr)) + 1);
27392753
strcpy(symname, SYMNAME(sptr));
27402754
}
27412755
if (SCG(sptr) == SC_DUMMY && !emit_dummy_as_local) {

tools/flang2/flang2exe/lldebug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,8 @@ void lldbg_emit_imported_entity(LL_DebugInfo *db, int entity_sptr,
253253
*/
254254
void lldbg_create_cmblk_mem_mdnode_list(int sptr, int gblsym);
255255

256+
/// \brief Initialize the DIFLAG values
257+
/// The values may vary depending on the LLVM branch being used
258+
void InitializeDIFlags(const LL_IRFeatures* feature);
259+
256260
#endif /* LLDEBUG_H_ */

0 commit comments

Comments
 (0)