+2018-04-30 Andrew Sadek <andrew.sadek.se@gmail.com>
+
+ Microblaze Target: PIC data text relative
+
+ * config/microblaze/microblaze.opt: add new option -mpic-data-text-rel.
+ * config/microblaze/microblaze-protos.h (microblaze_constant_address_p):
+ Add declaration.
+ * gcc/config/microblaze/microblaze.h (microblaze_constant_address_p):
+ CONSTANT_ADDRESS_P definition to microblaze_constant_address_p.
+ * config/microblaze/microblaze.c (TARGET_PIC_DATA_TEXT_REL):
+ New addressing mode for data-text relative position indepenedent code.
+ (microblaze_classify_unspec): add 'UNSPEC_TEXT' case ->
+ 'ADDRESS_SYMBOLIC_TXT_REL'.
+ (microblaze_classify_address): Add handling for UNSPEC + CONST_INT.
+ (microblaze_legitimate_pic_operand): Exclude function calls from
+ pic operands in case of TARGET_PIC_DATA_TEXT_REL option.
+ (microblaze_legitimize_address): Generate 'UNSPEC_TEXT' for all possible
+ addresses cases.
+ (microblaze_address_insns): Add 'ADDRESS_SYMBOLIC_TXT_REL' case.
+ (print_operand): Add 'ADDRESS_SYMBOLIC_TXT_REL' case.
+ (print_operand_address): Add 'ADDRESS_SYMBOLIC_TXT_REL' case + handling
+ for 'address + offset'.
+ (microblaze_expand_prologue): Add new function prologue call for
+ 'r20' assignation.
+ (microblaze_asm_generate_pic_addr_dif_vec): Override new target hook
+ 'TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC' to disable address diff vector
+ table in case of TARGET_PIC_DATA_TEXT_REL.
+ (expand_pic_symbol_ref): Add handling for 'UNSPEC_TEXT'.
+ * gcc/config/microblaze/microblaze.md (TARGET_PIC_DATA_TEXT_REL):
+ Add new macros 'UNSPEC_TEXT',
+ 'UNSPEC_SET_TEXT' + add rule for setting r20 in function prologue
+ + exclude function calls from 'UNSPEC_PLT' in case of data text
+ relative mode.
+ * doc/tm.texi.in (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC): Add
+ new target hook for generating address diff vector tables in case of
+ flag_pic.
+ * doc/tm.texi : Regenerate.
+ * stmt.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC): Append new condition
+ 'targetm.asm_out.generate_pic_addr_diff_vec' to flag_pic in case
+ of addr diff vector generation.
+ * target.def (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC): Add
+ target hook definition.
+ * targhooks.h, gcc/targhooks.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
+ Add default function for generate_pic_addr_diff_vec -> flag_pic.
+ * doc/invoke.texi (Add new pic option): Add new microblaze pic
+ option for data text relative.
+
2018-04-30 Richard Biener <rguenther@suse.de>
* tree-chrec.h (evolution_function_is_constant_p): Remove
ADDRESS_SYMBOLIC,
ADDRESS_GOTOFF,
ADDRESS_PLT,
- ADDRESS_TLS
+ ADDRESS_TLS,
+ ADDRESS_SYMBOLIC_TXT_REL
};
/* Classifies symbols
info->type = ADDRESS_TLS;
info->tls_type = tls_reloc (INTVAL (XVECEXP (x, 0, 1)));
}
+ else if (XINT (x, 1) == UNSPEC_TEXT)
+ {
+ info->type = ADDRESS_SYMBOLIC_TXT_REL;
+ }
else
{
return false;
}
/* Return true if X is a valid address for machine mode MODE. If it is,
- fill in INFO appropriately. STRICT is true if we should only accept
- hard base registers.
+ fill in INFO appropriately.
+ STRICT > 0 if we should only accept hard base registers.
+ STRICT = 2 if the operand address is being printed thus
+ function has been called by print_operand_address.
type regA regB offset symbol
{
rtx xplus0;
rtx xplus1;
+ rtx offset;
info->type = ADDRESS_INVALID;
info->regA = NULL;
info->offset = NULL;
info->symbol = NULL;
info->symbol_type = SYMBOL_TYPE_INVALID;
+ offset = NULL;
switch (GET_CODE (x))
{
/* for (plus x const_int) just look at x. */
if (GET_CODE (xconst0) == PLUS
&& GET_CODE (XEXP (xconst0, 1)) == CONST_INT
- && SMALL_INT (XEXP (xconst0, 1)))
+ && (SMALL_INT (XEXP (xconst0, 1))
+ || GET_CODE (XEXP (xconst0, 0)) == UNSPEC))
{
+ /* Hold CONST_INT Value in offset in case of
+ UNSPEC + CONST_INT. */
+ offset = XEXP (xconst0, 1);
+
/* This is ok as info->symbol is set to xplus1 the full
const-expression below. */
xconst0 = XEXP (xconst0, 0);
return true;
}
+ if (GET_CODE (xconst0) == UNSPEC && TARGET_PIC_DATA_TEXT_REL)
+ {
+ if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
+ return false;
+
+ info->offset = offset;
+ return microblaze_classify_unspec (info, xconst0);
+ }
+
/* Not base + symbol || base + UNSPEC. */
return false;
return !(flag_pic && pic_address_needs_scratch (x));
}
+ /* Avoid error in print_operand_address in case UNSPEC
+ is removed from SYMBOL or LABEL REFS during optimization. */
+ if ((GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
+ && flag_pic && TARGET_PIC_DATA_TEXT_REL && strict == 2)
+ {
+ info->type = ADDRESS_SYMBOLIC_TXT_REL;
+ return true;
+ }
+
if (flag_pic == 2)
return false;
else if (microblaze_tls_symbol_p(x))
return microblaze_classify_address (&addr, x, mode, strict);
}
+bool
+microblaze_constant_address_p (rtx x)
+{
+ return ((GET_CODE (x) == LABEL_REF) || (GET_CODE (x) == SYMBOL_REF)
+ || GET_CODE (x) == CONST_INT
+ || (GET_CODE (x) == CONST
+ && ! (flag_pic && pic_address_needs_scratch (x))));
+}
+
int
microblaze_valid_pic_const (rtx x)
{
int
microblaze_legitimate_pic_operand (rtx x)
{
- if (flag_pic == 2 && (symbol_mentioned_p(x) || label_mentioned_p(x)))
+ if (flag_pic == 2 && (symbol_mentioned_p (x) || label_mentioned_p (x))
+ && !(TARGET_PIC_DATA_TEXT_REL && call_insn_operand (x,VOIDmode)))
return 0;
if (microblaze_tls_referenced_p(x))
}
else if (flag_pic == 2)
{
- rtx pic_ref, reg;
- reg = gen_reg_rtx (Pmode);
-
- pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xplus1),
- UNSPEC_GOTOFF);
- pic_ref = gen_rtx_CONST (Pmode, pic_ref);
- pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
- pic_ref = gen_const_mem (Pmode, pic_ref);
- emit_move_insn (reg, pic_ref);
- result = gen_rtx_PLUS (Pmode, xplus0, reg);
- return result;
+ if (!TARGET_PIC_DATA_TEXT_REL)
+ {
+ rtx pic_ref, reg;
+ reg = gen_reg_rtx (Pmode);
+
+ pic_ref = gen_rtx_UNSPEC (Pmode,
+ gen_rtvec (1, xplus1),
+ UNSPEC_GOTOFF);
+ pic_ref = gen_rtx_CONST (Pmode, pic_ref);
+ pic_ref = gen_rtx_PLUS (Pmode,
+ pic_offset_table_rtx, pic_ref);
+ pic_ref = gen_const_mem (Pmode, pic_ref);
+ emit_move_insn (reg, pic_ref);
+ result = gen_rtx_PLUS (Pmode, xplus0, reg);
+ return result;
+ }
+ else
+ {
+ rtx pic_ref, reg;
+ reg = gen_reg_rtx (Pmode);
+ pic_ref = gen_rtx_UNSPEC (Pmode,
+ gen_rtvec (1, xplus1),
+ UNSPEC_TEXT);
+ pic_ref = gen_rtx_CONST (Pmode, pic_ref);
+ emit_insn (gen_addsi3 (reg,
+ pic_offset_table_rtx, xplus0));
+ result = gen_rtx_PLUS (Pmode, reg, pic_ref);
+ return result;
+ }
}
}
}
{
reg = microblaze_legitimize_tls_address (xinsn, NULL_RTX);
}
- else
+ else if (flag_pic == 2)
{
- rtx pic_ref;
+ if (reload_in_progress)
+ df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
- if (reload_in_progress)
- df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
+ if (!TARGET_PIC_DATA_TEXT_REL)
+ {
+ rtx pic_ref;
- pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xinsn), UNSPEC_GOTOFF);
- pic_ref = gen_rtx_CONST (Pmode, pic_ref);
- pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
- pic_ref = gen_const_mem (Pmode, pic_ref);
- reg = pic_ref;
- }
+ pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xinsn), UNSPEC_GOTOFF);
+ pic_ref = gen_rtx_CONST (Pmode, pic_ref);
+ pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
+ pic_ref = gen_const_mem (Pmode, pic_ref);
+ reg = pic_ref;
+ }
+ else
+ {
+ rtx pic_ref;
+
+ pic_ref = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, xinsn), UNSPEC_TEXT);
+ pic_ref = gen_rtx_CONST (Pmode, pic_ref);
+ pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, pic_ref);
+ reg = pic_ref;
+ }
+ }
return reg;
}
case ADDRESS_REG_INDEX:
return 1;
case ADDRESS_SYMBOLIC:
+ case ADDRESS_SYMBOLIC_TXT_REL:
case ADDRESS_GOTOFF:
return 2;
case ADDRESS_TLS:
total_size = var_size + args_size;
- if (flag_pic == 2)
+ if (flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL)
/* force setting GOT. */
df_set_regs_ever_live (MB_ABI_PIC_ADDR_REGNUM, true);
case ADDRESS_REG:
case ADDRESS_CONST_INT:
case ADDRESS_SYMBOLIC:
+ case ADDRESS_SYMBOLIC_TXT_REL:
case ADDRESS_GOTOFF:
case ADDRESS_TLS:
fputs ("i", file);
{
struct microblaze_address_info info;
enum microblaze_address_type type;
- if (!microblaze_classify_address (&info, addr, GET_MODE (addr), 1))
+ if (!microblaze_classify_address (&info, addr, GET_MODE (addr), 2))
fatal_insn ("insn contains an invalid address !", addr);
type = info.type;
output_addr_const (file, info.offset);
break;
case ADDRESS_SYMBOLIC:
+ case ADDRESS_SYMBOLIC_TXT_REL:
case ADDRESS_GOTOFF:
case ADDRESS_PLT:
case ADDRESS_TLS:
{
fputs ("@PLT", file);
}
+ else if (type == ADDRESS_SYMBOLIC_TXT_REL)
+ {
+ if (info.offset != NULL && CONST_INT_P (info.offset)
+ && INTVAL (info.offset) > 0)
+ {
+ fprintf (file, "+");
+ output_addr_const (file, info.offset);
+ }
+ fputs ("@TXTREL", file);
+ }
else if (type == ADDRESS_TLS)
{
switch (info.tls_type)
if (flag_stack_usage_info)
current_function_static_stack_size = fsiz;
-
/* If this function is a varargs function, store any registers that
would normally hold arguments ($5 - $10) on the stack. */
if (((TYPE_ARG_TYPES (fntype) != 0
offset += GET_MODE_SIZE (SImode);
}
-
}
if (fsiz > 0)
if ((flag_pic == 2 || TLS_NEEDS_GOT )
&& df_regs_ever_live_p (MB_ABI_PIC_ADDR_REGNUM))
{
- SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
- emit_insn (gen_set_got (pic_offset_table_rtx)); /* setting GOT. */
+ if ((flag_pic == 2 && !TARGET_PIC_DATA_TEXT_REL) || TLS_NEEDS_GOT)
+ {
+ SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
+ /* setting GOT. */
+ emit_insn (gen_set_got (pic_offset_table_rtx));
+ }
+ else
+ {
+ SET_REGNO (pic_offset_table_rtx, MB_ABI_PIC_ADDR_REGNUM);
+ /* setting start of text. */
+ emit_insn (gen_set_text (pic_offset_table_rtx));
+ }
}
/* If we are profiling, make sure no instructions are scheduled before
return (size > 0 && size <= microblaze_section_threshold);
}
+/* We need to disable address diff vectors in
+case of pic data text relative mode. */
+
+static bool
+microblaze_gen_pic_addr_dif_vec (void)
+{
+ return (flag_pic && !TARGET_PIC_DATA_TEXT_REL);
+}
static section *
microblaze_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
expand_pic_symbol_ref (machine_mode mode ATTRIBUTE_UNUSED, rtx op)
{
rtx result;
- result = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_GOTOFF);
+ bool isFunc = (GET_CODE (op) == SYMBOL_REF
+ && (SYMBOL_REF_FLAGS (op) & SYMBOL_FLAG_FUNCTION));
+ result = (!TARGET_PIC_DATA_TEXT_REL)
+ ? gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_GOTOFF)
+ : gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), UNSPEC_TEXT);
result = gen_rtx_CONST (Pmode, result);
- result = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
- result = gen_const_mem (Pmode, result);
+ result = (TARGET_PIC_DATA_TEXT_REL && isFunc)
+ ? gen_rtx_PLUS (Pmode, gen_raw_REG (Pmode,
+ get_base_reg (op)), result)
+ : gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
+ result = (!TARGET_PIC_DATA_TEXT_REL)
+ ? gen_const_mem (Pmode, result) : result;
+
return result;
}
if (reload_in_progress)
df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
result = expand_pic_symbol_ref (mode, op1);
+
+ if (TARGET_PIC_DATA_TEXT_REL && GET_CODE (op0) == REG
+ && REGNO (op0) >= FIRST_PSEUDO_REGISTER)
+ result = force_reg (SImode, result);
+
emit_move_insn (op0, result);
return true;
}
}
+ if (GET_CODE (op1) == PLUS && GET_CODE (XEXP (op1,1)) == CONST)
+ {
+ rtx p0, p1, result, temp;
+
+ p0 = XEXP (XEXP (op1,1), 0);
+
+ if (GET_CODE (p0) == PLUS)
+ {
+ p1 = XEXP (p0, 1);
+ p0 = XEXP (p0, 0);
+ }
+
+ if (GET_CODE (p0) == UNSPEC && GET_CODE (p1) == CONST_INT
+ && flag_pic && TARGET_PIC_DATA_TEXT_REL)
+ {
+ result = gen_rtx_CONST (Pmode, p0);
+ result = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, result);
+ temp = force_reg (SImode, result);
+ emit_move_insn (op0, gen_rtx_PLUS (SImode, temp, p1));
+ return true;
+ }
+ }
/* Handle Case of (const (plus symbol const_int)). */
if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1,0)) == PLUS)
{
#undef TARGET_LEGITIMATE_CONSTANT_P
#define TARGET_LEGITIMATE_CONSTANT_P microblaze_legitimate_constant_p
+#undef TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC microblaze_gen_pic_addr_dif_vec
+
#undef TARGET_MACHINE_DEPENDENT_REORG
#define TARGET_MACHINE_DEPENDENT_REORG microblaze_machine_dependent_reorg