From 055b008db5688da7657adf77a9e2cfab8e3c0e9e Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 7 Sep 2016 16:33:13 -0400
Subject: [PATCH 15/36] FIXME: reinstate usage of deferred locations

---
 gcc/read-rtl-function.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 100 insertions(+), 3 deletions(-)

diff --git a/gcc/read-rtl-function.c b/gcc/read-rtl-function.c
index 2f8304f..363010a 100644
--- a/gcc/read-rtl-function.c
+++ b/gcc/read-rtl-function.c
@@ -43,6 +43,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfg.h"
 #include "basic-block.h"
 #include "cfgrtl.h"
+#if 0
+#include "deferred-locations.h"
+#endif
 #include "emit-rtl.h"
 #include "cgraph.h"
 #include "tree-pass.h"
@@ -144,6 +147,27 @@ class fixup_note_insn_basic_block : public operand_fixup
   int m_bb_idx;
 };
 
+#if 0
+/* A concrete subclass of operand_fixup: fix up the INSN_LOCATION
+   of the insn based on a deferred_location *.  */
+
+class fixup_source_location : public operand_fixup
+{
+ public:
+  fixup_source_location (file_location loc, rtx insn,
+			 int operand_idx,
+			 deferred_location *dloc)
+    : operand_fixup (loc, insn, operand_idx),
+      m_dloc (dloc)
+  {}
+
+  void apply (function_reader *reader) const;
+
+ private:
+  deferred_location *m_dloc;
+};
+#endif
+
 /* A concrete subclass of operand_fixup: fix up the JUMP_LABEL
    of an insn based on a label name.  */
 
@@ -233,6 +257,9 @@ class function_reader : public rtx_reader
   auto_vec<fixup *> m_fixups;
   bitmap_head m_bb_indices;
   rtx_insn *m_first_insn;
+#if 0
+  deferred_locations m_deferred_locations;
+#endif
   auto_vec<tree> m_fake_scope;
 };
 
@@ -303,6 +330,15 @@ fixup_note_insn_basic_block::apply (function_reader */*reader*/) const
   NOTE_BASIC_BLOCK (m_rtx) = bb;
 }
 
+/* Fix up the INSN_LOCATION of the insn based on a deferred_location *.  */
+#if 0
+void
+fixup_source_location::apply (function_reader */*reader*/) const
+{
+  INSN_LOCATION (as_a <rtx_insn *> (m_rtx)) = m_dloc->m_srcloc;
+}
+#endif
+
 /* Fix up the JUMP_LABEL of an insn based on a label name.  */
 
 void
@@ -457,10 +493,16 @@ function_reader::add_fixup_note_insn_basic_block (file_location loc, rtx insn,
 /* Implementation of rtx_reader::add_fixup_source_location.
    Record the information for later post-processing.  */
 void
-function_reader::add_fixup_source_location (file_location, rtx,
-					    int, const char *, int)
+function_reader::add_fixup_source_location (file_location loc, rtx insn,
+					    int operand_idx,
+					    const char *filename, int lineno)
 {
-  /* Empty for now.  */
+#if 0
+  source_file *file = m_deferred_locations.get_source_file (filename);
+  source_line *line = file->get_source_line (lineno);
+  deferred_location *dloc = line->get_location (NULL, 0);
+  m_fixups.safe_push (new fixup_source_location (loc, insn, operand_idx, dloc));
+#endif
 }
 
 /* Implementation of rtx_reader::add_fixup_jump_label.
@@ -557,6 +599,9 @@ function_reader::create_function ()
 void
 function_reader::apply_fixups ()
 {
+#if 0
+  m_deferred_locations.add_to_line_table ();
+#endif
   /* line_table should now be populated; every deferred_location should
      now have an m_srcloc.  */
 
@@ -807,6 +852,43 @@ read_rtl_function_body (int argc, const char **argv,
   return true;
 }
 
+#if 0
+bool
+read_rtl_function_body_from_file_range (location_t start_loc,
+					location_t end_loc)
+{
+  expanded_location exploc_start = expand_location (start_loc);
+  expanded_location exploc_end = expand_location (end_loc);
+
+  if (exploc_start.file != exploc_end.file)
+    {
+      error_at (end_loc, "start/end of RTL fragment are in different files");
+      return false;
+    }
+  if (exploc_start.line >= exploc_end.line)
+    {
+      error_at (end_loc,
+		"start of RTL fragment must be on an earlier line than end");
+      return false;
+    }
+
+  in_rtl_frontend_p = true;
+
+  initialize_rtl ();
+  crtl->emit.init_emit ();
+  init_varasm_status ();
+
+  function_reader reader (line_table, NULL);
+  if (!reader.read_file_fragment (exploc_start.file, exploc_start.line,
+				  exploc_end.line - 1))
+    return false;
+
+  postprocess (&reader);
+
+  return true;
+}
+#endif
+
 #if CHECKING_P
 
 namespace selftest {
@@ -868,6 +950,14 @@ test_loading_dump_fragment_1 ()
   ASSERT_EQ (insn_8, get_insn_by_uid (8));
   ASSERT_EQ (insn_9, get_insn_by_uid (9));
 
+  /* Verify source code location information.  */
+#if 0
+  ASSERT_LOCATION_EQ ("../../src/gcc/testsuite/gcc.dg/asr_div1.c", 14, 0,
+		      INSN_LOCATION (insn_8));
+  ASSERT_LOCATION_EQ ("../../src/gcc/testsuite/gcc.dg/asr_div1.c", 14, 0,
+		      INSN_LOCATION (insn_9));
+#endif
+
   /* Verify that basic blocks were created.  */
   ASSERT_EQ (2, BLOCK_FOR_INSN (insn_8)->index);
   ASSERT_EQ (2, BLOCK_FOR_INSN (insn_9)->index);
@@ -959,6 +1049,9 @@ test_loading_dump_fragment_2 ()
       ASSERT_EQ (reg_expr, mem_expr);
     }
   }
+#if 0
+  ASSERT_LOCATION_EQ ("test.c", 2, 0, INSN_LOCATION (insn));
+#endif
 }
 
 /* Verify that CODE_LABEL insns are loaded correctly.  */
@@ -1036,6 +1129,10 @@ test_loading_jump_to_label_ref ()
   rtx label_ref = SET_SRC (PATTERN (jump_insn));
   ASSERT_EQ (LABEL_REF, GET_CODE (label_ref));
   ASSERT_EQ (code_label, LABEL_REF_LABEL (label_ref));
+#if 0
+  ASSERT_LOCATION_EQ ("../../src/gcc/testsuite/rtl.dg/test.c", 4, 0,
+		      INSN_LOCATION (jump_insn));
+#endif
   ASSERT_EQ (code_label, JUMP_LABEL (jump_insn));
 
   /* Verify the code_label. */
-- 
1.8.5.3

