[globalisel][tablegen] Change Expected<bool> to Error and rename functions.

Functions that still return Expected<X> are now called createAndImport*()

Changing the return type was requested in the review comments for r299001

llvm-svn: 299063
This commit is contained in:
Daniel Sanders 2017-03-30 09:36:33 +00:00
parent ca878c943b
commit c270c500b7
1 changed files with 41 additions and 45 deletions

View File

@ -1002,21 +1002,21 @@ private:
void gatherNodeEquivs(); void gatherNodeEquivs();
const CodeGenInstruction *findNodeEquiv(Record *N) const; const CodeGenInstruction *findNodeEquiv(Record *N) const;
Expected<bool> importRulePredicates(RuleMatcher &M, Error importRulePredicates(RuleMatcher &M, ArrayRef<Init *> Predicates) const;
ArrayRef<Init *> Predicates) const;
Expected<InstructionMatcher &> Expected<InstructionMatcher &>
importSelDAGMatcher(InstructionMatcher &InsnMatcher, createAndImportSelDAGMatcher(InstructionMatcher &InsnMatcher,
const TreePatternNode *Src) const; const TreePatternNode *Src) const;
Expected<bool> importChildMatcher(InstructionMatcher &InsnMatcher, Error importChildMatcher(InstructionMatcher &InsnMatcher,
TreePatternNode *SrcChild, unsigned OpIdx, TreePatternNode *SrcChild, unsigned OpIdx,
unsigned &TempOpIdx) const; unsigned &TempOpIdx) const;
Expected<BuildMIAction &> Expected<BuildMIAction &> createAndImportInstructionRenderer(
importInstructionRenderer(RuleMatcher &M, const TreePatternNode *Dst, RuleMatcher &M, const TreePatternNode *Dst,
const InstructionMatcher &InsnMatcher) const; const InstructionMatcher &InsnMatcher) const;
Expected<bool> importExplicitUseRenderer( Error importExplicitUseRenderer(BuildMIAction &DstMIBuilder,
BuildMIAction &DstMIBuilder, TreePatternNode *DstChild, TreePatternNode *DstChild,
const InstructionMatcher &InsnMatcher, unsigned &TempOpIdx) const; const InstructionMatcher &InsnMatcher,
Expected<bool> unsigned &TempOpIdx) const;
Error
importImplicitDefRenderers(BuildMIAction &DstMIBuilder, importImplicitDefRenderers(BuildMIAction &DstMIBuilder,
const std::vector<Record *> &ImplicitDefs) const; const std::vector<Record *> &ImplicitDefs) const;
@ -1054,17 +1054,16 @@ static Error failedImport(const Twine &Reason) {
return make_error<StringError>(Reason, inconvertibleErrorCode()); return make_error<StringError>(Reason, inconvertibleErrorCode());
} }
Expected<bool> Error
GlobalISelEmitter::importRulePredicates(RuleMatcher &M, GlobalISelEmitter::importRulePredicates(RuleMatcher &M,
ArrayRef<Init *> Predicates) const { ArrayRef<Init *> Predicates) const {
if (!Predicates.empty()) if (!Predicates.empty())
return failedImport("Pattern has a predicate"); return failedImport("Pattern has a predicate");
return true; return Error::success();
} }
Expected<InstructionMatcher &> Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
GlobalISelEmitter::importSelDAGMatcher(InstructionMatcher &InsnMatcher, InstructionMatcher &InsnMatcher, const TreePatternNode *Src) const {
const TreePatternNode *Src) const {
// Start with the defined operands (i.e., the results of the root operator). // Start with the defined operands (i.e., the results of the root operator).
if (Src->getExtTypes().size() > 1) if (Src->getExtTypes().size() > 1)
return failedImport("Src pattern has multiple results"); return failedImport("Src pattern has multiple results");
@ -1095,18 +1094,17 @@ GlobalISelEmitter::importSelDAGMatcher(InstructionMatcher &InsnMatcher,
// Match the used operands (i.e. the children of the operator). // Match the used operands (i.e. the children of the operator).
for (unsigned i = 0, e = Src->getNumChildren(); i != e; ++i) { for (unsigned i = 0, e = Src->getNumChildren(); i != e; ++i) {
if (auto Error = importChildMatcher(InsnMatcher, Src->getChild(i), OpIdx++, if (auto Error = importChildMatcher(InsnMatcher, Src->getChild(i), OpIdx++,
TempOpIdx) TempOpIdx))
.takeError())
return std::move(Error); return std::move(Error);
} }
return InsnMatcher; return InsnMatcher;
} }
Expected<bool> Error GlobalISelEmitter::importChildMatcher(InstructionMatcher &InsnMatcher,
GlobalISelEmitter::importChildMatcher(InstructionMatcher &InsnMatcher, TreePatternNode *SrcChild,
TreePatternNode *SrcChild, unsigned OpIdx, unsigned OpIdx,
unsigned &TempOpIdx) const { unsigned &TempOpIdx) const {
OperandMatcher &OM = InsnMatcher.addOperand(OpIdx, SrcChild->getName()); OperandMatcher &OM = InsnMatcher.addOperand(OpIdx, SrcChild->getName());
if (SrcChild->hasAnyPredicate()) if (SrcChild->hasAnyPredicate())
@ -1122,7 +1120,7 @@ GlobalISelEmitter::importChildMatcher(InstructionMatcher &InsnMatcher,
auto &ChildSDNI = CGP.getSDNodeInfo(SrcChild->getOperator()); auto &ChildSDNI = CGP.getSDNodeInfo(SrcChild->getOperator());
if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") { if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") {
OM.addPredicate<MBBOperandMatcher>(); OM.addPredicate<MBBOperandMatcher>();
return true; return Error::success();
} }
} }
@ -1137,7 +1135,7 @@ GlobalISelEmitter::importChildMatcher(InstructionMatcher &InsnMatcher,
// Check for constant immediates. // Check for constant immediates.
if (auto *ChildInt = dyn_cast<IntInit>(SrcChild->getLeafValue())) { if (auto *ChildInt = dyn_cast<IntInit>(SrcChild->getLeafValue())) {
OM.addPredicate<IntOperandMatcher>(ChildInt->getValue()); OM.addPredicate<IntOperandMatcher>(ChildInt->getValue());
return true; return Error::success();
} }
// Check for def's like register classes or ComplexPattern's. // Check for def's like register classes or ComplexPattern's.
@ -1148,7 +1146,7 @@ GlobalISelEmitter::importChildMatcher(InstructionMatcher &InsnMatcher,
if (ChildRec->isSubClassOf("RegisterClass")) { if (ChildRec->isSubClassOf("RegisterClass")) {
OM.addPredicate<RegisterBankOperandMatcher>( OM.addPredicate<RegisterBankOperandMatcher>(
Target.getRegisterClass(ChildRec)); Target.getRegisterClass(ChildRec));
return true; return Error::success();
} }
// Check for ComplexPattern's. // Check for ComplexPattern's.
@ -1161,7 +1159,7 @@ GlobalISelEmitter::importChildMatcher(InstructionMatcher &InsnMatcher,
const auto &Predicate = OM.addPredicate<ComplexPatternOperandMatcher>( const auto &Predicate = OM.addPredicate<ComplexPatternOperandMatcher>(
*ComplexPattern->second, TempOpIdx); *ComplexPattern->second, TempOpIdx);
TempOpIdx += Predicate.countTemporaryOperands(); TempOpIdx += Predicate.countTemporaryOperands();
return true; return Error::success();
} }
return failedImport( return failedImport(
@ -1171,7 +1169,7 @@ GlobalISelEmitter::importChildMatcher(InstructionMatcher &InsnMatcher,
return failedImport("Src pattern child is an unsupported kind"); return failedImport("Src pattern child is an unsupported kind");
} }
Expected<bool> GlobalISelEmitter::importExplicitUseRenderer( Error GlobalISelEmitter::importExplicitUseRenderer(
BuildMIAction &DstMIBuilder, TreePatternNode *DstChild, BuildMIAction &DstMIBuilder, TreePatternNode *DstChild,
const InstructionMatcher &InsnMatcher, unsigned &TempOpIdx) const { const InstructionMatcher &InsnMatcher, unsigned &TempOpIdx) const {
// The only non-leaf child we accept is 'bb': it's an operator because // The only non-leaf child we accept is 'bb': it's an operator because
@ -1182,7 +1180,7 @@ Expected<bool> GlobalISelEmitter::importExplicitUseRenderer(
if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") { if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") {
DstMIBuilder.addRenderer<CopyRenderer>(InsnMatcher, DstMIBuilder.addRenderer<CopyRenderer>(InsnMatcher,
DstChild->getName()); DstChild->getName());
return true; return Error::success();
} }
} }
return failedImport("Dst pattern child isn't a leaf node or an MBB"); return failedImport("Dst pattern child isn't a leaf node or an MBB");
@ -1205,12 +1203,12 @@ Expected<bool> GlobalISelEmitter::importExplicitUseRenderer(
if (ChildRec->isSubClassOf("Register")) { if (ChildRec->isSubClassOf("Register")) {
DstMIBuilder.addRenderer<AddRegisterRenderer>(ChildRec); DstMIBuilder.addRenderer<AddRegisterRenderer>(ChildRec);
return true; return Error::success();
} }
if (ChildRec->isSubClassOf("RegisterClass")) { if (ChildRec->isSubClassOf("RegisterClass")) {
DstMIBuilder.addRenderer<CopyRenderer>(InsnMatcher, DstChild->getName()); DstMIBuilder.addRenderer<CopyRenderer>(InsnMatcher, DstChild->getName());
return true; return Error::success();
} }
if (ChildRec->isSubClassOf("ComplexPattern")) { if (ChildRec->isSubClassOf("ComplexPattern")) {
@ -1229,7 +1227,7 @@ Expected<bool> GlobalISelEmitter::importExplicitUseRenderer(
} }
DstMIBuilder.addRenderer<RenderComplexPatternOperand>( DstMIBuilder.addRenderer<RenderComplexPatternOperand>(
*ComplexPattern->second, RenderedOperands); *ComplexPattern->second, RenderedOperands);
return true; return Error::success();
} }
return failedImport( return failedImport(
@ -1239,7 +1237,7 @@ Expected<bool> GlobalISelEmitter::importExplicitUseRenderer(
return failedImport("Dst pattern child is an unsupported kind"); return failedImport("Dst pattern child is an unsupported kind");
} }
Expected<BuildMIAction &> GlobalISelEmitter::importInstructionRenderer( Expected<BuildMIAction &> GlobalISelEmitter::createAndImportInstructionRenderer(
RuleMatcher &M, const TreePatternNode *Dst, RuleMatcher &M, const TreePatternNode *Dst,
const InstructionMatcher &InsnMatcher) const { const InstructionMatcher &InsnMatcher) const {
Record *DstOp = Dst->getOperator(); Record *DstOp = Dst->getOperator();
@ -1259,20 +1257,19 @@ Expected<BuildMIAction &> GlobalISelEmitter::importInstructionRenderer(
unsigned TempOpIdx = 0; unsigned TempOpIdx = 0;
for (unsigned i = 0, e = Dst->getNumChildren(); i != e; ++i) { for (unsigned i = 0, e = Dst->getNumChildren(); i != e; ++i) {
if (auto Error = importExplicitUseRenderer(DstMIBuilder, Dst->getChild(i), if (auto Error = importExplicitUseRenderer(DstMIBuilder, Dst->getChild(i),
InsnMatcher, TempOpIdx) InsnMatcher, TempOpIdx))
.takeError())
return std::move(Error); return std::move(Error);
} }
return DstMIBuilder; return DstMIBuilder;
} }
Expected<bool> GlobalISelEmitter::importImplicitDefRenderers( Error GlobalISelEmitter::importImplicitDefRenderers(
BuildMIAction &DstMIBuilder, BuildMIAction &DstMIBuilder,
const std::vector<Record *> &ImplicitDefs) const { const std::vector<Record *> &ImplicitDefs) const {
if (!ImplicitDefs.empty()) if (!ImplicitDefs.empty())
return failedImport("Pattern defines a physical register"); return failedImport("Pattern defines a physical register");
return true; return Error::success();
} }
Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) { Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
@ -1280,8 +1277,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
RuleMatcher M; RuleMatcher M;
M.addAction<DebugCommentAction>(P); M.addAction<DebugCommentAction>(P);
if (auto Error = if (auto Error = importRulePredicates(M, P.getPredicates()->getValues()))
importRulePredicates(M, P.getPredicates()->getValues()).takeError())
return std::move(Error); return std::move(Error);
// Next, analyze the pattern operators. // Next, analyze the pattern operators.
@ -1303,7 +1299,7 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
return failedImport("Src pattern results and dst MI defs are different"); return failedImport("Src pattern results and dst MI defs are different");
InstructionMatcher &InsnMatcherTemp = M.addInstructionMatcher(); InstructionMatcher &InsnMatcherTemp = M.addInstructionMatcher();
auto InsnMatcherOrError = importSelDAGMatcher(InsnMatcherTemp, Src); auto InsnMatcherOrError = createAndImportSelDAGMatcher(InsnMatcherTemp, Src);
if (auto Error = InsnMatcherOrError.takeError()) if (auto Error = InsnMatcherOrError.takeError())
return std::move(Error); return std::move(Error);
InstructionMatcher &InsnMatcher = InsnMatcherOrError.get(); InstructionMatcher &InsnMatcher = InsnMatcherOrError.get();
@ -1326,15 +1322,15 @@ Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) {
++OpIdx; ++OpIdx;
} }
auto DstMIBuilderOrError = importInstructionRenderer(M, Dst, InsnMatcher); auto DstMIBuilderOrError =
createAndImportInstructionRenderer(M, Dst, InsnMatcher);
if (auto Error = DstMIBuilderOrError.takeError()) if (auto Error = DstMIBuilderOrError.takeError())
return std::move(Error); return std::move(Error);
BuildMIAction &DstMIBuilder = DstMIBuilderOrError.get(); BuildMIAction &DstMIBuilder = DstMIBuilderOrError.get();
// Render the implicit defs. // Render the implicit defs.
// These are only added to the root of the result. // These are only added to the root of the result.
if (auto Error = if (auto Error = importImplicitDefRenderers(DstMIBuilder, P.getDstRegs()))
importImplicitDefRenderers(DstMIBuilder, P.getDstRegs()).takeError())
return std::move(Error); return std::move(Error);
// We're done with this pattern! It's eligible for GISel emission; return it. // We're done with this pattern! It's eligible for GISel emission; return it.