PostRASchedulerList.cpp revision 4ee451de366474b9c228b4e5fa573795a715216d
172f159640382a16e036b63dcb9c0b427e6d5dc0aDale Johannesen//===----- SchedulePostRAList.cpp - list scheduler ------------------------===// 2e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// 3e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// The LLVM Compiler Infrastructure 4e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// 54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source 64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details. 7e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// 8e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen//===----------------------------------------------------------------------===// 9e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// 10e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// This implements a top-down list scheduler, using standard algorithms. 11e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// The basic approach uses a priority queue of available nodes to schedule. 12e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// One at a time, nodes are taken from the priority queue (thus in priority 13e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// order), checked for legality to schedule, and emitted if legal. 14e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// 15e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// Nodes may not be legal to schedule either due to structural hazards (e.g. 16e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// pipeline or resource constraints) or because an input to the instruction has 17e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// not completed execution. 18e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// 19e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen//===----------------------------------------------------------------------===// 20e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 21e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen#define DEBUG_TYPE "post-RA-sched" 22e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen#include "llvm/CodeGen/Passes.h" 23e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen#include "llvm/CodeGen/MachineFunctionPass.h" 24e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen#include "llvm/Support/Debug.h" 25e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen//#include "llvm/ADT/Statistic.h" 26e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen//#include <climits> 27e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen//#include <queue> 28e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen#include "llvm/Support/CommandLine.h" 29e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesenusing namespace llvm; 30e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 31e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesennamespace { 32e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen bool NoPostRAScheduling; 33e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 34e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen // When this works it will be on by default. 35e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen cl::opt<bool, true> 36e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen DisablePostRAScheduler("disable-post-RA-scheduler", 37e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen cl::desc("Disable scheduling after register allocation"), 38e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen cl::location(NoPostRAScheduling), 39e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen cl::init(true)); 40e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 41e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen class VISIBILITY_HIDDEN SchedulePostRATDList : public MachineFunctionPass { 42e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen public: 43e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen static char ID; 44e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen SchedulePostRATDList() : MachineFunctionPass((intptr_t)&ID) {} 45e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen private: 46e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen MachineFunction *MF; 47e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen const TargetMachine *TM; 48e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen public: 49e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen const char *getPassName() const { 50e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen return "Post RA top-down list latency scheduler (STUB)"; 51e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen } 52e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 53e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen bool runOnMachineFunction(MachineFunction &Fn); 54e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen }; 55e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen char SchedulePostRATDList::ID = 0; 56e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen} 57e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 58e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesenbool SchedulePostRATDList::runOnMachineFunction(MachineFunction &Fn) { 59e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen if (NoPostRAScheduling) 60e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen return true; 61e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 62e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen DOUT << "SchedulePostRATDList\n"; 63e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen MF = &Fn; 64e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen TM = &MF->getTarget(); 65e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 66e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen // Loop over all of the basic blocks 67e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end(); 68e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen MBB != MBBe; ++MBB) 69e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen ; 70e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 71e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen return true; 72e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen} 73e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 74e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 75e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen//===----------------------------------------------------------------------===// 76e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen// Public Constructor Functions 77e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen//===----------------------------------------------------------------------===// 78e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen 79e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale JohannesenFunctionPass *llvm::createPostRAScheduler() { 80e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen return new SchedulePostRATDList(); 81e7e7d0d7e39d0c7c659d26b97e8081fce0fcd749Dale Johannesen} 82