-//===----------------------------------------------------------------------===//
-// Instruction Analysis
-//===----------------------------------------------------------------------===//
-
-class InstAnalyzer {
- const CodeGenDAGPatterns &CDP;
- bool &mayStore;
- bool &isLoad;
- bool &NeverHasSideEffects;
-public:
- InstAnalyzer(const CodeGenDAGPatterns &cdp,
- bool &maystore, bool &isload, bool &nhse)
- : CDP(cdp), mayStore(maystore), isLoad(isload), NeverHasSideEffects(nhse) {
- }
-
- void Analyze(Record *InstRecord) {
- const TreePattern *Pattern = CDP.getInstruction(InstRecord).getPattern();
- if (Pattern == 0) return; // No pattern.
-
- // Assume there is no side-effect unless we see one.
- NeverHasSideEffects = true;
-
- // FIXME: Assume only the first tree is the pattern. The others are clobber
- // nodes.
- AnalyzeNode(Pattern->getTree(0));
- }
-
-private:
- void AnalyzeNode(const TreePatternNode *N) {
- if (N->isLeaf()) {
- return;
- }
-
- if (N->getOperator()->getName() != "set") {
- // Get information about the SDNode for the operator.
- const SDNodeInfo &OpInfo = CDP.getSDNodeInfo(N->getOperator());
-
- // If node writes to memory, it obviously stores to memory.
- if (OpInfo.hasProperty(SDNPMayStore)) {
- mayStore = true;
- } else if (const CodeGenIntrinsic *IntInfo = N->getIntrinsicInfo(CDP)) {
- // If this is an intrinsic, analyze it.
- if (IntInfo->ModRef >= CodeGenIntrinsic::WriteArgMem)
- mayStore = true;// Intrinsics that can write to memory are 'mayStore'.
- }
- }
-
- for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
- AnalyzeNode(N->getChild(i));
- }
-
-};
-
-void InstrInfoEmitter::InferFromPattern(const CodeGenInstruction &Inst,
- bool &mayStore, bool &isLoad,
- bool &NeverHasSideEffects) {
- mayStore = isLoad = NeverHasSideEffects = false;
-
- InstAnalyzer(CDP, mayStore, isLoad, NeverHasSideEffects).Analyze(Inst.TheDef);
-
- // InstAnalyzer only correctly analyzes mayStore so far.
- if (Inst.mayStore) { // If the .td file explicitly sets mayStore, use it.
- // If we decided that this is a store from the pattern, then the .td file
- // entry is redundant.
- if (mayStore)
- fprintf(stderr,
- "Warning: mayStore flag explicitly set on instruction '%s'"
- " but flag already inferred from pattern.\n",
- Inst.TheDef->getName().c_str());
- mayStore = true;
- }
-
- // These two override everything.
- isLoad = Inst.isSimpleLoad;
- NeverHasSideEffects = Inst.neverHasSideEffects;
-
-#if 0
- // If the .td file explicitly says there is no side effect, believe it.
- if (Inst.neverHasSideEffects)
- NeverHasSideEffects = true;
-#endif
-}
-
-