[llvm-commits] [llvm-gcc-4.2] r75068 - in /llvm-gcc-4.2/trunk/gcc: c-common.c c-parser.c config/asm.h cp/parser.c

Dale Johannesen dalej at apple.com
Wed Jul 8 16:24:26 PDT 2009


Author: johannes
Date: Wed Jul  8 18:24:13 2009
New Revision: 75068

URL: http://llvm.org/viewvc/llvm-project?rev=75068&view=rev
Log:
Make branches in asm blocks work better.  The idea
here is to use the assembler's ability to branch to
local labels 0b and 0f; this works with inlining, and
does not require exposing labels and basic blocks in the IR
for the optimizers to play with.  Branches into and out of
an asm block don't work; they don't in gcc either.
Forward branches within an asm block work, which they
don't in gcc.
gcc.apple/asm-block-7.c etc.


Modified:
    llvm-gcc-4.2/trunk/gcc/c-common.c
    llvm-gcc-4.2/trunk/gcc/c-parser.c
    llvm-gcc-4.2/trunk/gcc/config/asm.h
    llvm-gcc-4.2/trunk/gcc/cp/parser.c

Modified: llvm-gcc-4.2/trunk/gcc/c-common.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-common.c?rev=75068&r1=75067&r2=75068&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-common.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-common.c Wed Jul  8 18:24:13 2009
@@ -286,6 +286,10 @@
 int flag_iasm_blocks;
 /* APPLE LOCAL end CW asm blocks */
 
+/* LLVM LOCAL begin CW asm blocks */
+int iasm_label_counter;
+/* LLVM LOCAL end CW asm blocks */
+
 /* Nonzero means to treat bitfields as signed unless they say `unsigned'.  */
 
 int flag_signed_bitfields = 1;
@@ -8311,6 +8315,18 @@
 	  sprintf (buf + strlen (buf), "%s", name);
 	  break;
 	}
+/* LLVM LOCAL begin */
+#ifdef ENABLE_LLVM
+      // Labels defined earlier in the asm block will have DECL_INITIAL set
+      // at this point; labels we haven't seen yet won't.  LABEL_DECL_UID
+      // should be set in either case (when we saw the forward ref, we
+      // assumed the target was inside the block; that's what gcc does).
+      if (DECL_INITIAL (arg))
+        sprintf(buf + strlen(buf), "%lldb", LABEL_DECL_UID (arg));
+      else
+        sprintf(buf + strlen(buf), "%lldf", LABEL_DECL_UID (arg));
+#else
+/* LLVM LOCAL end */
       TREE_USED (arg) = 1;
       IASM_OFFSET_PREFIX (e, buf);
       arg = build1 (ADDR_EXPR, ptr_type_node, arg);
@@ -8336,6 +8352,8 @@
 #endif
       iasm_get_register_var (arg, modifier, buf, argnum, must_be_reg, e);
       iasm_force_constraint (0, e);
+/* LLVM LOCAL */
+#endif  /* ENABLE_LLVM */
       break;
 
     case IDENTIFIER_NODE:
@@ -8634,16 +8652,15 @@
 tree
 iasm_label (tree labid, bool atsign)
 {
-/* LLVM LOCAL begin */
-/* Unused variables resulting from code change below. */
-#ifdef ENABLE_LLVM
-  tree stmt, label;
-#else
   tree sexpr;
   tree inputs = NULL_TREE, outputs = NULL_TREE, clobbers = NULL_TREE;
   tree stmt;
+/* LLVM LOCAL begin */
+#ifndef ENABLE_LLVM
   tree label, l;
   tree str, one;
+#else
+  tree label;
 #endif
 /* LLVM LOCAL end */
   STRIP_NOPS (labid);
@@ -8656,8 +8673,7 @@
 
   iasm_buffer[0] = '\0';
   label = iasm_define_label (labid);
-/* LLVM LOCAL */
-#ifdef ENABLE_LLVM
+#if 0
   /* Ideally I'd like to do this, but, it moves the label in:
 
 	nop
@@ -8682,6 +8698,8 @@
 #else
   /* Arrange for the label to be a parameter to the ASM_EXPR, as only then will the
      backend `manage it' for us, say, making a unique copy for inline expansion.  */
+/* LLVM LOCAL */
+#ifndef ENABLE_LLVM
   sprintf (iasm_buffer, "%%l0: # %s", IDENTIFIER_POINTER (DECL_NAME (label)));
 
   l = build1 (ADDR_EXPR, ptr_type_node, label);
@@ -8693,6 +8711,13 @@
   inputs = chainon (NULL_TREE, one);
   sexpr = build_string (strlen (iasm_buffer), iasm_buffer);
   
+/* LLVM LOCAL begin */
+#else
+  sprintf (iasm_buffer, "%lld: # %s", LABEL_DECL_UID (label),
+                                    IDENTIFIER_POINTER (DECL_NAME (label)));
+  sexpr = build_string (strlen (iasm_buffer), iasm_buffer);
+#endif
+/* LLVM LOCAL end */
   /* Simple asm statements are treated as volatile.  */
   stmt = build_stmt (ASM_EXPR, sexpr, outputs, inputs, clobbers, NULL_TREE);
   ASM_VOLATILE_P (stmt) = 1;
@@ -8832,6 +8857,10 @@
   strcat (buf, labname);
   newid = get_identifier (buf);
   newid = lookup_label (newid);
+/* LLVM LOCAL begin */  
+  if (LABEL_DECL_UID (newid) == -1)
+    LABEL_DECL_UID (newid) = iasm_label_counter++;
+/* LLVM LOCAL end */
   return newid;
 }
 
@@ -8859,6 +8888,10 @@
   strcat (buf, labname);
   newid = get_identifier (buf);
   newid = define_label (input_location, newid);
+  /* LLVM LOCAL begin */
+  if (LABEL_DECL_UID (newid) == -1)
+    LABEL_DECL_UID (newid) = iasm_label_counter++;
+  /* LLVM LOCAL end */
   return newid;
 }
 

Modified: llvm-gcc-4.2/trunk/gcc/c-parser.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c-parser.c?rev=75068&r1=75067&r2=75068&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c-parser.c (original)
+++ llvm-gcc-4.2/trunk/gcc/c-parser.c Wed Jul  8 18:24:13 2009
@@ -4122,6 +4122,8 @@
 	  iasm_state = iasm_asm;
 	  inside_iasm_block = true;
 	  iasm_kill_regs = true;
+          /* LLVM LOCAL */
+          iasm_label_counter = 0;
 	  iasm_in_decl = false;
 	  c_parser_iasm_line_seq_opt (parser);
 	  stmt = NULL_TREE;
@@ -9021,6 +9023,8 @@
   iasm_state = iasm_asm;
   inside_iasm_block = true;
   iasm_kill_regs = true;
+  /* LLVM LOCAL */
+  iasm_label_counter = 0;
   stmt = c_begin_compound_stmt (true);
   /* Parse an (optional) statement-seq.  */
   c_parser_iasm_line_seq_opt (parser);
@@ -9041,6 +9045,8 @@
   iasm_state = iasm_asm;
   inside_iasm_block = true;
   iasm_kill_regs = true;
+  /* LLVM LOCAL */
+  iasm_label_counter = 0;
   stmt = c_begin_compound_stmt (true);
   if (!c_parser_iasm_bol (parser))
     {    

Modified: llvm-gcc-4.2/trunk/gcc/config/asm.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/config/asm.h?rev=75068&r1=75067&r2=75068&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/config/asm.h (original)
+++ llvm-gcc-4.2/trunk/gcc/config/asm.h Wed Jul  8 18:24:13 2009
@@ -25,6 +25,8 @@
 extern bool iasm_kill_regs;
 extern bool iasm_in_operands;
 extern tree iasm_do_id (tree);
+/* LLVM LOCAL */
+extern int iasm_label_counter;
 /* Maximum number of arguments.  */
 #define IASM_MAX_ARG 11
 

Modified: llvm-gcc-4.2/trunk/gcc/cp/parser.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/parser.c?rev=75068&r1=75067&r2=75068&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/parser.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/parser.c Wed Jul  8 18:24:13 2009
@@ -7095,6 +7095,8 @@
       iasm_state = iasm_asm;
       inside_iasm_block = true;
       iasm_kill_regs = true;
+      /* LLVM LOCAL */
+      iasm_label_counter = 0;
       cp_parser_iasm_line_seq_opt (parser);
       iasm_state = iasm_none;
       iasm_end_block ();
@@ -18063,6 +18065,8 @@
   iasm_state = iasm_asm;
   inside_iasm_block = true;
   iasm_kill_regs = true;
+  /* LLVM LOCAL */
+  iasm_label_counter = 0;
   if (!cp_parser_require (parser, CPP_OPEN_BRACE, "`{'"))
     return error_mark_node;
   /* Begin the compound-statement.  */
@@ -18087,6 +18091,8 @@
   iasm_state = iasm_asm;
   inside_iasm_block = true;
   iasm_kill_regs = true;
+  /* LLVM LOCAL */
+  iasm_label_counter = 0;
   /* Begin the compound-statement.  */
   compound_stmt = begin_compound_stmt (/*has_no_scope=*/false);
   if (!cp_lexer_iasm_bol (parser->lexer))





More information about the llvm-commits mailing list