summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MIRParser/MIParser.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-08-19 23:31:05 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-08-19 23:31:05 +0000
commitdd13be0bccc888926cb5a5e81912b89b28142669 (patch)
tree7111d88094455929df5f323269a9221a38e8dafa /llvm/lib/CodeGen/MIRParser/MIParser.cpp
parent36593ac51b81952977a83955e82a83df56052db7 (diff)
downloadbcm5719-llvm-dd13be0bccc888926cb5a5e81912b89b28142669.tar.gz
bcm5719-llvm-dd13be0bccc888926cb5a5e81912b89b28142669.zip
MIR Serialization: Serialize unnamed local IR values in memory operands.
llvm-svn: 245521
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser/MIParser.cpp')
-rw-r--r--llvm/lib/CodeGen/MIRParser/MIParser.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index 4dfa793e730..80f6a654b97 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -73,6 +73,8 @@ class MIParser {
StringMap<unsigned> Names2SubRegIndices;
/// Maps from slot numbers to function's unnamed basic blocks.
DenseMap<unsigned, const BasicBlock *> Slots2BasicBlocks;
+ /// Maps from slot numbers to function's unnamed values.
+ DenseMap<unsigned, const Value *> Slots2Values;
/// Maps from target index names to target indices.
StringMap<int> Names2TargetIndices;
/// Maps from direct target flag names to the direct target flag values.
@@ -212,6 +214,8 @@ private:
const BasicBlock *getIRBlock(unsigned Slot);
const BasicBlock *getIRBlock(unsigned Slot, const Function &F);
+ const Value *getIRValue(unsigned Slot);
+
void initNames2TargetIndices();
/// Try to convert a name of target index to the corresponding target index.
@@ -1530,14 +1534,20 @@ bool MIParser::parseIRValue(const Value *&V) {
if (!V)
V = MF.getFunction()->getParent()->getValueSymbolTable().lookup(
Token.stringValue());
- if (!V)
- return error(Twine("use of undefined IR value '") + Token.range() + "'");
break;
}
- // TODO: Parse unnamed IR value references.
+ case MIToken::IRValue: {
+ unsigned SlotNumber = 0;
+ if (getUnsigned(SlotNumber))
+ return true;
+ V = getIRValue(SlotNumber);
+ break;
+ }
default:
llvm_unreachable("The current token should be an IR block reference");
}
+ if (!V)
+ return error(Twine("use of undefined IR value '") + Token.range() + "'");
return false;
}
@@ -1629,7 +1639,7 @@ bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) {
Dest = MachinePointerInfo(PSV, Offset);
return false;
}
- if (Token.isNot(MIToken::NamedIRValue))
+ if (Token.isNot(MIToken::NamedIRValue) && Token.isNot(MIToken::IRValue))
return error("expected an IR value reference");
const Value *V = nullptr;
if (parseIRValue(V))
@@ -1837,6 +1847,37 @@ const BasicBlock *MIParser::getIRBlock(unsigned Slot, const Function &F) {
return getIRBlockFromSlot(Slot, CustomSlots2BasicBlocks);
}
+static void mapValueToSlot(const Value *V, ModuleSlotTracker &MST,
+ DenseMap<unsigned, const Value *> &Slots2Values) {
+ int Slot = MST.getLocalSlot(V);
+ if (Slot == -1)
+ return;
+ Slots2Values.insert(std::make_pair(unsigned(Slot), V));
+}
+
+/// Creates the mapping from slot numbers to function's unnamed IR values.
+static void initSlots2Values(const Function &F,
+ DenseMap<unsigned, const Value *> &Slots2Values) {
+ ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false);
+ MST.incorporateFunction(F);
+ for (const auto &Arg : F.args())
+ mapValueToSlot(&Arg, MST, Slots2Values);
+ for (const auto &BB : F) {
+ mapValueToSlot(&BB, MST, Slots2Values);
+ for (const auto &I : BB)
+ mapValueToSlot(&I, MST, Slots2Values);
+ }
+}
+
+const Value *MIParser::getIRValue(unsigned Slot) {
+ if (Slots2Values.empty())
+ initSlots2Values(*MF.getFunction(), Slots2Values);
+ auto ValueInfo = Slots2Values.find(Slot);
+ if (ValueInfo == Slots2Values.end())
+ return nullptr;
+ return ValueInfo->second;
+}
+
void MIParser::initNames2TargetIndices() {
if (!Names2TargetIndices.empty())
return;
OpenPOWER on IntegriCloud