aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/LTO/LTOModule.h22
-rw-r--r--llvm/lib/LTO/LTOModule.cpp27
-rw-r--r--llvm/tools/lto/lto.cpp11
3 files changed, 20 insertions, 40 deletions
diff --git a/llvm/include/llvm/LTO/LTOModule.h b/llvm/include/llvm/LTO/LTOModule.h
index 64c066e..2f1f3c2 100644
--- a/llvm/include/llvm/LTO/LTOModule.h
+++ b/llvm/include/llvm/LTO/LTOModule.h
@@ -70,13 +70,14 @@ public:
static bool isBitcodeFile(const void *mem, size_t length);
static bool isBitcodeFile(const char *path);
- /// Returns 'true' if the file or memory contents is LLVM bitcode for the
- /// specified triple.
- static bool isBitcodeFileForTarget(const void *mem,
- size_t length,
- const char *triplePrefix);
- static bool isBitcodeFileForTarget(const char *path,
- const char *triplePrefix);
+ /// Returns 'true' if the memory buffer is LLVM bitcode for the specified
+ /// triple.
+ static bool isBitcodeForTarget(MemoryBuffer *memBuffer,
+ StringRef triplePrefix);
+
+ /// Create a MemoryBuffer from a memory range with an optional name.
+ static MemoryBuffer *makeBuffer(const void *mem, size_t length,
+ StringRef name = "");
/// Create an LTOModule. N.B. These methods take ownership of the buffer. The
/// caller must have initialized the Targets, the TargetMCs, the AsmPrinters,
@@ -202,17 +203,10 @@ private:
/// Get string that the data pointer points to.
bool objcClassNameFromExpression(const Constant *c, std::string &name);
- /// Returns 'true' if the bitcode BC is for the specified target triple.
- static bool isTargetMatch(StringRef BC, const char *TriplePrefix);
-
/// Create an LTOModule (private version). N.B. This method takes ownership of
/// the buffer.
static LTOModule *makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
TargetOptions options, std::string &errMsg);
-
- /// Create a MemoryBuffer from a memory range with an optional name.
- static MemoryBuffer *makeBuffer(const void *mem, size_t length,
- StringRef name = "");
};
}
#endif // LTO_MODULE_H
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index 6ba99ed..bdf3ed5 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -68,30 +68,9 @@ bool LTOModule::isBitcodeFile(const char *path) {
return type == sys::fs::file_magic::bitcode;
}
-/// isBitcodeFileForTarget - Returns 'true' if the file (or memory contents) is
-/// LLVM bitcode for the specified triple.
-bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length,
- const char *triplePrefix) {
- MemoryBuffer *buffer = makeBuffer(mem, length);
- if (!buffer)
- return false;
- return isTargetMatch(StringRef((const char *)mem, length), triplePrefix);
-}
-
-bool LTOModule::isBitcodeFileForTarget(const char *path,
- const char *triplePrefix) {
- std::unique_ptr<MemoryBuffer> buffer;
- if (MemoryBuffer::getFile(path, buffer))
- return false;
- return isTargetMatch(buffer->getBuffer(), triplePrefix);
-}
-
-/// Returns 'true' if the bitcode BC is for the specified target triple.
-bool LTOModule::isTargetMatch(StringRef BC, const char *TriplePrefix) {
- std::unique_ptr<MemoryBuffer> Buffer(
- MemoryBuffer::getMemBuffer(BC, "", false));
- std::string Triple = getBitcodeTargetTriple(Buffer.get(), getGlobalContext());
- return strncmp(Triple.c_str(), TriplePrefix, strlen(TriplePrefix)) == 0;
+bool LTOModule::isBitcodeForTarget(MemoryBuffer *buffer,
+ StringRef triplePrefix) {
+ return getBitcodeTargetTriple(buffer, getGlobalContext()) == triplePrefix;
}
LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 5f02124..8df7315 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -16,6 +16,7 @@
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/LTO/LTOCodeGenerator.h"
#include "llvm/LTO/LTOModule.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/TargetSelect.h"
// extra command-line flags needed for LTOCodeGenerator
@@ -87,7 +88,10 @@ bool lto_module_is_object_file(const char* path) {
bool lto_module_is_object_file_for_target(const char* path,
const char* target_triplet_prefix) {
- return LTOModule::isBitcodeFileForTarget(path, target_triplet_prefix);
+ std::unique_ptr<MemoryBuffer> buffer;
+ if (MemoryBuffer::getFile(path, buffer))
+ return false;
+ return LTOModule::isBitcodeForTarget(buffer.get(), target_triplet_prefix);
}
bool lto_module_is_object_file_in_memory(const void* mem, size_t length) {
@@ -98,7 +102,10 @@ bool
lto_module_is_object_file_in_memory_for_target(const void* mem,
size_t length,
const char* target_triplet_prefix) {
- return LTOModule::isBitcodeFileForTarget(mem, length, target_triplet_prefix);
+ std::unique_ptr<MemoryBuffer> buffer(LTOModule::makeBuffer(mem, length));
+ if (!buffer)
+ return false;
+ return LTOModule::isBitcodeForTarget(buffer.get(), target_triplet_prefix);
}
lto_module_t lto_module_create(const char* path) {