Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
75 lines (58 loc) · 1.99 KB

File metadata and controls

75 lines (58 loc) · 1.99 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "llvh/Support/Casting.h"
#include "llvh/Support/SourceMgr.h"
#include "llvh/Support/YAMLParser.h"
#include "hermes/AST/Context.h"
#include "hermes/BCGen/RegAlloc.h"
#include "gtest/gtest.h"
using namespace hermes;
namespace {
TEST(RegisterAllocatorTest, RegisterFileTest) {
RegisterFile File;
// We are starting with an empty register file.
EXPECT_EQ(File.getNumLiveRegisters(), 0u);
EXPECT_EQ(File.getMaxRegisterUsage(), 0u);
// Allocate a few registers.
Register R1 = File.allocateRegister();
Register R2 = File.allocateRegister();
Register R3 = File.allocateRegister();
// Make sure we know which registers are alive.
EXPECT_EQ(File.getMaxRegisterUsage(), 3u);
EXPECT_TRUE(File.isUsed(R1));
EXPECT_TRUE(File.isUsed(R2));
EXPECT_TRUE(File.isUsed(R3));
EXPECT_FALSE(File.isFree(R1));
EXPECT_FALSE(File.isFree(R2));
EXPECT_FALSE(File.isFree(R3));
EXPECT_EQ(File.getMaxRegisterUsage(), 3u);
// Make sure we can kill registers and things keep working.
File.killRegister(R2);
EXPECT_TRUE(File.isUsed(R1));
EXPECT_FALSE(File.isUsed(R2));
EXPECT_TRUE(File.isUsed(R3));
EXPECT_TRUE(File.isFree(R2));
// Make sure we can reuse the freed register.
Register R4 = File.allocateRegister();
EXPECT_EQ(File.getMaxRegisterUsage(), 3u);
File.killRegister(R1);
File.killRegister(R3);
File.killRegister(R4);
// Make sure that all registers have been freed.
EXPECT_EQ(File.getNumLiveRegisters(), 0u);
// Make sure we can allocate lots of registers and free them in some order.
std::vector<Register> regs;
for (int i = 0; i < 1000; i++) {
regs.push_back(File.allocateRegister());
}
for (auto &R : regs) {
File.killRegister(R);
}
// Make sure that all registers have been freed again.
EXPECT_EQ(File.getNumLiveRegisters(), 0u);
}
} // end anonymous namespace
Morty Proxy This is a proxified and sanitized view of the page, visit original site.