[llvm-dev] Testing selection dag combines

Jon Chesterfield via llvm-dev llvm-dev at lists.llvm.org
Thu May 11 08:52:40 PDT 2017


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.

Thanks!

#include "llvm/Target/OOT/OOTLowering.h"

#include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetMachine.h"

namespace llvm {
extern Target TheOOTTarget;
}

const llvm::TargetMachine &get_target_machine() {
  static bool init = false;
  static llvm::TargetMachine *local = nullptr;
  if (!init) {
    init = true;
    llvm::InitializeAllTargets();
    llvm::InitializeAllTargetMCs();
    llvm::InitializeAllAsmPrinters();
    llvm::InitializeAllAsmParsers();

    std::string TripleStr = llvm::sys::getDefaultTargetTriple();
    llvm::Triple Triple(TripleStr);

    std::string errMsg;
    const llvm::Target *march =
        llvm::TargetRegistry::lookupTarget(TripleStr, errMsg);
    assert(march);

    local = llvm::TheOOTTarget.createTargetMachine(
        TripleStr, "", "", llvm::TargetOptions(), llvm::None);
  }
  assert(local);
  return *local;
}

int main() {
  using namespace llvm;
  SelectionDAG DAG(get_target_machine(), CodeGenOpt::Default);

  DAG.dump(); // OK

  auto rt = DAG.getRoot();
  SDLoc dl(rt);

  SDValue aconstant = DAG.getConstant(123, dl, MVT::i32);
  aconstant.dump(); // segv
}

On Thu, May 11, 2017 at 11:48 AM, Jon Chesterfield <
jonathanchesterfield at gmail.com> wrote:

> Hi,
>
> 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.
>
> 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?
>
> Thanks,
>
> Jon
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170511/cc35d492/attachment.html>


More information about the llvm-dev mailing list