Skip to content

Commit

Permalink
Translation to LLVM: support llvm.global
Browse files Browse the repository at this point in the history
Add support for translating recently introduced llvm.global operations to
global variables in the LLVM IR proper.

PiperOrigin-RevId: 262564700
  • Loading branch information
tensorflower-gardener committed Aug 9, 2019
1 parent 5a174fe commit 977f213
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ModuleTranslation {

T translator(m);
translator.llvmModule = std::move(llvmModule);
translator.convertGlobals();
if (translator.convertFunctions())
return nullptr;

Expand All @@ -72,6 +73,7 @@ class ModuleTranslation {

private:
bool convertFunctions();
void convertGlobals();
bool convertOneFunction(FuncOp func);
void connectPHINodes(FuncOp func);
bool convertBlock(Block &bb, bool ignoreArguments);
Expand Down
10 changes: 10 additions & 0 deletions third_party/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ bool ModuleTranslation::convertBlock(Block &bb, bool ignoreArguments) {
return false;
}

// Create named global variables that correspond to llvm.global definitions.
void ModuleTranslation::convertGlobals() {
for (auto op : mlirModule.getOps<LLVM::GlobalOp>()) {
llvm::Type *type = op.getType().getUnderlyingType();
new llvm::GlobalVariable(
*llvmModule, type, op.constant(), llvm::GlobalValue::InternalLinkage,
getLLVMConstant(type, op.value(), op.getLoc()), op.sym_name());
}
}

// Get the SSA value passed to the current block from the terminator operation
// of its predecessor.
static Value *getPHISourceValue(Block *current, Block *pred,
Expand Down

0 comments on commit 977f213

Please sign in to comment.