[XRay] Support multiple return instructions in a single basic block
authorDean Michael Berris <dberris@google.com>
Wed, 31 Aug 2016 05:20:08 +0000 (05:20 +0000)
committerDean Michael Berris <dberris@google.com>
Wed, 31 Aug 2016 05:20:08 +0000 (05:20 +0000)
Add a .mir test to catch this case, and fix the xray-instrumentation
pass to handle it appropriately.

llvm-svn: 280192

llvm/lib/CodeGen/XRayInstrumentation.cpp
llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll
llvm/test/CodeGen/X86/xray-multiplerets-in-blocks.mir [new file with mode: 0644]

index 1f95708..714c069 100644 (file)
@@ -79,7 +79,6 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) {
         for (auto &MO : T.operands())
           MIB.addOperand(MO);
         Terminators.push_back(&T);
-        break;
       }
     }
   }
index d949b8f..7dfab65 100644 (file)
@@ -18,3 +18,35 @@ define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always"
 ; CHECK-LABEL: Lxray_synthetic_0:
 ; CHECK:       .quad .Lxray_sled_0
 ; CHECK:       .quad .Lxray_sled_1
+
+; We test multiple returns in a single function to make sure we're getting all
+; of them with XRay instrumentation.
+define i32 @bar(i32 %i) nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK:       .p2align 1, 0x90
+; CHECK-LABEL: Lxray_sled_2:
+; CHECK-NEXT:  .ascii "\353\t"
+; CHECK-NEXT:  nopw 512(%rax,%rax)
+; CHECK-LABEL: Ltmp1:
+Test:
+  %cond = icmp eq i32 %i, 0
+  br i1 %cond, label %IsEqual, label %NotEqual
+IsEqual:
+  ret i32 0
+; CHECK:       .p2align 1, 0x90
+; CHECK-LABEL: Lxray_sled_3:
+; CHECK-NEXT:  retq
+; CHECK-NEXT:  nopw %cs:512(%rax,%rax)
+NotEqual:
+  ret i32 1
+; CHECK:       .p2align 1, 0x90
+; CHECK-LABEL: Lxray_sled_4:
+; CHECK-NEXT:  retq
+; CHECK-NEXT:  nopw %cs:512(%rax,%rax)
+}
+; CHECK:       .p2align 4, 0x90
+; CHECK-NEXT:  .quad .Lxray_synthetic_1
+; CHECK-NEXT:  .section xray_instr_map,{{.*}}
+; CHECK-LABEL: Lxray_synthetic_1:
+; CHECK:       .quad .Lxray_sled_2
+; CHECK:       .quad .Lxray_sled_3
+; CHECK:       .quad .Lxray_sled_4
diff --git a/llvm/test/CodeGen/X86/xray-multiplerets-in-blocks.mir b/llvm/test/CodeGen/X86/xray-multiplerets-in-blocks.mir
new file mode 100644 (file)
index 0000000..4625d44
--- /dev/null
@@ -0,0 +1,28 @@
+# RUN: llc -run-pass xray-instrumentation -mtriple=x86_64-unknown-linux-gnu -o - %s | FileCheck %s
+#
+# Make sure we can handle multiple ret instructions in a single basic block for
+# XRay.
+
+--- |
+
+  define i32 @foo() noinline uwtable "function-instrument"="xray-always" {
+    ret i32 0
+    ret i32 1
+  }
+
+...
+
+---
+name: foo
+tracksRegLiveness: true
+liveins:
+  - { reg: '%edi'}
+body:            |
+  bb.0:
+    liveins: %edi
+    ; CHECK: PATCHABLE_FUNCTION_ENTER
+    RETQ
+    ; CHECK-NEXT: PATCHABLE_RET 2508
+    RETQ
+    ; CHECK-NEXT: PATCHABLE_RET 2508
+...