47 std::string get_filename(
methodinfo *m,
jitdata *jd, std::string prefix =
"cfg_", std::string suffix=
".dot");
48 std::string get_filename(
methodinfo *m,
jitdata *jd, std::string prefix, std::string suffix)
50 std::string filename = prefix;
57 for (
size_t i = filename.find_first_of(
'/');
58 i != std::string::npos;
59 i = filename.find_first_of(
'/',
i+1)) {
60 filename.replace(
i,1,1,
'.');
62 const char *unchar =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.";
63 for (
size_t i = filename.find_first_not_of(unchar);
64 i != std::string::npos;
65 i = filename.find_first_not_of(unchar,
i+1)) {
66 filename.replace(
i,1,1,
'_');
79 class SSAGraph :
public PrintableGraph<Method*,Instruction*> {
92 SSAGraph(
const Method &
M, std::string
name, GlobalSchedule *
sched = NULL,
bool verbose =
true)
96 SSAGraph(
const Method &
M, std::string
name,
bool verbose)
97 : M(M), name(name),
sched(NULL), verbose(verbose) {
101 for(Method::InstructionListTy::const_iterator
i =
M.begin(),
102 e =
M.end();
i !=
e; ++
i) {
107 if (!
verbose && (!(I->to_BeginInst() || I->to_EndInst())) )
112 for(Instruction::OperandListTy::const_iterator ii = I->op_begin(), ee = I->op_end();
116 Instruction *II = (*ii)->to_Instruction();
118 EdgeType edge = std::make_pair(II,I);
125 for(Instruction::DepListTy::const_iterator ii = I->dep_begin(), ee = I->dep_end();
127 Instruction *II = (*ii);
129 EdgeType edge = std::make_pair(II,I);
136 EndInst *EI = I->to_EndInst();
138 for(EndInst::SuccessorListTy::const_iterator ii = EI->succ_begin(), ee = EI->succ_end();
140 Value *v = ii->get();
142 Instruction *II = ii->get()->to_Instruction();
144 EdgeType edge = std::make_pair(EI,II);
150 EdgeType edge = std::make_pair(EI->get_BeginInst(),EI);
155 BeginInst *bi = (
sched) ?
sched->get(I) : I->get_BeginInst();
157 clusters[(
unsigned long)bi].insert(I);
162 virtual unsigned long getNodeID(Instruction *
const &node)
const {
163 return node->get_id();
166 virtual OStream& getGraphName(OStream&
OS)
const {
170 virtual OStream& getNodeLabel(OStream&
OS, Instruction *
const &node)
const {
172 OS <<
"[" << node->get_id() <<
": " << node->get_name() <<
" ("
176 for(Instruction::OperandListTy::const_iterator ii = node->op_begin(), ee = node->op_end();
181 Instruction *II = (*ii)->to_Instruction();
182 OS <<
"[" << II->get_id() <<
"]";
191 StringBuf getNodeAttributes(
const SSAGraph::NodeType &node)
const ;
193 StringBuf getEdgeLabel(
const SSAGraph::EdgeType &
e)
const ;
196 OStream& getEdgeAttributes(OStream& OS,
const SSAGraph::EdgeType &
e)
const;
199 class EdgeAttributeVisitor :
public InstructionVisitor {
204 EdgeAttributeVisitor(OStream &OS, BeginInst *
target)
205 : OS(OS), target(target) {}
206 virtual void visit_default(Instruction *I) {
211 virtual void visit(TABLESWITCHInst* I);
215 void EdgeAttributeVisitor::visit(TABLESWITCHInst* I) {
217 if (index == -1)
return;
218 if (std::size_t(index) == I->succ_size() - 1) {
219 OS <<
"label=\"default\"";
222 OS <<
"label=\"" << index <<
"\"";
226 inline OStream& SSAGraph::getEdgeAttributes(OStream& OS,
const SSAGraph::EdgeType &
e)
const {
234 OS <<
"style=dashed,";
236 BeginInst* begin = e.second->to_BeginInst();
238 EdgeAttributeVisitor visitor(OS,begin);
239 e.first->accept(visitor,
true);
263 std::string filename =
"ssa_";
264 filename+=name+
".dot";
287 std::string filename =
"basicblocks_";
288 filename+=name+
".dot";
310 std::string filename =
"bb_sched_";
315 filename +=
"_" + name +
".dot";
GlobalSchedule TODO: more info.
Option< bool > schedule_printer_enabled("GlobalSchedulePrinterPass","compiler2: enable GlobalSchedulePrinterPass", false,::cacao::option::xx_root())
static PassRegistry< GlobalSchedulePrinterPass< ScheduleEarlyPass > > X_early("GlobalSchedulePrinterPass(early)")
static void print(const char *filename, const PrintableGraphTy &G)
const GlobalSchedule * sched
virtual PassUsage & get_PassUsage(PassUsage &PA) const
Set the requirements for the pass.
alloc::set< EdgeType >::type sched_dep
virtual bool run(JITData &JD)
Run the Pass.
JNIEnv jclass jobject const char * name
jitdata * get_jitdata() const
std::set< EdgeType > & edges
const char * get_type_name(const Type::TypeID &type)
virtual bool run(JITData &JD)
Run the Pass.
static PassRegistry< GlobalSchedulePrinterPass< ScheduleLatePass > > X_late("GlobalSchedulePrinterPass(late)")
static PassRegistry< BasicBlockPrinterPass > Z("BasicBlockPrinterPass")
Stores the interdependencies of a pass.
virtual void visit(LoadInst *I, bool copyOperands)
virtual PassUsage & get_PassUsage(PassUsage &PA) const
Set the requirements for the pass.
virtual PassUsage & get_PassUsage(PassUsage &PA) const
Set the requirements for the pass.
static PassRegistry< GlobalSchedulePrinterPass< ScheduleClickPass > > X_click("GlobalSchedulePrinterPass(click)")
virtual bool run(JITData &JD)
Run the Pass.
GlobalSchedulePrinterPass TODO: more info.
byte_iterator begin() const
Represents the result of the addition of a certain IR-variable with a certain constant.
static Option< bool > enabled
alloc::set< EdgeType >::type cfg_edges
alloc::set< EdgeType >::type data_dep
static Option< bool > enabled
alloc::set< EdgeType >::type begin2end_edges
static PassRegistry< BasicBlockSchedulingPass > X("BasicBlockSchedulingPass")
void add_requires()
PassName is required.