about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--lib/Module/Passes.h5
-rw-r--r--lib/Module/RaiseAsm.cpp24
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/Module/Passes.h b/lib/Module/Passes.h
index f9454ffd..2b1ea9bc 100644
--- a/lib/Module/Passes.h
+++ b/lib/Module/Passes.h
@@ -23,6 +23,7 @@ namespace llvm {
   class Instruction;
   class Module;
   class TargetData;
+  class TargetLowering;
   class Type;
 }
 
@@ -33,6 +34,10 @@ namespace klee {
 class RaiseAsmPass : public llvm::ModulePass {
   static char ID;
 
+#if (LLVM_VERSION_MAJOR == 2 && LLVM_VERSION_MINOR >= 9)
+  const llvm::TargetLowering *TLI;
+#endif
+
   llvm::Function *getIntrinsic(llvm::Module &M,
                                unsigned IID,
                                const llvm::Type **Tys,
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
index f89a7661..11c89009 100644
--- a/lib/Module/RaiseAsm.cpp
+++ b/lib/Module/RaiseAsm.cpp
@@ -14,6 +14,12 @@
 #if !(LLVM_VERSION_MAJOR == 2 && LLVM_VERSION_MINOR < 7)
 #include "llvm/LLVMContext.h"
 #endif
+#if (LLVM_VERSION_MAJOR == 2 && LLVM_VERSION_MINOR >= 9)
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/System/Host.h"
+#include "llvm/Target/TargetLowering.h"
+#include "llvm/Target/TargetRegistry.h"
+#endif
 
 using namespace llvm;
 using namespace klee;
@@ -32,6 +38,10 @@ Function *RaiseAsmPass::getIntrinsic(llvm::Module &M,
 bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) {
   if (CallInst *ci = dyn_cast<CallInst>(I)) {
     if (InlineAsm *ia = dyn_cast<InlineAsm>(ci->getCalledValue())) {
+#if (LLVM_VERSION_MAJOR == 2 && LLVM_VERSION_MINOR >= 9)
+      (void) ia;
+      return TLI && TLI->ExpandInlineAsm(ci);
+#else
       const std::string &as = ia->getAsmString();
       const std::string &cs = ia->getConstraintString();
       const llvm::Type *T = ci->getType();
@@ -59,6 +69,7 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) {
 #endif
         return true;
       }
+#endif
     }
   }
 
@@ -67,6 +78,19 @@ bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) {
 
 bool RaiseAsmPass::runOnModule(Module &M) {
   bool changed = false;
+
+#if (LLVM_VERSION_MAJOR == 2 && LLVM_VERSION_MINOR >= 9)
+  std::string Err;
+  std::string HostTriple = llvm::sys::getHostTriple();
+  const Target *NativeTarget = TargetRegistry::lookupTarget(HostTriple, Err);
+  if (NativeTarget == 0) {
+    llvm::errs() << "Warning: unable to select native target: " << Err << "\n";
+    TLI = 0;
+  } else {
+    TargetMachine *TM = NativeTarget->createTargetMachine(HostTriple, "");
+    TLI = TM->getTargetLowering();
+  }
+#endif
   
   for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) {
     for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) {