Skip to content

Commit

Permalink
Avoid running lowerIR multiple times.
Browse files Browse the repository at this point in the history
Summary:
When calling with different values of `SegmentRange`, we don't need
to rerun the whole `lowerIR` pipeline.
Store a flag in the `Module` and check it before running `lowerIR`.

Reviewed By: dulinriley

Differential Revision: D16766752

fbshipit-source-id: f9cb358f36a5a16f1dc6355980ce82eb31b9af8b
  • Loading branch information
avp authored and facebook-github-bot committed Sep 4, 2019
1 parent f72b687 commit 7aa1a4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/hermes/IR/IR.h
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,9 @@ class Module : public Value {
std::unordered_map<RawStringList, uint32_t, HashRawStrings>
templateObjectIDMap_;

/// Set to true when lowerIR has been called on this Module.
bool isLowered_{false};

public:
explicit Module(std::shared_ptr<Context> ctx)
: Value(ValueKind::ModuleKind), Ctx(std::move(ctx)) {}
Expand Down Expand Up @@ -1894,6 +1897,14 @@ class Module : public Value {
/// Given a list of raw strings from a template literal, get its unique id.
uint32_t getTemplateObjectID(RawStringList &&rawStrings);

bool isLowered() const {
return isLowered_;
}

void setLowered(bool isLowered) {
isLowered_ = isLowered;
}

inline iterator begin() {
return FunctionList.begin();
}
Expand Down
4 changes: 4 additions & 0 deletions lib/BCGen/HBC/HBC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const unsigned kFastRegisterAllocationThreshold = 250;
const uint64_t kRegisterAllocationMemoryLimit = 10L * 1024 * 1024;

void lowerIR(Module *M, const BytecodeGenerationOptions &options) {
if (M->isLowered())
return;

PassManager PM;
PM.addPass(new LowerLoadStoreFrameInst());
if (options.optimizationEnabled) {
Expand Down Expand Up @@ -89,6 +92,7 @@ void lowerIR(Module *M, const BytecodeGenerationOptions &options) {
PM.addHoistStartGenerator();

PM.run(M);
M->setLowered(true);

if (options.verifyIR &&
verifyModule(*M, &llvm::errs(), VerificationMode::IR_VALID)) {
Expand Down

0 comments on commit 7aa1a4e

Please sign in to comment.