Skip to content

Commit 74de6c4

Browse files
smeenailanza
authored andcommitted
[CIR][CIRGen] Change buildX functions to emitX (#1093)
The buildX naming convention originated when the CIRGen implementation was planned to be substantially different from original CodeGen. CIRGen is now a much closer adaption of CodeGen, and the emitX to buildX renaming just makes things more confusing, since CodeGen also has some helper functions whose names start with build or Build, so it's not immediately clear which CodeGen function corresponds to a CIRGen buildX function. Rename the buildX functions back to emitX to fix this. This diff was generated mostly mechanically. I searched for all buildX functions in CIRGen and all emitX or buildX functions in CodeGen: ``` rg '\b[Bb]uild[A-Z][A-Za-z0-9_]*\b' clang/lib/CIR/CodeGen -Io | sort -u -o /tmp/buildfuncs rg '\b([Ee]mit|[Bb]uild)[A-Z][A-Za-z0-9_]*\b' clang/lib/CodeGen -Io | sort -u -o /tmp/emitfuncs ``` I used a simple Python script to find corresponding functions: https://gist.github.com/smeenai/02be7ced8564cef5518df72606ec7b19. https://gist.github.com/smeenai/6ffd67be4249c8cebdd7fa99cfa4f13c is the resulting list of correspondences. This isn't 100% accurate because it's not accounting for the files that the functions are present in, but that's pretty unlikely to matter here, so I kept it simple. The buildX functions in CIRGen which correspond to an emitX function in CodeGen should be changed, and the ones which correspond to a BuildX function in CodeGen should not be changed. That leaves some functions without any correspondences, which required a judgement call. I scanned through all those functions, and buildVirtualMethodAttr was the only one that seemed like it shouldn't be changed to emit. I performed the replacement as follows: ``` funcs="$(awk '(/-> [Ee]/ || !/->/) && !/buildVirtualMethodAttr/ { print substr($1, 6) }' /tmp/corrfuncs | paste -sd '|')" find clang/include/clang/CIR clang/lib/CIR/{CodeGen,FrontendAction} \( -name '*.h' -o -name '*.cpp' \) -print0 | \ xargs -0 perl -pi -e "s/\bbuild($funcs)\\b/emit\\1/g" ``` The mechanical changes are in the first commit of this PR. There was a manual fixup required for a token pasting macro in CIRGenExprScalar.cpp, which is the second commit. I then ran `git clang-format`, which is the third commit. (They'll be squashed together when the PR is committed.)
1 parent f679306 commit 74de6c4

37 files changed

+2524
-2564
lines changed

clang/include/clang/CIR/CIRGenerator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class CIRGenerator : public clang::ASTConsumer {
6666
~HandlingTopLevelDeclRAII() {
6767
unsigned Level = --Self.HandlingTopLevelDecls;
6868
if (Level == 0 && EmitDeferred)
69-
Self.buildDeferredDecls();
69+
Self.emitDeferredDecls();
7070
}
7171
};
7272

@@ -101,8 +101,8 @@ class CIRGenerator : public clang::ASTConsumer {
101101

102102
bool verifyModule();
103103

104-
void buildDeferredDecls();
105-
void buildDefaultMethods();
104+
void emitDeferredDecls();
105+
void emitDefaultMethods();
106106
};
107107

108108
} // namespace cir

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ constexpr bool cirCConvAssertionMode =
5454
namespace cir {
5555

5656
struct MissingFeatures {
57-
// TODO(CIR): Implement the CIRGenFunction::buildTypeCheck method that handles
57+
// TODO(CIR): Implement the CIRGenFunction::emitTypeCheck method that handles
5858
// sanitizer related type check features
59-
static bool buildTypeCheck() { return false; }
59+
static bool emitTypeCheck() { return false; }
6060
static bool tbaa() { return false; }
6161
static bool cleanups() { return false; }
6262
static bool emitNullabilityCheck() { return false; }
@@ -128,8 +128,8 @@ struct MissingFeatures {
128128

129129
// Missing Emissions
130130
static bool variablyModifiedTypeEmission() { return false; }
131-
static bool buildLValueAlignmentAssumption() { return false; }
132-
static bool buildDerivedToBaseCastForDevirt() { return false; }
131+
static bool emitLValueAlignmentAssumption() { return false; }
132+
static bool emitDerivedToBaseCastForDevirt() { return false; }
133133
static bool emitFunctionEpilog() { return false; }
134134

135135
// References related stuff
@@ -226,7 +226,7 @@ struct MissingFeatures {
226226
static bool deferredReplacements() { return false; }
227227
static bool shouldInstrumentFunction() { return false; }
228228
static bool xray() { return false; }
229-
static bool buildConstrainedFPCall() { return false; }
229+
static bool emitConstrainedFPCall() { return false; }
230230
static bool emitEmptyRecordCheck() { return false; }
231231

232232
// Inline assembly

clang/lib/CIR/CodeGen/CIRAsm.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ static void collectInOutConstrainsInfos(const CIRGenFunction &cgf,
200200
}
201201
}
202202

203-
std::pair<mlir::Value, mlir::Type> CIRGenFunction::buildAsmInputLValue(
203+
std::pair<mlir::Value, mlir::Type> CIRGenFunction::emitAsmInputLValue(
204204
const TargetInfo::ConstraintInfo &Info, LValue InputValue,
205205
QualType InputType, std::string &ConstraintStr, SourceLocation Loc) {
206206

207207
if (Info.allowsRegister() || !Info.allowsMemory()) {
208208
if (hasScalarEvaluationKind(InputType))
209-
return {buildLoadOfLValue(InputValue, Loc).getScalarVal(), mlir::Type()};
209+
return {emitLoadOfLValue(InputValue, Loc).getScalarVal(), mlir::Type()};
210210

211211
mlir::Type Ty = convertType(InputType);
212212
uint64_t Size = CGM.getDataLayout().getTypeSizeInBits(Ty);
@@ -226,9 +226,9 @@ std::pair<mlir::Value, mlir::Type> CIRGenFunction::buildAsmInputLValue(
226226
}
227227

228228
std::pair<mlir::Value, mlir::Type>
229-
CIRGenFunction::buildAsmInput(const TargetInfo::ConstraintInfo &Info,
230-
const Expr *InputExpr,
231-
std::string &ConstraintStr) {
229+
CIRGenFunction::emitAsmInput(const TargetInfo::ConstraintInfo &Info,
230+
const Expr *InputExpr,
231+
std::string &ConstraintStr) {
232232
auto loc = getLoc(InputExpr->getExprLoc());
233233

234234
// If this can't be a register or memory, i.e., has to be a constant
@@ -251,23 +251,23 @@ CIRGenFunction::buildAsmInput(const TargetInfo::ConstraintInfo &Info,
251251

252252
if (Info.allowsRegister() || !Info.allowsMemory())
253253
if (CIRGenFunction::hasScalarEvaluationKind(InputExpr->getType()))
254-
return {buildScalarExpr(InputExpr), mlir::Type()};
254+
return {emitScalarExpr(InputExpr), mlir::Type()};
255255
if (InputExpr->getStmtClass() == Expr::CXXThisExprClass)
256-
return {buildScalarExpr(InputExpr), mlir::Type()};
256+
return {emitScalarExpr(InputExpr), mlir::Type()};
257257
InputExpr = InputExpr->IgnoreParenNoopCasts(getContext());
258-
LValue Dest = buildLValue(InputExpr);
259-
return buildAsmInputLValue(Info, Dest, InputExpr->getType(), ConstraintStr,
260-
InputExpr->getExprLoc());
258+
LValue Dest = emitLValue(InputExpr);
259+
return emitAsmInputLValue(Info, Dest, InputExpr->getType(), ConstraintStr,
260+
InputExpr->getExprLoc());
261261
}
262262

263-
static void buildAsmStores(CIRGenFunction &CGF, const AsmStmt &S,
264-
const llvm::ArrayRef<mlir::Value> RegResults,
265-
const llvm::ArrayRef<mlir::Type> ResultRegTypes,
266-
const llvm::ArrayRef<mlir::Type> ResultTruncRegTypes,
267-
const llvm::ArrayRef<LValue> ResultRegDests,
268-
const llvm::ArrayRef<QualType> ResultRegQualTys,
269-
const llvm::BitVector &ResultTypeRequiresCast,
270-
const llvm::BitVector &ResultRegIsFlagReg) {
263+
static void emitAsmStores(CIRGenFunction &CGF, const AsmStmt &S,
264+
const llvm::ArrayRef<mlir::Value> RegResults,
265+
const llvm::ArrayRef<mlir::Type> ResultRegTypes,
266+
const llvm::ArrayRef<mlir::Type> ResultTruncRegTypes,
267+
const llvm::ArrayRef<LValue> ResultRegDests,
268+
const llvm::ArrayRef<QualType> ResultRegQualTys,
269+
const llvm::BitVector &ResultTypeRequiresCast,
270+
const llvm::BitVector &ResultRegIsFlagReg) {
271271
CIRGenBuilderTy &Builder = CGF.getBuilder();
272272
CIRGenModule &CGM = CGF.CGM;
273273
auto CTX = Builder.getContext();
@@ -337,11 +337,11 @@ static void buildAsmStores(CIRGenFunction &CGF, const AsmStmt &S,
337337
Dest = CGF.makeAddrLValue(A, Ty);
338338
}
339339

340-
CGF.buildStoreThroughLValue(RValue::get(Tmp), Dest);
340+
CGF.emitStoreThroughLValue(RValue::get(Tmp), Dest);
341341
}
342342
}
343343

344-
mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
344+
mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &S) {
345345
// Assemble the final asm string.
346346
std::string AsmString = S.generateAsmString(getContext());
347347

@@ -405,7 +405,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
405405
CGM.Error(S.getAsmLoc(), "multiple outputs to hard register: " + GCCReg);
406406

407407
OutputConstraints.push_back(OutputConstraint);
408-
LValue Dest = buildLValue(OutExpr);
408+
LValue Dest = emitLValue(OutExpr);
409409

410410
if (!Constraints.empty())
411411
Constraints += ',';
@@ -496,8 +496,8 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
496496
mlir::Value Arg;
497497
mlir::Type ArgElemType;
498498
std::tie(Arg, ArgElemType) =
499-
buildAsmInputLValue(Info, Dest, InputExpr->getType(),
500-
InOutConstraints, InputExpr->getExprLoc());
499+
emitAsmInputLValue(Info, Dest, InputExpr->getType(), InOutConstraints,
500+
InputExpr->getExprLoc());
501501

502502
if (mlir::Type AdjTy = getTargetHooks().adjustInlineAsmType(
503503
*this, OutputConstraint, Arg.getType()))
@@ -555,7 +555,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
555555
std::string ReplaceConstraint(InputConstraint);
556556
mlir::Value Arg;
557557
mlir::Type ArgElemType;
558-
std::tie(Arg, ArgElemType) = buildAsmInput(Info, InputExpr, Constraints);
558+
std::tie(Arg, ArgElemType) = emitAsmInput(Info, InputExpr, Constraints);
559559

560560
// If this input argument is tied to a larger output result, extend the
561561
// input to be the same size as the output. The LLVM backend wants to see
@@ -676,8 +676,8 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
676676
} else if (ResultRegTypes.size() > 1) {
677677
auto alignment = CharUnits::One();
678678
auto sname = cast<cir::StructType>(ResultType).getName();
679-
auto dest = buildAlloca(sname, ResultType, getLoc(S.getAsmLoc()),
680-
alignment, false);
679+
auto dest = emitAlloca(sname, ResultType, getLoc(S.getAsmLoc()),
680+
alignment, false);
681681
auto addr = Address(dest, alignment);
682682
builder.createStore(getLoc(S.getAsmLoc()), result, addr);
683683

@@ -692,9 +692,9 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
692692
}
693693
}
694694

695-
buildAsmStores(*this, S, RegResults, ResultRegTypes, ResultTruncRegTypes,
696-
ResultRegDests, ResultRegQualTys, ResultTypeRequiresCast,
697-
ResultRegIsFlagReg);
695+
emitAsmStores(*this, S, RegResults, ResultRegTypes, ResultTruncRegTypes,
696+
ResultRegDests, ResultRegQualTys, ResultTypeRequiresCast,
697+
ResultRegIsFlagReg);
698698

699699
return mlir::success();
700700
}

0 commit comments

Comments
 (0)