Skip to content

Commit

Permalink
Fix visibility and type
Browse files Browse the repository at this point in the history
  • Loading branch information
niuxiaog committed May 29, 2024
1 parent 25f611e commit 4363915
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/gc/Transforms/CST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,41 +343,43 @@ struct constGraphTensorCacheManager {
}
};

static void addGlobalI32(ModuleOp module, Location loc, OpBuilder &builder,
static void addGlobalI32(ModuleOp &module, Location loc, OpBuilder &builder,
StringRef name, int32_t value) {
OpBuilder::InsertionGuard insertGuard(builder);
builder.setInsertionPointToStart(module.getBody());

auto type = IntegerType::get(builder.getContext(), 32);
LLVM::GlobalOp global = builder.create<LLVM::GlobalOp>(
loc, type, /*isConstant=*/true, LLVM::Linkage::Internal, name,
loc, type, /*isConstant=*/true, LLVM::Linkage::External, name,
builder.getI32IntegerAttr(value),
/*alignment=*/0);
}

static void addGlobalI64Array(ModuleOp module, Location loc, OpBuilder &builder,
StringRef name, ArrayRef<int64_t> array) {
static void addGlobalI64Array(ModuleOp &module, Location loc,
OpBuilder &builder, StringRef name,
ArrayRef<int64_t> array) {
OpBuilder::InsertionGuard insertGuard(builder);
builder.setInsertionPointToStart(module.getBody());

auto type = LLVM::LLVMArrayType::get(
IntegerType::get(builder.getContext(), 64), array.size());
LLVM::GlobalOp global = builder.create<LLVM::GlobalOp>(
loc, type, /*isConstant=*/true, LLVM::Linkage::Internal, name,
builder.getI64ArrayAttr(array),
loc, type, /*isConstant=*/true, LLVM::Linkage::External, name,
builder.getI64TensorAttr(array),
/*alignment=*/0);
}

static void addGlobalI32Array(ModuleOp module, Location loc, OpBuilder &builder,
StringRef name, ArrayRef<int32_t> array) {
static void addGlobalI32Array(ModuleOp &module, Location loc,
OpBuilder &builder, StringRef name,
ArrayRef<int32_t> array) {
OpBuilder::InsertionGuard insertGuard(builder);
builder.setInsertionPointToStart(module.getBody());

auto type = LLVM::LLVMArrayType::get(
IntegerType::get(builder.getContext(), 32), array.size());
LLVM::GlobalOp global = builder.create<LLVM::GlobalOp>(
loc, type, /*isConstant=*/true, LLVM::Linkage::Internal, name,
builder.getI32ArrayAttr(array),
loc, type, /*isConstant=*/true, LLVM::Linkage::External, name,
builder.getI32TensorAttr(array),
/*alignment=*/0);
}

Expand Down Expand Up @@ -493,7 +495,7 @@ void CST::runOnOperation() {

FunctionType foldFuncType =
FunctionType::get(context, inputTypes, outputTypes);
auto foldFunc =
func::FuncOp foldFunc =
builder.create<func::FuncOp>(topFunc.getLoc(), funcName, foldFuncType);
Block *foldBlock = foldFunc.addEntryBlock();
// values of folded constant weights in foldBlock
Expand Down Expand Up @@ -541,6 +543,8 @@ void CST::runOnOperation() {
globalIndexes);

foldFunc.setVisibility(SymbolTable::Visibility::Public);
foldFunc->setAttr(LLVM::LLVMDialect::getEmitCWrapperAttrName(),
UnitAttr::get(context));
moduleOp.push_back(foldFunc);
symbolTable.insert(foldFunc);

Expand Down

0 comments on commit 4363915

Please sign in to comment.