<div dir="ltr"><div>I've successfully constructed an instance of a SelectionDAG outside of the back end. Actually using it segfaults though - I'll paste the code here in the hope that I'm just missing some setup. Suggestions very welcome.<br><br></div>Thanks!<br><div><br>#include "llvm/Target/OOT/OOTLowering.h"<br><br>#include "llvm/CodeGen/SelectionDAG.h"<br>#include "llvm/MC/SubtargetFeature.h"<br>#include "llvm/Support/TargetRegistry.h"<br>#include "llvm/Support/TargetSelect.h"<br>#include "llvm/Target/TargetLowering.h"<br>#include "llvm/Target/TargetMachine.h"<br><br>namespace llvm {<br>extern Target TheOOTTarget;<br>}<br><br>const llvm::TargetMachine &get_target_machine() {<br>  static bool init = false;<br>  static llvm::TargetMachine *local = nullptr;<br>  if (!init) {<br>    init = true;<br>    llvm::InitializeAllTargets();<br>    llvm::InitializeAllTargetMCs();<br>    llvm::InitializeAllAsmPrinters();<br>    llvm::InitializeAllAsmParsers();<br><br>    std::string TripleStr = llvm::sys::getDefaultTargetTriple();<br>    llvm::Triple Triple(TripleStr);<br><br>    std::string errMsg;<br>    const llvm::Target *march =<br>        llvm::TargetRegistry::lookupTarget(TripleStr, errMsg);<br>    assert(march);<br><br>    local = llvm::TheOOTTarget.createTargetMachine(<br>        TripleStr, "", "", llvm::TargetOptions(), llvm::None);<br>  }<br>  assert(local);<br>  return *local;<br>}<br><br>int main() {<br>  using namespace llvm;<br>  SelectionDAG DAG(get_target_machine(), CodeGenOpt::Default);<br><br>  DAG.dump(); // OK<br><br>  auto rt = DAG.getRoot();<br>  SDLoc dl(rt);<br><br>  SDValue aconstant = DAG.getConstant(123, dl, MVT::i32);<br>  aconstant.dump(); // segv<br>}<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 11, 2017 at 11:48 AM, Jon Chesterfield <span dir="ltr"><<a href="mailto:jonathanchesterfield@gmail.com" target="_blank">jonathanchesterfield@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Hi, <div dir="auto"><br></div><div dir="auto">I've written a few target specific dag combine functions, called from performDAGCombine. The mechanism is great but my testing quite labour intensive - I search for IR which hits the new function then check the MIR downstream.</div><div dir="auto"><br></div><div dir="auto">I would like to write tests along the lines of "given this dag, call this function on that node, then check the result is equivalent to this other dag". Could you point me at the appropriate API for creating a dag from scratch, and for performing an equivalence test?</div><div dir="auto"><br></div><div dir="auto">Thanks,</div><div dir="auto"><br></div><div dir="auto">Jon</div><div dir="auto"><br></div><div dir="auto"><br></div></div>
</blockquote></div><br></div>