Fix uses of reserved identifiers starting with an underscore followed by an uppercase...
[oota-llvm.git] / lib / CodeGen / StackMapLivenessAnalysis.cpp
index 788b83416badab7ded48c34cbb640475dfe37727..d838f8a064e180d9b93911f439861f9d1ababea6 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG_TYPE "stackmaps"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/StackMapLivenessAnalysis.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
 
 using namespace llvm;
 
+#define DEBUG_TYPE "stackmaps"
+
+namespace llvm {
+cl::opt<bool> EnablePatchPointLiveness("enable-patchpoint-liveness",
+  cl::Hidden, cl::init(true),
+  cl::desc("Enable PatchPoint Liveness Analysis Pass"));
+}
 
 STATISTIC(NumStackMapFuncVisited, "Number of functions visited");
 STATISTIC(NumStackMapFuncSkipped, "Number of functions skipped");
@@ -52,15 +60,18 @@ void StackMapLiveness::getAnalysisUsage(AnalysisUsage &AU) const {
 }
 
 /// Calculate the liveness information for the given machine function.
-bool StackMapLiveness::runOnMachineFunction(MachineFunction &_MF) {
-  DEBUG(dbgs() << "********** COMPUTING STACKMAP LIVENESS: "
-               << _MF.getName() << " **********\n");
-  MF = &_MF;
-  TRI = MF->getTarget().getRegisterInfo();
+bool StackMapLiveness::runOnMachineFunction(MachineFunction &MF) {
+  if (!EnablePatchPointLiveness)
+    return false;
+
+  DEBUG(dbgs() << "********** COMPUTING STACKMAP LIVENESS: " << MF.getName()
+               << " **********\n");
+  this->MF = &MF;
+  TRI = MF.getSubtarget().getRegisterInfo();
   ++NumStackMapFuncVisited;
 
-  // Skip this function if there are no stackmaps.
-  if (!MF->getFrameInfo()->hasStackMap()) {
+  // Skip this function if there are no patchpoints to process.
+  if (!MF.getFrameInfo()->hasPatchPoint()) {
     ++NumStackMapFuncSkipped;
     return false;
   }
@@ -78,17 +89,16 @@ bool StackMapLiveness::calculateLiveness() {
     LiveRegs.addLiveOuts(MBBI);
     bool HasStackMap = false;
     // Reverse iterate over all instructions and add the current live register
-    // set to an instruction if we encounter a stackmap or patchpoint
-    // instruction.
+    // set to an instruction if we encounter a patchpoint instruction.
     for (MachineBasicBlock::reverse_iterator I = MBBI->rbegin(),
          E = MBBI->rend(); I != E; ++I) {
-      if (I->getOpcode() == TargetOpcode::STACKMAP ||
-          I->getOpcode() == TargetOpcode::PATCHPOINT) {
+      if (I->getOpcode() == TargetOpcode::PATCHPOINT) {
         addLiveOutSetToMI(*I);
         HasChanged = true;
         HasStackMap = true;
         ++NumStackMaps;
       }
+      DEBUG(dbgs() << "   " << LiveRegs << "   " << *I);
       LiveRegs.stepBackward(*I);
     }
     ++NumBBsVisited;
@@ -103,8 +113,6 @@ void StackMapLiveness::addLiveOutSetToMI(MachineInstr &MI) {
   uint32_t *Mask = createRegisterMask();
   MachineOperand MO = MachineOperand::CreateRegLiveOut(Mask);
   MI.addOperand(*MF, MO);
-  DEBUG(dbgs() << "   " << MI);
-  DEBUG(printLiveOutSet(dbgs()));
 }
 
 /// Create a register mask and initialize it with the registers from the
@@ -115,14 +123,7 @@ uint32_t *StackMapLiveness::createRegisterMask() const {
   for (LivePhysRegs::const_iterator RI = LiveRegs.begin(), RE = LiveRegs.end();
        RI != RE; ++RI)
     Mask[*RI / 32] |= 1U << (*RI % 32);
-  return Mask;
-}
 
-/// Print the current register live set for debugging.
-void StackMapLiveness::printLiveOutSet(raw_ostream &OS) const {
-  OS << "   Register live-out:";
-  for (LivePhysRegs::const_iterator RI = LiveRegs.begin(), RE = LiveRegs.end();
-       RI != RE; ++RI)
-    OS << " " << TRI->getName(*RI);
-  OS << "\n";
+  TRI->adjustStackMapLiveOutMask(Mask);
+  return Mask;
 }