mirror of https://github.com/exaloop/codon.git
34 lines
754 B
C++
34 lines
754 B
C++
#pragma once
|
|
|
|
#include "sir/transform/pass.h"
|
|
|
|
namespace codon {
|
|
namespace ir {
|
|
namespace transform {
|
|
namespace cleanup {
|
|
|
|
/// Demotes global variables that are used in only one
|
|
/// function to locals of that function.
|
|
class GlobalDemotionPass : public Pass {
|
|
private:
|
|
/// number of variables we've demoted
|
|
int numDemotions;
|
|
|
|
public:
|
|
static const std::string KEY;
|
|
|
|
/// Constructs a global variable demotion pass
|
|
GlobalDemotionPass() : Pass(), numDemotions(0) {}
|
|
|
|
std::string getKey() const override { return KEY; }
|
|
void run(Module *v) override;
|
|
|
|
/// @return number of variables we've demoted
|
|
int getNumDemotions() const { return numDemotions; }
|
|
};
|
|
|
|
} // namespace cleanup
|
|
} // namespace transform
|
|
} // namespace ir
|
|
} // namespace codon
|