Fix translation of NVVM special registers to intrinsics.

The original implementation did not map the return value of the intrinsics
    call to the result value of the special register op. Uses of the result
    value hence hit a nullpointer.

--

PiperOrigin-RevId: 250255436
This commit is contained in:
Stephan Herhut 2019-05-28 04:45:50 -07:00 committed by Mehdi Amini
parent d4c071cc69
commit 8d703af2f8
3 changed files with 6 additions and 5 deletions

View File

@ -38,8 +38,8 @@ class NVVM_SpecialRegisterOp<string mnemonic,
list<OpTrait> traits = []> :
NVVM_Op<mnemonic, !listconcat(traits, [NoSideEffect])>,
Results<(outs LLVM_Type:$res)>, Arguments<(ins)> {
string llvmBuilder = "createIntrinsicCall(builder, llvm::Intrinsic::nvvm_"
# !subst(".","_", mnemonic) # ");";
string llvmBuilder = "$res = createIntrinsicCall(builder,"
# "llvm::Intrinsic::nvvm_" # !subst(".","_", mnemonic) # ");";
let parser = [{ return parseNVVMSpecialRegisterOp(parser, result); }];
let printer = [{ printNVVMSpecialRegisterOp(p, this->getOperation()); }];
}

View File

@ -86,6 +86,7 @@ private:
Module &mlirModule;
std::unique_ptr<llvm::Module> llvmModule;
protected:
// Mappings between original and translated values, used for lookups.
llvm::StringMap<llvm::Function *> functionMapping;
llvm::DenseMap<Value *, llvm::Value *> valueMapping;

View File

@ -34,11 +34,11 @@
using namespace mlir;
namespace {
static void createIntrinsicCall(llvm::IRBuilder<> &builder,
llvm::Intrinsic::ID intrinsic) {
static llvm::Value *createIntrinsicCall(llvm::IRBuilder<> &builder,
llvm::Intrinsic::ID intrinsic) {
llvm::Module *module = builder.GetInsertBlock()->getModule();
llvm::Function *fn = llvm::Intrinsic::getDeclaration(module, intrinsic, {});
builder.CreateCall(fn);
return builder.CreateCall(fn);
}
class ModuleTranslation : public LLVM::ModuleTranslation {