Skip to content

Commit 723f139

Browse files
authored
Merge pull request #133 from ThePortlandGroup/nv_stage
Pull 2017-07-11T08-14 Recent NVIDIA Changes
2 parents b7c6ef9 + 28c33f8 commit 723f139

File tree

9 files changed

+178
-41
lines changed

9 files changed

+178
-41
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Building LLVM requires fairly modern compiler toolchain and CMake, check [Gettin
1313
- openmp-llvm
1414
- modified clang
1515

16-
The latest LLVM version we support is 3.9
16+
The latest supported LLVM version is 4.0. Flang also supports LLVM version 3.9. To use 3.9, substitute 39 for 40 in the build instructions.
1717

1818
## Building
1919

@@ -34,7 +34,7 @@ Flang is developed outside of the llvm source tree.
3434
cd where/you/want/to/build
3535
git clone https://github.com/llvm-mirror/llvm.git
3636
cd llvm
37-
git checkout release_39
37+
git checkout release_40
3838
mkdir build && cd build
3939
cmake ..
4040
make
@@ -46,7 +46,7 @@ Flang is developed outside of the llvm source tree.
4646
cd where/you/want/to/build
4747
git clone https://github.com/flang-compiler/clang.git
4848
cd clang
49-
git checkout flang_release_39
49+
git checkout flang_release_40
5050
mkdir build && cd build
5151
cmake ..
5252
make
@@ -58,7 +58,7 @@ Flang is developed outside of the llvm source tree.
5858
cd where/you/want/to/build
5959
git clone https://github.com/llvm-mirror/openmp.git
6060
cd openmp/runtime
61-
git checkout release_39
61+
git checkout release_40
6262
mkdir build && cd build
6363
cmake ..
6464
make

tools/flang1/flang1exe/semant.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ struct _aexpr {
616616
#define AC_I_atan2 42
617617
#define AC_I_selected_char_kind 43
618618
#define AC_I_abs 44
619+
#define AC_I_iand 45
620+
#define AC_I_ior 46
621+
#define AC_I_ieor 47
619622

620623
#define BINOP(p) ((p)->op != AC_NEG && (p)->op != AC_CONV)
621624

tools/flang1/flang1exe/semutil2.c

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,15 @@ get_ac_intrinsic(int ast)
38293829
case I_DATAN2:
38303830
intrin = AC_I_atan2;
38313831
break;
3832+
case I_IAND:
3833+
intrin = AC_I_iand;
3834+
break;
3835+
case I_IOR:
3836+
intrin = AC_I_ior;
3837+
break;
3838+
case I_IEOR:
3839+
intrin = AC_I_ieor;
3840+
break;
38323841
}
38333842
break;
38343843
default:;
@@ -3873,6 +3882,9 @@ construct_intrinsic_acl(int ast, int dtype, int parent_acltype)
38733882
case AC_I_atan:
38743883
case AC_I_atan2:
38753884
case AC_I_abs:
3885+
case AC_I_iand:
3886+
case AC_I_ior:
3887+
case AC_I_ieor:
38763888
aclp = mk_elem_init_intrinsic(intrin, ast, dtype, parent_acltype);
38773889
break;
38783890
case AC_I_len:
@@ -8315,6 +8327,41 @@ eval_ishft(ACL *arg, int dtype)
83158327
return rslt;
83168328
}
83178329

8330+
#define INTINTRIN2(iname, ent, op) \
8331+
static ACL *ent(ACL *arg, DTYPE dtype) \
8332+
{ \
8333+
ACL *arg1 = eval_init_expr_item(arg); \
8334+
ACL *arg2 = eval_init_expr_item(arg->next); \
8335+
ACL *rslt = clone_init_const(arg1, TRUE); \
8336+
arg1 = rslt->id == AC_ACONST ? rslt->subc : rslt; \
8337+
arg2 = arg2->id == AC_ACONST ? arg2->subc : arg2; \
8338+
for (; arg1; arg1 = arg1->next, arg2 = arg2->next) { \
8339+
int con1 = arg1->conval; \
8340+
int con2 = arg2->conval; \
8341+
int num1[2], num2[2], res[2], conval; \
8342+
if (DT_ISWORD(arg1->dtype)) { \
8343+
num1[0] = 0, num1[1] = con1; \
8344+
} else { \
8345+
num1[0] = CONVAL1G(con1), num1[1] = CONVAL2G(con1); \
8346+
} \
8347+
if (DT_ISWORD(arg2->dtype)) { \
8348+
num2[0] = 0, num2[1] = con2; \
8349+
} else { \
8350+
num2[0] = CONVAL1G(con2), num2[1] = CONVAL2G(con2); \
8351+
} \
8352+
res[0] = num1[0] op num2[0]; \
8353+
res[1] = num1[1] op num2[1]; \
8354+
conval = DT_ISWORD(dtype) ? res[1] : getcon(res, DT_INT8); \
8355+
arg1->conval = conval; \
8356+
arg1->dtype = dtype; \
8357+
} \
8358+
return rslt; \
8359+
}
8360+
8361+
INTINTRIN2("iand", eval_iand, &)
8362+
INTINTRIN2("ior", eval_ior, |)
8363+
INTINTRIN2("ieor", eval_ieor, ^)
8364+
83188365
static ACL *
83198366
eval_ichar(ACL *arg, int dtype)
83208367
{
@@ -10387,9 +10434,18 @@ eval_init_op(int op, ACL *lop, int ldtype, ACL *rop, int rdtype, int sptr,
1038710434
case AC_I_abs:
1038810435
root = eval_abs(rop, dtype);
1038910436
break;
10437+
case AC_I_iand:
10438+
root = eval_iand(rop, dtype);
10439+
break;
10440+
case AC_I_ior:
10441+
root = eval_ior(rop, dtype);
10442+
break;
10443+
case AC_I_ieor:
10444+
root = eval_ieor(rop, dtype);
10445+
break;
1039010446
default:
10391-
interr("eval_init_op: intrinsic not supported in initialiation",
10392-
lop->u1.i, 3);
10447+
interr("eval_init_op(semutil2.c): intrinsic not supported in "
10448+
"initialization", lop->u1.i, 3);
1039310449
/* Try to avoid a seg fault by returning something reasonable */
1039410450
root = GET_ACL(15);
1039510451
root->id = AC_CONST;
@@ -13511,4 +13567,3 @@ gen_set_type(int dest_ast, int src_ast, int std, LOGICAL insert_before,
1351113567

1351213568
return std;
1351313569
}
13514-

tools/flang2/docs/xflag.n

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4715,6 +4715,8 @@ Allow new fast math power vector routines when real base elements are different
47154715
size from integer power elements
47164716
.XB 0x2000000:
47174717
Switch definition of "long double" on Power from "double double" to __float128
4718+
.XB 0x4000000:
4719+
Disable generation of !llvm.loop metadata
47184720

47194721
.XF "184:"
47204722
ARM modifications

tools/flang2/flang2exe/cgmain.c

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,25 @@ assign_fortran_storage_classes(void)
769769
}
770770
} /* end assign_fortran_storage_classes() */
771771

772+
INLINE static LL_MDRef
773+
cons_loop_metadata(void)
774+
{
775+
LL_MDRef lvcomp[2];
776+
LL_MDRef loopVect;
777+
LL_MDRef rv;
778+
779+
if (cpu_llvm_module->loop_md)
780+
return cpu_llvm_module->loop_md;
781+
rv = ll_create_flexible_md_node(cpu_llvm_module);
782+
lvcomp[0] = ll_get_md_string(cpu_llvm_module, "llvm.loop.vectorize.enable");
783+
lvcomp[1] = ll_get_md_i1(0);
784+
loopVect = ll_get_md_node(cpu_llvm_module, LL_PlainMDNode, lvcomp, 2);
785+
ll_extend_md_node(cpu_llvm_module, rv, rv);
786+
ll_extend_md_node(cpu_llvm_module, rv, loopVect);
787+
cpu_llvm_module->loop_md = rv;
788+
return rv;
789+
}
790+
772791
/**
773792
\brief Perform code translation from ILI to LLVM for one routine
774793
*/
@@ -965,19 +984,23 @@ schedule(void)
965984
continue;
966985
}
967986

968-
if (ILT_BR(ilt)) /* branch */
969-
{
970-
int next_bih_label;
987+
if (ILT_BR(ilt)) { /* branch */
988+
int next_bih_label = 0;
971989

972-
if (!ILT_NEXT(ilt) && bihnext &&
973-
((next_bih_label = BIH_LABEL(bihnext)) &&
974-
(DEFDG(next_bih_label) || CCSYMG(next_bih_label))))
975-
make_stmt(STMT_BR, ilix, FALSE, next_bih_label, ilt);
976-
else
977-
make_stmt(STMT_BR, ilix, FALSE, 0, ilt);
990+
if (!ILT_NEXT(ilt) && bihnext) {
991+
const int t_next_bih_label = BIH_LABEL(bihnext);
992+
if (t_next_bih_label &&
993+
(DEFDG(t_next_bih_label) || CCSYMG(t_next_bih_label)))
994+
next_bih_label = t_next_bih_label;
995+
}
996+
make_stmt(STMT_BR, ilix, FALSE, next_bih_label, ilt);
997+
if ((!XBIT(183, 0x4000000)) && BIH_SIMD(bih)) {
998+
LL_MDRef loop_md = cons_loop_metadata();
999+
llvm_info.last_instr->flags |= SIMD_BACKEDGE_FLAG;
1000+
llvm_info.last_instr->ll_type = (LL_Type*)(unsigned long)loop_md;
1001+
}
9781002
} else if ((ILT_ST(ilt) || ILT_DELETE(ilt)) &&
979-
IL_TYPE(opc) == ILTY_STORE) /* store */
980-
{
1003+
IL_TYPE(opc) == ILTY_STORE) { /* store */
9811004
rhs_ili = ILI_OPND(ilix, 1);
9821005
lhs_ili = ILI_OPND(ilix, 2);
9831006
nme = ILI_OPND(ilix, 3);
@@ -1009,7 +1032,8 @@ schedule(void)
10091032
ilix = ILI_OPND(ilix, 1);
10101033
opc = ILI_OPC(ilix);
10111034
break;
1012-
default:;
1035+
default:
1036+
break;
10131037
}
10141038
if (is_mvili_opcode(opc)) /* call part of the return */
10151039
goto return_with_call;
@@ -2213,8 +2237,7 @@ write_instructions(LL_Module *module)
22132237
print_token(llvm_instr_names[I_RESUME]);
22142238
write_verbose_type(cc->ll_type);
22152239
write_operand(cc, " ", FLG_OMIT_OP_TYPE);
2216-
break;
2217-
}
2240+
} break;
22182241
case I_CLEANUP:
22192242
print_token("\t");
22202243
print_token(llvm_instr_names[I_CLEANUP]);
@@ -2248,8 +2271,7 @@ write_instructions(LL_Module *module)
22482271
write_operand(cc, " ", FLG_OMIT_OP_TYPE);
22492272
print_token(" to i8*)");
22502273
}
2251-
break;
2252-
}
2274+
} break;
22532275
case I_FILTER: {
22542276
/* "filter <array-type> [ <array-of-typeinfo-vars> ]"
22552277
Each operand is a typeinfo variable for a type in the exception
@@ -2397,6 +2419,12 @@ write_instructions(LL_Module *module)
23972419
print_token(llvm_instr_names[i_name]);
23982420
print_space(1);
23992421
write_operands(instrs->operands, 0);
2422+
if (instrs->flags & SIMD_BACKEDGE_FLAG) {
2423+
char buf[32];
2424+
LL_MDRef loop_md = (LL_MDRef)(unsigned long)instrs->ll_type;
2425+
snprintf(buf, 32, ", !llvm.loop !%u", LL_MDREF_value(loop_md));
2426+
print_token(buf);
2427+
}
24002428
}
24012429
break;
24022430
case I_INDBR:
@@ -2796,7 +2824,7 @@ ad_instr(int ilix, INSTR_LIST *instr)
27962824
instr->prev = llvm_info.last_instr;
27972825
} else {
27982826
assert(!llvm_info.last_instr, "ad_instr(): last instruction not NULL", 0,
2799-
4);
2827+
ERR_Fatal);
28002828
Instructions = instr;
28012829
}
28022830
llvm_info.last_instr = instr;
@@ -2965,20 +2993,15 @@ make_stmt(STMT_Type stmt_type, int ilix, LOGICAL deletable, int next_bih_label,
29652993

29662994
case STMT_BR:
29672995
opc = ILI_OPC(ilix);
2968-
if (opc == IL_JMP) /* unconditional jump */
2969-
{
2996+
if (opc == IL_JMP) { /* unconditional jump */
29702997
last_stmt_is_branch = 1;
29712998
sptr = ILI_OPND(ilix, 1);
2972-
{
2973-
/* also in gen_new_landingpad_jump */
2974-
process_sptr(sptr);
2975-
Curr_Instr = gen_instr(I_BR, NULL, NULL, make_target_op(sptr));
2976-
ad_instr(ilix, Curr_Instr);
2977-
}
2978-
} else if (exprjump(opc) || zerojump(opc)) /* cond or zero jump */
2979-
{
2980-
if (exprjump(opc)) /* get sptr pointing to jump label */
2981-
{
2999+
/* also in gen_new_landingpad_jump */
3000+
process_sptr(sptr);
3001+
Curr_Instr = gen_instr(I_BR, NULL, NULL, make_target_op(sptr));
3002+
ad_instr(ilix, Curr_Instr);
3003+
} else if (exprjump(opc) || zerojump(opc)) { /* cond or zero jump */
3004+
if (exprjump(opc)) { /* get sptr pointing to jump label */
29823005
sptr = ILI_OPND(ilix, 4);
29833006
cc = ILI_OPND(ilix, 3);
29843007
} else {
@@ -3811,7 +3834,8 @@ gen_unary_expr(int ilix, int itype)
38113834
case IL_DFLOATK:
38123835
opc_type = make_lltype_from_dtype(DT_INT8);
38133836
break;
3814-
default:;
3837+
default:
3838+
break;
38153839
}
38163840

38173841
DBGTRACE2("#generating unary operand, op_ili: %d(%s)", op_ili,
@@ -3993,7 +4017,8 @@ gen_minmax_expr(int ilix, OPERAND *op1, OPERAND *op2)
39934017
break;
39944018
}
39954019
break;
3996-
default:; /*TODO: can this happen? */
4020+
default:
4021+
break; /*TODO: can this happen? */
39974022
}
39984023
cmp_op = make_tmp_op(bool_type, make_tmps());
39994024

@@ -4894,7 +4919,8 @@ gen_binary_expr(int ilix, int itype)
48944919
case IL_KNEG:
48954920
flags |= NOSIGNEDWRAP;
48964921
break;
4897-
default:;
4922+
default:
4923+
break;
48984924
}
48994925
/* account for the *NEG ili - LLVM treats all of these as subtractions
49004926
* from zero.

tools/flang2/flang2exe/dinit.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,43 @@ eval_ishft(CONST *arg, int dtype)
22632263
return rslt;
22642264
}
22652265

2266+
#define INTINTRIN2(iname, ent, op) \
2267+
static CONST *ent(CONST *arg, DTYPE dtype) \
2268+
{ \
2269+
CONST *arg1 = eval_init_expr_item(arg); \
2270+
CONST *arg2 = eval_init_expr_item(arg->next); \
2271+
CONST *rslt = clone_init_const_list(arg1, TRUE); \
2272+
arg1 = rslt->id == AC_ACONST ? rslt->subc : rslt; \
2273+
arg2 = arg2->id == AC_ACONST ? arg2->subc : arg2; \
2274+
for (; arg1; arg1 = arg1->next, arg2 = arg2->next) { \
2275+
int con1 = arg1->u1.conval; \
2276+
int con2 = arg2->u1.conval; \
2277+
int num1[2], num2[2], res[2], conval; \
2278+
if (DT_ISWORD(arg1->dtype)) { \
2279+
num1[0] = 0, num1[1] = con1; \
2280+
} else { \
2281+
num1[0] = CONVAL1G(con1), num1[1] = CONVAL2G(con1); \
2282+
} \
2283+
if (DT_ISWORD(arg2->dtype)) { \
2284+
num2[0] = 0, num2[1] = con2; \
2285+
} else { \
2286+
num2[0] = CONVAL1G(con2), num2[1] = CONVAL2G(con2); \
2287+
} \
2288+
res[0] = num1[0] op num2[0]; \
2289+
res[1] = num1[1] op num2[1]; \
2290+
conval = DT_ISWORD(dtype) ? res[1] : getcon(res, DT_INT8); \
2291+
arg1->u1.conval = conval; \
2292+
arg1->dtype = dtype; \
2293+
arg1->id = AC_CONST; \
2294+
arg1->repeatc = 1; \
2295+
} \
2296+
return rslt; \
2297+
}
2298+
2299+
INTINTRIN2("iand", eval_iand, &)
2300+
INTINTRIN2("ior", eval_ior, |)
2301+
INTINTRIN2("ieor", eval_ieor, ^)
2302+
22662303
static CONST *
22672304
eval_ichar(CONST *arg, int dtype)
22682305
{
@@ -4149,9 +4186,18 @@ eval_init_op(int op, CONST *lop, int ldtype, CONST *rop, int rdtype, int sptr,
41494186
case AC_I_abs:
41504187
root = eval_abs(rop, dtype);
41514188
break;
4189+
case AC_I_iand:
4190+
root = eval_iand(rop, dtype);
4191+
break;
4192+
case AC_I_ior:
4193+
root = eval_ior(rop, dtype);
4194+
break;
4195+
case AC_I_ieor:
4196+
root = eval_ieor(rop, dtype);
4197+
break;
41524198
default:
4153-
interr("eval_init_op: intrinsic not supported in initialiation",
4154-
lop->u1.conval, 3);
4199+
interr("eval_init_op(dinit.c): intrinsic not supported in "
4200+
"initialization", lop->u1.conval, 3);
41554201
return CONST_ERR(dtype);
41564202
}
41574203
} else if (DTY(ldtype) == TY_ARRAY && DTY(rdtype) == TY_ARRAY) {

tools/flang2/flang2exe/ll_structure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ typedef struct LL_Module {
809809
LL_MDNode *named_mdnodes[MD_NUM_NAMES];
810810
LL_MDRef omnipotentPtr;
811811
LL_MDRef unrefPtr;
812+
LL_MDRef loop_md;
812813

813814
/** Contents of the special global \c @llvm.used. List of pointers or constant
814815
exprs. */

0 commit comments

Comments
 (0)