llvm.org GIT mirror llvm / a53c520
Pass code-model through Module IR to LTO which will use it. 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, along with one for the front end, fixes that. Differential Revision: https://reviews.llvm.org/D52322 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342760 91177308-0d34-0410-b5e6-96231b3b80d8 Caroline Tice 11 months ago
7 changed file(s) with 114 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1515 #define LLVM_IR_MODULE_H
1616
1717 #include "llvm-c/Types.h"
18 #include "llvm/ADT/Optional.h"
1819 #include "llvm/ADT/STLExtras.h"
1920 #include "llvm/ADT/StringMap.h"
2021 #include "llvm/ADT/StringRef.h"
839840 void setPIELevel(PIELevel::Level PL);
840841 /// @}
841842
843 /// @}
844 /// @name Utility function for querying and setting code model
845 /// @{
846
847 /// Returns the code model (tiny, small, kernel, medium or large model)
848 Optional getCodeModel() const;
849
850 /// Set the code model (tiny, small, kernel, medium or large)
851 void setCodeModel(CodeModel::Model CL);
852 /// @}
853
842854 /// @name Utility functions for querying and setting PGO summary
843855 /// @{
844856
1212
1313 #include "llvm/IR/Module.h"
1414 #include "SymbolTableListTraitsImpl.h"
15 #include "llvm/ADT/Optional.h"
1516 #include "llvm/ADT/SmallPtrSet.h"
1617 #include "llvm/ADT/SmallString.h"
1718 #include "llvm/ADT/SmallVector.h"
506507 addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL);
507508 }
508509
510 Optional Module::getCodeModel() const {
511 auto *Val = cast_or_null(getModuleFlag("Code Model"));
512
513 if (!Val)
514 return None;
515
516 return static_cast(
517 cast(Val->getValue())->getZExtValue());
518 }
519
520 void Module::setCodeModel(CodeModel::Model CL) {
521 // Linking object files with different code models is undefined behavior
522 // because the compiler would have to generate additional code (to span
523 // longer jumps) if a larger code model is used with a smaller one.
524 // Therefore we will treat attempts to mix code models as an error.
525 addModuleFlag(ModFlagBehavior::Error, "Code Model", CL);
526 }
527
509528 void Module::setProfileSummary(Metadata *M) {
510529 addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
511530 }
137137 RelocModel =
138138 M.getPICLevel() == PICLevel::NotPIC ? Reloc::Static : Reloc::PIC_;
139139
140 Optional CodeModel;
141 if (Conf.CodeModel)
142 CodeModel = *Conf.CodeModel;
143 else
144 CodeModel = M.getCodeModel();
145
140146 return std::unique_ptr(TheTarget->createTargetMachine(
141147 TheTriple, Conf.CPU, Features.getString(), Conf.Options, RelocModel,
142 Conf.CodeModel, Conf.CGOptLevel));
148 CodeModel, Conf.CGOptLevel));
143149 }
144150
145151 static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
0 target triple = "x86_64-unknown-linux-gnu"
1 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2
3 !llvm.module.flags = !{!0, !1}
4
5 !0 = !{i32 1, !"wchar_size", i32 4}
6 !1 = !{i32 1, !"Code Model", i32 1}
7
8 %struct.rtx_def = type { i16, i16 }
9
10 define void @bar(%struct.rtx_def* %a, i8 %b, i32 %c) {
11 call void @llvm.memset.p0struct.rtx_def.i32(%struct.rtx_def* align 4 %a, i8 %b, i32 %c, i1 true)
12 ret void
13 }
14
15 declare void @llvm.memset.p0struct.rtx_def.i32(%struct.rtx_def*, i8, i32, i1)
0 ; RUN: llvm-as %s -o %t.o
1 ; RUN: llvm-lto2 run -r %t.o,_start,px %t.o -o %t.s
2 ; RUN: llvm-objdump -d %t.s.0 | FileCheck %s --check-prefix=CHECK-SMALL
3
4 target triple = "x86_64-unknown-linux-gnu"
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6
7 !llvm.module.flags = !{!0, !1}
8
9 !0 = !{i32 1, !"wchar_size", i32 4}
10 !1 = !{i32 1, !"Code Model", i32 1}
11
12 @data = internal constant [0 x i32] []
13
14 define i32* @_start() nounwind readonly {
15 entry:
16 ; CHECK-SMALL-LABEL: _start:
17 ; CHECK-SMALL: leaq (%rip), %rax
18 ret i32* getelementptr ([0 x i32], [0 x i32]* @data, i64 0, i64 0)
19 }
0 ; RUN: llvm-as %s -o %t.o
1 ; RUN: llvm-lto2 run -r %t.o,_start,px %t.o -o %t.s
2 ; RUN: llvm-objdump -d %t.s.0 | FileCheck %s --check-prefix=CHECK-LARGE
3
4 target triple = "x86_64-unknown-linux-gnu"
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6
7 !llvm.module.flags = !{!0, !1}
8
9 !0 = !{i32 1, !"wchar_size", i32 4}
10 !1 = !{i32 1, !"Code Model", i32 4}
11
12 @data = internal constant [0 x i32] []
13
14 define i32* @_start() nounwind readonly {
15 entry:
16 ; CHECK-LARGE-LABEL: _start:
17 ; CHECK-LARGE: movabsq $0, %rax
18 ret i32* getelementptr ([0 x i32], [0 x i32]* @data, i64 0, i64 0)
19 }
0 ; RUN: llvm-as %s -o %t0.o
1 ; RUN: llvm-as < %p/Inputs/codemodel-3.ll > %t1.o
2 ; RUN: not llvm-lto2 run -r %t0.o,_start,px -r %t1.o,bar,px %t0.o %t1.o -o %t2.s 2>&1 | FileCheck %s
3
4 target triple = "x86_64-unknown-linux-gnu"
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6
7 !llvm.module.flags = !{!0, !1}
8
9 !0 = !{i32 1, !"wchar_size", i32 4}
10 !1 = !{i32 1, !"Code Model", i32 4}
11
12 @data = internal constant [0 x i32] []
13
14 define i32* @_start() nounwind readonly {
15 entry:
16 ret i32* getelementptr ([0 x i32], [0 x i32]* @data, i64 0, i64 0)
17 }
18
19 ; CHECK: 'Code Model': IDs have conflicting values