[llvm] r212305 - Modify LTOModule::isTargetMatch to take a StringRef instead of a MemoryBuffer.

Peter Collingbourne peter at pcc.me.uk
Thu Jul 3 16:49:28 PDT 2014


Author: pcc
Date: Thu Jul  3 18:49:28 2014
New Revision: 212305

URL: http://llvm.org/viewvc/llvm-project?rev=212305&view=rev
Log:
Modify LTOModule::isTargetMatch to take a StringRef instead of a MemoryBuffer.

Modified:
    llvm/trunk/include/llvm/LTO/LTOModule.h
    llvm/trunk/lib/LTO/LTOModule.cpp

Modified: llvm/trunk/include/llvm/LTO/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOModule.h?rev=212305&r1=212304&r2=212305&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOModule.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOModule.h Thu Jul  3 18:49:28 2014
@@ -202,8 +202,8 @@ private:
   /// Get string that the data pointer points to.
   bool objcClassNameFromExpression(const Constant *c, std::string &name);
 
-  /// Returns 'true' if the memory buffer is for the specified target triple.
-  static bool isTargetMatch(MemoryBuffer *memBuffer, const char *triplePrefix);
+  /// 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.

Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=212305&r1=212304&r2=212305&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Thu Jul  3 18:49:28 2014
@@ -75,7 +75,7 @@ bool LTOModule::isBitcodeFileForTarget(c
   MemoryBuffer *buffer = makeBuffer(mem, length);
   if (!buffer)
     return false;
-  return isTargetMatch(buffer, triplePrefix);
+  return isTargetMatch(StringRef((const char *)mem, length), triplePrefix);
 }
 
 bool LTOModule::isBitcodeFileForTarget(const char *path,
@@ -83,15 +83,15 @@ bool LTOModule::isBitcodeFileForTarget(c
   std::unique_ptr<MemoryBuffer> buffer;
   if (MemoryBuffer::getFile(path, buffer))
     return false;
-  return isTargetMatch(buffer.release(), triplePrefix);
+  return isTargetMatch(buffer->getBuffer(), triplePrefix);
 }
 
-/// isTargetMatch - Returns 'true' if the memory buffer is for the specified
-/// target triple.
-bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) {
-  std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
-  delete buffer;
-  return strncmp(Triple.c_str(), triplePrefix, strlen(triplePrefix)) == 0;
+/// 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;
 }
 
 LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,





More information about the llvm-commits mailing list