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 {
}
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) {
if (CallInst *call = dyn_cast<CallInst>(*use_it)) {
for (User* user : li->users()) {
if (CallInst *call = dyn_cast<CallInst>(user)) {
if (call->getCalledFunction()->getName() == "_maybeDecrefCls") {
errs() << "Found decrefcls call: " << *call << '\n';
if (!isUserDefined(cls)) {
......@@ -134,9 +134,9 @@ class ConstClassesPass : public FunctionPass {
continue;
}
GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(*use_it);
GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(user);
if (!gep) {
//errs() << "Not a gep: " << **use_it << '\n';
//errs() << "Not a gep: " << *user << '\n';
continue;
}
......@@ -147,10 +147,10 @@ class ConstClassesPass : public FunctionPass {
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) {
LoadInst *gep_load = dyn_cast<LoadInst>(*gep_use_it);
for (User* gep_user : gep->users()) {
LoadInst *gep_load = dyn_cast<LoadInst>(gep_user);
if (!gep_load) {
//errs() << "Not a load: " << **gep_use_it << '\n';
//errs() << "Not a load: " << *gep_user << '\n';
continue;
}
......
......@@ -58,20 +58,20 @@ class DeadAllocsPass : public FunctionPass {
return false;
chain.seen.insert(v);
for (Value::use_iterator use_it = v->use_begin(), use_end = v->use_end(); use_it != use_end; ++use_it) {
if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(*use_it)) {
for (User* user : v->users()) {
if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(user)) {
if (canBeRead(gep, chain))
return true;
continue;
}
if (BitCastInst *bc = dyn_cast<BitCastInst>(*use_it)) {
if (BitCastInst *bc = dyn_cast<BitCastInst>(user)) {
if (canBeRead(bc, chain))
return true;
continue;
}
if (PHINode *phi = dyn_cast<PHINode>(*use_it)) {
if (PHINode *phi = dyn_cast<PHINode>(user)) {
if (canBeRead(phi, chain))
return true;
continue;
......@@ -79,9 +79,9 @@ class DeadAllocsPass : public FunctionPass {
// 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) {
chain.deletions.push_back(si);
continue;
......@@ -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));
chain.deletions.push_back(msi);
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';
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';
return true;
}
if (LoadInst *li = dyn_cast<LoadInst>(*use_it)) {
if (LoadInst *li = dyn_cast<LoadInst>(user)) {
assert(li->getPointerOperand() == v);
chain.loads.push_back(li);
continue;
}
errs() << **use_it << '\n';
errs() << *user << '\n';
RELEASE_ASSERT(0, "");
}
......
......@@ -34,6 +34,9 @@
#include "codegen/opt/escape_analysis.h"
#include "codegen/opt/util.h"
//#undef VERBOSITY
//#define VERBOSITY(x) 2
using namespace llvm;
namespace pyston {
......@@ -82,33 +85,33 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
checked.insert(next);
for (Value::use_iterator use_it = next->use_begin(), use_end = next->use_end(); use_it != use_end; ++use_it) {
if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(*use_it)) {
for (User* user : next->users()) {
if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(user)) {
queue.push_back(gep);
chain->derived.insert(gep);
chain_by_pointer[gep] = chain;
continue;
}
if (CastInst *bc = dyn_cast<CastInst>(*use_it)) {
if (CastInst *bc = dyn_cast<CastInst>(user)) {
queue.push_back(bc);
chain->derived.insert(bc);
chain_by_pointer[bc] = chain;
continue;
}
if (PHINode *phi = dyn_cast<PHINode>(*use_it)) {
if (PHINode *phi = dyn_cast<PHINode>(user)) {
queue.push_back(phi);
chain->derived.insert(phi);
chain_by_pointer[phi] = chain;
continue;
}
if (isa<LoadInst>(*use_it)) {
if (isa<LoadInst>(user)) {
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';
chain->escape_points.insert(ret);
continue;
......@@ -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) {
} else {
assert(si->getValueOperand() == next);
......@@ -129,7 +132,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
continue;
}
if (CallInst *si = dyn_cast<CallInst>(*use_it)) {
if (CallInst *si = dyn_cast<CallInst>(user)) {
if (VERBOSITY() >= 2) errs() << "Escapes here: " << *si << '\n';
chain->escape_points.insert(si);
continue;
......@@ -137,7 +140,7 @@ bool EscapeAnalysis::runOnFunction(Function &F) {
(*use_it)->dump();
user->dump();
RELEASE_ASSERT(0, "");
}
}
......
......@@ -107,9 +107,9 @@ public:
bool changed = false;
do {
changed = false;
for (Value::use_iterator use_it = processing->use_begin(), use_end = processing->use_end(); use_it != use_end; ++use_it) {
//errs() << "looking at: " << **use_it << '\n';
changed = visit(cast<Instruction>(*use_it));
for (User* user : processing->users()) {
//errs() << "looking at: " << *user << '\n';
changed = visit(cast<Instruction>(user));
if (changed)
break;
}
......
......@@ -148,6 +148,9 @@ std::string getInplaceOpName(int op_type) {
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) {
if (op_type == AST_TYPE::Lt)
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