about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-01-26 07:08:18 +0000
committerbors <bors@rust-lang.org>2019-01-26 07:08:18 +0000
commit42eb5ff4042236ec3635035332e059afa7d63f9d (patch)
tree2add28d90e48f64c036bf3dd0b37f454979e44e2 /src/test/codegen
parent9df043b543bb9bc3e50bc243811c58d52a3aefea (diff)
parentce289c6c9911c7ea55b7f30b125d3c38ed359da4 (diff)
downloadrust-42eb5ff4042236ec3635035332e059afa7d63f9d.tar.gz
rust-42eb5ff4042236ec3635035332e059afa7d63f9d.zip
Auto merge of #55641 - nagisa:optimize-attr, r=pnkfelix
Implement optimize(size) and optimize(speed) attributes

This PR implements both `optimize(size)` and `optimize(speed)` attributes.

While the functionality itself works fine now, this PR is not yet complete: the code might be messy in places and, most importantly, the compiletest must be improved with functionality to run tests with custom optimization levels. Otherwise the new attribute cannot be tested properly. Oh, and not all of the RFC is implemented – attribute propagation is not implemented for example.

# TODO

* [x] Improve compiletest so that tests can be written;
* [x] Assign a proper error number (E9999 currently, no idea how to allocate a number properly);
* [ ] Perhaps reduce the duplication in LLVM attribute assignment code…
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/inline-always-works-always.rs21
-rw-r--r--src/test/codegen/optimize-attr-1.rs50
2 files changed, 71 insertions, 0 deletions
diff --git a/src/test/codegen/inline-always-works-always.rs b/src/test/codegen/inline-always-works-always.rs
new file mode 100644
index 00000000000..912af782a8f
--- /dev/null
+++ b/src/test/codegen/inline-always-works-always.rs
@@ -0,0 +1,21 @@
+// revisions: NO-OPT SIZE-OPT SPEED-OPT
+//[NO-OPT] compile-flags: -Copt-level=0
+//[SIZE-OPT] compile-flags: -Copt-level=s
+//[SPEED-OPT] compile-flags: -Copt-level=3
+
+#![crate_type="rlib"]
+
+#[no_mangle]
+#[inline(always)]
+pub extern "C" fn callee() -> u32 {
+    4 + 4
+}
+
+// CHECK-LABEL: caller
+// SIZE-OPT: ret i32 8
+// SPEED-OPT: ret i32 8
+// NO-OPT: ret i32 8
+#[no_mangle]
+pub extern "C" fn caller() -> u32 {
+    callee()
+}
diff --git a/src/test/codegen/optimize-attr-1.rs b/src/test/codegen/optimize-attr-1.rs
new file mode 100644
index 00000000000..376447e5b5d
--- /dev/null
+++ b/src/test/codegen/optimize-attr-1.rs
@@ -0,0 +1,50 @@
+// revisions: NO-OPT SIZE-OPT SPEED-OPT
+//[NO-OPT] compile-flags: -Copt-level=0 -Ccodegen-units=1
+//[SIZE-OPT] compile-flags: -Copt-level=s -Ccodegen-units=1
+//[SPEED-OPT] compile-flags: -Copt-level=3 -Ccodegen-units=1
+
+#![feature(optimize_attribute)]
+#![crate_type="rlib"]
+
+// CHECK-LABEL: define i32 @nothing
+// CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]]
+// NO-OPT: ret i32 %1
+// SIZE-OPT: ret i32 4
+// SPEEC-OPT: ret i32 4
+#[no_mangle]
+pub fn nothing() -> i32 {
+    2 + 2
+}
+
+// CHECK-LABEL: define i32 @size
+// CHECK-SAME: [[SIZE_ATTRS:#[0-9]+]]
+// NO-OPT: ret i32 %1
+// SIZE-OPT: ret i32 6
+// SPEED-OPT: ret i32 6
+#[optimize(size)]
+#[no_mangle]
+pub fn size() -> i32 {
+    3 + 3
+}
+
+// CHECK-LABEL: define i32 @speed
+// NO-OPT-SAME: [[NOTHING_ATTRS]]
+// SPEED-OPT-SAME: [[NOTHING_ATTRS]]
+// SIZE-OPT-SAME: [[SPEED_ATTRS:#[0-9]+]]
+// NO-OPT: ret i32 %1
+// SIZE-OPT: ret i32 8
+// SPEED-OPT: ret i32 8
+#[optimize(speed)]
+#[no_mangle]
+pub fn speed() -> i32 {
+    4 + 4
+}
+
+// NO-OPT-DAG: attributes [[SIZE_ATTRS]] = {{.*}}minsize{{.*}}optsize{{.*}}
+// SPEED-OPT-DAG: attributes [[SIZE_ATTRS]] = {{.*}}minsize{{.*}}optsize{{.*}}
+// SIZE-OPT-DAG: attributes [[NOTHING_ATTRS]] = {{.*}}optsize{{.*}}
+// SIZE-OPT-DAG: attributes [[SIZE_ATTRS]] = {{.*}}minsize{{.*}}optsize{{.*}}
+
+// SIZE-OPT: attributes [[SPEED_ATTRS]]
+// SIZE-OPT-NOT: minsize
+// SIZE-OPT-NOT: optsize