Commit 4fa5406f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Update optimization passes to use the latest LLVM changes

LLVM had some breaking changes that I didn't notice; on the plus
side this new range-iteration style is much nicer.
parent 9fc57854
...@@ -121,8 +121,8 @@ class ConstClassesPass : public FunctionPass { ...@@ -121,8 +121,8 @@ class ConstClassesPass : public FunctionPass {
} }
std::vector<Instruction*> to_remove; std::vector<Instruction*> to_remove;
for (Value::use_iterator use_it = li->use_begin(), use_end = li->use_end(); use_it != use_end; ++use_it) { for (User* user : li->users()) {
if (CallInst *call = dyn_cast<CallInst>(*use_it)) { if (CallInst *call = dyn_cast<CallInst>(user)) {
if (call->getCalledFunction()->getName() == "_maybeDecrefCls") { if (call->getCalledFunction()->getName() == "_maybeDecrefCls") {
errs() << "Found decrefcls call: " << *call << '\n'; errs() << "Found decrefcls call: " << *call << '\n';
if (!isUserDefined(cls)) { if (!isUserDefined(cls)) {
...@@ -134,9 +134,9 @@ class ConstClassesPass : public FunctionPass { ...@@ -134,9 +134,9 @@ class ConstClassesPass : public FunctionPass {
continue; continue;
} }
GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(*use_it); GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(user);
if (!gep) { if (!gep) {
//errs() << "Not a gep: " << **use_it << '\n'; //errs() << "Not a gep: " << *user << '\n';
continue; continue;
} }
...@@ -147,10 +147,10 @@ class ConstClassesPass : public FunctionPass { ...@@ -147,10 +147,10 @@ class ConstClassesPass : public FunctionPass {
errs() << "Found a gep at offset " << offset << ": " << *gep << '\n'; errs() << "Found a gep at offset " << offset << ": " << *gep << '\n';
for (Value::use_iterator gep_use_it = gep->use_begin(), gep_use_end = gep->use_end(); gep_use_it != gep_use_end; ++gep_use_it) { for (User* gep_user : gep->users()) {
LoadInst *gep_load = dyn_cast<LoadInst>(*gep_use_it); LoadInst *gep_load = dyn_cast<LoadInst>(gep_user);
if (!gep_load) { if (!gep_load) {
//errs() << "Not a load: " << **gep_use_it << '\n'; //errs() << "Not a load: " << *gep_user << '\n';
continue; continue;
} }
......
...@@ -58,20 +58,20 @@ class DeadAllocsPass : public FunctionPass { ...@@ -58,20 +58,20 @@ class DeadAllocsPass : public FunctionPass {
return false; return false;
chain.seen.insert(v); chain.seen.insert(v);
for (Value::use_iterator use_it = v->use_begin(), use_end = v->use_end(); use_it != use_end; ++use_it) { for (User* user : v->users()) {
if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(*use_it)) { if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(user)) {
if (canBeRead(gep, chain)) if (canBeRead(gep, chain))
return true; return true;
continue; continue;
} }
if (BitCastInst *bc = dyn_cast<BitCastInst>(*use_it)) { if (BitCastInst *bc = dyn_cast<BitCastInst>(user)) {
if (canBeRead(bc, chain)) if (canBeRead(bc, chain))
return true; return true;
continue; continue;
} }
if (PHINode *phi = dyn_cast<PHINode>(*use_it)) { if (PHINode *phi = dyn_cast<PHINode>(user)) {
if (canBeRead(phi, chain)) if (canBeRead(phi, chain))
return true; return true;
continue; continue;
...@@ -79,9 +79,9 @@ class DeadAllocsPass : public FunctionPass { ...@@ -79,9 +79,9 @@ class DeadAllocsPass : public FunctionPass {
// Can't call canBeRead after this point: // Can't call canBeRead after this point:
chain.seen.insert(cast<Instruction>(*use_it)); chain.seen.insert(cast<Instruction>(user));
if (StoreInst *si = dyn_cast<StoreInst>(*use_it)) { if (StoreInst *si = dyn_cast<StoreInst>(user)) {
if (si->getPointerOperand() == v) { if (si->getPointerOperand() == v) {
chain.deletions.push_back(si); chain.deletions.push_back(si);
continue; continue;
...@@ -91,29 +91,29 @@ class DeadAllocsPass : public FunctionPass { ...@@ -91,29 +91,29 @@ class DeadAllocsPass : public FunctionPass {
} }
} }
if (MemSetInst *msi = dyn_cast<MemSetInst>(*use_it)) { if (MemSetInst *msi = dyn_cast<MemSetInst>(user)) {
assert(v == msi->getArgOperand(0)); assert(v == msi->getArgOperand(0));
chain.deletions.push_back(msi); chain.deletions.push_back(msi);
continue; continue;
} }
if (CallInst *si = dyn_cast<CallInst>(*use_it)) { if (CallInst *si = dyn_cast<CallInst>(user)) {
if (VERBOSITY() >= 2) errs() << "Not dead; used here: " << *si << '\n'; if (VERBOSITY() >= 2) errs() << "Not dead; used here: " << *si << '\n';
return true; return true;
} }
if (ReturnInst *ret = dyn_cast<ReturnInst>(*use_it)) { if (ReturnInst *ret = dyn_cast<ReturnInst>(user)) {
if (VERBOSITY() >= 2) errs() << "Not dead; used here: " << *ret << '\n'; if (VERBOSITY() >= 2) errs() << "Not dead; used here: " << *ret << '\n';
return true; return true;
} }
if (LoadInst *li = dyn_cast<LoadInst>(*use_it)) { if (LoadInst *li = dyn_cast<LoadInst>(user)) {
assert(li->getPointerOperand() == v); assert(li->getPointerOperand() == v);
chain.loads.push_back(li); chain.loads.push_back(li);
continue; continue;
} }
errs() << **use_it << '\n'; errs() << *user << '\n';
RELEASE_ASSERT(0, ""); RELEASE_ASSERT(0, "");
} }
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
#include "codegen/opt/escape_analysis.h" #include "codegen/opt/escape_analysis.h"
#include "codegen/opt/util.h" #include "codegen/opt/util.h"
//#undef VERBOSITY
//#define VERBOSITY(x) 2
using namespace llvm; using namespace llvm;
namespace pyston { namespace pyston {
...@@ -82,33 +85,33 @@ bool EscapeAnalysis::runOnFunction(Function &F) { ...@@ -82,33 +85,33 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
checked.insert(next); checked.insert(next);
for (Value::use_iterator use_it = next->use_begin(), use_end = next->use_end(); use_it != use_end; ++use_it) { for (User* user : next->users()) {
if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(*use_it)) { if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(user)) {
queue.push_back(gep); queue.push_back(gep);
chain->derived.insert(gep); chain->derived.insert(gep);
chain_by_pointer[gep] = chain; chain_by_pointer[gep] = chain;
continue; continue;
} }
if (CastInst *bc = dyn_cast<CastInst>(*use_it)) { if (CastInst *bc = dyn_cast<CastInst>(user)) {
queue.push_back(bc); queue.push_back(bc);
chain->derived.insert(bc); chain->derived.insert(bc);
chain_by_pointer[bc] = chain; chain_by_pointer[bc] = chain;
continue; continue;
} }
if (PHINode *phi = dyn_cast<PHINode>(*use_it)) { if (PHINode *phi = dyn_cast<PHINode>(user)) {
queue.push_back(phi); queue.push_back(phi);
chain->derived.insert(phi); chain->derived.insert(phi);
chain_by_pointer[phi] = chain; chain_by_pointer[phi] = chain;
continue; continue;
} }
if (isa<LoadInst>(*use_it)) { if (isa<LoadInst>(user)) {
continue; continue;
} }
if (ReturnInst *ret = dyn_cast<ReturnInst>(*use_it)) { if (ReturnInst *ret = dyn_cast<ReturnInst>(user)) {
if (VERBOSITY() >= 2) errs() << "Not dead; used here: " << *ret << '\n'; if (VERBOSITY() >= 2) errs() << "Not dead; used here: " << *ret << '\n';
chain->escape_points.insert(ret); chain->escape_points.insert(ret);
continue; continue;
...@@ -119,7 +122,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) { ...@@ -119,7 +122,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
if (StoreInst *si = dyn_cast<StoreInst>(*use_it)) { if (StoreInst *si = dyn_cast<StoreInst>(user)) {
if (si->getPointerOperand() == next) { if (si->getPointerOperand() == next) {
} else { } else {
assert(si->getValueOperand() == next); assert(si->getValueOperand() == next);
...@@ -129,7 +132,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) { ...@@ -129,7 +132,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
continue; continue;
} }
if (CallInst *si = dyn_cast<CallInst>(*use_it)) { if (CallInst *si = dyn_cast<CallInst>(user)) {
if (VERBOSITY() >= 2) errs() << "Escapes here: " << *si << '\n'; if (VERBOSITY() >= 2) errs() << "Escapes here: " << *si << '\n';
chain->escape_points.insert(si); chain->escape_points.insert(si);
continue; continue;
...@@ -137,7 +140,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) { ...@@ -137,7 +140,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
(*use_it)->dump(); user->dump();
RELEASE_ASSERT(0, ""); RELEASE_ASSERT(0, "");
} }
} }
......
...@@ -107,9 +107,9 @@ public: ...@@ -107,9 +107,9 @@ public:
bool changed = false; bool changed = false;
do { do {
changed = false; changed = false;
for (Value::use_iterator use_it = processing->use_begin(), use_end = processing->use_end(); use_it != use_end; ++use_it) { for (User* user : processing->users()) {
//errs() << "looking at: " << **use_it << '\n'; //errs() << "looking at: " << *user << '\n';
changed = visit(cast<Instruction>(*use_it)); changed = visit(cast<Instruction>(user));
if (changed) if (changed)
break; break;
} }
......
...@@ -148,6 +148,9 @@ std::string getInplaceOpName(int op_type) { ...@@ -148,6 +148,9 @@ std::string getInplaceOpName(int op_type) {
return "__i" + normal_name.substr(2); return "__i" + normal_name.substr(2);
} }
// Maybe better name is "swapped" -- it's what the runtime will try if the normal op
// name fails, it will switch the order of the lhs/rhs and call the reverse op.
// Calling it "reverse" because that's what I'm assuming the 'r' stands for in ex __radd__
std::string getReverseOpName(int op_type) { std::string getReverseOpName(int op_type) {
if (op_type == AST_TYPE::Lt) if (op_type == AST_TYPE::Lt)
return getOpName(AST_TYPE::GtE); return getOpName(AST_TYPE::GtE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment