mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:54:44 +01:00
Remove SelfParam, add an AddrPattern instead. (#3506)
This is intended to make the representation of a `self` pattern be more similar to other patterns.
This commit is contained in:
@@ -73,6 +73,21 @@ auto FileContext::GetGlobal(SemIR::InstId inst_id) -> llvm::Value* {
|
||||
CARBON_FATAL() << "Missing value: " << inst_id << " " << target;
|
||||
}
|
||||
|
||||
// Returns the parameter for the given instruction from a function parameter
|
||||
// list.
|
||||
static auto GetAsParam(const SemIR::File& sem_ir, SemIR::InstId pattern_id)
|
||||
-> std::pair<SemIR::InstId, SemIR::Param> {
|
||||
auto pattern = sem_ir.insts().Get(pattern_id);
|
||||
|
||||
// Step over `addr`.
|
||||
if (auto addr = pattern.TryAs<SemIR::AddrPattern>()) {
|
||||
pattern_id = addr->inner_id;
|
||||
pattern = sem_ir.insts().Get(pattern_id);
|
||||
}
|
||||
|
||||
return {pattern_id, pattern.As<SemIR::Param>()};
|
||||
}
|
||||
|
||||
auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id)
|
||||
-> llvm::Function* {
|
||||
const auto& function = sem_ir().functions().Get(function_id);
|
||||
@@ -103,7 +118,7 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id)
|
||||
}
|
||||
for (auto param_ref_id :
|
||||
llvm::concat<const SemIR::InstId>(implicit_param_refs, param_refs)) {
|
||||
auto param_type_id = sem_ir().insts().Get(param_ref_id).type_id();
|
||||
auto param_type_id = GetAsParam(sem_ir(), param_ref_id).second.type_id;
|
||||
switch (auto value_rep = SemIR::GetValueRepr(sem_ir(), param_type_id);
|
||||
value_rep.kind) {
|
||||
case SemIR::ValueRepr::Unknown:
|
||||
@@ -148,16 +163,13 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id)
|
||||
// Set up parameters and the return slot.
|
||||
for (auto [inst_id, arg] :
|
||||
llvm::zip_equal(param_inst_ids, llvm_function->args())) {
|
||||
auto inst = sem_ir().insts().Get(inst_id);
|
||||
auto name_id = SemIR::NameId::Invalid;
|
||||
if (inst_id == function.return_slot_id) {
|
||||
name_id = SemIR::NameId::ReturnSlot;
|
||||
arg.addAttr(llvm::Attribute::getWithStructRetType(
|
||||
llvm_context(), GetType(function.return_type_id)));
|
||||
} else if (inst.Is<SemIR::SelfParam>()) {
|
||||
name_id = SemIR::NameId::SelfValue;
|
||||
} else {
|
||||
name_id = inst.As<SemIR::Param>().name_id;
|
||||
name_id = GetAsParam(sem_ir(), inst_id).second.name_id;
|
||||
}
|
||||
arg.setName(sem_ir().names().GetIRBaseName(name_id));
|
||||
}
|
||||
@@ -194,14 +206,14 @@ auto FileContext::BuildFunctionDefinition(SemIR::FunctionId function_id)
|
||||
}
|
||||
for (auto param_ref_id :
|
||||
llvm::concat<const SemIR::InstId>(implicit_param_refs, param_refs)) {
|
||||
auto param_type_id = sem_ir().insts().Get(param_ref_id).type_id();
|
||||
auto [param_id, param] = GetAsParam(sem_ir(), param_ref_id);
|
||||
auto param_type_id = param.type_id;
|
||||
if (SemIR::GetValueRepr(sem_ir(), param_type_id).kind ==
|
||||
SemIR::ValueRepr::None) {
|
||||
function_lowering.SetLocal(
|
||||
param_ref_id, llvm::PoisonValue::get(GetType(param_type_id)));
|
||||
param_id, llvm::PoisonValue::get(GetType(param_type_id)));
|
||||
} else {
|
||||
function_lowering.SetLocal(param_ref_id,
|
||||
llvm_function->getArg(param_index));
|
||||
function_lowering.SetLocal(param_id, llvm_function->getArg(param_index));
|
||||
++param_index;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user