From: Caroline Tice Date: Fri, 21 Sep 2018 18:34:59 +0000 (+0000) Subject: Add necessary support for storing code-model to module IR. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=376881c98e8cd750a0821948af1712a022acf14b;p=clang Add necessary support for storing code-model to module IR. Currently the code-model does not get saved in the module IR, so if a code model is specified when compiling with LTO, it gets lost and is not propagated properly to LTO. This patch does what is necessary in the front end to pass the code-model to the module, so that the back end can store it in the Module . Differential Revision: https://reviews.llvm.org/D52323 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342758 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 49c926db56..85fed52579 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -44,6 +44,7 @@ #include "clang/CodeGen/ConstantInitBuilder.h" #include "clang/Frontend/CodeGenOptions.h" #include "clang/Sema/SemaDiagnostic.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/CallSite.h" @@ -53,6 +54,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/ProfileData/InstrProfReader.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MD5.h" @@ -556,6 +558,20 @@ void CodeGenModule::Release() { getModule().setPIELevel(static_cast(PLevel)); } + if (getCodeGenOpts().CodeModel.size() > 0) { + unsigned CM = llvm::StringSwitch(getCodeGenOpts().CodeModel) + .Case("tiny", llvm::CodeModel::Tiny) + .Case("small", llvm::CodeModel::Small) + .Case("kernel", llvm::CodeModel::Kernel) + .Case("medium", llvm::CodeModel::Medium) + .Case("large", llvm::CodeModel::Large) + .Default(~0u); + if (CM != ~0u) { + llvm::CodeModel::Model codeModel = static_cast(CM); + getModule().setCodeModel(codeModel); + } + } + if (CodeGenOpts.NoPLT) getModule().setRtLibUseGOT(); diff --git a/test/CodeGen/codemodels.c b/test/CodeGen/codemodels.c new file mode 100644 index 0000000000..f85c7a0ff8 --- /dev/null +++ b/test/CodeGen/codemodels.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-NOMODEL +// RUN: %clang_cc1 -emit-llvm -mcode-model tiny %s -o - | FileCheck %s -check-prefix=CHECK-TINY +// RUN: %clang_cc1 -emit-llvm -mcode-model small %s -o - | FileCheck %s -check-prefix=CHECK-SMALL +// RUN: %clang_cc1 -emit-llvm -mcode-model kernel %s -o - | FileCheck %s -check-prefix=CHECK-KERNEL +// RUN: %clang_cc1 -emit-llvm -mcode-model medium %s -o - | FileCheck %s -check-prefix=CHECK-MEDIUM +// RUN: %clang_cc1 -emit-llvm -mcode-model large %s -o - | FileCheck %s -check-prefix=CHECK-LARGE + +// CHECK-TINY: !llvm.module.flags = !{{{.*}}} +// CHECK-TINY: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 0} +// CHECK-SMALL: !llvm.module.flags = !{{{.*}}} +// CHECK-SMALL: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 1} +// CHECK-KERNEL: !llvm.module.flags = !{{{.*}}} +// CHECK-KERNEL: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 2} +// CHECK-MEDIUM: !llvm.module.flags = !{{{.*}}} +// CHECK-MEDIUM: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 3} +// CHECK-LARGE: !llvm.module.flags = !{{{.*}}} +// CHECK-LARGE: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 4} +// CHECK-NOMODEL-NOT: Code Model