Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,8 @@ static void emitAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
auto load = builder.createLoad(loc, Ptr);
// FIXME(cir): add scope information.
assert(!cir::MissingFeatures::syncScopeID());
load->setAttr("mem_order", orderAttr);
if (E->isVolatile())
load->setAttr("is_volatile", mlir::UnitAttr::get(builder.getContext()));
load.setMemOrder(Order);
load.setIsVolatile(E->isVolatile());

// TODO(cir): this logic should be part of createStore, but doing so
// currently breaks CodeGen/union.cpp and CodeGen/union.cpp.
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,8 @@ RValue CIRGenFunction::emitRotate(const CallExpr *E, bool IsRotateRight) {
// result, but the CIR ops uses the same type for all values.
auto ty = src.getType();
shiftAmt = builder.createIntCast(shiftAmt, ty);
auto r =
builder.create<cir::RotateOp>(getLoc(E->getSourceRange()), src, shiftAmt);
if (!IsRotateRight)
r->setAttr("left", mlir::UnitAttr::get(src.getContext()));
auto r = cir::RotateOp::create(builder, getLoc(E->getSourceRange()), src,
shiftAmt, !IsRotateRight);
return RValue::get(r);
}

Expand Down Expand Up @@ -2377,7 +2375,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
auto fnOp =
CGM.GetOrCreateCIRFunction(ND->getName(), ty, gd, /*ForVTable=*/false,
/*DontDefer=*/false);
fnOp.setBuiltinAttr(mlir::UnitAttr::get(&getMLIRContext()));
fnOp.setBuiltin(true);
return emitCall(E->getCallee()->getType(), CIRGenCallee::forDirect(fnOp), E,
ReturnValue);
}
Expand Down
24 changes: 10 additions & 14 deletions clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,11 @@ cir::CallOp CIRGenFunction::emitCoroIDBuiltinCall(mlir::Location loc,

cir::FuncOp fnOp;
if (!builtin) {
fnOp = CGM.createCIRFunction(
fnOp = CGM.createCIRBuiltinFunction(
loc, CGM.builtinCoroId,
cir::FuncType::get({int32Ty, VoidPtrTy, VoidPtrTy, VoidPtrTy}, int32Ty),
/*FD=*/nullptr);
assert(fnOp && "should always succeed");
fnOp.setBuiltinAttr(mlir::UnitAttr::get(&getMLIRContext()));
} else
fnOp = cast<cir::FuncOp>(builtin);

Expand All @@ -191,11 +190,10 @@ cir::CallOp CIRGenFunction::emitCoroAllocBuiltinCall(mlir::Location loc) {

cir::FuncOp fnOp;
if (!builtin) {
fnOp = CGM.createCIRFunction(loc, CGM.builtinCoroAlloc,
cir::FuncType::get({int32Ty}, boolTy),
/*FD=*/nullptr);
fnOp = CGM.createCIRBuiltinFunction(loc, CGM.builtinCoroAlloc,
cir::FuncType::get({int32Ty}, boolTy),
/*FD=*/nullptr);
assert(fnOp && "should always succeed");
fnOp.setBuiltinAttr(mlir::UnitAttr::get(&getMLIRContext()));
} else
fnOp = cast<cir::FuncOp>(builtin);

Expand All @@ -211,12 +209,11 @@ CIRGenFunction::emitCoroBeginBuiltinCall(mlir::Location loc,

cir::FuncOp fnOp;
if (!builtin) {
fnOp = CGM.createCIRFunction(
fnOp = CGM.createCIRBuiltinFunction(
loc, CGM.builtinCoroBegin,
cir::FuncType::get({int32Ty, VoidPtrTy}, VoidPtrTy),
/*FD=*/nullptr);
assert(fnOp && "should always succeed");
fnOp.setBuiltinAttr(mlir::UnitAttr::get(&getMLIRContext()));
} else
fnOp = cast<cir::FuncOp>(builtin);

Expand All @@ -232,12 +229,11 @@ cir::CallOp CIRGenFunction::emitCoroEndBuiltinCall(mlir::Location loc,

cir::FuncOp fnOp;
if (!builtin) {
fnOp =
CGM.createCIRFunction(loc, CGM.builtinCoroEnd,
cir::FuncType::get({VoidPtrTy, boolTy}, boolTy),
/*FD=*/nullptr);
fnOp = CGM.createCIRBuiltinFunction(
loc, CGM.builtinCoroEnd,
cir::FuncType::get({VoidPtrTy, boolTy}, boolTy),
/*FD=*/nullptr);
assert(fnOp && "should always succeed");
fnOp.setBuiltinAttr(mlir::UnitAttr::get(&getMLIRContext()));
} else
fnOp = cast<cir::FuncOp>(builtin);

Expand All @@ -252,7 +248,7 @@ CIRGenFunction::emitCoroutineBody(const CoroutineBodyStmt &S) {

auto Fn = dyn_cast<cir::FuncOp>(CurFn);
assert(Fn && "other callables NYI");
Fn.setCoroutineAttr(mlir::UnitAttr::get(&getMLIRContext()));
Fn.setCoroutine(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate concern: should we rename these optional attributes to follow some pattern? Right now we have both thing and is_thing, for example load has is_deref while function has coroutine. After these changes (which are great) it gets a bit more confusing as to what's happening in these setters/getters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be for is_thing when it makes sense. But things like no_signed_wrap sound weird as is_no_signed_wrap.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. We can do a case by case thing and this isn't high priority.

auto coroId = emitCoroIDBuiltinCall(openCurlyLoc, nullPtrCst);
createCoroData(*this, CurCoro, coroId);

Expand Down
3 changes: 1 addition & 2 deletions clang/lib/CIR/CodeGen/CIRGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ void CIRGenFunction::emitAutoVarInit(const AutoVarEmission &emission) {
auto allocaOp = addr.getDefiningOp<cir::AllocaOp>();
assert(allocaOp && "Address should come straight out of the alloca");

if (!allocaOp.use_empty())
allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
allocaOp.setInit(!allocaOp.use_empty());
return;
}

Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ void CIRGenFunction::emitStoreOfScalar(mlir::Value value, Address addr,
if (currVarDecl && SrcAlloca) {
const VarDecl *VD = currVarDecl;
assert(VD && "VarDecl expected");
if (VD->hasInit())
SrcAlloca.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
SrcAlloca.setInit(VD->hasInit());
}

assert(currSrcLoc && "must pass in source location");
Expand Down Expand Up @@ -1329,7 +1328,7 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *E) {

// Tag 'load' with deref attribute.
if (auto loadOp = Addr.getDefiningOp<cir::LoadOp>()) {
loadOp.setIsDerefAttr(mlir::UnitAttr::get(&getMLIRContext()));
loadOp.setIsDeref(true);
}

LValue LV = LValue::makeAddr(Addr, T, BaseInfo, TBAAInfo);
Expand Down
14 changes: 5 additions & 9 deletions clang/lib/CIR/CodeGen/CIRGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,8 @@ mlir::LogicalResult CIRGenFunction::declare(const Decl *var, QualType ty,

addr = emitAlloca(namedVar->getName(), ty, loc, alignment);
auto allocaOp = addr.getDefiningOp<cir::AllocaOp>();
if (isParam)
allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
if (ty->isReferenceType() || ty.isConstQualified())
allocaOp.setConstantAttr(mlir::UnitAttr::get(&getMLIRContext()));
allocaOp.setInit(isParam);
allocaOp.setConstant(ty->isReferenceType() || ty.isConstQualified());

symbolTable.insert(var, addr);
return mlir::success();
Expand All @@ -316,10 +314,8 @@ mlir::LogicalResult CIRGenFunction::declare(Address addr, const Decl *var,

addrVal = addr.getPointer();
auto allocaOp = addrVal.getDefiningOp<cir::AllocaOp>();
if (isParam)
allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
if (ty->isReferenceType() || ty.isConstQualified())
allocaOp.setConstantAttr(mlir::UnitAttr::get(&getMLIRContext()));
allocaOp.setInit(isParam);
allocaOp.setConstant(ty->isReferenceType() || ty.isConstQualified());

symbolTable.insert(var, addrVal);
return mlir::success();
Expand Down Expand Up @@ -1350,7 +1346,7 @@ void CIRGenFunction::StartFunction(GlobalDecl gd, QualType retTy,
// We're in a lambda.
auto fn = dyn_cast<cir::FuncOp>(CurFn);
assert(fn && "other callables NYI");
fn.setLambdaAttr(mlir::UnitAttr::get(&getMLIRContext()));
fn.setLambda(true);

// Figure out the captures.
md->getParent()->getCaptureFields(LambdaCaptureFields,
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,15 @@ cir::FuncOp CIRGenModule::createCIRFunction(mlir::Location loc, StringRef name,
return f;
}

cir::FuncOp
CIRGenModule::createCIRBuiltinFunction(mlir::Location loc, StringRef name,
cir::FuncType ty,
const clang::FunctionDecl *fd) {
cir::FuncOp fnOp = createCIRFunction(loc, name, ty, fd);
fnOp.setBuiltin(true);
return fnOp;
}

cir::FuncOp CIRGenModule::createRuntimeFunction(cir::FuncType ty,
StringRef name, mlir::ArrayAttr,
[[maybe_unused]] bool local,
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,11 @@ class CIRGenModule : public CIRGenTypeCache {
cir::FuncType Ty,
const clang::FunctionDecl *FD);

/// Create a CIR function with builtin attribute set.
cir::FuncOp createCIRBuiltinFunction(mlir::Location loc, llvm::StringRef name,
cir::FuncType Ty,
const clang::FunctionDecl *FD);

cir::FuncOp createRuntimeFunction(cir::FuncType Ty, llvm::StringRef Name,
mlir::ArrayAttr = {}, bool Local = false,
bool AssumeConvergent = false);
Expand Down
Loading