Skip to content

Commit f4422ef

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Remove jit::hir::BasicBlock::cfg
Summary: Remove the reverse-reference from BasicBlock to CFG. It isn't needed, all places where we need the CFG it is already accessible. Reviewed By: yoney Differential Revision: D88279074 fbshipit-source-id: e9a7adfbe3d1ba0416fd4ea8a6bb7d4c408d88b4
1 parent 47d789d commit f4422ef

8 files changed

Lines changed: 17 additions & 25 deletions

File tree

cinderx/Jit/hir/builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ InlineResult HIRBuilder::inlineHIR(
736736

737737
// The caller function has already been converted to SSA form and all HIR
738738
// passes require input to be in SSA form. SSAify the inlined function.
739-
SSAify{}.Run(entry_block, &caller->env);
739+
SSAify{}.Run(*caller, entry_block);
740740

741741
// Re-link the CFG.
742742
for (auto& [fs, parent] : framestate_parent) {

cinderx/Jit/hir/hir.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace jit::hir {
1717
#ifndef _LIBCPP_VERSION
1818
static_assert(sizeof(Function) == 48 * kPointerSize);
1919
static_assert(sizeof(CFG) == 6 * kPointerSize);
20-
static_assert(sizeof(BasicBlock) == 21 * kPointerSize);
20+
static_assert(sizeof(BasicBlock) == 20 * kPointerSize);
2121
static_assert(sizeof(Instr) == 6 * kPointerSize);
2222
#endif
2323

@@ -1041,7 +1041,6 @@ void BasicBlock::removePhiPredecessor(BasicBlock* old_pred) {
10411041

10421042
BasicBlock* CFG::AllocateBlock() {
10431043
auto block = AllocateUnlinkedBlock();
1044-
block->cfg = this;
10451044
blocks.PushBack(*block);
10461045
return block;
10471046
}
@@ -1054,14 +1053,11 @@ BasicBlock* CFG::AllocateUnlinkedBlock() {
10541053
}
10551054

10561055
void CFG::InsertBlock(BasicBlock* block) {
1057-
block->cfg = this;
10581056
blocks.PushBack(*block);
10591057
}
10601058

10611059
void CFG::RemoveBlock(BasicBlock* block) {
1062-
JIT_DCHECK(block->cfg == this, "block doesn't belong to us");
10631060
block->cfg_node.Unlink();
1064-
block->cfg = nullptr;
10651061
}
10661062

10671063
BasicBlock* CFG::splitAfter(Instr& target) {

cinderx/Jit/hir/hir.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,7 @@ class CFG;
37653765
class BasicBlock {
37663766
public:
37673767
BasicBlock() : BasicBlock(0) {}
3768-
explicit BasicBlock(int id_) : id(id_), cfg(nullptr) {}
3768+
explicit BasicBlock(int id_) : id(id_) {}
37693769
~BasicBlock();
37703770

37713771
// Replace any references to old_pred in this block's Phis with new_pred.
@@ -3910,9 +3910,6 @@ class BasicBlock {
39103910

39113911
int id;
39123912

3913-
// CFG that this block belongs to; may be NULL
3914-
CFG* cfg;
3915-
39163913
// Basic blocks belong to a list of all blocks in their CFG
39173914
IntrusiveListNode cfg_node;
39183915

cinderx/Jit/hir/pass.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,14 @@ Type outputType(const Instr& instr) {
542542
instr, [&](std::size_t ind) { return instr.GetOperand(ind)->type(); });
543543
}
544544

545-
void reflowTypes(Environment* env, BasicBlock* start) {
545+
void reflowTypes(Function& func) {
546+
reflowTypes(func, func.cfg.entry_block);
547+
}
548+
549+
void reflowTypes(Function& func, BasicBlock* start) {
546550
// First, reset all types to Bottom so Phi inputs from back edges don't
547551
// contribute to the output type of the Phi until they've been processed.
548-
for (auto& pair : env->GetRegisters()) {
552+
for (auto& pair : func.env.GetRegisters()) {
549553
pair.second->set_type(TBottom);
550554
}
551555

@@ -564,7 +568,7 @@ void reflowTypes(Environment* env, BasicBlock* start) {
564568
type,
565569
instr,
566570
value->type(),
567-
*start->cfg);
571+
func.cfg);
568572
}
569573

570574
auto dst = instr.output();
@@ -584,10 +588,6 @@ void reflowTypes(Environment* env, BasicBlock* start) {
584588
}
585589
}
586590

587-
void reflowTypes(Function& func) {
588-
reflowTypes(&func.env, func.cfg.entry_block);
589-
}
590-
591591
bool removeTrampolineBlocks(CFG* cfg) {
592592
std::vector<BasicBlock*> trampolines;
593593
for (auto& block : cfg->blocks) {

cinderx/Jit/hir/pass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Type outputType(
5656
// SSAify and any optimizations that could refine the output type of an
5757
// instruction.
5858
void reflowTypes(Function& func);
59-
void reflowTypes(Environment* env, BasicBlock* start);
59+
void reflowTypes(Function& func, BasicBlock* start);
6060

6161
// Remove any blocks that consist of a single jump to another block.
6262
bool removeTrampolineBlocks(CFG* cfg);

cinderx/Jit/hir/ssa.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool checkCFG(const Function& func, std::ostream& err) {
6363
auto block = queue.front();
6464
queue.pop();
6565

66-
if (block->cfg != &func.cfg) {
66+
if (!block->cfg_node.isLinked()) {
6767
fmt::print(err, "ERROR: Reachable bb {} isn't part of CFG\n", block->id);
6868
return false;
6969
}
@@ -274,15 +274,15 @@ bool checkFunc(const Function& func, std::ostream& err) {
274274
}
275275

276276
void SSAify::Run(Function& irfunc) {
277-
Run(irfunc.cfg.entry_block, &irfunc.env);
277+
Run(irfunc, irfunc.cfg.entry_block);
278278
PhiElimination{}.Run(irfunc);
279279
}
280280

281281
// This implements the algorithm outlined in "Simple and Efficient Construction
282282
// of Static Single Assignment Form"
283283
// https://pp.info.uni-karlsruhe.de/uploads/publikationen/braun13cc.pdf
284-
void SSAify::Run(BasicBlock* start, Environment* env) {
285-
env_ = env;
284+
void SSAify::Run(Function& irfunc, BasicBlock* start) {
285+
env_ = &irfunc.env;
286286

287287
auto blocks = CFG::GetRPOTraversal(start);
288288
auto ssa_basic_blocks = initSSABasicBlocks(blocks);
@@ -340,7 +340,7 @@ void SSAify::Run(BasicBlock* start, Environment* env) {
340340
delete ssablock;
341341
}
342342

343-
reflowTypes(env, start);
343+
reflowTypes(irfunc, start);
344344
}
345345

346346
Register* SSAify::getDefine(SSABasicBlock* ssablock, Register* reg) {

cinderx/Jit/hir/ssa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SSAify : public Pass {
4040
SSAify() : Pass("SSAify"), env_(nullptr) {}
4141

4242
void Run(Function& irfunc) override;
43-
void Run(BasicBlock* block, Environment* env);
43+
void Run(Function& irfunc, BasicBlock* block);
4444

4545
static std::unique_ptr<SSAify> Factory() {
4646
return std::make_unique<SSAify>();

cinderx/RuntimeTests/hir_parser_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ TEST_F(HIRParserTest, ParsesHIR) {
6363
auto block = func->cfg.entry_block;
6464
ASSERT_NE(block, nullptr);
6565
ASSERT_EQ(block->id, 0);
66-
ASSERT_EQ(block->cfg, &func->cfg);
6766

6867
auto blocks_it = func->cfg.blocks.begin();
6968
auto blocks_end = func->cfg.blocks.end();

0 commit comments

Comments
 (0)