mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-14 15:28:20 +00:00
move some code around, no change in the generated code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25758 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1829,7 +1829,6 @@ private:
|
|||||||
TreePatternNode *Pattern;
|
TreePatternNode *Pattern;
|
||||||
// Matched instruction.
|
// Matched instruction.
|
||||||
TreePatternNode *Instruction;
|
TreePatternNode *Instruction;
|
||||||
unsigned PatternNo;
|
|
||||||
|
|
||||||
// Node to name mapping
|
// Node to name mapping
|
||||||
std::map<std::string, std::string> VariableMap;
|
std::map<std::string, std::string> VariableMap;
|
||||||
@@ -1858,10 +1857,9 @@ private:
|
|||||||
public:
|
public:
|
||||||
PatternCodeEmitter(DAGISelEmitter &ise, ListInit *preds,
|
PatternCodeEmitter(DAGISelEmitter &ise, ListInit *preds,
|
||||||
TreePatternNode *pattern, TreePatternNode *instr,
|
TreePatternNode *pattern, TreePatternNode *instr,
|
||||||
unsigned PatNum,
|
|
||||||
std::vector<std::pair<bool, std::string> > &gc)
|
std::vector<std::pair<bool, std::string> > &gc)
|
||||||
: ISE(ise), Predicates(preds), Pattern(pattern), Instruction(instr),
|
: ISE(ise), Predicates(preds), Pattern(pattern), Instruction(instr),
|
||||||
PatternNo(PatNum), GeneratedCode(gc), TmpNo(0) {}
|
GeneratedCode(gc), TmpNo(0) {}
|
||||||
|
|
||||||
/// EmitMatchCode - Emit a matcher for N, going to the label for PatternNo
|
/// EmitMatchCode - Emit a matcher for N, going to the label for PatternNo
|
||||||
/// if the match fails. At this point, we already know that the opcode for N
|
/// if the match fails. At this point, we already know that the opcode for N
|
||||||
@@ -2531,17 +2529,12 @@ private:
|
|||||||
|
|
||||||
/// EmitCodeForPattern - Given a pattern to match, emit code to the specified
|
/// EmitCodeForPattern - Given a pattern to match, emit code to the specified
|
||||||
/// stream to match the pattern, and generate the code for the match if it
|
/// stream to match the pattern, and generate the code for the match if it
|
||||||
/// succeeds. Returns true if execution may jump to the fail label instead of
|
/// succeeds. Returns true if the pattern is not guaranteed to match.
|
||||||
/// returning.
|
void DAGISelEmitter::EmitCodeForPattern(PatternToMatch &Pattern,
|
||||||
bool DAGISelEmitter::EmitCodeForPattern(PatternToMatch &Pattern,
|
std::vector<std::pair<bool, std::string> > &GeneratedCode) {
|
||||||
std::ostream &OS) {
|
|
||||||
static unsigned PatternCount = 0;
|
|
||||||
unsigned PatternNo = PatternCount++;
|
|
||||||
|
|
||||||
std::vector<std::pair<bool, std::string> > GeneratedCode;
|
|
||||||
PatternCodeEmitter Emitter(*this, Pattern.getPredicates(),
|
PatternCodeEmitter Emitter(*this, Pattern.getPredicates(),
|
||||||
Pattern.getSrcPattern(), Pattern.getDstPattern(),
|
Pattern.getSrcPattern(), Pattern.getDstPattern(),
|
||||||
PatternNo, GeneratedCode);
|
GeneratedCode);
|
||||||
|
|
||||||
// Emit the matcher, capturing named arguments in VariableMap.
|
// Emit the matcher, capturing named arguments in VariableMap.
|
||||||
bool FoundChain = false;
|
bool FoundChain = false;
|
||||||
@@ -2585,39 +2578,7 @@ bool DAGISelEmitter::EmitCodeForPattern(PatternToMatch &Pattern,
|
|||||||
} while (Emitter.InsertOneTypeCheck(Pat, Pattern.getSrcPattern(), "N"));
|
} while (Emitter.InsertOneTypeCheck(Pat, Pattern.getSrcPattern(), "N"));
|
||||||
|
|
||||||
Emitter.EmitResultCode(Pattern.getDstPattern(), true /*the root*/);
|
Emitter.EmitResultCode(Pattern.getDstPattern(), true /*the root*/);
|
||||||
|
|
||||||
delete Pat;
|
delete Pat;
|
||||||
|
|
||||||
|
|
||||||
OS << " { // Pattern #" << PatternNo << ": ";
|
|
||||||
Pattern.getSrcPattern()->print(OS);
|
|
||||||
OS << "\n // Emits: ";
|
|
||||||
Pattern.getDstPattern()->print(OS);
|
|
||||||
OS << "\n";
|
|
||||||
OS << " // Pattern complexity = "
|
|
||||||
<< getPatternSize(Pattern.getSrcPattern(), *this)
|
|
||||||
<< " cost = "
|
|
||||||
<< getResultPatternCost(Pattern.getDstPattern()) << "\n";
|
|
||||||
|
|
||||||
// Actually output the generated code now.
|
|
||||||
bool CanFail = false;
|
|
||||||
unsigned Indent = 4;
|
|
||||||
for (unsigned i = 0, e = GeneratedCode.size(); i != e; ++i) {
|
|
||||||
if (!GeneratedCode[i].first) {
|
|
||||||
// Normal code.
|
|
||||||
OS << std::string(Indent, ' ') << GeneratedCode[i].second << "\n";
|
|
||||||
} else {
|
|
||||||
CanFail = true;
|
|
||||||
OS << std::string(Indent, ' ')
|
|
||||||
<< "if (" << GeneratedCode[i].second << ") {\n";
|
|
||||||
Indent += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (; Indent != 4; Indent -= 2)
|
|
||||||
OS << std::string(Indent-2, ' ') << "}\n";
|
|
||||||
|
|
||||||
OS << " }\n";
|
|
||||||
return CanFail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2678,6 +2639,7 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
|
|||||||
|
|
||||||
const SDNodeInfo &OpcodeInfo = getSDNodeInfo(PBOI->first);
|
const SDNodeInfo &OpcodeInfo = getSDNodeInfo(PBOI->first);
|
||||||
std::vector<PatternToMatch*> &Patterns = PBOI->second;
|
std::vector<PatternToMatch*> &Patterns = PBOI->second;
|
||||||
|
assert(!Patterns.empty() && "No patterns but map has entry?");
|
||||||
|
|
||||||
// We want to emit all of the matching code now. However, we want to emit
|
// We want to emit all of the matching code now. However, we want to emit
|
||||||
// the matches in order of minimal cost. Sort the patterns so the least
|
// the matches in order of minimal cost. Sort the patterns so the least
|
||||||
@@ -2685,18 +2647,52 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) {
|
|||||||
std::stable_sort(Patterns.begin(), Patterns.end(),
|
std::stable_sort(Patterns.begin(), Patterns.end(),
|
||||||
PatternSortingPredicate(*this));
|
PatternSortingPredicate(*this));
|
||||||
|
|
||||||
bool mightNotReturn = true;
|
bool mightNotMatch = true;
|
||||||
for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
|
||||||
if (!mightNotReturn) {
|
PatternToMatch &Pattern = *Patterns[i];
|
||||||
|
std::vector<std::pair<bool, std::string> > GeneratedCode;
|
||||||
|
EmitCodeForPattern(Pattern, GeneratedCode);
|
||||||
|
|
||||||
|
static unsigned PatternCount = 0;
|
||||||
|
unsigned PatternNo = PatternCount++;
|
||||||
|
|
||||||
|
OS << " { // Pattern #" << PatternNo << ": ";
|
||||||
|
Pattern.getSrcPattern()->print(OS);
|
||||||
|
OS << "\n // Emits: ";
|
||||||
|
Pattern.getDstPattern()->print(OS);
|
||||||
|
OS << "\n";
|
||||||
|
OS << " // Pattern complexity = "
|
||||||
|
<< getPatternSize(Pattern.getSrcPattern(), *this) << " cost = "
|
||||||
|
<< getResultPatternCost(Pattern.getDstPattern()) << "\n";
|
||||||
|
|
||||||
|
// Actually output the generated code now.
|
||||||
|
mightNotMatch = false;
|
||||||
|
unsigned Indent = 4;
|
||||||
|
for (unsigned j = 0, e = GeneratedCode.size(); j != e; ++j) {
|
||||||
|
if (!GeneratedCode[j].first) {
|
||||||
|
// Normal code.
|
||||||
|
OS << std::string(Indent, ' ') << GeneratedCode[j].second << "\n";
|
||||||
|
} else {
|
||||||
|
mightNotMatch = true;
|
||||||
|
OS << std::string(Indent, ' ')
|
||||||
|
<< "if (" << GeneratedCode[j].second << ") {\n";
|
||||||
|
Indent += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (; Indent != 4; Indent -= 2)
|
||||||
|
OS << std::string(Indent-2, ' ') << "}\n";
|
||||||
|
|
||||||
|
OS << " }\n";
|
||||||
|
|
||||||
|
if (!mightNotMatch && i != Patterns.size()-1) {
|
||||||
std::cerr << "Pattern "
|
std::cerr << "Pattern "
|
||||||
<< Patterns[i]->getDstPattern()->getOperator()->getName()
|
<< Patterns[i+1]->getDstPattern()->getOperator()->getName()
|
||||||
<< " is impossible to select!\n";
|
<< " is impossible to select!\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
mightNotReturn = EmitCodeForPattern(*Patterns[i], OS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mightNotReturn)
|
if (mightNotMatch)
|
||||||
OS << " std::cerr << \"Cannot yet select: \";\n"
|
OS << " std::cerr << \"Cannot yet select: \";\n"
|
||||||
<< " N.Val->dump(CurDAG);\n"
|
<< " N.Val->dump(CurDAG);\n"
|
||||||
<< " std::cerr << '\\n';\n"
|
<< " std::cerr << '\\n';\n"
|
||||||
|
@@ -155,7 +155,9 @@ namespace llvm {
|
|||||||
: Types(), Operator(Op), Val(0), TransformFn(0),
|
: Types(), Operator(Op), Val(0), TransformFn(0),
|
||||||
Children(Ch) { Types.push_back(MVT::isUnknown); }
|
Children(Ch) { Types.push_back(MVT::isUnknown); }
|
||||||
TreePatternNode(Init *val) // leaf ctor
|
TreePatternNode(Init *val) // leaf ctor
|
||||||
: Types(), Operator(0), Val(val), TransformFn(0) { Types.push_back(MVT::isUnknown); }
|
: Types(), Operator(0), Val(val), TransformFn(0) {
|
||||||
|
Types.push_back(MVT::isUnknown);
|
||||||
|
}
|
||||||
~TreePatternNode();
|
~TreePatternNode();
|
||||||
|
|
||||||
const std::string &getName() const { return Name; }
|
const std::string &getName() const { return Name; }
|
||||||
@@ -468,7 +470,8 @@ private:
|
|||||||
std::map<std::string, Record*> &InstResults,
|
std::map<std::string, Record*> &InstResults,
|
||||||
std::vector<Record*> &InstImpInputs,
|
std::vector<Record*> &InstImpInputs,
|
||||||
std::vector<Record*> &InstImpResults);
|
std::vector<Record*> &InstImpResults);
|
||||||
bool EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
|
void EmitCodeForPattern(PatternToMatch &Pattern,
|
||||||
|
std::vector<std::pair<bool, std::string> > &GeneratedCode);
|
||||||
void EmitInstructionSelector(std::ostream &OS);
|
void EmitInstructionSelector(std::ostream &OS);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user