type.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_LOWER_TYPE_H_
  5. #define CARBON_TOOLCHAIN_LOWER_TYPE_H_
  6. #include "llvm/ADT/ArrayRef.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "llvm/IR/DebugInfoMetadata.h"
  9. #include "llvm/IR/DerivedTypes.h"
  10. #include "toolchain/sem_ir/ids.h"
  11. namespace Carbon::Lower {
  12. class FileContext;
  13. // Information about how a function is called in SemIR, used as input to
  14. // build a FunctionTypeInfo.
  15. struct FunctionInContext {
  16. FileContext* context;
  17. SemIR::FunctionId function_id;
  18. SemIR::SpecificId specific_id;
  19. };
  20. // Information used to build a FunctionInfo in FileContext.
  21. struct FunctionTypeInfo {
  22. // The type of the lowered function.
  23. llvm::FunctionType* type;
  24. // The debug info type of the lowered function.
  25. llvm::DISubroutineType* di_type;
  26. // The indices of the `Call` parameter patterns that correspond to parameters
  27. // of the LLVM IR function, in the order of the LLVM IR parameter list.
  28. llvm::SmallVector<SemIR::CallParamIndex> lowered_param_indices;
  29. // The indices of any `Call` param patterns that aren't present in
  30. // lowered_param_indices.
  31. llvm::SmallVector<SemIR::CallParamIndex> unused_param_indices;
  32. // The names of the lowered `Call` parameters, in the same order as
  33. // `lowered_param_indices`.
  34. llvm::SmallVector<SemIR::NameId> param_name_ids;
  35. // When `return_param_id` is not `None`, the corresponding lowered parameter
  36. // should be given an `sret` attribute with this type.
  37. llvm::Type* sret_type = nullptr;
  38. // Whether the function type information is inexact, because some component
  39. // type was incomplete.
  40. bool inexact;
  41. };
  42. // Builds and returns a FunctionTypeInfo from the accumulated information in the
  43. // given functions.
  44. auto BuildFunctionTypeInfo(llvm::ArrayRef<FunctionInContext> functions)
  45. -> FunctionTypeInfo;
  46. struct LoweredTypes {
  47. llvm::Type* llvm_ir_type;
  48. llvm::DIType* llvm_di_type;
  49. };
  50. // Builds the `llvm::Type` and `llvm::DIType` for the given instruction.
  51. auto BuildType(FileContext& context, SemIR::InstId inst_id) -> LoweredTypes;
  52. } // namespace Carbon::Lower
  53. #endif // CARBON_TOOLCHAIN_LOWER_TYPE_H_