aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Module/RaiseAsm.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-05-21 04:36:41 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-05-21 04:36:41 +0000
commit6f290d8f9e9d7faac295cb51fc96884a18f4ded4 (patch)
tree46e7d426abc0c9f06ac472ac6f7f9e661b5d78cb /lib/Module/RaiseAsm.cpp
parenta55960edd4dcd7535526de8d2277642522aa0209 (diff)
downloadklee-6f290d8f9e9d7faac295cb51fc96884a18f4ded4.tar.gz
Initial KLEE checkin.
- Lots more tweaks, documentation, and web page content is needed, but this should compile & work on OS X & Linux. git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@72205 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Module/RaiseAsm.cpp')
-rw-r--r--lib/Module/RaiseAsm.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/Module/RaiseAsm.cpp b/lib/Module/RaiseAsm.cpp
new file mode 100644
index 00000000..67fbf8ae
--- /dev/null
+++ b/lib/Module/RaiseAsm.cpp
@@ -0,0 +1,69 @@
+//===-- RaiseAsm.cpp ------------------------------------------------------===//
+//
+// The KLEE Symbolic Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Passes.h"
+
+#include "llvm/InlineAsm.h"
+
+using namespace llvm;
+using namespace klee;
+
+char RaiseAsmPass::ID = 0;
+
+Function *RaiseAsmPass::getIntrinsic(llvm::Module &M,
+ unsigned IID,
+ const Type **Tys,
+ unsigned NumTys) {
+ return Intrinsic::getDeclaration(&M, (llvm::Intrinsic::ID) IID, Tys, NumTys);
+}
+
+// FIXME: This should just be implemented as a patch to
+// X86TargetAsmInfo.cpp, then everyone will benefit.
+bool RaiseAsmPass::runOnInstruction(Module &M, Instruction *I) {
+ if (CallInst *ci = dyn_cast<CallInst>(I)) {
+ if (InlineAsm *ia = dyn_cast<InlineAsm>(ci->getCalledValue())) {
+ const std::string &as = ia->getAsmString();
+ const std::string &cs = ia->getConstraintString();
+ const llvm::Type *T = ci->getType();
+
+ // bswaps
+ if (ci->getNumOperands() == 2 &&
+ T == ci->getOperand(1)->getType() &&
+ ((T == llvm::Type::Int16Ty &&
+ as == "rorw $$8, ${0:w}" &&
+ cs == "=r,0,~{dirflag},~{fpsr},~{flags},~{cc}") ||
+ (T == llvm::Type::Int32Ty &&
+ as == "rorw $$8, ${0:w};rorl $$16, $0;rorw $$8, ${0:w}" &&
+ cs == "=r,0,~{dirflag},~{fpsr},~{flags},~{cc}"))) {
+ llvm::Value *Arg0 = ci->getOperand(1);
+ Function *F = getIntrinsic(M, Intrinsic::bswap, Arg0->getType());
+ ci->setOperand(0, F);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool RaiseAsmPass::runOnModule(Module &M) {
+ bool changed = false;
+
+ for (Module::iterator fi = M.begin(), fe = M.end(); fi != fe; ++fi) {
+ for (Function::iterator bi = fi->begin(), be = fi->end(); bi != be; ++bi) {
+ for (BasicBlock::iterator ii = bi->begin(), ie = bi->end(); ii != ie;) {
+ Instruction *i = ii;
+ ++ii;
+ changed |= runOnInstruction(M, i);
+ }
+ }
+ }
+
+ return changed;
+}