diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-06-17 20:52:32 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-06-17 20:52:32 +0000 |
commit | 7fddeccb8b4694002e3a2130d4bce07d628b1db2 (patch) | |
tree | 01bc06f3a0d026c80340d658807481ae33240033 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | f32991461f301bbc99c17cc51fd44a50d2012179 (diff) | |
download | bcm5719-llvm-7fddeccb8b4694002e3a2130d4bce07d628b1db2.tar.gz bcm5719-llvm-7fddeccb8b4694002e3a2130d4bce07d628b1db2.zip |
Move the personality function from LandingPadInst to Function
The personality routine currently lives in the LandingPadInst.
This isn't desirable because:
- All LandingPadInsts in the same function must have the same
personality routine. This means that each LandingPadInst beyond the
first has an operand which produces no additional information.
- There is ongoing work to introduce EH IR constructs other than
LandingPadInst. Moving the personality routine off of any one
particular Instruction and onto the parent function seems a lot better
than have N different places a personality function can sneak onto an
exceptional function.
Differential Revision: http://reviews.llvm.org/D10429
llvm-svn: 239940
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 10e0410c025..ccb9d5dd038 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -150,6 +150,7 @@ class BitcodeReader : public GVMaterializer { std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits; std::vector<std::pair<Function*, unsigned> > FunctionPrefixes; std::vector<std::pair<Function*, unsigned> > FunctionPrologues; + std::vector<std::pair<Function*, unsigned> > FunctionPersonalityFns; SmallVector<Instruction*, 64> InstsWithTBAATag; @@ -2031,11 +2032,13 @@ std::error_code BitcodeReader::resolveGlobalAndAliasInits() { std::vector<std::pair<GlobalAlias*, unsigned> > AliasInitWorklist; std::vector<std::pair<Function*, unsigned> > FunctionPrefixWorklist; std::vector<std::pair<Function*, unsigned> > FunctionPrologueWorklist; + std::vector<std::pair<Function*, unsigned> > FunctionPersonalityFnWorklist; GlobalInitWorklist.swap(GlobalInits); AliasInitWorklist.swap(AliasInits); FunctionPrefixWorklist.swap(FunctionPrefixes); FunctionPrologueWorklist.swap(FunctionPrologues); + FunctionPersonalityFnWorklist.swap(FunctionPersonalityFns); while (!GlobalInitWorklist.empty()) { unsigned ValID = GlobalInitWorklist.back().second; @@ -2093,6 +2096,19 @@ std::error_code BitcodeReader::resolveGlobalAndAliasInits() { FunctionPrologueWorklist.pop_back(); } + while (!FunctionPersonalityFnWorklist.empty()) { + unsigned ValID = FunctionPersonalityFnWorklist.back().second; + if (ValID >= ValueList.size()) { + FunctionPersonalityFns.push_back(FunctionPersonalityFnWorklist.back()); + } else { + if (Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID])) + FunctionPersonalityFnWorklist.back().first->setPersonalityFn(C); + else + return error("Expected a constant"); + } + FunctionPersonalityFnWorklist.pop_back(); + } + return std::error_code(); } @@ -3023,6 +3039,9 @@ std::error_code BitcodeReader::parseModule(bool Resume, if (Record.size() > 13 && Record[13] != 0) FunctionPrefixes.push_back(std::make_pair(Func, Record[13]-1)); + if (Record.size() > 14 && Record[14] != 0) + FunctionPersonalityFns.push_back(std::make_pair(Func, Record[14] - 1)); + ValueList.push_back(Func); // If this is a function with a body, remember the prototype we are @@ -3976,21 +3995,35 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) { break; } - case bitc::FUNC_CODE_INST_LANDINGPAD: { + case bitc::FUNC_CODE_INST_LANDINGPAD: + case bitc::FUNC_CODE_INST_LANDINGPAD_OLD: { // LANDINGPAD: [ty, val, val, num, (id0,val0 ...)?] unsigned Idx = 0; - if (Record.size() < 4) - return error("Invalid record"); + if (BitCode == bitc::FUNC_CODE_INST_LANDINGPAD) { + if (Record.size() < 3) + return error("Invalid record"); + } else { + assert(BitCode == bitc::FUNC_CODE_INST_LANDINGPAD_OLD); + if (Record.size() < 4) + return error("Invalid record"); + } Type *Ty = getTypeByID(Record[Idx++]); if (!Ty) return error("Invalid record"); - Value *PersFn = nullptr; - if (getValueTypePair(Record, Idx, NextValueNo, PersFn)) - return error("Invalid record"); + if (BitCode == bitc::FUNC_CODE_INST_LANDINGPAD_OLD) { + Value *PersFn = nullptr; + if (getValueTypePair(Record, Idx, NextValueNo, PersFn)) + return error("Invalid record"); + + if (!F->hasPersonalityFn()) + F->setPersonalityFn(cast<Constant>(PersFn)); + else if (F->getPersonalityFn() != cast<Constant>(PersFn)) + return error("Personality function mismatch"); + } bool IsCleanup = !!Record[Idx++]; unsigned NumClauses = Record[Idx++]; - LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, NumClauses); + LandingPadInst *LP = LandingPadInst::Create(Ty, NumClauses); LP->setCleanup(IsCleanup); for (unsigned J = 0; J != NumClauses; ++J) { LandingPadInst::ClauseType CT = |