[PATCH] D45917: Pass -Oz/-Os along to the backend

Jessica Paquette via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 23 09:49:54 PDT 2018


paquette updated this revision to Diff 143584.
paquette added a comment.

Add context to diff.


https://reviews.llvm.org/D45917

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGen/arm64-outline.c


Index: test/CodeGen/arm64-outline.c
===================================================================
--- /dev/null
+++ test/CodeGen/arm64-outline.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -triple arm64--- -Oz -S -mllvm -debug-pass=Structure %s -o /dev/null 2> FileCheck %s
+// CHECK: Machine Outliner
+// RUN: %clang_cc1 -emit-llvm -Oz -S -mllvm -debug-pass=Structure %s -o /dev/null 2> FileCheck %s
+// CHECK-NOT: Machine Outliner
+// Ensure that -Oz is properly passed down to the backend by checking if the 
+// Machine Outliner is only added by default in ARM64.
+
+void foo(void) {
+}
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -354,6 +354,19 @@
   }
 }
 
+static CodeGenSizeOpt::Level getCGSizeOptLevel(const CodeGenOptions &CodeGenOpts) {
+  switch (CodeGenOpts.OptimizeSize) {
+    default:
+      llvm_unreachable("Invalid size optimization level!");
+    case 0:
+      return CodeGenSizeOpt::None;
+    case 1:
+      return CodeGenSizeOpt::OptSize; // Os
+    case 2:
+      return CodeGenSizeOpt::MinSize; // Oz
+  }
+}
+
 static Optional<llvm::CodeModel::Model>
 getCodeModel(const CodeGenOptions &CodeGenOpts) {
   unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.CodeModel)
@@ -692,11 +705,12 @@
       llvm::join(TargetOpts.Features.begin(), TargetOpts.Features.end(), ",");
   llvm::Reloc::Model RM = CodeGenOpts.RelocationModel;
   CodeGenOpt::Level OptLevel = getCGOptLevel(CodeGenOpts);
-
+  CodeGenSizeOpt::Level SizeOptLevel = getCGSizeOptLevel(CodeGenOpts);
   llvm::TargetOptions Options;
   initTargetOptions(Options, CodeGenOpts, TargetOpts, LangOpts, HSOpts);
   TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
-                                          Options, RM, CM, OptLevel));
+                                          Options, RM, CM, OptLevel,
+                                          SizeOptLevel));
 }
 
 bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45917.143584.patch
Type: text/x-patch
Size: 2100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180423/5b4bbe09/attachment.bin>


More information about the llvm-commits mailing list