GlobalISel: rework getOrCreateVReg to avoid double lookup. NFC.

Thanks to Quentin for suggesting the refactoring.

llvm-svn: 293087
This commit is contained in:
Tim Northover 2017-01-25 20:58:22 +00:00
parent 5d27063eb4
commit 9e35f1e21c
1 changed files with 19 additions and 19 deletions

View File

@ -60,8 +60,10 @@ void IRTranslator::getAnalysisUsage(AnalysisUsage &AU) const {
unsigned IRTranslator::getOrCreateVReg(const Value &Val) {
unsigned &ValReg = ValToVReg[&Val];
// Check if this is the first time we see Val.
if (!ValReg) {
if (ValReg)
return ValReg;
// Fill ValRegsSequence with the sequence of registers
// we need to concat together to produce the value.
assert(Val.getType()->isSized() &&
@ -80,10 +82,8 @@ unsigned IRTranslator::getOrCreateVReg(const Value &Val) {
reportTranslationError(Val, "unable to translate constant");
}
}
}
// Look Val up again in case the reference has been invalidated since.
return ValToVReg[&Val];
return VReg;
}
int IRTranslator::getOrCreateFrameIndex(const AllocaInst &AI) {