[PATCH] D52323: Add necessary support for storing code-model to module IR.
Caroline Tice via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 20 14:19:42 PDT 2018
cmtice created this revision.
cmtice added reviewers: tejohnson, pcc.
Herald added subscribers: cfe-commits, dexonsmith, mehdi_amini.
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 (see https://reviews.llvm.org/D52322 for the back-end patch).
Fixes PR33306.
Repository:
rC Clang
https://reviews.llvm.org/D52323
Files:
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
test/CodeGen/codemodels.c
Index: test/CodeGen/codemodels.c
===================================================================
--- test/CodeGen/codemodels.c
+++ test/CodeGen/codemodels.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-NOMODEL
+// 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-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
Index: lib/CodeGen/CodeGenModule.h
===================================================================
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -35,6 +35,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ValueHandle.h"
+#include "llvm/Support/CodeGen.h"
#include "llvm/Transforms/Utils/SanitizerStats.h"
namespace llvm {
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ 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"
@@ -556,6 +557,21 @@
getModule().setPIELevel(static_cast<llvm::PIELevel::Level>(PLevel));
}
+ if (getCodeGenOpts().CodeModel.size() > 0) {
+ unsigned CM = llvm::StringSwitch<unsigned>(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)
+ .Case("default", ~1u)
+ .Default(~0u);
+ if ((CM != ~0u) && (CM != ~1u)) {
+ llvm::CodeModel::Model codeModel = static_cast<llvm::CodeModel::Model>(CM);
+ getModule().setCodeModel(codeModel);
+ }
+ }
+
if (CodeGenOpts.NoPLT)
getModule().setRtLibUseGOT();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52323.166360.patch
Type: text/x-patch
Size: 2832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180920/22d8e0e9/attachment.bin>
More information about the cfe-commits
mailing list