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
This commit is contained in:
Caroline Tice
2018-09-21 18:41:31 +00:00
parent c146db2943
commit a53c520ec5
7 changed files with 114 additions and 1 deletions
+19
View File
@@ -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);
}