aboutsummaryrefslogtreecommitdiff
path: root/test/Transforms
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2012-10-10 17:44:43 -0700
committerMark Seaborn <mseaborn@chromium.org>2012-10-10 17:44:43 -0700
commit7ef7d6db32b8a009c749a4d4f070cc7a72b1f3ff (patch)
tree8cc55ec3c0a25d7631ec166a2654585e3d5b540d /test/Transforms
parentff0566a629426809a704bc118c149dca569a5614 (diff)
PNaCl: Add a pass to convert llvm.global_ctors to __init_array_start/end
This pass converts LLVM's special symbols llvm.global_ctors and llvm.global_dtors to concrete arrays, __init_array_start/end and __fini_array_start/end, that are usable by a C library. The pass sorts the contents of global_ctors/dtors according to the priority values they contain and removes the priority values. This pass will allow us to simplify the PNaCl ABI so that less is done at translation time. BUG= http://code.google.com/p/nativeclient/issues/detail?id=3018 TEST=test/Transforms/NaCl/expand-ctors*.ll Review URL: https://codereview.chromium.org/10977030
Diffstat (limited to 'test/Transforms')
-rw-r--r--test/Transforms/NaCl/expand-ctors-empty.ll11
-rw-r--r--test/Transforms/NaCl/expand-ctors.ll36
2 files changed, 47 insertions, 0 deletions
diff --git a/test/Transforms/NaCl/expand-ctors-empty.ll b/test/Transforms/NaCl/expand-ctors-empty.ll
new file mode 100644
index 0000000000..4368270765
--- /dev/null
+++ b/test/Transforms/NaCl/expand-ctors-empty.ll
@@ -0,0 +1,11 @@
+; Currently we do not define __{init,fini}_array_end as named aliases.
+; RUN: opt < %s -nacl-expand-ctors -S | not grep __init_array_end
+; RUN: opt < %s -nacl-expand-ctors -S | not grep __fini_array_end
+
+; RUN: opt < %s -nacl-expand-ctors -S | FileCheck %s
+
+; If llvm.global_ctors is not present, it is treated as if it is an
+; empty array, and __{init,fini}_array_start are defined anyway.
+
+; CHECK: @__init_array_start = internal constant [0 x void ()*] zeroinitializer
+; CHECK: @__fini_array_start = internal constant [0 x void ()*] zeroinitializer
diff --git a/test/Transforms/NaCl/expand-ctors.ll b/test/Transforms/NaCl/expand-ctors.ll
new file mode 100644
index 0000000000..7f202618e7
--- /dev/null
+++ b/test/Transforms/NaCl/expand-ctors.ll
@@ -0,0 +1,36 @@
+; We expect these symbol names to be removed:
+; RUN: opt < %s -nacl-expand-ctors -S | not grep llvm.global_ctors
+; RUN: opt < %s -nacl-expand-ctors -S | not grep __init_array_end
+; RUN: opt < %s -nacl-expand-ctors -S | not grep __fini_array_end
+
+; RUN: opt < %s -nacl-expand-ctors -S | FileCheck %s
+
+@llvm.global_ctors = appending global [3 x { i32, void ()* }]
+ [{ i32, void ()* } { i32 300, void ()* @init_func_A },
+ { i32, void ()* } { i32 100, void ()* @init_func_B },
+ { i32, void ()* } { i32 200, void ()* @init_func_C }]
+
+@__init_array_start = extern_weak global [0 x void ()*]
+@__init_array_end = extern_weak global [0 x void ()*]
+
+; CHECK: @__init_array_start = internal constant [3 x void ()*] [void ()* @init_func_B, void ()* @init_func_C, void ()* @init_func_A]
+; CHECK: @__fini_array_start = internal constant [0 x void ()*] zeroinitializer
+
+define void @init_func_A() { ret void }
+define void @init_func_B() { ret void }
+define void @init_func_C() { ret void }
+
+define [0 x void ()*]* @get_array_start() {
+ ret [0 x void ()*]* @__init_array_start;
+}
+; CHECK: @get_array_start()
+; CHECK: ret {{.*}} @__init_array_start
+
+define [0 x void ()*]* @get_array_end() {
+ ret [0 x void ()*]* @__init_array_end;
+}
+
+; @get_array_end() is converted to use a GetElementPtr that returns
+; the end of the generated array:
+; CHECK: @get_array_end()
+; CHECK: ret {{.*}} bitcast ([3 x void ()*]* getelementptr inbounds ([3 x void ()*]* @__init_array_start, i32 1)