Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
      2 // RUN: %clang_cc1 -triple arm64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
      3 // RUN: %clang_cc1 -triple armv7-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
      4 
      5 // CHECK-NOT: @sp = common global
      6 register unsigned long current_stack_pointer asm("sp");
      7 struct p4_Thread {
      8   struct {
      9     int len;
     10   } word;
     11 };
     12 // Testing pointer types as well
     13 register struct p4_Thread *p4TH asm("sp");
     14 
     15 // CHECK: define{{.*}} i[[bits:[0-9]+]] @get_stack_pointer_addr()
     16 // CHECK: [[ret:%[0-9]+]] = call i[[bits]] @llvm.read_register.i[[bits]](metadata !0)
     17 // CHECK: ret i[[bits]] [[ret]]
     18 unsigned long get_stack_pointer_addr() {
     19   return current_stack_pointer;
     20 }
     21 // CHECK: declare{{.*}} i[[bits]] @llvm.read_register.i[[bits]](metadata)
     22 
     23 // CHECK: define{{.*}} void @set_stack_pointer_addr(i[[bits]] %addr) #0 {
     24 // CHECK: [[sto:%[0-9]+]] = load i[[bits]]* %
     25 // CHECK: call void @llvm.write_register.i[[bits]](metadata !0, i[[bits]] [[sto]])
     26 // CHECK: ret void
     27 void set_stack_pointer_addr(unsigned long addr) {
     28   current_stack_pointer = addr;
     29 }
     30 // CHECK: declare{{.*}} void @llvm.write_register.i[[bits]](metadata, i[[bits]])
     31 
     32 // CHECK: define {{.*}}@fn1
     33 int fn1() {
     34   return (*p4TH).word.len;
     35 }
     36 // CHECK: %[[regr:[0-9]+]] = call i[[bits]] @llvm.read_register.i[[bits]](metadata !0)
     37 // CHECK: inttoptr i[[bits]] %[[regr]] to %struct.p4_Thread*
     38 
     39 // CHECK: define {{.*}}@fn2
     40 void fn2(struct p4_Thread *val) {
     41   p4TH = val;
     42 }
     43 // CHECK: %[[regw:[0-9]+]] = ptrtoint %struct.p4_Thread* %{{.*}} to i[[bits]]
     44 // CHECK: call void @llvm.write_register.i[[bits]](metadata !0, i[[bits]] %[[regw]])
     45 
     46 // CHECK: !llvm.named.register.sp = !{!0}
     47 // CHECK: !0 = metadata !{metadata !"sp"}
     48