summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Globals.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-12-08 19:01:00 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-12-08 19:01:00 +0000
commit235c275b20d44e3aeb8bfe98dc34b2ead704bf32 (patch)
tree538eadab86e6bfd2ee1a401abcfe3c67355524ae /llvm/lib/IR/Globals.cpp
parentaa4f4450af0b6e5406189679713b61f225d0ab1b (diff)
downloadbcm5719-llvm-235c275b20d44e3aeb8bfe98dc34b2ead704bf32.tar.gz
bcm5719-llvm-235c275b20d44e3aeb8bfe98dc34b2ead704bf32.zip
IR, X86: Understand !absolute_symbol metadata on global variables.
Summary: Attaching !absolute_symbol to a global variable does two things: 1) Marks it as an absolute symbol reference. 2) Specifies the value range of that symbol's address. Teach the X86 backend to allow absolute symbols to appear in place of immediates by extending the relocImm and mov64imm32 matchers. Start using relocImm in more places where it is legal. As previously proposed on llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2016-October/105800.html Differential Revision: https://reviews.llvm.org/D25878 llvm-svn: 289087
Diffstat (limited to 'llvm/lib/IR/Globals.cpp')
-rw-r--r--llvm/lib/IR/Globals.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index f8ac37f9fc3..7cad629eaa7 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalValue.h"
@@ -222,6 +223,26 @@ GlobalObject *GlobalValue::getBaseObject() {
return nullptr;
}
+bool GlobalValue::isAbsoluteSymbolRef() const {
+ auto *GO = dyn_cast<GlobalObject>(this);
+ if (!GO)
+ return false;
+
+ return GO->getMetadata(LLVMContext::MD_absolute_symbol);
+}
+
+Optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
+ auto *GO = dyn_cast<GlobalObject>(this);
+ if (!GO)
+ return None;
+
+ MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
+ if (!MD)
+ return None;
+
+ return getConstantRangeFromMetadata(*MD);
+}
+
//===----------------------------------------------------------------------===//
// GlobalVariable Implementation
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud