Skip to content

Commit 02b5829

Browse files
committed
apply suggestions
1 parent fd1d37e commit 02b5829

File tree

6 files changed

+61
-42
lines changed

6 files changed

+61
-42
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ struct MissingFeatures {
159159
static bool bitfields() { return false; }
160160
static bool typeChecks() { return false; }
161161
static bool lambdaFieldToName() { return false; }
162+
static bool paramInfo() { return false; }
163+
static bool funcTypeExtInfo() { return false; }
162164

163165
// Missing types
164166
static bool dataMemberType() { return false; }

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,57 +25,71 @@ CIRGenFunctionInfo::create(CanQualType resultType,
2525
RequiredArgs required) {
2626
void *buffer = operator new(totalSizeToAlloc<ArgInfo>(argTypes.size() + 1));
2727

28+
assert(!cir::MissingFeatures::paramInfo());
29+
assert(!cir::MissingFeatures::funcTypeExtInfo());
30+
2831
CIRGenFunctionInfo *fi = new (buffer) CIRGenFunctionInfo();
2932

3033
fi->required = required;
3134
fi->numArgs = argTypes.size();
32-
fi->getArgsBuffer()[0].type = resultType;
33-
for (unsigned i = 0; i < argTypes.size(); ++i)
34-
fi->getArgsBuffer()[i + 1].type = argTypes[i];
35+
36+
// ArgsBuffer contains the return type at index 0, and the argument types
37+
// starting at index 1, so there are argTypes.size() + 1 elements in total.
38+
unsigned idx = 1;
39+
ArgInfo *argsBuffer = fi->getArgsBuffer();
40+
argsBuffer[0].type = resultType;
41+
for (const auto &argType : argTypes)
42+
argsBuffer[idx++].type = argType;
3543

3644
return fi;
3745
}
3846

3947
cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
4048
bool inserted = functionsBeingProcessed.insert(&fi).second;
49+
(void)inserted;
4150
assert(inserted && "Recursively being processed?");
4251

43-
mlir::Type resultType = nullptr;
44-
const cir::ABIArgInfo &retAI = fi.getReturnInfo();
52+
mlir::Type resultType;
53+
const cir::ABIArgInfo &retInfo = fi.getReturnInfo();
4554

46-
switch (retAI.getKind()) {
55+
switch (retInfo.getKind()) {
4756
case cir::ABIArgInfo::Ignore:
4857
// TODO(CIR): This should probably be the None type from the builtin
4958
// dialect.
5059
resultType = nullptr;
5160
break;
5261

5362
case cir::ABIArgInfo::Direct:
54-
resultType = retAI.getCoerceToType();
63+
resultType = retInfo.getCoerceToType();
5564
break;
5665

5766
default:
58-
assert(false && "NYI");
67+
cgm.errorNYI("getFunctionType: unhandled return kind");
5968
}
6069

61-
SmallVector<mlir::Type, 8> argTypes;
62-
unsigned argNo = 0;
63-
CIRGenFunctionInfo::const_arg_iterator it = fi.arg_begin(),
64-
ie = it + fi.getNumRequiredArgs();
65-
for (; it != ie; ++it, ++argNo) {
66-
const auto &argInfo = it->info;
70+
// TODO(cir): ClangToCIRArgMapping
6771

68-
switch (argInfo.getKind()) {
69-
default:
70-
llvm_unreachable("NYI");
71-
case cir::ABIArgInfo::Direct:
72-
mlir::Type argType = argInfo.getCoerceToType();
73-
argTypes.push_back(argType);
72+
SmallVector<mlir::Type, 8> argTypes(fi.getNumRequiredArgs());
73+
74+
unsigned argNo = 0;
75+
llvm::ArrayRef<CIRGenFunctionInfoArgInfo> argInfos(fi.argInfoBegin(),
76+
fi.getNumRequiredArgs());
77+
for (const auto &argInfo : argInfos) {
78+
const auto &abiArgInfo = argInfo.info;
79+
80+
switch (abiArgInfo.getKind()) {
81+
case cir::ABIArgInfo::Direct: {
82+
mlir::Type argType = abiArgInfo.getCoerceToType();
83+
argTypes[argNo++] = argType;
7484
break;
7585
}
86+
default:
87+
cgm.errorNYI("getFunctionType: unhandled argument kind");
88+
}
7689
}
7790

7891
bool erased = functionsBeingProcessed.erase(&fi);
92+
(void)erased;
7993
assert(erased && "Not in set?");
8094

8195
return cir::FuncType::get(argTypes,

clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ class CIRGenFunctionInfo final
103103
llvm::ArrayRef<CanQualType> argTypes) {
104104
id.AddBoolean(required.getOpaqueData());
105105
resultType.Profile(id);
106-
for (const auto &arg : argTypes)
106+
for (const CanQualType &arg : argTypes)
107107
arg.Profile(id);
108108
}
109109

110110
// NOLINTNEXTLINE(readability-identifier-naming)
111111
void Profile(llvm::FoldingSetNodeID &id) {
112112
id.AddBoolean(required.getOpaqueData());
113113
getReturnType().Profile(id);
114-
for (const auto &i : arguments())
115-
i.type.Profile(id);
114+
for (const ArgInfo &argInfo : argInfos())
115+
argInfo.type.Profile(id);
116116
}
117117

118118
CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
@@ -124,24 +124,27 @@ class CIRGenFunctionInfo final
124124
using const_arg_iterator = const ArgInfo *;
125125
using arg_iterator = ArgInfo *;
126126

127-
const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }
128-
const_arg_iterator arg_end() const { return getArgsBuffer() + 1 + numArgs; }
129-
arg_iterator arg_begin() { return getArgsBuffer() + 1; }
130-
arg_iterator arg_end() { return getArgsBuffer() + 1 + numArgs; }
127+
const_arg_iterator argInfoBegin() const { return getArgsBuffer() + 1; }
128+
const_arg_iterator argInfoEnd() const {
129+
return getArgsBuffer() + 1 + numArgs;
130+
}
131+
arg_iterator argInfoBegin() { return getArgsBuffer() + 1; }
132+
arg_iterator argInfoEnd() { return getArgsBuffer() + 1 + numArgs; }
131133

132-
unsigned arg_size() const { return numArgs; }
134+
unsigned argInfoSize() const { return numArgs; }
133135

134-
llvm::MutableArrayRef<ArgInfo> arguments() {
135-
return llvm::MutableArrayRef<ArgInfo>(arg_begin(), numArgs);
136+
llvm::MutableArrayRef<ArgInfo> argInfos() {
137+
return llvm::MutableArrayRef<ArgInfo>(argInfoBegin(), numArgs);
136138
}
137-
llvm::ArrayRef<ArgInfo> arguments() const {
138-
return llvm::ArrayRef<ArgInfo>(arg_begin(), numArgs);
139+
llvm::ArrayRef<ArgInfo> argInfos() const {
140+
return llvm::ArrayRef<ArgInfo>(argInfoBegin(), numArgs);
139141
}
140142

141143
bool isVariadic() const { return required.allowsOptionalArgs(); }
142144
RequiredArgs getRequiredArgs() const { return required; }
143145
unsigned getNumRequiredArgs() const {
144-
return isVariadic() ? getRequiredArgs().getNumRequiredArgs() : arg_size();
146+
return isVariadic() ? getRequiredArgs().getNumRequiredArgs()
147+
: argInfoSize();
145148
}
146149
};
147150

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/CIR/Dialect/IR/CIRDialect.h"
2323
#include "clang/CIR/MissingFeatures.h"
2424

25+
#include "CIRGenFunctionInfo.h"
2526
#include "mlir/IR/BuiltinOps.h"
2627
#include "mlir/IR/Location.h"
2728
#include "mlir/IR/MLIRContext.h"
@@ -222,8 +223,8 @@ void CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd,
222223
funcDecl->getType()
223224
->getCanonicalTypeUnqualified()
224225
.getAs<FunctionNoProtoType>()) {
225-
auto &fi = getTypes().arrangeCIRFunctionInfo(noProto->getReturnType(), {},
226-
RequiredArgs::All);
226+
const CIRGenFunctionInfo &fi = getTypes().arrangeCIRFunctionInfo(
227+
noProto->getReturnType(), {}, RequiredArgs::All);
227228
funcType = getTypes().getFunctionType(fi);
228229
} else
229230
funcType = cast<cir::FuncType>(convertType(funcDecl->getType()));

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "CIRGenTypes.h"
22

3+
#include "CIRGenFunctionInfo.h"
34
#include "CIRGenModule.h"
45

56
#include "clang/AST/ASTContext.h"
@@ -523,7 +524,7 @@ CIRGenTypes::arrangeCIRFunctionInfo(CanQualType returnType,
523524
if (retInfo.canHaveCoerceToType() && retInfo.getCoerceToType() == nullptr)
524525
retInfo.setCoerceToType(convertType(fi->getReturnType()));
525526

526-
for (auto &i : fi->arguments())
527+
for (CIRGenFunctionInfoArgInfo &i : fi->argInfos())
527528
if (i.info.canHaveCoerceToType() && i.info.getCoerceToType() == nullptr)
528529
i.info.setCoerceToType(convertType(i.type));
529530

clang/lib/CIR/CodeGen/TargetInfo.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ void X8664ABIInfo::computeInfo(CIRGenFunctionInfo &funcInfo) const {
3232
// Top level CIR has unlimited arguments and return types. Lowering for ABI
3333
// specific concerns should happen during a lowering phase. Assume everything
3434
// is direct for now.
35-
for (CIRGenFunctionInfo::arg_iterator it = funcInfo.arg_begin(),
36-
ie = funcInfo.arg_end();
37-
it != ie; ++it) {
38-
if (testIfIsVoidTy(it->type))
39-
it->info = cir::ABIArgInfo::getIgnore();
35+
for (CIRGenFunctionInfoArgInfo &argInfo : funcInfo.argInfos()) {
36+
if (testIfIsVoidTy(argInfo.type))
37+
argInfo.info = cir::ABIArgInfo::getIgnore();
4038
else
41-
it->info = cir::ABIArgInfo::getDirect(cgt.convertType(it->type));
39+
argInfo.info = cir::ABIArgInfo::getDirect(cgt.convertType(argInfo.type));
4240
}
4341
CanQualType retTy = funcInfo.getReturnType();
4442
if (testIfIsVoidTy(retTy))

0 commit comments

Comments
 (0)