LLVM 18.0.0git
Go to the documentation of this file.
1//===- ValueList.cpp - Internal BitcodeReader implementation --------------===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9#include "ValueList.h"
11#include "llvm/IR/Argument.h"
12#include "llvm/IR/Constant.h"
13#include "llvm/IR/Constants.h"
14#include "llvm/IR/GlobalValue.h"
15#include "llvm/IR/Instruction.h"
16#include "llvm/IR/Type.h"
17#include "llvm/IR/User.h"
18#include "llvm/IR/Value.h"
20#include "llvm/Support/Error.h"
22#include <cstddef>
24using namespace llvm;
27 unsigned TypeID) {
28 if (Idx == size()) {
29 push_back(V, TypeID);
30 return Error::success();
31 }
33 if (Idx >= size())
34 resize(Idx + 1);
36 auto &Old = ValuePtrs[Idx];
37 if (!Old.first) {
38 Old.first = V;
39 Old.second = TypeID;
40 return Error::success();
41 }
43 assert(!isa<Constant>(&*Old.first) && "Shouldn't update constant");
44 // If there was a forward reference to this value, replace it.
45 Value *PrevVal = Old.first;
46 if (PrevVal->getType() != V->getType())
47 return createStringError(
48 std::errc::illegal_byte_sequence,
49 "Assigned value does not match type of forward declaration");
50 Old.first->replaceAllUsesWith(V);
51 PrevVal->deleteValue();
52 return Error::success();
56 unsigned TyID,
57 BasicBlock *ConstExprInsertBB) {
58 // Bail out for a clearly invalid value.
59 if (Idx >= RefsUpperBound)
60 return nullptr;
62 if (Idx >= size())
63 resize(Idx + 1);
65 if (Value *V = ValuePtrs[Idx].first) {
66 // If the types don't match, it's invalid.
67 if (Ty && Ty != V->getType())
68 return nullptr;
70 Expected<Value *> MaybeV = MaterializeValueFn(Idx, ConstExprInsertBB);
71 if (!MaybeV) {
72 // TODO: We might want to propagate the precise error message here.
73 consumeError(MaybeV.takeError());
74 return nullptr;
75 }
76 return MaybeV.get();
77 }
79 // No type specified, must be invalid reference.
80 if (!Ty)
81 return nullptr;
83 // Create and return a placeholder, which will later be RAUW'd.
84 Value *V = new Argument(Ty);
85 ValuePtrs[Idx] = {V, TyID};
86 return V;
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
Definition: ValueList.cpp:55
void resize(unsigned N)
Definition: ValueList.h:49
void push_back(Value *V, unsigned TypeID)
Definition: ValueList.h:52
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
Definition: ValueList.cpp:26
unsigned size() const
Definition: ValueList.h:48
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
Error takeError()
Take ownership of the stored error.
Definition: Error.h:601
reference get()
Returns a reference to the stored T value.
Definition: Error.h:571
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Definitions of all of the base types for the Type system.
Definition: Type.h:54
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void deleteValue()
Delete a pointer to a generic Value.
Definition: Value.cpp:110
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1244
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1041