diff options
author | Caroline Tice <cmtice@google.com> | 2018-09-21 18:41:31 +0000 |
---|---|---|
committer | Caroline Tice <cmtice@google.com> | 2018-09-21 18:41:31 +0000 |
commit | 3dea3f9e0a7e2c72ff7e109d1581b62365fc7ae8 (patch) | |
tree | ae18be7979a8f0730ee13cb221f15961824720ff /llvm/lib/IR/Module.cpp | |
parent | 8a59dbf7fd73f28792f605c059e5cea189e0c587 (diff) | |
download | bcm5719-llvm-3dea3f9e0a7e2c72ff7e109d1581b62365fc7ae8.tar.gz bcm5719-llvm-3dea3f9e0a7e2c72ff7e109d1581b62365fc7ae8.zip |
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
llvm-svn: 342760
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 882ab106a37..7d02a3956ff 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -13,6 +13,7 @@ #include "llvm/IR/Module.h" #include "SymbolTableListTraitsImpl.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -507,6 +508,24 @@ void Module::setPIELevel(PIELevel::Level PL) { addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL); } +Optional<CodeModel::Model> Module::getCodeModel() const { + auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Code Model")); + + if (!Val) + return None; + + return static_cast<CodeModel::Model>( + cast<ConstantInt>(Val->getValue())->getZExtValue()); +} + +void Module::setCodeModel(CodeModel::Model CL) { + // Linking object files with different code models is undefined behavior + // because the compiler would have to generate additional code (to span + // longer jumps) if a larger code model is used with a smaller one. + // Therefore we will treat attempts to mix code models as an error. + addModuleFlag(ModFlagBehavior::Error, "Code Model", CL); +} + void Module::setProfileSummary(Metadata *M) { addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M); } |