summaryrefslogtreecommitdiffstats
path: root/llvm/lib/LTO/LTOModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/LTO/LTOModule.cpp')
-rw-r--r--llvm/lib/LTO/LTOModule.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index 79cff1f68fe..f73a608e3c4 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -18,6 +18,7 @@
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
@@ -37,6 +38,8 @@
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/system_error.h"
+#include "llvm/Target/TargetLowering.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Transforms/Utils/GlobalStatus.h"
using namespace llvm;
@@ -177,6 +180,8 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
return NULL;
}
+ Ret->parseMetadata();
+
return Ret;
}
@@ -798,3 +803,27 @@ bool LTOModule::parseSymbols(std::string &errMsg) {
return false;
}
+
+/// parseMetadata - Parse metadata from the module
+void LTOModule::parseMetadata() {
+ // Linker Options
+ if (Value *Val = _module->getModuleFlag("Linker Options")) {
+ MDNode *LinkerOptions = cast<MDNode>(Val);
+ for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
+ MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
+ for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
+ MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
+ StringRef Op = _linkeropt_strings.
+ GetOrCreateValue(MDOption->getString()).getKey();
+ StringRef DepLibName = _target->getTargetLowering()->
+ getObjFileLowering().getDepLibFromLinkerOpt(Op);
+ if (!DepLibName.empty())
+ _deplibs.push_back(DepLibName.data());
+ else if (!Op.empty())
+ _linkeropts.push_back(Op.data());
+ }
+ }
+ }
+
+ // Add other interesting metadata here.
+}
OpenPOWER on IntegriCloud