Skip to content

Commit 9e35f1e

Browse files
committed
GlobalISel: rework getOrCreateVReg to avoid double lookup. NFC.
Thanks to Quentin for suggesting the refactoring. llvm-svn: 293087
1 parent 5d27063 commit 9e35f1e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,30 @@ void IRTranslator::getAnalysisUsage(AnalysisUsage &AU) const {
6060

6161
unsigned IRTranslator::getOrCreateVReg(const Value &Val) {
6262
unsigned &ValReg = ValToVReg[&Val];
63-
// Check if this is the first time we see Val.
64-
if (!ValReg) {
65-
// Fill ValRegsSequence with the sequence of registers
66-
// we need to concat together to produce the value.
67-
assert(Val.getType()->isSized() &&
68-
"Don't know how to create an empty vreg");
69-
unsigned VReg = MRI->createGenericVirtualRegister(LLT{*Val.getType(), *DL});
70-
ValReg = VReg;
71-
72-
if (auto CV = dyn_cast<Constant>(&Val)) {
73-
bool Success = translate(*CV, VReg);
74-
if (!Success) {
75-
if (!TPC->isGlobalISelAbortEnabled()) {
76-
MF->getProperties().set(
77-
MachineFunctionProperties::Property::FailedISel);
78-
return VReg;
79-
}
80-
reportTranslationError(Val, "unable to translate constant");
63+
64+
if (ValReg)
65+
return ValReg;
66+
67+
// Fill ValRegsSequence with the sequence of registers
68+
// we need to concat together to produce the value.
69+
assert(Val.getType()->isSized() &&
70+
"Don't know how to create an empty vreg");
71+
unsigned VReg = MRI->createGenericVirtualRegister(LLT{*Val.getType(), *DL});
72+
ValReg = VReg;
73+
74+
if (auto CV = dyn_cast<Constant>(&Val)) {
75+
bool Success = translate(*CV, VReg);
76+
if (!Success) {
77+
if (!TPC->isGlobalISelAbortEnabled()) {
78+
MF->getProperties().set(
79+
MachineFunctionProperties::Property::FailedISel);
80+
return VReg;
8181
}
82+
reportTranslationError(Val, "unable to translate constant");
8283
}
8384
}
8485

85-
// Look Val up again in case the reference has been invalidated since.
86-
return ValToVReg[&Val];
86+
return VReg;
8787
}
8888

8989
int IRTranslator::getOrCreateFrameIndex(const AllocaInst &AI) {

0 commit comments

Comments
 (0)