[vmkit-commits] [vmkit] r144534 - /vmkit/trunk/mmtk/magic/LowerMagic.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Nov 14 03:46:22 PST 2011


Author: geoffray
Date: Mon Nov 14 05:46:21 2011
New Revision: 144534

URL: http://llvm.org/viewvc/llvm-project?rev=144534&view=rev
Log:
Unbreak MMTk compilation by recognizing the hardware null check instruction.


Modified:
    vmkit/trunk/mmtk/magic/LowerMagic.cpp

Modified: vmkit/trunk/mmtk/magic/LowerMagic.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerMagic.cpp?rev=144534&r1=144533&r2=144534&view=diff
==============================================================================
--- vmkit/trunk/mmtk/magic/LowerMagic.cpp (original)
+++ vmkit/trunk/mmtk/magic/LowerMagic.cpp Mon Nov 14 05:46:21 2011
@@ -20,6 +20,8 @@
 
 #include <cstdio>
 
+#include "mvm/System.h"
+
 using namespace llvm;
 
 namespace vmmagic {
@@ -353,21 +355,39 @@
 
 
 static bool removePotentialNullCheck(BasicBlock* Cur, Value* Obj) {
-  BasicBlock* BB = Cur->getUniquePredecessor();
-  LLVMContext& Context = Cur->getParent()->getContext();
-  if (BB) {
-    Instruction* T = BB->getTerminator();
-    if (dyn_cast<BranchInst>(T) && T != BB->begin()) {
-      BasicBlock::iterator BIE = BB->end();
-      --BIE; // Terminator
-      --BIE; // Null test
-      if (ICmpInst* IE = dyn_cast<ICmpInst>(BIE)) {
-        if (IE->getPredicate() == ICmpInst::ICMP_EQ &&
-            IE->getOperand(0) == Obj &&
-            IE->getOperand(1) == Constant::getNullValue(Obj->getType())) {
-          BIE->replaceAllUsesWith(ConstantInt::getFalse(Context));
-          BIE->eraseFromParent();
-          return true;
+  if (!Obj->getType()->isPointerTy()) return false;
+
+  if (mvm::System::SupportsHardwareNullCheck()) {
+    for (Value::use_iterator I = Obj->use_begin(), E = Obj->use_end(); I != E; I++) {
+      if (GetElementPtrInst* GE = dyn_cast<GetElementPtrInst>(*I)) {
+        for (Value::use_iterator II = GE->use_begin(), EE = GE->use_end(); II != EE; II++) {
+          if (LoadInst* LI = dyn_cast<LoadInst>(*II)) {
+            if (LI->isVolatile()) {
+              assert(LI->use_empty());
+              LI->eraseFromParent();
+              return true;
+            }
+          }
+        }
+      }
+    }
+  } else {
+    BasicBlock* BB = Cur->getUniquePredecessor();
+    LLVMContext& Context = Cur->getParent()->getContext();
+    if (BB) {
+      Instruction* T = BB->getTerminator();
+      if (dyn_cast<BranchInst>(T) && T != BB->begin()) {
+        BasicBlock::iterator BIE = BB->end();
+        --BIE; // Terminator
+        --BIE; // Null test
+        if (ICmpInst* IE = dyn_cast<ICmpInst>(BIE)) {
+          if (IE->getPredicate() == ICmpInst::ICMP_EQ &&
+              IE->getOperand(0) == Obj &&
+              IE->getOperand(1) == Constant::getNullValue(Obj->getType())) {
+            BIE->replaceAllUsesWith(ConstantInt::getFalse(Context));
+            BIE->eraseFromParent();
+            return true;
+          }
         }
       }
     }





More information about the vmkit-commits mailing list