From d41672fa697c2730fc5c52005030e30b3faec024 Mon Sep 17 00:00:00 2001 From: Sriraman Tallam Date: Thu, 28 Apr 2016 18:15:44 +0000 Subject: [PATCH] Add "PIE Level" metadata to module flags. http://reviews.llvm.org/D19671 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267911 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Module.h | 11 +++++++++++ include/llvm/Support/CodeGen.h | 4 ++++ lib/IR/Module.cpp | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/llvm/IR/Module.h b/include/llvm/IR/Module.h index 0a6a127bb0d..25585b0cb6a 100644 --- a/include/llvm/IR/Module.h +++ b/include/llvm/IR/Module.h @@ -732,6 +732,17 @@ public: void setPICLevel(PICLevel::Level PL); /// @} +/// @} +/// @name Utility functions for querying and setting PIE level +/// @{ + + /// \brief Returns the PIE level (small or large model) + PIELevel::Level getPIELevel() const; + + /// \brief Set the PIE level (small or large model) + void setPIELevel(PIELevel::Level PL); +/// @} + /// @name Utility functions for querying and setting PGO summary /// @{ diff --git a/include/llvm/Support/CodeGen.h b/include/llvm/Support/CodeGen.h index 0ff3d56363c..6e31ef4cb10 100644 --- a/include/llvm/Support/CodeGen.h +++ b/include/llvm/Support/CodeGen.h @@ -32,6 +32,10 @@ namespace llvm { enum Level { Default=0, Small=1, Large=2 }; } + namespace PIELevel { + enum Level { Default=0, Small=1, Large=2 }; + } + // TLS models. namespace TLSModel { enum Model { diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 10110367841..b15cac40274 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -497,6 +497,20 @@ void Module::setPICLevel(PICLevel::Level PL) { addModuleFlag(ModFlagBehavior::Error, "PIC Level", PL); } +PIELevel::Level Module::getPIELevel() const { + auto *Val = cast_or_null(getModuleFlag("PIE Level")); + + if (!Val) + return PIELevel::Default; + + return static_cast( + cast(Val->getValue())->getZExtValue()); +} + +void Module::setPIELevel(PIELevel::Level PL) { + addModuleFlag(ModFlagBehavior::Error, "PIE Level", PL); +} + void Module::setMaximumFunctionCount(uint64_t Count) { addModuleFlag(ModFlagBehavior::Error, "MaxFunctionCount", Count); }