From 27fa77e102ae716869f0daa0c96c5f3c71772f7b Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 25 Mar 2016 22:12:41 +0000 Subject: [PATCH] SelectionDAG: Remove arbitrary and bug-prone complexity from SDLoc The implementation of SDLoc has an extra layer of indirection here for no particular reason, and was leading to problems where we were dereferencing pointers to SDNodes that had already been deleted so that we could get at the DebugLoc for a new SDNode. This is one of the errors that came up often in PR26808. Instead, we can just track the DebugLoc and IROrder directly. This makes the code both easier to understand and more correct. It's also basically NFC other than fixing a large number of places where we were reading the memory of deleted SDNodes. llvm-svn: 264470 --- llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 40 +++++++-------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index a352aae..5b7b849 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -835,40 +835,20 @@ protected: /// be used by the DAGBuilder, the other to be used by others. class SDLoc { private: - // Ptr could be used for either Instruction* or SDNode*. It is used for - // Instruction* if IROrder is not -1. - const void *Ptr; - int IROrder; + DebugLoc DL; + int IROrder = 0; public: - SDLoc() : Ptr(nullptr), IROrder(0) {} - SDLoc(const SDNode *N) : Ptr(N), IROrder(-1) { - assert(N && "null SDNode"); - } - SDLoc(const SDValue V) : Ptr(V.getNode()), IROrder(-1) { - assert(Ptr && "null SDNode"); - } - SDLoc(const Instruction *I, int Order) : Ptr(I), IROrder(Order) { + SDLoc() = default; + SDLoc(const SDNode *N) : DL(N->getDebugLoc()), IROrder(N->getIROrder()) {} + SDLoc(const SDValue V) : SDLoc(V.getNode()) {} + SDLoc(const Instruction *I, int Order) : IROrder(Order) { assert(Order >= 0 && "bad IROrder"); + if (I) + DL = I->getDebugLoc(); } - unsigned getIROrder() { - if (IROrder >= 0 || Ptr == nullptr) { - return (unsigned)IROrder; - } - const SDNode *N = (const SDNode*)(Ptr); - return N->getIROrder(); - } - DebugLoc getDebugLoc() { - if (!Ptr) { - return DebugLoc(); - } - if (IROrder >= 0) { - const Instruction *I = (const Instruction*)(Ptr); - return I->getDebugLoc(); - } - const SDNode *N = (const SDNode*)(Ptr); - return N->getDebugLoc(); - } + unsigned getIROrder() { return IROrder; } + DebugLoc getDebugLoc() { return DL; } }; -- 2.7.4